main.sh 3.4 KB

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