aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/memory-hotplug
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2012-07-30 17:43:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:22 -0400
commitd89dffa976bcd13fd87eb76e02e3b71c3a7868e3 (patch)
tree28c6c2185aed3ebf3c0cea008ffd021cbc2d3cdc /tools/testing/selftests/memory-hotplug
parent08dfb4ddeeeebdee4f3d5a08a87dc9aa68d26f81 (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/memory-hotplug')
-rw-r--r--tools/testing/selftests/memory-hotplug/Makefile6
-rw-r--r--tools/testing/selftests/memory-hotplug/on-off-test.sh230
2 files changed, 236 insertions, 0 deletions
diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
new file mode 100644
index 000000000000..7c9c20ff578a
--- /dev/null
+++ b/tools/testing/selftests/memory-hotplug/Makefile
@@ -0,0 +1,6 @@
1all:
2
3run_tests:
4 ./on-off-test.sh
5
6clean:
diff --git a/tools/testing/selftests/memory-hotplug/on-off-test.sh b/tools/testing/selftests/memory-hotplug/on-off-test.sh
new file mode 100644
index 000000000000..a2816f631542
--- /dev/null
+++ b/tools/testing/selftests/memory-hotplug/on-off-test.sh
@@ -0,0 +1,230 @@
1#!/bin/bash
2
3SYSFS=
4
5prerequisite()
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/memory/memory* > /dev/null 2>&1; then
22 echo $msg memory hotplug is not supported >&2
23 exit 0
24 fi
25}
26
27#
28# list all hot-pluggable memory
29#
30hotpluggable_memory()
31{
32 local state=${1:-.\*}
33
34 for memory in $SYSFS/devices/system/memory/memory*; do
35 if grep -q 1 $memory/removable &&
36 grep -q $state $memory/state; then
37 echo ${memory##/*/memory}
38 fi
39 done
40}
41
42hotplaggable_offline_memory()
43{
44 hotpluggable_memory offline
45}
46
47hotpluggable_online_memory()
48{
49 hotpluggable_memory online
50}
51
52memory_is_online()
53{
54 grep -q online $SYSFS/devices/system/memory/memory$1/state
55}
56
57memory_is_offline()
58{
59 grep -q offline $SYSFS/devices/system/memory/memory$1/state
60}
61
62online_memory()
63{
64 echo online > $SYSFS/devices/system/memory/memory$1/state
65}
66
67offline_memory()
68{
69 echo offline > $SYSFS/devices/system/memory/memory$1/state
70}
71
72online_memory_expect_success()
73{
74 local memory=$1
75
76 if ! online_memory $memory; then
77 echo $FUNCNAME $memory: unexpected fail >&2
78 elif ! memory_is_online $memory; then
79 echo $FUNCNAME $memory: unexpected offline >&2
80 fi
81}
82
83online_memory_expect_fail()
84{
85 local memory=$1
86
87 if online_memory $memory 2> /dev/null; then
88 echo $FUNCNAME $memory: unexpected success >&2
89 elif ! memory_is_offline $memory; then
90 echo $FUNCNAME $memory: unexpected online >&2
91 fi
92}
93
94offline_memory_expect_success()
95{
96 local memory=$1
97
98 if ! offline_memory $memory; then
99 echo $FUNCNAME $memory: unexpected fail >&2
100 elif ! memory_is_offline $memory; then
101 echo $FUNCNAME $memory: unexpected offline >&2
102 fi
103}
104
105offline_memory_expect_fail()
106{
107 local memory=$1
108
109 if offline_memory $memory 2> /dev/null; then
110 echo $FUNCNAME $memory: unexpected success >&2
111 elif ! memory_is_online $memory; then
112 echo $FUNCNAME $memory: unexpected offline >&2
113 fi
114}
115
116error=-12
117priority=0
118ratio=10
119
120while getopts e:hp:r: opt; do
121 case $opt in
122 e)
123 error=$OPTARG
124 ;;
125 h)
126 echo "Usage $0 [ -e errno ] [ -p notifier-priority ] [ -r percent-of-memory-to-offline ]"
127 exit
128 ;;
129 p)
130 priority=$OPTARG
131 ;;
132 r)
133 ratio=$OPTARG
134 ;;
135 esac
136done
137
138if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then
139 echo "error code must be -4095 <= errno < 0" >&2
140 exit 1
141fi
142
143prerequisite
144
145#
146# Online all hot-pluggable memory
147#
148for memory in `hotplaggable_offline_memory`; do
149 online_memory_expect_success $memory
150done
151
152#
153# Offline $ratio percent of hot-pluggable memory
154#
155for memory in `hotpluggable_online_memory`; do
156 if [ $((RANDOM % 100)) -lt $ratio ]; then
157 offline_memory_expect_success $memory
158 fi
159done
160
161#
162# Online all hot-pluggable memory again
163#
164for memory in `hotplaggable_offline_memory`; do
165 online_memory_expect_success $memory
166done
167
168#
169# Test with memory notifier error injection
170#
171
172DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'`
173NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/memory
174
175prerequisite_extra()
176{
177 msg="skip extra tests:"
178
179 /sbin/modprobe -q -r memory-notifier-error-inject
180 /sbin/modprobe -q memory-notifier-error-inject priority=$priority
181
182 if [ ! -d "$DEBUGFS" ]; then
183 echo $msg debugfs is not mounted >&2
184 exit 0
185 fi
186
187 if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
188 echo $msg memory-notifier-error-inject module is not available >&2
189 exit 0
190 fi
191}
192
193prerequisite_extra
194
195#
196# Offline $ratio percent of hot-pluggable memory
197#
198echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
199for memory in `hotpluggable_online_memory`; do
200 if [ $((RANDOM % 100)) -lt $ratio ]; then
201 offline_memory_expect_success $memory
202 fi
203done
204
205#
206# Test memory hot-add error handling (offline => online)
207#
208echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
209for memory in `hotplaggable_offline_memory`; do
210 online_memory_expect_fail $memory
211done
212
213#
214# Online all hot-pluggable memory
215#
216echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
217for memory in `hotplaggable_offline_memory`; do
218 online_memory_expect_success $memory
219done
220
221#
222# Test memory hot-remove error handling (online => offline)
223#
224echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
225for memory in `hotpluggable_online_memory`; do
226 offline_memory_expect_fail $memory
227done
228
229echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
230/sbin/modprobe -q -r memory-notifier-error-inject