cpuhotplug02.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/sh
  2. #
  3. # Test Case 2
  4. #
  5. export TCID="cpuhotplug02"
  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: What happens to a process when its CPU is offlined?
  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. # Callback to be executed when script exits from a user interrupt
  29. # or regular program termination.
  30. #
  31. do_clean()
  32. {
  33. kill_pid ${SPIN_LOOP_PID}
  34. }
  35. while getopts c:l: OPTION; do
  36. case $OPTION in
  37. c)
  38. CPU_TO_TEST=$OPTARG;;
  39. l)
  40. HOTPLUG02_LOOPS=$OPTARG;;
  41. ?)
  42. usage;;
  43. esac
  44. done
  45. LOOP_COUNT=1
  46. if [ $(get_present_cpus_num) -lt 2 ]; then
  47. tst_brkm TCONF "system doesn't have required CPU hotplug support"
  48. fi
  49. if [ -z "${CPU_TO_TEST}" ]; then
  50. tst_brkm TBROK "usage: ${0##*/} <CPU to online>"
  51. fi
  52. # Validate the specified CPU is available
  53. if ! cpu_is_valid "${CPU_TO_TEST}" ; then
  54. tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
  55. fi
  56. # Validate the specified CPU is online; if not, online it
  57. if ! cpu_is_online "${CPU_TO_TEST}" ; then
  58. if ! online_cpu ${CPU_TO_TEST}; then
  59. tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
  60. fi
  61. fi
  62. TST_CLEANUP=do_clean
  63. # Start up a process that just uses CPU cycles
  64. cpuhotplug_do_spin_loop > /dev/null&
  65. SPIN_LOOP_PID=$!
  66. sleep 5
  67. until [ $LOOP_COUNT -gt $HOTPLUG02_LOOPS ]; do
  68. # Move spin_loop.sh to the CPU to offline.
  69. set_affinity ${SPIN_LOOP_PID} ${CPU_TO_TEST}
  70. # Verify the process migrated to the CPU we intended it to go to
  71. offline_cpu ${CPU_TO_TEST}
  72. NEW_CPU=`ps --pid=${SPIN_LOOP_PID} -o psr --no-headers`
  73. if [ -z "${NEW_CPU}" ]; then
  74. tst_brkm TBROK "PID ${SPIN_LOOP_PID} no longer running"
  75. fi
  76. if [ ${CPU_TO_TEST} = ${NEW_CPU} ]; then
  77. tst_resm TFAIL "process did not change from CPU ${NEW_CPU}"
  78. tst_exit
  79. fi
  80. # Turn the CPU back online just to see what happens.
  81. online_cpu ${CPU_TO_TEST}
  82. LOOP_COUNT=$((LOOP_COUNT+1))
  83. done
  84. tst_resm TPASS "turned off CPU ${CPU_TO_TEST}, process migrated to \
  85. CPU ${NEW_CPU}"
  86. sleep 2
  87. tst_exit