xref: /aosp_15_r20/external/ltp/testcases/kernel/device-drivers/rcu/rcu_torture.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2014-2015 Oracle and/or its affiliates. All Rights Reserved.
4# Copyright (C) 2019 Xiao Yang <[email protected]>
5# Author: Alexey Kodanev <[email protected]>
6#
7# One of the possible ways to test RCU is to use rcutorture kernel module.
8# The test requires that kernel configured with CONFIG_RCU_TORTURE_TEST.
9# It runs rcutorture module using particular options and then inspects
10# dmesg output for module's test results.
11# For more information, please read Linux Documentation: RCU/torture.txt
12
13TST_CNT=4
14TST_SETUP=rcutorture_setup
15TST_TESTFUNC=do_test
16TST_NEEDS_ROOT=1
17TST_NEEDS_CMDS="modprobe dmesg sed tail"
18TST_OPTS="t:w:"
19TST_USAGE=rcutorture_usage
20TST_PARSE_ARGS=rcutorture_parse_args
21
22# default options
23test_time=30
24num_writers=5
25
26rcutorture_usage()
27{
28	echo "Usage:"
29	echo "-t x    time in seconds for each test-case"
30	echo "-w x    number of writers"
31}
32
33rcutorture_parse_args()
34{
35	case $1 in
36	t) test_time=$2 ;;
37	w) num_writers=$2 ;;
38	esac
39}
40
41rcutorture_setup()
42{
43	local module=1
44
45	# check if rcutorture is built as a kernel module by inserting
46	# and then removing it
47	modprobe -q rcutorture ||  module=
48	modprobe -qr rcutorture || module=
49
50	[ -z "$module" ] && \
51		tst_brk TCONF "rcutorture is built-in, non-existent or in use"
52}
53
54rcutorture_test()
55{
56	local rcu_type=$1
57
58	tst_res TINFO "$rcu_type-torture: running $test_time sec..."
59
60	modprobe rcutorture nfakewriters=$num_writers \
61		torture_type=$rcu_type >/dev/null
62	if [ $? -ne 0 ]; then
63		dmesg | grep -q "invalid torture type: \"$rcu_type\"" && \
64			tst_brk TCONF "invalid $rcu_type type"
65
66		tst_brk TBROK "failed to load module"
67	fi
68
69	sleep $test_time
70
71	modprobe -r rcutorture >/dev/null || \
72		tst_brk TBROK "failed to unload module"
73
74	# check module status in dmesg
75	local res=$(dmesg | sed -nE "s/.* $rcu_type-torture:.* End of test: (.*): .*/\1/p" | tail -n1)
76	if [ "$res" = "SUCCESS" ]; then
77		tst_res TPASS "$rcu_type-torture: $res"
78	else
79		tst_res TFAIL "$rcu_type-torture: $res, see dmesg"
80	fi
81}
82
83do_test()
84{
85	case $1 in
86	1) rcutorture_test rcu;;
87	2) rcutorture_test srcu;;
88	3) rcutorture_test srcud;;
89	4) rcutorture_test tasks;;
90	esac
91}
92
93. tst_test.sh
94tst_run
95