diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 219ae81ed..e1092b4f6 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -1,5 +1,11 @@ #!/bin/bash +# bats-core v1.2.1 defines BATS_RUN_TMPDIR +if [ -z "$BATS_RUN_TMPDIR" ]; then + echo "bats >= v1.2.1 is required. Aborting." >&2 + exit 1 +fi + # Root directory of integration tests. INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")") @@ -15,9 +21,9 @@ RECVTTY="${INTEGRATION_ROOT}/../../contrib/cmd/recvtty/recvtty" TESTDATA="${INTEGRATION_ROOT}/testdata" # Destinations for test containers. -BUSYBOX_BUNDLE="$BATS_TMPDIR/busyboxtest" -HELLO_BUNDLE="$BATS_TMPDIR/hello-world" -DEBIAN_BUNDLE="$BATS_TMPDIR/debiantest" +BUSYBOX_BUNDLE="$BATS_RUN_TMPDIR/busyboxtest" +HELLO_BUNDLE="$BATS_RUN_TMPDIR/hello-world" +DEBIAN_BUNDLE="$BATS_RUN_TMPDIR/debiantest" # CRIU PATH CRIU="$(which criu 2>/dev/null || true)" @@ -29,10 +35,10 @@ KERNEL_MINOR="${KERNEL_VERSION#$KERNEL_MAJOR.}" KERNEL_MINOR="${KERNEL_MINOR%%.*}" # Root state path. -ROOT=$(mktemp -d "$BATS_TMPDIR/runc.XXXXXX") +ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc.XXXXXX") # Path to console socket. -CONSOLE_SOCKET="$BATS_TMPDIR/console.sock" +CONSOLE_SOCKET="$BATS_RUN_TMPDIR/console.sock" # Check if we're in rootless mode. ROOTLESS=$(id -u) @@ -423,17 +429,17 @@ function testcontainer() { function setup_recvtty() { # We need to start recvtty in the background, so we double fork in the shell. - ("$RECVTTY" --pid-file "$BATS_TMPDIR/recvtty.pid" --mode null "$CONSOLE_SOCKET" &) & + ("$RECVTTY" --pid-file "$BATS_RUN_TMPDIR/recvtty.pid" --mode null "$CONSOLE_SOCKET" &) & } function teardown_recvtty() { # When we kill recvtty, the container will also be killed. - if [ -f "$BATS_TMPDIR/recvtty.pid" ]; then - kill -9 $(cat "$BATS_TMPDIR/recvtty.pid") + if [ -f "$BATS_RUN_TMPDIR/recvtty.pid" ]; then + kill -9 $(cat "$BATS_RUN_TMPDIR/recvtty.pid") fi # Clean up the files that might be left over. - rm -f "$BATS_TMPDIR/recvtty.pid" + rm -f "$BATS_RUN_TMPDIR/recvtty.pid" rm -f "$CONSOLE_SOCKET" } diff --git a/tests/integration/list.bats b/tests/integration/list.bats index fc70dd880..1ebb77c1e 100644 --- a/tests/integration/list.bats +++ b/tests/integration/list.bats @@ -6,7 +6,7 @@ function setup() { unset ALT_ROOT teardown setup_busybox - ALT_ROOT=$(mktemp -d "$BATS_TMPDIR/runc-2.XXXXXX") + ALT_ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc-2.XXXXXX") } function teardown() { diff --git a/tests/integration/root.bats b/tests/integration/root.bats index 623bd845e..127e5a9ab 100644 --- a/tests/integration/root.bats +++ b/tests/integration/root.bats @@ -6,7 +6,7 @@ function setup() { unset ALT_ROOT teardown setup_busybox - ALT_ROOT=$(mktemp -d "$BATS_TMPDIR/runc-2.XXXXXX") + ALT_ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc-2.XXXXXX") } function teardown() { diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 013194d1e..dd0adea72 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -3,7 +3,7 @@ load helpers function teardown() { - rm -f "$BATS_TMPDIR"/runc-cgroups-integration-test.json + rm -f "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json teardown_running_container test_update teardown_running_container test_update_rt teardown_busybox @@ -208,7 +208,7 @@ EOF check_systemd_value "TasksMax" 10 # reset to initial test value via json file - cat <"$BATS_TMPDIR"/runc-cgroups-integration-test.json + cat <"$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json { "memory": { "limit": 33554432, @@ -226,7 +226,7 @@ EOF } EOF - runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update + runc update -r "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json test_update [ "$status" -eq 0 ] check_cgroup_value "cpuset.cpus" 0 @@ -297,7 +297,7 @@ EOF check_cpu_quota -1 100000 "infinity" # reset to initial test value via json file - cat <"$BATS_TMPDIR"/runc-cgroups-integration-test.json + cat <"$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json { "cpu": { "shares": 100, @@ -308,7 +308,7 @@ EOF EOF [ "$status" -eq 0 ] - runc update -r "$BATS_TMPDIR"/runc-cgroups-integration-test.json test_update + runc update -r "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json test_update [ "$status" -eq 0 ] check_cpu_quota 500000 1000000 "500ms" check_cpu_shares 100 @@ -573,7 +573,7 @@ EOF update_config '.process.args |= ["sh", "-c", "while true; do echo >/dev/null; done"]' # Set up a temporary console socket and recvtty so we can get the stdio. - TMP_RECVTTY_DIR="$(mktemp -d "$BATS_TMPDIR/runc-tmp-recvtty.XXXXXX")" + TMP_RECVTTY_DIR="$(mktemp -d "$BATS_RUN_TMPDIR/runc-tmp-recvtty.XXXXXX")" TMP_RECVTTY_PID="$TMP_RECVTTY_DIR/recvtty.pid" TMP_CONSOLE_SOCKET="$TMP_RECVTTY_DIR/console.sock" CONTAINER_OUTPUT="$TMP_RECVTTY_DIR/output"