From 9b71787be0ca628956d0ade3cd059a8ea03e4b64 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 5 Apr 2023 15:15:07 -0700 Subject: [PATCH] tests/int: fix some checks Apparently, bash with set -e deliberately ignores non-zero return codes from ! cmd, unless this is the last command. The workaround is to either use "! cmd || false', "or run ! cmd". Choose the latter, and require bash-core 1.5.0 (since this is when "run !" was added), replacing the older check. Alas I only learned this recently from the bash-core documentation. Signed-off-by: Kir Kolyshkin --- tests/integration/checkpoint.bats | 8 ++++---- tests/integration/exec.bats | 4 ++-- tests/integration/helpers.bash | 8 ++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 0a8e58a2c..de3647b23 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -355,7 +355,7 @@ function simple_cr() { runc checkpoint --work-path ./work-dir test_busybox grep -B 5 Error ./work-dir/dump.log || true [ "$status" -eq 0 ] - ! test -f ./work-dir/"$tmplog1" + run ! test -f ./work-dir/"$tmplog1" test -f ./work-dir/"$tmplog2" # after checkpoint busybox is no longer running @@ -366,7 +366,7 @@ function simple_cr() { runc restore -d --work-path ./work-dir --console-socket "$CONSOLE_SOCKET" test_busybox grep -B 5 Error ./work-dir/restore.log || true [ "$status" -eq 0 ] - ! test -f ./work-dir/"$tmplog1" + run ! test -f ./work-dir/"$tmplog1" test -f ./work-dir/"$tmplog2" # busybox should be back up and running @@ -434,7 +434,7 @@ function simple_cr() { [ "$status" -eq 0 ] testcontainer test_busybox checkpointed # Check that the cgroup is gone. - ! test -d "$orig_path" + run ! test -d "$orig_path" # Restore into a different cgroup. set_cgroups_path # Changes the path. @@ -445,7 +445,7 @@ function simple_cr() { testcontainer test_busybox running # Check that the old cgroup path doesn't exist. - ! test -d "$orig_path" + run ! test -d "$orig_path" # Check that the new path exists. local new_path diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 3bcd46629..069214cc9 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -234,12 +234,12 @@ function check_exec_debug() { # Check we can join top-level cgroup (implicit). runc exec test_busybox cat /proc/self/cgroup [ "$status" -eq 0 ] - ! grep -v ":$REL_CGROUPS_PATH\$" <<<"$output" + run ! grep -v ":$REL_CGROUPS_PATH\$" <<<"$output" # Check we can join top-level cgroup (explicit). runc exec --cgroup / test_busybox cat /proc/self/cgroup [ "$status" -eq 0 ] - ! grep -v ":$REL_CGROUPS_PATH\$" <<<"$output" + run ! grep -v ":$REL_CGROUPS_PATH\$" <<<"$output" # Create a few subcgroups. # Note that cpu,cpuacct may be mounted together or separate. diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 9f3890a8c..ee2e9c9e0 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -2,11 +2,7 @@ set -u -# bats-core v1.2.1 defines BATS_RUN_TMPDIR. -if [ ! -v BATS_RUN_TMPDIR ]; then - echo "bats >= v1.2.1 is required. Aborting." >&2 - exit 1 -fi +bats_require_minimum_version 1.5.0 # Root directory of integration tests. INTEGRATION_ROOT=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") @@ -357,7 +353,7 @@ function have_criu() { # Workaround for https://github.com/opencontainers/runc/issues/3532. local ver ver=$(rpm -q criu 2>/dev/null || true) - ! grep -q '^criu-3\.17-[123]\.el9' <<<"$ver" + run ! grep -q '^criu-3\.17-[123]\.el9' <<<"$ver" } # Allows a test to specify what things it requires. If the environment can't