Home | History | Annotate | Download | only in cpuset_hierarchy_test
      1 #!/bin/sh
      2 
      3 ################################################################################
      4 #                                                                              #
      5 # Copyright (c) 2009 FUJITSU LIMITED                                           #
      6 #                                                                              #
      7 # This program is free software;  you can redistribute it and#or modify        #
      8 # it under the terms of the GNU General Public License as published by         #
      9 # the Free Software Foundation; either version 2 of the License, or            #
     10 # (at your option) any later version.                                          #
     11 #                                                                              #
     12 # This program is distributed in the hope that it will be useful, but          #
     13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY   #
     14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License     #
     15 # for more details.                                                            #
     16 #                                                                              #
     17 # You should have received a copy of the GNU General Public License            #
     18 # along with this program;  if not, write to the Free Software                 #
     19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA      #
     20 #                                                                              #
     21 # Author: Miao Xie <miaox (at] cn.fujitsu.com>                                      #
     22 #                                                                              #
     23 ################################################################################
     24 
     25 export TCID="cpuset_hierarchy"
     26 export TST_TOTAL=32
     27 export TST_COUNT=1
     28 
     29 . cpuset_funcs.sh
     30 
     31 check
     32 
     33 nr_cpus=$NR_CPUS
     34 nr_mems=$N_NODES
     35 
     36 cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
     37 mems_all="$(seq -s, 0 $((nr_mems-1)))"
     38 
     39 exit_status=0
     40 
     41 # test cpus
     42 
     43 test1()
     44 {
     45 	echo > "$CPUSET/father/cpus" || return 1
     46 	echo > "$CPUSET/father/child/cpus" || return 1
     47 
     48 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
     49 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
     50 
     51 	test -z "$(cat "$CPUSET/father/cpus")" || return 1
     52 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
     53 }
     54 
     55 test2()
     56 {
     57 	echo > "$CPUSET/father/cpus" || return 1
     58 	echo 0 > "$CPUSET/father/child/cpus" 2> /dev/null && return 1
     59 
     60 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
     61 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
     62 
     63 	test -z "$(cat "$CPUSET/father/cpus")" || return 1
     64 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
     65 }
     66 
     67 test3()
     68 {
     69 	echo 0 > "$CPUSET/father/cpus" || return 1
     70 	echo > "$CPUSET/father/child/cpus" || return 1
     71 
     72 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
     73 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
     74 
     75 	test 0 = "$(cat "$CPUSET/father/cpus")" || return 1
     76 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
     77 }
     78 
     79 test4()
     80 {
     81 	echo 0 > "$CPUSET/father/cpus" || return 1
     82 	echo 0 > "$CPUSET/father/child/cpus" || return 1
     83 
     84 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
     85 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
     86 
     87 	test 0 = "$(cat "$CPUSET/father/cpus")" || return 1
     88 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
     89 }
     90 
     91 test5()
     92 {
     93 	echo 0 > "$CPUSET/father/cpus" || return 1
     94 	echo 1 > "$CPUSET/father/child/cpus" 2> /dev/null && return 1
     95 
     96 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
     97 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
     98 
     99 	test 0 = "$(cat "$CPUSET/father/cpus")" || return 1
    100 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
    101 }
    102 
    103 test6()
    104 {
    105 	echo 0 > "$CPUSET/father/cpus" || return 1
    106 	echo 0,1 > "$CPUSET/father/child/cpus" 2> /dev/null && return 1
    107 
    108 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    109 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    110 
    111 	test 0 = "$(cat "$CPUSET/father/cpus")" || return 1
    112 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
    113 }
    114 
    115 test7()
    116 {
    117 	echo "0,1" > "$CPUSET/father/cpus" || return 1
    118 	echo 0 > "$CPUSET/father/child/cpus" || return 1
    119 
    120 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    121 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    122 
    123 	test "0-1" = "$(cat "$CPUSET/father/cpus")" || return 1
    124 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    125 }
    126 
    127 test8()
    128 {
    129 	echo "0,1" > "$CPUSET/father/cpus" || return 1
    130 	echo 0 > "$CPUSET/father/child/cpus" || return 1
    131 
    132 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    133 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    134 
    135 	test "0-1" = "$(cat "$CPUSET/father/cpus")" || return 1
    136 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    137 }
    138 
    139 test9()
    140 {
    141 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    142 	echo > "$CPUSET/father/child/cpus" || return 1
    143 	echo > "$CPUSET/father/cpus" || return 1
    144 
    145 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    146 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    147 
    148 	test -z "$(cat "$CPUSET/father/cpus")" || return 1
    149 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
    150 }
    151 
    152 test10()
    153 {
    154 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    155 	echo 0 > "$CPUSET/father/child/cpus" || return 1
    156 	echo > "$CPUSET/father/cpus" 2> /dev/null && return 1
    157 
    158 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    159 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    160 
    161 	test "0-$((nr_cpus-1))" = "$(cat "$CPUSET/father/cpus")" || return 1
    162 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    163 }
    164 
    165 test11()
    166 {
    167 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    168 	echo > "$CPUSET/father/child/cpus" || return 1
    169 	echo 0 > "$CPUSET/father/cpus" || return 1
    170 
    171 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    172 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    173 
    174 	test 0 = "$(cat "$CPUSET/father/cpus")" || return 1
    175 	test -z "$(cat "$CPUSET/father/child/cpus")" || return 1
    176 }
    177 
    178 test12()
    179 {
    180 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    181 	echo 0 > "$CPUSET/father/child/cpus" || return 1
    182 	echo 0 > "$CPUSET/father/cpus" || return 1
    183 
    184 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    185 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    186 
    187 	test 0 = "$(cat "$CPUSET/father/cpus")" || return 1
    188 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    189 }
    190 
    191 test13()
    192 {
    193 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    194 	echo 1 > "$CPUSET/father/child/cpus" || return 1
    195 	echo 0 > "$CPUSET/father/cpus" 2> /dev/null && return 1
    196 
    197 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    198 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    199 
    200 	test "0-$((nr_cpus-1))" = "$(cat "$CPUSET/father/cpus")" || return 1
    201 	test 1 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    202 }
    203 
    204 test14()
    205 {
    206 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    207 	echo 0,1 > "$CPUSET/father/child/cpus" || return 1
    208 	echo 0 > "$CPUSET/father/cpus" 2> /dev/null && return 1
    209 
    210 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    211 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    212 
    213 	test "0-$((nr_cpus-1))" = "$(cat "$CPUSET/father/cpus")" || return 1
    214 	test "0-1" = "$(cat "$CPUSET/father/child/cpus")" || return 1
    215 }
    216 
    217 test15()
    218 {
    219 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    220 	echo 0 > "$CPUSET/father/child/cpus" || return 1
    221 	echo "0,1" > "$CPUSET/father/cpus" || return 1
    222 
    223 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    224 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    225 
    226 	test "0-1" = "$(cat "$CPUSET/father/cpus")" || return 1
    227 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    228 }
    229 
    230 test16()
    231 {
    232 	echo "$cpus_all" > "$CPUSET/father/cpus" || return 1
    233 	echo 0 > "$CPUSET/father/child/cpus" || return 1
    234 	echo "0,1" > "$CPUSET/father/cpus" || return 1
    235 
    236 	cpuset_log "father cpus $(cat "$CPUSET/father/cpus")"
    237 	cpuset_log "child cpus $(cat "$CPUSET/father/child/cpus")"
    238 
    239 	test "0-1" = "$(cat "$CPUSET/father/cpus")" || return 1
    240 	test 0 = "$(cat "$CPUSET/father/child/cpus")" || return 1
    241 }
    242 
    243 ## test mems
    244 
    245 test17()
    246 {
    247 	echo > "$CPUSET/father/mems" || return 1
    248 	echo > "$CPUSET/father/child/mems" || return 1
    249 
    250 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    251 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    252 
    253 	test -z "$(cat "$CPUSET/father/mems")" || return 1
    254 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    255 }
    256 
    257 test18()
    258 {
    259 	echo > "$CPUSET/father/mems" || return 1
    260 	echo 0 > "$CPUSET/father/child/mems" 2> /dev/null && return 1
    261 
    262 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    263 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    264 
    265 	test -z "$(cat "$CPUSET/father/mems")" || return 1
    266 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    267 }
    268 
    269 test19()
    270 {
    271 	echo 0 > "$CPUSET/father/mems" || return 1
    272 	echo > "$CPUSET/father/child/mems" || return 1
    273 
    274 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    275 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    276 
    277 	test 0 = "$(cat "$CPUSET/father/mems")" || return 1
    278 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    279 }
    280 
    281 test20()
    282 {
    283 	echo 0 > "$CPUSET/father/mems" || return 1
    284 	echo 0 > "$CPUSET/father/child/mems" || return 1
    285 
    286 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    287 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    288 
    289 	test 0 = "$(cat "$CPUSET/father/mems")" || return 1
    290 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    291 }
    292 
    293 test21()
    294 {
    295 	echo 0 > "$CPUSET/father/mems" || return 1
    296 	echo 1 > "$CPUSET/father/child/mems" 2> /dev/null && return 1
    297 
    298 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    299 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    300 
    301 	test 0 = "$(cat "$CPUSET/father/mems")" || return 1
    302 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    303 }
    304 
    305 test22()
    306 {
    307 	echo 0 > "$CPUSET/father/mems" || return 1
    308 	echo 0,1 > "$CPUSET/father/child/mems" 2> /dev/null && return 1
    309 
    310 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    311 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    312 
    313 	test 0 = "$(cat "$CPUSET/father/mems")" || return 1
    314 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    315 }
    316 
    317 test23()
    318 {
    319 	echo "0,1" > "$CPUSET/father/mems" || return 1
    320 	echo 0 > "$CPUSET/father/child/mems" || return 1
    321 
    322 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    323 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    324 
    325 	test "0-1" = "$(cat "$CPUSET/father/mems")" || return 1
    326 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    327 }
    328 
    329 test24()
    330 {
    331 	echo "0,1" > "$CPUSET/father/mems" || return 1
    332 	echo 0 > "$CPUSET/father/child/mems" || return 1
    333 
    334 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    335 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    336 
    337 	test "0-1" = "$(cat "$CPUSET/father/mems")" || return 1
    338 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    339 }
    340 
    341 test25()
    342 {
    343 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    344 	echo > "$CPUSET/father/child/mems" || return 1
    345 	echo > "$CPUSET/father/mems" || return 1
    346 
    347 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    348 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    349 
    350 	test -z "$(cat "$CPUSET/father/mems")" || return 1
    351 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    352 }
    353 
    354 test26()
    355 {
    356 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    357 	echo 0 > "$CPUSET/father/child/mems" || return 1
    358 	echo > "$CPUSET/father/mems" 2> /dev/null && return 1
    359 
    360 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    361 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    362 
    363 	test "0-$((nr_mems-1))" = "$(cat "$CPUSET/father/mems")" || return 1
    364 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    365 }
    366 
    367 test27()
    368 {
    369 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    370 	echo > "$CPUSET/father/child/mems" || return 1
    371 	echo 0 > "$CPUSET/father/mems" || return 1
    372 
    373 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    374 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    375 
    376 	test 0 = "$(cat "$CPUSET/father/mems")" || return 1
    377 	test -z "$(cat "$CPUSET/father/child/mems")" || return 1
    378 }
    379 
    380 test28()
    381 {
    382 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    383 	echo 0 > "$CPUSET/father/child/mems" || return 1
    384 	echo 0 > "$CPUSET/father/mems" || return 1
    385 
    386 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    387 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    388 
    389 	test 0 = "$(cat "$CPUSET/father/mems")" || return 1
    390 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    391 }
    392 
    393 test29()
    394 {
    395 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    396 	echo 1 > "$CPUSET/father/child/mems" || return 1
    397 	echo 0 > "$CPUSET/father/mems" 2> /dev/null && return 1
    398 
    399 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    400 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    401 
    402 	test "0-$((nr_mems-1))" = "$(cat "$CPUSET/father/mems")" || return 1
    403 	test 1 = "$(cat "$CPUSET/father/child/mems")" || return 1
    404 }
    405 
    406 test30()
    407 {
    408 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    409 	echo 0,1 > "$CPUSET/father/child/mems" || return 1
    410 	echo 0 > "$CPUSET/father/mems" 2> /dev/null && return 1
    411 
    412 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    413 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    414 
    415 	test "0-$((nr_mems-1))" = "$(cat "$CPUSET/father/mems")" || return 1
    416 	test "0-1" = "$(cat "$CPUSET/father/child/mems")" || return 1
    417 }
    418 
    419 test31()
    420 {
    421 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    422 	echo 0 > "$CPUSET/father/child/mems" || return 1
    423 	echo "0,1" > "$CPUSET/father/mems" || return 1
    424 
    425 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    426 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    427 
    428 	test "0-1" = "$(cat "$CPUSET/father/mems")" || return 1
    429 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    430 }
    431 
    432 test32()
    433 {
    434 	echo "$mems_all" > "$CPUSET/father/mems" || return 1
    435 	echo 0 > "$CPUSET/father/child/mems" || return 1
    436 	echo "0,1" > "$CPUSET/father/mems" || return 1
    437 
    438 	cpuset_log "father mems $(cat "$CPUSET/father/mems")"
    439 	cpuset_log "child mems $(cat "$CPUSET/father/child/mems")"
    440 
    441 	test "0-1" = "$(cat "$CPUSET/father/mems")" || return 1
    442 	test 0 = "$(cat "$CPUSET/father/child/mems")" || return 1
    443 }
    444 
    445 for i in $(seq 1 $TST_TOTAL)
    446 do
    447 	setup
    448 	if [ $? -ne 0 ]; then
    449 		exit_status=1
    450 	else
    451 		mkdir "$CPUSET/father"
    452 		mkdir "$CPUSET/father/child"
    453 		test$i
    454 		if [ $? -ne 0 ]; then
    455 			tst_resm TFAIL "Break the hierarchy limit."
    456 			exit_status=1
    457 		else
    458 			tst_resm TPASS "Hierarchy test succeeded."
    459 		fi
    460 
    461 		cleanup
    462 		if [ $? -ne 0 ]; then
    463 			exit_status=1
    464 		fi
    465 	fi
    466 	TST_COUNT=$(($TST_COUNT + 1))
    467 done
    468 
    469 exit $exit_status
    470