cpuset_hierarchy_test.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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_hierarchy"
  24. export TST_TOTAL=32
  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. # test cpus
  34. test1()
  35. {
  36. echo > "$CPUSET/father/cpuset.cpus" || return 1
  37. echo > "$CPUSET/father/child/cpuset.cpus" || return 1
  38. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  39. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  40. test -z "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  41. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  42. }
  43. test2()
  44. {
  45. echo > "$CPUSET/father/cpuset.cpus" || return 1
  46. echo 0 > "$CPUSET/father/child/cpuset.cpus" 2> /dev/null && return 1
  47. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  48. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  49. test -z "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  50. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  51. }
  52. test3()
  53. {
  54. echo 0 > "$CPUSET/father/cpuset.cpus" || return 1
  55. echo > "$CPUSET/father/child/cpuset.cpus" || return 1
  56. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  57. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  58. test 0 = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  59. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  60. }
  61. test4()
  62. {
  63. echo 0 > "$CPUSET/father/cpuset.cpus" || return 1
  64. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  65. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  66. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  67. test 0 = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  68. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  69. }
  70. test5()
  71. {
  72. echo 0 > "$CPUSET/father/cpuset.cpus" || return 1
  73. echo 1 > "$CPUSET/father/child/cpuset.cpus" 2> /dev/null && return 1
  74. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  75. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  76. test 0 = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  77. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  78. }
  79. test6()
  80. {
  81. echo 0 > "$CPUSET/father/cpuset.cpus" || return 1
  82. echo 0,1 > "$CPUSET/father/child/cpuset.cpus" 2> /dev/null && return 1
  83. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  84. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  85. test 0 = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  86. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  87. }
  88. test7()
  89. {
  90. echo "0,1" > "$CPUSET/father/cpuset.cpus" || return 1
  91. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  92. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  93. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  94. test "0-1" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  95. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  96. }
  97. test8()
  98. {
  99. echo "0,1" > "$CPUSET/father/cpuset.cpus" || return 1
  100. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  101. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  102. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  103. test "0-1" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  104. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  105. }
  106. test9()
  107. {
  108. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  109. echo > "$CPUSET/father/child/cpuset.cpus" || return 1
  110. echo > "$CPUSET/father/cpuset.cpus" || return 1
  111. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  112. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  113. test -z "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  114. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  115. }
  116. test10()
  117. {
  118. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  119. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  120. echo > "$CPUSET/father/cpuset.cpus" 2> /dev/null && return 1
  121. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  122. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  123. test "0-$((nr_cpus-1))" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  124. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  125. }
  126. test11()
  127. {
  128. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  129. echo > "$CPUSET/father/child/cpuset.cpus" || return 1
  130. echo 0 > "$CPUSET/father/cpuset.cpus" || return 1
  131. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  132. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  133. test 0 = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  134. test -z "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  135. }
  136. test12()
  137. {
  138. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  139. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  140. echo 0 > "$CPUSET/father/cpuset.cpus" || return 1
  141. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  142. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  143. test 0 = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  144. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  145. }
  146. test13()
  147. {
  148. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  149. echo 1 > "$CPUSET/father/child/cpuset.cpus" || return 1
  150. echo 0 > "$CPUSET/father/cpuset.cpus" 2> /dev/null && return 1
  151. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  152. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  153. test "0-$((nr_cpus-1))" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  154. test 1 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  155. }
  156. test14()
  157. {
  158. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  159. echo 0,1 > "$CPUSET/father/child/cpuset.cpus" || return 1
  160. echo 0 > "$CPUSET/father/cpuset.cpus" 2> /dev/null && return 1
  161. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  162. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  163. test "0-$((nr_cpus-1))" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  164. test "0-1" = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  165. }
  166. test15()
  167. {
  168. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  169. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  170. echo "0,1" > "$CPUSET/father/cpuset.cpus" || return 1
  171. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  172. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  173. test "0-1" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  174. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  175. }
  176. test16()
  177. {
  178. echo "$cpus_all" > "$CPUSET/father/cpuset.cpus" || return 1
  179. echo 0 > "$CPUSET/father/child/cpuset.cpus" || return 1
  180. echo "0,1" > "$CPUSET/father/cpuset.cpus" || return 1
  181. cpuset_log "father cpuset.cpus $(cat "$CPUSET/father/cpuset.cpus")"
  182. cpuset_log "child cpuset.cpus $(cat "$CPUSET/father/child/cpuset.cpus")"
  183. test "0-1" = "$(cat "$CPUSET/father/cpuset.cpus")" || return 1
  184. test 0 = "$(cat "$CPUSET/father/child/cpuset.cpus")" || return 1
  185. }
  186. ## test mems
  187. test17()
  188. {
  189. echo > "$CPUSET/father/cpuset.mems" || return 1
  190. echo > "$CPUSET/father/child/cpuset.mems" || return 1
  191. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  192. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  193. test -z "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  194. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  195. }
  196. test18()
  197. {
  198. echo > "$CPUSET/father/cpuset.mems" || return 1
  199. echo 0 > "$CPUSET/father/child/cpuset.mems" 2> /dev/null && return 1
  200. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  201. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  202. test -z "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  203. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  204. }
  205. test19()
  206. {
  207. echo 0 > "$CPUSET/father/cpuset.mems" || return 1
  208. echo > "$CPUSET/father/child/cpuset.mems" || return 1
  209. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  210. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  211. test 0 = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  212. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  213. }
  214. test20()
  215. {
  216. echo 0 > "$CPUSET/father/cpuset.mems" || return 1
  217. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  218. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  219. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  220. test 0 = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  221. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  222. }
  223. test21()
  224. {
  225. echo 0 > "$CPUSET/father/cpuset.mems" || return 1
  226. echo 1 > "$CPUSET/father/child/cpuset.mems" 2> /dev/null && return 1
  227. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  228. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  229. test 0 = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  230. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  231. }
  232. test22()
  233. {
  234. echo 0 > "$CPUSET/father/cpuset.mems" || return 1
  235. echo 0,1 > "$CPUSET/father/child/cpuset.mems" 2> /dev/null && return 1
  236. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  237. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  238. test 0 = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  239. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  240. }
  241. test23()
  242. {
  243. echo "0,1" > "$CPUSET/father/cpuset.mems" || return 1
  244. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  245. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  246. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  247. test "0-1" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  248. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  249. }
  250. test24()
  251. {
  252. echo "0,1" > "$CPUSET/father/cpuset.mems" || return 1
  253. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  254. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  255. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  256. test "0-1" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  257. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  258. }
  259. test25()
  260. {
  261. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  262. echo > "$CPUSET/father/child/cpuset.mems" || return 1
  263. echo > "$CPUSET/father/cpuset.mems" || return 1
  264. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  265. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  266. test -z "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  267. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  268. }
  269. test26()
  270. {
  271. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  272. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  273. echo > "$CPUSET/father/cpuset.mems" 2> /dev/null && return 1
  274. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  275. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  276. test "0-$((nr_mems-1))" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  277. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  278. }
  279. test27()
  280. {
  281. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  282. echo > "$CPUSET/father/child/cpuset.mems" || return 1
  283. echo 0 > "$CPUSET/father/cpuset.mems" || return 1
  284. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  285. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  286. test 0 = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  287. test -z "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  288. }
  289. test28()
  290. {
  291. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  292. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  293. echo 0 > "$CPUSET/father/cpuset.mems" || return 1
  294. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  295. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  296. test 0 = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  297. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  298. }
  299. test29()
  300. {
  301. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  302. echo 1 > "$CPUSET/father/child/cpuset.mems" || return 1
  303. echo 0 > "$CPUSET/father/cpuset.mems" 2> /dev/null && return 1
  304. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  305. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  306. test "0-$((nr_mems-1))" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  307. test 1 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  308. }
  309. test30()
  310. {
  311. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  312. echo 0,1 > "$CPUSET/father/child/cpuset.mems" || return 1
  313. echo 0 > "$CPUSET/father/cpuset.mems" 2> /dev/null && return 1
  314. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  315. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  316. test "0-$((nr_mems-1))" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  317. test "0-1" = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  318. }
  319. test31()
  320. {
  321. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  322. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  323. echo "0,1" > "$CPUSET/father/cpuset.mems" || return 1
  324. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  325. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  326. test "0-1" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  327. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  328. }
  329. test32()
  330. {
  331. echo "$mems_all" > "$CPUSET/father/cpuset.mems" || return 1
  332. echo 0 > "$CPUSET/father/child/cpuset.mems" || return 1
  333. echo "0,1" > "$CPUSET/father/cpuset.mems" || return 1
  334. cpuset_log "father cpuset.mems $(cat "$CPUSET/father/cpuset.mems")"
  335. cpuset_log "child cpuset.mems $(cat "$CPUSET/father/child/cpuset.mems")"
  336. test "0-1" = "$(cat "$CPUSET/father/cpuset.mems")" || return 1
  337. test 0 = "$(cat "$CPUSET/father/child/cpuset.mems")" || return 1
  338. }
  339. for i in $(seq 1 $TST_TOTAL)
  340. do
  341. setup
  342. if [ $? -ne 0 ]; then
  343. exit_status=1
  344. else
  345. mkdir "$CPUSET/father"
  346. mkdir "$CPUSET/father/child"
  347. test$i
  348. if [ $? -ne 0 ]; then
  349. tst_resm TFAIL "Break the hierarchy limit."
  350. exit_status=1
  351. else
  352. tst_resm TPASS "Hierarchy test succeeded."
  353. fi
  354. cleanup
  355. if [ $? -ne 0 ]; then
  356. exit_status=1
  357. fi
  358. fi
  359. TST_COUNT=$(($TST_COUNT + 1))
  360. done
  361. exit $exit_status