aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite-wslua.sh
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2014-03-18 13:21:51 -0400
committerAnders Broman <a.broman58@gmail.com>2014-03-19 05:04:54 +0000
commit04d950130624c14ac8af39c621f69851d8088ed6 (patch)
treeec315eb356b27def24a385b7b5aa8bdf72529b11 /test/suite-wslua.sh
parentd832cb18db4e152177cf13673385288987ba9448 (diff)
Add capture file reader/writer support for Lua so scripts can implement new capture file formats.
This enables a Lua script to implement a brand new capture file format reader/writer, so that for example one could write a script to read from vendor-specific "logs" of packets, and show them as normal packets in wireshark. Change-Id: Id394edfffa94529f39789844c382b7ab6cc2d814 Reviewed-on: https://code.wireshark.org/review/431 Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Reviewed-by: Michael Mann <mmann78@netscape.net> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'test/suite-wslua.sh')
-rwxr-xr-xtest/suite-wslua.sh98
1 files changed, 98 insertions, 0 deletions
diff --git a/test/suite-wslua.sh b/test/suite-wslua.sh
index fa682b08d3..0b8fc4e339 100755
--- a/test/suite-wslua.sh
+++ b/test/suite-wslua.sh
@@ -66,6 +66,103 @@ wslua_step_field_test() {
fi
}
+wslua_step_file_test() {
+ if [ $HAVE_LUA -ne 0 ]; then
+ test_step_skipped
+ return
+ fi
+
+ # First run tshark with the pcap_file_reader script.
+ $TSHARK -r $CAPTURE_DIR/dhcp.pcap -X lua_script:$TESTS_DIR/lua/pcap_file.lua > testin.txt 2>&1
+ $TSHARK -r $CAPTURE_DIR/wpa-Induction.pcap.gz -X lua_script:$TESTS_DIR/lua/pcap_file.lua >> testin.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ echo
+ cat ./testin.txt
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ return
+ fi
+
+ # then run tshark again without the script
+ $TSHARK -r $CAPTURE_DIR/dhcp.pcap > testout.txt 2>&1
+ $TSHARK -r $CAPTURE_DIR/wpa-Induction.pcap.gz >> testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ echo
+ cat ./testout.txt
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ return
+ fi
+
+ # now compare the two files - they should be identical
+ if diff -q ./testin.txt ./testout.txt; then
+ rm ./testin.txt
+ else
+ echo
+ cat ./testin.txt
+ cat ./testout.txt
+ test_step_failed "reading the pcap file with Lua did not match internal"
+ fi
+
+ # Now generate a new capture file using the Lua writer.
+ $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
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ echo
+ cat ./testout.txt
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ return
+ fi
+
+ # now compare the two files - they should be identical
+ if diff -q $CAPTURE_DIR/dhcp.pcap ./testin.txt; then
+ rm ./testin.txt
+ else
+ echo
+ cat ./testout.txt
+ test_step_failed "writing the pcap out as Lua did not match dhcp.cap"
+ fi
+
+ # Now read an acme sipmsg.log using the acme Lua reader, writing it out as pcapng.
+ $TSHARK -r $CAPTURE_DIR/sipmsg.log -X lua_script:$TESTS_DIR/lua/acme_file.lua -w testin.txt -F pcapng > testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ echo
+ cat ./testout.txt
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ return
+ fi
+
+ # testin.txt is now a pcapng, read it out using -V verbose into testout.txt
+ $TSHARK -r ./testin.txt -V > testout.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ echo
+ cat ./testout.txt
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ return
+ fi
+
+ # now readout sip.pcapng into testin.txt using -V verbose
+ $TSHARK -r $CAPTURE_DIR/sip.pcapng -V > testin.txt 2>&1
+ RETURNVALUE=$?
+ if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
+ echo
+ cat ./testin.txt
+ test_step_failed "exit status of $DUT: $RETURNVALUE"
+ return
+ fi
+
+ # now compare testin and testout - they should be identical
+ if diff -q ./testout.txt ./testin.txt; then
+ test_step_ok
+ else
+ echo
+ cat ./testout.txt
+ test_step_failed "writing the acme sipmsg.log out as pcapng did not match sip.pcapng"
+ fi
+}
+
wslua_step_listener_test() {
if [ $HAVE_LUA -ne 0 ]; then
test_step_skipped
@@ -260,6 +357,7 @@ wslua_suite() {
test_step_set_post wslua_cleanup_step
test_step_add "wslua dissector" wslua_step_dissector_test
test_step_add "wslua field/fieldinfo" wslua_step_field_test
+ test_step_add "wslua file" wslua_step_file_test
test_step_add "wslua globals" wslua_step_globals_test
test_step_add "wslua gregex" wslua_step_gregex_test
test_step_add "wslua int64" wslua_step_int64_test