File: runtests

package info (click to toggle)
base-installer 1.227
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,288 kB
  • sloc: sh: 1,587; ansic: 704; makefile: 59; perl: 50
file content (128 lines) | stat: -rwxr-xr-x 2,357 bytes parent folder | download | duplicates (4)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /bin/sh
set -e

if [ -z "$1" ]; then
	echo "Usage: runtests <architecture>" >&2
	exit 1
fi

ARCH="$1"
PASSES=0
FAILURES=0

[ "$TEST_VERBOSE" ] || export TEST_VERBOSE=1

verbose () {
	if [ "$TEST_VERBOSE" -ge 2 ]; then
		echo "$@"
	fi
	eval "$@"
}

# Run a test based on a test file.
run_test () {
	TEST="$1"

	unset SUBARCH CPUINFO OFCPUS MACHINE FLAVOUR USABLE UNUSABLE \
		|| true
	unset $(set | sed -n 's/^\(KERNEL_.*\)=.*/\1/p')
	NUMCPUS=1
	MAJORS=2.6

	while read name value; do
		case $name in
			subarch)
				SUBARCH="$value"
				;;
			cpuinfo)
				CPUINFO="${TEST%/*}/$value"
				;;
			ofcpus)
				OFCPUS="${TEST%/*}/$value"
				;;
			numcpus)
				NUMCPUS="$value"
				;;
			machine)
				MACHINE="$value"
				;;
			majors)
				MAJORS="$value"
				;;
			flavour)
				FLAVOUR="$value"
				;;
			kernel-*)
				KERNEL_LIST_NAME="$(echo "$name" | tr '[a-z].-' '[A-Z]__')"
				eval $KERNEL_LIST_NAME="\$value"
				export $KERNEL_LIST_NAME
				;;
			usable)
				USABLE="$value"
				;;
			unusable)
				UNUSABLE="$value"
				;;
			env)
				# TODO: is there any quote-safe way to do
				# this?
				eval "export ${value%% *}='${value#* }'"
				;;
		esac
	done < "$TEST"

	export ARCH SUBARCH CPUINFO OFCPUS NUMCPUS MACHINE
	export MAJORS FLAVOUR
	export USABLE UNUSABLE

	TMP="$(mktemp -t base-installer-tests.XXXXXX)"
	trap 'rm -f "$TMP"' 0 HUP INT QUIT TERM

	# Run the actual testset.
	verbose ./dotest >"$TMP"

	# Massage testset output into a more useful form.
	while read state message; do
		case "$state" in
			PASS)
				PASSES="$(($PASSES + 1))"
				;;
			FAIL)
				FAILURES="$(($FAILURES + 1))"
				;;
		esac
		if [ "$state" != PASS ] || [ "$TEST_VERBOSE" -ge 2 ]; then
			echo "$state $TEST $message"
		fi
	done <"$TMP"
	rm -f "$TMP"
	trap 0 HUP INT QUIT TERM
}

if [ "$2" ]; then
	ONETEST="$2"
	run_test "$ONETEST"
else
	for test in "$ARCH"/*.test; do
		# Sanity check: check test file for incorrect line continuations
		if ! awk 'BEGIN {lc=0}
			  /\\[[:space:]]*$/ {if (lc==1 && substr($0,1,1)!=" ") {exit 1}; lc=1}
			  /[^\\][[:space:]]*$/ {lc=0}
			  END {if (lc==1) {exit 1}}' $test
		then
			echo "Incorrect line continuation in test file '$test'"
			exit 1
		fi
		run_test "$test"
	done
fi

if [ "$TEST_VERBOSE" -ge 1 ]; then
	echo "$ARCH: $PASSES passes, $FAILURES failures."
fi

if [ "$FAILURES" -eq 0 ]; then
	exit 0
else
	exit 1
fi