test_hmm.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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="test_hmm"
  12. DRIVER="test_hmm"
  13. # 1 if fails
  14. exitcode=1
  15. # Kselftest framework requirement - SKIP code is 4.
  16. ksft_skip=4
  17. check_test_requirements()
  18. {
  19. uid=$(id -u)
  20. if [ $uid -ne 0 ]; then
  21. echo "$0: Must be run as root"
  22. exit $ksft_skip
  23. fi
  24. if ! which modprobe > /dev/null 2>&1; then
  25. echo "$0: You need modprobe installed"
  26. exit $ksft_skip
  27. fi
  28. if ! modinfo $DRIVER > /dev/null 2>&1; then
  29. echo "$0: You must have the following enabled in your kernel:"
  30. echo "CONFIG_TEST_HMM=m"
  31. exit $ksft_skip
  32. fi
  33. }
  34. load_driver()
  35. {
  36. if [ $# -eq 0 ]; then
  37. modprobe $DRIVER > /dev/null 2>&1
  38. else
  39. if [ $# -eq 2 ]; then
  40. modprobe $DRIVER spm_addr_dev0=$1 spm_addr_dev1=$2
  41. > /dev/null 2>&1
  42. else
  43. echo "Missing module parameters. Make sure pass"\
  44. "spm_addr_dev0 and spm_addr_dev1"
  45. usage
  46. fi
  47. fi
  48. }
  49. unload_driver()
  50. {
  51. modprobe -r $DRIVER > /dev/null 2>&1
  52. }
  53. run_smoke()
  54. {
  55. echo "Running smoke test. Note, this test provides basic coverage."
  56. load_driver $1 $2
  57. $(dirname "${BASH_SOURCE[0]}")/hmm-tests
  58. unload_driver
  59. }
  60. usage()
  61. {
  62. echo -n "Usage: $0"
  63. echo
  64. echo "Example usage:"
  65. echo
  66. echo "# Shows help message"
  67. echo "./${TEST_NAME}.sh"
  68. echo
  69. echo "# Smoke testing"
  70. echo "./${TEST_NAME}.sh smoke"
  71. echo
  72. echo "# Smoke testing with SPM enabled"
  73. echo "./${TEST_NAME}.sh smoke <spm_addr_dev0> <spm_addr_dev1>"
  74. echo
  75. exit 0
  76. }
  77. function run_test()
  78. {
  79. if [ $# -eq 0 ]; then
  80. usage
  81. else
  82. if [ "$1" = "smoke" ]; then
  83. run_smoke $2 $3
  84. else
  85. usage
  86. fi
  87. fi
  88. }
  89. check_test_requirements
  90. run_test $@
  91. exit 0