1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 2*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later 3*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2015 SUSE 4*49cdfc7eSAndroid Build Coastguard Worker# Author: Cedric Hnyda <[email protected]> 5*49cdfc7eSAndroid Build Coastguard Worker# Usage 6*49cdfc7eSAndroid Build Coastguard Worker# ./pids.sh caseno max 7*49cdfc7eSAndroid Build Coastguard Worker 8*49cdfc7eSAndroid Build Coastguard WorkerTST_CLEANUP=cleanup 9*49cdfc7eSAndroid Build Coastguard WorkerTST_SETUP=setup 10*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test 11*49cdfc7eSAndroid Build Coastguard WorkerTST_POS_ARGS=3 12*49cdfc7eSAndroid Build Coastguard WorkerTST_USAGE=usage 13*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_ROOT=1 14*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CMDS="killall" 15*49cdfc7eSAndroid Build Coastguard Worker 16*49cdfc7eSAndroid Build Coastguard Workercaseno=$1 17*49cdfc7eSAndroid Build Coastguard Workermax=$2 18*49cdfc7eSAndroid Build Coastguard Workersubcgroup_num=$3 19*49cdfc7eSAndroid Build Coastguard Workermounted=1 20*49cdfc7eSAndroid Build Coastguard Worker 21*49cdfc7eSAndroid Build Coastguard Workerusage() 22*49cdfc7eSAndroid Build Coastguard Worker{ 23*49cdfc7eSAndroid Build Coastguard Worker cat << EOF 24*49cdfc7eSAndroid Build Coastguard Workerusage: $0 caseno max_processes 25*49cdfc7eSAndroid Build Coastguard Worker 26*49cdfc7eSAndroid Build Coastguard Workercaseno - testcase number from interval 1-9 27*49cdfc7eSAndroid Build Coastguard Workermax_processes - maximal number of processes to attach 28*49cdfc7eSAndroid Build Coastguard Worker (not applicable to testcase 5) 29*49cdfc7eSAndroid Build Coastguard Workersubcgroup_num - number of subgroups created in group 30*49cdfc7eSAndroid Build Coastguard Worker (only applicable to testcase 7) 31*49cdfc7eSAndroid Build Coastguard WorkerOPTIONS 32*49cdfc7eSAndroid Build Coastguard WorkerEOF 33*49cdfc7eSAndroid Build Coastguard Worker} 34*49cdfc7eSAndroid Build Coastguard Worker 35*49cdfc7eSAndroid Build Coastguard Workercleanup() 36*49cdfc7eSAndroid Build Coastguard Worker{ 37*49cdfc7eSAndroid Build Coastguard Worker killall -9 pids_task2 >/dev/null 2>&1 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard Worker cgroup_cleanup 40*49cdfc7eSAndroid Build Coastguard Worker} 41*49cdfc7eSAndroid Build Coastguard Worker 42*49cdfc7eSAndroid Build Coastguard Workersetup() 43*49cdfc7eSAndroid Build Coastguard Worker{ 44*49cdfc7eSAndroid Build Coastguard Worker cgroup_require "pids" 45*49cdfc7eSAndroid Build Coastguard Worker cgroup_version=$(cgroup_get_version "pids") 46*49cdfc7eSAndroid Build Coastguard Worker testpath=$(cgroup_get_test_path "pids") 47*49cdfc7eSAndroid Build Coastguard Worker task_list=$(cgroup_get_task_list "pids") 48*49cdfc7eSAndroid Build Coastguard Worker 49*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "test starts with cgroup version $cgroup_version" 50*49cdfc7eSAndroid Build Coastguard Worker} 51*49cdfc7eSAndroid Build Coastguard Worker 52*49cdfc7eSAndroid Build Coastguard Workerstart_pids_tasks2() 53*49cdfc7eSAndroid Build Coastguard Worker{ 54*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2_path $testpath $1 55*49cdfc7eSAndroid Build Coastguard Worker} 56*49cdfc7eSAndroid Build Coastguard Worker 57*49cdfc7eSAndroid Build Coastguard Workerstart_pids_tasks2_path() 58*49cdfc7eSAndroid Build Coastguard Worker{ 59*49cdfc7eSAndroid Build Coastguard Worker path=$1 60*49cdfc7eSAndroid Build Coastguard Worker nb=$2 61*49cdfc7eSAndroid Build Coastguard Worker for i in `seq 1 $nb`; do 62*49cdfc7eSAndroid Build Coastguard Worker pids_task2 & 63*49cdfc7eSAndroid Build Coastguard Worker echo $! > "$path/$task_list" 64*49cdfc7eSAndroid Build Coastguard Worker done 65*49cdfc7eSAndroid Build Coastguard Worker 66*49cdfc7eSAndroid Build Coastguard Worker if [ $(wc -l < "$path/$task_list") -ne "$nb" ]; then 67*49cdfc7eSAndroid Build Coastguard Worker tst_brk TBROK "failed to attach process" 68*49cdfc7eSAndroid Build Coastguard Worker fi 69*49cdfc7eSAndroid Build Coastguard Worker} 70*49cdfc7eSAndroid Build Coastguard Worker 71*49cdfc7eSAndroid Build Coastguard Workerstop_pids_tasks() 72*49cdfc7eSAndroid Build Coastguard Worker{ 73*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks_path $testpath 74*49cdfc7eSAndroid Build Coastguard Worker} 75*49cdfc7eSAndroid Build Coastguard Worker 76*49cdfc7eSAndroid Build Coastguard Workerstop_pids_tasks_path() 77*49cdfc7eSAndroid Build Coastguard Worker{ 78*49cdfc7eSAndroid Build Coastguard Worker local i 79*49cdfc7eSAndroid Build Coastguard Worker path=$1 80*49cdfc7eSAndroid Build Coastguard Worker 81*49cdfc7eSAndroid Build Coastguard Worker for i in $(cat "$path/$task_list"); do 82*49cdfc7eSAndroid Build Coastguard Worker ROD kill -9 $i 83*49cdfc7eSAndroid Build Coastguard Worker wait $i 84*49cdfc7eSAndroid Build Coastguard Worker done 85*49cdfc7eSAndroid Build Coastguard Worker} 86*49cdfc7eSAndroid Build Coastguard Worker 87*49cdfc7eSAndroid Build Coastguard Workercase1() 88*49cdfc7eSAndroid Build Coastguard Worker{ 89*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2 $max 90*49cdfc7eSAndroid Build Coastguard Worker 91*49cdfc7eSAndroid Build Coastguard Worker # should return 0 because there is no limit 92*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/$task_list" 93*49cdfc7eSAndroid Build Coastguard Worker ret=$? 94*49cdfc7eSAndroid Build Coastguard Worker 95*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 96*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "fork failed unexpectedly" 97*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 98*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "fork didn't fail" 99*49cdfc7eSAndroid Build Coastguard Worker else 100*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "pids_task1 failed" 101*49cdfc7eSAndroid Build Coastguard Worker fi 102*49cdfc7eSAndroid Build Coastguard Worker 103*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 104*49cdfc7eSAndroid Build Coastguard Worker} 105*49cdfc7eSAndroid Build Coastguard Worker 106*49cdfc7eSAndroid Build Coastguard Workercase2() 107*49cdfc7eSAndroid Build Coastguard Worker{ 108*49cdfc7eSAndroid Build Coastguard Worker tmp=$((max - 1)) 109*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "limit the number of pid to $max" 110*49cdfc7eSAndroid Build Coastguard Worker ROD echo $max \> $testpath/pids.max 111*49cdfc7eSAndroid Build Coastguard Worker 112*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2 $tmp 113*49cdfc7eSAndroid Build Coastguard Worker 114*49cdfc7eSAndroid Build Coastguard Worker # should return 2 because the limit of pids is reached 115*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/$task_list" 116*49cdfc7eSAndroid Build Coastguard Worker ret=$? 117*49cdfc7eSAndroid Build Coastguard Worker 118*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 119*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "fork failed as expected" 120*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 121*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "fork didn't fail despite the limit" 122*49cdfc7eSAndroid Build Coastguard Worker else 123*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "pids_task1 failed" 124*49cdfc7eSAndroid Build Coastguard Worker fi 125*49cdfc7eSAndroid Build Coastguard Worker 126*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 127*49cdfc7eSAndroid Build Coastguard Worker} 128*49cdfc7eSAndroid Build Coastguard Worker 129*49cdfc7eSAndroid Build Coastguard Workercase3() 130*49cdfc7eSAndroid Build Coastguard Worker{ 131*49cdfc7eSAndroid Build Coastguard Worker lim=$((max + 2)) 132*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "limit the number of avalaible pid to $lim" 133*49cdfc7eSAndroid Build Coastguard Worker ROD echo $lim \> $testpath/pids.max 134*49cdfc7eSAndroid Build Coastguard Worker 135*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2 $max 136*49cdfc7eSAndroid Build Coastguard Worker 137*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/$task_list" 138*49cdfc7eSAndroid Build Coastguard Worker ret=$? 139*49cdfc7eSAndroid Build Coastguard Worker 140*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 141*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "fork failed unexpectedly" 142*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 143*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "fork worked as expected" 144*49cdfc7eSAndroid Build Coastguard Worker else 145*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "pids_task1 failed" 146*49cdfc7eSAndroid Build Coastguard Worker fi 147*49cdfc7eSAndroid Build Coastguard Worker 148*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 149*49cdfc7eSAndroid Build Coastguard Worker} 150*49cdfc7eSAndroid Build Coastguard Worker 151*49cdfc7eSAndroid Build Coastguard Workercase4() 152*49cdfc7eSAndroid Build Coastguard Worker{ 153*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "limit the number of avalaible pid to 0" 154*49cdfc7eSAndroid Build Coastguard Worker ROD echo 0 \> $testpath/pids.max 155*49cdfc7eSAndroid Build Coastguard Worker 156*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2 $max 157*49cdfc7eSAndroid Build Coastguard Worker 158*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "all process were attached" 159*49cdfc7eSAndroid Build Coastguard Worker 160*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 161*49cdfc7eSAndroid Build Coastguard Worker} 162*49cdfc7eSAndroid Build Coastguard Worker 163*49cdfc7eSAndroid Build Coastguard Workercase5() 164*49cdfc7eSAndroid Build Coastguard Worker{ 165*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "try to limit the number of avalaible pid to -1" 166*49cdfc7eSAndroid Build Coastguard Worker echo -1 > $testpath/pids.max 167*49cdfc7eSAndroid Build Coastguard Worker 168*49cdfc7eSAndroid Build Coastguard Worker if [ "$?" -eq "0" ]; then 169*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "managed to set the limit to -1" 170*49cdfc7eSAndroid Build Coastguard Worker else 171*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "didn't manage to set the limit to -1" 172*49cdfc7eSAndroid Build Coastguard Worker fi 173*49cdfc7eSAndroid Build Coastguard Worker} 174*49cdfc7eSAndroid Build Coastguard Worker 175*49cdfc7eSAndroid Build Coastguard Workercase6() 176*49cdfc7eSAndroid Build Coastguard Worker{ 177*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "set a limit that is smaller than current number of pids" 178*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2 $max 179*49cdfc7eSAndroid Build Coastguard Worker 180*49cdfc7eSAndroid Build Coastguard Worker lim=$((max - 1)) 181*49cdfc7eSAndroid Build Coastguard Worker ROD echo $lim \> $testpath/pids.max 182*49cdfc7eSAndroid Build Coastguard Worker 183*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/$task_list" 184*49cdfc7eSAndroid Build Coastguard Worker ret=$? 185*49cdfc7eSAndroid Build Coastguard Worker 186*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 187*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "fork failed as expected" 188*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 189*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "fork didn't fail despite the limit" 190*49cdfc7eSAndroid Build Coastguard Worker else 191*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "pids_task1 failed" 192*49cdfc7eSAndroid Build Coastguard Worker fi 193*49cdfc7eSAndroid Build Coastguard Worker 194*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 195*49cdfc7eSAndroid Build Coastguard Worker} 196*49cdfc7eSAndroid Build Coastguard Worker 197*49cdfc7eSAndroid Build Coastguard Workercase7() 198*49cdfc7eSAndroid Build Coastguard Worker{ 199*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "the number of all child cgroup tasks larger than its parent limit" 200*49cdfc7eSAndroid Build Coastguard Worker 201*49cdfc7eSAndroid Build Coastguard Worker lim=$((max / subcgroup_num)) 202*49cdfc7eSAndroid Build Coastguard Worker if [ "$((lim * subcgroup_num))" -ne "$max" ]; then 203*49cdfc7eSAndroid Build Coastguard Worker tst_res TWARN "input max value must be a multiplier of $subcgroup_num" 204*49cdfc7eSAndroid Build Coastguard Worker return 205*49cdfc7eSAndroid Build Coastguard Worker fi 206*49cdfc7eSAndroid Build Coastguard Worker 207*49cdfc7eSAndroid Build Coastguard Worker ROD echo $max \> $testpath/pids.max 208*49cdfc7eSAndroid Build Coastguard Worker 209*49cdfc7eSAndroid Build Coastguard Worker for i in `seq 1 $subcgroup_num`; do 210*49cdfc7eSAndroid Build Coastguard Worker mkdir $testpath/child$i 211*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2_path $testpath/child$i $lim 212*49cdfc7eSAndroid Build Coastguard Worker done 213*49cdfc7eSAndroid Build Coastguard Worker 214*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/$task_list" 215*49cdfc7eSAndroid Build Coastguard Worker ret=$? 216*49cdfc7eSAndroid Build Coastguard Worker 217*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 218*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "parent cgroup fork failed as expected" 219*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 220*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "parent cgroup fork didn't fail despite the limit" 221*49cdfc7eSAndroid Build Coastguard Worker else 222*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "parent cgroup pids_task1 failed" 223*49cdfc7eSAndroid Build Coastguard Worker fi 224*49cdfc7eSAndroid Build Coastguard Worker 225*49cdfc7eSAndroid Build Coastguard Worker for i in `seq 1 $subcgroup_num`; do 226*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/child$i/$task_list" 227*49cdfc7eSAndroid Build Coastguard Worker ret=$? 228*49cdfc7eSAndroid Build Coastguard Worker 229*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 230*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "child$i cgroup fork failed as expected" 231*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 232*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "child$i cgroup fork didn't fail despite the limit" 233*49cdfc7eSAndroid Build Coastguard Worker else 234*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "child$i cgroup pids_task1 failed" 235*49cdfc7eSAndroid Build Coastguard Worker fi 236*49cdfc7eSAndroid Build Coastguard Worker done 237*49cdfc7eSAndroid Build Coastguard Worker 238*49cdfc7eSAndroid Build Coastguard Worker for i in `seq 1 $subcgroup_num`; do 239*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks_path $testpath/child$i 240*49cdfc7eSAndroid Build Coastguard Worker rmdir $testpath/child$i 241*49cdfc7eSAndroid Build Coastguard Worker done 242*49cdfc7eSAndroid Build Coastguard Worker 243*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 244*49cdfc7eSAndroid Build Coastguard Worker} 245*49cdfc7eSAndroid Build Coastguard Worker 246*49cdfc7eSAndroid Build Coastguard Workercase8() 247*49cdfc7eSAndroid Build Coastguard Worker{ 248*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "set child cgroup limit smaller than its parent limit" 249*49cdfc7eSAndroid Build Coastguard Worker ROD echo $max \> $testpath/pids.max 250*49cdfc7eSAndroid Build Coastguard Worker if [ "$cgroup_version" = "2" ]; then 251*49cdfc7eSAndroid Build Coastguard Worker ROD echo +pids \> "$testpath"/cgroup.subtree_control 252*49cdfc7eSAndroid Build Coastguard Worker fi 253*49cdfc7eSAndroid Build Coastguard Worker mkdir $testpath/child 254*49cdfc7eSAndroid Build Coastguard Worker 255*49cdfc7eSAndroid Build Coastguard Worker lim=$((max - 1)) 256*49cdfc7eSAndroid Build Coastguard Worker ROD echo $lim \> $testpath/child/pids.max 257*49cdfc7eSAndroid Build Coastguard Worker tmp=$((max - 2)) 258*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2_path $testpath/child $tmp 259*49cdfc7eSAndroid Build Coastguard Worker 260*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/child/$task_list" 261*49cdfc7eSAndroid Build Coastguard Worker ret=$? 262*49cdfc7eSAndroid Build Coastguard Worker 263*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 264*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "fork failed as expected" 265*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 266*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "fork didn't fail despite the limit" 267*49cdfc7eSAndroid Build Coastguard Worker else 268*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "pids_task1 failed" 269*49cdfc7eSAndroid Build Coastguard Worker fi 270*49cdfc7eSAndroid Build Coastguard Worker 271*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks_path $testpath/child 272*49cdfc7eSAndroid Build Coastguard Worker rmdir $testpath/child 273*49cdfc7eSAndroid Build Coastguard Worker} 274*49cdfc7eSAndroid Build Coastguard Worker 275*49cdfc7eSAndroid Build Coastguard Workercase9() 276*49cdfc7eSAndroid Build Coastguard Worker{ 277*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "migrate cgroup" 278*49cdfc7eSAndroid Build Coastguard Worker lim=$((max - 1)) 279*49cdfc7eSAndroid Build Coastguard Worker 280*49cdfc7eSAndroid Build Coastguard Worker if [ "$cgroup_version" = "2" ]; then 281*49cdfc7eSAndroid Build Coastguard Worker ROD echo +pids \> "$testpath"/cgroup.subtree_control 282*49cdfc7eSAndroid Build Coastguard Worker fi 283*49cdfc7eSAndroid Build Coastguard Worker for i in 1 2; do 284*49cdfc7eSAndroid Build Coastguard Worker mkdir $testpath/child$i 285*49cdfc7eSAndroid Build Coastguard Worker ROD echo $max \> $testpath/child$i/pids.max 286*49cdfc7eSAndroid Build Coastguard Worker start_pids_tasks2_path $testpath/child$i $lim 287*49cdfc7eSAndroid Build Coastguard Worker done 288*49cdfc7eSAndroid Build Coastguard Worker 289*49cdfc7eSAndroid Build Coastguard Worker pid=`head -n 1 "$testpath/child1/$task_list"`; 290*49cdfc7eSAndroid Build Coastguard Worker ROD echo $pid \> "$testpath/child2/$task_list" 291*49cdfc7eSAndroid Build Coastguard Worker 292*49cdfc7eSAndroid Build Coastguard Worker if grep -q "$pid" "$testpath/child2/$task_list"; then 293*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "migrate pid $pid from cgroup1 to cgroup2 as expected" 294*49cdfc7eSAndroid Build Coastguard Worker else 295*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "migrate pid $pid from cgroup1 to cgroup2 failed" 296*49cdfc7eSAndroid Build Coastguard Worker fi 297*49cdfc7eSAndroid Build Coastguard Worker 298*49cdfc7eSAndroid Build Coastguard Worker if [ $(cat "$testpath/child1/pids.current") -eq $((lim - 1)) ]; then 299*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "migrate child1 cgroup as expected" 300*49cdfc7eSAndroid Build Coastguard Worker else 301*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "migrate child1 cgroup failed" 302*49cdfc7eSAndroid Build Coastguard Worker fi 303*49cdfc7eSAndroid Build Coastguard Worker 304*49cdfc7eSAndroid Build Coastguard Worker if [ $(cat "$testpath/child2/pids.current") -eq $((lim + 1)) ]; then 305*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "migrate child2 cgroup as expected" 306*49cdfc7eSAndroid Build Coastguard Worker else 307*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "migrate child2 cgroup failed" 308*49cdfc7eSAndroid Build Coastguard Worker fi 309*49cdfc7eSAndroid Build Coastguard Worker 310*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/child1/$task_list" 311*49cdfc7eSAndroid Build Coastguard Worker ret=$? 312*49cdfc7eSAndroid Build Coastguard Worker 313*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 314*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "child1 fork failed unexpectedly" 315*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 316*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "child1 fork worked as expected" 317*49cdfc7eSAndroid Build Coastguard Worker else 318*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "child1 pids_task1 failed" 319*49cdfc7eSAndroid Build Coastguard Worker fi 320*49cdfc7eSAndroid Build Coastguard Worker 321*49cdfc7eSAndroid Build Coastguard Worker pids_task1 "$testpath/child2/$task_list" 322*49cdfc7eSAndroid Build Coastguard Worker ret=$? 323*49cdfc7eSAndroid Build Coastguard Worker 324*49cdfc7eSAndroid Build Coastguard Worker if [ "$ret" -eq "2" ]; then 325*49cdfc7eSAndroid Build Coastguard Worker tst_res TPASS "child2 fork failed as expected" 326*49cdfc7eSAndroid Build Coastguard Worker elif [ "$ret" -eq "0" ]; then 327*49cdfc7eSAndroid Build Coastguard Worker tst_res TFAIL "child2 fork didn't fail despite the limit" 328*49cdfc7eSAndroid Build Coastguard Worker else 329*49cdfc7eSAndroid Build Coastguard Worker tst_res TBROK "child2 pids_task1 failed" 330*49cdfc7eSAndroid Build Coastguard Worker fi 331*49cdfc7eSAndroid Build Coastguard Worker 332*49cdfc7eSAndroid Build Coastguard Worker for i in 1 2; do 333*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks_path $testpath/child$i 334*49cdfc7eSAndroid Build Coastguard Worker rmdir $testpath/child$i 335*49cdfc7eSAndroid Build Coastguard Worker done 336*49cdfc7eSAndroid Build Coastguard Worker stop_pids_tasks 337*49cdfc7eSAndroid Build Coastguard Worker} 338*49cdfc7eSAndroid Build Coastguard Worker 339*49cdfc7eSAndroid Build Coastguard Workerdo_test() 340*49cdfc7eSAndroid Build Coastguard Worker{ 341*49cdfc7eSAndroid Build Coastguard Worker tst_res TINFO "Running testcase $caseno with $max processes" 342*49cdfc7eSAndroid Build Coastguard Worker case$caseno 343*49cdfc7eSAndroid Build Coastguard Worker} 344*49cdfc7eSAndroid Build Coastguard Worker 345*49cdfc7eSAndroid Build Coastguard Worker. cgroup_lib.sh 346*49cdfc7eSAndroid Build Coastguard Workertst_run 347