github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/update.bats (about) 1 #!/usr/bin/env bats 2 3 load helpers 4 5 function teardown() { 6 rm -f $BATS_TMPDIR/runc-update-integration-test.json 7 teardown_running_container test_update 8 teardown_busybox 9 } 10 11 function setup() { 12 teardown 13 setup_busybox 14 15 # Add cgroup path 16 sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "\/runc-update-integration-test",/' ${BUSYBOX_BUNDLE}/config.json 17 18 # Set some initial known values 19 DATA=$(cat <<EOF 20 "memory": { 21 "limit": 33554432, 22 "reservation": 25165824, 23 "kernel": 16777216, 24 "kernelTCP": 11534336 25 }, 26 "cpu": { 27 "shares": 100, 28 "quota": 500000, 29 "period": 1000000, 30 "cpus": "0" 31 }, 32 "blockio": { 33 "blkioWeight": 1000 34 }, 35 EOF 36 ) 37 DATA=$(echo ${DATA} | sed 's/\n/\\n/g') 38 sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json 39 } 40 41 function check_cgroup_value() { 42 cgroup=$1 43 source=$2 44 expected=$3 45 46 current=$(cat $cgroup/$source) 47 [ "$current" -eq "$expected" ] 48 } 49 50 # TODO: test rt cgroup updating 51 @test "update" { 52 requires cgroups_kmem 53 # run a few busyboxes detached 54 runc run -d --console /dev/pts/ptmx test_update 55 [ "$status" -eq 0 ] 56 wait_for_container 15 1 test_update 57 58 # get the cgroup paths 59 for g in MEMORY CPUSET CPU BLKIO; do 60 base_path=$(grep "cgroup" /proc/self/mountinfo | gawk 'toupper($NF) ~ /\<'${g}'\>/ { print $5; exit }') 61 eval CGROUP_${g}="${base_path}/runc-update-integration-test" 62 done 63 64 # check that initial values were properly set 65 check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 66 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 67 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 68 check_cgroup_value $CGROUP_CPU "cpu.shares" 100 69 check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 70 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 71 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336 72 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 73 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 74 75 # update blkio-weight 76 runc update test_update --blkio-weight 500 77 [ "$status" -eq 0 ] 78 check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500 79 80 # update cpu-period 81 runc update test_update --cpu-period 900000 82 [ "$status" -eq 0 ] 83 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000 84 85 # update cpu-quota 86 runc update test_update --cpu-quota 600000 87 [ "$status" -eq 0 ] 88 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000 89 90 # update cpu-shares 91 runc update test_update --cpu-share 200 92 [ "$status" -eq 0 ] 93 check_cgroup_value $CGROUP_CPU "cpu.shares" 200 94 95 # update cpuset if supported (i.e. we're running on a multicore cpu) 96 cpu_count=$(grep '^processor' /proc/cpuinfo | wc -l) 97 if [ $cpu_count -gt 1 ]; then 98 runc update test_update --cpuset-cpus "1" 99 [ "$status" -eq 0 ] 100 check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 1 101 fi 102 103 # update memory limit 104 runc update test_update --memory 67108864 105 [ "$status" -eq 0 ] 106 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864 107 108 runc update test_update --memory 50M 109 [ "$status" -eq 0 ] 110 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 52428800 111 112 113 # update memory soft limit 114 runc update test_update --memory-reservation 33554432 115 [ "$status" -eq 0 ] 116 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432 117 118 # update memory swap (if available) 119 if [ -f "$CGROUP_MEMORY/memory.memsw.limit_in_bytes" ]; then 120 runc update test_update --memory-swap 96468992 121 [ "$status" -eq 0 ] 122 check_cgroup_value $CGROUP_MEMORY "memory.memsw.limit_in_bytes" 96468992 123 fi 124 125 # update kernel memory limit 126 runc update test_update --kernel-memory 50331648 127 [ "$status" -eq 0 ] 128 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648 129 130 # update kernel memory tcp limit 131 runc update test_update --kernel-memory-tcp 41943040 132 [ "$status" -eq 0 ] 133 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 41943040 134 135 # Revert to the test initial value via json on stding 136 runc update -r - test_update <<EOF 137 { 138 "memory": { 139 "limit": 33554432, 140 "reservation": 25165824, 141 "kernel": 16777216, 142 "kernelTCP": 11534336 143 }, 144 "cpu": { 145 "shares": 100, 146 "quota": 500000, 147 "period": 1000000, 148 "cpus": "0" 149 }, 150 "blockIO": { 151 "blkioWeight": 1000 152 } 153 } 154 EOF 155 [ "$status" -eq 0 ] 156 check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 157 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 158 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 159 check_cgroup_value $CGROUP_CPU "cpu.shares" 100 160 check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 161 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 162 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336 163 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 164 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 165 166 # redo all the changes at once 167 runc update test_update --blkio-weight 500 \ 168 --cpu-period 900000 --cpu-quota 600000 --cpu-share 200 --memory 67108864 \ 169 --memory-reservation 33554432 --kernel-memory 50331648 --kernel-memory-tcp 41943040 170 [ "$status" -eq 0 ] 171 check_cgroup_value $CGROUP_BLKIO "blkio.weight" 500 172 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 900000 173 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 600000 174 check_cgroup_value $CGROUP_CPU "cpu.shares" 200 175 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648 176 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 41943040 177 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 67108864 178 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 33554432 179 180 # reset to initial test value via json file 181 DATA=$(cat <<"EOF" 182 { 183 "memory": { 184 "limit": 33554432, 185 "reservation": 25165824, 186 "kernel": 16777216, 187 "kernelTCP": 11534336 188 }, 189 "cpu": { 190 "shares": 100, 191 "quota": 500000, 192 "period": 1000000, 193 "cpus": "0" 194 }, 195 "blockIO": { 196 "blkioWeight": 1000 197 } 198 } 199 EOF 200 ) 201 echo $DATA > $BATS_TMPDIR/runc-update-integration-test.json 202 203 runc update -r $BATS_TMPDIR/runc-update-integration-test.json test_update 204 [ "$status" -eq 0 ] 205 check_cgroup_value $CGROUP_BLKIO "blkio.weight" 1000 206 check_cgroup_value $CGROUP_CPU "cpu.cfs_period_us" 1000000 207 check_cgroup_value $CGROUP_CPU "cpu.cfs_quota_us" 500000 208 check_cgroup_value $CGROUP_CPU "cpu.shares" 100 209 check_cgroup_value $CGROUP_CPUSET "cpuset.cpus" 0 210 check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 16777216 211 check_cgroup_value $CGROUP_MEMORY "memory.kmem.tcp.limit_in_bytes" 11534336 212 check_cgroup_value $CGROUP_MEMORY "memory.limit_in_bytes" 33554432 213 check_cgroup_value $CGROUP_MEMORY "memory.soft_limit_in_bytes" 25165824 214 }