10 echo $msg must be run as root
>&2
14 SYSFS
=`mount -t sysfs | head -1 | awk '{ print $3 }'`
16 if [ ! -d "$SYSFS" ]; then
17 echo $msg sysfs is not mounted
>&2
21 if ! ls $SYSFS/devices
/system
/memory
/memory
* > /dev
/null
2>&1; then
22 echo $msg memory hotplug is not supported
>&2
28 # list all hot-pluggable memory
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}
42 hotplaggable_offline_memory
()
44 hotpluggable_memory offline
47 hotpluggable_online_memory
()
49 hotpluggable_memory online
54 grep -q online
$SYSFS/devices
/system
/memory
/memory
$1/state
59 grep -q offline
$SYSFS/devices
/system
/memory
/memory
$1/state
64 echo online
> $SYSFS/devices
/system
/memory
/memory
$1/state
69 echo offline
> $SYSFS/devices
/system
/memory
/memory
$1/state
72 online_memory_expect_success
()
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
83 online_memory_expect_fail
()
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
94 offline_memory_expect_success
()
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
105 offline_memory_expect_fail
()
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
120 while getopts e
:hp
:r
: opt
; do
126 echo "Usage $0 [ -e errno ] [ -p notifier-priority ] [ -r percent-of-memory-to-offline ]"
138 if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then
139 echo "error code must be -4095 <= errno < 0" >&2
145 echo "Test scope: $ratio% hotplug memory"
146 echo -e "\t online all hotplug memory in offline state"
147 echo -e "\t offline $ratio% hotplug memory in online state"
148 echo -e "\t online all hotplug memory in offline state"
151 # Online all hot-pluggable memory
153 for memory
in `hotplaggable_offline_memory`; do
154 echo offline-online
$memory
155 online_memory_expect_success
$memory
159 # Offline $ratio percent of hot-pluggable memory
161 for memory
in `hotpluggable_online_memory`; do
162 if [ $
((RANDOM
% 100)) -lt $ratio ]; then
163 echo online-offline
$memory
164 offline_memory_expect_success
$memory
169 # Online all hot-pluggable memory again
171 for memory
in `hotplaggable_offline_memory`; do
172 echo offline-online
$memory
173 online_memory_expect_success
$memory
177 # Test with memory notifier error injection
180 DEBUGFS
=`mount -t debugfs | head -1 | awk '{ print $3 }'`
181 NOTIFIER_ERR_INJECT_DIR
=$DEBUGFS/notifier-error-inject
/memory
185 msg
="skip extra tests:"
187 /sbin
/modprobe
-q -r memory-notifier-error-inject
188 /sbin
/modprobe
-q memory-notifier-error-inject priority
=$priority
190 if [ ! -d "$DEBUGFS" ]; then
191 echo $msg debugfs is not mounted
>&2
195 if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
196 echo $msg memory-notifier-error-inject module is not available
>&2
204 # Offline $ratio percent of hot-pluggable memory
206 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions
/MEM_GOING_OFFLINE
/error
207 for memory
in `hotpluggable_online_memory`; do
208 if [ $
((RANDOM
% 100)) -lt $ratio ]; then
209 offline_memory_expect_success
$memory
214 # Test memory hot-add error handling (offline => online)
216 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions
/MEM_GOING_ONLINE
/error
217 for memory
in `hotplaggable_offline_memory`; do
218 online_memory_expect_fail
$memory
222 # Online all hot-pluggable memory
224 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions
/MEM_GOING_ONLINE
/error
225 for memory
in `hotplaggable_offline_memory`; do
226 online_memory_expect_success
$memory
230 # Test memory hot-remove error handling (online => offline)
232 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions
/MEM_GOING_OFFLINE
/error
233 for memory
in `hotpluggable_online_memory`; do
234 offline_memory_expect_fail
$memory
237 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions
/MEM_GOING_OFFLINE
/error
238 /sbin
/modprobe
-q -r memory-notifier-error-inject