main.sh 3.5 KB

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