diff --git a/testing/external/.gitignore b/testing/external/.gitignore index 2077736b5b..34fc39a267 100644 --- a/testing/external/.gitignore +++ b/testing/external/.gitignore @@ -1,3 +1,4 @@ *.git diag.log bro-testing +.proxy diff --git a/testing/external/README b/testing/external/README index 2cec89df4a..345c7a81ae 100644 --- a/testing/external/README +++ b/testing/external/README @@ -12,20 +12,28 @@ private traces. Initialization -------------- -Before the test-suite can be run, one needs to download the traces and -the corresponding test and baseline files. They are kept in a separate -git repository and a ``Makefile`` is provided to clone a copy: +Before the test-suite can be run, one needs to download the necessary +files. Test and baselines are kept in git repositories, while any +traces are download directly. A ``Makefile`` is provided to get +everything that's needed initially: .. console: > make init +If you need a proxy to download the traces, enter it into a file +``.proxy`` either in the top-level directory or inside one of the +repositories. + To later update to upstream changes: .. console: > make pull +This updates the tests and the traces as necessary. + + Running Tests ------------- @@ -53,7 +61,7 @@ To update a test's baseline, first run ``btest`` in update mode: .. console: > cd bro-testing - > btest -U tests/test-you-want-to-update + > btest -u tests/test-you-want-to-update Then use ``git`` to commit the changes and push the changes upstream as usual. @@ -63,20 +71,29 @@ Adding a Local Repository One can add local non-public set of tests (potentially using private traces) by creating a git repository of a similar structure as the -public one. A helper script is provided to set up such a repository: +public one. + +If you already have such a private test repository that you want to +include into the test suite, clone it directly into ````. + +If you want to create a new private repository, there's a helper +script to set that up: .. console: > ./scripts/create-new-repo The first argument is the local name of the repository (it will be -cloned into ````); and then second is the path to the git +cloned into ````); and the second is the URL of the git repository. The repository will be initialized with a few standard -directories as well as a skeleton test in ``/tests``. You -can then edit files as needed (and in particular add traces to -``/traces``). +directories as well as a skeleton test in ``/tests``. You can +then edit files as needed. You add trace files by editing +``Traces/traces.cfg``; see the comments in there. For each trace, you +also need to calculate a checksum with ``md5sum`` and put it into +``.md5sum``. The scripts use this to decide if they need to +redownload the trace. Accordingly, if you update a trace, make sure to +also recalculate its checksum. Note that the traces will be downloaded +to ``Traces/`` but must not be added to the git repostiory; there's a +``.gitignore`` installed to prevent that. -If you already have such a private test repository that you want to -include into the test suite, clone it directly into -````. diff --git a/testing/external/scripts/create-new-repo b/testing/external/scripts/create-new-repo index c9cc68d6a6..8c3bacc0ef 100755 --- a/testing/external/scripts/create-new-repo +++ b/testing/external/scripts/create-new-repo @@ -35,6 +35,7 @@ done ln -s ../subdir-btest.cfg ./btest.cfg cp $cwd/`dirname $0`/skel/test.skeleton tests +cp $cwd/`dirname $0`/skel/traces.cfg . cp $cwd/`dirname $0`/skel/Makefile . cp $cwd/`dirname $0`/skel/.gitignore . diff --git a/testing/external/scripts/skel/.gitignore b/testing/external/scripts/skel/.gitignore index d49f35423e..91bbaf9ec2 100644 --- a/testing/external/scripts/skel/.gitignore +++ b/testing/external/scripts/skel/.gitignore @@ -1 +1,3 @@ +Traces diag.log +.proxy diff --git a/testing/external/scripts/skel/Makefile b/testing/external/scripts/skel/Makefile index c535827937..7926c51532 100644 --- a/testing/external/scripts/skel/Makefile +++ b/testing/external/scripts/skel/Makefile @@ -2,10 +2,13 @@ DIAG=diag.log BTEST=../../../aux/btest/btest -all: +all: update-traces @rm -f $(DIAG) @$(BTEST) -f $(DIAG) -brief: +brief: update-traces @rm -f $(DIAG) @$(BTEST) -b -f $(DIAG) + +update-traces: + ../scripts/update-traces Traces diff --git a/testing/external/scripts/skel/traces.cfg b/testing/external/scripts/skel/traces.cfg new file mode 100644 index 0000000000..b3184cc7c2 --- /dev/null +++ b/testing/external/scripts/skel/traces.cfg @@ -0,0 +1,7 @@ +# +# Format: +# +# +# +# Use scripts/make-md5sum to calculate the md5sum. +# diff --git a/testing/external/scripts/update-traces b/testing/external/scripts/update-traces new file mode 100755 index 0000000000..fc1f515fff --- /dev/null +++ b/testing/external/scripts/update-traces @@ -0,0 +1,76 @@ +#! /usr/bin/env bash +# +# Downloads all traces as specified in /traces.cfg to directory $1. +# +# traces.cfg must consist of lines of the form " " + +if [ "$1" == "" ]; then + echo "usage: `basename $0` " + exit 1 +fi + +if [ ! -e $cfg ]; then + echo "No $cfg found." + exit 1 +fi + +cfg=traces.cfg + +for proxy in .proxy ../.proxy; do + if [ -e $proxy ]; then + proxy=`cat $proxy | head -1 | awk '{print $1}'` + echo Using proxy $proxy ... + proxy="ALL_PROXY=$proxy" + break + fi +done + +cat $cfg | while read line; do + + if echo $line | grep -q '^[ \t]*$'; then + continue + fi + + if echo $line | grep -q '^[ \t]*#'; then + continue + fi + + url=`echo $line | awk '{print $1}'` + auth=`echo $line | awk '{print $3}'` + + file=$1/`echo $url | sed 's#^.*/##g'` + fp=$file.md5sum + + if [ "$auth" != "" ]; then + auth="-u $auth" + fi + + # Get the fingerprint file. + if ! eval "$proxy curl $auth -fsS --anyauth $url.md5sum -o $fp.tmp"; then + echo "Error: Could not get $url.fingerprint, skipping download." + continue + fi + + download=0 + + if [ -e $fp ]; then + if ! cmp -s $fp $fp.tmp; then + download=1 + fi + else + download=1 + fi + + if [ "$download" = "1" ]; then + echo Getting $url ... + echo + eval "$proxy curl $auth -f --anyauth $url -o $file" + echo + mv $fp.tmp $fp + else + echo "`basename $file` already available." + fi + +done + +