test.sh 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. LOGFILE="build/test-$$.log"
  3. SUCCESS_MSG="###$RANDOM :SuCCeSS: $RANDOM###"
  4. die() {
  5. echo "error: $1" >&2
  6. exit 1
  7. }
  8. runcmd() {
  9. _cmd=$(printf "%q" "$*")
  10. cat <<EOF
  11. expect {
  12. "*/ # " { send "$_cmd\n" }
  13. "*panicked" { exit 1 }
  14. }
  15. EOF
  16. }
  17. wait_str() {
  18. cat <<EOF
  19. expect {
  20. "*$*" {}
  21. "*panicked" { exit 1 }
  22. }
  23. EOF
  24. }
  25. wait_init_exit() {
  26. echo 'expect "*init exited:" { exit 0 }'
  27. }
  28. cleanup() {
  29. killall -KILL "qemu-system-$ARCH"
  30. }
  31. [ -z "$ARCH" ] && die "ARCH environment variable is not set"
  32. trap cleanup EXIT
  33. expect <<EOF | tee "$LOGFILE"
  34. set timeout 10
  35. spawn make test-run "ARCH=$ARCH" MODE=release "QEMU=qemu-system-$ARCH"
  36. $(runcmd ls -la)
  37. $(wait_str proc)
  38. $(runcmd echo \""$SUCCESS_MSG"\")
  39. $(wait_str "\n$SUCCESS_MSG")
  40. $(runcmd poweroff)
  41. $(wait_init_exit)
  42. EOF
  43. status=$?
  44. echo
  45. # shellcheck disable=SC2181
  46. if [ $status -ne 0 ]; then
  47. echo "=== Test $$ with ARCH=$ARCH failed"
  48. else
  49. echo "=== Test $$ with ARCH=$ARCH passed"
  50. fi