Skip to contentSkip to conversation

rcu/rcu_torture.sh: Rewrite test

PATCH Superseded Xiao Yang 3 participants 5 messages Jul 10, 2019 – Jul 11, 2019

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH v3 1/1 rcu/rcu_torture.sh: Rewrite test

1) Cleanup and convert to new API
2) Update valid rcutorture types(rcu, srcu, srcud, tasks)

Note:
Exclude valid busted* types(busted, busted_srcud) that check the test itself and expect failures, suggested by:
https://www.spinics.net/lists/kernel/msg3045252.html

---
 testcases/kernel/device-drivers/rcu/rcu_torture.sh | 142 +++++++++------------
 1 file changed, 63 insertions(+), 79 deletions(-)
testcases/kernel/device-drivers/rcu/rcu_torture.sh +63 -79
index c3739f9..9df4390 100755
@@ -1,20 +1,7 @@
 #!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2015 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Copyright (C) 2019 Xiao Yang <[email protected]>
 # Author: Alexey Kodanev <[email protected]>
 #
 # One of the possible ways to test RCU is to use rcutorture kernel module.
@@ -23,89 +10,86 @@
 # dmesg output for module's test results.
 # For more information, please read Linux Documentation: RCU/torture.txt
 
-TCID="rcu_torture"
-TST_TOTAL=14
-TST_CLEANUP=cleanup
+TST_CNT=4
+TST_SETUP=rcutorture_setup
+TST_TESTFUNC=do_test
+TST_NEEDS_ROOT=1
+TST_NEEDS_CMDS="modprobe dmesg sed tail"
+TST_OPTS="t:w:"
+TST_USAGE=rcutorture_usage
+TST_PARSE_ARGS=rcutorture_parse_args
 
-. test.sh
+. tst_test.sh
 
 # default options
-test_time=60
+test_time=30
 num_writers=5
 
-while getopts :ht:w: opt; do
-	case "$opt" in
-	h)
-		echo "Usage:"
-		echo "h        help"
-		echo "t x      time in seconds for each test-case"
-		echo "w x      number of writers"
-		exit 0
-	;;
-	t) test_time=$OPTARG ;;
-	w) num_writers=$OPTARG ;;
-	*)
-		tst_brkm TBROK "unknown option: $opt"
-	;;
-	esac
-done
-
-cleanup()
+rcutorture_usage()
 {
-	tst_resm TINFO "cleanup"
-	rmmod rcutorture > /dev/null 2>&1
+	echo "Usage:"
+	echo "-t x    time in seconds for each test-case"
+	echo "-w x    number of writers"
 }
 
-tst_require_root
-
-# check if module is present
-modprobe rcutorture > /dev/null 2>&1 || \
-	tst_brkm TCONF "Test requires rcutorture module"
-rmmod rcutorture > /dev/null 2>&1
-
-trap cleanup INT
-
-rcu_type="rcu rcu_bh srcu sched"
+rcutorture_parse_args()
+{
+	case $1 in
+	t) test_time=$2 ;;
+	w) num_writers=$2 ;;
+	esac
+}
 
-if tst_kvcmp -lt "3.12"; then
-	rcu_type="$rcu_type rcu_sync rcu_expedited rcu_bh_sync rcu_bh_expedited \
-	          srcu_sync srcu_expedited sched_sync sched_expedited"
+rcutorture_setup()
+{
+	local module=1
 
-	if tst_kvcmp -lt "3.11"; then
-		rcu_type="$rcu_type srcu_raw srcu_raw_sync"
-	fi
-fi
+	# check if rcutorture is built as a kernel module by inserting
+	# and then removing it
+	modprobe rcutorture >/dev/null 2>&1 ||  module=0
+	modprobe -r rcutorture >/dev/null 2>&1 || module=0
 
-TST_TOTAL=$(echo "$rcu_type" | wc -w)
+	[ $module -eq 0 ] && \
+		tst_brk TCONF "rcutorture is built-in, non-existent or in use"
+}
 
