Add btests for new functionality

- Expand language.set to cover sets of sets
- Expand language.table to cover tables indexed with tables
- Add language.table-nested-set-ordering to capture the reproducer from GHI-1753
This commit is contained in:
Christian Kreibich 2021-09-16 13:14:25 -07:00
parent 10e8d36340
commit cfcf1f83cc
7 changed files with 58 additions and 0 deletions

View file

@ -70,3 +70,8 @@ equality (FAIL)
non-equality (PASS) non-equality (PASS)
equality (FAIL) equality (FAIL)
magnitude (FAIL) magnitude (FAIL)
nested-set-add (PASS)
nested-set-add (PASS)
nested-set-add (PASS)
nested-set-del (PASS)
nested-set-in (PASS)

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[a={
SHA1,
MD5
}, b=12345678901234567890, c=<uninitialized>]

View file

@ -47,3 +47,5 @@ remove element (PASS)
!in operator (PASS) !in operator (PASS)
remove element (PASS) remove element (PASS)
!in operator (PASS) !in operator (PASS)
nested table addition (PASS)
nested table removal (PASS)

View file

@ -28,6 +28,8 @@ type r: record {
b: set[count]; b: set[count];
}; };
type s: set[set[count]];
global foo: set[r]; global foo: set[r];
global bar = set(1,3,5); global bar = set(1,3,5);

View file

@ -24,6 +24,7 @@ event zeek_init()
local s6: set[port, string, bool] = set(); local s6: set[port, string, bool] = set();
local s7: set[port, string, bool]; local s7: set[port, string, bool];
local s8 = set( [8/tcp, "type inference", T] ); local s8 = set( [8/tcp, "type inference", T] );
local s9: set[set[count]] = set();
# Type inference tests # Type inference tests
@ -181,5 +182,15 @@ event zeek_init()
test_case( "equality", a == a | set(5,11) ); test_case( "equality", a == a | set(5,11) );
test_case( "magnitude", |a_and_b| == |a_or_b|); test_case( "magnitude", |a_and_b| == |a_or_b|);
add s9[set(1,2,3)];
test_case( "nested-set-add", |s9| == 1 );
add s9[set(1,2,3)];
test_case( "nested-set-add", |s9| == 1 );
add s9[set(2,3,4)];
test_case( "nested-set-add", |s9| == 2 );
delete s9[set(1,2,3)];
test_case( "nested-set-del", |s9| == 1 );
test_case( "nested-set-in", set(2,3,4) in s9 );
} }

View file

@ -0,0 +1,25 @@
# This testcase used to cause subtle memory overflow problems due to deviating
# traversal order of the k$a set members. With 4.2, this will trigger an
# InternalError due to new bounds-checking. For context, see GHI-1753.
#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
type Key: record {
a: set[string];
b: string &optional;
c: string &optional;
};
global state: table[Key] of count = {};
event zeek_init() {
local k: Key;
k$a = set("MD5", "SHA1");
k$b = "12345678901234567890";
state[k] = 1;
print k;
}

View file

@ -29,6 +29,9 @@ event zeek_init()
local t11: table[conn_id, bool] of count = { local t11: table[conn_id, bool] of count = {
[ [$orig_h=1.1.1.1, $orig_p=1234/tcp, [ [$orig_h=1.1.1.1, $orig_p=1234/tcp,
$resp_h=2.2.2.2, $resp_p=4321/tcp], T ] = 42 }; $resp_h=2.2.2.2, $resp_p=4321/tcp], T ] = 42 };
local t12: table[table[count] of string] of string = {
[table([1] = "foo", [2] = "bar")] = "oh1"
};
# Type inference tests # Type inference tests
@ -159,5 +162,10 @@ event zeek_init()
delete t11[cid, T]; delete t11[cid, T];
test_case( "remove element", |t11| == 1 ); test_case( "remove element", |t11| == 1 );
test_case( "!in operator", [cid, T] !in t11 ); test_case( "!in operator", [cid, T] !in t11 );
t12[table([2] = "blum", [3] = "frub")] = "oh2";
test_case( "nested table addition", |t12| == 2 );
delete t12[table([1] = "foo", [2] = "bar")];
test_case( "nested table removal", |t12| == 1 );
} }