• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Test Case 4
4#
5
6export TCID="cpuhotplug04"
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 it prevent us from offlining the last CPU?
18
19EOF
20
21usage()
22{
23	cat << EOF
24	usage: $0 -l loop
25
26	OPTIONS
27		-l  number of cycle test
28
29EOF
30	exit 1
31}
32
33do_clean()
34{
35	# Online the ones that were on initially
36	# Restore CPU states
37	set_all_cpu_states "$cpu_states"
38}
39
40while getopts l: OPTION; do
41	case $OPTION in
42	l)
43		HOTPLUG04_LOOPS=$OPTARG;;
44	?)
45		usage;;
46	esac
47done
48
49LOOP_COUNT=1
50
51if tst_virt_hyperv; then
52	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
53fi
54
55cpus_num=$(get_present_cpus_num)
56if [ $cpus_num -lt 2 ]; then
57	tst_brkm TCONF "system doesn't have required CPU hotplug support"
58fi
59
60if [ $(get_hotplug_cpus_num) -lt 1 ]; then
61	tst_brkm TCONF "system doesn't have at least one hotpluggable CPU"
62fi
63
64TST_CLEANUP=do_clean
65
66cpu_states=$(get_all_cpu_states)
67
68until [ $LOOP_COUNT -gt $HOTPLUG04_LOOPS ]; do
69
70	# Online all the hotpluggable CPUs
71	for i in $(get_hotplug_cpus); do
72		if ! cpu_is_online $i; then
73			if ! online_cpu $i; then
74				tst_brkm TBROK "$i can not be onlined"
75			fi
76		fi
77	done
78
79	# Now offline them
80	cpu=0
81	for i in $(get_hotplug_cpus); do
82		cpu=$((cpu + 1))
83
84		# If all the CPUs are hotpluggable, we expect
85		# that the kernel will refuse to offline the last CPU.
86		# If only some of the CPUs are hotpluggable,
87		# they all can be offlined.
88		if [ $cpu -eq $cpus_num ]; then
89			if offline_cpu $i 2> /dev/null; then
90				tst_brkm TFAIL "Have we just offlined the last CPU?"
91			else
92				tst_resm TPASS "System prevented us from offlining the last CPU - $i"
93			fi
94		else
95			if ! offline_cpu $i; then
96				tst_brkm TFAIL "Could not offline $i"
97			fi
98		fi
99	done
100
101	LOOP_COUNT=$((LOOP_COUNT+1))
102
103done
104
105tst_resm TPASS "Success"
106
107tst_exit
108