Skip to content

Commit 986451c

Browse files
authored
Merge pull request opencontainers#4383 from kolyshkin/test-cmd
Move test helper binaries
2 parents 4cb480d + 66fe7db commit 986451c

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ vendor/pkg
22
/runc
33
/runc-*
44
/contrib/cmd/memfd-bind/memfd-bind
5-
/tests/cmd/recvtty/recvtty
6-
/tests/cmd/sd-helper/sd-helper
7-
/tests/cmd/seccompagent/seccompagent
8-
/tests/cmd/fs-idmap/fs-idmap
9-
/tests/cmd/pidfd-kill/pidfd-kill
10-
/tests/cmd/remap-rootfs/remap-rootfs
5+
/tests/cmd/_bin
116
man/man8
127
release
138
Vagrantfile

Makefile

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,27 @@ runc-bin:
7777
$(GO_BUILD) -o runc .
7878

7979
.PHONY: all
80-
all: runc memfd-bind recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
80+
all: runc memfd-bind
8181

8282
.PHONY: memfd-bind
8383
memfd-bind:
8484
$(GO_BUILD) -o contrib/cmd/$@/$@ ./contrib/cmd/$@
8585

86-
.PHONY: recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
87-
recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs:
88-
$(GO_BUILD) -o tests/cmd/$@/$@ ./tests/cmd/$@
86+
TESTBINDIR := tests/cmd/_bin
87+
$(TESTBINDIR):
88+
mkdir $(TESTBINDIR)
89+
90+
TESTBINS := recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
91+
.PHONY: test-binaries $(TESTBINS)
92+
test-binaries: $(TESTBINS)
93+
$(TESTBINS): $(TESTBINDIR)
94+
$(GO_BUILD) -o $(TESTBINDIR) ./tests/cmd/$@
8995

9096
.PHONY: clean
9197
clean:
9298
rm -f runc runc-*
9399
rm -f contrib/cmd/memfd-bind/memfd-bind
94-
rm -f tests/cmd/recvtty/recvtty
95-
rm -f tests/cmd/sd-helper/sd-helper
96-
rm -f tests/cmd/seccompagent/seccompagent
97-
rm -f tests/cmd/fs-idmap/fs-idmap
98-
rm -f tests/cmd/pidfd-kill/pidfd-kill
99-
rm -f tests/cmd/remap-rootfs/remap-rootfs
100+
rm -fr $(TESTBINDIR)
100101
sudo rm -rf release
101102
rm -rf man/man8
102103

@@ -128,7 +129,7 @@ dbuild: runcimage
128129
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
129130
--privileged --rm \
130131
-v $(CURDIR):/go/src/$(PROJECT) \
131-
$(RUNC_IMAGE) make clean all
132+
$(RUNC_IMAGE) make clean runc test-binaries
132133

133134
.PHONY: lint
134135
lint:
@@ -157,7 +158,7 @@ unittest: runcimage
157158
$(RUNC_IMAGE) make localunittest TESTFLAGS="$(TESTFLAGS)"
158159

159160
.PHONY: localunittest
160-
localunittest: all
161+
localunittest: test-binaries
161162
$(GO) test -timeout 3m -tags "$(BUILDTAGS)" $(TESTFLAGS) -v ./...
162163

163164
.PHONY: integration
@@ -169,7 +170,7 @@ integration: runcimage
169170
$(RUNC_IMAGE) make localintegration TESTPATH="$(TESTPATH)"
170171

171172
.PHONY: localintegration
172-
localintegration: all
173+
localintegration: runc test-binaries
173174
bats -t tests/integration$(TESTPATH)
174175

175176
.PHONY: rootlessintegration
@@ -181,7 +182,7 @@ rootlessintegration: runcimage
181182
$(RUNC_IMAGE) make localrootlessintegration
182183

183184
.PHONY: localrootlessintegration
184-
localrootlessintegration: all
185+
localrootlessintegration: runc test-binaries
185186
tests/rootless.sh
186187

187188
.PHONY: shell

tests/cmd/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
These are helpers used by [integration tests](/tests/integration).
2+
3+
They are compiled from the top-level Makefile via `make test-binaries`,
4+
and the resulting binaries can be found in `./_bin`.

tests/cmd/seccompagent/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ behaviour can break the integration tests.
1212

1313
Compile runc and seccompagent:
1414
```bash
15-
make all
15+
make runc seccompagent
1616
```
1717

1818
Run the seccomp agent in the background:
1919
```bash
20-
sudo ./tests/cmd/seccompagent/seccompagent &
20+
sudo ./tests/cmd/_bin/seccompagent &
2121
```
2222

2323
Prepare a container:

tests/integration/helpers.bash

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ eval "$IMAGES"
1313
unset IMAGES
1414

1515
: "${RUNC:="${INTEGRATION_ROOT}/../../runc"}"
16-
RECVTTY="${INTEGRATION_ROOT}/../../tests/cmd/recvtty/recvtty"
17-
SD_HELPER="${INTEGRATION_ROOT}/../../tests/cmd/sd-helper/sd-helper"
18-
SECCOMP_AGENT="${INTEGRATION_ROOT}/../../tests/cmd/seccompagent/seccompagent"
19-
FS_IDMAP="${INTEGRATION_ROOT}/../../tests/cmd/fs-idmap/fs-idmap"
20-
PIDFD_KILL="${INTEGRATION_ROOT}/../../tests/cmd/pidfd-kill/pidfd-kill"
21-
REMAP_ROOTFS="${INTEGRATION_ROOT}/../../tests/cmd/remap-rootfs/remap-rootfs"
16+
17+
# Path to binaries compiled from packages in tests/cmd by "make test-binaries").
18+
TESTBINDIR=${INTEGRATION_ROOT}/../cmd/_bin
2219

2320
# Some variables may not always be set. Set those to empty value,
2421
# if unset, to avoid "unbound variable" error.
@@ -143,7 +140,7 @@ function init_cgroup_paths() {
143140
function create_parent() {
144141
if [ -v RUNC_USE_SYSTEMD ]; then
145142
[ ! -v SD_PARENT_NAME ] && return
146-
"$SD_HELPER" --parent machine.slice start "$SD_PARENT_NAME"
143+
"$TESTBINDIR/sd-helper" --parent machine.slice start "$SD_PARENT_NAME"
147144
else
148145
[ ! -v REL_PARENT_PATH ] && return
149146
if [ -v CGROUP_V2 ]; then
@@ -163,7 +160,7 @@ function create_parent() {
163160
function remove_parent() {
164161
if [ -v RUNC_USE_SYSTEMD ]; then
165162
[ ! -v SD_PARENT_NAME ] && return
166-
"$SD_HELPER" --parent machine.slice stop "$SD_PARENT_NAME"
163+
"$TESTBINDIR/sd-helper" --parent machine.slice stop "$SD_PARENT_NAME"
167164
else
168165
[ ! -v REL_PARENT_PATH ] && return
169166
if [ -v CGROUP_V2 ]; then
@@ -715,7 +712,7 @@ function setup_recvtty() {
715712
export CONSOLE_SOCKET="$dir/sock"
716713

717714
# We need to start recvtty in the background, so we double fork in the shell.
718-
("$RECVTTY" --pid-file "$dir/pid" --mode null "$CONSOLE_SOCKET" &) &
715+
("$TESTBINDIR/recvtty" --pid-file "$dir/pid" --mode null "$CONSOLE_SOCKET" &) &
719716
}
720717

721718
function teardown_recvtty() {
@@ -732,7 +729,7 @@ function teardown_recvtty() {
732729
}
733730

734731
function setup_seccompagent() {
735-
("${SECCOMP_AGENT}" -socketfile="$SECCCOMP_AGENT_SOCKET" -pid-file "$BATS_TMPDIR/seccompagent.pid" &) &
732+
("$TESTBINDIR/seccompagent" -socketfile="$SECCCOMP_AGENT_SOCKET" -pid-file "$BATS_TMPDIR/seccompagent.pid" &) &
736733
}
737734

738735
function teardown_seccompagent() {
@@ -790,7 +787,7 @@ function teardown_bundle() {
790787
function remap_rootfs() {
791788
[ ! -v ROOT ] && return 0 # nothing to remap
792789

793-
"$REMAP_ROOTFS" "$ROOT/bundle"
790+
"$TESTBINDIR/remap-rootfs" "$ROOT/bundle"
794791
}
795792

796793
function is_kernel_gte() {
@@ -812,7 +809,7 @@ function requires_idmap_fs() {
812809

813810
# We need to "|| true" it to avoid CI failure as this binary may return with
814811
# something different than 0.
815-
stderr=$($FS_IDMAP "$fs" 2>&1 >/dev/null || true)
812+
stderr=$("$TESTBINDIR/fs-idmap" "$fs" 2>&1 >/dev/null || true)
816813

817814
case $stderr in
818815
*invalid\ argument)
@@ -846,7 +843,7 @@ function setup_pidfd_kill() {
846843
mkdir "${dir}"
847844
export PIDFD_SOCKET="${dir}/sock"
848845

849-
("${PIDFD_KILL}" --pid-file "${dir}/pid" --signal "${signal}" "${PIDFD_SOCKET}" &) &
846+
("$TESTBINDIR/pidfd-kill" --pid-file "${dir}/pid" --signal "${signal}" "${PIDFD_SOCKET}" &) &
850847

851848
# ensure socket is ready
852849
retry 10 1 stat "${PIDFD_SOCKET}"

tests/integration/update.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ EOF
801801
TMP_RECVTTY_PID="$TMP_RECVTTY_DIR/recvtty.pid"
802802
TMP_CONSOLE_SOCKET="$TMP_RECVTTY_DIR/console.sock"
803803
CONTAINER_OUTPUT="$TMP_RECVTTY_DIR/output"
804-
("$RECVTTY" --no-stdin --pid-file "$TMP_RECVTTY_PID" \
804+
("$TESTBINDIR/recvtty" --no-stdin --pid-file "$TMP_RECVTTY_PID" \
805805
--mode single "$TMP_CONSOLE_SOCKET" &>"$CONTAINER_OUTPUT") &
806806
retry 10 0.1 [ -e "$TMP_CONSOLE_SOCKET" ]
807807

0 commit comments

Comments
 (0)