• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@oracle.com>
19#
20# This is a wrapper for locktorture kernel module. The test requiers
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
26TCID="lock_torture"
27TST_TOTAL=6
28TST_CLEANUP=cleanup
29. test.sh
30
31# default options
32test_time=60
33
34while 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
47done
48
49cleanup()
50{
51	tst_resm TINFO "cleanup"
52	rmmod locktorture > /dev/null 2>&1
53}
54
55tst_kvercmp 3 18 0 && \
56	tst_brkm TCONF "test must be run with kernel 3.18 or newer"
57
58tst_require_root
59
60# check if module is present
61modprobe locktorture > /dev/null 2>&1 || \
62	tst_brkm TCONF "Test requires locktorture module"
63rmmod locktorture > /dev/null 2>&1
64
65trap cleanup INT
66
67lock_type="spin_lock spin_lock_irq rw_lock rw_lock_irq mutex_lock rwsem_lock"
68
69est_time=$(echo "scale=2; $test_time * $TST_TOTAL / 60 " | bc)
70tst_resm TINFO "estimate time $est_time min"
71
72for type in $lock_type; do
73
74	tst_resm TINFO "$type: running $test_time sec..."
75
76	modprobe locktorture torture_type=$type \
77	         > /dev/null 2>&1 || tst_brkm TBROK "failed to load module"
78
79	sleep $test_time
80
81	rmmod locktorture > /dev/null 2>&1 || \
82		tst_brkm TBROK "failed to unload module"
83
84	# check module status in dmesg
85	result_str=`dmesg | sed -nE '$s/.*End of test: ([A-Z]+):.*/\1/p'`
86	if [ "$result_str" = "SUCCESS" ]; then
87		tst_resm TPASS "$type: completed"
88	else
89		tst_resm TFAIL "$type: $result_str, see dmesg"
90	fi
91done
92
93tst_exit
94