diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-03-19 12:14:09 -0400 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2014-03-19 17:02:40 +0000 |
commit | c8a98f37ec300b522a732c349a7d3f0c17b7168d (patch) | |
tree | 6eedd23e705a4f8b801850cf782281de206fac52 | |
parent | a68e3a410c210e798aa9c96c03ef5cc075f19ca9 (diff) |
Fix lua file testsuite not working and weak heuristic readers not being registered
The testsuite for Lua file reader/writer uses the acme_file.lua script to
generate a pcapng file from an Acme sipmsg.log file. It then compares the
tshark verbose output of this new pcapng file to a sip.pcapng file in
the test/captures directory that was previously made. Unfortunately, the
acme_file.lua script generates a timestamp based on local system timezone,
rather than UTC, so the testsuite fails if not run in the EST timezone where
the sip.pcapng file was originally made. This has now been fixed.
Also, trying to register new weak heuristic readers fails because the GArray
is terminated with a NULL-based row without Glib knowing about that. So this
commit changes it to let Glib handle the NULL-terminated row, so that appending
takes it into account automatically.
Change-Id: I037ce1cfbda03585b3a1e159df78ff8ebb41fc32
Reviewed-on: https://code.wireshark.org/review/741
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
-rw-r--r-- | test/captures/sip.pcapng | bin | 3696 -> 3696 bytes | |||
-rw-r--r-- | test/lua/acme_file.lua | 19 | ||||
-rw-r--r-- | test/lua/pcap_file.lua | 4 | ||||
-rwxr-xr-x | test/suite-wslua.sh | 19 | ||||
-rw-r--r-- | wiretap/file_access.c | 3 |
5 files changed, 32 insertions, 13 deletions
diff --git a/test/captures/sip.pcapng b/test/captures/sip.pcapng Binary files differindex 58373b9aa5..78610491c5 100644 --- a/test/captures/sip.pcapng +++ b/test/captures/sip.pcapng diff --git a/test/lua/acme_file.lua b/test/lua/acme_file.lua index 8eeaea5473..29a325e1d2 100644 --- a/test/lua/acme_file.lua +++ b/test/lua/acme_file.lua @@ -196,6 +196,10 @@ if DEBUG or DEBUG2 then end end +-- this should be done as a preference setting +local ALWAYS_UDP = true + + local fh = FileHandler.new("Oracle Acme Packet logs", "acme", "A file reader for Oracle Acme Packet message logs such as sipmsg.log","rs") @@ -323,6 +327,14 @@ end -- monthlist table for getting month number value from 3-char name (number is table index) local monthlist = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} +-- Compute the difference in seconds between local time and UTC +-- from http://lua-users.org/wiki/TimeZone +local function get_timezone() + local now = os.time() + return os.difftime(now, os.time(os.date("!*t", now))) +end +local timezone = get_timezone() + local function get_timestamp(line, file_position, seeking) local i, line_pos, month, day, hour, min, sec, milli = line:find(header_time_pattern) if not month then @@ -387,6 +399,8 @@ local function get_timestamp(line, file_position, seeking) dprint("timestamp conversion failed") end + timet = timet + timezone + -- make an NSTime statics.nstime = NSTime(timet, milli * 1000000) packets[file_position][TTIME] = statics.nstime @@ -1192,6 +1206,11 @@ local function parse_header(file, line, file_position, seeking) ttype = UDP end + -- override above decisions based on configuration + if ALWAYS_UDP then + ttype = UDP + end + direction = get_direction(direction) if direction == nil then dprint("parse_header: failed to convert direction") diff --git a/test/lua/pcap_file.lua b/test/lua/pcap_file.lua index 3f3367880d..ca684e318b 100644 --- a/test/lua/pcap_file.lua +++ b/test/lua/pcap_file.lua @@ -64,7 +64,7 @@ local ENCAP_TYPE = wtap.UNKNOWN ---------------------------------------- -- The read_open() is called by Wireshark once per file, to see if the file is this reader's type. --- Wireshark passes in a File object to this function +-- Wireshark passes in (1) a File object and (2) CaptureInfo object to this function -- It expects in return either nil or false to mean it's not our file type, or true if it is -- In our case what this means is we figure out if the file has the magic header, and get the -- endianess of the file, and the encapsulation type of its frames/records @@ -181,7 +181,7 @@ end ---------------------------------------- -- ok, so let's create a FileHandler object -local fh = FileHandler.new("Lua-based PCAP reader", "lua_pcap", "A Lua-based file reader for PCAP-type files","rs") +local fh = FileHandler.new("Lua-based PCAP reader", "lua_pcap", "A Lua-based file reader for PCAP-type files","rms") -- set above functions to the FileHandler fh.read_open = read_open diff --git a/test/suite-wslua.sh b/test/suite-wslua.sh index 0b8fc4e339..a3b14f8091 100755 --- a/test/suite-wslua.sh +++ b/test/suite-wslua.sh @@ -79,7 +79,7 @@ wslua_step_file_test() { if [ ! $RETURNVALUE -eq $EXIT_OK ]; then echo cat ./testin.txt - test_step_failed "exit status of $DUT: $RETURNVALUE" + test_step_failed "subtest-1 exit status of $DUT: $RETURNVALUE" return fi @@ -90,7 +90,7 @@ wslua_step_file_test() { if [ ! $RETURNVALUE -eq $EXIT_OK ]; then echo cat ./testout.txt - test_step_failed "exit status of $DUT: $RETURNVALUE" + test_step_failed "subtest-2 exit status of $DUT: $RETURNVALUE" return fi @@ -101,7 +101,7 @@ wslua_step_file_test() { echo cat ./testin.txt cat ./testout.txt - test_step_failed "reading the pcap file with Lua did not match internal" + test_step_failed "subtest-3 reading the pcap file with Lua did not match internal" fi # Now generate a new capture file using the Lua writer. @@ -110,7 +110,7 @@ wslua_step_file_test() { if [ ! $RETURNVALUE -eq $EXIT_OK ]; then echo cat ./testout.txt - test_step_failed "exit status of $DUT: $RETURNVALUE" + test_step_failed "subtest-4 exit status of $DUT: $RETURNVALUE" return fi @@ -120,7 +120,7 @@ wslua_step_file_test() { else echo cat ./testout.txt - test_step_failed "writing the pcap out as Lua did not match dhcp.cap" + test_step_failed "subtest-5 creating a new pcap file using Lua did not match dhcp.cap" fi # Now read an acme sipmsg.log using the acme Lua reader, writing it out as pcapng. @@ -129,7 +129,7 @@ wslua_step_file_test() { if [ ! $RETURNVALUE -eq $EXIT_OK ]; then echo cat ./testout.txt - test_step_failed "exit status of $DUT: $RETURNVALUE" + test_step_failed "subtest-6 exit status of $DUT: $RETURNVALUE" return fi @@ -139,7 +139,7 @@ wslua_step_file_test() { if [ ! $RETURNVALUE -eq $EXIT_OK ]; then echo cat ./testout.txt - test_step_failed "exit status of $DUT: $RETURNVALUE" + test_step_failed "subtest-7 exit status of $DUT: $RETURNVALUE" return fi @@ -149,7 +149,7 @@ wslua_step_file_test() { if [ ! $RETURNVALUE -eq $EXIT_OK ]; then echo cat ./testin.txt - test_step_failed "exit status of $DUT: $RETURNVALUE" + test_step_failed "subtest-8 exit status of $DUT: $RETURNVALUE" return fi @@ -159,7 +159,8 @@ wslua_step_file_test() { else echo cat ./testout.txt - test_step_failed "writing the acme sipmsg.log out as pcapng did not match sip.pcapng" + diff ./testout.txt ./testin.txt + test_step_failed "subtest-9 writing the acme sipmsg.log out as pcapng did not match sip.pcapng" fi } diff --git a/wiretap/file_access.c b/wiretap/file_access.c index b43a11ede9..816ae66065 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -368,7 +368,6 @@ static struct open_info open_info_base[] = { /* Extremely weak heuristics - put them at the end. */ { "VWR", OPEN_INFO_HEURISTIC, vwr_open, "vwr", NULL }, { "Camins", OPEN_INFO_HEURISTIC, camins_open, "camins", NULL }, - { NULL, 0, NULL, NULL, NULL } }; /* this is only used to build the dynamic array on load, do NOT use this @@ -405,7 +404,7 @@ void init_open_routines(void) { if (open_info_arr) return; - open_info_arr = g_array_new(FALSE,TRUE,sizeof(struct open_info)); + open_info_arr = g_array_new(TRUE,TRUE,sizeof(struct open_info)); g_array_append_vals(open_info_arr, open_info_base, N_OPEN_INFO_ROUTINES); |