summaryrefslogtreecommitdiff
path: root/net/test/parallel_tests.sh
blob: 93a43c8ae5338f8a43a3444f6ae3e5a1479d7ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

# Runs many iterations of run_net_test.sh in parallel processes, for the
# purposes of finding flaky tests.

if ! [[ $1 =~ ^[0-9]+$ ]] || ! [[ $2 =~ ^[0-9]+$ ]] || [ -z "$3" ]; then
  echo "Usage: $0 <workers> <runs_per_worker> <test>" >&2
  exit 1
fi

# A function run by every worker. Runs the tests <runs_per_worker> times.
function runtests() {
  local worker=$1
  local runs=$2
  local test=$3
  local j=0
  while ((j < runs)); do
    $DIR/run_net_test.sh --readonly --builder --nobuild $test \
        > /dev/null 2> $RESULTSDIR/results.$worker.$j
    j=$((j + 1))
    echo -n "." >&2
  done
}

WORKERS=$1
RUNS=$2
TEST=$3
DIR=$(dirname $0)
RESULTSDIR=$(mktemp --tmpdir -d net_test.parallel.XXXXXX)
[ -z $RESULTSDIR ] && exit 1

test_file=$DIR/$TEST
if [[ ! -x $test_file ]]; then
  echo "test file '${test_file}' does not exist"
  exit 1
fi

echo "Building kernel..." >&2
$DIR/run_net_test.sh --norun || exit 1

echo "Running $WORKERS worker(s) with $RUNS test run(s) each..." >&2

# Start all the workers.
worker=0
while ((worker < WORKERS)); do
  runtests $worker $RUNS $TEST &
  worker=$((worker + 1))
done
wait

echo

# Output the results.
egrep -h "^ERROR:|^FAIL:|0 failed tests|giving up" $RESULTSDIR/results.* | \
    sort | uniq -c | sort -rn >&2

# If there were any failures, leave the results around for examination.
if egrep -q "^ERROR|^FAIL" $RESULTSDIR/results.*; then
  echo "Failures occurred, leaving results in $RESULTSDIR" >&2
else
  rm -rf $RESULTSDIR
fi