From f5a1786ea1cc96f3230c05a7f93b6242373f5ab9 Mon Sep 17 00:00:00 2001 From: Hadriel Kaplan Date: Thu, 6 Feb 2014 03:14:11 -0500 Subject: Add test suite for Lua dissector-related functions This isn't super-fancy, but it runs a simple protocol dissector and verifies the tshark output matches what it expects. Things like Proto, ProtoField, Field, Tvb, TvbRange, etc., are used in an example dissector script - it dissects DNS... partially. Enough to make sure things aren't fundamentally broken. This provides something to add on top of later as well. Change-Id: Icf3c8e9534944bcf4c4f6150f02a9a43f999cd75 Reviewed-on: https://code.wireshark.org/review/126 Reviewed-by: Alexis La Goutte Tested-by: Alexis La Goutte --- test/suite-unittests.sh | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/suite-unittests.sh') diff --git a/test/suite-unittests.sh b/test/suite-unittests.sh index f9e0c68561..4d713678e8 100755 --- a/test/suite-unittests.sh +++ b/test/suite-unittests.sh @@ -69,6 +69,34 @@ unittests_step_exntest() { unittests_step_test } +unittests_step_lua_dissector_test() { + if [ $HAVE_LUA -ne 0 ]; then + test_step_skipped + return + fi + + # First run tshark with the dissector script. + $TSHARK -r $CAPTURE_DIR/dns_port.pcap -V -X lua_script:$TESTS_DIR/lua/dissector.lua > testin.txt 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -eq $EXIT_OK ]; then + echo + cat ./testin_tmp.txt + test_step_failed "exit status of $DUT: $RETURNVALUE" + return + fi + + # then run tshark again with the verification script. (it internally reads in testin.txt) + $TSHARK -r $CAPTURE_DIR/dns_port.pcap -X lua_script:$TESTS_DIR/lua/verify_dissector.lua > testout.txt 2>&1 + if grep -q "All tests passed!" testout.txt; then + test_step_ok + else + echo + cat ./testin.txt + cat ./testout.txt + test_step_failed "didn't find pass marker" + fi +} + unittests_step_lua_int64_test() { if [ $HAVE_LUA -ne 0 ]; then test_step_skipped @@ -80,7 +108,8 @@ unittests_step_lua_int64_test() { if grep -q "All tests passed!" testout.txt; then test_step_ok else - cat testout.txt + echo + cat ./testout.txt test_step_failed "didn't find pass marker" fi } @@ -111,12 +140,14 @@ unittests_step_wmem_test() { unittests_cleanup_step() { rm -f ./testout.txt + rm -f ./testin.txt } unittests_suite() { test_step_set_pre unittests_cleanup_step test_step_set_post unittests_cleanup_step test_step_add "exntest" unittests_step_exntest + test_step_add "lua dissector" unittests_step_lua_dissector_test test_step_add "lua int64" unittests_step_lua_int64_test test_step_add "oids_test" unittests_step_oids_test test_step_add "reassemble_test" unittests_step_reassemble_test -- cgit v1.2.3