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