mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00

When Bro was compiled with broker disabled, then some Bro scripts were referencing functions and types that were not defined. Fixed by adding @ifdefs to several scripts. Removed one @ifdef because it was causing several unit tests to fail. Also fixed the @TEST-REQUIRES check in tests that rely on broker so that such tests are skipped when broker is disabled.
83 lines
2 KiB
Text
83 lines
2 KiB
Text
# @TEST-SERIALIZE: brokercomm
|
|
# @TEST-REQUIRES: grep -q ENABLE_BROKER:BOOL=true $BUILD/CMakeCache.txt
|
|
|
|
# @TEST-EXEC: btest-bg-run recv "bro -b ../recv.bro broker_port=$BROKER_PORT >recv.out"
|
|
# @TEST-EXEC: btest-bg-run send "bro -b ../send.bro broker_port=$BROKER_PORT >send.out"
|
|
|
|
# @TEST-EXEC: btest-bg-wait 20
|
|
# @TEST-EXEC: btest-diff recv/recv.out
|
|
# @TEST-EXEC: btest-diff send/send.out
|
|
|
|
@TEST-START-FILE recv.bro
|
|
|
|
const broker_port: port &redef;
|
|
redef exit_only_after_terminate = T;
|
|
|
|
event bro_init()
|
|
{
|
|
Broker::enable();
|
|
Broker::subscribe_to_prints("bro/print/");
|
|
Broker::listen(broker_port, "127.0.0.1");
|
|
}
|
|
|
|
global messages_to_recv = 6;
|
|
global messages_sent = 0;
|
|
global messages_recv = 0;
|
|
|
|
event Broker::print_handler(msg: string)
|
|
{
|
|
++messages_recv;
|
|
print "got print msg", msg;
|
|
|
|
if ( messages_to_recv == messages_recv )
|
|
{
|
|
terminate();
|
|
return;
|
|
}
|
|
|
|
Broker::send_print("bro/print/my_topic", fmt("pong %d", messages_sent));
|
|
++messages_sent;
|
|
}
|
|
|
|
@TEST-END-FILE
|
|
|
|
@TEST-START-FILE send.bro
|
|
|
|
const broker_port: port &redef;
|
|
redef exit_only_after_terminate = T;
|
|
|
|
event bro_init()
|
|
{
|
|
Broker::enable();
|
|
Broker::subscribe_to_prints("bro/print/my_topic");
|
|
Broker::connect("127.0.0.1", broker_port, 1secs);
|
|
}
|
|
|
|
global messages_sent = 0;
|
|
global messages_recv = 0;
|
|
global peer_disconnected = F;
|
|
|
|
event Broker::outgoing_connection_established(peer_address: string,
|
|
peer_port: port,
|
|
peer_name: string)
|
|
{
|
|
print "Broker::outgoing_connection_established", peer_address, peer_port;
|
|
Broker::send_print("bro/print/hi", fmt("ping %d", messages_sent));
|
|
++messages_sent;
|
|
}
|
|
|
|
event Broker::outgoing_connection_broken(peer_address: string,
|
|
peer_port: port)
|
|
{
|
|
terminate();
|
|
}
|
|
|
|
event Broker::print_handler(msg: string)
|
|
{
|
|
++messages_recv;
|
|
print "got print msg", msg;
|
|
Broker::send_print("bro/print/hi", fmt("ping %d", messages_sent));
|
|
++messages_sent;
|
|
}
|
|
|
|
@TEST-END-FILE
|