-est_time=`echo "scale=2; $test_time * $TST_TOTAL / 60 " | bc`
-tst_resm TINFO "estimate time $est_time min"
+rcutorture_test()
+{
+	local rcu_type=$1
 
-for type in $rcu_type; do
+	tst_res TINFO "${rcu_type}-torture: running ${test_time} sec..."
 
-	tst_resm TINFO "$type: running $test_time sec..."
+	modprobe rcutorture nfakewriters=${num_writers} \
+		torture_type=${rcu_type} >/dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		dmesg | grep -q "invalid torture type: \"${rcu_type}\"" && \
+			tst_brk TCONF "invalid ${rcu_type} type"
 
-	modprobe rcutorture nfakewriters=$num_writers \
-	         stat_interval=60 test_no_idle_hz=1 shuffle_interval=3 \
-	         stutter=5 irqreader=1 fqs_duration=0 fqs_holdoff=0 \
-	         fqs_stutter=3 test_boost=1 test_boost_interval=7 \
-	         test_boost_duration=4 shutdown_secs=0 \
-	         stall_cpu=0 stall_cpu_holdoff=10 n_barrier_cbs=0 \
-	         onoff_interval=0 onoff_holdoff=0 torture_type=$type \
-	         > /dev/null 2>&1 || tst_brkm TBROK "failed to load module"
+		tst_brk TBROK "failed to load module"
+	fi
 
-	sleep $test_time
+	sleep ${test_time}
 
-	rmmod rcutorture > /dev/null 2>&1 || \
-		tst_brkm TBROK "failed to unload module"
+	modprobe -r rcutorture >/dev/null 2>&1 || \
+		tst_brk TBROK "failed to unload module"
 
 	# check module status in dmesg
-	result_str=`dmesg | sed -nE '$s/.*End of test: ([A-Z]+):.*/\1/p'`
-	if [ "$result_str" = "SUCCESS" ]; then
-		tst_resm TPASS "$type: completed"
+	local res=$(dmesg | sed -nE "s/.* ${rcu_type}-torture:.* End of test: (.*): .*/\1/p" | tail -n1)
+	if [ "$res" = "SUCCESS" ]; then
+		tst_res TPASS "${rcu_type}-torture: $res"
 	else
-		tst_resm TFAIL "$type: $result_str, see dmesg"
+		tst_res TFAIL "${rcu_type}-torture: $res, see dmesg"
 	fi
-done
+}
+
+do_test()
+{
+	case $1 in
+	1) rcutorture_test rcu;;
+	2) rcutorture_test srcu;;
+	3) rcutorture_test srcud;;
+	4) rcutorture_test tasks;;
+	esac
+}
 
-tst_exit
+tst_run
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/1 rcu/rcu_torture.sh: Rewrite test

Hi Xiao,

Quoted 9 lines

1) Cleanup and convert to new API
2) Update valid rcutorture types(rcu, srcu, srcud, tasks)

Note:
Exclude valid busted* types(busted, busted_srcud) that check the test itself and expect failures, suggested by:
https://www.spinics.net/lists/kernel/msg3045252.html

Only few comments below (nits).

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 25

Quoted 3 lines
 # default options
testcases/kernel/device-drivers/rcu/rcu_torture.sh +1 -1
-test_time=60
+test_time=30

You shortened the test to half, good :).

...

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 50

Quoted 12 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +7 -4
+rcutorture_setup()
+{
+	local module=1
 
-	if tst_kvcmp -lt "3.11"; then
-		rcu_type="$rcu_type srcu_raw srcu_raw_sync"
-	fi
-fi
+	# check if rcutorture is built as a kernel module by inserting
+	# and then removing it
+	modprobe rcutorture >/dev/null 2>&1 ||  module=0
+	modprobe -r rcutorture >/dev/null 2>&1 || module=0

This can be just module=1 or module= (none value). (+ -q is enough instead of redirections). i.e.:

modprobe rcutorture -q || module=
modprobe -r rcutorture -q || module=
[ -n "$module" ] && \

(or even [ "$module" ] && \ )

We usually don't use 0 for shell scripts in LTP.
But that's a nit.

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 60

Quoted 13 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +7 -4
-TST_TOTAL=$(echo "$rcu_type" | wc -w)
+	[ $module -eq 0 ] && \
+		tst_brk TCONF "rcutorture is built-in, non-existent or in use"
+}
 
