main.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. source cpu.sh
  4. source cpufreq.sh
  5. source governor.sh
  6. source module.sh
  7. source special-tests.sh
  8. DIR="$(dirname $(readlink -f "$0"))"
  9. source "${DIR}"/../kselftest/ktap_helpers.sh
  10. FUNC=basic # do basic tests by default
  11. OUTFILE=cpufreq_selftest
  12. SYSFS=
  13. CPUROOT=
  14. CPUFREQROOT=
  15. helpme()
  16. {
  17. printf "Usage: $0 [-h] [-todg args]
  18. [-h <help>]
  19. [-o <output-file-for-dump>]
  20. [-t <basic: Basic cpufreq testing
  21. suspend: suspend/resume,
  22. hibernate: hibernate/resume,
  23. suspend_rtc: suspend/resume back using the RTC wakeup alarm,
  24. hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
  25. modtest: test driver or governor modules. Only to be used with -d or -g options,
  26. sptest1: Simple governor switch to produce lockdep.
  27. sptest2: Concurrent governor switch to produce lockdep.
  28. sptest3: Governor races, shuffle between governors quickly.
  29. sptest4: CPU hotplugs with updates to cpufreq files.>]
  30. [-d <driver's module name: only with \"-t modtest>\"]
  31. [-g <governor's module name: only with \"-t modtest>\"]
  32. \n"
  33. exit "${KSFT_FAIL}"
  34. }
  35. prerequisite()
  36. {
  37. msg="skip all tests:"
  38. if [ $UID != 0 ]; then
  39. ktap_skip_all "$msg must be run as root"
  40. exit "${KSFT_SKIP}"
  41. fi
  42. taskset -p 01 $$
  43. SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
  44. if [ ! -d "$SYSFS" ]; then
  45. ktap_skip_all "$msg sysfs is not mounted"
  46. exit "${KSFT_SKIP}"
  47. fi
  48. CPUROOT=$SYSFS/devices/system/cpu
  49. CPUFREQROOT="$CPUROOT/cpufreq"
  50. if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
  51. ktap_skip_all "$msg cpus not available in sysfs"
  52. exit "${KSFT_SKIP}"
  53. fi
  54. if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
  55. ktap_skip_all "$msg cpufreq directory not available in sysfs"
  56. exit "${KSFT_SKIP}"
  57. fi
  58. }
  59. parse_arguments()
  60. {
  61. while getopts ht:o:d:g: arg
  62. do
  63. case $arg in
  64. h) # --help
  65. helpme
  66. ;;
  67. t) # --func_type (Function to perform: basic, suspend, hibernate,
  68. # suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
  69. FUNC=$OPTARG
  70. ;;
  71. o) # --output-file (Output file to store dumps)
  72. OUTFILE=$OPTARG
  73. ;;
  74. d) # --driver-mod-name (Name of the driver module)
  75. DRIVER_MOD=$OPTARG
  76. ;;
  77. g) # --governor-mod-name (Name of the governor module)
  78. GOVERNOR_MOD=$OPTARG
  79. ;;
  80. \?)
  81. helpme
  82. ;;
  83. esac
  84. done
  85. }
  86. do_test()
  87. {
  88. # Check if CPUs are managed by cpufreq or not
  89. count=$(count_cpufreq_managed_cpus)
  90. if [ $count = 0 -a $FUNC != "modtest" ]; then
  91. ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
  92. fi
  93. case "$FUNC" in
  94. "basic")
  95. cpufreq_basic_tests
  96. ;;
  97. "suspend")
  98. do_suspend "suspend" 1
  99. ;;
  100. "hibernate")
  101. do_suspend "hibernate" 1
  102. ;;
  103. "suspend_rtc")
  104. do_suspend "suspend" 1 rtc
  105. ;;
  106. "hibernate_rtc")
  107. do_suspend "hibernate" 1 rtc
  108. ;;
  109. "modtest")
  110. # Do we have modules in place?
  111. if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
  112. ktap_exit_fail_msg "No driver or governor module passed with -d or -g"
  113. fi
  114. if [ $DRIVER_MOD ]; then
  115. if [ $GOVERNOR_MOD ]; then
  116. module_test $DRIVER_MOD $GOVERNOR_MOD
  117. else
  118. module_driver_test $DRIVER_MOD
  119. fi
  120. else
  121. if [ $count = 0 ]; then
  122. ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
  123. fi
  124. module_governor_test $GOVERNOR_MOD
  125. fi
  126. ;;
  127. "sptest1")
  128. simple_lockdep
  129. ;;
  130. "sptest2")
  131. concurrent_lockdep
  132. ;;
  133. "sptest3")
  134. governor_race
  135. ;;
  136. "sptest4")
  137. hotplug_with_updates
  138. ;;
  139. *)
  140. ktap_print_msg "Invalid [-f] function type"
  141. helpme
  142. ;;
  143. esac
  144. }
  145. # clear dumps
  146. # $1: file name
  147. clear_dumps()
  148. {
  149. echo "" > $1.txt
  150. echo "" > $1.dmesg_cpufreq.txt
  151. echo "" > $1.dmesg_full.txt
  152. }
  153. # $1: output file name
  154. dmesg_dumps()
  155. {
  156. dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
  157. # We may need the full logs as well
  158. dmesg >> $1.dmesg_full.txt
  159. }
  160. ktap_print_header
  161. # Parse arguments
  162. parse_arguments $@
  163. ktap_set_plan 1
  164. # Make sure all requirements are met
  165. prerequisite
  166. # Run requested functions
  167. clear_dumps $OUTFILE
  168. do_test | tee -a $OUTFILE.txt
  169. if [ "${PIPESTATUS[0]}" -ne 0 ]; then
  170. exit ${PIPESTATUS[0]};
  171. fi
  172. dmesg_dumps $OUTFILE
  173. ktap_test_pass "Completed successfully"
  174. ktap_print_totals
  175. exit "${KSFT_PASS}"