[LTP] [PATCH] cpuhotplug*.sh: Check return value of online_cpu/offline_cpu

Zhao Gongyi zhaogongyi@huawei.com
Thu Aug 4 09:38:05 CEST 2022


We need to check the return value of online_cpu() and offline_cpu()
although it is always success.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../hotplug/cpu_hotplug/functional/cpuhotplug02.sh   | 10 ++++++++--
 .../hotplug/cpu_hotplug/functional/cpuhotplug05.sh   |  9 +++++++--
 .../hotplug/cpu_hotplug/functional/cpuhotplug06.sh   |  5 ++++-
 .../hotplug/cpu_hotplug/functional/cpuhotplug07.sh   | 12 ++++++------
 4 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh
index f12aabc72..ba274db01 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh
@@ -90,7 +90,10 @@ until [ $LOOP_COUNT -gt $HOTPLUG02_LOOPS ]; do
 	set_affinity ${SPIN_LOOP_PID} ${CPU_TO_TEST}

 	# Verify the process migrated to the CPU we intended it to go to
-	offline_cpu ${CPU_TO_TEST}
+	if ! offline_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
+	fi
+
 	NEW_CPU=`ps --pid=${SPIN_LOOP_PID} -o psr --no-headers`
 	if [ -z "${NEW_CPU}" ]; then
 		tst_brkm TBROK "PID ${SPIN_LOOP_PID} no longer running"
@@ -101,7 +104,10 @@ until [ $LOOP_COUNT -gt $HOTPLUG02_LOOPS ]; do
 	fi

 	# Turn the CPU back online just to see what happens.
-	online_cpu ${CPU_TO_TEST}
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
+
 	LOOP_COUNT=$((LOOP_COUNT+1))
 done

diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh
index 2feb8d9ff..1eb204f4e 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh
@@ -36,7 +36,9 @@ EOF
 do_clean()
 {
 	pid_is_valid ${SAR_PID} && kill_pid ${SAR_PID}
-	online_cpu "$CPU_TO_TEST"
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
 }

 get_field()
@@ -149,7 +151,10 @@ until [ $LOOP_COUNT -gt $HOTPLUG05_LOOPS ]; do
 		tst_exit
 	fi

-	offline_cpu ${CPU_TO_TEST}
+	if ! offline_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
+	fi
+
 	kill_pid ${SAR_PID}

 	LOOP_COUNT=$((LOOP_COUNT+1))
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh
index 319c66537..b9c1889d3 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh
@@ -99,7 +99,10 @@ until [ $LOOP_COUNT -gt $HOTPLUG06_LOOPS ]; do
 		tst_exit
 	fi

-	online_cpu ${CPU_TO_TEST}
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
+
 	kill_pid ${TOP_PID}

 	LOOP_COUNT=$((LOOP_COUNT+1))
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh
index 0d2dec7fe..af170f1cc 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh
@@ -100,9 +100,9 @@ until [ $LOOP_COUNT -gt $HOTPLUG07_LOOPS ]; do
 	# Move spin_loop.sh to the CPU to offline.
 	set_affinity ${KCOMPILE_LOOP_PID} ${CPU_TO_TEST}

-	offline_cpu ${CPU_TO_TEST}
-	RC=$?
-	echo "Offlining cpu${CPU_TO_TEST}: Return Code = ${RC}"
+	if ! offline_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
+	fi

 	NEW_CPU=`ps --pid=${KCOMPILE_LOOP_PID} -o psr --no-headers`
 	if [ -z "${NEW_CPU}" ]; then
@@ -113,9 +113,9 @@ until [ $LOOP_COUNT -gt $HOTPLUG07_LOOPS ]; do
 		tst_exit
 	fi

-	online_cpu ${CPU_TO_TEST}
-	RC=$?
-	echo "Onlining cpu${CPU_TO_TEST}: Return Code = ${RC}"
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi

 	LOOP_COUNT=$((LOOP_COUNT+1))

--
2.17.1



More information about the ltp mailing list