test_vmalloc.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Copyright (C) 2018 Uladzislau Rezki (Sony) <[email protected]>
  5. #
  6. # This is a test script for the kernel test driver to analyse vmalloc
  7. # allocator. Therefore it is just a kernel module loader. You can specify
  8. # and pass different parameters in order to:
  9. # a) analyse performance of vmalloc allocations;
  10. # b) stressing and stability check of vmalloc subsystem.
  11. TEST_NAME="vmalloc"
  12. DRIVER="test_${TEST_NAME}"
  13. NUM_CPUS=`grep -c ^processor /proc/cpuinfo`
  14. # 1 if fails
  15. exitcode=1
  16. # Kselftest framework requirement - SKIP code is 4.
  17. ksft_skip=4
  18. #
  19. # Static templates for performance, stressing and smoke tests.
  20. # Also it is possible to pass any supported parameters manualy.
  21. #
  22. PERF_PARAM="sequential_test_order=1 test_repeat_count=3"
  23. SMOKE_PARAM="test_loop_count=10000 test_repeat_count=10"
  24. STRESS_PARAM="nr_threads=$NUM_CPUS test_repeat_count=20"
  25. check_test_requirements()
  26. {
  27. uid=$(id -u)
  28. if [ $uid -ne 0 ]; then
  29. echo "$0: Must be run as root"
  30. exit $ksft_skip
  31. fi
  32. if ! which modprobe > /dev/null 2>&1; then
  33. echo "$0: You need modprobe installed"
  34. exit $ksft_skip
  35. fi
  36. if ! modinfo $DRIVER > /dev/null 2>&1; then
  37. echo "$0: You must have the following enabled in your kernel:"
  38. echo "CONFIG_TEST_VMALLOC=m"
  39. exit $ksft_skip
  40. fi
  41. }
  42. run_perfformance_check()
  43. {
  44. echo "Run performance tests to evaluate how fast vmalloc allocation is."
  45. echo "It runs all test cases on one single CPU with sequential order."
  46. modprobe $DRIVER $PERF_PARAM > /dev/null 2>&1
  47. echo "Done."
  48. echo "Ccheck the kernel message buffer to see the summary."
  49. }
  50. run_stability_check()
  51. {
  52. echo "Run stability tests. In order to stress vmalloc subsystem all"
  53. echo "available test cases are run by NUM_CPUS workers simultaneously."
  54. echo "It will take time, so be patient."
  55. modprobe $DRIVER $STRESS_PARAM > /dev/null 2>&1
  56. echo "Done."
  57. echo "Check the kernel ring buffer to see the summary."
  58. }
  59. run_smoke_check()
  60. {
  61. echo "Run smoke test. Note, this test provides basic coverage."
  62. echo "Please check $0 output how it can be used"
  63. echo "for deep performance analysis as well as stress testing."
  64. modprobe $DRIVER $SMOKE_PARAM > /dev/null 2>&1
  65. echo "Done."
  66. echo "Check the kernel ring buffer to see the summary."
  67. }
  68. usage()
  69. {
  70. echo -n "Usage: $0 [ performance ] | [ stress ] | | [ smoke ] | "
  71. echo "manual parameters"
  72. echo
  73. echo "Valid tests and parameters:"
  74. echo
  75. modinfo $DRIVER
  76. echo
  77. echo "Example usage:"
  78. echo
  79. echo "# Shows help message"
  80. echo "./${DRIVER}.sh"
  81. echo
  82. echo "# Runs 1 test(id_1), repeats it 5 times by NUM_CPUS workers"
  83. echo "./${DRIVER}.sh nr_threads=$NUM_CPUS run_test_mask=1 test_repeat_count=5"
  84. echo
  85. echo -n "# Runs 4 tests(id_1|id_2|id_4|id_16) on one CPU with "
  86. echo "sequential order"
  87. echo -n "./${DRIVER}.sh sequential_test_order=1 "
  88. echo "run_test_mask=23"
  89. echo
  90. echo -n "# Runs all tests by NUM_CPUS workers, shuffled order, repeats "
  91. echo "20 times"
  92. echo "./${DRIVER}.sh nr_threads=$NUM_CPUS test_repeat_count=20"
  93. echo
  94. echo "# Performance analysis"
  95. echo "./${DRIVER}.sh performance"
  96. echo
  97. echo "# Stress testing"
  98. echo "./${DRIVER}.sh stress"
  99. echo
  100. exit 0
  101. }
  102. function validate_passed_args()
  103. {
  104. VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`
  105. #
  106. # Something has been passed, check it.
  107. #
  108. for passed_arg in $@; do
  109. key=${passed_arg//=*/}
  110. val="${passed_arg:$((${#key}+1))}"
  111. valid=0
  112. for valid_arg in $VALID_ARGS; do
  113. if [[ $key = $valid_arg ]] && [[ $val -gt 0 ]]; then
  114. valid=1
  115. break
  116. fi
  117. done
  118. if [[ $valid -ne 1 ]]; then
  119. echo "Error: key or value is not correct: ${key} $val"
  120. exit $exitcode
  121. fi
  122. done
  123. }
  124. function run_manual_check()
  125. {
  126. #
  127. # Validate passed parameters. If there is wrong one,
  128. # the script exists and does not execute further.
  129. #
  130. validate_passed_args $@
  131. echo "Run the test with following parameters: $@"
  132. modprobe $DRIVER $@ > /dev/null 2>&1
  133. echo "Done."
  134. echo "Check the kernel ring buffer to see the summary."
  135. }
  136. function run_test()
  137. {
  138. if [ $# -eq 0 ]; then
  139. usage
  140. else
  141. if [[ "$1" = "performance" ]]; then
  142. run_perfformance_check
  143. elif [[ "$1" = "stress" ]]; then
  144. run_stability_check
  145. elif [[ "$1" = "smoke" ]]; then
  146. run_smoke_check
  147. else
  148. run_manual_check $@
  149. fi
  150. fi
  151. }
  152. check_test_requirements
  153. run_test $@
  154. exit 0