pm_include.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #!/bin/bash
  2. TMPDIR=/tmp
  3. PASS=0
  4. FAIL=1
  5. NOSUPPORT=2
  6. MISSING_FILE=3
  7. UNTESTED=4
  8. YES=0
  9. cleanup() {
  10. if [ -f ${1} ] ; then
  11. rm -f ${1}
  12. fi
  13. }
  14. check_kervel_arch() {
  15. # Checking required kernel version and architecture
  16. if tst_kvcmp -lt "2.6.21"; then
  17. tst_brkm TCONF "Kernel version not supported; not " \
  18. "running testcases"
  19. else
  20. case "$(uname -m)" in
  21. i[4-6]86|x86_64)
  22. ;;
  23. *)
  24. tst_brkm TCONF "Arch not supported; not running " \
  25. "testcases"
  26. ;;
  27. esac
  28. fi
  29. }
  30. check_config_options() {
  31. if ( ! ${3} "${1}" ${2} | grep -v "#" > /dev/null ) ; then
  32. tst_brkm TCONF "NOSUPPORT: current system dosen't support ${1}"
  33. fi
  34. }
  35. get_topology() {
  36. declare -a cpus
  37. declare -a phyid
  38. total_cpus=`tst_ncpus`
  39. (( total_cpus-=1 ))
  40. for cpu in $(seq 0 "${total_cpus}" )
  41. do
  42. cpus[$cpu]=cpu${cpu}
  43. phyid[$cpu]=$(cat \
  44. /sys/devices/system/cpu/cpu${cpu}/topology/physical_package_id)
  45. done
  46. j=0
  47. while [ "${j}" -lt "${total_cpus}" ]
  48. do
  49. (( k = $j + 1 ))
  50. if [ ${phyid[$j]} -eq ${phyid[$k]} ] ; then
  51. echo "${cpus[$j]} -P ${cpus[$k]}" | sed -e "s/cpu//g"
  52. fi
  53. (( j+=1 ))
  54. done
  55. }
  56. check_cpufreq() {
  57. total_cpus=`tst_ncpus`
  58. (( total_cpus-=1 ))
  59. for cpu in $(seq 0 "${total_cpus}" )
  60. do
  61. if [ ! -d /sys/devices/system/cpu/cpu${cpu}/cpufreq ] ; then
  62. tst_brkm TCONF "NOSUPPORT: cpufreq support not " \
  63. "found please check Kernel configuration " \
  64. "or BIOS settings"
  65. fi
  66. done
  67. }
  68. get_supporting_freq() {
  69. cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies \
  70. | uniq
  71. }
  72. get_supporting_govr() {
  73. cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors \
  74. | uniq
  75. }
  76. is_hyper_threaded() {
  77. siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'`
  78. cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq | cut -f2 -d':'`
  79. [ $siblings -gt $cpu_cores ]; echo $?
  80. }
  81. check_input() {
  82. validity_check=${2:-valid}
  83. testfile=$3
  84. if [ "${validity_check}" = "invalid" ] ; then
  85. PASS="Testcase FAIL - Able to execute"
  86. FAIL="Testcase PASS - Unable to execute"
  87. else
  88. PASS="Testcase PASS"
  89. FAIL="Testcase FAIL"
  90. fi
  91. RC=0
  92. for input in ${1}
  93. do
  94. echo ${input} > ${test_file} 2>/dev/null
  95. return_value=$?
  96. output=$(cat ${test_file})
  97. if [ "${return_value}" = "0" -a "${input}" = "${output}" ] ; then
  98. echo "${0}: ${PASS}: echo ${input} > ${test_file}"
  99. if [ "${validity_check}" = "invalid" ] ; then
  100. RC=1
  101. fi
  102. else
  103. echo "${0}: ${FAIL}: echo ${input} > ${test_file}"
  104. if [ "${validity_check}" = "valid" ] ; then
  105. RC=1
  106. fi
  107. fi
  108. done
  109. return $RC
  110. }
  111. is_multi_socket() {
  112. no_of_sockets=`cat \
  113. /sys/devices/system/cpu/cpu?/topology/physical_package_id \
  114. | uniq | wc -l`
  115. [ $no_of_sockets -gt 1 ] ; echo $?
  116. }
  117. is_multi_core() {
  118. siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'`
  119. cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq | cut -f2 -d':'`
  120. if [ $siblings -eq $cpu_cores ]; then
  121. [ $cpu_cores -gt 1 ]; echo $?
  122. else
  123. : $(( num_of_cpus = siblings / cpu_cores ))
  124. [ $num_of_cpus -gt 1 ]; echo $?
  125. fi
  126. }
  127. is_dual_core() {
  128. siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'`
  129. cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq \
  130. | cut -f2 -d':'`
  131. if [ $siblings -eq $cpu_cores ]; then
  132. [ $cpu_cores -eq 2 ]; echo $?
  133. else
  134. : $(( num_of_cpus = siblings / cpu_cores ))
  135. [ $num_of_cpus -eq 2 ]; echo $?
  136. fi
  137. }
  138. get_kernel_version() {
  139. # Get kernel minor version
  140. export kernel_version=`uname -r | awk -F. '{print $1"."$2"."$3}' \
  141. | cut -f1 -d'-'`
  142. }
  143. get_valid_input() {
  144. kernel_version=$1
  145. case "$kernel_version" in
  146. '2.6.26' | '2.6.27' | '2.6.28')
  147. export valid_input="0 1" ;;
  148. *) export valid_input="0 1 2" ;;
  149. esac
  150. }
  151. analyze_result_hyperthreaded() {
  152. sched_mc=$1
  153. pass_count=$2
  154. sched_smt=$3
  155. PASS="Test PASS"
  156. FAIL="Test FAIL"
  157. RC=0
  158. case "$sched_mc" in
  159. 0)
  160. case "$sched_smt" in
  161. 0)
  162. if [ $pass_count -lt 5 ]; then
  163. echo "${PASS}: cpu consolidation failed for" \
  164. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  165. else
  166. RC=1
  167. echo "${FAIL}: cpu consolidation passed for" \
  168. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  169. fi
  170. ;;
  171. *)
  172. if [ $pass_count -lt 5 ]; then
  173. RC=1
  174. echo "${FAIL}: cpu consolidation for" \
  175. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  176. else
  177. echo "${PASS}: cpu consolidation for" \
  178. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  179. fi
  180. ;;
  181. esac ;;
  182. *)
  183. if [ $pass_count -lt 5 ]; then
  184. RC=1
  185. echo "${FAIL}: cpu consolidation for" \
  186. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  187. else
  188. echo "${PASS}: cpu consolidation for" \
  189. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  190. fi
  191. ;;
  192. esac
  193. return $RC
  194. }
  195. analyze_package_consolidation_result() {
  196. sched_mc=$1
  197. pass_count=$2
  198. if [ $# -gt 2 ]
  199. then
  200. sched_smt=$3
  201. else
  202. sched_smt=-1
  203. fi
  204. PASS="Test PASS"
  205. FAIL="Test FAIL"
  206. RC=0
  207. if [ $hyper_threaded -eq $YES -a $sched_smt -gt -1 ]; then
  208. analyze_result_hyperthreaded $sched_mc $pass_count $sched_smt
  209. else
  210. case "$sched_mc" in
  211. 0)
  212. if [ $pass_count -lt 5 ]; then
  213. echo "${PASS}: cpu consolidation failed for" \
  214. "sched_mc=$sched_mc"
  215. else
  216. RC=1
  217. echo "${FAIL}: cpu consolidation passed for" \
  218. "sched_mc=$sched_mc"
  219. fi
  220. ;;
  221. *)
  222. if [ $pass_count -lt 5 ]; then
  223. RC=1
  224. echo "${FAIL}: consolidation at package level" \
  225. "failed for sched_mc=$sched_mc"
  226. else
  227. echo "${PASS}: consolidation at package level" \
  228. "passed for sched_mc=$sched_mc"
  229. fi
  230. ;;
  231. esac
  232. fi
  233. return $RC
  234. }
  235. analyze_core_consolidation_result() {
  236. sched_smt=$1
  237. pass_count=$2
  238. PASS="Test PASS"
  239. FAIL="Test FAIL"
  240. RC=0
  241. case "$sched_smt" in
  242. 0)
  243. if [ $pass_count -lt 5 ]; then
  244. echo "${PASS}: consolidation at core level failed" \
  245. "when sched_smt=$sched_smt"
  246. else
  247. RC=1
  248. echo "${FAIL}: consolidation at core level passed for" \
  249. "sched_smt=$sched_smt"
  250. fi ;;
  251. *)
  252. if [ $pass_count -lt 5 ]; then
  253. RC=1
  254. echo "${FAIL}: consolidation at core level failed for" \
  255. "sched_smt=$sched_smt"
  256. else
  257. echo "${PASS}: consolidation at core level passed for" \
  258. "sched_smt=$sched_smt"
  259. fi ;;
  260. esac
  261. return $RC
  262. }
  263. analyze_sched_domain_result(){
  264. sched_mc=$1
  265. result=$2
  266. sched_smt=$3
  267. PASS="Test PASS"
  268. FAIL="Test FAIL"
  269. RC=0
  270. if [ $hyper_threaded -eq $YES ]; then
  271. if [ $sched_smt ]; then
  272. if [ "$result" = 0 ];then
  273. echo "${PASS}: sched domain test for" \
  274. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  275. else
  276. RC=1
  277. echo "${FAIL}: sched domain test for" \
  278. "sched_mc=$sched_mc & sched_smt=$sched_smt"
  279. fi
  280. else
  281. if [ "$result" = 0 ];then
  282. echo "${PASS}: sched domain test for" \
  283. "sched_mc=$sched_mc"
  284. else
  285. RC=1
  286. echo "${FAIL}: sched domain test for" \
  287. "sched_mc=$sched_mc"
  288. fi
  289. fi
  290. else
  291. if [ "$result" = 0 ];then
  292. echo "${PASS}: sched domain test for sched_mc=$sched_mc"
  293. else
  294. RC=1
  295. echo "${FAIL}: sched domain test for sched_mc=$sched_mc"
  296. fi
  297. fi
  298. return $RC
  299. }