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 <ice_yangxiao@163.com> 5# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 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. tst_test.sh 23 24# default options 25test_time=30 26num_writers=5 27 28rcutorture_usage() 29{ 30 echo "Usage:" 31 echo "-t x time in seconds for each test-case" 32 echo "-w x number of writers" 33} 34 35rcutorture_parse_args() 36{ 37 case $1 in 38 t) test_time=$2 ;; 39 w) num_writers=$2 ;; 40 esac 41} 42 43rcutorture_setup() 44{ 45 local module=1 46 47 # check if rcutorture is built as a kernel module by inserting 48 # and then removing it 49 modprobe -q rcutorture || module= 50 modprobe -qr rcutorture || module= 51 52 [ -z "$module" ] && \ 53 tst_brk TCONF "rcutorture is built-in, non-existent or in use" 54} 55 56rcutorture_test() 57{ 58 local rcu_type=$1 59 60 tst_res TINFO "$rcu_type-torture: running $test_time sec..." 61 62 modprobe rcutorture nfakewriters=$num_writers \ 63 torture_type=$rcu_type >/dev/null 64 if [ $? -ne 0 ]; then 65 dmesg | grep -q "invalid torture type: \"$rcu_type\"" && \ 66 tst_brk TCONF "invalid $rcu_type type" 67 68 tst_brk TBROK "failed to load module" 69 fi 70 71 sleep $test_time 72 73 modprobe -r rcutorture >/dev/null || \ 74 tst_brk TBROK "failed to unload module" 75 76 # check module status in dmesg 77 local res=$(dmesg | sed -nE "s/.* $rcu_type-torture:.* End of test: (.*): .*/\1/p" | tail -n1) 78 if [ "$res" = "SUCCESS" ]; then 79 tst_res TPASS "$rcu_type-torture: $res" 80 else 81 tst_res TFAIL "$rcu_type-torture: $res, see dmesg" 82 fi 83} 84 85do_test() 86{ 87 case $1 in 88 1) rcutorture_test rcu;; 89 2) rcutorture_test srcu;; 90 3) rcutorture_test srcud;; 91 4) rcutorture_test tasks;; 92 esac 93} 94 95tst_run 96