From 25e28c04f0e63922f30779e87328c5218596b22a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 25 Nov 2013 15:48:16 -0600 Subject: [PATCH] Add a Broxygen coverage test. --- scripts/broxygen/__load__.bro | 12 +++++++ .../Baseline/doc.broxygen.all_scripts/.stderr | 1 + .../Baseline/doc.broxygen.all_scripts/.stdout | 1 + testing/btest/coverage/broxygen.sh | 35 +++++++++++++++++++ testing/btest/doc/broxygen/all_scripts.test | 4 +++ 5 files changed, 53 insertions(+) create mode 100644 testing/btest/coverage/broxygen.sh diff --git a/scripts/broxygen/__load__.bro b/scripts/broxygen/__load__.bro index 68a0d878b6..70bf1cf2ef 100644 --- a/scripts/broxygen/__load__.bro +++ b/scripts/broxygen/__load__.bro @@ -1,2 +1,14 @@ @load test-all-policy.bro + +# Scripts which are commented out in test-all-policy.bro. +@load protocols/ssl/notary.bro +@load frameworks/communication/listen.bro +@load frameworks/control/controllee.bro +@load frameworks/control/controller.bro + @load ./example.bro + +event bro_init() + { + terminate(); + } diff --git a/testing/btest/Baseline/doc.broxygen.all_scripts/.stderr b/testing/btest/Baseline/doc.broxygen.all_scripts/.stderr index e69de29bb2..977e8fc37a 100644 --- a/testing/btest/Baseline/doc.broxygen.all_scripts/.stderr +++ b/testing/btest/Baseline/doc.broxygen.all_scripts/.stderr @@ -0,0 +1 @@ +received termination signal diff --git a/testing/btest/Baseline/doc.broxygen.all_scripts/.stdout b/testing/btest/Baseline/doc.broxygen.all_scripts/.stdout index bfc3c033df..f72022e359 100644 --- a/testing/btest/Baseline/doc.broxygen.all_scripts/.stdout +++ b/testing/btest/Baseline/doc.broxygen.all_scripts/.stdout @@ -1 +1,2 @@ +The '' control command is unknown. WARNING: No Site::local_nets have been defined. It's usually a good idea to define your local networks. diff --git a/testing/btest/coverage/broxygen.sh b/testing/btest/coverage/broxygen.sh new file mode 100644 index 0000000000..13bf24bce3 --- /dev/null +++ b/testing/btest/coverage/broxygen.sh @@ -0,0 +1,35 @@ +# This check piggy-backs on the test-all-policy.bro test, assuming that every +# loadable script is referenced there. The only additional check here is +# that the broxygen package should even load scripts that are commented +# out in test-all-policy.bro because the broxygen package is only loaded +# when generated documentation and will terminate has soon as bro_init +# is handled, even if a script will e.g. put Bro into listen mode or otherwise +# cause it to not terminate after scripts are parsed. + +# @TEST-EXEC: bash %INPUT $DIST/scripts/test-all-policy.bro $DIST/scripts/broxygen/__load__.bro + +error_count=0 + +error_msg() + { + error_count=$((error_count+1)) + echo "$@" 1>&2; + } + +if [ $# -ne 2 ]; then + print "incorrect arguments" + exit 1 +fi + +all_loads=$(egrep "#[[:space:]]*@load.*" $1 | sed 's/#[[:space:]]*@load[[:space:]]*//g') +broxygen_loads=$(egrep "@load.*" $2 | sed 's/@load[[:space:]]*//g') + +for f in $all_loads; do + echo "$broxygen_loads" | grep -q $f || error_msg "$f not loaded in broxygen/__load__.bro" +done + +if [ $error_count -gt 0 ]; then + exit 1; +fi + +exit 0 diff --git a/testing/btest/doc/broxygen/all_scripts.test b/testing/btest/doc/broxygen/all_scripts.test index 56bb5313bb..f4d9237adf 100644 --- a/testing/btest/doc/broxygen/all_scripts.test +++ b/testing/btest/doc/broxygen/all_scripts.test @@ -1,6 +1,10 @@ # This test is mostly just checking that there's no errors that result # from loading all scripts and generated docs for each. +# This must be serialized with communication tests because it does load +# listen.bro in order to document it. + +# @TEST-SERIALIZE: comm # @TEST-EXEC: bro -X broxygen.config broxygen # @TEST-EXEC: btest-diff .stdout # @TEST-EXEC: btest-diff .stderr