cpuset_base_ops_testset.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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_base_ops"
  24. export TST_TOTAL=97
  25. export TST_COUNT=1
  26. . cpuset_funcs.sh
  27. check
  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 write_string="$2"
  39. local expect_string="$3"
  40. local write_result=
  41. local ret=0
  42. mkdir -p "$(dirname $write_file)" || {
  43. tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)"
  44. return 1
  45. }
  46. [ "$write_string" = NULL ] && write_string=" "
  47. /bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr
  48. ret=$?
  49. write_result="$(cat "$write_file")"
  50. case "$expect_string" in
  51. EMPTY)
  52. test -z "$write_result" -a $ret = 0
  53. ret=$?
  54. ;;
  55. WRITE_ERROR)
  56. ret=$((!$ret))
  57. ;;
  58. *)
  59. test "$expect_string" = "$write_result" -a $ret = 0
  60. ret=$?
  61. ;;
  62. esac
  63. if [ $ret -eq 0 ]; then
  64. tst_resm TPASS "$cfile_name: Get the expected string"
  65. else
  66. tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\""
  67. fi
  68. return $ret
  69. }
  70. base_op_test()
  71. {
  72. setup
  73. if [ $? -ne 0 ]; then
  74. exit_status=1
  75. else
  76. base_op_write_and_test "$@"
  77. if [ $? -ne 0 ]; then
  78. exit_status=1
  79. fi
  80. cleanup
  81. if [ $? -ne 0 ]; then
  82. exit_status=1
  83. fi
  84. fi
  85. TST_COUNT=$(($TST_COUNT + 1))
  86. }
  87. test_cpus()
  88. {
  89. cfile_name="cpuset.cpus"
  90. while read cpus result
  91. do
  92. base_op_test "$CPUSET/1/cpuset.cpus" "$cpus" "$result"
  93. done <<- EOF
  94. NULL EMPTY
  95. 0 0
  96. $nr_cpus WRITE_ERROR
  97. $cpus_all 0-$((nr_cpus-1))
  98. ${cpus_all}$nr_cpus WRITE_ERROR
  99. 0,0 0
  100. 0-0 0
  101. 0-$((nr_cpus-1)) 0-$((nr_cpus-1))
  102. -1 WRITE_ERROR
  103. 0-$nr_cpus WRITE_ERROR
  104. 0--$((nr_cpus-1)) WRITE_ERROR
  105. 0AAA WRITE_ERROR
  106. AAA WRITE_ERROR
  107. EOF
  108. # while read cpus result
  109. if [ $nr_cpus -ge 3 ]; then
  110. base_op_test "$CPUSET/1/cpuset.cpus" "0,1-$((nr_cpus-2)),$((nr_cpus-1))" "0-$((nr_cpus-1))"
  111. base_op_test "$CPUSET/1/cpuset.cpus" "0,1-$((nr_cpus-2))," "0-$((nr_cpus-2))"
  112. fi
  113. if tst_kvcmp -ge "4.3"; then
  114. base_op_test "$CPUSET/1/cpuset.cpus" "0-" "WRITE_ERROR"
  115. fi
  116. }
  117. test_mems()
  118. {
  119. cfile_name="cpuset.mems"
  120. while read mems result
  121. do
  122. base_op_test "$CPUSET/1/cpuset.mems" "$mems" "$result"
  123. done <<- EOF
  124. NULL EMPTY
  125. 0 0
  126. $nr_mems WRITE_ERROR
  127. $mems_all 0-$((nr_mems-1))
  128. ${mems_all}$nr_mems WRITE_ERROR
  129. 0,0 0
  130. 0-0 0
  131. 0-$((nr_mems-1)) 0-$((nr_mems-1))
  132. -1 WRITE_ERROR
  133. 0-$nr_mems WRITE_ERROR
  134. 0--$((nr_mems-1)) WRITE_ERROR
  135. 0AAA WRITE_ERROR
  136. AAA WRITE_ERROR
  137. EOF
  138. # while read mems result
  139. if [ $nr_mems -ge 3 ]; then
  140. base_op_test "$CPUSET/1/cpuset.mems" "0,1-$((nr_mems-2)),$((nr_mems-1))" "0-$((nr_mems-1))"
  141. base_op_test "$CPUSET/1/cpuset.mems" "0,1-$((nr_mems-2))," "0-$((nr_mems-2))"
  142. fi
  143. if tst_kvcmp -ge "4.3"; then
  144. base_op_test "$CPUSET/1/cpuset.mems" "0-" "WRITE_ERROR"
  145. fi
  146. }
  147. test_flags()
  148. {
  149. for filename in cpu_exclusive mem_exclusive mem_hardwall \
  150. memory_migrate memory_spread_page memory_spread_slab \
  151. sched_load_balance memory_pressure_enabled
  152. do
  153. cfile_name="cpuset.$filename"
  154. while read flags result
  155. do
  156. base_op_test "$CPUSET/cpuset.$filename" "$flags" "$result"
  157. done <<- EOF
  158. 0 0
  159. 1 1
  160. -1 WRITE_ERROR
  161. A WRITE_ERROR
  162. 2 1
  163. EOF
  164. # while read flags, result
  165. done # for filename in flagfiles
  166. }
  167. # attach_task_test <cpus> <mems> <expect>
  168. attach_task_test()
  169. {
  170. local cpus=$1
  171. local mems=$2
  172. local expect=$3
  173. local pid=
  174. local ret=
  175. setup
  176. if [ $? -ne 0 ]; then
  177. exit_status=1
  178. cleanup
  179. TST_COUNT=$(($TST_COUNT + 1))
  180. return
  181. fi
  182. # create sub cpuset
  183. mkdir "$CPUSET/sub_cpuset" > /dev/null
  184. if [ $? -ne 0 ]; then
  185. exit_status=1
  186. cleanup
  187. TST_COUNT=$(($TST_COUNT + 1))
  188. return
  189. fi
  190. if [ "$cpus" != "NULL" ]; then
  191. echo $cpus > "$CPUSET/sub_cpuset/cpuset.cpus"
  192. fi
  193. if [ "$mems" != "NULL" ]; then
  194. echo $mems > "$CPUSET/sub_cpuset/cpuset.mems"
  195. fi
  196. cat /dev/zero > /dev/null &
  197. pid=$!
  198. # attach task into the cpuset group
  199. echo $pid > "$CPUSET/sub_cpuset/tasks" 2> /dev/null
  200. if [ $? -eq $expect ]; then
  201. tst_resm TPASS "Attaching Task Test successed!!"
  202. else
  203. tst_resm TFAIL "Attaching Task Test failed!! cpus - \"$cpus\", mems - \"$mems\", Expect - \"$expect\", Fact - \"$ret\". (0 - Attach Success, 1 - Attach Fail)"
  204. exit_status=1
  205. fi
  206. /bin/kill $pid > /dev/null 2>&1
  207. cleanup
  208. if [ $? -ne 0 ]; then
  209. exit_status=1
  210. fi
  211. TST_COUNT=$(($TST_COUNT + 1))
  212. }
  213. test_attach_task()
  214. {
  215. cfile_name="tasks"
  216. while read cpus mems expect
  217. do
  218. attach_task_test "$cpus" "$mems" "$expect"
  219. done <<- EOF
  220. 0 NULL 1
  221. 0 0 0
  222. NULL 0 1
  223. EOF
  224. # while read cpus mems expect
  225. }
  226. test_readonly_cfiles()
  227. {
  228. for filename in cpus mems memory_pressure
  229. do
  230. cfile_name="cpuset.$filename(READONLY)"
  231. base_op_test "$CPUSET/cpuset.$filename" "0" "WRITE_ERROR"
  232. done # for filename in readonly cfiles
  233. }
  234. # Case 1-3
  235. test_readonly_cfiles
  236. # Case 4-19
  237. test_cpus
  238. # Case 20-35
  239. test_mems
  240. # Case 36-83
  241. test_flags
  242. # Case 84-86
  243. test_attach_task
  244. exit $exit_status