Home | History | Annotate | Download | only in functional
      1 #!/bin/sh
      2 #
      3 # Test Case 5 - sar
      4 #
      5 
      6 export TCID="cpuhotplug05"
      7 export TST_TOTAL=1
      8 export LC_TIME="POSIX"
      9 
     10 # Includes:
     11 . test.sh
     12 . cpuhotplug_testsuite.sh
     13 . cpuhotplug_hotplug.sh
     14 
     15 cat <<EOF
     16 Name:   $TCID
     17 Date:   `date`
     18 Desc:   Does sar behave properly during CPU hotplug events?
     19 
     20 EOF
     21 
     22 usage()
     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 
     32 EOF
     33 	exit 1
     34 }
     35 
     36 do_clean()
     37 {
     38 	pid_is_valid ${SAR_PID} && kill_pid ${SAR_PID}
     39 }
     40 
     41 while getopts c:l:d: OPTION; do
     42 	case $OPTION in
     43 	c)
     44 		CPU_TO_TEST=$OPTARG;;
     45 	l)
     46 		HOTPLUG05_LOOPS=$OPTARG;;
     47 	d)
     48 		TMP=$OPTARG;;
     49 	?)
     50 		usage;;
     51 	esac
     52 done
     53 
     54 LOOP_COUNT=1
     55 
     56 tst_check_cmds sar
     57 
     58 if [ $(get_present_cpus_num) -lt 2 ]; then
     59 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
     60 fi
     61 
     62 if [ -z "$CPU_TO_TEST" ]; then
     63 	tst_brkm TBROK "usage: ${0##*} <CPU to offline>"
     64 fi
     65 
     66 # Validate the specified CPU is available
     67 if ! cpu_is_valid "${CPU_TO_TEST}" ; then
     68 	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
     69 fi
     70 
     71 # Check that the specified CPU is offline; if not, offline it
     72 if cpu_is_online "${CPU_TO_TEST}" ; then
     73 	if ! offline_cpu ${CPU_TO_TEST} ; then
     74 		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
     75 	fi
     76 fi
     77 
     78 TST_CLEANUP=do_clean
     79 
     80 until [ $LOOP_COUNT -gt $HOTPLUG05_LOOPS ]; do
     81 
     82 	# Start up SAR and give it a couple cycles to run
     83 	sar 1 0 &>/dev/null &
     84 	sleep 2
     85 	# "sar 1 0" is supported before 'sysstat-8.1.4(include sar)',
     86 	# after that use "sar 1" instead of. Use 'ps -C sar' to check.
     87 	if ps -C sar &>/dev/null; then
     88 		pkill sar
     89 		sar -P ALL 1 0 > $TMP/log_$$ &
     90 	else
     91 		sar -P ALL 1 > $TMP/log_$$ &
     92 	fi
     93 	sleep 2
     94 	SAR_PID=$!
     95 
     96 	# Verify that SAR has correctly listed the missing CPU
     97 	while ! awk '{print $8}' $TMP/log_$$ | grep -i "^0.00"; do
     98 		tst_brkm TBROK "CPU${CPU_TO_TEST} Not Found on SAR!"
     99 	done
    100 	time=`date +%X`
    101 	sleep .5
    102 
    103 	# Verify that at least some of the CPUs are offline
    104 	NUMBER_CPU_OFF=$(grep "$time" $TMP/log_$$ | awk '{print $8}' \
    105 		|grep -i "^0.00" | wc -l)
    106 	if [ ${NUMBER_CPU_OFF} -eq 0 ]; then
    107 		tst_brkm TBROK "no CPUs found offline"
    108 	fi
    109 
    110 	# Online the CPU
    111 	if ! online_cpu ${CPU_TO_TEST}; then
    112 		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined line"
    113 	fi
    114 
    115 	sleep 2
    116 	time=$(date +%T)
    117 	sleep .5
    118 
    119 	# Check that SAR registered the change in CPU online/offline states
    120 	NEW_NUMBER_CPU_OFF=$(grep "$time" $TMP/log_$$|awk '{print $8}' \
    121 		| grep -i "^0.00"| wc -l)
    122 	NUMBER_CPU_OFF=$((NUMBER_CPU_OFF-1))
    123 	if [ "$NUMBER_CPU_OFF" != "$NEW_NUMBER_CPU_OFF" ]; then
    124 		tst_resm TFAIL "no change in number of offline CPUs was found."
    125 		tst_exit
    126 	fi
    127 
    128 	offline_cpu ${CPU_TO_TEST}
    129 	kill_pid ${SAR_PID}
    130 
    131 	LOOP_COUNT=$((LOOP_COUNT+1))
    132 
    133 done
    134 
    135 tst_resm TPASS "CPU was found after turned on."
    136 
    137 tst_exit
    138