linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/5] selftests: fix memory-hotplug test
@ 2017-06-27  6:17 Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 1/5] selftests: typo correction for " Po-Hsu Lin
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Po-Hsu Lin @ 2017-06-27  6:17 UTC (permalink / raw)
  To: shuah, linux-kselftest, linux-kernel

This patchset will fix a typo, print the name of the memory notifier
error injection test, add two extra checks and fixes the online /
offline memory test in the memory-hotplug test.

Po-Hsu Lin (5):
  selftests: typo correction for memory-hotplug test
  selftests: check hot-pluggagble memory for memory-hotplug test
  selftests: check percentage range for memory-hotplug test
  selftests: add missing test name in memory-hotplug test
  selftests: fix memory-hotplug test

 .../selftests/memory-hotplug/mem-on-off-test.sh    |   86 +++++++++++++++-----
 1 file changed, 67 insertions(+), 19 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCHv2 1/5] selftests: typo correction for memory-hotplug test
  2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
@ 2017-06-27  6:17 ` Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 2/5] selftests: check hot-pluggagble memory " Po-Hsu Lin
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Po-Hsu Lin @ 2017-06-27  6:17 UTC (permalink / raw)
  To: shuah, linux-kselftest, linux-kernel

Typo fixed for hotpluggable_offline_memory() in memory-hotplug test.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh    |   10 +++++-----
 1 file changed, 5 insertions(+), 5 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 6cddde0..a8d8587 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -39,7 +39,7 @@ hotpluggable_memory()
 	done
 }
 
-hotplaggable_offline_memory()
+hotpluggable_offline_memory()
 {
 	hotpluggable_memory offline
 }
@@ -150,7 +150,7 @@ echo -e "\t online all hotplug memory in offline state"
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
 	echo offline-online $memory
 	online_memory_expect_success $memory
 done
@@ -168,7 +168,7 @@ done
 #
 # Online all hot-pluggable memory again
 #
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
 	echo offline-online $memory
 	online_memory_expect_success $memory
 done
@@ -214,7 +214,7 @@ done
 # Test memory hot-add error handling (offline => online)
 #
 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
 	online_memory_expect_fail $memory
 done
 
@@ -222,7 +222,7 @@ done
 # Online all hot-pluggable memory
 #
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
 	online_memory_expect_success $memory
 done
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCHv2 2/5] selftests: check hot-pluggagble memory for memory-hotplug test
  2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 1/5] selftests: typo correction for " Po-Hsu Lin
@ 2017-06-27  6:17 ` Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 3/5] selftests: check percentage range " Po-Hsu Lin
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Po-Hsu Lin @ 2017-06-27  6:17 UTC (permalink / raw)
  To: shuah, linux-kselftest, linux-kernel

Check for hot-pluggable memory availability in prerequisite() of the
memory-hotplug test.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh    |    5 +++++
 1 file changed, 5 insertions(+)

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 a8d8587..993ff2b 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -22,6 +22,11 @@ prerequisite()
 		echo $msg memory hotplug is not supported >&2
 		exit 0
 	fi
+
+	if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
+		echo $msg no hot-pluggable memory >&2
+		exit 0
+	fi
 }
 
 #
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCHv2 3/5] selftests: check percentage range for memory-hotplug test
  2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 1/5] selftests: typo correction for " Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 2/5] selftests: check hot-pluggagble memory " Po-Hsu Lin
@ 2017-06-27  6:17 ` Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 4/5] selftests: add missing test name in " Po-Hsu Lin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Po-Hsu Lin @ 2017-06-27  6:17 UTC (permalink / raw)
  To: shuah, linux-kselftest, linux-kernel

Check the precentage range for -r flag in memory-hotplug test.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh    |    4 ++++
 1 file changed, 4 insertions(+)

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 993ff2b..c735ece 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -136,6 +136,10 @@ while getopts e:hp:r: opt; do
 		;;
 	r)
 		ratio=$OPTARG
+		if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
+			echo "The percentage should be an integer within 0~100 range"
+			exit 1
+		fi
 		;;
 	esac
 done
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCHv2 4/5] selftests: add missing test name in memory-hotplug test
  2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
                   ` (2 preceding siblings ...)
  2017-06-27  6:17 ` [PATCHv2 3/5] selftests: check percentage range " Po-Hsu Lin
@ 2017-06-27  6:17 ` Po-Hsu Lin
  2017-06-27  6:17 ` [PATCHv2 5/5] selftests: fix " Po-Hsu Lin
  2017-06-28 14:01 ` [PATCHv2 0/5] " Shuah Khan
  5 siblings, 0 replies; 7+ messages in thread
