xref: /aosp_15_r20/kernel/tests/net/test/parallel_tests.sh (revision 2f2c4c7ab4226c71756b9c31670392fdd6887c4f)
1*2f2c4c7aSAndroid Build Coastguard Worker#!/bin/sh
2*2f2c4c7aSAndroid Build Coastguard Worker
3*2f2c4c7aSAndroid Build Coastguard Worker# Runs many iterations of run_net_test.sh in parallel processes, for the
4*2f2c4c7aSAndroid Build Coastguard Worker# purposes of finding flaky tests.
5*2f2c4c7aSAndroid Build Coastguard Worker
6*2f2c4c7aSAndroid Build Coastguard Workerif ! [[ $1 =~ ^[0-9]+$ ]] || ! [[ $2 =~ ^[0-9]+$ ]] || [ -z "$3" ]; then
7*2f2c4c7aSAndroid Build Coastguard Worker  echo "Usage: $0 <workers> <runs_per_worker> <test>" >&2
8*2f2c4c7aSAndroid Build Coastguard Worker  exit 1
9*2f2c4c7aSAndroid Build Coastguard Workerfi
10*2f2c4c7aSAndroid Build Coastguard Worker
11*2f2c4c7aSAndroid Build Coastguard Worker# A function run by every worker. Runs the tests <runs_per_worker> times.
12*2f2c4c7aSAndroid Build Coastguard Workerfunction runtests() {
13*2f2c4c7aSAndroid Build Coastguard Worker  local worker=$1
14*2f2c4c7aSAndroid Build Coastguard Worker  local runs=$2
15*2f2c4c7aSAndroid Build Coastguard Worker  local test=$3
16*2f2c4c7aSAndroid Build Coastguard Worker  local j=0
17*2f2c4c7aSAndroid Build Coastguard Worker  while ((j < runs)); do
18*2f2c4c7aSAndroid Build Coastguard Worker    $DIR/run_net_test.sh --builder --nobuild $test \
19*2f2c4c7aSAndroid Build Coastguard Worker        > /dev/null 2> $RESULTSDIR/results.$worker.$j
20*2f2c4c7aSAndroid Build Coastguard Worker    j=$((j + 1))
21*2f2c4c7aSAndroid Build Coastguard Worker    echo -n "." >&2
22*2f2c4c7aSAndroid Build Coastguard Worker  done
23*2f2c4c7aSAndroid Build Coastguard Worker}
24*2f2c4c7aSAndroid Build Coastguard Worker
25*2f2c4c7aSAndroid Build Coastguard WorkerWORKERS=$1
26*2f2c4c7aSAndroid Build Coastguard WorkerRUNS=$2
27*2f2c4c7aSAndroid Build Coastguard WorkerTEST=$3
28*2f2c4c7aSAndroid Build Coastguard WorkerDIR=$(dirname $0)
29*2f2c4c7aSAndroid Build Coastguard WorkerRESULTSDIR=$(mktemp --tmpdir -d net_test.parallel.XXXXXX)
30*2f2c4c7aSAndroid Build Coastguard Worker[ -z $RESULTSDIR ] && exit 1
31*2f2c4c7aSAndroid Build Coastguard Worker
32*2f2c4c7aSAndroid Build Coastguard Workertest_file=$DIR/$TEST
33*2f2c4c7aSAndroid Build Coastguard Workerif [[ ! -x $test_file ]]; then
34*2f2c4c7aSAndroid Build Coastguard Worker  echo "test file '${test_file}' does not exist"
35*2f2c4c7aSAndroid Build Coastguard Worker  exit 1
36*2f2c4c7aSAndroid Build Coastguard Workerfi
37*2f2c4c7aSAndroid Build Coastguard Worker
38*2f2c4c7aSAndroid Build Coastguard Workerecho "Building kernel..." >&2
39*2f2c4c7aSAndroid Build Coastguard Worker$DIR/run_net_test.sh --norun || exit 1
40*2f2c4c7aSAndroid Build Coastguard Worker
41*2f2c4c7aSAndroid Build Coastguard Workerecho "Running $WORKERS worker(s) with $RUNS test run(s) each..." >&2
42*2f2c4c7aSAndroid Build Coastguard Worker
43*2f2c4c7aSAndroid Build Coastguard Worker# Start all the workers.
44*2f2c4c7aSAndroid Build Coastguard Workerworker=0
45*2f2c4c7aSAndroid Build Coastguard Workerwhile ((worker < WORKERS)); do
46*2f2c4c7aSAndroid Build Coastguard Worker  runtests $worker $RUNS $TEST &
47*2f2c4c7aSAndroid Build Coastguard Worker  worker=$((worker + 1))
48*2f2c4c7aSAndroid Build Coastguard Workerdone
49*2f2c4c7aSAndroid Build Coastguard Workerwait
50*2f2c4c7aSAndroid Build Coastguard Worker
51*2f2c4c7aSAndroid Build Coastguard Workerecho
52*2f2c4c7aSAndroid Build Coastguard Worker
53*2f2c4c7aSAndroid Build Coastguard Worker# Output the results.
54*2f2c4c7aSAndroid Build Coastguard Workeregrep -h "^ERROR:|^FAIL:|0 failed tests|giving up" $RESULTSDIR/results.* | \
55*2f2c4c7aSAndroid Build Coastguard Worker    sort | uniq -c | sort -rn >&2
56*2f2c4c7aSAndroid Build Coastguard Worker
57*2f2c4c7aSAndroid Build Coastguard Worker# If there were any failures, leave the results around for examination.
58*2f2c4c7aSAndroid Build Coastguard Workerif egrep -q "^ERROR|^FAIL" $RESULTSDIR/results.*; then
59*2f2c4c7aSAndroid Build Coastguard Worker  echo "Failures occurred, leaving results in $RESULTSDIR" >&2
60*2f2c4c7aSAndroid Build Coastguard Workerelse
61*2f2c4c7aSAndroid Build Coastguard Worker  rm -rf $RESULTSDIR
62*2f2c4c7aSAndroid Build Coastguard Workerfi
63