mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Add memory leak unit test for "hook" function flavor.
This commit is contained in:
parent
e0fb9eb2b2
commit
c8d64b5028
1 changed files with 78 additions and 0 deletions
78
testing/btest/core/leaks/hook.bro
Normal file
78
testing/btest/core/leaks/hook.bro
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
# Needs perftools support.
|
||||||
|
#
|
||||||
|
# @TEST-GROUP: leaks
|
||||||
|
#
|
||||||
|
# @TEST-REQUIRES: bro --help 2>&1 | grep -q mem-leaks
|
||||||
|
#
|
||||||
|
# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local bro -m -b -r $TRACES/wikipedia.trace %INPUT
|
||||||
|
|
||||||
|
type rec: record {
|
||||||
|
a: count;
|
||||||
|
b: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
global myhook: hook(r: rec);
|
||||||
|
global myhook2: hook(s: string);
|
||||||
|
# a hook doesn't have to take any arguments
|
||||||
|
global myhook4: hook();
|
||||||
|
|
||||||
|
hook myhook(r: rec) &priority=5
|
||||||
|
{
|
||||||
|
print "myhook, &priority=5", r;
|
||||||
|
# break statement short-circuits the hook handling chain.
|
||||||
|
break;
|
||||||
|
print "ERROR: break statement should return from hook handler body";
|
||||||
|
}
|
||||||
|
|
||||||
|
hook myhook(r: rec)
|
||||||
|
{
|
||||||
|
# This handler shouldn't execute ever because of the handler at priority=5
|
||||||
|
# exiting the body from a "break" statement.
|
||||||
|
print "myhook, &priority=0", rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
hook myhook(r: rec) &priority=10
|
||||||
|
{
|
||||||
|
print "myhook, &priority=10", r;
|
||||||
|
# modifications to the record argument will be seen by remaining handlers.
|
||||||
|
r$a = 37;
|
||||||
|
r$b = "goobye world";
|
||||||
|
# returning from the handler early, is fine, remaining handlers still run.
|
||||||
|
return;
|
||||||
|
print "ERROR: break statement should return from hook handler body";
|
||||||
|
}
|
||||||
|
|
||||||
|
# hook function doesn't need a declaration, we can go straight to defining
|
||||||
|
# a handler body.
|
||||||
|
hook myhook3(i: count)
|
||||||
|
{
|
||||||
|
print "myhook3", i;
|
||||||
|
}
|
||||||
|
|
||||||
|
hook myhook4() &priority=1
|
||||||
|
{
|
||||||
|
print "myhook4", 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hook myhook4() &priority=2
|
||||||
|
{
|
||||||
|
print "myhook4", 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
event new_connection(c: connection)
|
||||||
|
{
|
||||||
|
print "new_connection", c$id;
|
||||||
|
|
||||||
|
hook myhook([$a=1156, $b="hello world"]);
|
||||||
|
|
||||||
|
# A hook with no handlers is fine, it's just a no-op.
|
||||||
|
hook myhook2("nope");
|
||||||
|
|
||||||
|
hook myhook3(8);
|
||||||
|
hook myhook4();
|
||||||
|
|
||||||
|
# A hook can be treated like other data types and doesn't have to be
|
||||||
|
# invoked directly by name.
|
||||||
|
local h = myhook;
|
||||||
|
hook h([$a=2, $b="it works"]);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue