Improve an input framework unit test

This commit is contained in:
Jon Siwek 2018-07-17 17:51:13 -05:00
parent 1d1a63c16c
commit bf67076cdc
4 changed files with 38 additions and 56 deletions

View file

@ -1,4 +1,8 @@
2.5-746 | 2018-07-17 17:51:13 -0500
* Improve an input framework unit test (Jon Siwek, Corelight)
2.5-745 | 2018-07-17 16:46:16 -0500
* Add explicit key in Travis known_hosts (Jon Siwek, Corelight)

View file

@ -1 +1 @@
2.5-745
2.5-746

View file

@ -1,27 +1,9 @@
Input::EVENT_NEW
..:
F
Input::EVENT_NEW
bro
F
Input::EVENT_NEW
out
F
Input::EVENT_NEW
stderr.bro
F
Input::EVENT_NEW
stderr output contained nonexistant
T
Input::EVENT_NEW
stderr output contained nonexistant
T
Input::EVENT_NEW
stderr output contained nonexistant
T
done
End of Data event
input
Process finished event
input
Exit code != 0
Input::EVENT_NEW line output (stderr=F): ../mydir:
Input::EVENT_NEW line output (stderr=F): a
Input::EVENT_NEW line output (stderr=F): b
Input::EVENT_NEW line output (stderr=F): c
Input::EVENT_NEW line output (stderr=T): <stderr output contained nonexistant>
Input::EVENT_NEW line output (stderr=T): <stderr output contained nonexistant>
Input::EVENT_NEW line output (stderr=T): <stderr output contained nonexistant>
End of Data event, input
Process finished event, input, T

View file

@ -1,3 +1,4 @@
# @TEST-EXEC: mkdir mydir && touch mydir/a && touch mydir/b && touch mydir/c
# @TEST-EXEC: btest-bg-run bro bro -b %INPUT
# @TEST-EXEC: btest-bg-wait 10
# @TEST-EXEC: btest-diff out
@ -9,64 +10,59 @@ type Val: record {
is_stderr: bool;
};
global try: count;
global try = 0;
global n = 0;
global outfile: file;
event line(description: Input::EventDescription, tpe: Input::Event, s: string, is_stderr: bool)
{
print outfile, tpe;
local line_output = fmt("%s line output (stderr=%s): ", tpe, is_stderr);
if ( is_stderr )
{
# work around localized error messages. and if some localization does not include the filename... well... that would be bad :)
if ( strstr(s, "nonexistant") > 0 )
{
print outfile, "stderr output contained nonexistant";
}
line_output += "<stderr output contained nonexistant>";
else
line_output += "<unexpected/weird error localization>";
}
else
{
print outfile, s;
}
print outfile, is_stderr;
line_output += s;
try = try + 1;
if ( try == 7 )
{
print outfile, "done";
Input::remove("input");
}
print outfile, line_output;
++try;
if ( n == 2 && try == 7 )
terminate();
}
global n = 0;
event Input::end_of_data(name: string, source:string)
{
print outfile, "End of Data event";
print outfile, name;
print outfile, "End of Data event", name;
++n;
if ( n == 2 )
if ( n == 2 && try == 7 )
terminate();
}
event InputRaw::process_finished(name: string, source:string, exit_code:count, signal_exit:bool)
{
print outfile, "Process finished event";
print outfile, name;
if ( exit_code != 0 )
print outfile, "Exit code != 0";
print outfile, "Process finished event", name, exit_code != 0;
++n;
if ( n == 2 )
if ( n == 2 && try == 7 )
terminate();
}
event bro_init()
{
local config_strings: table[string] of string = {
["read_stderr"] = "1"
};
outfile = open("../out");
try = 0;
Input::add_event([$source="ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |", $reader=Input::READER_RAW, $name="input", $fields=Val, $ev=line, $want_record=F, $config=config_strings, $mode=Input::STREAM]);
Input::add_event([$source="ls ../mydir ../nonexistant ../nonexistant2 ../nonexistant3 |",
$reader=Input::READER_RAW, $name="input",
$fields=Val, $ev=line, $want_record=F,
$config=config_strings, $mode=Input::STREAM]);
}