File: run_tests.sh

package info (click to toggle)
nsync 1.29.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,816 kB
  • sloc: ansic: 9,130; asm: 1,137; makefile: 944; sh: 619; cpp: 551
file content (102 lines) | stat: -rwxr-xr-x 2,164 bytes parent folder | download | duplicates (5)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh

usage="usage: run_tests [-p <N>] [-n <N>] [-bB] test...
  -p <N>             runs <N> tests in parallel
  -n <N>             runs <N> subtests in parallel
  -b                 benchmarks are run if tests pass
  -B                 only benchmarks are run
  -x <cross-runner>  runs each test as <cross-runner> <test> ...

The purpose of the cross-runner is to allow a test cross-compiled
for another environment to be run in that environment, perhaps via
an interpreter, or remotely.

Benchmarks are not run in parallel."

parallel=1
subparallel=1
run_tests=true
run_benchmarks=false
crossrunner=
rc=0
tests=
while
	arg="$1"
	case "$arg" in
	-*)
		case "$arg" in -*b*) run_benchmarks=true;; esac
		case "$arg" in -*B*) run_benchmarks=true; run_tests=false;; esac
		case "$arg" in -*n*) subparallel="${2?"$usage"}"; shift;; esac
		case "$arg" in -*p*) parallel="${2?"$usage"}"; shift;; esac
		case "$arg" in -*x*) crossrunner="${2?"$usage"}"; shift;; esac
		case "$arg" in -*[!bBnpx]*) echo "$usage" >&2; exit 2;; esac
		;;
	"")	break;;
	*)	tests="$tests $arg";;
	esac
do
	shift
done

if $run_tests; then
	case $parallel in
	1)
		for x in $tests; do
			$crossrunner $x -n $subparallel
			trc=$?
			case $rc in 0) rc=$trc;; esac
		done
		;;
	*)
		tmp=/tmp/run_tests.$$
		w=1000
		r=1000

		for x in $tests; do
			while 
				while [ -s $tmp.rc.$r ]; do
					cat $tmp.o.$r
					case $rc in 0) rc=`cat $tmp.rc.$r`;; esac
					rm -f $tmp.o.$r $tmp.rc.$r
					r=`expr $r + 1`
				done
				i=$r
				p=0
				while [ $i -lt $w ]; do
					i=`expr $i + 1`
					if [ ! -s $tmp.rc.$i ]; then p=`expr $p + 1`; fi
				done
				[ $parallel -le $p ]
			do
				sleep 1
			done
			($crossrunner $x -n $subparallel > $tmp.o.$w 2>&1; echo $? > $tmp.rc.$w) &
			w=`expr $w + 1`
		done
		while 
			while [ -s $tmp.rc.$r ]; do
				cat $tmp.o.$r
				case $rc in 0) rc=`cat $tmp.rc.$r`;; esac
				rm -f $tmp.o.$r $tmp.rc.$r
				r=`expr $r + 1`
			done
			[ $r -lt $w ]
		do
			sleep 1
		done
		;;
	esac
fi

case $rc in
0)	;;
*)	run_benchmarks=false;;
esac
if $run_benchmarks; then
	for x in $tests; do
		$crossrunner $x -B
		trc=$?
		case $rc in 0) rc=$trc;; esac
	done
fi
exit $rc