runpwtests03.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #! /bin/sh
  2. #
  3. # Copyright (c) International Business Machines Corp., 2001
  4. # Author: Nageswara R Sastry <nasastry@in.ibm.com>
  5. #
  6. # This program is free software; you can redistribute it and#or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. # for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. #
  20. export TCID="Power_Management03"
  21. export TST_TOTAL=4
  22. . test.sh
  23. . pm_include.sh
  24. check_cpufreq_sysfs_files() {
  25. total_cpus=`expr $(tst_ncpus) - 1`
  26. RC=0
  27. for cpu in $(seq 0 "${total_cpus}" )
  28. do
  29. cpufiles=$(find /sys/devices/system/cpu/cpu"${cpu}"/cpufreq/ \
  30. -name "*" -type f -perm /400)
  31. for files in ${cpufiles}
  32. do
  33. cat ${files} >/dev/null 2>&1
  34. if [ $? -ne 0 ] ; then
  35. echo "${0}: FAIL: cat ${files}"
  36. RC=1
  37. fi
  38. done
  39. done
  40. if [ ${RC} -eq 0 ] ; then
  41. echo "${0}: PASS: Checking cpu freq sysfs files"
  42. fi
  43. return $RC
  44. }
  45. change_govr() {
  46. available_govr=$(get_supporting_govr)
  47. total_cpus=`expr $(tst_ncpus) - 1`
  48. RC=0
  49. for cpu in $(seq 0 "${total_cpus}" )
  50. do
  51. for govr in ${available_govr}
  52. do
  53. echo ${govr} > \
  54. /sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor
  55. if [ "$?" -ne "0" ] ; then
  56. echo "${0}: FAIL: Unable to set" \
  57. "governor -- ${govr} for cpu${cpu}"
  58. RC=1
  59. fi
  60. done
  61. done
  62. if [ ${RC} -eq 0 ] ; then
  63. echo "${0}: PASS: Changing cpu governors"
  64. fi
  65. return $RC
  66. }
  67. change_freq() {
  68. available_freq=$(get_supporting_freq)
  69. available_govr=$(get_supporting_govr)
  70. RC=0
  71. total_cpus=`expr $(tst_ncpus) - 1`
  72. if ( echo ${available_govr} | grep -i "userspace" \
  73. >/dev/null 2>&1 ); then
  74. for cpu in $(seq 0 "${total_cpus}" )
  75. do
  76. echo userspace > \
  77. /sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor
  78. if [ $? -ne 0 ] ; then
  79. RC=1
  80. fi
  81. done
  82. if [ ${RC} -ne 1 ] ; then
  83. for cpu in $(seq 0 "${total_cpus}" )
  84. do
  85. for freq in ${available_freq}
  86. do
  87. echo ${freq} > \
  88. /sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_setspeed
  89. if [ "$?" -ne "0" ] ; then
  90. echo "${0}: FAIL: Unable" \
  91. "to set frequency -- ${freq} for cpu${cpu}"
  92. RC=1
  93. fi
  94. done
  95. done
  96. fi
  97. fi
  98. if [ ${RC} -eq 0 ] ; then
  99. echo "${0}: PASS: Changing cpu frequencies"
  100. fi
  101. return $RC
  102. }
  103. pwkm_load_unload() {
  104. RC=0
  105. loaded_governor=`cat \
  106. /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
  107. for module in `modprobe -l | grep cpufreq_ | \
  108. cut -f8 -d"/" | cut -f1 -d"."`
  109. do
  110. #echo -n "Loading $module ... "
  111. if [ $module != "cpufreq_$loaded_governor" ]; then
  112. modprobe $module >/dev/null
  113. if [ $? -ne 0 ] ; then
  114. echo "${0}: FAIL: Loading of module $module" \
  115. "or check whether you compiled as module or not"
  116. RC=1
  117. fi
  118. fi
  119. done
  120. for module in `modprobe -l | grep cpufreq_ | \
  121. cut -f8 -d"/" | cut -f1 -d"."`
  122. do
  123. #echo -n "Unloading $module ... "
  124. if [ $module != "cpufreq_$loaded_governor" ]; then
  125. modprobe -r $module >/dev/null
  126. if [ $? -ne 0 ] ; then
  127. echo "${0}: FAIL: Loading of module $module" \
  128. "or check whether you compiled as module or not"
  129. RC=1
  130. fi
  131. fi
  132. done
  133. return $RC
  134. }
  135. # Checking test environment
  136. check_kervel_arch
  137. # Checking cpufreq sysfs interface files
  138. if [ ! -d /sys/devices/system/cpu/cpu0/cpufreq ] ; then
  139. tst_brkm TCONF "Required kernel configuration for CPU_FREQ NOT set"
  140. fi
  141. if check_cpufreq_sysfs_files ; then
  142. tst_resm TPASS "CPUFREQ sysfs tests"
  143. else
  144. tst_resm TFAIL "CPUFREQ sysfs tests"
  145. fi
  146. # Changing governors
  147. if change_govr ; then
  148. tst_resm TPASS "Changing governors"
  149. else
  150. tst_resm TFAIL "Changing governors"
  151. fi
  152. # Changing frequencies
  153. if change_freq ; then
  154. tst_resm TPASS "Changing frequncies"
  155. else
  156. tst_resm TFAIL "Changing frequncies"
  157. fi
  158. # Loading and Unloading governor related kernel modules
  159. if pwkm_load_unload ; then
  160. tst_resm TPASS "Loading and Unloading of governor kernel" \
  161. "modules"
  162. else
  163. tst_resm TFAIL "Loading and Unloading of governor kernel" \
  164. "modules got failed"
  165. fi
  166. tst_exit