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