Lua: Add some ProtoField tests.
[metze/wireshark/wip.git] / test / suite-unittests.sh
1 #!/bin/bash
2 #
3 # Run the epan unit tests
4 #
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #
22
23 unittests_step_test() {
24         $DUT $ARGS > testout.txt 2>&1
25         RETURNVALUE=$?
26         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
27                 echo
28                 cat ./testout.txt
29                 test_step_failed "exit status of $DUT: $RETURNVALUE"
30                 return
31         fi
32         test_step_ok
33 }
34
35 TOOL_SEARCH_PATHS="
36         $WS_BIN_PATH
37         $WS_BIN_PATH/epan
38         $SOURCE_DIR/epan
39         $WS_BIN_PATH/epan/wmem
40         $SOURCE_DIR/epan/wmem
41         $WS_BIN_PATH/tools
42         $SOURCE_DIR/tools
43 "
44
45 check_dut() {
46         TEST_EXE=""
47         # WS_BIN_PATH must be checked first, otherwise
48         # we'll find a non-functional program in epan or epan/wmem.
49         for TEST_PATH in $TOOL_SEARCH_PATHS ; do
50                 if [ -x "$TEST_PATH/$1" ]; then
51                         TEST_EXE=$TEST_PATH/$1
52                         break
53                 fi
54         done
55
56         if [ -n "$TEST_EXE" ]; then
57                 if [[ "$WS_SYSTEM" == "Windows" && "$TEST_EXE" == *.py ]] ; then
58                         SCRIPT_PATH=$( cygpath -w "$TEST_EXE" )
59                         TSHARK_PATH=$( cygpath -w "$TSHARK" )
60                         DUT="python $SCRIPT_PATH"
61                 else
62                         TSHARK_PATH="$TSHARK"
63                         DUT=$TEST_EXE
64                 fi
65         else
66                 test_step_failed "$1 not found. Have you built test-programs?"
67                 return 1
68         fi
69 }
70
71 unittests_step_exntest() {
72         check_dut exntest || return
73         ARGS=
74         unittests_step_test
75 }
76
77 unittests_step_oids_test() {
78         check_dut oids_test || return
79         ARGS=
80         unittests_step_test
81 }
82
83 unittests_step_reassemble_test() {
84         check_dut reassemble_test || return
85         ARGS=
86         unittests_step_test
87 }
88
89 unittests_step_tvbtest() {
90         check_dut tvbtest || return
91         ARGS=
92         unittests_step_test
93 }
94
95 unittests_step_wmem_test() {
96         check_dut wmem_test || return
97         ARGS=--verbose
98         unittests_step_test
99 }
100
101 unittests_step_ftsanity() {
102         check_dut ftsanity.py || return
103         ARGS=$TSHARK_PATH
104         unittests_step_test
105 }
106
107 unittests_step_fieldcount() {
108         check_dut tshark || return
109         ARGS="-G fieldcount"
110         unittests_step_test
111 }
112
113 unittests_cleanup_step() {
114         rm -f ./testout.txt
115 }
116
117 unittests_suite() {
118         test_step_set_pre unittests_cleanup_step
119         test_step_set_post unittests_cleanup_step
120         test_step_add "exntest" unittests_step_exntest
121         test_step_add "oids_test" unittests_step_oids_test
122         test_step_add "reassemble_test" unittests_step_reassemble_test
123         test_step_add "tvbtest" unittests_step_tvbtest
124         test_step_add "wmem_test" unittests_step_wmem_test
125         test_step_add "ftsanity.py" unittests_step_ftsanity
126         test_step_add "field count" unittests_step_fieldcount
127 }
128 #
129 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
130 #
131 # Local variables:
132 # sh-basic-offset: 8
133 # tab-width: 8
134 # indent-tabs-mode: t
135 # End:
136 #
137 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
138 # :indentSize=8:tabSize=8:noTabs=false:
139 #