diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 20:25:34 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 20:25:34 -0400 |
commit | 27c1ee3f929555b71fa39ec0d81a7e7185de1b16 (patch) | |
tree | 42e40bdfe4efac660d650658019391536ce67a42 /tools/testing | |
parent | 37cd9600a9e20359b0283983c9e3a55d84347168 (diff) | |
parent | 086ff4b3a7fb9cdf41e6a5d0ccd99b86d84633a1 (diff) |
Merge branch 'akpm' (Andrew's patch-bomb)
Merge Andrew's first set of patches:
"Non-MM patches:
- lots of misc bits
- tree-wide have_clk() cleanups
- quite a lot of printk tweaks. I draw your attention to "printk:
convert the format for KERN_<LEVEL> to a 2 byte pattern" which
looks a bit scary. But afaict it's solid.
- backlight updates
- lib/ feature work (notably the addition and use of memweight())
- checkpatch updates
- rtc updates
- nilfs updates
- fatfs updates (partial, still waiting for acks)
- kdump, proc, fork, IPC, sysctl, taskstats, pps, etc
- new fault-injection feature work"
* Merge emailed patches from Andrew Morton <akpm@linux-foundation.org>: (128 commits)
drivers/misc/lkdtm.c: fix missing allocation failure check
lib/scatterlist: do not re-write gfp_flags in __sg_alloc_table()
fault-injection: add tool to run command with failslab or fail_page_alloc
fault-injection: add selftests for cpu and memory hotplug
powerpc: pSeries reconfig notifier error injection module
memory: memory notifier error injection module
PM: PM notifier error injection module
cpu: rewrite cpu-notifier-error-inject module
fault-injection: notifier error injection
c/r: fcntl: add F_GETOWNER_UIDS option
resource: make sure requested range is included in the root range
include/linux/aio.h: cpp->C conversions
fs: cachefiles: add support for large files in filesystem caching
pps: return PTR_ERR on error in device_create
taskstats: check nla_reserve() return
sysctl: suppress kmemleak messages
ipc: use Kconfig options for __ARCH_WANT_[COMPAT_]IPC_PARSE_VERSION
ipc: compat: use signed size_t types for msgsnd and msgrcv
ipc: allow compat IPC version field parsing if !ARCH_WANT_OLD_COMPAT_IPC
ipc: add COMPAT_SHMLBA support
...
Diffstat (limited to 'tools/testing')
-rw-r--r-- | tools/testing/fault-injection/failcmd.sh | 219 | ||||
-rw-r--r-- | tools/testing/selftests/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/selftests/cpu-hotplug/Makefile | 6 | ||||
-rw-r--r-- | tools/testing/selftests/cpu-hotplug/on-off-test.sh | 221 | ||||
-rw-r--r-- | tools/testing/selftests/memory-hotplug/Makefile | 6 | ||||
-rw-r--r-- | tools/testing/selftests/memory-hotplug/on-off-test.sh | 230 |
6 files changed, 683 insertions, 1 deletions
diff --git a/tools/testing/fault-injection/failcmd.sh b/tools/testing/fault-injection/failcmd.sh new file mode 100644 index 000000000000..1776e924b202 --- /dev/null +++ b/tools/testing/fault-injection/failcmd.sh | |||
@@ -0,0 +1,219 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # NAME | ||
4 | # failcmd.sh - run a command with injecting slab/page allocation failures | ||
5 | # | ||
6 | # SYNOPSIS | ||
7 | # failcmd.sh --help | ||
8 | # failcmd.sh [<options>] command [arguments] | ||
9 | # | ||
10 | # DESCRIPTION | ||
11 | # Run command with injecting slab/page allocation failures by fault | ||
12 | # injection. | ||
13 | # | ||
14 | # NOTE: you need to run this script as root. | ||
15 | # | ||
16 | |||
17 | usage() | ||
18 | { | ||
19 | cat >&2 <<EOF | ||
20 | Usage: $0 [options] command [arguments] | ||
21 | |||
22 | OPTIONS | ||
23 | -p percent | ||
24 | --probability=percent | ||
25 | likelihood of failure injection, in percent. | ||
26 | Default value is 1 | ||
27 | |||
28 | -t value | ||
29 | --times=value | ||
30 | specifies how many times failures may happen at most. | ||
31 | Default value is 1 | ||
32 | |||
33 | --oom-kill-allocating-task=value | ||
34 | set /proc/sys/vm/oom_kill_allocating_task to specified value | ||
35 | before running the command. | ||
36 | Default value is 1 | ||
37 | |||
38 | -h, --help | ||
39 | Display a usage message and exit | ||
40 | |||
41 | --interval=value, --space=value, --verbose=value, --task-filter=value, | ||
42 | --stacktrace-depth=value, --require-start=value, --require-end=value, | ||
43 | --reject-start=value, --reject-end=value, --ignore-gfp-wait=value | ||
44 | See Documentation/fault-injection/fault-injection.txt for more | ||
45 | information | ||
46 | |||
47 | failslab options: | ||
48 | --cache-filter=value | ||
49 | |||
50 | fail_page_alloc options: | ||
51 | --ignore-gfp-highmem=value, --min-order=value | ||
52 | |||
53 | ENVIRONMENT | ||
54 | FAILCMD_TYPE | ||
55 | The following values for FAILCMD_TYPE are recognized: | ||
56 | |||
57 | failslab | ||
58 | inject slab allocation failures | ||
59 | fail_page_alloc | ||
60 | inject page allocation failures | ||
61 | |||
62 | If FAILCMD_TYPE is not defined, then failslab is used. | ||
63 | EOF | ||
64 | } | ||
65 | |||
66 | if [ $UID != 0 ]; then | ||
67 | echo must be run as root >&2 | ||
68 | exit 1 | ||
69 | fi | ||
70 | |||
71 | DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3}'` | ||
72 | |||
73 | if [ ! -d "$DEBUGFS" ]; then | ||
74 | echo debugfs is not mounted >&2 | ||
75 | exit 1 | ||
76 | fi | ||
77 | |||
78 | FAILCMD_TYPE=${FAILCMD_TYPE:-failslab} | ||
79 | FAULTATTR=$DEBUGFS/$FAILCMD_TYPE | ||
80 | |||
81 | if [ ! -d $FAULTATTR ]; then | ||
82 | echo $FAILCMD_TYPE is not available >&2 | ||
83 | exit 1 | ||
84 | fi | ||
85 | |||
86 | LONGOPTS=probability:,interval:,times:,space:,verbose:,task-filter: | ||
87 | LONGOPTS=$LONGOPTS,stacktrace-depth:,require-start:,require-end: | ||
88 | LONGOPTS=$LONGOPTS,reject-start:,reject-end:,oom-kill-allocating-task:,help | ||
89 | |||
90 | if [ $FAILCMD_TYPE = failslab ]; then | ||
91 | LONGOPTS=$LONGOPTS,ignore-gfp-wait:,cache-filter: | ||
92 | elif [ $FAILCMD_TYPE = fail_page_alloc ]; then | ||
93 | LONGOPTS=$LONGOPTS,ignore-gfp-wait:,ignore-gfp-highmem:,min-order: | ||
94 | fi | ||
95 | |||
96 | TEMP=`getopt -o p:i:t:s:v:h --long $LONGOPTS -n 'failcmd.sh' -- "$@"` | ||
97 | |||
98 | if [ $? != 0 ]; then | ||
99 | usage | ||
100 | exit 1 | ||
101 | fi | ||
102 | |||
103 | eval set -- "$TEMP" | ||
104 | |||
105 | fault_attr_default() | ||
106 | { | ||
107 | echo N > $FAULTATTR/task-filter | ||
108 | echo 0 > $FAULTATTR/probability | ||
109 | echo 1 > $FAULTATTR/times | ||
110 | } | ||
111 | |||
112 | fault_attr_default | ||
113 | |||
114 | oom_kill_allocating_task_saved=`cat /proc/sys/vm/oom_kill_allocating_task` | ||
115 | |||
116 | restore_values() | ||
117 | { | ||
118 | fault_attr_default | ||
119 | echo $oom_kill_allocating_task_saved \ | ||
120 | > /proc/sys/vm/oom_kill_allocating_task | ||
121 | } | ||
122 | |||
123 | # | ||
124 | # Default options | ||
125 | # | ||
126 | declare -i oom_kill_allocating_task=1 | ||
127 | declare task_filter=Y | ||
128 | declare -i probability=1 | ||
129 | declare -i times=1 | ||
130 | |||
131 | while true; do | ||
132 | case "$1" in | ||
133 | -p|--probability) | ||
134 | probability=$2 | ||
135 | shift 2 | ||
136 | ;; | ||
137 | -i|--interval) | ||
138 | echo $2 > $FAULTATTR/interval | ||
139 | shift 2 | ||
140 | ;; | ||
141 | -t|--times) | ||
142 | times=$2 | ||
143 | shift 2 | ||
144 | ;; | ||
145 | -s|--space) | ||
146 | echo $2 > $FAULTATTR/space | ||
147 | shift 2 | ||
148 | ;; | ||
149 | -v|--verbose) | ||
150 | echo $2 > $FAULTATTR/verbose | ||
151 | shift 2 | ||
152 | ;; | ||
153 | --task-filter) | ||
154 | task_filter=$2 | ||
155 | shift 2 | ||
156 | ;; | ||
157 | --stacktrace-depth) | ||
158 | echo $2 > $FAULTATTR/stacktrace-depth | ||
159 | shift 2 | ||
160 | ;; | ||
161 | --require-start) | ||
162 | echo $2 > $FAULTATTR/require-start | ||
163 | shift 2 | ||
164 | ;; | ||
165 | --require-end) | ||
166 | echo $2 > $FAULTATTR/require-end | ||
167 | shift 2 | ||
168 | ;; | ||
169 | --reject-start) | ||
170 | echo $2 > $FAULTATTR/reject-start | ||
171 | shift 2 | ||
172 | ;; | ||
173 | --reject-end) | ||
174 | echo $2 > $FAULTATTR/reject-end | ||
175 | shift 2 | ||
176 | ;; | ||
177 | --oom-kill-allocating-task) | ||
178 | oom_kill_allocating_task=$2 | ||
179 | shift 2 | ||
180 | ;; | ||
181 | --ignore-gfp-wait) | ||
182 | echo $2 > $FAULTATTR/ignore-gfp-wait | ||
183 | shift 2 | ||
184 | ;; | ||
185 | --cache-filter) | ||
186 | echo $2 > $FAULTATTR/cache_filter | ||
187 | shift 2 | ||
188 | ;; | ||
189 | --ignore-gfp-highmem) | ||
190 | echo $2 > $FAULTATTR/ignore-gfp-highmem | ||
191 | shift 2 | ||
192 | ;; | ||
193 | --min-order) | ||
194 | echo $2 > $FAULTATTR/min-order | ||
195 | shift 2 | ||
196 | ;; | ||
197 | -h|--help) | ||
198 | usage | ||
199 | exit 0 | ||
200 | shift | ||
201 | ;; | ||
202 | --) | ||
203 | shift | ||
204 | break | ||
205 | ;; | ||
206 | esac | ||
207 | done | ||
208 | |||
209 | [ -z "$@" ] && exit 0 | ||
210 | |||
211 | echo $oom_kill_allocating_task > /proc/sys/vm/oom_kill_allocating_task | ||
212 | echo $task_filter > $FAULTATTR/task-filter | ||
213 | echo $probability > $FAULTATTR/probability | ||
214 | echo $times > $FAULTATTR/times | ||
215 | |||
216 | trap "restore_values" SIGINT SIGTERM EXIT | ||
217 | |||
218 | cmd="echo 1 > /proc/self/make-it-fail && exec $@" | ||
219 | bash -c "$cmd" | ||
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index a4162e15c25f..85baf11e2acd 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | TARGETS = breakpoints kcmp mqueue vm | 1 | TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug |
2 | 2 | ||
3 | all: | 3 | all: |
4 | for TARGET in $(TARGETS); do \ | 4 | for TARGET in $(TARGETS); do \ |
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 | ||
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 @@ | |||
1 | all: | ||
2 | |||
3 | run_tests: | ||
4 | ./on-off-test.sh | ||
5 | |||
6 | clean: | ||
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 | |||
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/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 | # | ||
30 | hotpluggable_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 | |||
42 | hotplaggable_offline_memory() | ||
43 | { | ||
44 | hotpluggable_memory offline | ||
45 | } | ||
46 | |||
47 | hotpluggable_online_memory() | ||
48 | { | ||
49 | hotpluggable_memory online | ||
50 | } | ||
51 | |||
52 | memory_is_online() | ||
53 | { | ||
54 | grep -q online $SYSFS/devices/system/memory/memory$1/state | ||
55 | } | ||
56 | |||
57 | memory_is_offline() | ||
58 | { | ||
59 | grep -q offline $SYSFS/devices/system/memory/memory$1/state | ||
60 | } | ||
61 | |||
62 | online_memory() | ||
63 | { | ||
64 | echo online > $SYSFS/devices/system/memory/memory$1/state | ||
65 | } | ||
66 | |||
67 | offline_memory() | ||
68 | { | ||
69 | echo offline > $SYSFS/devices/system/memory/memory$1/state | ||
70 | } | ||
71 | |||
72 | online_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 | |||
83 | online_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 | |||
94 | offline_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 | |||
105 | offline_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 | |||
116 | error=-12 | ||
117 | priority=0 | ||
118 | ratio=10 | ||
119 | |||
120 | while 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 | ||
136 | done | ||
137 | |||
138 | if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then | ||
139 | echo "error code must be -4095 <= errno < 0" >&2 | ||
140 | exit 1 | ||
141 | fi | ||
142 | |||
143 | prerequisite | ||
144 | |||
145 | # | ||
146 | # Online all hot-pluggable memory | ||
147 | # | ||
148 | for memory in `hotplaggable_offline_memory`; do | ||
149 | online_memory_expect_success $memory | ||
150 | done | ||
151 | |||
152 | # | ||
153 | # Offline $ratio percent of hot-pluggable memory | ||
154 | # | ||
155 | for memory in `hotpluggable_online_memory`; do | ||
156 | if [ $((RANDOM % 100)) -lt $ratio ]; then | ||
157 | offline_memory_expect_success $memory | ||
158 | fi | ||
159 | done | ||
160 | |||
161 | # | ||
162 | # Online all hot-pluggable memory again | ||
163 | # | ||
164 | for memory in `hotplaggable_offline_memory`; do | ||
165 | online_memory_expect_success $memory | ||
166 | done | ||
167 | |||
168 | # | ||
169 | # Test with memory notifier error injection | ||
170 | # | ||
171 | |||
172 | DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'` | ||
173 | NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/memory | ||
174 | |||
175 | prerequisite_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 | |||
193 | prerequisite_extra | ||
194 | |||
195 | # | ||
196 | # Offline $ratio percent of hot-pluggable memory | ||
197 | # | ||
198 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error | ||
199 | for memory in `hotpluggable_online_memory`; do | ||
200 | if [ $((RANDOM % 100)) -lt $ratio ]; then | ||
201 | offline_memory_expect_success $memory | ||
202 | fi | ||
203 | done | ||
204 | |||
205 | # | ||
206 | # Test memory hot-add error handling (offline => online) | ||
207 | # | ||
208 | echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error | ||
209 | for memory in `hotplaggable_offline_memory`; do | ||
210 | online_memory_expect_fail $memory | ||
211 | done | ||
212 | |||
213 | # | ||
214 | # Online all hot-pluggable memory | ||
215 | # | ||
216 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error | ||
217 | for memory in `hotplaggable_offline_memory`; do | ||
218 | online_memory_expect_success $memory | ||
219 | done | ||
220 | |||
221 | # | ||
222 | # Test memory hot-remove error handling (online => offline) | ||
223 | # | ||
224 | echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error | ||
225 | for memory in `hotpluggable_online_memory`; do | ||
226 | offline_memory_expect_fail $memory | ||
227 | done | ||
228 | |||
229 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error | ||
230 | /sbin/modprobe -q -r memory-notifier-error-inject | ||