Commit Graph

82 Commits

Author SHA1 Message Date
sean 3805b01e8a ci(checkpoint): workaround to avoid mutate cgroupv2 mount options
add --manage-cgroups-mode ignore to avoid pollute cgroupv2 mount options
during unittest and intergration test
https://github.com/checkpoint-restore/criu/issues/3029

Signed-off-by: sean <xujihui1985@gmail.com>
2026-06-23 18:59:03 +08:00
Kir Kolyshkin 2cd4782b70 tests/int/checkpoint: drop unneeded tests
Those tests were added by commit 8d180e96 ("Add support for Linux
Network Devices"), apparently by copy-pasting the test cases which
call simple_cr (all four of them).

While different simple_cr tests make sense as they cover different
code paths in runc and/or check for various regression, the same
variations with netdevice do not make sense, as having a net device
is orthogonal to e.g. bind mount, --debug, or cgroupns.

Remove those.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-08 11:07:42 -07:00
Kir Kolyshkin 9932ad19be tests/int: introduce the concept of unsafe tests
Some of runc integration tests may do something that I would not like
when running those on my development laptop. Examples include

 - changing the root mount propagation [1];
 - replacing /root/runc [2];
 - changing the file in /etc (see checkpoint.bats).

Yet it is totally fine to do all that in a throwaway CI environment,
or inside a Docker container.

Introduce a mechanism to skip specific "unsafe" tests unless an
environment variable, RUNC_ALLOW_UNSAFE_TESTS, is set. Use it
from a specific checkpoint/restore test which modifies
/etc/criu/default.conf.

[1]: https://github.com/opencontainers/runc/pull/5200
[2]: https://github.com/opencontainers/runc/pull/5207

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-02 20:03:47 -07:00
Kir Kolyshkin ad72eab6c7 tests/int/checkpoint: fix using run twice
In our bats tests, runc itself is a wrapper which calls bats run helper,
so using "run runc" is wrong as it results in calling run helper twice.

Fixes: 8d180e965
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-10-18 15:30:16 -07:00
Kir Kolyshkin 0eb03ef86f tests/int: remove useless/obvious comments
This is a bit opinionated, but some comments in integration tests do not
really help to understand the nature of the tests being performed by
stating something very obvious, like

	# run busybox detached
	runc run -d busybox

To make things worse, these not-so-helpful messages are being
copy/pasted over and over, and that is the main reason to remove them.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-10-18 15:30:16 -07:00
Antonio Ojea 8d180e9658 Add support for Linux Network Devices
Implement support for passing Linux Network Devices to the container
network namespace.

The network device is passed during the creation of the container,
before the process is started.

It implements the logic defined in the OCI runtime specification.

Signed-off-by: Antonio Ojea <aojea@google.com>
2025-06-18 15:52:30 +01:00
Andrei Vagin b68cbdff34 criu: Add time namespace to container config after checkpoint/restore
Since v3.14, CRIU always restores processes into a time namespace to
prevent backward jumps of monotonic and boottime clocks. This change
updates the container configuration to ensure that `runc exec` launches
new processes within the container's time namespace.

Fixes #2610

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2025-03-26 15:12:01 +00:00
lfbzhm 83ea9e5f62 Merge pull request #4251 from kolyshkin/test-cr
tests/int/checkpoint: rm double logging
2024-05-07 23:07:34 +08:00
Kir Kolyshkin f6b7167bc5 tests/int/checkpoint: add requires criu_feature_xxx
1. A few tests use "criu check --feature" to check for a specific
   feature. Let's generalize it.

2. Fix "checkpoint --pre-dump and restore" test to require memory
   tracking (which is missing on ARM).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-04-24 19:40:45 -07:00
Kir Kolyshkin e5c82f00e1 tests/int/checkpoint: rm double logging
Since commit c77aaa3f the tail of criu.log is printed by runc, so
there's no need to do the same thing in tests.

Related to 3711, 3816.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-04-24 17:23:43 -07:00
Kir Kolyshkin 9b71787be0 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 <kolyshkin@gmail.com>
2023-04-05 15:22:23 -07:00
Kir Kolyshkin c4aa452b18 tests/int/checkpoint: fix lazy migration flakiness
When doing a lazy checkpoint/restore, we should not restore into the
same cgroup, otherwise there is a race which result in occasional
killing of the restored container (GH #2760, #2924).

The fix is to use --manage-cgroup-mode=ignore, which allows to restore
into a different cgroup.

Note that since cgroupsPath is not set in config.json, the cgroup is
derived from the container name, so calling set_cgroups_path is not
needed.

For the previous (unsuccessful) attempt to fix this, as well as detailed
(and apparently correct) analysis, see commit 36fe3cc28c.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-12-15 15:37:42 -08:00
Kir Kolyshkin d4582ae2f1 tests/int: add "--manage-cgroups-mode ignore" test
This test checks that the container is restored into a different cgroup.

To do so, a user should
 - use --manage-cgroups-mode ignore on both checkpoint and restore;
 - change the cgroupsPath value in config.json before restoring.

The test does some checks to ensure that its logic is correct, and that
after the restore the old (original) cgroup does not exist, the new one
exists, and the container's init is in that new cgroup.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-12-15 15:37:42 -08:00
Kir Kolyshkin 25ef852ad6 tests/int: use = in test for strings comparison
Strictly speaking, == is for [[ only, not for [ / test,
and, unlike =, the right side is a pattern.

To avoid confusion, use =. In cases where we compare with empty string,
use -z instead.

Keep using [[ in some cases since it does not require quoting the left
and right side of comparison (I trust shellcheck on that one).

This should have no effect (other than the code being a tad more
strict).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-03-23 11:12:44 -07:00
Kir Kolyshkin c8c3e8526d tests: fix checks for non-existent variables
Audit all checks for non-empty variables (i.e. ' -z ', ' -n ',
' != ""' and '= ""'), and fix those cases where a variable might be
unset. Those variables (that might not be set) are

 - RUNC_USE_SYSTEMD
 - BATS_RUN_TMPDIR
 - AUX_UID
 - AUX_DIR
 - SD_PARENT_NAME
 - REL_PARENT_PATH
 - ROOT
 - HAVE_CRIU
 - ROOTLESS_FEATURES
 - and a few test-specific or file-specific variables

This should allow us to enable set -u.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-02-28 18:41:35 -08:00
Kir Kolyshkin 6e1d476aad runc: remove --criu option
This was introduced in an initial commit, back in the day when criu was
a highly experimental thing. Today it's not; most users who need it have
it packaged by their distro vendor.

The usual way to run a binary is to look it up in directories listed in
$PATH. This is flexible enough and allows for multiple scenarios (custom
binaries, extra binaries, etc.). This is the way criu should be run.

Make --criu a hidden option (thus removing it from help). Remove the
option from man pages, integration tests, etc. Remove all traces of
CriuPath from data structures.

Add a warning that --criu is ignored and will be removed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-01-26 20:25:56 -08:00
Liu Hua 74ae9e0fc9 checkpoint: resolve symlink for external bind mount(fix ci broken)
runc resolves symlink before doing bind mount. So
we should save original path while formatting CriuReq for
dump and restore.

"checkpoint: resolve symlink for external bind mount" is merged as
da22625f6986f0ef196eaa1f8bb6adce098f0fb7(PR 2902) previously. And reverted
in commit 70fdc0573dced3464e9c31d674559f77c1de3973(PR 3043) duo to behavior changes
caused by commit 0ca91f44f1664da834bc61115a849b56d22f595f(Fixes: CVE-2021-30465)

Signed-off-by: Liu Hua <weldonliu@tencent.com>
2021-08-19 18:42:42 +08:00
Kir Kolyshkin 70fdc0573d Revert "checkpoint: resolve symlink for external bind mount"
This reverts commit da22625f69
(PR 2902).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-24 20:52:43 -07:00
Mrunal Patel 1079288bef Merge pull request #2902 from liusdu/checkpoint
checkpoint: resolve symlink for external bind mount
2021-06-24 22:52:02 -04:00
Liu Hua da22625f69 checkpoint: resolve symlink for external bind mount
runc resolves symlink before doing bind mount. So
we should save original path while formatting CriuReq for
checkpoint.

Signed-off-by: Liu Hua <weldonliu@tencent.com>
2021-04-25 09:50:00 +08:00
Liu Hua 23e3794d9c checkpoint: validate parent path
`--parent-path` needs to be relative path of `--image-path`,
and points to previous checkpoint directory.

Signed-off-by: Liu Hua <weldonliu@tencent.com>
2021-04-23 13:20:08 +08:00
Liu Hua aa62272382 tiny fix iterative checkpoint test case
Criu creates symlink named "parent" under image-path while doing
interactive checkpoint, without checking wether symlink points to
right place. This patch corrects related test case.

Signed-off-by: Liu Hua <weldonliu@tencent.com>
2021-04-19 20:04:52 +08:00
Akihiro Suda c453f1a523 Merge pull request #2881 from kolyshkin/test-rand-cg
tests/int: some refactoring, fix a flake
2021-04-06 13:27:19 +09:00
Kir Kolyshkin 36fe3cc28c tests/int/cpt: fix lazy-pages flakiness
"checkpoint --lazy-pages and restore" test sometimes fails on restore
in our CI on Fedora 33 when systemd cgroup driver is used:

> (00.076104) Error (compel/src/lib/infect.c:1513): Task 48521 is in unexpected state: f7f
> (00.076122) Error (compel/src/lib/infect.c:1520): Task stopped with 15: Terminated
> ...
> (00.078246) Error (criu/cr-restore.c:2483): Restoring FAILED.

I think what happens is

1. The test runs runc checkpoint in lazy-pages mode in background.
2. The test runs criu lazy-pages in background.
3. The test runs runc restore.

Now, all three are working in together: criu restore restores, criu
lazy-pages listens for page faults on a uffd and fetch missing pages
from runc checkpoint, who serves those pages.

At some point criu lazy-pages decides to fetch the rest of the pages,
and once it's done it exits, and runc checkpoint, as there are no more
pages to serve, exits too.

At the end of runc checkpoint the container is removed (see "defer
destroy(container)" in checkpoint.go. This involves a call to
cgroupManager.Destroy, which, in case systemd manager is used,
calls stopUnit, which makes systemd to not just remove the unit,
but also send SIGTERM to its processes, if there are any.

As the container is being restored into the same systemd unit,
sometimes this results in sending SIGTERM to a process which
criu restores, and thus restoring fails.

The remedy here is to change the name of systemd unit to which the
container is restored.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 12:57:53 -07:00
Kir Kolyshkin 0e0890027c tests/int/checkpoint: close lazy_r fd
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 12:57:32 -07:00
Kir Kolyshkin b09030a5f4 tests/int/checkpoint: close fds in check_pipes
In check_pipes, make sure we
 - close all fds we opened in setup_pipes;
 - check that runc stderr is empty (and fail if it's not).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 12:57:27 -07:00
Kir Kolyshkin bed4d89f57 Merge pull request #2807 from kolyshkin/google-golang-protobuf
go.mod, libct: switch to google.golang.org/protobuf
2021-03-31 20:34:16 -07:00
Kir Kolyshkin 62f1f0e499 tests/int/checkpoint: check all logs for errors
This is to help debug issue #2805.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-28 11:17:23 -07:00
Kir Kolyshkin 346cb35922 Revert "tests/checkpoint: show full log lazy pages cpt"
The full log is very long and it did not gave us any additional clues.

This reverts commit 053e15c001.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-28 10:54:36 -07:00
Akihiro Suda 0ae1475066 Merge pull request #2798 from adrianreber/2021-02-08-nested-bind.mounts
Correctly restore containers with nested bind mounts
2021-03-17 12:47:21 +09:00
Kir Kolyshkin 053e15c001 tests/checkpoint: show full log lazy pages cpt
Sometimes the test fails without any clear diagnostics:

> not ok 16 checkpoint --lazy-pages and restore
> (in test file tests/integration/checkpoint.bats, line 191)
>  `[ "$out" = "0000000 000000 0000001" ]' failed
> ...
> criu failed: type NOTIFY errno 3\nlog file: work-dir/dump.log

We look for and print errors via grep, but in the above case
there are nothing that is denoted error in the log.

So, let's show the damn log in its entirely (note it is only shown
if test fails).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-08 15:04:40 -08:00
Kir Kolyshkin db025aba75 libct: criuSwrk: only iterate over CriuOpts if debug is set
In case log level is less than debug, this code does nothing,
so let's add a condition and skip it entirely.

Add a test case to make sure this code path is hit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-04 08:58:42 -08:00
Adrian Reber 051646a3b0 tests: test nested bind mount restore
This adds a checkpoint/restore test to ensure that nested bind mount
mountpoints are correctly re-created.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-02-10 08:55:57 +01:00
Kir Kolyshkin 41670e21f0 tests/int: rework/simplify setup and teardown
1. Get rid of fixed ROOT, *_BUNDLE, and CONSOLE_SOCKET dirs.
   Now they are temporary directories created in setup_bundle.

2. Automate containers cleanup: instead of having to specify all
   containers to be removed, list and destroy everything (which is
   now possible since every test case has its own unique root).

3. Randomize cgroup paths so two tests running in parallel won't
   use the same cgroup.

Now it's theoretically possible to execute tests in parallel.
Practically it's not possible yet because bats uses GNU parallel,
which do not provide a terminal for whatever it executes, and
many runc tests (all those that run containers with terminal:
true) needs a tty. This may possibly be addressed later.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-09 20:05:54 -08:00
Kir Kolyshkin 2ceb97196e tests/integration: rm excessive run use
Bats' run should only be used when we want to check both the command
output and its non-zero exit status.

Otherwise, we can rely on implicit exit code check (as the tests are
run with set -e), or use if, etc.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-29 16:49:43 -07:00
Kir Kolyshkin fc8c779704 tests/integration/*.bats: reformat with shfmt
Various bats tests use various types of indentation (about half
is tabs, the rest is 2 spaces, 4 spaces, etc.).

Let's bring it to one style (tabs) using recently added
shfmt support for bats files (see [1]).

This commit is brought to you by

	shfmt -ln bats -w tests/integration/*.bats

[1] https://github.com/mvdan/sh/issues/600

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-11 19:15:36 -07:00
Kir Kolyshkin 186a38ba73 tests/int: whitespace cleanup
Fix
 - whitespace at EOL
 - empty lines at EOF

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-21 02:47:23 -07:00
Kir Kolyshkin 908b7076e9 tests/int/*.bats: make sure to delete containers
With some grep|awk help, found a few places where the containers
supposed to be removed in teardown() weren't.

To find container names:

	grep -E '^[[:space:]]*\<_*_*runc\>.*\<(create|run|restore)\>'

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-21 02:47:23 -07:00
Kir Kolyshkin d1d13d9ac3 tests/int/checkpoint: don't hide stderr
For test cases where we used pipes for container's stdin/stdout/stderr,
stderr was redirected to the same pipe as stdout, which practically
means it is lost.

These redirects to fd is needed not because we check that container is
working by writing to its stdin and reading from stdout (see
check_pipes), but also because bats redirects test stdout/stderr to a
file, which makes c/r impossible (as the file is outside of container).
This is why we can't just do something like `2>stderr.log`, and have
to do what is done in this commit.

Introduce and use another pipe for stdout, to be used for both runc run
and runc restore, so it will be shown in case of errors.

Since its handling is somewhat complicated and is used from 4 places
(2 for run, 2 for restore), separate it into a helper functions.

NOTE the code assumes that runc exits with non-zero exit code in case
there is anything that needs to be shown to a user from runc's stderr.

While at it, add error checking to runc run calls.

Hopefully, this will help debug those rare checkpoint failures in CI.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-09 20:40:08 -07:00
Kir Kolyshkin 627074d0f9 tests/int/checkpoint: rm useless code
Commit 417f5ff40 added a code to close fds and kill processes, which
should have helped in an event of test case failure.

In fact, each test case is executed in a subshell, so
 - any variables set there can't reach teardown();
 - all the fds are closed (as the process is gone).

Now, I am not sure about the processes, but the code being removed
has never worked anyway, so it does not make sense to keep it.
Normally, those are waited for. In case of a test case failure,
well, the subsequent cases might fail, too.

Fixes: 417f5ff40d
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-09 20:04:48 -07:00
Kir Kolyshkin bca5f24c99 tests/int/checkpoint.bats: fix showing logs on fail
This fixes the following issue with the test:

	not ok 12 checkpoint --lazy-pages and restore
	# (in test file tests/integration/checkpoint.bats, line 202)
	#   `[ $ret -eq 0 ]' failed
	...
	# grep: ./work-dir/restore.log: No such file or directory

One might think that `--work-path ./image-dir` is a mistake, but it's
not, since `criu lazy-pages -D ./image-dir` creates a socket in
./image-dir, and then `criu restore --lazy-pages` expects a socket in
the workdir.

Fixes: e232a71a3d
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-09 18:24:39 -07:00
Kir Kolyshkin 34b4b106c6 tests/int: alt fix for shellcheck SC2034
Instead of ignoring it, use a throwaway variable _
(yes, just like in Go).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-19 16:50:57 -07:00
Kir Kolyshkin f36fb46bdf tests/int/*bats: ignore SC2016
Ignore the shellcheck warnings like this one:

> In tty.bats line 32:
> 	update_config '(.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]'
>                     ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

While at it, fix some minor whitespace issues in tty.bats.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 598d8b73a5 tests/int/checkpoint.bats: ignore SC2206
Ignore warnings like this:

> In checkpoint.bats line 169:
>   PIDS_TO_KILL=($cpt_pid)
>                 ^------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Since in all the cases we deal with either pids or fds, and they don't
have spaces.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 4ba4baea0e tests/int/*bats: fix shellcheck SC2086, SC2006
Those are pretty simple to allow shellcheck to fix these, so
this commit is courtesy of

> shellcheck -i SC2086 -i SC2006 -f diff *.bats > fix.diff
> patch -p1 < fix.diff

repeated 3 times ;)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin b02ca2dc9c tests/int: fix shellcheck warning SC2002
Fix all warnings like this one:

> In checkpoint.bats line 197:
>   cat ./work-dir/restore.log | grep -B 5 Error || true
>       ^--------------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 4b8ff6a17c tests/int/checkpoint.bats: ignore some shellcheck warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 5026bfab9c tests/int: fix error handling and logging
TL;DR: this allows to show logs from failed runc restore.

Bats scripts are run with `set -e`. This is well known and obvious,
and yet there are a few errors with respect to that, including a few
"gems" by yours truly.

1. bats scripts are run with `set -e`, meaning that `[ $? -eq 0 ]` is
   useless since the execution won't ever reach this line in case of
   non-zero exit code from a preceding command. So, remove all such
   checks, they are useless and misleading.

2. bats scripts are run with `set -e`, meaning that `ret=$?` is useless
   since the execution won't ever reach this line in case of non-zero
   exit code from a preceding command.

In particular, the code that calls runc restore needs to save the exit
code, show the errors in the log, and only when check the exit code and
fail if it's non-zero. It can not use `run` (or `runc` which uses `run`)
because of shell redirection that we need to set up.

The solution, implemented in this patch, is to use code like this:

```bash
ret=0
__runc ... || ret=$?
show_logs
[ $ret -eq 0 ]
```

In case __runc exits with non-zero exit code, `ret=$?` is executed, and
it always succeeds, so we won't fail just yet and have a chance to show
logs before checking the value of $ret.

In case __runc succeeds, `ret=$?` is never executed, so $ret will still
be zero (this is the reason why it needs to be set explicitly).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-08 20:33:04 -07:00
Aleksa Sarai f8749ba098 merge branch 'pr-2509'
Kir Kolyshkin (2):
  tests/int/checkpoint: fds and pids cleanup
  tests/int/checkpoint: don't remove readonly flag

LGTMs: @mrunalp @AkihiroSuda @cyphar
Closes #2509
2020-07-20 13:03:38 +10:00
Kir Kolyshkin 6d5125f8b4 tests/int/checkpoint: don't remove readonly flag
This should not longer be necessary (in theory, at least),
let's see how it goes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-07-08 12:56:25 -07:00