x86, cpufeature: If we disable CLFLUSH, we should disable CLFLUSHOPT
[linux/fpc-iii.git] / tools / testing / selftests / cpu-hotplug / on-off-test.sh
blobbdde7cf428bbf8f40f92fb556573896f6e651892
1 #!/bin/bash
3 SYSFS=
5 prerequisite()
7 msg="skip all tests:"
9 if [ $UID != 0 ]; then
10 echo $msg must be run as root >&2
11 exit 0
14 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
16 if [ ! -d "$SYSFS" ]; then
17 echo $msg sysfs is not mounted >&2
18 exit 0
21 if ! ls $SYSFS/devices/system/cpu/cpu* > /dev/null 2>&1; then
22 echo $msg cpu hotplug is not supported >&2
23 exit 0
28 # list all hot-pluggable CPUs
30 hotpluggable_cpus()
32 local state=${1:-.\*}
34 for cpu in $SYSFS/devices/system/cpu/cpu*; do
35 if [ -f $cpu/online ] && grep -q $state $cpu/online; then
36 echo ${cpu##/*/cpu}
38 done
41 hotplaggable_offline_cpus()
43 hotpluggable_cpus 0
46 hotpluggable_online_cpus()
48 hotpluggable_cpus 1
51 cpu_is_online()
53 grep -q 1 $SYSFS/devices/system/cpu/cpu$1/online
56 cpu_is_offline()
58 grep -q 0 $SYSFS/devices/system/cpu/cpu$1/online
61 online_cpu()
63 echo 1 > $SYSFS/devices/system/cpu/cpu$1/online
66 offline_cpu()
68 echo 0 > $SYSFS/devices/system/cpu/cpu$1/online
71 online_cpu_expect_success()
73 local cpu=$1
75 if ! online_cpu $cpu; then
76 echo $FUNCNAME $cpu: unexpected fail >&2
77 elif ! cpu_is_online $cpu; then
78 echo $FUNCNAME $cpu: unexpected offline >&2
82 online_cpu_expect_fail()
84 local cpu=$1
86 if online_cpu $cpu 2> /dev/null; then
87 echo $FUNCNAME $cpu: unexpected success >&2
88 elif ! cpu_is_offline $cpu; then
89 echo $FUNCNAME $cpu: unexpected online >&2
93 offline_cpu_expect_success()
95 local cpu=$1
97 if ! offline_cpu $cpu; then
98 echo $FUNCNAME $cpu: unexpected fail >&2
99 elif ! cpu_is_offline $cpu; then
100 echo $FUNCNAME $cpu: unexpected offline >&2
104 offline_cpu_expect_fail()
106 local cpu=$1
108 if offline_cpu $cpu 2> /dev/null; then
109 echo $FUNCNAME $cpu: unexpected success >&2
110 elif ! cpu_is_online $cpu; then
111 echo $FUNCNAME $cpu: unexpected offline >&2
115 error=-12
116 priority=0
118 while getopts e:hp: opt; do
119 case $opt in
121 error=$OPTARG
124 echo "Usage $0 [ -e errno ] [ -p notifier-priority ]"
125 exit
128 priority=$OPTARG
130 esac
131 done
133 if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then
134 echo "error code must be -4095 <= errno < 0" >&2
135 exit 1
138 prerequisite
141 # Online all hot-pluggable CPUs
143 for cpu in `hotplaggable_offline_cpus`; do
144 online_cpu_expect_success $cpu
145 done
148 # Offline all hot-pluggable CPUs
150 for cpu in `hotpluggable_online_cpus`; do
151 offline_cpu_expect_success $cpu
152 done
155 # Online all hot-pluggable CPUs again
157 for cpu in `hotplaggable_offline_cpus`; do
158 online_cpu_expect_success $cpu
159 done
162 # Test with cpu notifier error injection
165 DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'`
166 NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/cpu
168 prerequisite_extra()
170 msg="skip extra tests:"
172 /sbin/modprobe -q -r cpu-notifier-error-inject
173 /sbin/modprobe -q cpu-notifier-error-inject priority=$priority
175 if [ ! -d "$DEBUGFS" ]; then
176 echo $msg debugfs is not mounted >&2
177 exit 0
180 if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
181 echo $msg cpu-notifier-error-inject module is not available >&2
182 exit 0
186 prerequisite_extra
189 # Offline all hot-pluggable CPUs
191 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error
192 for cpu in `hotpluggable_online_cpus`; do
193 offline_cpu_expect_success $cpu
194 done
197 # Test CPU hot-add error handling (offline => online)
199 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_UP_PREPARE/error
200 for cpu in `hotplaggable_offline_cpus`; do
201 online_cpu_expect_fail $cpu
202 done
205 # Online all hot-pluggable CPUs
207 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_UP_PREPARE/error
208 for cpu in `hotplaggable_offline_cpus`; do
209 online_cpu_expect_success $cpu
210 done
213 # Test CPU hot-remove error handling (online => offline)
215 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error
216 for cpu in `hotpluggable_online_cpus`; do
217 offline_cpu_expect_fail $cpu
218 done
220 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error
221 /sbin/modprobe -q -r cpu-notifier-error-inject