mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 11:08:20 +00:00
Add more tests for previously-untested BIFs
This commit is contained in:
parent
94e850397b
commit
03aee9197d
28 changed files with 272 additions and 2 deletions
3
testing/btest/Baseline/bifs.all_set/out
Normal file
3
testing/btest/Baseline/bifs.all_set/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
F
|
||||
F
|
||||
T
|
3
testing/btest/Baseline/bifs.any_set/out
Normal file
3
testing/btest/Baseline/bifs.any_set/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
T
|
||||
F
|
||||
F
|
2
testing/btest/Baseline/bifs.clear_table/out
Normal file
2
testing/btest/Baseline/bifs.clear_table/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
1
|
||||
0
|
1
testing/btest/Baseline/bifs.exit/out
Normal file
1
testing/btest/Baseline/bifs.exit/out
Normal file
|
@ -0,0 +1 @@
|
|||
hello
|
3
testing/btest/Baseline/bifs.getsetenv/out
Normal file
3
testing/btest/Baseline/bifs.getsetenv/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
OK
|
||||
OK
|
||||
OK
|
6
testing/btest/Baseline/bifs.length/out
Normal file
6
testing/btest/Baseline/bifs.length/out
Normal file
|
@ -0,0 +1,6 @@
|
|||
1
|
||||
4
|
||||
2
|
||||
0
|
||||
0
|
||||
0
|
|
@ -2,3 +2,5 @@ f97c5d29941bfb1b2fdab0874906ab82
|
|||
7b0391feb2e0cd271f1cf39aafb4376f
|
||||
f97c5d29941bfb1b2fdab0874906ab82
|
||||
7b0391feb2e0cd271f1cf39aafb4376f
|
||||
571c0a35c7858ad5a0e16b8fdb41adcd
|
||||
1751cbd623726f423f734e23a8c7ec06
|
||||
|
|
6
testing/btest/Baseline/bifs.rand/out
Normal file
6
testing/btest/Baseline/bifs.rand/out
Normal file
|
@ -0,0 +1,6 @@
|
|||
185
|
||||
236
|
||||
805
|
||||
47
|
||||
996
|
||||
498
|
4
testing/btest/Baseline/bifs.resize/out
Normal file
4
testing/btest/Baseline/bifs.resize/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
5
|
||||
0
|
||||
7
|
2
testing/btest/Baseline/bifs.sort/out
Normal file
2
testing/btest/Baseline/bifs.sort/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
[5, 3, 8]
|
||||
[3, 5, 8]
|
1
testing/btest/Baseline/bifs.system/out
Normal file
1
testing/btest/Baseline/bifs.system/out
Normal file
|
@ -0,0 +1 @@
|
|||
thistest
|
1
testing/btest/Baseline/bifs.system_env/out
Normal file
1
testing/btest/Baseline/bifs.system_env/out
Normal file
|
@ -0,0 +1 @@
|
|||
helloworld
|
2
testing/btest/Baseline/bifs.val_size/out
Normal file
2
testing/btest/Baseline/bifs.val_size/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
72
|
||||
72
|
15
testing/btest/bifs/all_set.bro
Normal file
15
testing/btest/bifs/all_set.bro
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = vector( T, F, T );
|
||||
print all_set(a);
|
||||
|
||||
local b = vector();
|
||||
print all_set(b);
|
||||
|
||||
local c = vector( T );
|
||||
print all_set(c);
|
||||
}
|
15
testing/btest/bifs/any_set.bro
Normal file
15
testing/btest/bifs/any_set.bro
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = vector( F, T, F );
|
||||
print any_set(a);
|
||||
|
||||
local b = vector();
|
||||
print any_set(b);
|
||||
|
||||
local c = vector( F );
|
||||
print any_set(c);
|
||||
}
|
14
testing/btest/bifs/clear_table.bro
Normal file
14
testing/btest/bifs/clear_table.bro
Normal file
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT > out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local mytable: table[string] of string = { ["key1"] = "val1" };
|
||||
|
||||
print |mytable|;
|
||||
|
||||
clear_table(mytable);
|
||||
|
||||
print |mytable|;
|
||||
}
|
9
testing/btest/bifs/exit.bro
Normal file
9
testing/btest/bifs/exit.bro
Normal file
|
@ -0,0 +1,9 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out || test $? -eq 7
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
print "hello";
|
||||
exit(7);
|
||||
}
|
20
testing/btest/bifs/getsetenv.bro
Normal file
20
testing/btest/bifs/getsetenv.bro
Normal file
|
@ -0,0 +1,20 @@
|
|||
#
|
||||
# @TEST-EXEC: TESTBRO=testvalue bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = getenv("NOTDEFINED");
|
||||
local b = getenv("TESTBRO");
|
||||
if ( |a| == 0 )
|
||||
print "OK";
|
||||
if ( b == "testvalue" )
|
||||
print "OK";
|
||||
|
||||
if ( setenv("NOTDEFINED", "now defined" ) == T )
|
||||
{
|
||||
if ( getenv("NOTDEFINED") == "now defined" )
|
||||
print "OK";
|
||||
}
|
||||
|
||||
}
|
22
testing/btest/bifs/length.bro
Normal file
22
testing/btest/bifs/length.bro
Normal file
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT > out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local mytable: table[string] of string = { ["key1"] = "val1" };
|
||||
local myset: set[count] = set( 3, 6, 2, 7 );
|
||||
local myvec: vector of string = vector( "value1", "value2" );
|
||||
|
||||
print length(mytable);
|
||||
print length(myset);
|
||||
print length(myvec);
|
||||
|
||||
mytable = table();
|
||||
myset = set();
|
||||
myvec = vector();
|
||||
|
||||
print length(mytable);
|
||||
print length(myset);
|
||||
print length(myvec);
|
||||
}
|
|
@ -14,3 +14,6 @@ md5_hash_update("b", "three");
|
|||
|
||||
print md5_hash_finish("a");
|
||||
print md5_hash_finish("b");
|
||||
|
||||
print md5_hmac("one");
|
||||
print md5_hmac("one", "two", "three");
|
||||
|
|
18
testing/btest/bifs/order.bro
Normal file
18
testing/btest/bifs/order.bro
Normal file
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
function myfunc(a: count, b: count): bool
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = vector( 5, 3, 8 );
|
||||
|
||||
print order(a, myfunc);
|
||||
|
||||
print a;
|
||||
|
||||
}
|
|
@ -5,8 +5,10 @@
|
|||
|
||||
global cmds = "print \"hello world\";";
|
||||
cmds = string_cat(cmds, "\nprint \"foobar\";");
|
||||
piped_exec("bro", cmds);
|
||||
if ( piped_exec("bro", cmds) != T )
|
||||
exit(1);
|
||||
|
||||
# Test null output.
|
||||
piped_exec("cat > test.txt", "\x00\x00hello\x00\x00");
|
||||
if ( piped_exec("cat > test.txt", "\x00\x00hello\x00\x00") != T )
|
||||
exit(1);
|
||||
|
||||
|
|
24
testing/btest/bifs/rand.bro
Normal file
24
testing/btest/bifs/rand.bro
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = rand(1000);
|
||||
local b = rand(1000);
|
||||
local c = rand(1000);
|
||||
|
||||
print a;
|
||||
print b;
|
||||
print c;
|
||||
|
||||
srand(575);
|
||||
|
||||
local d = rand(1000);
|
||||
local e = rand(1000);
|
||||
local f = rand(1000);
|
||||
|
||||
print d;
|
||||
print e;
|
||||
print f;
|
||||
}
|
26
testing/btest/bifs/resize.bro
Normal file
26
testing/btest/bifs/resize.bro
Normal file
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = vector( 5, 3, 8 );
|
||||
|
||||
print |a|;
|
||||
|
||||
if ( resize(a, 5) != 3 )
|
||||
exit(1);
|
||||
|
||||
print |a|;
|
||||
|
||||
if ( resize(a, 0) != 5 )
|
||||
exit(1);
|
||||
|
||||
print |a|;
|
||||
|
||||
if ( resize(a, 7) != 0 )
|
||||
exit(1);
|
||||
|
||||
print |a|;
|
||||
|
||||
}
|
18
testing/btest/bifs/sort.bro
Normal file
18
testing/btest/bifs/sort.bro
Normal file
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
function myfunc(a: count, b: count): bool
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = vector( 5, 3, 8 );
|
||||
|
||||
print sort(a, myfunc);
|
||||
|
||||
print a;
|
||||
|
||||
}
|
15
testing/btest/bifs/system.bro
Normal file
15
testing/btest/bifs/system.bro
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = system("echo thistest > out");
|
||||
if ( a != 0 )
|
||||
exit(1);
|
||||
|
||||
local b = system("");
|
||||
if ( b == 0 )
|
||||
exit(1);
|
||||
|
||||
}
|
21
testing/btest/bifs/system_env.bro
Normal file
21
testing/btest/bifs/system_env.bro
Normal file
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local vars: table[string] of string = { ["TESTBRO"] = "helloworld" };
|
||||
|
||||
# make sure the env. variable is not set
|
||||
local myvar = getenv("TESTBRO");
|
||||
if ( |myvar| != 0 )
|
||||
exit(1);
|
||||
|
||||
local a = system_env("echo $TESTBRO > out", vars);
|
||||
if ( a != 0 )
|
||||
exit(1);
|
||||
|
||||
myvar = getenv("TESTBRO");
|
||||
if ( |myvar| != 0 )
|
||||
exit(1);
|
||||
}
|
12
testing/btest/bifs/val_size.bro
Normal file
12
testing/btest/bifs/val_size.bro
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT > out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = 1;
|
||||
local b = T;
|
||||
|
||||
print val_size(a);
|
||||
print val_size(b);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue