@@ -7,7 +7,7 @@ if [ -z "$BATS_RUN_TMPDIR" ]; then
7
7
fi
8
8
9
9
# Root directory of integration tests.
10
- INTEGRATION_ROOT=$( dirname " $( readlink -f " $BASH_SOURCE " ) " )
10
+ INTEGRATION_ROOT=$( dirname " $( readlink -f " ${ BASH_SOURCE[0]} " ) " )
11
11
12
12
# Download images, get *_IMAGE variables.
13
13
IMAGES=$( " ${INTEGRATION_ROOT} " /get-images.sh)
@@ -18,6 +18,7 @@ RUNC="${INTEGRATION_ROOT}/../../runc"
18
18
RECVTTY=" ${INTEGRATION_ROOT} /../../contrib/cmd/recvtty/recvtty"
19
19
20
20
# Test data path.
21
+ # shellcheck disable=SC2034
21
22
TESTDATA=" ${INTEGRATION_ROOT} /testdata"
22
23
23
24
# CRIU PATH
@@ -38,7 +39,9 @@ function runc() {
38
39
39
40
# Some debug information to make life easier. bats will only print it if the
40
41
# test failed, in which case the output is useful.
41
- echo " runc $@ (status=$status ):" >&2
42
+ # shellcheck disable=SC2154
43
+ echo " runc $* (status=$status ):" >&2
44
+ # shellcheck disable=SC2154
42
45
echo " $output " >&2
43
46
}
44
47
@@ -47,44 +50,34 @@ function __runc() {
47
50
" $RUNC " ${RUNC_USE_SYSTEMD+--systemd-cgroup} --root " $ROOT /state" " $@ "
48
51
}
49
52
50
- # Wrapper for runc spec, which takes only one argument (the bundle path) .
53
+ # Wrapper for runc spec.
51
54
function runc_spec() {
52
- ! [[ " $# " > 1 ]]
53
-
54
55
local args=()
55
- local bundle=" "
56
-
57
56
if [ " $ROOTLESS " -ne 0 ]; then
58
57
args+=(" --rootless" )
59
58
fi
60
- if [ " $# " -ne 0 ]; then
61
- bundle=" $1 "
62
- args+=(" --bundle" " $bundle " )
63
- fi
64
59
65
60
runc spec " ${args[@]} "
66
61
67
62
# Always add additional mappings if we have idmaps.
68
63
if [[ " $ROOTLESS " -ne 0 ]] && [[ " $ROOTLESS_FEATURES " == * " idmap" * ]]; then
69
- runc_rootless_idmap " $bundle "
64
+ runc_rootless_idmap
70
65
fi
71
66
}
72
67
73
68
# Helper function to reformat config.json file. Input uses jq syntax.
74
69
function update_config() {
75
- bundle=" ${2:- .} "
76
- jq " $1 " " $bundle /config.json" | awk ' BEGIN{RS="";getline<"-";print>ARGV[1]}' " $bundle /config.json"
70
+ jq " $1 " " ./config.json" | awk ' BEGIN{RS="";getline<"-";print>ARGV[1]}' " ./config.json"
77
71
}
78
72
79
73
# Shortcut to add additional uids and gids, based on the values set as part of
80
74
# a rootless configuration.
81
75
function runc_rootless_idmap() {
82
- bundle=" ${1:- .} "
83
76
update_config ' .mounts |= map((select(.type == "devpts") | .options += ["gid=5"]) // .)
84
77
| .linux.uidMappings += [{"hostID": ' " $ROOTLESS_UIDMAP_START " ' , "containerID": 1000, "size": ' " $ROOTLESS_UIDMAP_LENGTH " ' }]
85
78
| .linux.gidMappings += [{"hostID": ' " $ROOTLESS_GIDMAP_START " ' , "containerID": 100, "size": 1}]
86
- | .linux.gidMappings += [{"hostID": ' " $(( $ ROOTLESS_GIDMAP_START + 10 )) " ' , "containerID": 1, "size": 20}]
87
- | .linux.gidMappings += [{"hostID": ' " $(( $ ROOTLESS_GIDMAP_START + 100 )) " ' , "containerID": 1000, "size": ' " $(( $ ROOTLESS_GIDMAP_LENGTH - 1000 )) " ' }]' $bundle
79
+ | .linux.gidMappings += [{"hostID": ' " $(( ROOTLESS_GIDMAP_START + 10 )) " ' , "containerID": 1, "size": 20}]
80
+ | .linux.gidMappings += [{"hostID": ' " $(( ROOTLESS_GIDMAP_START + 100 )) " ' , "containerID": 1000, "size": ' " $(( ROOTLESS_GIDMAP_LENGTH - 1000 )) " ' }]'
88
81
}
89
82
90
83
# Returns systemd version as a number (-1 if systemd is not enabled/supported).
@@ -131,17 +124,16 @@ function init_cgroup_paths() {
131
124
CGROUP_SUBSYSTEMS=$( awk ' !/^#/ {print $1}' /proc/cgroups)
132
125
local g base_path
133
126
for g in ${CGROUP_SUBSYSTEMS} ; do
134
- base_path=$( gawk ' $(NF-2) == "cgroup" && $NF ~ /\<' ${g} ' \>/ { print $5; exit }' /proc/self/mountinfo)
127
+ base_path=$( gawk ' $(NF-2) == "cgroup" && $NF ~ /\<' " ${g} " ' \>/ { print $5; exit }' /proc/self/mountinfo)
135
128
test -z " $base_path " && continue
136
- eval CGROUP_${g^^} _BASE_PATH=" ${base_path} "
129
+ eval CGROUP_" ${g^^} " _BASE_PATH=" ${base_path} "
137
130
done
138
131
fi
139
132
}
140
133
141
134
# Randomize cgroup path(s), and update cgroupsPath in config.json.
142
135
# This function sets a few cgroup-related variables.
143
136
function set_cgroups_path() {
144
- bundle=" ${1:- .} "
145
137
init_cgroup_paths
146
138
147
139
local rnd=" $RANDOM "
@@ -165,47 +157,47 @@ function set_cgroups_path() {
165
157
CGROUP_PATH=${CGROUP_BASE_PATH}${REL_CGROUPS_PATH}
166
158
fi
167
159
168
- update_config ' .linux.cgroupsPath |= "' " ${OCI_CGROUPS_PATH} " ' "' " $bundle "
160
+ update_config ' .linux.cgroupsPath |= "' " ${OCI_CGROUPS_PATH} " ' "'
169
161
}
170
162
171
163
# Get a value from a cgroup file.
172
164
function get_cgroup_value() {
173
165
local source=$1
174
166
local cgroup var current
175
167
176
- if [ " x $CGROUP_UNIFIED " = " xyes " ]; then
168
+ if [ " $CGROUP_UNIFIED " = " yes " ]; then
177
169
cgroup=$CGROUP_PATH
178
170
else
179
171
var=${source%% .* } # controller name (e.g. memory)
180
172
var=CGROUP_${var^^} _BASE_PATH # variable name (e.g. CGROUP_MEMORY_BASE_PATH)
181
- eval cgroup=\$ ${var}${REL_CGROUPS_PATH}
173
+ eval cgroup=\$ " ${var}${REL_CGROUPS_PATH} "
182
174
fi
183
- cat $cgroup /$source
175
+ cat " $cgroup /$source "
184
176
}
185
177
186
178
# Helper to check a if value in a cgroup file matches the expected one.
187
179
function check_cgroup_value() {
188
180
local current
189
- current=" $( get_cgroup_value $1 ) "
181
+ current=" $( get_cgroup_value " $1 " ) "
190
182
local expected=$2
191
183
192
- echo " current" $current " !? " " $expected "
184
+ echo " current $current !? $expected "
193
185
[ " $current " = " $expected " ]
194
186
}
195
187
196
188
# Helper to check a value in systemd.
197
189
function check_systemd_value() {
198
190
[ -z " ${RUNC_USE_SYSTEMD} " ] && return
199
- local source=$1
191
+ local source=" $1 "
200
192
[ " $source " = " unsupported" ] && return
201
193
local expected=" $2 "
202
194
local expected2=" $3 "
203
195
local user=" "
204
- [ $( id -u) != " 0" ] && user=" --user"
196
+ [ " $( id -u) " != " 0" ] && user=" --user"
205
197
206
- current=$( systemctl show $user --property $source $SD_UNIT_NAME | awk -F= ' {print $2}' )
198
+ current=$( systemctl show $user --property " $source " " $SD_UNIT_NAME " | awk -F= ' {print $2}' )
207
199
echo " systemd $source : current $current !? $expected $expected2 "
208
- [ " $current " = " $expected " ] || [ -n " $expected2 " -a " $current " = " $expected2 " ]
200
+ [ " $current " = " $expected " ] || [[ -n " $expected2 " && " $current " = " $expected2 " ] ]
209
201
}
210
202
211
203
function check_cpu_quota() {
@@ -253,21 +245,18 @@ function check_cpu_shares() {
253
245
function check_cpu_weight() {
254
246
local weight=$1
255
247
256
- check_cgroup_value " cpu.weight" $weight
257
- check_systemd_value " CPUWeight" $weight
248
+ check_cgroup_value " cpu.weight" " $weight "
249
+ check_systemd_value " CPUWeight" " $weight "
258
250
}
259
251
260
252
# Helper function to set a resources limit
261
253
function set_resources_limit() {
262
- bundle=" ${1:- .} "
263
- update_config ' .linux.resources.pids.limit |= 100' $bundle
254
+ update_config ' .linux.resources.pids.limit |= 100'
264
255
}
265
256
266
257
# Helper function to make /sys/fs/cgroup writable
267
258
function set_cgroup_mount_writable() {
268
- bundle=" ${1:- .} "
269
- update_config ' .mounts |= map((select(.type == "cgroup") | .options -= ["ro"]) // .)' \
270
- $bundle
259
+ update_config ' .mounts |= map((select(.type == "cgroup") | .options -= ["ro"]) // .)'
271
260
}
272
261
273
262
# Fails the current test, providing the error given.
@@ -330,7 +319,7 @@ function requires() {
330
319
;;
331
320
cgroups_swap)
332
321
init_cgroup_paths
333
- if [ $CGROUP_UNIFIED = " no" -a ! -e " ${CGROUP_MEMORY_BASE_PATH} /memory.memsw.limit_in_bytes" ]; then
322
+ if [ $CGROUP_UNIFIED = " no" ] && [ ! -e " ${CGROUP_MEMORY_BASE_PATH} /memory.memsw.limit_in_bytes" ]; then
334
323
skip_me=1
335
324
fi
336
325
;;
@@ -359,8 +348,9 @@ function requires() {
359
348
fi
360
349
;;
361
350
smp)
362
- local cpu_count=$( grep -c ' ^processor' /proc/cpuinfo)
363
- if [ " $cpu_count " -lt 2 ]; then
351
+ local cpus
352
+ cpus=$( grep -c ' ^processor' /proc/cpuinfo)
353
+ if [ " $cpus " -lt 2 ]; then
364
354
skip_me=1
365
355
fi
366
356
;;
@@ -397,10 +387,10 @@ function retry() {
397
387
if [[ " $status " -eq 0 ]]; then
398
388
return 0
399
389
fi
400
- sleep $delay
390
+ sleep " $delay "
401
391
done
402
392
403
- echo " Command \" $@ \" failed $attempts times. Output: $output "
393
+ echo " Command \" $* \" failed $attempts times. Output: $output "
404
394
false
405
395
}
406
396
@@ -418,8 +408,8 @@ function wait_for_container() {
418
408
419
409
function testcontainer() {
420
410
# test state of container
421
- runc state $1
422
- if [ $2 == " checkpointed" ]; then
411
+ runc state " $1 "
412
+ if [ " $2 " == " checkpointed" ]; then
423
413
[ " $status " -eq 1 ]
424
414
return
425
415
fi
@@ -431,7 +421,7 @@ function setup_recvtty() {
431
421
[ -z " $ROOT " ] && return 1 # must not be called without ROOT set
432
422
local dir=" $ROOT /tty"
433
423
434
- mkdir $dir
424
+ mkdir " $dir "
435
425
export CONSOLE_SOCKET=" $dir /sock"
436
426
437
427
# We need to start recvtty in the background, so we double fork in the shell.
@@ -444,7 +434,7 @@ function teardown_recvtty() {
444
434
445
435
# When we kill recvtty, the container will also be killed.
446
436
if [ -f " $dir /pid" ]; then
447
- kill -9 $( cat " $dir /pid" )
437
+ kill -9 " $( cat " $dir /pid" ) "
448
438
fi
449
439
450
440
# Clean up the files that might be left over.
@@ -455,11 +445,11 @@ function setup_bundle() {
455
445
local image=" $1 "
456
446
457
447
# Root for various container directories (state, tty, bundle).
458
- export ROOT=$( mktemp -d " $BATS_RUN_TMPDIR /runc.XXXXXX" )
448
+ ROOT=$( mktemp -d " $BATS_RUN_TMPDIR /runc.XXXXXX" )
459
449
mkdir -p " $ROOT /state" " $ROOT /bundle/rootfs"
460
450
461
451
setup_recvtty
462
- cd " $ROOT /bundle"
452
+ cd " $ROOT /bundle" || return
463
453
464
454
tar --exclude ' ./dev/*' -C rootfs -xf " $image "
465
455
@@ -482,7 +472,7 @@ function setup_debian() {
482
472
function teardown_bundle() {
483
473
[ -z " $ROOT " ] && return 0 # nothing to teardown
484
474
485
- cd " $INTEGRATION_ROOT "
475
+ cd " $INTEGRATION_ROOT " || return
486
476
teardown_recvtty
487
477
local ct
488
478
for ct in $( __runc list -q) ; do
0 commit comments