Add an initial "shellcheck" target.
[metze/wireshark/wip.git] / tools / test-captures.sh
1 #!/bin/bash
2
3 # A little script to run tshark on capture file[s] (potentially ones that
4 # failed fuzz testing). Useful because it sets up ulimits and other environment
5 # variables for you to ensure things like misused ephemeral memory are caught.
6 # (I'm writing this after having my machine hang up for like 15 minutes because
7 # I wasn't paying attention while tshark was running on a fuzzed capture and
8 # it used all my RAM + swap--which was pretty painful.)
9 #
10 # Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
11 #
12 # Wireshark - Network traffic analyzer
13 # By Gerald Combs <gerald@wireshark.org>
14 # Copyright 1998 Gerald Combs
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29
30 TEST_TYPE="manual"
31 # shellcheck source=tools/test-common.sh
32 . `dirname $0`/test-common.sh || exit 1
33
34 # Run under AddressSanitizer ?
35 ASAN=$CONFIGURED_WITH_ASAN
36
37 while getopts "ab:" OPTCHAR ; do
38     case $OPTCHAR in
39         a) ASAN=1 ;;
40         b) WIRESHARK_BIN_DIR=$OPTARG ;;
41     esac
42 done
43 shift $(($OPTIND - 1))
44
45 if [ $# -lt 1 ]
46 then
47         printf "Usage: $(basename $0) [-b bin_dir] /path/to/file[s].pcap\n"
48         exit 1
49 fi
50
51 ws_bind_exec_paths
52 ws_check_exec "$TSHARK"
53
54 # Set some limits to the child processes, e.g. stop it if it's running
55 # longer than MAX_CPU_TIME seconds. (ulimit is not supported well on
56 # cygwin - it shows some warnings - and the features we use may not all
57 # be supported on some UN*X platforms.)
58 ulimit -S -t $MAX_CPU_TIME
59
60 # Allow core files to be generated
61 ulimit -c unlimited
62
63 # Don't enable ulimit -v when using ASAN. See
64 # https://github.com/google/sanitizers/wiki/AddressSanitizer#ulimit--v
65 if [ $ASAN -eq 0 ]; then
66         ulimit -S -v $MAX_VMEM
67 fi
68
69 for file in "$@"
70 do
71         echo "Testing file $file..."
72         echo -n " - with tree... "
73         if $TSHARK -nVxr $file > /dev/null
74         then
75                 echo "OK"
76                 echo -n " - without tree... "
77                 if $WIRESHARK_BIN_DIR/tshark -nr $file > /dev/null
78                 then
79                         echo "OK"
80                         echo -n " - without tree but with a read filter... "
81                         if $WIRESHARK_BIN_DIR/tshark -Yframe -nr $file > /dev/null
82                         then
83                                 echo "OK"
84                         else
85                                 echo "Failed"
86                                 exit 1
87                         fi
88                 else
89                         echo "Failed"
90                         exit 1
91                 fi
92         else
93                 echo "Failed"
94                 exit 1
95         fi
96 done