-est_time=`echo "scale=2; $test_time * $TST_TOTAL / 60 " | bc`
-tst_resm TINFO "estimate time $est_time min"
+rcutorture_test()
+{
+	local rcu_type=$1
 
-for type in $rcu_type; do
+	tst_res TINFO "${rcu_type}-torture: running ${test_time} sec..."
	tst_res TINFO "${rcu_type}-torture: running $test_time sec..."

(I prefer using brackets ${foo} only when needed - $foo is more readable).

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 63

Quoted 3 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +2 -1
-	tst_resm TINFO "$type: running $test_time sec..."
+	modprobe rcutorture nfakewriters=${num_writers} \
+		torture_type=${rcu_type} >/dev/null 2>&1

Again, use -q:
modprobe -q rcutorture nfakewriters=$num_writers torture_type=$rcu_type

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 66

Quoted 3 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +3 -0
+	if [ $? -ne 0 ]; then
+		dmesg | grep -q "invalid torture type: \"${rcu_type}\"" && \
+			tst_brk TCONF "invalid ${rcu_type} type"

and here ${foo} => $foo

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 68

Quoted 9 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +1 -8
-	modprobe rcutorture nfakewriters=$num_writers \
-	         stat_interval=60 test_no_idle_hz=1 shuffle_interval=3 \
-	         stutter=5 irqreader=1 fqs_duration=0 fqs_holdoff=0 \
-	         fqs_stutter=3 test_boost=1 test_boost_interval=7 \
-	         test_boost_duration=4 shutdown_secs=0 \
-	         stall_cpu=0 stall_cpu_holdoff=10 n_barrier_cbs=0 \
-	         onoff_interval=0 onoff_holdoff=0 torture_type=$type \
-	         > /dev/null 2>&1 || tst_brkm TBROK "failed to load module"
+		tst_brk TBROK "failed to load module"

And here. But I'd prefer to keep stderr (in case of failure it's better to see immediately what the problem was).

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 71

Quoted 4 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +2 -1
+	fi
 
-	sleep $test_time
+	sleep ${test_time}

sleep $test_time

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 74

Quoted 4 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +2 -2
-	rmmod rcutorture > /dev/null 2>&1 || \
-		tst_brkm TBROK "failed to unload module"
+	modprobe -r rcutorture >/dev/null 2>&1 || \
+		tst_brk TBROK "failed to unload module"

The same here (here I'd also keep stdout)

testcases/kernel/device-drivers/rcu/rcu_torture.sh line 81

Quoted 10 lines
testcases/kernel/device-drivers/rcu/rcu_torture.sh +4 -4
 	# check module status in dmesg
-	result_str=`dmesg | sed -nE '$s/.*End of test: ([A-Z]+):.*/\1/p'`
-	if [ "$result_str" = "SUCCESS" ]; then
-		tst_resm TPASS "$type: completed"
+	local res=$(dmesg | sed -nE "s/.* ${rcu_type}-torture:.* End of test: (.*): .*/\1/p" | tail -n1)
+	if [ "$res" = "SUCCESS" ]; then
+		tst_res TPASS "${rcu_type}-torture: $res"
 	else
-		tst_resm TFAIL "$type: $result_str, see dmesg"
+		tst_res TFAIL "${rcu_type}-torture: $res, see dmesg"

Maybe print dmesg (for automated tests, when you don't have direct access to machine).

Kind regards,
Petr

#2 lore raw

PATCH v3 1/1 rcu/rcu_torture.sh: Rewrite test

On 2019/07/11 14:03, Petr Vorel wrote:
Hi Petr,

Thanks for your detailed review. Just one question:

Quoted 2 lines

Maybe print dmesg (for automated tests, when you don't have direct access to machine).

Do you have any simple way to only print related dmesg for the every run when running it in loops?

Best Regards,
Xiao Yang

#3 lore raw

PATCH v3 1/1 rcu/rcu_torture.sh: Rewrite test

Hi Xiao,

Quoted 5 lines

Thanks for your detailed review. Just one question:

Quoted 2 lines

Maybe print dmesg (for automated tests, when you don't have direct access to machine).

Do you have any simple way to only print related dmesg for the every run when running it in loops?

Maybe some -c or -C dmesg switch? (at least cgroup_regression_test.sh or pm_sched_mc.py uses that).
But that's maybe too aggressive (removes dmesg for all previous tests). So feel free to ignore this.

Kind regards,
Petr

author
#4 lore raw

PATCH v3 1/1 rcu/rcu_torture.sh: Rewrite test

Quoted 11 lines · Petr Vorel

Hi Xiao,

Quoted 5 lines

Thanks for your detailed review. Just one question:

Quoted 2 lines

Maybe print dmesg (for automated tests, when you don't have direct access to machine).

Do you have any simple way to only print related dmesg for the every run when running it in loops?

Maybe some -c or -C dmesg switch? (at least cgroup_regression_test.sh or pm_sched_mc.py uses that).
But that's maybe too aggressive (removes dmesg for all previous tests). So feel free to ignore this.

Hi Petr,

It's aggressive to me as well. :-)
I will send v4 patch as you suggested.

Best Regards,
Xiao Yang

Quoted 3 lines

Kind regards,
Petr