• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# A simple wrapper for pre- and post-execution activities for any given
4# openposix test.
5#
6# run_test contains logic moved out of Makefile.
7#
8# Ngie Cooper, June 2010
9#
10
11LOGFILE=${LOGFILE:=logfile}
12
13NUM_FAIL=0
14NUM_PASS=0
15NUM_TESTS=0
16
17run_test_loop() {
18
19	for t in $*; do
20
21		if run_test "$t"; then
22			NUM_PASS=$(expr $NUM_PASS + 1)
23		else
24			NUM_FAIL=$(expr $NUM_FAIL + 1)
25		fi
26		NUM_TESTS=$(expr $NUM_TESTS + 1)
27
28	done
29
30	cat <<EOF
31*******************
32Testing $(basename $PWD)
33*******************
34$(printf "PASS\t\t%3d" $NUM_PASS)
35$(printf "FAIL\t\t%3d" $NUM_FAIL)
36*******************
37$(printf "TOTAL\t\t%3d" $NUM_TESTS)
38*******************
39EOF
40
41}
42
43run_test() {
44
45	testname="$TEST_PATH/${1%.*}"
46
47	complog=$(basename $testname).log.$$
48
49	sh -c "$SCRIPT_DIR/t0 $TIMEOUT_VAL ./$1 $(cat ./$(echo "$1" | sed 's,\.[^\.]*,,').args 2>/dev/null)" > $complog 2>&1
50
51	ret_code=$?
52
53	if [ "$ret_code" = "0" ]; then
54		echo "$testname: execution: PASS" >> "${LOGFILE}"
55	elif [ -f "$1" ]; then
56		case "$ret_code" in
57		1)
58			msg="FAILED"
59			;;
60		2)
61			msg="UNRESOLVED"
62			;;
63		4)
64			msg="UNSUPPORTED"
65			;;
66		5)
67			msg="UNTESTED"
68			;;
69		$TIMEOUT_RET)
70			msg="HUNG"
71			;;
72		*)
73			if [ $ret_code -gt 128 ]; then
74				msg="SIGNALED"
75			else
76				msg="EXITED ABNORMALLY"
77			fi
78		esac
79		echo "$testname: execution: $msg: Output: " >> "${LOGFILE}"
80		cat $complog >> "${LOGFILE}"
81		echo "$testname: execution: $msg "
82	else
83		echo "$testname: execution: SKIPPED (test not present)"
84	fi
85
86	rm -f $complog
87
88	return $ret_code
89
90}
91
92# SETUP
93if [ -w "$LOGFILE" ] || echo "" > "$LOGFILE"; then
94	:
95else
96	echo >&2 "ERROR: $LOGFILE not writable"
97	exit 1
98fi
99
100SCRIPT_DIR=$(dirname "$0")
101TEST_PATH=$1; shift
102T0=$SCRIPT_DIR/t0
103T0_VAL=$SCRIPT_DIR/t0.val
104
105if [ ! -x $T0 ]; then
106	echo >&2 "ERROR: $T0 doesn't exist / isn't executable"
107	exit 1
108fi
109
110if [ ! -f "$T0_VAL" ]; then
111	$SCRIPT_DIR/t0 0 >/dev/null 2>&1
112	echo $? > "$T0_VAL"
113fi
114if TIMEOUT_RET=$(cat "$T0_VAL"); then
115
116	TIMEOUT_VAL=${TIMEOUT_VAL:=300}
117	if [ -f test_defs ] ; then
118		. ./test_defs || exit $?
119	fi
120	trap '' INT
121
122	# RUN
123	run_test_loop $*
124	exit $NUM_FAIL
125
126else
127	exit $?
128fi
129