cpuset_inherit_testset.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/sh
  2. ################################################################################
  3. # #
  4. # Copyright (c) 2009 FUJITSU LIMITED #
  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 #
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #
  19. # #
  20. # Author: Miao Xie <miaox@cn.fujitsu.com> #
  21. # #
  22. ################################################################################
  23. export TCID="cpuset_inherit"
  24. export TST_TOTAL=33
  25. export TST_COUNT=1
  26. . cpuset_funcs.sh
  27. check 1 1
  28. nr_cpus=$NR_CPUS
  29. nr_mems=$N_NODES
  30. cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
  31. mems_all="$(seq -s, 0 $((nr_mems-1)))"
  32. exit_status=0
  33. cfile_name=
  34. # base_op_write_and_test <write_file_name> <write_string> <expect_string>
  35. base_op_write_and_test()
  36. {
  37. local write_file="$1"
  38. local inherit_value="$2"
  39. local write_string="$3"
  40. local expect_string="$4"
  41. local return_result=
  42. echo $inherit_value > $CLONE_CHILDREN
  43. mkdir -p "$(dirname $write_file)" || {
  44. tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)"
  45. return 1
  46. }
  47. [ "$write_string" = NULL ] && write_string=" "
  48. /bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr
  49. mkdir $(dirname $write_file)/2 2> $CPUSET_TMP/stderr
  50. return_result=$?
  51. write_result="$(cat "$(dirname $write_file)/2/$(basename $write_file)")"
  52. case "$expect_string" in
  53. EMPTY)
  54. test -z "$write_result" -a $return_result = 0
  55. return_result=$?
  56. ;;
  57. WRITE_ERROR)
  58. return_result=$((!$return_result))
  59. ;;
  60. *)
  61. test "$expect_string" = "$write_result" -a $return_result = 0
  62. return_result=$?
  63. ;;
  64. esac
  65. if [ $return_result -eq 0 ]; then
  66. tst_resm TPASS "$cfile_name: Inherited information is right!"
  67. else
  68. tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\""
  69. fi
  70. return $return_result
  71. }
  72. inherit_test()
  73. {
  74. setup
  75. if [ $? -ne 0 ]; then
  76. exit_status=1
  77. else
  78. base_op_write_and_test "$@"
  79. if [ $? -ne 0 ]; then
  80. exit_status=1
  81. fi
  82. cleanup
  83. if [ $? -ne 0 ]; then
  84. exit_status=1
  85. fi
  86. fi
  87. TST_COUNT=$(($TST_COUNT + 1))
  88. }
  89. test_cpus()
  90. {
  91. cfile_name="cpus"
  92. num=$((nr_cpus-1))
  93. cpu_string="0-$num"
  94. if [ $nr_cpus -eq 1 ]; then
  95. cpu_string="0"
  96. fi
  97. while read inherit cpus result
  98. do
  99. inherit_test "$CPUSET/1/cpuset.cpus" "$inherit" "$cpus" "$result"
  100. done <<- EOF
  101. 0 NULL EMPTY
  102. 0 0 EMPTY
  103. 0 $cpus_all EMPTY
  104. 1 NULL EMPTY
  105. 1 0 0
  106. 1 $cpus_all $cpu_string
  107. EOF
  108. # while read cpus result
  109. }
  110. test_mems()
  111. {
  112. cfile_name="mems"
  113. while read inherit mems result
  114. do
  115. inherit_test "$CPUSET/1/cpuset.mems" "$inherit" "$mems" "$result"
  116. done <<- EOF
  117. 0 NULL EMPTY
  118. 0 0 EMPTY
  119. 0 $mems_all EMPTY
  120. 1 NULL EMPTY
  121. 1 0 0
  122. 1 $mems_all $mem_string
  123. EOF
  124. # while read mems result
  125. }
  126. # test cpu_exclusive mem_exclusive mem_hardwall memory_migrate
  127. test_three_result_similar_flags()
  128. {
  129. for filename in cpu_exclusive mem_exclusive mem_hardwall \
  130. memory_migrate
  131. do
  132. cfile_name="$filename"
  133. while read inherit flags result
  134. do
  135. inherit_test "$CPUSET/1/cpuset.$filename" "$inherit" "$flags" "$result"
  136. done <<- EOF
  137. 0 0 0
  138. 0 1 0
  139. EOF
  140. # while read flags, result
  141. done # for filename in flagfiles
  142. }
  143. # test memory_spread_page memory_spread_slab
  144. test_spread_flags()
  145. {
  146. for filename in memory_spread_page memory_spread_slab
  147. do
  148. cfile_name="$filename"
  149. while read inherit flags result
  150. do
  151. inherit_test "$CPUSET/1/cpuset.$filename" "$inherit" "$flags" "$result"
  152. done <<- EOF
  153. 0 0 0
  154. 0 1 1
  155. EOF
  156. # while read flags, result
  157. done # for filename in flagfiles
  158. }
  159. test_sched_load_balance_flag()
  160. {
  161. cfile_name="sched_load_balance"
  162. while read inherit flag result
  163. do
  164. inherit_test "$CPUSET/1/cpuset.sched_load_balance" "$inherit" "$flag" "$result"
  165. done <<- EOF
  166. 0 0 1
  167. 0 1 1
  168. EOF
  169. # while read mems result
  170. }
  171. test_domain()
  172. {
  173. cfile_name="sched_relax_domain_level"
  174. while read inherit domain_level result
  175. do
  176. inherit_test "$CPUSET/1/cpuset.sched_relax_domain_level" "$inherit" "$domain_level" "$result"
  177. done <<- EOF
  178. 0 -1 -1
  179. 0 0 -1
  180. 0 1 -1
  181. 0 2 -1
  182. 0 3 -1
  183. 0 4 -1
  184. 0 5 -1
  185. EOF
  186. # while read domain_level result
  187. }
  188. # Case 1-6
  189. test_cpus
  190. # Case 7-12
  191. test_mems
  192. # Case 13-20
  193. test_three_result_similar_flags
  194. # Case 21-24
  195. test_spread_flags
  196. # Case 25-26
  197. test_sched_load_balance_flag
  198. # Case 27-33
  199. test_domain
  200. exit $exit_status