run-tests.sh 5.3 KB

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