run_kselftest.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Run installed kselftest tests.
  5. #
  6. BASE_DIR=$(realpath $(dirname $0))
  7. cd $BASE_DIR
  8. TESTS="$BASE_DIR"/kselftest-list.txt
  9. if [ ! -r "$TESTS" ] ; then
  10. echo "$0: Could not find list of tests to run ($TESTS)" >&2
  11. available=""
  12. else
  13. available="$(cat "$TESTS")"
  14. fi
  15. . ./kselftest/runner.sh
  16. ROOT=$PWD
  17. usage()
  18. {
  19. cat <<EOF
  20. Usage: $0 [OPTIONS]
  21. -s | --summary Print summary with detailed log in output.log (conflict with -p)
  22. -p | --per_test_log Print test log in /tmp with each test name (conflict with -s)
  23. -t | --test COLLECTION:TEST Run TEST from COLLECTION
  24. -c | --collection COLLECTION Run all tests from COLLECTION
  25. -l | --list List the available collection:test entries
  26. -d | --dry-run Don't actually run any tests
  27. -n | --netns Run each test in namespace
  28. -h | --help Show this usage info
  29. -o | --override-timeout Number of seconds after which we timeout
  30. EOF
  31. exit $1
  32. }
  33. COLLECTIONS=""
  34. TESTS=""
  35. dryrun=""
  36. kselftest_override_timeout=""
  37. while true; do
  38. case "$1" in
  39. -s | --summary)
  40. logfile="$BASE_DIR"/output.log
  41. cat /dev/null > $logfile
  42. shift ;;
  43. -p | --per-test-log)
  44. per_test_logging=1
  45. shift ;;
  46. -t | --test)
  47. TESTS="$TESTS $2"
  48. shift 2 ;;
  49. -c | --collection)
  50. COLLECTIONS="$COLLECTIONS $2"
  51. shift 2 ;;
  52. -l | --list)
  53. echo "$available"
  54. exit 0 ;;
  55. -d | --dry-run)
  56. dryrun="echo"
  57. shift ;;
  58. -n | --netns)
  59. RUN_IN_NETNS=1
  60. shift ;;
  61. -o | --override-timeout)
  62. kselftest_override_timeout="$2"
  63. shift 2 ;;
  64. -h | --help)
  65. usage 0 ;;
  66. "")
  67. break ;;
  68. *)
  69. usage 1 ;;
  70. esac
  71. done
  72. # Add all selected collections to the explicit test list.
  73. if [ -n "$COLLECTIONS" ]; then
  74. for collection in $COLLECTIONS ; do
  75. found="$(echo "$available" | grep "^$collection:")"
  76. if [ -z "$found" ] ; then
  77. echo "No such collection '$collection'" >&2
  78. exit 1
  79. fi
  80. TESTS="$TESTS $found"
  81. done
  82. fi
  83. # Replace available test list with explicitly selected tests.
  84. if [ -n "$TESTS" ]; then
  85. valid=""
  86. for test in $TESTS ; do
  87. found="$(echo "$available" | grep "^${test}$")"
  88. if [ -z "$found" ] ; then
  89. echo "No such test '$test'" >&2
  90. exit 1
  91. fi
  92. valid="$valid $found"
  93. done
  94. available="$(echo "$valid" | sed -e 's/ /\n/g')"
  95. fi
  96. collections=$(echo "$available" | cut -d: -f1 | sort | uniq)
  97. for collection in $collections ; do
  98. [ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg
  99. tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2)
  100. ($dryrun cd "$collection" && $dryrun run_many $tests)
  101. done