diff --git a/CHANGES b/CHANGES index 5eb9d2dec0..0f05f4fb59 100644 --- a/CHANGES +++ b/CHANGES @@ -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) diff --git a/VERSION b/VERSION index 46f8a42564..fcd1315f19 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.5-745 +2.5-746 diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.raw.stderr/out b/testing/btest/Baseline/scripts.base.frameworks.input.raw.stderr/out index b7f857339d..65d0c26ab4 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.input.raw.stderr/out +++ b/testing/btest/Baseline/scripts.base.frameworks.input.raw.stderr/out @@ -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): +Input::EVENT_NEW line output (stderr=T): +Input::EVENT_NEW line output (stderr=T): +End of Data event, input +Process finished event, input, T diff --git a/testing/btest/scripts/base/frameworks/input/raw/stderr.bro b/testing/btest/scripts/base/frameworks/input/raw/stderr.bro index 8e3fcefe41..8ff4cc7f1b 100644 --- a/testing/btest/scripts/base/frameworks/input/raw/stderr.bro +++ b/testing/btest/scripts/base/frameworks/input/raw/stderr.bro @@ -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 += ""; + else + line_output += ""; } 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]); }