Home | History | Annotate | Line # | Download | only in bfin
run-tests.sh revision 1.1.1.1
      1  1.1  christos #!/bin/sh
      2  1.1  christos 
      3  1.1  christos usage() {
      4  1.1  christos 	cat <<-EOF
      5  1.1  christos 	Usage: $0 [-rs] [-rj <board>] [-rh <board ip>] [tests]
      6  1.1  christos 
      7  1.1  christos 	If no tests are specified, all tests are processed.
      8  1.1  christos 
      9  1.1  christos 	Options:
     10  1.1  christos 	  -rs          Run on simulator
     11  1.1  christos 	  -rj <board>  Run on board via JTAG
     12  1.1  christos 	  -rh <ip>     Run on board ip
     13  1.1  christos 	  -j <num>     Num jobs to run
     14  1.1  christos 	EOF
     15  1.1  christos 	exit ${1:-1}
     16  1.1  christos }
     17  1.1  christos 
     18  1.1  christos : ${MAKE:=make}
     19  1.1  christos boardip=
     20  1.1  christos boardjtag=
     21  1.1  christos run_sim=false
     22  1.1  christos run_jtag=false
     23  1.1  christos run_host=false
     24  1.1  christos jobs=`getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`
     25  1.1  christos : $(( jobs += 1 ))
     26  1.1  christos while [ -n "$1" ] ; do
     27  1.1  christos 	case $1 in
     28  1.1  christos 		-rs) run_sim=true;;
     29  1.1  christos 		-rj) boardjtag=$2; shift; run_jtag=true;;
     30  1.1  christos 		-rh) boardip=$2; shift; run_host=true;;
     31  1.1  christos 		-j)  jobs=$2; shift;;
     32  1.1  christos 		-*)  usage;;
     33  1.1  christos 		*)   break;;
     34  1.1  christos 	esac
     35  1.1  christos 	shift
     36  1.1  christos done
     37  1.1  christos ${run_jtag} || ${run_host} || ${run_sim} || run_sim=true
     38  1.1  christos 
     39  1.1  christos if ${run_host} && [ -z "${boardip}" ] ; then
     40  1.1  christos 	usage
     41  1.1  christos fi
     42  1.1  christos 
     43  1.1  christos cd "${0%/*}" || exit 1
     44  1.1  christos 
     45  1.1  christos dorsh() {
     46  1.1  christos 	# rsh sucks and does not pass up its exit status, so we have to:
     47  1.1  christos 	#  on board:
     48  1.1  christos 	#    - send all output to stdout
     49  1.1  christos 	#    - send exit status to stderr
     50  1.1  christos 	#  on host:
     51  1.1  christos 	#    - swap stdout and stderr
     52  1.1  christos 	#    - pass exit status to `exit`
     53  1.1  christos 	#    - send stderr back to stdout and up
     54  1.1  christos 	(exit \
     55  1.1  christos 		$(rsh -l root $boardip \
     56  1.1  christos 			'(/tmp/'$1') 2>&1; ret=$?; echo $ret 1>&2; [ $ret -eq 0 ] && rm -f /tmp/'$1 \
     57  1.1  christos 			3>&1 1>&2 2>&3) \
     58  1.1  christos 		2>&1) 2>&1
     59  1.1  christos }
     60  1.1  christos 
     61  1.1  christos dojtag() {
     62  1.1  christos 	if grep -q CHECKREG ${1%.x} ; then
     63  1.1  christos 		echo "DBGA does not work via JTAG"
     64  1.1  christos 		exit 77
     65  1.1  christos 	fi
     66  1.1  christos 
     67  1.1  christos 	cat <<-EOF > commands
     68  1.1  christos 		target remote localhost:2000
     69  1.1  christos 		load
     70  1.1  christos 
     71  1.1  christos 		b *_pass
     72  1.1  christos 		commands
     73  1.1  christos 		exit 0
     74  1.1  christos 		end
     75  1.1  christos 
     76  1.1  christos 		b *_fail
     77  1.1  christos 		commands
     78  1.1  christos 		exit 1
     79  1.1  christos 		end
     80  1.1  christos 
     81  1.1  christos 		# we're executing at EVT1, so this doesn't really help ...
     82  1.1  christos 		set ((long *)0xFFE02000)[3] = _fail
     83  1.1  christos 		set ((long *)0xFFE02000)[5] = _fail
     84  1.1  christos 
     85  1.1  christos 		c
     86  1.1  christos 	EOF
     87  1.1  christos 	bfin-elf-gdb -x commands "$1"
     88  1.1  christos 	ret=$?
     89  1.1  christos 	rm -f commands
     90  1.1  christos 	exit ${ret}
     91  1.1  christos }
     92  1.1  christos 
     93  1.1  christos testit() {
     94  1.1  christos 	local name=$1 x=$2 y=`echo $2 | sed 's:\.[xX]$::'` out rsh_out addr
     95  1.1  christos 	shift; shift
     96  1.1  christos 	local fail=`grep xfail ${y}`
     97  1.1  christos 	if [ "${name}" = "HOST" -a ! -f $x ] ; then
     98  1.1  christos 		return
     99  1.1  christos 	fi
    100  1.1  christos 	printf '%-5s %-40s' ${name} ${x}
    101  1.1  christos 	out=`"$@" ${x} 2>&1`
    102  1.1  christos 	(pf "${out}")
    103  1.1  christos 	if [ $? -ne 0 ] ; then
    104  1.1  christos 		if [ "${name}" = "SIM" ] ; then
    105  1.1  christos 			tmp=`echo ${out} | awk '{print $3}' | sed 's/://'`
    106  1.1  christos 			tmp1=`expr index "${out}" "program stopped with signal 4"`
    107  1.1  christos 			if [ ${tmp1} -eq 1 ] ; then
    108  1.1  christos 				 printf 'illegal instruction\n'
    109  1.1  christos 			elif [ -n "${tmp}" ] ; then
    110  1.1  christos 				printf 'FAIL at line '
    111  1.1  christos 				addr=`echo $out | sed 's:^[A-Za-z ]*::' | sed 's:^0x[0-9][0-9] ::' | sed 's:^[A-Za-z ]*::' | awk '{print $1}'`
    112  1.1  christos 				bfin-elf-addr2line -e ${x} ${addr} | awk -F "/" '{print $NF}'
    113  1.1  christos 			fi
    114  1.1  christos 		elif [ "${name}" = "HOST" ] ; then
    115  1.1  christos 			rsh_out=`rsh -l root $boardip '/bin/dmesg -c | /bin/grep -e DBGA -e "FAULT "'`
    116  1.1  christos 			tmp=`echo ${rsh_out} | sed 's:\].*$::' | awk '{print $NF}' | awk -F ":" '{print $NF}'`
    117  1.1  christos 			if [ -n "${tmp}" ] ; then
    118  1.1  christos 				echo "${rsh_out}"
    119  1.1  christos 				printf 'FAIL at line '
    120  1.1  christos 				bfin-elf-addr2line -e ${x} $(echo ${rsh_out} | sed 's:\].*$::' | awk '{print $NF}') | awk -F "/" '{print $NF}'
    121  1.1  christos 			fi
    122  1.1  christos 		fi
    123  1.1  christos 		ret=$(( ret + 1 ))
    124  1.1  christos 		if [ -z "${fail}" ] ; then
    125  1.1  christos 			unexpected_fail=$(( unexpected_fail + 1 ))
    126  1.1  christos 			echo "!!!Expected Pass, but fail"
    127  1.1  christos 		fi
    128  1.1  christos 	else
    129  1.1  christos 		if [ ! -z "${fail}" ] ; then
    130  1.1  christos 			unexpected_pass=$(( unexpected_pass + 1 ))
    131  1.1  christos 			echo "!!!Expected fail, but pass"
    132  1.1  christos 		else
    133  1.1  christos 			expected_pass=$(( expected_pass + 1 ))
    134  1.1  christos 		fi
    135  1.1  christos 	fi
    136  1.1  christos }
    137  1.1  christos 
    138  1.1  christos pf() {
    139  1.1  christos 	local ret=$?
    140  1.1  christos 	if [ ${ret} -eq 0 ] ; then
    141  1.1  christos 		echo "PASS"
    142  1.1  christos 	elif [ ${ret} -eq 77 ] ; then
    143  1.1  christos 		echo "SKIP $*"
    144  1.1  christos 	else
    145  1.1  christos 		echo "FAIL! $*"
    146  1.1  christos 		exit 1
    147  1.1  christos 	fi
    148  1.1  christos }
    149  1.1  christos 
    150  1.1  christos [ $# -eq 0 ] && set -- *.[Ss]
    151  1.1  christos bins_hw=$( (${run_sim} || ${run_jtag}) && printf '%s.x ' "$@")
    152  1.1  christos if ${run_host} ; then
    153  1.1  christos 	for files in "$@" ; do
    154  1.1  christos 		tmp=`grep -e CYCLES -e TESTSET -e CLI -e STI -e RTX -e RTI -e SEQSTAT $files -l`
    155  1.1  christos 		if [ -z "${tmp}" ] ; then
    156  1.1  christos 			bins_host=`echo "${bins_host} ${files}.X"`
    157  1.1  christos 		else
    158  1.1  christos 			echo "skipping ${files}, since it isn't userspace friendly"
    159  1.1  christos 		fi
    160  1.1  christos 	done
    161  1.1  christos fi
    162  1.1  christos if [ -n "${bins_hw}" ] ; then
    163  1.1  christos 	bins_all="${bins_hw}"
    164  1.1  christos fi
    165  1.1  christos 
    166  1.1  christos if [ -n "${bins_host}" ] ; then
    167  1.1  christos 	bins_all="${bins_all} ${bins_host}"
    168  1.1  christos fi
    169  1.1  christos 
    170  1.1  christos if [ -z "${bins_all}" ] ; then
    171  1.1  christos 	exit
    172  1.1  christos fi
    173  1.1  christos 
    174  1.1  christos printf 'Compiling tests: '
    175  1.1  christos ${MAKE} -s -j ${bins_all}
    176  1.1  christos pf
    177  1.1  christos 
    178  1.1  christos if ${run_jtag} ; then
    179  1.1  christos 	printf 'Setting up gdbproxy (see gdbproxy.log): '
    180  1.1  christos 	killall -q bfin-gdbproxy
    181  1.1  christos 	bfin-gdbproxy -q bfin --reset --board=${boardjtag} --init-sdram >gdbproxy.log 2>&1 &
    182  1.1  christos 	t=0
    183  1.1  christos 	while [ ${t} -lt 5 ] ; do
    184  1.1  christos 		if netstat -nap 2>&1 | grep -q ^tcp.*:2000.*gdbproxy ; then
    185  1.1  christos 			break
    186  1.1  christos 		else
    187  1.1  christos 			: $(( t += 1 ))
    188  1.1  christos 			sleep 1
    189  1.1  christos 		fi
    190  1.1  christos 	done
    191  1.1  christos 	pf
    192  1.1  christos fi
    193  1.1  christos 
    194  1.1  christos if ${run_host} ; then
    195  1.1  christos 	printf 'Uploading tests to board "%s": ' "${boardip}"
    196  1.1  christos 	rcp ${bins_host} root@${boardip}:/tmp/
    197  1.1  christos 	pf
    198  1.1  christos 	rsh -l root $boardip '/bin/dmesg -c' > /dev/null
    199  1.1  christos fi
    200  1.1  christos 
    201  1.1  christos SIM="../../../bfin/run"
    202  1.1  christos if [ ! -x ${SIM} ] ; then
    203  1.1  christos 	SIM="bfin-elf-run"
    204  1.1  christos fi
    205  1.1  christos echo "Using sim: ${SIM}"
    206  1.1  christos 
    207  1.1  christos ret=0
    208  1.1  christos unexpected_fail=0
    209  1.1  christos unexpected_pass=0
    210  1.1  christos expected_pass=0
    211  1.1  christos pids=()
    212  1.1  christos for s in "$@" ; do
    213  1.1  christos 	(
    214  1.1  christos 	out=$(
    215  1.1  christos 	${run_sim}  && testit SIM  ${s}.x ${SIM} `sed -n '/^# sim:/s|^[^:]*:||p' ${s}`
    216  1.1  christos 	${run_jtag} && testit JTAG ${s}.x dojtag
    217  1.1  christos 	${run_host} && testit HOST ${s}.X dorsh
    218  1.1  christos 	)
    219  1.1  christos 	case $out in
    220  1.1  christos 	*PASS*) ;;
    221  1.1  christos 	*) echo "$out" ;;
    222  1.1  christos 	esac
    223  1.1  christos 	) &
    224  1.1  christos 	pids+=( $! )
    225  1.1  christos 	if [[ ${#pids[@]} -gt ${jobs} ]] ; then
    226  1.1  christos 		wait ${pids[0]}
    227  1.1  christos 		pids=( ${pids[@]:1} )
    228  1.1  christos 	fi
    229  1.1  christos done
    230  1.1  christos wait
    231  1.1  christos 
    232  1.1  christos killall -q bfin-gdbproxy
    233  1.1  christos if [ ${ret} -eq 0 ] ; then
    234  1.1  christos 	rm -f gdbproxy.log
    235  1.1  christos #	${MAKE} -s clean &
    236  1.1  christos 	exit 0
    237  1.1  christos else
    238  1.1  christos 	echo number of failures ${ret}
    239  1.1  christos 	if [ ${unexpected_pass} -gt 0 ] ; then
    240  1.1  christos 		echo "Unexpected passes: ${unexpected_pass}"
    241  1.1  christos 	fi
    242  1.1  christos 	if [ ${unexpected_fail} -gt 0 ] ; then
    243  1.1  christos 		echo "Unexpected fails: ${unexpected_fail}"
    244  1.1  christos 	fi
    245  1.1  christos 	if [ ${expected_pass} -gt 0 ] ; then
    246  1.1  christos 		echo "passes : ${expected_pass}"
    247  1.1  christos 	fi
    248  1.1  christos 	exit 1
    249  1.1  christos fi
    250