module.sh 4.8 KB

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