1#!/bin/sh
2
3# Runs many iterations of run_net_test.sh in parallel processes, for the
4# purposes of finding flaky tests.
5
6if ! [[ $1 =~ ^[0-9]+$ ]] || ! [[ $2 =~ ^[0-9]+$ ]]; then
7  echo "Usage: $0 <workers> <runs_per_worker>" >&2
8  exit 1
9fi
10
11# A function run by every worker. Runs the tests <runs_per_worker> times.
12function runtests() {
13  local worker=$1
14  local runs=$2
15  local j=0
16  while ((j < runs)); do
17    $DIR/run_net_test.sh --readonly --builder --nobuild all_tests.sh \
18        > /dev/null 2> $RESULTSDIR/results.$worker.$j
19    j=$((j + 1))
20    echo -n "." >&2
21  done
22}
23
24WORKERS=$1
25RUNS=$2
26DIR=$(dirname $0)
27RESULTSDIR=$(mktemp --tmpdir -d net_test.parallel.XXXXXX)
28[ -z $RESULTSDIR ] && exit 1
29
30echo "Building kernel..." >&2
31$DIR/run_net_test.sh --norun
32
33echo "Running $WORKERS worker(s) with $RUNS test run(s) each..." >&2
34
35# Start all the workers.
36worker=0
37while ((worker < WORKERS)); do
38  runtests $worker $RUNS &
39  worker=$((worker + 1))
40done
41wait
42
43echo
44
45# Output the results.
46egrep -h "^ERROR:|^FAIL:|0 failed tests|giving up" $RESULTSDIR/results.* | \
47    sort | uniq -c | sort -rn >&2
48
49# If there were any failures, leave the results around for examination.
50if egrep -q "^ERROR|^FAIL" $RESULTSDIR/results.*; then
51  echo "Failures occurred, leaving results in $RESULTSDIR" >&2
52else
53  rm -rf $RESULTSDIR
54fi
55