Changes to how script coverage integrates with test suites.

- BRO_PROFILER_FILE now passes .X* templated filenames to mkstemp
  for generating unique coverage state files.  All test suites
  now use this so each Bro instance writes to a unique coverage file.
- Rearranging Makefile targets.  The general rule is that if the
  all/brief target fails out due to a test failure, then the dependent
  coverage target won't run, but can still be invoked directly later.
  (e.g. make brief || make coverage)
This commit is contained in:
Jon Siwek 2012-03-01 13:00:44 -06:00
parent 92ed583ee7
commit ef5e9caaf4
8 changed files with 56 additions and 17 deletions

View file

@ -1,4 +1,5 @@
#include <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
#include "Brofiler.h"
@ -48,7 +49,38 @@ bool Brofiler::WriteStats()
char* bf = getenv("BRO_PROFILER_FILE");
if ( ! bf ) return false;
FILE* f = fopen(bf, "w");
bool gen_unique = false;
const char* p = strstr(bf, ".X");
if ( p )
{
gen_unique = true;
while ( *(++p) )
{
if ( *p != 'X' )
{
gen_unique = false;
break;
}
}
}
FILE* f;
if ( gen_unique )
{
int fd = mkstemp(bf);
if ( fd == -1 )
{
reporter->Error("Failed to generate unique file name from BRO_PROFILER_FILE: %s\n", bf);
return false;
}
f = fdopen(fd, "w");
}
else
{
f = fopen(bf, "w");
}
if ( ! f )
{
reporter->Error("Failed to open BRO_PROFILER_FILE destination '%s' for writing\n", bf);

View file

@ -26,7 +26,9 @@ public:
/**
* Combines usage stats from current run with any read from ReadStats(),
* then writes information to file pointed to by environment variable
* BRO_PROFILER_FILE.
* BRO_PROFILER_FILE. If the value of that env. variable ends with
* ".XXXX" (any amount of X's), then it is first passed through mkstemp
* to get a unique file.
*
* @return: true when usage info is written, otherwise false.
*/

View file

@ -12,6 +12,7 @@ make-brief:
@for repo in $(DIRS); do (cd $$repo && make brief ); done
coverage:
@for repo in $(DIRS); do (cd $$repo && echo "Coverage for '$$repo' dir:" && make coverage); done
@test -f btest/coverage.log && cp btest/coverage.log `mktemp brocov.tmp.XXX` || true
@for f in external/*/coverage.log; do test -f $$f && cp $$f `mktemp brocov.tmp.XXX` || true; done
@echo "Complete test suite code coverage:"

View file

@ -2,16 +2,23 @@
DIAG=diag.log
BTEST=../../aux/btest/btest
all: cleanup
# Showing all tests.
@$(BTEST) -f $(DIAG)
@../scripts/coverage-calc ".tmp/script-coverage*" coverage.log `pwd`/../../scripts
all: cleanup btest-verbose coverage
brief: cleanup
# Brief output showing only failed tests.
# Showing all tests.
btest-verbose:
@$(BTEST) -f $(DIAG)
brief: cleanup btest-brief coverage
# Brief output showing only failed tests.
btest-brief:
@$(BTEST) -b -f $(DIAG)
coverage:
@../scripts/coverage-calc ".tmp/script-coverage*" coverage.log `pwd`/../../scripts
cleanup:
@rm -f $(DIAG)
@rm -f .tmp/script-coverage*
.PHONY: all btest-verbose brief btest-brief coverage cleanup

View file

@ -18,4 +18,4 @@ DIST=%(testbase)s/../..
BUILD=%(testbase)s/../../build
TEST_DIFF_CANONIFIER=$SCRIPTS/diff-canonifier
TMPDIR=%(testbase)s/.tmp
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage.XXXX

View file

@ -24,3 +24,7 @@ push:
status:
@for repo in $(REPOS); do ( cd $$repo && echo '>>' $$repo && git status -bs && echo ); done
coverage:
@for repo in $(REPOS); do (cd $$repo && echo "Coverage for '$$repo' repo:" && make coverage); done
.PHONY: all brief init pull push status coverage

View file

@ -17,4 +17,4 @@ TRACES=%(testbase)s/Traces
SCRIPTS=%(testbase)s/../scripts
DIST=%(testbase)s/../../..
BUILD=%(testbase)s/../../../build
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage.XXXX

View file

@ -1,7 +0,0 @@
#! /usr/bin/env bash
# This is a wrapper script to btest's real btest-bg-run. It's used
# when collecting Bro script coverage statistics so that two independent
# Bro processing don't try to write those usage statistics to the same file.
BRO_PROFILER_FILE=`mktemp $TMPDIR/script-coverage.XXXX` $BTEST_PATH/btest-bg-run $@