vm_smoke_test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/sh
  2. #
  3. # This software is a part of ISAR.
  4. # Copyright (C) 2015-2018 ilbers GmbH
  5. CONSOLE_OUTPUT=/tmp/isar_console
  6. PID_FILE=/tmp/qemu.pid
  7. VERBOSE=1
  8. TIMEOUT=300
  9. # Error codes:
  10. ES_OK=0
  11. ES_FAIL=1
  12. ES_BUG=3
  13. RET=$ES_OK
  14. dump_boot_log() {
  15. echo "Boot log:\n8<--"
  16. cat $CONSOLE_OUTPUT
  17. echo "\n8<--"
  18. }
  19. check_login_prompt() {
  20. echo -n "Check login prompt: "
  21. str=$(grep "isar login: " $CONSOLE_OUTPUT)
  22. if [ -n "$str" ]; then
  23. echo "PASSED"
  24. else
  25. echo "FAIL"
  26. RET=$ES_FAIL
  27. FAIL=1
  28. fi
  29. }
  30. check_example_module() {
  31. echo -n "Check example module: "
  32. str=$(grep "Just an example" $CONSOLE_OUTPUT)
  33. if [ -n "$str" ]; then
  34. echo "PASSED"
  35. else
  36. echo "FAIL"
  37. RET=$ES_FAIL
  38. FAIL=1
  39. fi
  40. }
  41. run_test () {
  42. ARCH=$1
  43. DISTRO=$2
  44. echo "-------------------------------------------------"
  45. echo "Testing Isar [$DISTRO] image for [$ARCH] machine:"
  46. start_vm -a $ARCH -d $DISTRO -o $CONSOLE_OUTPUT -p $PID_FILE > /dev/null 2>&1 &
  47. sleep 5
  48. if [ -z `ps -p $! -o pid=` ]; then
  49. echo "QEMU start: FAILED"
  50. RET=$ES_FAIL
  51. echo "Command output:\n8<--"
  52. start_vm -a $ARCH -d $DISTRO -o $CONSOLE_OUTPUT -p $PID_FILE
  53. echo "\n8<--"
  54. else
  55. sleep $TIMEOUT
  56. kill `cat $PID_FILE`
  57. FAIL=0
  58. check_login_prompt
  59. check_example_module
  60. [ $VERBOSE -eq 1 -o $FAIL -eq 1 ] && dump_boot_log
  61. rm $CONSOLE_OUTPUT
  62. fi
  63. rm $PID_FILE
  64. }
  65. show_help() {
  66. echo "This script tests the Isar images for default targets in QEMU."
  67. echo
  68. echo "Usage:"
  69. echo " $0 [params]"
  70. echo
  71. echo "Parameters:"
  72. echo " -f,--fast test reduced set of supported targets."
  73. echo " -o,--output FILE specify file to store console output."
  74. echo " The default is: /tmp/isar_console"
  75. echo " -p,--pid-file FILE specify file to store QEMU process PID."
  76. echo " The default is: /tmp/qemu.pid"
  77. echo " -q, --quiet do not display boot logs for all the targets."
  78. echo " If test failed for the specific configuration,"
  79. echo " the respective boot log will be printed anyway."
  80. echo " -t,--timeout SEC specify time in seconds to wait before stop QEMU."
  81. echo " The default is: 300"
  82. echo " -h, --help display this message and exit."
  83. echo
  84. echo "Exit status:"
  85. echo " 0 if OK,"
  86. echo " 1 if test failed,"
  87. echo " 3 if invalid parameters are passed."
  88. }
  89. # Parse command line to get user configuration
  90. while [ $# -gt 0 ]
  91. do
  92. key="$1"
  93. case $key in
  94. -h|--help)
  95. show_help
  96. exit 0
  97. ;;
  98. -o|--output)
  99. CONSOLE_OUTPUT=$2
  100. shift
  101. ;;
  102. -p|--pid-file)
  103. PID_FILE=$2
  104. shift
  105. ;;
  106. -f|--fast)
  107. FAST_BUILD="1"
  108. ;;
  109. -q|--quiet)
  110. VERBOSE=0
  111. ;;
  112. -t|--timeout)
  113. TIMEOUT=$2
  114. shift
  115. ;;
  116. *)
  117. echo "error: invalid parameter '$key', please try '--help' to get list of supported parameters"
  118. exit $ES_BUG
  119. ;;
  120. esac
  121. shift
  122. done
  123. # ARM machine
  124. if [ -z "$FAST_BUILD" ]; then
  125. run_test arm buster
  126. fi
  127. run_test arm stretch
  128. # AMD64 machine
  129. if [ -z "$FAST_BUILD" ]; then
  130. run_test amd64 buster
  131. fi
  132. run_test amd64 stretch
  133. # i386 machine
  134. if [ -z "$FAST_BUILD" ]; then
  135. run_test i386 stretch
  136. run_test i386 buster
  137. fi
  138. # ARM64 machine
  139. run_test arm64 stretch
  140. exit $RET