3 # Run the Lua API unit tests
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
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.
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.
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.
23 wslua_step_dir_test() {
24 if [ $HAVE_LUA -ne 0 ]; then
29 # Tshark catches lua script failures, so we have to parse the output.
30 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/dir.lua > testout.txt 2>&1
31 if grep -q "All tests passed!" testout.txt; then
35 test_step_failed "didn't find pass marker"
39 wslua_step_dissector_test() {
40 if [ $HAVE_LUA -ne 0 ]; then
45 # First run tshark with the dissector script.
46 $TSHARK -r $CAPTURE_DIR/dns_port.pcap -V -X lua_script:$TESTS_DIR/lua/dissector.lua > testin.txt 2>&1
48 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
51 test_step_failed "subtest-1 exit status of $DUT: $RETURNVALUE"
55 # then run tshark again with the verification script. (it internally reads in testin.txt)
56 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/verify_dissector.lua > testout.txt 2>&1
57 grep -q "All tests passed!" testout.txt
61 test_step_failed "subtest-1 didn't find pass marker"
64 # run tshark with the dissector script again, but in mode 2.
65 $TSHARK -r $CAPTURE_DIR/dns_port.pcap -V -X lua_script:$TESTS_DIR/lua/dissector.lua -X lua_script1:heur_regmode=2 > testin.txt 2>&1
67 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
70 test_step_failed "subtest-2 exit status of $DUT: $RETURNVALUE"
74 # then run tshark again with the verification script. (it internally reads in testin.txt)
75 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/verify_dissector.lua -X lua_script1:no_heur > testout.txt 2>&1
76 grep -q "All tests passed!" testout.txt
80 test_step_failed "subtest-2 didn't find pass marker"
83 # run tshark with the dissector script again, but in mode 3.
84 $TSHARK -r $CAPTURE_DIR/dns_port.pcap -V -X lua_script:$TESTS_DIR/lua/dissector.lua -X lua_script1:heur_regmode=3 > testin.txt 2>&1
86 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
89 test_step_failed "subtest-3 exit status of $DUT: $RETURNVALUE"
93 # then run tshark again with the verification script. (it internally reads in testin.txt)
94 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/verify_dissector.lua -X lua_script1:no_heur > testout.txt 2>&1
95 grep -q "All tests passed!" testout.txt
99 test_step_failed "subtest-3 didn't find pass marker"
104 -r $CAPTURE_DIR/segmented_fpm.pcap
105 -X lua_script:$TESTS_DIR/lua/dissectFPM.lua
113 # run tshark with the FPM dissector script, enabling dissect_tcp_pdus().
114 $TSHARK $FPM_ARGS -o fpm.dissect_tcp:true > testin.txt 2>&1
116 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
119 test_step_failed "subtest-4a exit status of $DUT: $RETURNVALUE"
123 # run tshark with the FPM dissector script, disabling dissect_tcp_pdus().
124 $TSHARK $FPM_ARGS -o fpm.dissect_tcp:false > testout.txt 2>&1
126 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
129 test_step_failed "subtest-4b exit status of $DUT: $RETURNVALUE"
133 # now compare the two files - they should be identical
134 if diff -q ./testin.txt ./testout.txt; then
142 test_step_failed "subtest-4 the new and old tcp dissection methods differed"
146 wslua_step_field_test() {
147 if [ $HAVE_LUA -ne 0 ]; then
152 # Tshark catches lua script failures, so we have to parse the output.
153 $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/field.lua > testout.txt 2>&1
154 if grep -q "All tests passed!" testout.txt; then
158 test_step_failed "didn't find pass marker"
162 wslua_step_file_test() {
163 if [ $HAVE_LUA -ne 0 ]; then
168 # First run tshark with the pcap_file_reader script.
169 $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/pcap_file.lua > testin.txt 2>&1
170 $TSHARK -r $CAPTURE_DIR/wpa-Induction.pcap.gz -X lua_script:$TESTS_DIR/lua/pcap_file.lua >> testin.txt 2>&1
172 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
175 test_step_failed "subtest-1 exit status of $DUT: $RETURNVALUE"
179 # then run tshark again without the script
180 $TSHARK -r $CAPTURE_DIR/dhcp.pcap > testout.txt 2>&1
181 $TSHARK -r $CAPTURE_DIR/wpa-Induction.pcap.gz >> testout.txt 2>&1
183 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
186 test_step_failed "subtest-2 exit status of $DUT: $RETURNVALUE"
190 # now compare the two files - they should be identical
191 if diff -q ./testin.txt ./testout.txt; then
197 test_step_failed "subtest-3 reading the pcap file with Lua did not match internal"
201 # Now generate a new capture file using the Lua writer.
202 $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/pcap_file.lua -w testin.txt -F lua_pcap2 > testout.txt 2>&1
204 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
207 test_step_failed "subtest-4 exit status of $DUT: $RETURNVALUE"
211 # now compare the two files - they should be identical
212 if diff -q $CAPTURE_DIR/dhcp.pcap ./testin.txt; then
217 test_step_failed "subtest-5 creating a new pcap file using Lua did not match dhcp.cap"
221 # Now read an acme sipmsg.log using the acme Lua reader, writing it out as pcapng.
222 $TSHARK -r $CAPTURE_DIR/sipmsg.log -X lua_script:$TESTS_DIR/lua/acme_file.lua -w testin.txt -F pcapng > testout.txt 2>&1
224 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
227 test_step_failed "subtest-6 exit status of $DUT: $RETURNVALUE"
231 # testin.txt is now a pcapng, read it out using -V verbose into testout.txt
232 $TSHARK -r ./testin.txt -V > testout.txt 2>&1
234 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
237 test_step_failed "subtest-7 exit status of $DUT: $RETURNVALUE"
241 # now readout sip.pcapng into testin.txt using -V verbose
242 $TSHARK -r $CAPTURE_DIR/sip.pcapng -V > testin.txt 2>&1
244 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
247 test_step_failed "subtest-8 exit status of $DUT: $RETURNVALUE"
251 # now compare testin and testout - they should be identical
252 if diff -q ./testout.txt ./testin.txt; then
257 diff ./testout.txt ./testin.txt
258 test_step_failed "subtest-9 writing the acme sipmsg.log out as pcapng did not match sip.pcapng"
262 wslua_step_listener_test() {
263 if [ $HAVE_LUA -ne 0 ]; then
268 # Tshark catches lua script failures, so we have to parse the output.
269 $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/listener.lua > testout.txt 2>&1
270 if grep -q "All tests passed!" testout.txt; then
274 test_step_failed "didn't find pass marker"
278 wslua_step_nstime_test() {
279 if [ $HAVE_LUA -ne 0 ]; then
284 # Tshark catches lua script failures, so we have to parse the output.
285 $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/nstime.lua > testout.txt 2>&1
286 if grep -q "All tests passed!" testout.txt; then
290 test_step_failed "didn't find pass marker"
294 wslua_step_pinfo_test() {
295 if [ $HAVE_LUA -ne 0 ]; then
300 # Tshark catches lua script failures, so we have to parse the output.
301 $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/pinfo.lua > testout.txt 2>&1
302 if grep -q "All tests passed!" testout.txt; then
306 test_step_failed "didn't find pass marker"
311 wslua_step_proto_test() {
312 if [ $HAVE_LUA -ne 0 ]; then
317 # First run tshark with the proto script.
318 $TSHARK -r $CAPTURE_DIR/dns_port.pcap -V -X lua_script:$TESTS_DIR/lua/proto.lua > testin.txt 2>&1
319 grep -q "All tests passed!" testin.txt
320 if [ $? -ne 0 ]; then
322 test_step_failed "didn't find pass marker"
325 # then run tshark again with the verification script. (it internally reads in testin.txt)
326 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/verify_dissector.lua > testout.txt 2>&1
327 if grep -q "All tests passed!" testout.txt; then
333 test_step_failed "didn't find pass marker"
337 wslua_step_int64_test() {
338 if [ $HAVE_LUA -ne 0 ]; then
343 # Tshark catches lua script failures, so we have to parse the output.
344 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/int64.lua > testout.txt 2>&1
345 if grep -q "All tests passed!" testout.txt; then
350 test_step_failed "didn't find pass marker"
354 wslua_step_args_test() {
355 if [ $HAVE_LUA -ne 0 ]; then
360 # Tshark catches lua script failures, so we have to parse the output.
361 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/script_args.lua -X lua_script1:1 > testout.txt 2>&1
362 grep -q "All tests passed!" testout.txt
363 if [ $? -ne 0 ]; then
365 test_step_failed "lua_args_test test 1 failed"
367 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/script_args.lua -X lua_script1:3 -X lua_script1:foo -X lua_script1:bar > testout.txt 2>&1
368 grep -q "All tests passed!" testout.txt
369 if [ $? -ne 0 ]; then
371 test_step_failed "lua_args_test test 2 failed"
373 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/script_args.lua -X lua_script:$TESTS_DIR/lua/script_args.lua -X lua_script1:3 -X lua_script2:1 -X lua_script1:foo -X lua_script1:bar > testout.txt 2>&1
374 grep -q "All tests passed!" testout.txt
375 if [ $? -ne 0 ]; then
377 test_step_failed "lua_args_test test 3 failed"
379 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/script_args.lua > testout.txt 2>&1
380 if grep -q "All tests passed!" testout.txt; then
382 test_step_failed "lua_args_test negative test 4 failed"
384 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/script_args.lua -X lua_script1:3 > testout.txt 2>&1
385 if grep -q "All tests passed!" testout.txt; then
387 test_step_failed "lua_args_test negative test 5 failed"
392 wslua_step_globals_test() {
393 if [ $HAVE_LUA -ne 0 ]; then
398 # Tshark catches lua script failures, so we have to parse the output.
399 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/verify_globals.lua -X lua_script1:$TESTS_DIR/lua/ -X lua_script1:$TESTS_DIR/lua/globals_2.2.txt > testout.txt 2>&1
400 grep -q "All tests passed!" testout.txt
401 if [ $? -ne 0 ]; then
403 test_step_failed "lua_globals_test test 1 failed"
408 wslua_step_gregex_test() {
409 if [ $HAVE_LUA -ne 0 ]; then
414 # Tshark catches lua script failures, so we have to parse the output.
415 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/gregex.lua -X lua_script1:-d$TESTS_DIR/lua/ -X lua_script1:glib -X lua_script1:-V > testout.txt 2>&1
416 if grep -q "All tests passed!" testout.txt; then
420 test_step_failed "didn't find pass marker"
424 wslua_step_struct_test() {
425 if [ $HAVE_LUA -ne 0 ]; then
430 # Tshark catches lua script failures, so we have to parse the output.
431 $TSHARK -r $CAPTURE_DIR/empty.pcap -X lua_script:$TESTS_DIR/lua/struct.lua > testout.txt 2>&1
432 if grep -q "All tests passed!" testout.txt; then
436 test_step_failed "didn't find pass marker"
440 wslua_step_tvb_test() {
441 if [ $HAVE_LUA -ne 0 ]; then
446 # Tshark catches lua script failures, so we have to parse the output.
447 # perform this twice: once with a tree, once without
448 $TSHARK -r $CAPTURE_DIR/dns_port.pcap -X lua_script:$TESTS_DIR/lua/tvb.lua -V > testout.txt 2>&1
449 grep -q "All tests passed!" testout.txt
450 if [ $? -ne 0 ]; then
452 test_step_failed "lua_args_test test 1 failed"
455 $TSHARK -r $CAPTURE_DIR/dns_port.pcap -X lua_script:$TESTS_DIR/lua/tvb.lua > testout.txt 2>&1
456 if grep -q "All tests passed!" testout.txt; then
460 test_step_failed "didn't find pass marker"
464 wslua_cleanup_step() {
470 test_step_set_pre wslua_cleanup_step
471 test_step_set_post wslua_cleanup_step
472 test_step_add "wslua dir" wslua_step_dir_test
473 test_step_add "wslua dissector" wslua_step_dissector_test
474 test_step_add "wslua field/fieldinfo" wslua_step_field_test
475 test_step_add "wslua file" wslua_step_file_test
476 test_step_add "wslua globals" wslua_step_globals_test
477 test_step_add "wslua gregex" wslua_step_gregex_test
478 test_step_add "wslua int64" wslua_step_int64_test
479 test_step_add "wslua listener" wslua_step_listener_test
480 test_step_add "wslua nstime" wslua_step_nstime_test
481 test_step_add "wslua pinfo" wslua_step_pinfo_test
482 test_step_add "wslua proto/protofield" wslua_step_proto_test
483 test_step_add "wslua script arguments" wslua_step_args_test
484 test_step_add "wslua struct" wslua_step_struct_test
485 test_step_add "wslua tvb" wslua_step_tvb_test
488 # Editor modelines - https://www.wireshark.org/tools/modelines.html
493 # indent-tabs-mode: t
496 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
497 # :indentSize=8:tabSize=8:noTabs=false: