1#!/bin/sh
2#
3# Test Case 6 - top
4#
5
6export TCID="cpuhotplug06"
7export TST_TOTAL=1
8
9# Includes:
10. test.sh
11. cpuhotplug_testsuite.sh
12. cpuhotplug_hotplug.sh
13
14cat <<EOF
15Name:   $TCID
16Date:   `date`
17Desc:   Does top work properly when CPU hotplug events occur?
18
19EOF
20
21usage()
22{
23	cat << EOF
24	usage: $0 -c cpu -l loop
25
26	OPTIONS
27		-c  cpu which is specified for testing
28		-l  number of cycle test
29
30EOF
31	exit 1
32}
33
34do_clean()
35{
36	pid_is_valid ${TOP_PID} && kill_pid ${TOP_PID}
37}
38
39while getopts c:l: OPTION; do
40	case $OPTION in
41	c)
42		CPU_TO_TEST=$OPTARG;;
43	l)
44		HOTPLUG06_LOOPS=$OPTARG;;
45	?)
46		usage;;
47	esac
48done
49
50LOOP_COUNT=1
51
52if [ $(get_present_cpus_num) -lt 2 ]; then
53	tst_brkm TCONF "system doesn't have required CPU hotplug support"
54fi
55
56if [ -z "$CPU_TO_TEST" ]; then
57	tst_brkm TBROK "Usage: ${0##*/} <CPU to offline>"
58fi
59
60# Verify that the specified CPU is available
61if ! cpu_is_valid "${CPU_TO_TEST}" ; then
62	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
63fi
64
65# Check that the specified CPU is online; if not, online it
66if ! cpu_is_online "${CPU_TO_TEST}" ; then
67	if ! online_cpu ${CPU_TO_TEST}; then
68		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
69	fi
70fi
71
72TST_CLEANUP=do_clean
73
74until [ $LOOP_COUNT -gt $HOTPLUG06_LOOPS ]; do
75	# Start up top and give it a little time to run
76	top -b -d 00.10 > /dev/null 2>&1 &
77	TOP_PID=$!
78	sleep 1
79
80	# Now offline the CPU
81	if ! offline_cpu ${CPU_TO_TEST} ; then
82		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
83	fi
84
85	# Wait a little time for top to notice the CPU is gone
86	sleep 1
87
88	# Check that top hasn't crashed
89	if ! pid_is_valid ${TOP_PID} ; then
90		tst_resm TFAIL "PID ${TOP_PID} no longer running"
91		tst_exit
92	fi
93
94	online_cpu ${CPU_TO_TEST}
95	kill_pid ${TOP_PID}
96
97	LOOP_COUNT=$((LOOP_COUNT+1))
98
99done
100
101tst_resm TPASS "PID ${TOP_PID} still running."
102
103tst_exit
104