• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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}
40
41while 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
52done
53
54LOOP_COUNT=1
55
56tst_check_cmds sar
57
58if [ $(get_present_cpus_num) -lt 2 ]; then
59	tst_brkm TCONF "system doesn't have required CPU hotplug support"
60fi
61
62if [ -z "$CPU_TO_TEST" ]; then
63	tst_brkm TBROK "usage: ${0##*} <CPU to offline>"
64fi
65
66# Validate the specified CPU is available
67if ! cpu_is_valid "${CPU_TO_TEST}" ; then
68	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
69fi
70
71# Check that the specified CPU is offline; if not, offline it
72if 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
76fi
77
78TST_CLEANUP=do_clean
79
80until [ $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 2>&1 &
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 2>&1; 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
133done
134
135tst_resm TPASS "CPU was found after turned on."
136
137tst_exit
138