lock_torture.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 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. TCID="lock_torture"
  26. TST_TOTAL=6
  27. TST_CLEANUP=cleanup
  28. . test.sh
  29. # default options
  30. test_time=60
  31. while getopts :ht: opt; do
  32. case "$opt" in
  33. h)
  34. echo "Usage:"
  35. echo "h help"
  36. echo "t x time in seconds for each test-case"
  37. exit 0
  38. ;;
  39. t) test_time=$OPTARG ;;
  40. *)
  41. tst_brkm TBROK "unknown option: $opt"
  42. ;;
  43. esac
  44. done
  45. cleanup()
  46. {
  47. tst_resm TINFO "cleanup"
  48. rmmod locktorture > /dev/null 2>&1
  49. }
  50. if tst_kvcmp -lt "3.18"; then
  51. tst_brkm TCONF "test must be run with kernel 3.18 or newer"
  52. fi
  53. tst_require_root
  54. # check if module is present
  55. modprobe locktorture > /dev/null 2>&1 || \
  56. tst_brkm TCONF "Test requires locktorture module"
  57. rmmod locktorture > /dev/null 2>&1
  58. trap cleanup INT
  59. lock_type="spin_lock spin_lock_irq rw_lock rw_lock_irq mutex_lock rwsem_lock"
  60. est_time=$(echo "scale=2; $test_time * $TST_TOTAL / 60 " | bc)
  61. tst_resm TINFO "estimate time $est_time min"
  62. for type in $lock_type; do
  63. tst_resm TINFO "$type: running $test_time sec..."
  64. modprobe locktorture torture_type=$type \
  65. > /dev/null 2>&1 || tst_brkm TBROK "failed to load module"
  66. sleep $test_time
  67. rmmod locktorture > /dev/null 2>&1 || \
  68. tst_brkm TBROK "failed to unload module"
  69. # check module status in dmesg
  70. result_str=`dmesg | sed -nE '$s/.*End of test: ([A-Z]+):.*/\1/p'`
  71. if [ "$result_str" = "SUCCESS" ]; then
  72. tst_resm TPASS "$type: completed"
  73. else
  74. tst_resm TFAIL "$type: $result_str, see dmesg"
  75. fi
  76. done
  77. tst_exit