Skip to content

Commit 492dc55

Browse files
authored
Merge pull request #4276 from kolyshkin/arm-cpt-test-fixes
fix checkpoint/restore tests on actuated-arm64
2 parents 3d07cbc + 36be6d0 commit 492dc55

File tree

2 files changed

+31
-65
lines changed

2 files changed

+31
-65
lines changed

libcontainer/criu_linux.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,21 @@ var criuFeatures *criurpc.CriuFeatures
3030

3131
var ErrCriuMissingFeatures = errors.New("criu is missing features")
3232

33-
func (c *Container) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc.CriuOpts, criuFeat *criurpc.CriuFeatures) error {
33+
func (c *Container) checkCriuFeatures(criuOpts *CriuOpts, criuFeat *criurpc.CriuFeatures) error {
3434
t := criurpc.CriuReqType_FEATURE_CHECK
3535

3636
// make sure the features we are looking for are really not from
3737
// some previous check
3838
criuFeatures = nil
3939

4040
req := &criurpc.CriuReq{
41-
Type: &t,
42-
// Theoretically this should not be necessary but CRIU
43-
// segfaults if Opts is empty.
44-
// Fixed in CRIU 2.12
45-
Opts: rpcOpts,
41+
Type: &t,
4642
Features: criuFeat,
4743
}
4844

4945
err := c.criuSwrk(nil, req, criuOpts, nil)
5046
if err != nil {
51-
logrus.Debugf("%s", err)
52-
return errors.New("CRIU feature check failed")
47+
return fmt.Errorf("CRIU feature check failed: %w", err)
5348
}
5449

5550
var missingFeatures []string
@@ -398,7 +393,7 @@ func (c *Container) Checkpoint(criuOpts *CriuOpts) error {
398393
MemTrack: proto.Bool(true),
399394
}
400395

401-
if err := c.checkCriuFeatures(criuOpts, &rpcOpts, &feat); err != nil {
396+
if err := c.checkCriuFeatures(criuOpts, &feat); err != nil {
402397
return err
403398
}
404399

@@ -412,7 +407,7 @@ func (c *Container) Checkpoint(criuOpts *CriuOpts) error {
412407
feat := criurpc.CriuFeatures{
413408
LazyPages: proto.Bool(true),
414409
}
415-
if err := c.checkCriuFeatures(criuOpts, &rpcOpts, &feat); err != nil {
410+
if err := c.checkCriuFeatures(criuOpts, &feat); err != nil {
416411
return err
417412
}
418413

libcontainer/integration/checkpoint_test.go

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package integration
22

33
import (
4-
"bufio"
54
"bytes"
6-
"errors"
75
"os"
86
"os/exec"
97
"path/filepath"
@@ -15,38 +13,11 @@ import (
1513
"golang.org/x/sys/unix"
1614
)
1715

18-
func showFile(t *testing.T, fname string) {
19-
t.Helper()
20-
t.Logf("=== %s ===\n", fname)
21-
22-
f, err := os.Open(fname)
23-
if err != nil {
24-
t.Log(err)
25-
return
26-
}
27-
defer f.Close() //nolint: errcheck
28-
29-
scanner := bufio.NewScanner(f)
30-
for scanner.Scan() {
31-
t.Log(scanner.Text())
32-
}
33-
34-
if err := scanner.Err(); err != nil {
35-
t.Log(err)
36-
return
37-
}
38-
39-
t.Logf("=== END ===\n")
16+
func criuFeature(feature string) bool {
17+
return exec.Command("criu", "check", "--feature", feature).Run() == nil
4018
}
4119

4220
func TestUsernsCheckpoint(t *testing.T) {
43-
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
44-
t.Skip("Test requires userns.")
45-
}
46-
cmd := exec.Command("criu", "check", "--feature", "userns")
47-
if err := cmd.Run(); err != nil {
48-
t.Skip("Unable to c/r a container with userns")
49-
}
5021
testCheckpoint(t, true)
5122
}
5223

@@ -69,6 +40,10 @@ func testCheckpoint(t *testing.T, userns bool) {
6940
t.Skip("Test requires criu >= 3.17-4 on CentOS Stream 9.")
7041
}
7142

43+
if userns && !criuFeature("userns") {
44+
t.Skip("Test requires userns")
45+
}
46+
7247
config := newTemplateConfig(t, &tParam{userns: userns})
7348
stateDir := t.TempDir()
7449

@@ -102,46 +77,43 @@ func testCheckpoint(t *testing.T, userns bool) {
10277
ok(t, err)
10378

10479
tmp := t.TempDir()
80+
var parentImage string
81+
82+
// Test pre-dump if mem_dirty_track is available.
83+
if criuFeature("mem_dirty_track") {
84+
parentImage = "../criu-parent"
85+
parentDir := filepath.Join(tmp, "criu-parent")
86+
preDumpOpts := &libcontainer.CriuOpts{
87+
ImagesDirectory: parentDir,
88+
WorkDirectory: parentDir,
89+
PreDump: true,
90+
}
10591

106-
parentDir := filepath.Join(tmp, "criu-parent")
107-
preDumpOpts := &libcontainer.CriuOpts{
108-
ImagesDirectory: parentDir,
109-
WorkDirectory: parentDir,
110-
PreDump: true,
111-
}
112-
preDumpLog := filepath.Join(preDumpOpts.WorkDirectory, "dump.log")
113-
114-
if err := container.Checkpoint(preDumpOpts); err != nil {
115-
showFile(t, preDumpLog)
116-
if errors.Is(err, libcontainer.ErrCriuMissingFeatures) {
117-
t.Skip(err)
92+
if err := container.Checkpoint(preDumpOpts); err != nil {
93+
t.Fatal(err)
11894
}
119-
t.Fatal(err)
120-
}
12195

122-
state, err := container.Status()
123-
ok(t, err)
96+
state, err := container.Status()
97+
ok(t, err)
12498

125-
if state != libcontainer.Running {
126-
t.Fatal("Unexpected preDump state: ", state)
99+
if state != libcontainer.Running {
100+
t.Fatal("Unexpected preDump state: ", state)
101+
}
127102
}
128103

129104
imagesDir := filepath.Join(tmp, "criu")
130105

131106
checkpointOpts := &libcontainer.CriuOpts{
132107
ImagesDirectory: imagesDir,
133108
WorkDirectory: imagesDir,
134-
ParentImage: "../criu-parent",
109+
ParentImage: parentImage,
135110
}
136-
dumpLog := filepath.Join(checkpointOpts.WorkDirectory, "dump.log")
137-
restoreLog := filepath.Join(checkpointOpts.WorkDirectory, "restore.log")
138111

139112
if err := container.Checkpoint(checkpointOpts); err != nil {
140-
showFile(t, dumpLog)
141113
t.Fatal(err)
142114
}
143115

144-
state, err = container.Status()
116+
state, err := container.Status()
145117
ok(t, err)
146118

147119
if state != libcontainer.Stopped {
@@ -171,7 +143,6 @@ func testCheckpoint(t *testing.T, userns bool) {
171143
_ = restoreStdinR.Close()
172144
defer restoreStdinW.Close() //nolint: errcheck
173145
if err != nil {
174-
showFile(t, restoreLog)
175146
t.Fatal(err)
176147
}
177148

0 commit comments

Comments
 (0)