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]+$ ]] || [ -z "$3" ]; then 7 echo "Usage: $0 <workers> <runs_per_worker> <test>" >&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 test=$3 16 local j=0 17 while ((j < runs)); do 18 $DIR/run_net_test.sh --builder --nobuild $test \ 19 > /dev/null 2> $RESULTSDIR/results.$worker.$j 20 j=$((j + 1)) 21 echo -n "." >&2 22 done 23} 24 25WORKERS=$1 26RUNS=$2 27TEST=$3 28DIR=$(dirname $0) 29RESULTSDIR=$(mktemp --tmpdir -d net_test.parallel.XXXXXX) 30[ -z $RESULTSDIR ] && exit 1 31 32test_file=$DIR/$TEST 33if [[ ! -x $test_file ]]; then 34 echo "test file '${test_file}' does not exist" 35 exit 1 36fi 37 38echo "Building kernel..." >&2 39$DIR/run_net_test.sh --norun || exit 1 40 41echo "Running $WORKERS worker(s) with $RUNS test run(s) each..." >&2 42 43# Start all the workers. 44worker=0 45while ((worker < WORKERS)); do 46 runtests $worker $RUNS $TEST & 47 worker=$((worker + 1)) 48done 49wait 50 51echo 52 53# Output the results. 54egrep -h "^ERROR:|^FAIL:|0 failed tests|giving up" $RESULTSDIR/results.* | \ 55 sort | uniq -c | sort -rn >&2 56 57# If there were any failures, leave the results around for examination. 58if egrep -q "^ERROR|^FAIL" $RESULTSDIR/results.*; then 59 echo "Failures occurred, leaving results in $RESULTSDIR" >&2 60else 61 rm -rf $RESULTSDIR 62fi 63