Revert "drsuapi_dissect_element_DsGetNCChangesCtr6TS_ctr6 dissect_krb5_PAC_NDRHEADERBLOB"
[wireshark-sm.git] / tools / test-common.sh
blob2656eecece4ae74000ebd2be81cba167dfb2a88f
1 #!/bin/bash
3 # Copyright 2013 Gerald Combs <gerald@wireshark.org>
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # SPDX-License-Identifier: GPL-2.0-or-later
11 # Common variables and functions for fuzz and randpkt tests.
13 # This needs to point to a 'date' that supports %s.
14 if [ -z "$TEST_TYPE" ] ; then
15 echo "TEST_TYPE must be defined by the sourcing script."
16 exit 1
19 DATE=/bin/date
20 BASE_NAME=$TEST_TYPE-$($DATE +%Y-%m-%d)-$$
22 # Directory containing binaries. Default: cmake run directory.
23 if [ -z "$WIRESHARK_BIN_DIR" ]; then
24 WIRESHARK_BIN_DIR=run
27 # Temporary file directory and names.
28 # (had problems with this on cygwin, tried TMP_DIR=./ which worked)
29 TMP_DIR=/tmp
30 if [ "$OSTYPE" == "cygwin" ] ; then
31 TMP_DIR=$(cygpath --windows "$TMP_DIR")
33 TMP_FILE=$BASE_NAME.pcap
34 ERR_FILE=$BASE_NAME.err
36 # Loop this many times (< 1 loops forever)
37 MAX_PASSES=0
39 # These may be set to your liking
40 # Stop the child process if it's running longer than x seconds
41 MAX_CPU_TIME=600
42 # Stop the child process if it's using more than y * 1024 bytes
43 MAX_VMEM=1000000
44 # Stop the child process if its stack is larger than z * 1024 bytes
45 # Windows XP: 2033
46 # Windows 7: 2034
47 # Mac OS X 10.6: 8192
48 # Linux 2.6.24: 8192
49 # Solaris 10: 8192
50 MAX_STACK=2033
51 # Insert z times an error into the capture file (0.02 seems to be a good value to find errors)
52 ERR_PROB=0.02
53 # Maximum number of packets to fuzz
54 MAX_FUZZ_PACKETS=50000
56 # Call *after* any changes to WIRESHARK_BIN_DIR (e.g., via command-line options)
57 function ws_bind_exec_paths() {
58 # Tweak the following to your liking. Editcap must support "-E".
59 TSHARK="$WIRESHARK_BIN_DIR/tshark"
60 EDITCAP="$WIRESHARK_BIN_DIR/editcap"
61 CAPINFOS="$WIRESHARK_BIN_DIR/capinfos"
62 RANDPKT="$WIRESHARK_BIN_DIR/randpkt"
64 if [ "$WIRESHARK_BIN_DIR" = "." ]; then
65 export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1
69 function ws_check_exec() {
70 NOTFOUND=0
71 for i in "$@" ; do
72 if [ ! -x "$i" ]; then
73 echo "Couldn't find \"$i\""
74 NOTFOUND=1
76 done
77 if [ $NOTFOUND -eq 1 ]; then
78 exit 1
82 source "$(dirname "$0")"/debug-alloc.env
84 # Address Sanitizer options
85 export ASAN_OPTIONS=detect_leaks=0
87 # See if we were configured with gcc or clang's AddressSanitizer.
88 CONFIGURED_WITH_ASAN=0
89 # If tshark is built with ASAN this will generate an error. We could
90 # also pass help=1 and look for help text.
91 ASAN_OPTIONS=Invalid_Option_Flag $TSHARK -h > /dev/null 2>&1
92 if [ $? -ne 0 ] ; then
93 CONFIGURED_WITH_ASAN=1
95 export CONFIGURED_WITH_ASAN
97 # Create an error report
98 function ws_exit_error() {
99 echo -e "\n ERROR"
100 echo -e "Processing failed. Capture info follows:\n"
101 echo " Input file: $CF"
102 echo " Output file: $TMP_DIR/$TMP_FILE"
103 echo " Pass: $PASS"
104 echo
106 # Fill in build information
108 if [ -n "$CI_COMMIT_BRANCH" ] ; then
109 printf "Branch: %s\\n" "$CI_COMMIT_BRANCH"
110 else
111 printf "Branch: %s\\n" "$(git rev-parse --abbrev-ref HEAD)"
114 printf "Input file: %s\\n" "$CF"
116 if [ -n "$CI_JOB_NAME" ] ; then
117 printf "CI job name: %s, ID: %s\\n" "$CI_JOB_NAME" "$CI_JOB_ID"
118 printf "CI job URL: %s\\n" "$CI_JOB_URL"
121 printf "Return value: %s\\n" "$RETVAL"
122 printf "Dissector bug: %s\\n" "$DISSECTOR_BUG"
123 if [ "$VALGRIND" -eq 1 ] ; then
124 printf "Valgrind error count: %s\\n" "$VG_ERR_CNT"
127 printf "Date and time: %s\\n" "$( date --utc )"
129 SINCE_HOURS=48
130 if [ -d "${GIT_DIR:-.git}" ] ; then
131 printf "\\nCommits in the last %s hours:\\n" $SINCE_HOURS
132 git --no-pager log --oneline --no-decorate --since=${SINCE_HOURS}hours
133 printf "\\n"
136 printf "Build host information:\\n"
137 uname -srvm
138 lsb_release -a 2> /dev/null
139 printf "\\n"
141 } > "$TMP_DIR/${ERR_FILE}.header"
143 # Trim the stderr output if needed
144 ERR_SIZE=$(du -sk $TMP_DIR/$ERR_FILE | awk '{ print $1 }')
145 if [ $ERR_SIZE -ge 5000 ] ; then
146 mv $TMP_DIR/$ERR_FILE $TMP_DIR/${ERR_FILE}.full
147 head -n 2000 $TMP_DIR/${ERR_FILE}.full > $TMP_DIR/$ERR_FILE
148 echo -e "\n\n[ Output removed ]\n\n" >> $TMP_DIR/$ERR_FILE
149 tail -n 2000 $TMP_DIR/${ERR_FILE}.full >> $TMP_DIR/$ERR_FILE
150 rm -f $TMP_DIR/${ERR_FILE}.full
153 cat $TMP_DIR/${ERR_FILE} >> $TMP_DIR/${ERR_FILE}.header
154 mv $TMP_DIR/${ERR_FILE}.header $TMP_DIR/${ERR_FILE}
156 echo -e "stderr follows:\n"
157 cat $TMP_DIR/$ERR_FILE
159 exit 255