Run tests synchronously by default

Running tests in parallel (which is the default)
results in spurious failures in the `scm` git tests,
probably due to an undiagnosed race condition.

This change lets tests run serially by default,
but provides a flag `-p` (or `--parallel`)
which enables running them in parallel again.

It also adds a variable `test_flags`
which is passed to each test run,
and which can be set by running

    env test="-v" ./configure
This commit is contained in:
Martin Kühl
2016-01-04 09:31:41 +01:00
committed by Allan Odgaard
parent bbced5c3f3
commit 597a49015d
3 changed files with 15 additions and 11 deletions

View File

@@ -860,11 +860,11 @@ rule link_oak_test
description = Link test $out
rule run_test
command = $in && touch $out
command = $in $test_flags && touch $out
description = Run test $in
rule always_run_test
command = $in
command = $in $test_flags
description = Run test $in
rule skip_test

View File

@@ -139,7 +139,8 @@ static void write_usage (FILE* io)
fprintf(io, "Usage: %s [-b|--benchmark] [-m|--measure] [-r|--repeat] [-v|--verbose] [-h|--help] [-V|--version]\n", getprogname());
fprintf(io, "Options:\n");
fprintf(io, " -b/--benchmark Run benchmarks instead of tests.\n");
fprintf(io, " -m/--measure Measure time of each test. This disables concurrency.\n");
fprintf(io, " -m/--measure Measure time of each test.\n");
fprintf(io, " -p/--parallel Run tests in parallel.\n");
fprintf(io, " -r/--repeat <n> Number of times to repeat each test/benchmark.\n");
fprintf(io, " -v/--verbose Be verbose.\n");
fprintf(io, " -h/--help Show this help.\n");
@@ -152,6 +153,7 @@ int main (int argc, char const* argv[])
{
{ "benchmark", no_argument, 0, 'b' },
{ "measure", no_argument, 0, 'm' },
{ "parallel", no_argument, 0, 'p' },
{ "repeat", required_argument, 0, 'r' },
{ "verbose", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
@@ -160,18 +162,20 @@ int main (int argc, char const* argv[])
};
bool measure = false;
bool parallel = false;
bool run_benchmarks = false;
bool verbose = false;
size_t repeat = 1;
unsigned int ch;
while((ch = getopt_long(argc, (char* const*)argv, "bmr:vhV", options, NULL)) != -1)
while((ch = getopt_long(argc, (char* const*)argv, "bmpr:vhV", options, NULL)) != -1)
{
extern char* optarg;
switch(ch)
{
case 'b': run_benchmarks = true; break;
case 'm': measure = true; break;
case 'p': parallel = true; break;
case 'r': repeat = atoi(optarg); break;
case 'v': verbose = true; break;
case 'h': write_usage(stdout); return 0;
@@ -221,17 +225,17 @@ int main (int argc, char const* argv[])
if(!run_benchmarks)
{
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if(measure)
{
for(auto test : tests)
test.execute(measure, repeat);
}
else
if(parallel)
{
dispatch_apply(tests.size(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t n){
tests[n].execute(measure, repeat);
});
}
else
{
for(auto test : tests)
test.execute(measure, repeat);
}
});
}

2
configure vendored
View File

@@ -93,7 +93,7 @@ done
mkdir -p "$builddir/Frameworks/SoftwareUpdate/fixtures"
DST=$(cd >/dev/null "$builddir/Frameworks/SoftwareUpdate/fixtures"; pwd) make -C Frameworks/SoftwareUpdate/fixtures
bin/gen_build -o build.ninja -C "$builddir" -dAPP_NAME="$name" -dAPP_VERSION="$ver" -dAPP_MIN_OS="$min_os" -dCC="$CC" -dCXX="$CXX" -didentity="$identity" -drest_api="$rest_api" -dbzip2_flag="$bzip2_flag" -dcapnp_prefix="$capnp_prefix" -dlibressl_prefix="$libressl_prefix" target
bin/gen_build -o build.ninja -C "$builddir" -dAPP_NAME="$name" -dAPP_VERSION="$ver" -dAPP_MIN_OS="$min_os" -dCC="$CC" -dCXX="$CXX" -didentity="$identity" -drest_api="$rest_api" -dbzip2_flag="$bzip2_flag" -dtest_flags="$test" -dcapnp_prefix="$capnp_prefix" -dlibressl_prefix="$libressl_prefix" target
ninja Frameworks/encoding/src/frequencies.capnp.h
ninja Frameworks/plist/src/cache.capnp.h