module.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Modules specific tests cases
  5. # protect against multiple inclusion
  6. if [ $FILE_MODULE ]; then
  7. return 0
  8. else
  9. FILE_MODULE=DONE
  10. fi
  11. source cpu.sh
  12. source cpufreq.sh
  13. source governor.sh
  14. # Check basic insmod/rmmod
  15. # $1: module
  16. test_basic_insmod_rmmod()
  17. {
  18. printf "** Test: Running ${FUNCNAME[0]} **\n\n"
  19. printf "Inserting $1 module\n"
  20. # insert module
  21. insmod $1
  22. if [ $? != 0 ]; then
  23. ktap_exit_fail_msg "Insmod $1 failed\n"
  24. fi
  25. printf "Removing $1 module\n"
  26. # remove module
  27. rmmod $1
  28. if [ $? != 0 ]; then
  29. ktap_exit_fail_msg "rmmod $1 failed\n"
  30. fi
  31. printf "\n"
  32. }
  33. # Insert cpufreq driver module and perform basic tests
  34. # $1: cpufreq-driver module to insert
  35. # $2: If we want to play with CPUs (1) or not (0)
  36. module_driver_test_single()
  37. {
  38. printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n"
  39. if [ $2 -eq 1 ]; then
  40. # offline all non-boot CPUs
  41. for_each_non_boot_cpu offline_cpu
  42. printf "\n"
  43. fi
  44. # insert module
  45. printf "Inserting $1 module\n\n"
  46. insmod $1
  47. if [ $? != 0 ]; then
  48. printf "Insmod $1 failed\n"
  49. return;
  50. fi
  51. if [ $2 -eq 1 ]; then
  52. # online all non-boot CPUs
  53. for_each_non_boot_cpu online_cpu
  54. printf "\n"
  55. fi
  56. # run basic tests
  57. cpufreq_basic_tests
  58. # remove module
  59. printf "Removing $1 module\n\n"
  60. rmmod $1
  61. if [ $? != 0 ]; then
  62. printf "rmmod $1 failed\n"
  63. return;
  64. fi
  65. # There shouldn't be any cpufreq directories now.
  66. for_each_cpu cpu_should_not_have_cpufreq_directory
  67. printf "\n"
  68. }
  69. # $1: cpufreq-driver module to insert
  70. module_driver_test()
  71. {
  72. printf "** Test: Running ${FUNCNAME[0]} **\n\n"
  73. # check if module is present or not
  74. ls $1 > /dev/null
  75. if [ $? != 0 ]; then
  76. printf "$1: not present in `pwd` folder\n"
  77. return;
  78. fi
  79. # test basic module tests
  80. test_basic_insmod_rmmod $1
  81. # Do simple module test
  82. module_driver_test_single $1 0
  83. # Remove CPUs before inserting module and then bring them back
  84. module_driver_test_single $1 1
  85. printf "\n"
  86. }
  87. # find governor name based on governor module name
  88. # $1: governor module name
  89. find_gov_name()
  90. {
  91. if [ $1 = "cpufreq_ondemand.ko" ]; then
  92. printf "ondemand"
  93. elif [ $1 = "cpufreq_conservative.ko" ]; then
  94. printf "conservative"
  95. elif [ $1 = "cpufreq_userspace.ko" ]; then
  96. printf "userspace"
  97. elif [ $1 = "cpufreq_performance.ko" ]; then
  98. printf "performance"
  99. elif [ $1 = "cpufreq_powersave.ko" ]; then
  100. printf "powersave"
  101. elif [ $1 = "cpufreq_schedutil.ko" ]; then
  102. printf "schedutil"
  103. fi
  104. }
  105. # $1: governor string, $2: governor module, $3: policy
  106. # example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2
  107. module_governor_test_single()
  108. {
  109. printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n"
  110. backup_governor $3
  111. # switch to new governor
  112. printf "Switch from $CUR_GOV to $1\n"
  113. switch_show_governor $3 $1
  114. # try removing module, it should fail as governor is used
  115. printf "Removing $2 module\n\n"
  116. rmmod $2
  117. if [ $? = 0 ]; then
  118. printf "WARN: rmmod $2 succeeded even if governor is used\n"
  119. insmod $2
  120. else
  121. printf "Pass: unable to remove $2 while it is being used\n\n"
  122. fi
  123. # switch back to old governor
  124. printf "Switchback to $CUR_GOV from $1\n"
  125. restore_governor $3
  126. printf "\n"
  127. }
  128. # Insert cpufreq governor module and perform basic tests
  129. # $1: cpufreq-governor module to insert
  130. module_governor_test()
  131. {
  132. printf "** Test: Running ${FUNCNAME[0]} **\n\n"
  133. # check if module is present or not
  134. ls $1 > /dev/null
  135. if [ $? != 0 ]; then
  136. printf "$1: not present in `pwd` folder\n"
  137. return;
  138. fi
  139. # test basic module tests
  140. test_basic_insmod_rmmod $1
  141. # insert module
  142. printf "Inserting $1 module\n\n"
  143. insmod $1
  144. if [ $? != 0 ]; then
  145. printf "Insmod $1 failed\n"
  146. return;
  147. fi
  148. # switch to new governor for each cpu
  149. for_each_policy module_governor_test_single $(find_gov_name $1) $1
  150. # remove module
  151. printf "Removing $1 module\n\n"
  152. rmmod $1
  153. if [ $? != 0 ]; then
  154. printf "rmmod $1 failed\n"
  155. return;
  156. fi
  157. printf "\n"
  158. }
  159. # test modules: driver and governor
  160. # $1: driver module, $2: governor module
  161. module_test()
  162. {
  163. printf "** Test: Running ${FUNCNAME[0]} **\n\n"
  164. # check if modules are present or not
  165. ls $1 $2 > /dev/null
  166. if [ $? != 0 ]; then
  167. printf "$1 or $2: is not present in `pwd` folder\n"
  168. return;
  169. fi
  170. # TEST1: Insert gov after driver
  171. # insert driver module
  172. printf "Inserting $1 module\n\n"
  173. insmod $1
  174. if [ $? != 0 ]; then
  175. printf "Insmod $1 failed\n"
  176. return;
  177. fi
  178. # run governor tests
  179. module_governor_test $2
  180. # remove driver module
  181. printf "Removing $1 module\n\n"
  182. rmmod $1
  183. if [ $? != 0 ]; then
  184. printf "rmmod $1 failed\n"
  185. return;
  186. fi
  187. # TEST2: Insert driver after governor
  188. # insert governor module
  189. printf "Inserting $2 module\n\n"
  190. insmod $2
  191. if [ $? != 0 ]; then
  192. printf "Insmod $2 failed\n"
  193. return;
  194. fi
  195. # run governor tests
  196. module_driver_test $1
  197. # remove driver module
  198. printf "Removing $2 module\n\n"
  199. rmmod $2
  200. if [ $? != 0 ]; then
  201. printf "rmmod $2 failed\n"
  202. return;
  203. fi
  204. }