mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 19:18:19 +00:00
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:
parent
92ed583ee7
commit
ef5e9caaf4
8 changed files with 56 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "Brofiler.h"
|
#include "Brofiler.h"
|
||||||
|
@ -48,7 +49,38 @@ bool Brofiler::WriteStats()
|
||||||
char* bf = getenv("BRO_PROFILER_FILE");
|
char* bf = getenv("BRO_PROFILER_FILE");
|
||||||
if ( ! bf ) return false;
|
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 )
|
if ( ! f )
|
||||||
{
|
{
|
||||||
reporter->Error("Failed to open BRO_PROFILER_FILE destination '%s' for writing\n", bf);
|
reporter->Error("Failed to open BRO_PROFILER_FILE destination '%s' for writing\n", bf);
|
||||||
|
|
|
@ -26,7 +26,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Combines usage stats from current run with any read from ReadStats(),
|
* Combines usage stats from current run with any read from ReadStats(),
|
||||||
* then writes information to file pointed to by environment variable
|
* 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.
|
* @return: true when usage info is written, otherwise false.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,6 +12,7 @@ make-brief:
|
||||||
@for repo in $(DIRS); do (cd $$repo && make brief ); done
|
@for repo in $(DIRS); do (cd $$repo && make brief ); done
|
||||||
|
|
||||||
coverage:
|
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
|
@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
|
@for f in external/*/coverage.log; do test -f $$f && cp $$f `mktemp brocov.tmp.XXX` || true; done
|
||||||
@echo "Complete test suite code coverage:"
|
@echo "Complete test suite code coverage:"
|
||||||
|
|
|
@ -2,16 +2,23 @@
|
||||||
DIAG=diag.log
|
DIAG=diag.log
|
||||||
BTEST=../../aux/btest/btest
|
BTEST=../../aux/btest/btest
|
||||||
|
|
||||||
all: cleanup
|
all: cleanup btest-verbose coverage
|
||||||
# Showing all tests.
|
|
||||||
@$(BTEST) -f $(DIAG)
|
|
||||||
@../scripts/coverage-calc ".tmp/script-coverage*" coverage.log `pwd`/../../scripts
|
|
||||||
|
|
||||||
brief: cleanup
|
# Showing all tests.
|
||||||
# Brief output showing only failed tests.
|
btest-verbose:
|
||||||
|
@$(BTEST) -f $(DIAG)
|
||||||
|
|
||||||
|
brief: cleanup btest-brief coverage
|
||||||
|
|
||||||
|
# Brief output showing only failed tests.
|
||||||
|
btest-brief:
|
||||||
@$(BTEST) -b -f $(DIAG)
|
@$(BTEST) -b -f $(DIAG)
|
||||||
|
|
||||||
|
coverage:
|
||||||
@../scripts/coverage-calc ".tmp/script-coverage*" coverage.log `pwd`/../../scripts
|
@../scripts/coverage-calc ".tmp/script-coverage*" coverage.log `pwd`/../../scripts
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@rm -f $(DIAG)
|
@rm -f $(DIAG)
|
||||||
@rm -f .tmp/script-coverage*
|
@rm -f .tmp/script-coverage*
|
||||||
|
|
||||||
|
.PHONY: all btest-verbose brief btest-brief coverage cleanup
|
||||||
|
|
|
@ -18,4 +18,4 @@ DIST=%(testbase)s/../..
|
||||||
BUILD=%(testbase)s/../../build
|
BUILD=%(testbase)s/../../build
|
||||||
TEST_DIFF_CANONIFIER=$SCRIPTS/diff-canonifier
|
TEST_DIFF_CANONIFIER=$SCRIPTS/diff-canonifier
|
||||||
TMPDIR=%(testbase)s/.tmp
|
TMPDIR=%(testbase)s/.tmp
|
||||||
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage
|
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage.XXXX
|
||||||
|
|
4
testing/external/Makefile
vendored
4
testing/external/Makefile
vendored
|
@ -24,3 +24,7 @@ push:
|
||||||
status:
|
status:
|
||||||
@for repo in $(REPOS); do ( cd $$repo && echo '>>' $$repo && git status -bs && echo ); done
|
@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
|
||||||
|
|
2
testing/external/subdir-btest.cfg
vendored
2
testing/external/subdir-btest.cfg
vendored
|
@ -17,4 +17,4 @@ TRACES=%(testbase)s/Traces
|
||||||
SCRIPTS=%(testbase)s/../scripts
|
SCRIPTS=%(testbase)s/../scripts
|
||||||
DIST=%(testbase)s/../../..
|
DIST=%(testbase)s/../../..
|
||||||
BUILD=%(testbase)s/../../../build
|
BUILD=%(testbase)s/../../../build
|
||||||
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage
|
BRO_PROFILER_FILE=%(testbase)s/.tmp/script-coverage.XXXX
|
||||||
|
|
|
@ -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 $@
|
|
Loading…
Add table
Add a link
Reference in a new issue