cpuset_memory_testset.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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_memory"
  24. export TST_TOTAL=18
  25. export TST_COUNT=1
  26. . cpuset_funcs.sh
  27. check
  28. exit_status=0
  29. nr_cpus=$NR_CPUS
  30. nr_mems=$N_NODES
  31. cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
  32. mems_all="$(seq -s, 0 $((nr_mems-1)))"
  33. cpu_of_node0=0
  34. HUGEPAGESIZE=$(awk '/Hugepagesize/{ print $2 }' /proc/meminfo)
  35. HUGEPAGESIZE=$(($HUGEPAGESIZE * 1024))
  36. MEMORY_RESULT="$CPUSET_TMP/memory_result"
  37. # simple_getresult
  38. # $1 - cpuset_memory_test's pid
  39. # $2 - move cpuset_memory_test's pid to this cpuset
  40. simple_getresult()
  41. {
  42. sleep 1
  43. echo $1 > "$2/tasks"
  44. /bin/kill -s SIGUSR1 $1
  45. sleep 1
  46. /bin/kill -s SIGUSR1 $1
  47. sleep 1
  48. /bin/kill -s SIGINT $1
  49. wait $1
  50. read node < "$MEMORY_RESULT"
  51. }
  52. test1()
  53. {
  54. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  55. if [ $? -ne 0 ]; then
  56. cpuset_log_error $CPUSET_TMP/stderr
  57. tst_resm TFAIL "set general group parameter failed."
  58. return 1
  59. fi
  60. cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
  61. simple_getresult $! "$CPUSET/0"
  62. if [ "$node" != "0" ]; then
  63. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  64. return 1
  65. fi
  66. }
  67. test2()
  68. {
  69. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  70. if [ $? -ne 0 ]; then
  71. cpuset_log_error $CPUSET_TMP/stderr
  72. tst_resm TFAIL "set general group parameter failed."
  73. return 1
  74. fi
  75. cpuset_memory_test --mmap-file >"$MEMORY_RESULT" &
  76. simple_getresult $! "$CPUSET/0"
  77. if [ "$node" != "0" ]; then
  78. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  79. return 1
  80. fi
  81. }
  82. test3()
  83. {
  84. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  85. if [ $? -ne 0 ]; then
  86. cpuset_log_error $CPUSET_TMP/stderr
  87. tst_resm TFAIL "set general group parameter failed."
  88. return 1
  89. fi
  90. cpuset_memory_test --shm >"$MEMORY_RESULT" &
  91. simple_getresult $! "$CPUSET/0"
  92. if [ "$node" != "0" ]; then
  93. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  94. return 1
  95. fi
  96. }
  97. test4()
  98. {
  99. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  100. if [ $? -ne 0 ]; then
  101. cpuset_log_error $CPUSET_TMP/stderr
  102. tst_resm TFAIL "set general group parameter failed."
  103. return 1
  104. fi
  105. cpuset_memory_test --mmap-lock1 >"$MEMORY_RESULT" &
  106. simple_getresult $! "$CPUSET/0"
  107. if [ "$node" != "0" ]; then
  108. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  109. return 1
  110. fi
  111. }
  112. test5()
  113. {
  114. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  115. if [ $? -ne 0 ]; then
  116. cpuset_log_error $CPUSET_TMP/stderr
  117. tst_resm TFAIL "set general group parameter failed."
  118. return 1
  119. fi
  120. cpuset_memory_test --mmap-lock2 >"$MEMORY_RESULT" &
  121. simple_getresult $! "$CPUSET/0"
  122. if [ "$node" != "0" ]; then
  123. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  124. return 1
  125. fi
  126. }
  127. # check whether the system supports hugetlbfs or not
  128. # return 0 - don't support hugetlbfs
  129. # 1 - support hugetlbfs
  130. check_hugetlbfs()
  131. {
  132. local fssupport=$(grep -w hugetlbfs /proc/filesystems 2>/dev/null | cut -f2)
  133. if [ "$fssupport" = "hugetlbfs" ]; then
  134. return 1
  135. else
  136. return 0
  137. fi
  138. }
  139. test6()
  140. {
  141. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  142. if [ $? -ne 0 ]; then
  143. cpuset_log_error $CPUSET_TMP/stderr
  144. tst_resm TFAIL "set general group parameter failed."
  145. return 1
  146. fi
  147. check_hugetlbfs
  148. if [ $? -eq 0 ]; then
  149. tst_resm TCONF "This system don't support hugetlbfs"
  150. return 0
  151. fi
  152. mkdir /hugetlb
  153. mount -t hugetlbfs none /hugetlb
  154. save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
  155. echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
  156. cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
  157. simple_getresult $! "$CPUSET/0"
  158. umount /hugetlb
  159. rmdir /hugetlb
  160. echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
  161. if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
  162. tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
  163. return 1
  164. fi
  165. if [ "$node" != "0" ]; then
  166. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  167. return 1
  168. fi
  169. }
  170. test7()
  171. {
  172. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  173. if [ $? -ne 0 ]; then
  174. cpuset_log_error $CPUSET_TMP/stderr
  175. tst_resm TFAIL "set general group parameter failed."
  176. return 1
  177. fi
  178. check_hugetlbfs
  179. if [ $? -eq 0 ]; then
  180. tst_resm TCONF "This system don't support hugetlbfs"
  181. return 0
  182. fi
  183. mkdir /hugetlb
  184. mount -t hugetlbfs none /hugetlb
  185. save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
  186. echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
  187. cpuset_memory_test --shm --hugepage -s $HUGEPAGESIZE --key=7 >"$MEMORY_RESULT" &
  188. simple_getresult $! "$CPUSET/0"
  189. umount /hugetlb
  190. rmdir /hugetlb
  191. echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
  192. if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
  193. tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
  194. return 1
  195. fi
  196. if [ "$node" != "0" ]; then
  197. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  198. return 1
  199. fi
  200. }
  201. test8()
  202. {
  203. cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  204. if [ $? -ne 0 ]; then
  205. cpuset_log_error $CPUSET_TMP/stderr
  206. tst_resm TFAIL "set general group parameter failed."
  207. return 1
  208. fi
  209. cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
  210. simple_getresult $! "$CPUSET/0"
  211. if [ "$node" != "0" ]; then
  212. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
  213. return 1
  214. fi
  215. }
  216. test9()
  217. {
  218. cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  219. if [ $? -ne 0 ]; then
  220. cpuset_log_error $CPUSET_TMP/stderr
  221. tst_resm TFAIL "set general group parameter failed."
  222. return 1
  223. fi
  224. cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
  225. simple_getresult $! "$CPUSET/0"
  226. if [ "$node" != "1" ]; then
  227. tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#1)."
  228. return 1
  229. fi
  230. }
  231. # talk2memory_test_for_case_10_11
  232. # $1 - cpuset_memory_test's pid
  233. # $2 - move cpuset_memory_test's pid to this cpuset
  234. # $3 - move cpuset_memory_test's pid to this cpuset(a new cpuset)
  235. talk2memory_test_for_case_10_11()
  236. {
  237. sleep 1
  238. echo $1 > "$2/tasks"
  239. /bin/kill -s SIGUSR1 $1
  240. sleep 1
  241. echo $1 > "$3/tasks"
  242. /bin/kill -s SIGUSR1 $1
  243. sleep 1
  244. /bin/kill -s SIGUSR1 $1
  245. sleep 1
  246. /bin/kill -s SIGINT $1
  247. wait $1
  248. }
  249. test10()
  250. {
  251. cpuset_set "$CPUSET/1" "$cpus_all" "0" "0" 2> $CPUSET_TMP/stderr
  252. if [ $? -ne 0 ]; then
  253. cpuset_log_error $CPUSET_TMP/stderr
  254. tst_resm TFAIL "set general group1's parameter failed."
  255. return 1
  256. fi
  257. cpuset_set "$CPUSET/2" "$cpus_all" "1" "0" 2> $CPUSET_TMP/stderr
  258. if [ $? -ne 0 ]; then
  259. cpuset_log_error $CPUSET_TMP/stderr
  260. tst_resm TFAIL "set general group2's parameter failed."
  261. return 1
  262. fi
  263. cpuset_memory_test --mmap-anon --check >"$MEMORY_RESULT" &
  264. talk2memory_test_for_case_10_11 $! "$CPUSET/1" "$CPUSET/2"
  265. {
  266. read node0
  267. read node1
  268. read node2
  269. } < "$MEMORY_RESULT"
  270. if [ "$node0" != "0" ]; then
  271. tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#0)."
  272. return 1
  273. fi
  274. if [ "$node1" != "0" ]; then
  275. tst_resm TFAIL "Allocated memory was moved to the Node#$node1(Expect: Node#0)."
  276. return 1
  277. fi
  278. if [ "$node2" != "1" ]; then
  279. tst_resm TFAIL "allocate memory on the Node#$node2(Expect: Node#1) after changing group."
  280. return 1
  281. fi
  282. }
  283. test11()
  284. {
  285. cpuset_set "$CPUSET/1" "$cpus_all" "0" "0" 2> $CPUSET_TMP/stderr
  286. if [ $? -ne 0 ]; then
  287. cpuset_log_error $CPUSET_TMP/stderr
  288. tst_resm TFAIL "set general group1's parameter failed."
  289. return 1
  290. fi
  291. cpuset_set "$CPUSET/2" "$cpus_all" "1" "0" 2> $CPUSET_TMP/stderr
  292. if [ $? -ne 0 ]; then
  293. cpuset_log_error $CPUSET_TMP/stderr
  294. tst_resm TFAIL "set general group2's parameter failed."
  295. return 1
  296. fi
  297. echo 1 > "$CPUSET/2/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  298. if [ $? -ne 0 ]; then
  299. cpuset_log_error $CPUSET_TMP/stderr
  300. tst_resm TFAIL "set general group2's memory_migrate failed."
  301. return 1
  302. fi
  303. cpuset_memory_test --mmap-anon --check >"$MEMORY_RESULT" &
  304. talk2memory_test_for_case_10_11 $! "$CPUSET/1" "$CPUSET/2"
  305. {
  306. read node0
  307. read node1
  308. read node2
  309. } < "$MEMORY_RESULT"
  310. if [ "$node0" != "0" ]; then
  311. tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#0)."
  312. return 1
  313. fi
  314. if [ "$node1" != "1" ]; then
  315. tst_resm TFAIL "Allocated memory was not moved to the Node#1(Result: Node#$node1)."
  316. return 1
  317. fi
  318. if [ "$node2" != "1" ]; then
  319. tst_resm TFAIL "allocate memory on the Node#$node2(Expect: Node#1) after changing group."
  320. return 1
  321. fi
  322. }
  323. # talk2memory_test_for_case_12_13
  324. # $1 - cpuset_memory_test's pid
  325. # $2 - the test cpuset
  326. talk2memory_test_for_case_12_13()
  327. {
  328. sleep 1
  329. echo $1 > "$2/tasks"
  330. /bin/kill -s SIGUSR1 $1
  331. echo 0 > "$2/cpuset.mems" || return 1
  332. sleep 1
  333. /bin/kill -s SIGUSR1 $1
  334. sleep 1
  335. /bin/kill -s SIGUSR1 $1
  336. sleep 1
  337. /bin/kill -s SIGINT $1
  338. wait $1
  339. }
  340. test12()
  341. {
  342. cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  343. if [ $? -ne 0 ]; then
  344. cpuset_log_error $CPUSET_TMP/stderr
  345. tst_resm TFAIL "set general group's parameter failed."
  346. return 1
  347. fi
  348. cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
  349. talk2memory_test_for_case_12_13 $! "$CPUSET/0"
  350. {
  351. read node0
  352. read node1
  353. } < "$MEMORY_RESULT"
  354. if [ "$node0" != "1" ]; then
  355. tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#1)."
  356. return 1
  357. fi
  358. if [ "$node1" != "0" ]; then
  359. tst_resm TFAIL "allocate memory on the Node#$node1(Expect: Node#0) after changing mems."
  360. return 1
  361. fi
  362. }
  363. test13()
  364. {
  365. cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  366. if [ $? -ne 0 ]; then
  367. cpuset_log_error $CPUSET_TMP/stderr
  368. tst_resm TFAIL "set general group's parameter failed."
  369. return 1
  370. fi
  371. echo 1 > "$CPUSET/0/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  372. if [ $? -ne 0 ]; then
  373. cpuset_log_error $CPUSET_TMP/stderr
  374. tst_resm TFAIL "set general group's memory_migrate failed."
  375. return 1
  376. fi
  377. cpuset_memory_test --mmap-anon --check >"$MEMORY_RESULT" &
  378. talk2memory_test_for_case_12_13 $! "$CPUSET/0"
  379. {
  380. read node0
  381. read node1
  382. read node2
  383. } < "$MEMORY_RESULT"
  384. if [ "$node0" != "1" ]; then
  385. tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#1)."
  386. return 1
  387. fi
  388. if [ "$node1" != "0" ]; then
  389. tst_resm TFAIL "Allocated memory was not moved to the Node#0(Result: Node#$node1)."
  390. return 1
  391. fi
  392. if [ "$node2" != "0" ]; then
  393. tst_resm TFAIL "allocate memory on the Node#$node2(Expect: Node#0) after changing mems."
  394. return 1
  395. fi
  396. }
  397. # get the second thread's tid
  398. #$1 - pid
  399. get_the_second()
  400. {
  401. ls /proc/$1/task | (
  402. read tid1
  403. read tid2
  404. if [ "$1" -eq "$tid1" ]
  405. then
  406. echo $tid2
  407. else
  408. echo $tid1
  409. fi
  410. )
  411. }
  412. test14()
  413. {
  414. cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  415. if [ $? -ne 0 ]; then
  416. cpuset_log_error $CPUSET_TMP/stderr
  417. tst_resm TFAIL "set general group1's parameter failed."
  418. return 1
  419. fi
  420. cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  421. if [ $? -ne 0 ]; then
  422. cpuset_log_error $CPUSET_TMP/stderr
  423. tst_resm TFAIL "set general group2's parameter failed."
  424. return 1
  425. fi
  426. cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
  427. {
  428. local testpid=$!
  429. sleep 1
  430. local testtid=$(get_the_second $testpid)
  431. echo $testpid > "$CPUSET/1/tasks"
  432. /bin/kill -s SIGUSR1 $testpid
  433. echo $testtid > "$CPUSET/2/tasks"
  434. sleep 1
  435. /bin/kill -s SIGUSR2 $testpid
  436. sleep 1
  437. /bin/kill -s SIGINT $testpid
  438. wait $testpid
  439. }
  440. {
  441. read node0
  442. read node1
  443. } < "$MEMORY_RESULT"
  444. if [ "$node0" != "0" ]; then
  445. tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#0)."
  446. return 1
  447. fi
  448. if [ "$node1" != "1" ]; then
  449. tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1)."
  450. return 1
  451. fi
  452. }
  453. test15()
  454. {
  455. cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  456. if [ $? -ne 0 ]; then
  457. cpuset_log_error $CPUSET_TMP/stderr
  458. tst_resm TFAIL "set general group1's parameter failed."
  459. return 1
  460. fi
  461. cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  462. if [ $? -ne 0 ]; then
  463. cpuset_log_error $CPUSET_TMP/stderr
  464. tst_resm TFAIL "set general group2's parameter failed."
  465. return 1
  466. fi
  467. echo 1 > "$CPUSET/2/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  468. if [ $? -ne 0 ]; then
  469. cpuset_log_error $CPUSET_TMP/stderr
  470. tst_resm TFAIL "set general group2's memory_migrate failed."
  471. return 1
  472. fi
  473. cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
  474. {
  475. local testpid=$!
  476. sleep 1
  477. local testtid=$(get_the_second $testpid)
  478. echo $testpid > "$CPUSET/1/tasks"
  479. /bin/kill -s SIGUSR1 $testpid
  480. echo $testtid > "$CPUSET/2/tasks"
  481. sleep 1
  482. /bin/kill -s SIGUSR2 $testpid
  483. sleep 1
  484. /bin/kill -s SIGINT $testpid
  485. wait $testpid
  486. }
  487. {
  488. read node0
  489. read node1
  490. } < "$MEMORY_RESULT"
  491. if [ "$node0" != "0" ]; then
  492. tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#0)."
  493. return 1
  494. fi
  495. if [ "$node1" != "1" ]; then
  496. tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1)."
  497. return 1
  498. fi
  499. }
  500. test16()
  501. {
  502. cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
  503. if [ $? -ne 0 ]; then
  504. cpuset_log_error $CPUSET_TMP/stderr
  505. tst_resm TFAIL "set general group1's parameter failed."
  506. return 1
  507. fi
  508. cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  509. if [ $? -ne 0 ]; then
  510. cpuset_log_error $CPUSET_TMP/stderr
  511. tst_resm TFAIL "set general group2's parameter failed."
  512. return 1
  513. fi
  514. echo 1 > "$CPUSET/2/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  515. if [ $? -ne 0 ]; then
  516. cpuset_log_error $CPUSET_TMP/stderr
  517. tst_resm TFAIL "set general group2's memory_migrate failed."
  518. return 1
  519. fi
  520. cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
  521. {
  522. local testpid=$!
  523. sleep 1
  524. local testtid=$(get_the_second $testpid)
  525. echo $testpid > "$CPUSET/1/tasks"
  526. /bin/kill -s SIGUSR1 $testpid
  527. echo $testtid > "$CPUSET/2/tasks"
  528. sleep 1
  529. echo 1 > "$CPUSET/1/cpuset.memory_migrate"
  530. sleep 1
  531. /bin/kill -s SIGUSR2 $testpid
  532. sleep 1
  533. /bin/kill -s SIGUSR1 $testpid
  534. sleep 1
  535. /bin/kill -s SIGUSR1 $testpid
  536. sleep 1
  537. /bin/kill -s SIGINT $testpid
  538. wait $testpid
  539. }
  540. {
  541. read node0
  542. read node1
  543. read node2
  544. } < "$MEMORY_RESULT"
  545. if [ "$node0" != "0" ]; then
  546. tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#0) first."
  547. return 1
  548. fi
  549. if [ "$node1" != "1" ]; then
  550. tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1)."
  551. return 1
  552. fi
  553. if [ "$node2" != "0" ]; then
  554. tst_resm TFAIL "Thread1 allocated memory on the Node#$node2(Expect: Node#0) second."
  555. return 1
  556. fi
  557. }
  558. test17()
  559. {
  560. cpuset_set "$CPUSET/1" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  561. if [ $? -ne 0 ]; then
  562. cpuset_log_error $CPUSET_TMP/stderr
  563. tst_resm TFAIL "set general group1's parameter failed."
  564. return 1
  565. fi
  566. cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  567. if [ $? -ne 0 ]; then
  568. cpuset_log_error $CPUSET_TMP/stderr
  569. tst_resm TFAIL "set general group2's parameter failed."
  570. return 1
  571. fi
  572. echo 1 > "$CPUSET/2/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  573. if [ $? -ne 0 ]; then
  574. cpuset_log_error $CPUSET_TMP/stderr
  575. tst_resm TFAIL "set general group2's memory_migrate failed."
  576. return 1
  577. fi
  578. cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
  579. {
  580. local testpid=$!
  581. sleep 1
  582. local testtid=$(get_the_second $testpid)
  583. echo $testpid > "$CPUSET/1/tasks"
  584. /bin/kill -s SIGUSR1 $testpid
  585. echo $testtid > "$CPUSET/2/tasks"
  586. sleep 1
  587. echo 0 > "$CPUSET/1/cpuset.mems"
  588. sleep 1
  589. /bin/kill -s SIGUSR2 $testpid
  590. sleep 1
  591. /bin/kill -s SIGUSR1 $testpid
  592. sleep 1
  593. /bin/kill -s SIGUSR1 $testpid
  594. sleep 1
  595. /bin/kill -s SIGUSR2 $testpid
  596. sleep 1
  597. /bin/kill -s SIGUSR2 $testpid
  598. sleep 1
  599. /bin/kill -s SIGINT $testpid
  600. wait $testpid
  601. }
  602. {
  603. read node0
  604. read node1
  605. read node2
  606. read node3
  607. } < "$MEMORY_RESULT"
  608. if [ "$node0" != "1" ]; then
  609. tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#1) first."
  610. return 1
  611. fi
  612. if [ "$node1" != "1" ]; then
  613. tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1) first."
  614. return 1
  615. fi
  616. if [ "$node2" != "0" ]; then
  617. tst_resm TFAIL "Thread1 allocated memory on the Node#$node2(Expect: Node#0) second"
  618. return 1
  619. fi
  620. if [ "$node3" != "1" ]; then
  621. tst_resm TFAIL "Thread2 allocated memory on the Node#$node3(Expect: Node#1) second"
  622. return 1
  623. fi
  624. }
  625. test18()
  626. {
  627. cpuset_set "$CPUSET/1" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  628. if [ $? -ne 0 ]; then
  629. cpuset_log_error $CPUSET_TMP/stderr
  630. tst_resm TFAIL "set general group1's parameter failed."
  631. return 1
  632. fi
  633. echo 1 > "$CPUSET/1/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  634. if [ $? -ne 0 ]; then
  635. cpuset_log_error $CPUSET_TMP/stderr
  636. tst_resm TFAIL "set general group1's memory_migrate failed."
  637. return 1
  638. fi
  639. cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
  640. if [ $? -ne 0 ]; then
  641. cpuset_log_error $CPUSET_TMP/stderr
  642. tst_resm TFAIL "set general group2's parameter failed."
  643. return 1
  644. fi
  645. echo 1 > "$CPUSET/2/cpuset.memory_migrate" 2> $CPUSET_TMP/stderr
  646. if [ $? -ne 0 ]; then
  647. cpuset_log_error $CPUSET_TMP/stderr
  648. tst_resm TFAIL "set general group2's memory_migrate failed."
  649. return 1
  650. fi
  651. cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
  652. {
  653. local testpid=$!
  654. sleep 1
  655. local testtid=$(get_the_second $testpid)
  656. echo $testpid > "$CPUSET/1/tasks"
  657. /bin/kill -s SIGUSR1 $testpid
  658. echo $testtid > "$CPUSET/2/tasks"
  659. sleep 1
  660. echo 0 > "$CPUSET/1/cpuset.mems"
  661. sleep 1
  662. /bin/kill -s SIGUSR2 $testpid
  663. sleep 1
  664. /bin/kill -s SIGUSR1 $testpid
  665. sleep 1
  666. /bin/kill -s SIGUSR1 $testpid
  667. sleep 1
  668. /bin/kill -s SIGUSR2 $testpid
  669. sleep 1
  670. /bin/kill -s SIGUSR2 $testpid
  671. sleep 1
  672. /bin/kill -s SIGINT $testpid
  673. wait $testpid
  674. }
  675. {
  676. read node0
  677. read node1
  678. read node2
  679. read node3
  680. } < "$MEMORY_RESULT"
  681. if [ "$node0" != "1" ]; then
  682. tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#1) first."
  683. return 1
  684. fi
  685. if [ "$node1" != "1" ]; then
  686. tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1) first."
  687. return 1
  688. fi
  689. if [ "$node2" != "0" ]; then
  690. tst_resm TFAIL "Thread1 allocated memory on the Node#$node2(Expect: Node#0) second"
  691. return 1
  692. fi
  693. if [ "$node3" != "1" ]; then
  694. tst_resm TFAIL "Thread2 allocated memory on the Node#$node3(Expect: Node#1) second"
  695. return 1
  696. fi
  697. }
  698. for c in $(seq 1 $TST_TOTAL)
  699. do
  700. setup
  701. if [ $? -ne 0 ]; then
  702. exit_status=1
  703. else
  704. test$c
  705. if [ $? -ne 0 ]; then
  706. exit_status=1
  707. cleanup
  708. else
  709. cleanup
  710. if [ $? -ne 0 ]; then
  711. exit_status=1
  712. else
  713. tst_resm TPASS "Cpuset memory allocation test succeeded."
  714. fi
  715. fi
  716. fi
  717. TST_COUNT=$(($TST_COUNT + 1))
  718. done
  719. exit $exit_status