Skip to content

Commit

Permalink
Move test helper binaries
Browse files Browse the repository at this point in the history
Instead of having every test helper binary in its own directory, let's
use /tests/cmd/_bin as a destination directory.

This allows for simpler setup/cleanup.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Dec 3, 2024
1 parent b7da167 commit e072757
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ vendor/pkg
/runc
/runc-*
/contrib/cmd/memfd-bind/memfd-bind
/tests/cmd/recvtty/recvtty
/tests/cmd/sd-helper/sd-helper
/tests/cmd/seccompagent/seccompagent
/tests/cmd/fs-idmap/fs-idmap
/tests/cmd/pidfd-kill/pidfd-kill
/tests/cmd/remap-rootfs/remap-rootfs
/tests/cmd/_bin
man/man8
release
Vagrantfile
Expand Down
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,27 @@ runc-bin:
$(GO_BUILD) -o runc .

.PHONY: all
all: runc memfd-bind recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
all: runc memfd-bind test-helpers

.PHONY: memfd-bind
memfd-bind:
$(GO_BUILD) -o contrib/cmd/$@/$@ ./contrib/cmd/$@

.PHONY: recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs:
$(GO_BUILD) -o tests/cmd/$@/$@ ./tests/cmd/$@
HELPERS_DIR := tests/cmd/_bin
$(HELPERS_DIR):
mkdir $(HELPERS_DIR)

TEST_HELPERS := recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
.PHONY: test-helpers $(TEST_HELPERS)
test-helpers: $(TEST_HELPERS)
$(TEST_HELPERS): $(HELPERS_DIR)
$(GO_BUILD) -o $(HELPERS_DIR) ./tests/cmd/$@

.PHONY: clean
clean:
rm -f runc runc-*
rm -f contrib/cmd/memfd-bind/memfd-bind
rm -f tests/cmd/recvtty/recvtty
rm -f tests/cmd/sd-helper/sd-helper
rm -f tests/cmd/seccompagent/seccompagent
rm -f tests/cmd/fs-idmap/fs-idmap
rm -f tests/cmd/pidfd-kill/pidfd-kill
rm -f tests/cmd/remap-rootfs/remap-rootfs
rm -fr $(HELPERS_DIR)
sudo rm -rf release
rm -rf man/man8

Expand Down
4 changes: 4 additions & 0 deletions tests/cmd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
These are helpers used by [integration tests](/tests/integration).

They are compiled from the top-level Makefile via `make test-helpers`,
and the resulting binaries can be found in ./_bin.
2 changes: 1 addition & 1 deletion tests/cmd/seccompagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ make all

Run the seccomp agent in the background:
```bash
sudo ./tests/cmd/seccompagent/seccompagent &
sudo ./tests/cmd/_bin/seccompagent &
```

Prepare a container:
Expand Down
23 changes: 10 additions & 13 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ eval "$IMAGES"
unset IMAGES

: "${RUNC:="${INTEGRATION_ROOT}/../../runc"}"
RECVTTY="${INTEGRATION_ROOT}/../../tests/cmd/recvtty/recvtty"
SD_HELPER="${INTEGRATION_ROOT}/../../tests/cmd/sd-helper/sd-helper"
SECCOMP_AGENT="${INTEGRATION_ROOT}/../../tests/cmd/seccompagent/seccompagent"
FS_IDMAP="${INTEGRATION_ROOT}/../../tests/cmd/fs-idmap/fs-idmap"
PIDFD_KILL="${INTEGRATION_ROOT}/../../tests/cmd/pidfd-kill/pidfd-kill"
REMAP_ROOTFS="${INTEGRATION_ROOT}/../../tests/cmd/remap-rootfs/remap-rootfs"

# Path to binaries compiled from packages in tests/cmd by "make test-helpers").
CMD=${INTEGRATION_ROOT}/../cmd/_bin

# Some variables may not always be set. Set those to empty value,
# if unset, to avoid "unbound variable" error.
Expand Down Expand Up @@ -143,7 +140,7 @@ function init_cgroup_paths() {
function create_parent() {
if [ -v RUNC_USE_SYSTEMD ]; then
[ ! -v SD_PARENT_NAME ] && return
"$SD_HELPER" --parent machine.slice start "$SD_PARENT_NAME"
"$CMD/sd-helper" --parent machine.slice start "$SD_PARENT_NAME"
else
[ ! -v REL_PARENT_PATH ] && return
if [ -v CGROUP_V2 ]; then
Expand All @@ -163,7 +160,7 @@ function create_parent() {
function remove_parent() {
if [ -v RUNC_USE_SYSTEMD ]; then
[ ! -v SD_PARENT_NAME ] && return
"$SD_HELPER" --parent machine.slice stop "$SD_PARENT_NAME"
"$CMD/sd-helper" --parent machine.slice stop "$SD_PARENT_NAME"
else
[ ! -v REL_PARENT_PATH ] && return
if [ -v CGROUP_V2 ]; then
Expand Down Expand Up @@ -715,7 +712,7 @@ function setup_recvtty() {
export CONSOLE_SOCKET="$dir/sock"

# We need to start recvtty in the background, so we double fork in the shell.
("$RECVTTY" --pid-file "$dir/pid" --mode null "$CONSOLE_SOCKET" &) &
("$CMD/recvtty" --pid-file "$dir/pid" --mode null "$CONSOLE_SOCKET" &) &
}

function teardown_recvtty() {
Expand All @@ -732,7 +729,7 @@ function teardown_recvtty() {
}

function setup_seccompagent() {
("${SECCOMP_AGENT}" -socketfile="$SECCCOMP_AGENT_SOCKET" -pid-file "$BATS_TMPDIR/seccompagent.pid" &) &
("$CMD/seccompagent" -socketfile="$SECCCOMP_AGENT_SOCKET" -pid-file "$BATS_TMPDIR/seccompagent.pid" &) &
}

function teardown_seccompagent() {
Expand Down Expand Up @@ -790,7 +787,7 @@ function teardown_bundle() {
function remap_rootfs() {
[ ! -v ROOT ] && return 0 # nothing to remap

"$REMAP_ROOTFS" "$ROOT/bundle"
"$CMD/remap-rootfs" "$ROOT/bundle"
}

function is_kernel_gte() {
Expand All @@ -812,7 +809,7 @@ function requires_idmap_fs() {

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

case $stderr in
*invalid\ argument)
Expand Down Expand Up @@ -846,7 +843,7 @@ function setup_pidfd_kill() {
mkdir "${dir}"
export PIDFD_SOCKET="${dir}/sock"

("${PIDFD_KILL}" --pid-file "${dir}/pid" --signal "${signal}" "${PIDFD_SOCKET}" &) &
("$CMD/pidfd-kill" --pid-file "${dir}/pid" --signal "${signal}" "${PIDFD_SOCKET}" &) &

# ensure socket is ready
retry 10 1 stat "${PIDFD_SOCKET}"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ EOF
TMP_RECVTTY_PID="$TMP_RECVTTY_DIR/recvtty.pid"
TMP_CONSOLE_SOCKET="$TMP_RECVTTY_DIR/console.sock"
CONTAINER_OUTPUT="$TMP_RECVTTY_DIR/output"
("$RECVTTY" --no-stdin --pid-file "$TMP_RECVTTY_PID" \
("$CMD/recvtty" --no-stdin --pid-file "$TMP_RECVTTY_PID" \
--mode single "$TMP_CONSOLE_SOCKET" &>"$CONTAINER_OUTPUT") &
retry 10 0.1 [ -e "$TMP_CONSOLE_SOCKET" ]

Expand Down

0 comments on commit e072757

Please sign in to comment.