Skip to content

Commit

Permalink
tests/int: fix some checks
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kolyshkin committed Apr 5, 2023
1 parent 50aff8a commit 026c60e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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]}")")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 026c60e

Please sign in to comment.