Debian Codegraph @

tools/run_tests.sh

raw
1 #!/bin/sh
2
3 usage="usage: run_tests [-p <N>] [-n <N>] [-bB] test...
4 -p <N> runs <N> tests in parallel
5 -n <N> runs <N> subtests in parallel
6 -b benchmarks are run if tests pass
7 -B only benchmarks are run
8 -x <cross-runner> runs each test as <cross-runner> <test> ...
9
10 The purpose of the cross-runner is to allow a test cross-compiled
11 for another environment to be run in that environment, perhaps via
12 an interpreter, or remotely.
13
14 Benchmarks are not run in parallel."
15
16 parallel=1
17 subparallel=1
18 run_tests=true
19 run_benchmarks=false
20 crossrunner=
21 rc=0
22 tests=
23 while
24 arg="$1"
25 case "$arg" in
26 -*)
27 case "$arg" in -*b*) run_benchmarks=true;; esac
28 case "$arg" in -*B*) run_benchmarks=true; run_tests=false;; esac
29 case "$arg" in -*n*) subparallel="${2?"$usage"}"; shift;; esac
30 case "$arg" in -*p*) parallel="${2?"$usage"}"; shift;; esac
31 case "$arg" in -*x*) crossrunner="${2?"$usage"}"; shift;; esac
32 case "$arg" in -*[!bBnpx]*) echo "$usage" >&2; exit 2;; esac
33 ;;
34 "") break;;
35 *) tests="$tests $arg";;
36 esac
37 do
38 shift
39 done
40
41 if $run_tests; then
42 case $parallel in
43 1)
44 for x in $tests; do
45 $crossrunner $x -n $subparallel
46 trc=$?
47 case $rc in 0) rc=$trc;; esac
48 done
49 ;;
50 *)
51 tmp=/tmp/run_tests.$$
52 w=1000
53 r=1000
54
55 for x in $tests; do
56 while
57 while [ -s $tmp.rc.$r ]; do
58 cat $tmp.o.$r
59 case $rc in 0) rc=`cat $tmp.rc.$r`;; esac
60 rm -f $tmp.o.$r $tmp.rc.$r
61 r=`expr $r + 1`
62 done
63 i=$r
64 p=0
65 while [ $i -lt $w ]; do
66 i=`expr $i + 1`
67 if [ ! -s $tmp.rc.$i ]; then p=`expr $p + 1`; fi
68 done
69 [ $parallel -le $p ]
70 do
71 sleep 1
72 done
73 ($crossrunner $x -n $subparallel > $tmp.o.$w 2>&1; echo $? > $tmp.rc.$w) &
74 w=`expr $w + 1`
75 done
76 while
77 while [ -s $tmp.rc.$r ]; do
78 cat $tmp.o.$r
79 case $rc in 0) rc=`cat $tmp.rc.$r`;; esac
80 rm -f $tmp.o.$r $tmp.rc.$r
81 r=`expr $r + 1`
82 done
83 [ $r -lt $w ]
84 do
85 sleep 1
86 done
87 ;;
88 esac
89 fi
90
91 case $rc in
92 0) ;;
93 *) run_benchmarks=false;;
94 esac
95 if $run_benchmarks; then
96 for x in $tests; do
97 $crossrunner $x -B
98 trc=$?
99 case $rc in 0) rc=$trc;; esac
100 done
101 fi
102 exit $rc