• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 top -v | grep -q htop; then
53	tst_brkm TCONF "htop is used instead of top (workaround: alias top='/path/to/real/top')"
54fi
55
56if [ $(get_present_cpus_num) -lt 2 ]; then
57	tst_brkm TCONF "system doesn't have required CPU hotplug support"
58fi
59
60if [ -z "$CPU_TO_TEST" ]; then
61	tst_brkm TBROK "Usage: ${0##*/} <CPU to offline>"
62fi
63
64# Verify that the specified CPU is available
65if ! cpu_is_valid "${CPU_TO_TEST}" ; then
66	tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug"
67fi
68
69# Check that the specified CPU is online; if not, online it
70if ! cpu_is_online "${CPU_TO_TEST}" ; then
71	if ! online_cpu ${CPU_TO_TEST}; then
72		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
73	fi
74fi
75
76TST_CLEANUP=do_clean
77
78until [ $LOOP_COUNT -gt $HOTPLUG06_LOOPS ]; do
79	# Start up top and give it a little time to run
80	top -b -d 00.10 > /dev/null 2>&1 &
81	TOP_PID=$!
82	sleep 1
83
84	# Now offline the CPU
85	if ! offline_cpu ${CPU_TO_TEST} ; then
86		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
87	fi
88
89	# Wait a little time for top to notice the CPU is gone
90	sleep 1
91
92	# Check that top hasn't crashed
93	if ! pid_is_valid ${TOP_PID} ; then
94		tst_resm TFAIL "PID ${TOP_PID} no longer running"
95		tst_exit
96	fi
97
98	online_cpu ${CPU_TO_TEST}
99	kill_pid ${TOP_PID}
100
101	LOOP_COUNT=$((LOOP_COUNT+1))
102
103done
104
105tst_resm TPASS "PID ${TOP_PID} still running."
106
107tst_exit
108