1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 3f08c3bdfSopenharmony_ci# 4f08c3bdfSopenharmony_ci# This program is free software; you can redistribute it and/or 5f08c3bdfSopenharmony_ci# modify it under the terms of the GNU General Public License as 6f08c3bdfSopenharmony_ci# published by the Free Software Foundation; either version 2 of 7f08c3bdfSopenharmony_ci# the License, or (at your option) any later version. 8f08c3bdfSopenharmony_ci# 9f08c3bdfSopenharmony_ci# This program is distributed in the hope that it would be useful, 10f08c3bdfSopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of 11f08c3bdfSopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12f08c3bdfSopenharmony_ci# GNU General Public License for more details. 13f08c3bdfSopenharmony_ci# 14f08c3bdfSopenharmony_ci# You should have received a copy of the GNU General Public License 15f08c3bdfSopenharmony_ci# along with this program; if not, write the Free Software Foundation, 16f08c3bdfSopenharmony_ci# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17f08c3bdfSopenharmony_ci# 18f08c3bdfSopenharmony_ci# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 19f08c3bdfSopenharmony_ci# 20f08c3bdfSopenharmony_ci# This is a wrapper for locktorture kernel module. The test requires 21f08c3bdfSopenharmony_ci# that kernel configured with CONFIG_LOCK_TORTURE_TEST. It runs locktorture 22f08c3bdfSopenharmony_ci# module using particular options and then inspects dmesg output for module's 23f08c3bdfSopenharmony_ci# test results. For more information, please read Linux Documentation: 24f08c3bdfSopenharmony_ci# locking/locktorture.txt 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ciTCID="lock_torture" 27f08c3bdfSopenharmony_ciTST_TOTAL=6 28f08c3bdfSopenharmony_ciTST_CLEANUP=cleanup 29f08c3bdfSopenharmony_ci. test.sh 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci# default options 32f08c3bdfSopenharmony_citest_time=60 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ciwhile getopts :ht: opt; do 35f08c3bdfSopenharmony_ci case "$opt" in 36f08c3bdfSopenharmony_ci h) 37f08c3bdfSopenharmony_ci echo "Usage:" 38f08c3bdfSopenharmony_ci echo "h help" 39f08c3bdfSopenharmony_ci echo "t x time in seconds for each test-case" 40f08c3bdfSopenharmony_ci exit 0 41f08c3bdfSopenharmony_ci ;; 42f08c3bdfSopenharmony_ci t) test_time=$OPTARG ;; 43f08c3bdfSopenharmony_ci *) 44f08c3bdfSopenharmony_ci tst_brkm TBROK "unknown option: $opt" 45f08c3bdfSopenharmony_ci ;; 46f08c3bdfSopenharmony_ci esac 47f08c3bdfSopenharmony_cidone 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_cicleanup() 50f08c3bdfSopenharmony_ci{ 51f08c3bdfSopenharmony_ci tst_resm TINFO "cleanup" 52f08c3bdfSopenharmony_ci rmmod locktorture > /dev/null 2>&1 53f08c3bdfSopenharmony_ci} 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ciif tst_kvcmp -lt "3.18"; then 56f08c3bdfSopenharmony_ci tst_brkm TCONF "test must be run with kernel 3.18 or newer" 57f08c3bdfSopenharmony_cifi 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_citst_require_root 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci# check if module is present 62f08c3bdfSopenharmony_cimodprobe locktorture > /dev/null 2>&1 || \ 63f08c3bdfSopenharmony_ci tst_brkm TCONF "Test requires locktorture module" 64f08c3bdfSopenharmony_cirmmod locktorture > /dev/null 2>&1 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_citrap cleanup INT 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_cilock_type="spin_lock spin_lock_irq rw_lock rw_lock_irq mutex_lock rwsem_lock" 69f08c3bdfSopenharmony_ci 70f08c3bdfSopenharmony_ciest_time=$(echo "scale=2; $test_time * $TST_TOTAL / 60 " | bc) 71f08c3bdfSopenharmony_citst_resm TINFO "estimate time $est_time min" 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_cifor type in $lock_type; do 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci tst_resm TINFO "$type: running $test_time sec..." 76f08c3bdfSopenharmony_ci 77f08c3bdfSopenharmony_ci modprobe locktorture torture_type=$type \ 78f08c3bdfSopenharmony_ci > /dev/null 2>&1 || tst_brkm TBROK "failed to load module" 79f08c3bdfSopenharmony_ci 80f08c3bdfSopenharmony_ci sleep $test_time 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci rmmod locktorture > /dev/null 2>&1 || \ 83f08c3bdfSopenharmony_ci tst_brkm TBROK "failed to unload module" 84f08c3bdfSopenharmony_ci 85f08c3bdfSopenharmony_ci # check module status in dmesg 86f08c3bdfSopenharmony_ci result_str=`dmesg | sed -nE '$s/.*End of test: ([A-Z]+):.*/\1/p'` 87f08c3bdfSopenharmony_ci if [ "$result_str" = "SUCCESS" ]; then 88f08c3bdfSopenharmony_ci tst_resm TPASS "$type: completed" 89f08c3bdfSopenharmony_ci else 90f08c3bdfSopenharmony_ci tst_resm TFAIL "$type: $result_str, see dmesg" 91f08c3bdfSopenharmony_ci fi 92f08c3bdfSopenharmony_cidone 93f08c3bdfSopenharmony_ci 94f08c3bdfSopenharmony_citst_exit 95