cpuhotplug05.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/sh
  2. #
  3. # Test Case 5 - sar
  4. #
  5. export TCID="cpuhotplug05"
  6. export TST_TOTAL=1
  7. export LC_TIME="POSIX"
  8. # Includes:
  9. . test.sh
  10. . cpuhotplug_testsuite.sh
  11. . cpuhotplug_hotplug.sh
  12. cat <<EOF
  13. Name: $TCID
  14. Date: `date`
  15. Desc: Does sar behave properly during CPU hotplug events?
  16. EOF
  17. usage()
  18. {
  19. cat << EOF
  20. usage: $0 -c cpu -l loop -d directory
  21. OPTIONS
  22. -c cpu which is specified for testing
  23. -l number of cycle test
  24. -d directory used to lay file
  25. EOF
  26. exit 1
  27. }
  28. do_clean()
  29. {
  30. pid_is_valid ${SAR_PID} && kill_pid ${SAR_PID}
  31. online_cpu "$CPU_TO_TEST"
  32. }
  33. get_field()
  34. {
  35. echo "$1" | awk "{print \$$2}"
  36. }
  37. while getopts c:l:d: OPTION; do
  38. case $OPTION in
  39. c)
  40. CPU_TO_TEST=$OPTARG;;
  41. l)
  42. HOTPLUG05_LOOPS=$OPTARG;;
  43. d)
  44. TMP=$OPTARG;;
  45. ?)
  46. usage;;
  47. esac
  48. done
  49. LOOP_COUNT=1
  50. tst_require_cmds sar
  51. if [ $(get_present_cpus_num) -lt 2 ]; then
  52. tst_brkm TCONF "system doesn't have required CPU hotplug support"
  53. fi
  54. if [ -z "$CPU_TO_TEST" ]; then
  55. tst_brkm TBROK "usage: ${0##*} <CPU to offline>"
  56. fi
  57. # Validate the specified CPU is available
  58. if ! cpu_is_valid "${CPU_TO_TEST}" ; then
  59. tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
  60. fi
  61. # Check that the specified CPU is offline; if not, offline it
  62. if cpu_is_online "${CPU_TO_TEST}" ; then
  63. if ! offline_cpu ${CPU_TO_TEST} ; then
  64. tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
  65. fi
  66. fi
  67. TST_CLEANUP=do_clean
  68. LOG_FILE="$TMP/log_$$"
  69. until [ $LOOP_COUNT -gt $HOTPLUG05_LOOPS ]; do
  70. # Start up SAR and give it a couple cycles to run
  71. sar 1 0 >/dev/null 2>&1 &
  72. sleep 2
  73. # "sar 1 0" is supported before 'sysstat-8.1.4(include sar)',
  74. # after that use "sar 1" instead of. Use 'ps -C sar' to check.
  75. if ps -C sar >/dev/null 2>&1; then
  76. pkill sar
  77. sar -P "$CPU_TO_TEST" 1 0 > "$LOG_FILE" &
  78. else
  79. sar -P "$CPU_TO_TEST" 1 > "$LOG_FILE" &
  80. fi
  81. sleep 2
  82. SAR_PID=$!
  83. # Since the CPU is offline, SAR should display all the 6 fields
  84. # of CPU statistics as '0.00'
  85. offline_status=$(tail -n 1 "$LOG_FILE")
  86. if [ -z "$offline_status" ]; then
  87. tst_brkm TBROK "SAR output file is empty"
  88. fi
  89. cpu_field=$(get_field "$offline_status" "2")
  90. if [ "${cpu_field}" = "CPU" ]; then
  91. # Since sysstat-11.7.1, sar/sadf didn't display offline CPU
  92. tst_resm TINFO "SAR didn't display offline CPU"
  93. else
  94. for i in $(seq 3 8); do
  95. field=$(get_field "$offline_status" "$i")
  96. if [ "$field" != "0.00" ]; then
  97. tst_brkm TBROK "Field $i is '$field', '0.00' expected"
  98. fi
  99. done
  100. fi
  101. # Online the CPU
  102. if ! online_cpu ${CPU_TO_TEST}; then
  103. tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
  104. fi
  105. sleep 2
  106. # Check that SAR registered the change in CPU online/offline states
  107. online_status=$(tail -n 1 "$LOG_FILE")
  108. check_passed=0
  109. for i in $(seq 3 8); do
  110. field_online=$(get_field "$online_status" "$i")
  111. if [ "$field_online" != "0.00" ]; then
  112. check_passed=1
  113. break
  114. fi
  115. done
  116. if [ $check_passed -eq 0 ]; then
  117. tst_resm TFAIL "No change in the CPU statistics"
  118. tst_exit
  119. fi
  120. offline_cpu ${CPU_TO_TEST}
  121. kill_pid ${SAR_PID}
  122. LOOP_COUNT=$((LOOP_COUNT+1))
  123. done
  124. tst_resm TPASS "SAR updated statistics after the CPU was turned on."
  125. tst_exit