aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRado Radoulov <rad0x6f@gmail.com>2017-04-27 13:06:24 -0400
committerPeter Wu <peter@lekensteyn.nl>2017-05-05 08:38:40 +0000
commitae8b18d6183538a4ffd5d18588be1b5e1a058206 (patch)
treee9b30127d9dfa9ac55d87fc1eb0cf4edcba89ffc /test
parentce8863c6efcee54655b7856002430bd1716a7776 (diff)
New Lua function TreeItem:referenced(ProtoField | Dissector).
This function returns TRUE/FALSE depending whether the specified ProtoField/Dissector needs to be dissected. By using this function in conjunction with the TreeItem.visible attribute, Lua dissectors can be significantly sped up by making less C interop calls which are relatively slow in terms of dissection especially when using sub-protocols where the dissection of an entire protocol can be skipped. Added tests for TreeItem:referenced to protofield.lua Change-Id: I44feacb91a2a5b0e3c28c0ccd8d6b04cccd67261 Reviewed-on: https://code.wireshark.org/review/21387 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test')
-rw-r--r--test/lua/protofield.lua16
-rwxr-xr-xtest/suite-wslua.sh27
2 files changed, 34 insertions, 9 deletions
diff --git a/test/lua/protofield.lua b/test/lua/protofield.lua
index c4026e5cf8..6b6110ddff 100644
--- a/test/lua/protofield.lua
+++ b/test/lua/protofield.lua
@@ -30,7 +30,7 @@ local function setFailed(name)
end
-- expected number of runs
-local taptests = { [OTHER]=28 }
+local taptests = { [OTHER]=32 }
local function getResults()
print("\n-----------------------------\n")
for k,v in pairs(taptests) do
@@ -70,6 +70,7 @@ end
local test_proto = Proto.new("test", "Test Proto")
test_proto.fields.time_field = ProtoField.uint16("test.time", "Time", base.UNIT_STRING, {" sec", " secs"})
test_proto.fields.dist_field = ProtoField.uint16("test.dist", "Distance", base.UNIT_STRING, {" km"})
+test_proto.fields.filtered_field = ProtoField.uint16("test.filtered", "Filtered Field", base.DEC)
-- Field name: empty, illegal, incompatible
success = pcall(ProtoField.int8, nil, "empty field name 1")
@@ -155,6 +156,19 @@ function test_proto.dissector(tvb, pinfo, tree)
test("Time: 65535 secs", ti.text == "Time: 65535 secs")
ti = tree:add(test_proto.fields.dist_field, tvb3())
test("Distance: 65535 km", ti.text == "Distance: 65535 km")
+
+ ti = tree:add(test_proto.fields.filtered_field, tvb2())
+ -- Note that this file should be loaded in tshark twice. Once with a visible
+ -- tree (-V) and once without a visible tree.
+ if tree.visible then
+ -- Tree is visible so both fields should be referenced
+ test("Visible tree: Time is referenced", tree:referenced(test_proto.fields.time_field) == true)
+ test("Visible tree: Filtered field is referenced", tree:referenced(test_proto.fields.filtered_field) == true)
+ else
+ -- Tree is not visible so only the field that appears in a filter should be referenced
+ test("Invisible tree: Time is NOT referenced", tree:referenced(test_proto.fields.time_field) == false)
+ test("Invisible tree: Filtered field is referenced", tree:referenced(test_proto.fields.filtered_field) == true)
+ end
end
DissectorTable.get("udp.port"):add(65333, test_proto)
diff --git a/test/suite-wslua.sh b/test/suite-wslua.sh
index c788a7d81c..20745f449a 100755
--- a/test/suite-wslua.sh
+++ b/test/suite-wslua.sh
@@ -340,14 +340,25 @@ wslua_step_protofield_test() {
return
fi
- # Tshark catches lua script failures, so we have to parse the output.
- $TSHARK -r $CAPTURE_DIR/dns_port.pcap -X lua_script:$TESTS_DIR/lua/protofield.lua -V > testout.txt 2>&1
- if grep -q "All tests passed!" testout.txt; then
- test_step_ok
- else
- cat testout.txt
- test_step_failed "didn't find pass marker"
- fi
+ # Tshark catches lua script failures, so we have to parse the output.
+ # Perform this twice: once with a tree, once without
+
+ # Pass 1 (visible tree)
+ $TSHARK -r $CAPTURE_DIR/dns_port.pcap -X lua_script:$TESTS_DIR/lua/protofield.lua -V -Y "test.filtered==1" > testout.txt 2>&1
+ grep -q "All tests passed!" testout.txt
+ if [ $? -ne 0 ]; then
+ cat testout.txt
+ test_step_failed "protofield_test: didn't find pass marker (pass 1)"
+ fi
+
+ # Pass 2 (invisible tree)
+ $TSHARK -r $CAPTURE_DIR/dns_port.pcap -X lua_script:$TESTS_DIR/lua/protofield.lua -Y "test.filtered==1" > testout.txt 2>&1
+ if grep -q "All tests passed!" testout.txt; then
+ test_step_ok
+ else
+ cat testout.txt
+ test_step_failed "protofield_test: didn't find pass marker (pass 2)"
+ fi
}
wslua_step_int64_test() {