cpuhotplug06.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh
  2. #
  3. # Test Case 6 - top
  4. #
  5. export TCID="cpuhotplug06"
  6. export TST_TOTAL=1
  7. # Includes:
  8. . test.sh
  9. . cpuhotplug_testsuite.sh
  10. . cpuhotplug_hotplug.sh
  11. cat <<EOF
  12. Name: $TCID
  13. Date: `date`
  14. Desc: Does top work properly when CPU hotplug events occur?
  15. EOF
  16. usage()
  17. {
  18. cat << EOF
  19. usage: $0 -c cpu -l loop
  20. OPTIONS
  21. -c cpu which is specified for testing
  22. -l number of cycle test
  23. EOF
  24. exit 1
  25. }
  26. do_clean()
  27. {
  28. pid_is_valid ${TOP_PID} && kill_pid ${TOP_PID}
  29. }
  30. while getopts c:l: OPTION; do
  31. case $OPTION in
  32. c)
  33. CPU_TO_TEST=$OPTARG;;
  34. l)
  35. HOTPLUG06_LOOPS=$OPTARG;;
  36. ?)
  37. usage;;
  38. esac
  39. done
  40. LOOP_COUNT=1
  41. if top -v | grep -q htop; then
  42. tst_brkm TCONF "htop is used instead of top (workaround: alias top='/path/to/real/top')"
  43. fi
  44. if [ $(get_present_cpus_num) -lt 2 ]; then
  45. tst_brkm TCONF "system doesn't have required CPU hotplug support"
  46. fi
  47. if [ -z "$CPU_TO_TEST" ]; then
  48. tst_brkm TBROK "Usage: ${0##*/} <CPU to offline>"
  49. fi
  50. # Verify that the specified CPU is available
  51. if ! cpu_is_valid "${CPU_TO_TEST}" ; then
  52. tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
  53. fi
  54. # Check that the specified CPU is online; if not, online it
  55. if ! cpu_is_online "${CPU_TO_TEST}" ; then
  56. if ! online_cpu ${CPU_TO_TEST}; then
  57. tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
  58. fi
  59. fi
  60. TST_CLEANUP=do_clean
  61. until [ $LOOP_COUNT -gt $HOTPLUG06_LOOPS ]; do
  62. # Start up top and give it a little time to run
  63. top -b -d 00.10 > /dev/null 2>&1 &
  64. TOP_PID=$!
  65. sleep 1
  66. # Now offline the CPU
  67. if ! offline_cpu ${CPU_TO_TEST} ; then
  68. tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
  69. fi
  70. # Wait a little time for top to notice the CPU is gone
  71. sleep 1
  72. # Check that top hasn't crashed
  73. if ! pid_is_valid ${TOP_PID} ; then
  74. tst_resm TFAIL "PID ${TOP_PID} no longer running"
  75. tst_exit
  76. fi
  77. online_cpu ${CPU_TO_TEST}
  78. kill_pid ${TOP_PID}
  79. LOOP_COUNT=$((LOOP_COUNT+1))
  80. done
  81. tst_resm TPASS "PID ${TOP_PID} still running."
  82. tst_exit