From: Po-Hsu Lin @ 2017-06-27  6:17 UTC (permalink / raw)
  To: shuah, linux-kselftest, linux-kernel

There is no prompt for testing memory notifier error injection,
added with the same echo format of other tests above.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh    |    1 +
 1 file changed, 1 insertion(+)

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 c735ece..0f62c16 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -207,6 +207,7 @@ prerequisite_extra()
 	fi
 }
 
+echo -e "\t Test with memory notifier error injection"
 prerequisite_extra
 
 #
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCHv2 5/5] selftests: fix memory-hotplug test
  2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
                   ` (3 preceding siblings ...)
  2017-06-27  6:17 ` [PATCHv2 4/5] selftests: add missing test name in " Po-Hsu Lin
@ 2017-06-27  6:17 ` Po-Hsu Lin
  2017-06-28 14:01 ` [PATCHv2 0/5] " Shuah Khan
  5 siblings, 0 replies; 7+ messages in thread
From: Po-Hsu Lin @ 2017-06-27  6:17 UTC (permalink / raw)
  To: shuah, linux-kselftest, linux-kernel

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>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh    |   70 +++++++++++++++-----
 1 file 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 0f62c16..35025ce 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()
 
 	if ! online_memory $memory; then
 		echo $FUNCNAME $memory: unexpected fail >&2
+		return 1
 	elif ! memory_is_online $memory; then
 		echo $FUNCNAME $memory: unexpected offline >&2
+		return 1
 	fi
+	return 0
 }
 
 online_memory_expect_fail()
@@ -91,9 +94,12 @@ online_memory_expect_fail()
 
 	if online_memory $memory 2> /dev/null; then
 		echo $FUNCNAME $memory: unexpected success >&2
+		return 1
 	elif ! memory_is_offline $memory; then
 		echo $FUNCNAME $memory: unexpected online >&2
+		return 1
 	fi
+	return 0
 }
 
 offline_memory_expect_success()
@@ -102,9 +108,12 @@ offline_memory_expect_success()
 
 	if ! offline_memory $memory; then
 		echo $FUNCNAME $memory: unexpected fail >&2
+		return 1
 	elif ! memory_is_offline $memory; then
 		echo $FUNCNAME $memory: unexpected offline >&2
+		return 1
 	fi
+	return 0
 }
 
 offline_memory_expect_fail()
@@ -113,14 +122,18 @@ offline_memory_expect_fail()
 
 	if offline_memory $memory 2> /dev/null; then
 		echo $FUNCNAME $memory: unexpected success >&2
+		return 1
 	elif ! memory_is_online $memory; then
 		echo $FUNCNAME $memory: unexpected offline >&2
+		return 1
 	fi
+	return 0
 }
 
 error=-12
 priority=0
 ratio=10
+retval=0
 
 while getopts e:hp:r: opt; do
 	case $opt in
@@ -152,35 +165,58 @@ fi
 prerequisite
 
 echo "Test scope: $ratio% hotplug memory"
