aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorPo-Hsu Lin <po-hsu.lin@canonical.com>2017-06-27 02:17:15 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2017-06-30 12:06:23 -0400
commit5ff0c60b0e5e8c2a2139c304d7620b0ea70d721a (patch)
tree888991c3eef427301d1f8ff2797c7be478385f41 /tools/testing
parent02d8f075ac44f6f0dc46881965f815576921f2c0 (diff)
selftests: fix memory-hotplug test
In the memory offline test, the $ration was used with RANDOM as the possibility to get it offlined, correct it to become the portion of available removable memory blocks. Also ask the tool to try to offline the next available memory block if the attempt is unsuccessful. It will only fail if all removable memory blocks are busy. A nice example: $ sudo ./test.sh Test scope: 10% hotplug memory online all hot-pluggable memory in offline state: SKIPPED - no hot-pluggable memory in offline state offline 10% hot-pluggable memory in online state trying to offline 3 out of 28 memory block(s): online->offline memory1 online->offline memory10 ./test.sh: line 74: echo: write error: Resource temporarily unavailable offline_memory_expect_success 10: unexpected fail online->offline memory100 online->offline memory101 online all hot-pluggable memory in offline state: offline->online memory1 offline->online memory100 offline->online memory101 skip extra tests: debugfs is not mounted $ echo $? 0 Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools/testing')
-rwxr-xr-xtools/testing/selftests/memory-hotplug/mem-on-off-test.sh70
1 files changed, 54 insertions, 16 deletions
diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 0f62c16c35c4..35025ce9ca66 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -80,9 +80,12 @@ online_memory_expect_success()
80 80
81 if ! online_memory $memory; then 81 if ! online_memory $memory; then
82 echo $FUNCNAME $memory: unexpected fail >&2 82 echo $FUNCNAME $memory: unexpected fail >&2
83 return 1
83 elif ! memory_is_online $memory; then 84 elif ! memory_is_online $memory; then
84 echo $FUNCNAME $memory: unexpected offline >&2 85 echo $FUNCNAME $memory: unexpected offline >&2
86 return 1
85 fi 87 fi
88 return 0
86} 89}
87 90
88online_memory_expect_fail() 91online_memory_expect_fail()
@@ -91,9 +94,12 @@ online_memory_expect_fail()
91 94
92 if online_memory $memory 2> /dev/null; then 95 if online_memory $memory 2> /dev/null; then
93 echo $FUNCNAME $memory: unexpected success >&2 96 echo $FUNCNAME $memory: unexpected success >&2
97 return 1
94 elif ! memory_is_offline $memory; then 98 elif ! memory_is_offline $memory; then
95 echo $FUNCNAME $memory: unexpected online >&2 99 echo $FUNCNAME $memory: unexpected online >&2
100 return 1
96 fi 101 fi
102 return 0
97} 103}
98 104
99offline_memory_expect_success() 105offline_memory_expect_success()
@@ -102,9 +108,12 @@ offline_memory_expect_success()
102 108
103 if ! offline_memory $memory; then 109 if ! offline_memory $memory; then
104 echo $FUNCNAME $memory: unexpected fail >&2 110 echo $FUNCNAME $memory: unexpected fail >&2
111 return 1
105 elif ! memory_is_offline $memory; then 112 elif ! memory_is_offline $memory; then
106 echo $FUNCNAME $memory: unexpected offline >&2 113 echo $FUNCNAME $memory: unexpected offline >&2
114 return 1
107 fi 115 fi
116 return 0
108} 117}
109 118
110offline_memory_expect_fail() 119offline_memory_expect_fail()
@@ -113,14 +122,18 @@ offline_memory_expect_fail()
113 122
114 if offline_memory $memory 2> /dev/null; then 123 if offline_memory $memory 2> /dev/null; then
115 echo $FUNCNAME $memory: unexpected success >&2 124 echo $FUNCNAME $memory: unexpected success >&2
125 return 1
116 elif ! memory_is_online $memory; then 126 elif ! memory_is_online $memory; then
117 echo $FUNCNAME $memory: unexpected offline >&2 127 echo $FUNCNAME $memory: unexpected offline >&2
128 return 1
118 fi 129 fi
130 return 0
119} 131}
120 132
121error=-12 133error=-12
122priority=0 134priority=0
123ratio=10 135ratio=10
136retval=0
124 137
125while getopts e:hp:r: opt; do 138while getopts e:hp:r: opt; do
126 case $opt in 139 case $opt in
@@ -152,35 +165,58 @@ fi
152prerequisite 165prerequisite
153 166
154echo "Test scope: $ratio% hotplug memory" 167echo "Test scope: $ratio% hotplug memory"
155echo -e "\t online all hotplug memory in offline state"
156echo -e "\t offline $ratio% hotplug memory in online state"
157echo -e "\t online all hotplug memory in offline state"
158 168
159# 169#
160# Online all hot-pluggable memory 170# Online all hot-pluggable memory
161# 171#
162for memory in `hotpluggable_offline_memory`; do 172hotpluggable_num=`hotpluggable_offline_memory | wc -l`
163 echo offline-online $memory 173echo -e "\t online all hot-pluggable memory in offline state:"
164 online_memory_expect_success $memory 174if [ "$hotpluggable_num" -gt 0 ]; then
165done 175 for memory in `hotpluggable_offline_memory`; do
176 echo "offline->online memory$memory"
177 if ! online_memory_expect_success $memory; then
178 retval=1
179 fi
180 done
181else
182 echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
183fi
166 184
167# 185#
168# Offline $ratio percent of hot-pluggable memory 186# Offline $ratio percent of hot-pluggable memory
169# 187#
188hotpluggable_num=`hotpluggable_online_memory | wc -l`
189target=`echo "a=$hotpluggable_num*$ratio; if ( a%100 ) a/100+1 else a/100" | bc`
190echo -e "\t offline $ratio% hot-pluggable memory in online state"
191echo -e "\t trying to offline $target out of $hotpluggable_num memory block(s):"
170for memory in `hotpluggable_online_memory`; do 192for memory in `hotpluggable_online_memory`; do
171 if [ $((RANDOM % 100)) -lt $ratio ]; then 193 if [ "$target" -gt 0 ]; then
172 echo online-offline $memory 194 echo "online->offline memory$memory"
173 offline_memory_expect_success $memory 195 if offline_memory_expect_success $memory; then
196 target=$(($target - 1))
197 fi
174 fi 198 fi
175done 199done
200if [ "$target" -gt 0 ]; then
201 retval=1
202 echo -e "\t\t FAILED - unable to offline some memory blocks, device busy?"
203fi
176 204
177# 205#
178# Online all hot-pluggable memory again 206# Online all hot-pluggable memory again
179# 207#
180for memory in `hotpluggable_offline_memory`; do 208hotpluggable_num=`hotpluggable_offline_memory | wc -l`
181 echo offline-online $memory 209echo -e "\t online all hot-pluggable memory in offline state:"
182 online_memory_expect_success $memory 210if [ "$hotpluggable_num" -gt 0 ]; then
183done 211 for memory in `hotpluggable_offline_memory`; do
212 echo "offline->online memory$memory"
213 if ! online_memory_expect_success $memory; then
214 retval=1
215 fi
216 done
217else
218 echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
219fi
184 220
185# 221#
186# Test with memory notifier error injection 222# Test with memory notifier error injection
@@ -198,12 +234,12 @@ prerequisite_extra()
198 234
199 if [ ! -d "$DEBUGFS" ]; then 235 if [ ! -d "$DEBUGFS" ]; then
200 echo $msg debugfs is not mounted >&2 236 echo $msg debugfs is not mounted >&2
201 exit 0 237 exit $retval
202 fi 238 fi
203 239
204 if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then 240 if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
205 echo $msg memory-notifier-error-inject module is not available >&2 241 echo $msg memory-notifier-error-inject module is not available >&2
206 exit 0 242 exit $retval
207 fi 243 fi
208} 244}
209 245
@@ -246,3 +282,5 @@ done
246 282
247echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error 283echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
248/sbin/modprobe -q -r memory-notifier-error-inject 284/sbin/modprobe -q -r memory-notifier-error-inject
285
286exit $retval