diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2012-07-30 17:43:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 20:25:22 -0400 |
commit | d89dffa976bcd13fd87eb76e02e3b71c3a7868e3 (patch) | |
tree | 28c6c2185aed3ebf3c0cea008ffd021cbc2d3cdc /tools/testing/selftests/cpu-hotplug | |
parent | 08dfb4ddeeeebdee4f3d5a08a87dc9aa68d26f81 (diff) |
fault-injection: add selftests for cpu and memory hotplug
This adds two selftests
* tools/testing/selftests/cpu-hotplug/on-off-test.sh is testing script
for CPU hotplug
1. Online all hot-pluggable CPUs
2. Offline all hot-pluggable CPUs
3. Online all hot-pluggable CPUs again
4. Exit if cpu-notifier-error-inject.ko is not available
5. Offline all hot-pluggable CPUs in preparation for testing
6. Test CPU hot-add error handling by injecting notifier errors
7. Online all hot-pluggable CPUs in preparation for testing
8. Test CPU hot-remove error handling by injecting notifier errors
* tools/testing/selftests/memory-hotplug/on-off-test.sh is doing the
similar thing for memory hotplug.
1. Online all hot-pluggable memory
2. Offline 10% of hot-pluggable memory
3. Online all hot-pluggable memory again
4. Exit if memory-notifier-error-inject.ko is not available
5. Offline 10% of hot-pluggable memory in preparation for testing
6. Test memory hot-add error handling by injecting notifier errors
7. Online all hot-pluggable memory in preparation for testing
8. Test memory hot-remove error handling by injecting notifier errors
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Greg KH <greg@kroah.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Dave Jones <davej@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing/selftests/cpu-hotplug')
-rw-r--r-- | tools/testing/selftests/cpu-hotplug/Makefile | 6 | ||||
-rw-r--r-- | tools/testing/selftests/cpu-hotplug/on-off-test.sh | 221 |
2 files changed, 227 insertions, 0 deletions
diff --git a/tools/testing/selftests/cpu-hotplug/Makefile b/tools/testing/selftests/cpu-hotplug/Makefile new file mode 100644 index 000000000000..7c9c20ff578a --- /dev/null +++ b/tools/testing/selftests/cpu-hotplug/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | all: | ||
2 | |||
3 | run_tests: | ||
4 | ./on-off-test.sh | ||
5 | |||
6 | clean: | ||
diff --git a/tools/testing/selftests/cpu-hotplug/on-off-test.sh b/tools/testing/selftests/cpu-hotplug/on-off-test.sh new file mode 100644 index 000000000000..bdde7cf428bb --- /dev/null +++ b/tools/testing/selftests/cpu-hotplug/on-off-test.sh | |||
@@ -0,0 +1,221 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | SYSFS= | ||
4 | |||
5 | prerequisite() | ||
6 | { | ||
7 | msg="skip all tests:" | ||
8 | |||
9 | if [ $UID != 0 ]; then | ||
10 | echo $msg must be run as root >&2 | ||
11 | exit 0 | ||
12 | fi | ||
13 | |||
14 | SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` | ||
15 | |||
16 | if [ ! -d "$SYSFS" ]; then | ||
17 | echo $msg sysfs is not mounted >&2 | ||
18 | exit 0 | ||
19 | fi | ||
20 | |||
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 | ||
24 | fi | ||
25 | } | ||
26 | |||
27 | # | ||
28 | # list all hot-pluggable CPUs | ||
29 | # | ||
30 | hotpluggable_cpus() | ||
31 | { | ||
32 | local state=${1:-.\*} | ||
33 | |||
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} | ||
37 | fi | ||
38 | done | ||
39 | } | ||
40 | |||
41 | hotplaggable_offline_cpus() | ||
42 | { | ||
43 | hotpluggable_cpus 0 | ||
44 | } | ||
45 | |||
46 | hotpluggable_online_cpus() | ||
47 | { | ||
48 | hotpluggable_cpus 1 | ||
49 | } | ||
50 | |||
51 | cpu_is_online() | ||
52 | { | ||
53 | grep -q 1 $SYSFS/devices/system/cpu/cpu$1/online | ||
54 | } | ||
55 | |||
56 | cpu_is_offline() | ||
57 | { | ||
58 | grep -q 0 $SYSFS/devices/system/cpu/cpu$1/online | ||
59 | } | ||
60 | |||
61 | online_cpu() | ||
62 | { | ||
63 | echo 1 > $SYSFS/devices/system/cpu/cpu$1/online | ||
64 | } | ||
65 | |||
66 | offline_cpu() | ||
67 | { | ||
68 | echo 0 > $SYSFS/devices/system/cpu/cpu$1/online | ||
69 | } | ||
70 | |||
71 | online_cpu_expect_success() | ||
72 | { | ||
73 | local cpu=$1 | ||
74 | |||
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 | ||
79 | fi | ||
80 | } | ||
81 | |||
82 | online_cpu_expect_fail() | ||
83 | { | ||
84 | local cpu=$1 | ||
85 | |||
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 | ||
90 | fi | ||
91 | } | ||
92 | |||
93 | offline_cpu_expect_success() | ||
94 | { | ||
95 | local cpu=$1 | ||
96 | |||
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 | ||
101 | fi | ||
102 | } | ||
103 | |||
104 | offline_cpu_expect_fail() | ||
105 | { | ||
106 | local cpu=$1 | ||
107 | |||
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 | ||
112 | fi | ||
113 | } | ||
114 | |||
115 | error=-12 | ||
116 | priority=0 | ||
117 | |||
118 | while getopts e:hp: opt; do | ||
119 | case $opt in | ||
120 | e) | ||
121 | error=$OPTARG | ||
122 | ;; | ||
123 | h) | ||
124 | echo "Usage $0 [ -e errno ] [ -p notifier-priority ]" | ||
125 | exit | ||
126 | ;; | ||
127 | p) | ||
128 | priority=$OPTARG | ||
129 | ;; | ||
130 | esac | ||
131 | done | ||
132 | |||
133 | if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then | ||
134 | echo "error code must be -4095 <= errno < 0" >&2 | ||
135 | exit 1 | ||
136 | fi | ||
137 | |||
138 | prerequisite | ||
139 | |||
140 | # | ||
141 | # Online all hot-pluggable CPUs | ||
142 | # | ||
143 | for cpu in `hotplaggable_offline_cpus`; do | ||
144 | online_cpu_expect_success $cpu | ||
145 | done | ||
146 | |||
147 | # | ||
148 | # Offline all hot-pluggable CPUs | ||
149 | # | ||
150 | for cpu in `hotpluggable_online_cpus`; do | ||
151 | offline_cpu_expect_success $cpu | ||
152 | done | ||
153 | |||
154 | # | ||
155 | # Online all hot-pluggable CPUs again | ||
156 | # | ||
157 | for cpu in `hotplaggable_offline_cpus`; do | ||
158 | online_cpu_expect_success $cpu | ||
159 | done | ||
160 | |||
161 | # | ||
162 | # Test with cpu notifier error injection | ||
163 | # | ||
164 | |||
165 | DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'` | ||
166 | NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/cpu | ||
167 | |||
168 | prerequisite_extra() | ||
169 | { | ||
170 | msg="skip extra tests:" | ||
171 | |||
172 | /sbin/modprobe -q -r cpu-notifier-error-inject | ||
173 | /sbin/modprobe -q cpu-notifier-error-inject priority=$priority | ||
174 | |||
175 | if [ ! -d "$DEBUGFS" ]; then | ||
176 | echo $msg debugfs is not mounted >&2 | ||
177 | exit 0 | ||
178 | fi | ||
179 | |||
180 | if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then | ||
181 | echo $msg cpu-notifier-error-inject module is not available >&2 | ||
182 | exit 0 | ||
183 | fi | ||
184 | } | ||
185 | |||
186 | prerequisite_extra | ||
187 | |||
188 | # | ||
189 | # Offline all hot-pluggable CPUs | ||
190 | # | ||
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 | ||
195 | |||
196 | # | ||
197 | # Test CPU hot-add error handling (offline => online) | ||
198 | # | ||
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 | ||
203 | |||
204 | # | ||
205 | # Online all hot-pluggable CPUs | ||
206 | # | ||
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 | ||
211 | |||
212 | # | ||
213 | # Test CPU hot-remove error handling (online => offline) | ||
214 | # | ||
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 | ||
219 | |||
220 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error | ||
221 | /sbin/modprobe -q -r cpu-notifier-error-inject | ||