-echo -e "\t online all hotplug memory in offline state"
-echo -e "\t offline $ratio% hotplug memory in online state"
-echo -e "\t online all hotplug memory in offline state"
 
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotpluggable_offline_memory`; do
-	echo offline-online $memory
-	online_memory_expect_success $memory
-done
+hotpluggable_num=`hotpluggable_offline_memory | wc -l`
+echo -e "\t online all hot-pluggable memory in offline state:"
+if [ "$hotpluggable_num" -gt 0 ]; then
+	for memory in `hotpluggable_offline_memory`; do
+		echo "offline->online memory$memory"
+		if ! online_memory_expect_success $memory; then
+			retval=1
+		fi
+	done
+else
+	echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
+fi
 
 #
 # Offline $ratio percent of hot-pluggable memory
 #
+hotpluggable_num=`hotpluggable_online_memory | wc -l`
+target=`echo "a=$hotpluggable_num*$ratio; if ( a%100 ) a/100+1 else a/100" | bc`
+echo -e "\t offline $ratio% hot-pluggable memory in online state"
+echo -e "\t trying to offline $target out of $hotpluggable_num memory block(s):"
 for memory in `hotpluggable_online_memory`; do
-	if [ $((RANDOM % 100)) -lt $ratio ]; then
-		echo online-offline $memory
-		offline_memory_expect_success $memory
+	if [ "$target" -gt 0 ]; then
+		echo "online->offline memory$memory"
+		if offline_memory_expect_success $memory; then
+			target=$(($target - 1))
+		fi
 	fi
 done
+if [ "$target" -gt 0 ]; then
+	retval=1
+	echo -e "\t\t FAILED - unable to offline some memory blocks, device busy?"
+fi
 
 #
 # Online all hot-pluggable memory again
 #
-for memory in `hotpluggable_offline_memory`; do
-	echo offline-online $memory
-	online_memory_expect_success $memory
-done
+hotpluggable_num=`hotpluggable_offline_memory | wc -l`
+echo -e "\t online all hot-pluggable memory in offline state:"
+if [ "$hotpluggable_num" -gt 0 ]; then
+	for memory in `hotpluggable_offline_memory`; do
+		echo "offline->online memory$memory"
+		if ! online_memory_expect_success $memory; then
+			retval=1
+		fi
+	done
+else
+	echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
+fi
 
 #
 # Test with memory notifier error injection
@@ -198,12 +234,12 @@ prerequisite_extra()
 
 	if [ ! -d "$DEBUGFS" ]; then
 		echo $msg debugfs is not mounted >&2
-		exit 0
+		exit $retval
 	fi
 
 	if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
 		echo $msg memory-notifier-error-inject module is not available >&2
-		exit 0
+		exit $retval
 	fi
 }
 
@@ -246,3 +282,5 @@ done
 
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
 /sbin/modprobe -q -r memory-notifier-error-inject
+
+exit $retval
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCHv2 0/5] selftests: fix memory-hotplug test
  2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
                   ` (4 preceding siblings ...)
  2017-06-27  6:17 ` [PATCHv2 5/5] selftests: fix " Po-Hsu Lin
@ 2017-06-28 14:01 ` Shuah Khan
  5 siblings, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2017-06-28 14:01 UTC (permalink / raw)
  To: Po-Hsu Lin, linux-kselftest, linux-kernel, Shuah Khan

On 06/27/2017 12:17 AM, Po-Hsu Lin wrote:
> This patchset will fix a typo, print the name of the memory notifier
> error injection test, add two extra checks and fixes the online /
> offline memory test in the memory-hotplug test.
> 
> Po-Hsu Lin (5):
>   selftests: typo correction for memory-hotplug test
>   selftests: check hot-pluggagble memory for memory-hotplug test
>   selftests: check percentage range for memory-hotplug test
>   selftests: add missing test name in memory-hotplug test
>   selftests: fix memory-hotplug test
> 
>  .../selftests/memory-hotplug/mem-on-off-test.sh    |   86 +++++++++++++++-----
>  1 file changed, 67 insertions(+), 19 deletions(-)
> 

Applied the series to linux-kselftest next for 4.13-rc1

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-06-28 14:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27  6:17 [PATCHv2 0/5] selftests: fix memory-hotplug test Po-Hsu Lin
2017-06-27  6:17 ` [PATCHv2 1/5] selftests: typo correction for " Po-Hsu Lin
2017-06-27  6:17 ` [PATCHv2 2/5] selftests: check hot-pluggagble memory " Po-Hsu Lin
2017-06-27  6:17 ` [PATCHv2 3/5] selftests: check percentage range " Po-Hsu Lin
2017-06-27  6:17 ` [PATCHv2 4/5] selftests: add missing test name in " Po-Hsu Lin
2017-06-27  6:17 ` [PATCHv2 5/5] selftests: fix " Po-Hsu Lin
2017-06-28 14:01 ` [PATCHv2 0/5] " Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).