diff --git a/libcontainer/integration/checkpoint_test.go b/libcontainer/integration/checkpoint_test.go index 6c3ddf63bd9..c509a335e9b 100644 --- a/libcontainer/integration/checkpoint_test.go +++ b/libcontainer/integration/checkpoint_test.go @@ -14,11 +14,11 @@ import ( "golang.org/x/sys/unix" ) +func criuFeature(feature string) bool { + return exec.Command("criu", "check", "--feature", feature).Run() == nil +} + func TestUsernsCheckpoint(t *testing.T) { - cmd := exec.Command("criu", "check", "--feature", "userns") - if err := cmd.Run(); err != nil { - t.Skip("Test requires userns") - } testCheckpoint(t, true) } @@ -41,6 +41,10 @@ func testCheckpoint(t *testing.T, userns bool) { t.Skip("Test requires criu >= 3.17-4 on CentOS Stream 9.") } + if userns && !criuFeature("userns") { + t.Skip("Test requires userns") + } + config := newTemplateConfig(t, &tParam{userns: userns}) stateDir := t.TempDir() @@ -74,26 +78,28 @@ func testCheckpoint(t *testing.T, userns bool) { ok(t, err) tmp := t.TempDir() + var parentImage string + + // Test pre-dump if mem_dirty_track is available. + if criuFeature("mem_dirty_track") { + parentImage = "../criu-parent" + parentDir := filepath.Join(tmp, "criu-parent") + preDumpOpts := &libcontainer.CriuOpts{ + ImagesDirectory: parentDir, + WorkDirectory: parentDir, + PreDump: true, + } - parentDir := filepath.Join(tmp, "criu-parent") - preDumpOpts := &libcontainer.CriuOpts{ - ImagesDirectory: parentDir, - WorkDirectory: parentDir, - PreDump: true, - } - - if err := container.Checkpoint(preDumpOpts); err != nil { - if errors.Is(err, libcontainer.ErrCriuMissingFeatures) { - t.Skip(err) + if err := container.Checkpoint(preDumpOpts); err != nil { + t.Fatal(err) } - t.Fatal(err) - } - state, err := container.Status() - ok(t, err) + state, err := container.Status() + ok(t, err) - if state != libcontainer.Running { - t.Fatal("Unexpected preDump state: ", state) + if state != libcontainer.Running { + t.Fatal("Unexpected preDump state: ", state) + } } imagesDir := filepath.Join(tmp, "criu") @@ -101,14 +107,14 @@ func testCheckpoint(t *testing.T, userns bool) { checkpointOpts := &libcontainer.CriuOpts{ ImagesDirectory: imagesDir, WorkDirectory: imagesDir, - ParentImage: "../criu-parent", + ParentImage: parentImage, } if err := container.Checkpoint(checkpointOpts); err != nil { t.Fatal(err) } - state, err = container.Status() + state, err := container.Status() ok(t, err) if state != libcontainer.Stopped {