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