rcu_torture.sh 2.2 KB

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