diff --git a/CHANGES b/CHANGES index 83fd9d5f5a..c693829b91 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +2.6-beta2-43 | 2018-10-19 11:15:44 -0500 + + * Improve scripts/base/utils/dir unit test (Jon Siwek, Corelight) + 2.6-beta2-42 | 2018-10-18 10:21:01 -0500 * Fix documentation link for notice_alarm.log fields (Jon Siwek, Corelight) diff --git a/VERSION b/VERSION index dfc98289cd..ee7812dccc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.6-beta2-42 +2.6-beta2-43 diff --git a/testing/btest/Baseline/scripts.base.utils.dir/bro..stdout b/testing/btest/Baseline/scripts.base.utils.dir/bro..stdout index c3103b7f64..7c6067601e 100644 --- a/testing/btest/Baseline/scripts.base.utils.dir/bro..stdout +++ b/testing/btest/Baseline/scripts.base.utils.dir/bro..stdout @@ -1,10 +1,5 @@ -new_file1, ../testdir/bye -new_file1, ../testdir/hi -new_file1, ../testdir/howsitgoing -new_file2, ../testdir/bye -new_file2, ../testdir/hi -new_file2, ../testdir/howsitgoing -new_file1, ../testdir/bye -new_file1, ../testdir/newone -new_file2, ../testdir/bye -new_file2, ../testdir/newone +initial file, ../testdir/hi +initial file, ../testdir/howsitgoing +initial file, ../testdir/bye +new_file, ../testdir/newone +new_file, ../testdir/bye diff --git a/testing/btest/scripts/base/utils/dir.test b/testing/btest/scripts/base/utils/dir.test index 76ec5d4fb5..4cbb4a3c89 100644 --- a/testing/btest/scripts/base/utils/dir.test +++ b/testing/btest/scripts/base/utils/dir.test @@ -1,6 +1,12 @@ # @TEST-EXEC: btest-bg-run bro bro -b ../dirtest.bro -# @TEST-EXEC: btest-bg-wait 15 -# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff bro/.stdout +# @TEST-EXEC: $SCRIPTS/wait-for-file bro/next1 10 || (btest-bg-wait -k 1 && false) +# @TEST-EXEC: touch testdir/newone +# @TEST-EXEC: rm testdir/bye +# @TEST-EXEC: $SCRIPTS/wait-for-file bro/next2 10 || (btest-bg-wait -k 1 && false) +# @TEST-EXEC: touch testdir/bye +# @TEST-EXEC: btest-bg-wait 20 +# @TEST-EXEC: touch testdir/newone +# @TEST-EXEC: btest-diff bro/.stdout @TEST-START-FILE dirtest.bro @@ -9,43 +15,41 @@ redef exit_only_after_terminate = T; global c: count = 0; -function check_terminate_condition() - { - c += 1; +global initial_files: set[string] = set(); - if ( c == 10 ) +function check_initial_file(s: string) + { + if ( s in initial_files ) + print "initial file", s; + else + print "didn't see initial file", s; + } + +function new_file(fname: string) + { + ++c; + + if ( c <= 3 ) + add initial_files[fname]; + else + print "new_file", fname; + + if ( c == 3 ) + { + check_initial_file("../testdir/hi"); + check_initial_file("../testdir/howsitgoing"); + check_initial_file("../testdir/bye"); + system("touch next1"); + } + else if ( c == 4 ) + system("touch next2"); + else if ( c == 5 ) terminate(); } -function new_file1(fname: string) - { - print "new_file1", fname; - check_terminate_condition(); - } - -function new_file2(fname: string) - { - print "new_file2", fname; - check_terminate_condition(); - } - -event change_things() - { - system("touch ../testdir/newone"); - system("rm ../testdir/bye"); - } - -event change_things2() - { - system("touch ../testdir/bye"); - } - event bro_init() { - Dir::monitor("../testdir", new_file1, .5sec); - Dir::monitor("../testdir", new_file2, 1sec); - schedule 3sec { change_things() }; - schedule 6sec { change_things2() }; + Dir::monitor("../testdir", new_file, .25sec); } @TEST-END-FILE