Skip to content

Commit 2e13089

Browse files
author
Zhou Hao
authored
Merge pull request #658 from kinvolk/alban/inceptiontap
Fix TAP output with multiple RuntimeInsideValidate
2 parents 699dbce + 069db1a commit 2e13089

File tree

20 files changed

+130
-47
lines changed

20 files changed

+130
-47
lines changed

docs/devel_guidelines.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,52 @@ Each validation test has a `.go` file in the `validation/` directory and can be
77
### TAP output
88

99
Each validation test prints TAP output.
10-
So far, we have two kinds of validation tests and they print the TAP output differently:
11-
* tests using `util.RuntimeInsideValidate`: they start the process `runtimetest` inside the container and `runtimetest` prints the TAP output. The test process itself must not output anything to avoid mixing its output with the TAP output. Each test can only call `util.RuntimeInsideValidate` one time because several TAP outputs cannot be concatenated.
12-
* tests using `util.RuntimeOutsideValidate`: they create a container but without executing `runtimetest`. The test program itself must print the TAP output.
10+
So far, we have three kinds of validation tests and they print the TAP output differently:
11+
12+
#### Using `util.RuntimeOutsideValidate`
13+
14+
They create a container but without executing `runtimetest`. The test program itself must print the TAP output.
15+
16+
Example:
17+
```go
18+
err = util.RuntimeOutsideValidate(g, t, func(config *rspec.Spec, t *tap.T, state *rspec.State) error {
19+
err := testFoo()
20+
t.Ok((err == nil), "check foo")
21+
if err != nil {
22+
t.Diagnostic(err.Error())
23+
return nil
24+
}
25+
return nil
26+
})
27+
28+
```
29+
#### Using `util.RuntimeInsideValidate` and passthrough
30+
31+
They start the process `runtimetest` inside the container and `runtimetest` prints the TAP output.
32+
The test process itself must not output anything to avoid mixing its output with the TAP output.
33+
Each test can only call `util.RuntimeInsideValidate` one time because several TAP outputs cannot be concatenated.
34+
35+
Example:
36+
```go
37+
err = util.RuntimeInsideValidate(g, nil, nil)
38+
if err != nil {
39+
util.Fatal(err)
40+
}
41+
```
42+
43+
#### Using `util.RuntimeInsideValidate` and encapsulation
44+
45+
Similar to the passthrough variant but the test consumes the output from `runtimetest` and re-emit a single TAP result for the container run.
46+
For that, the TAP object must be passed as parameter to `util.RuntimeInsideValidate`.
47+
48+
Example:
49+
```go
50+
g.AddAnnotation("TestName", "check foo")
51+
err = util.RuntimeInsideValidate(g, t, nil)
52+
if err != nil {
53+
util.Fatal(err)
54+
}
55+
```
1356

1457
### Exit status
1558

validation/default/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func main() {
99
if err != nil {
1010
util.Fatal(err)
1111
}
12-
err = util.RuntimeInsideValidate(g, nil)
12+
err = util.RuntimeInsideValidate(g, nil, nil)
1313
if err != nil {
1414
util.Fatal(err)
1515
}

validation/hostname/hostname.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ func testHostname(t *tap.T, hostname string) error {
1515
}
1616

1717
g.SetHostname(hostname)
18-
err = util.RuntimeInsideValidate(g, nil)
18+
g.AddAnnotation("TestName", fmt.Sprintf("check hostname %q", hostname))
19+
err = util.RuntimeInsideValidate(g, t, nil)
1920
t.Ok(err == nil, "hostname is set correctly")
2021
if err != nil {
2122
t.Diagnosticf("expect: err == nil, actual: err != nil")

validation/linux_devices/linux_devices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func main() {
5151
pdev.FileMode = &pmode
5252
g.AddDevice(pdev)
5353

54-
err = util.RuntimeInsideValidate(g, nil)
54+
err = util.RuntimeInsideValidate(g, nil, nil)
5555
if err != nil {
5656
util.Fatal(err)
5757
}

validation/linux_masked_paths/linux_masked_paths.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"os"
77
"path/filepath"
88

9+
"github.com/mndrix/tap-go"
910
"github.com/opencontainers/runtime-tools/validation/util"
1011
"golang.org/x/sys/unix"
1112
)
1213

13-
func checkMaskedPaths() error {
14+
func checkMaskedPaths(t *tap.T) error {
1415
g, err := util.GetDefaultGenerator()
1516
if err != nil {
1617
return err
@@ -32,7 +33,8 @@ func checkMaskedPaths() error {
3233
g.AddLinuxMaskedPaths(maskedDirSub)
3334
g.AddLinuxMaskedPaths(maskedFileSub)
3435
g.AddLinuxMaskedPaths(maskedFileSubSub)
35-
err = util.RuntimeInsideValidate(g, func(path string) error {
36+
g.AddAnnotation("TestName", "check masked paths")
37+
err = util.RuntimeInsideValidate(g, t, func(path string) error {
3638
testDir := filepath.Join(path, maskedDirSub)
3739
err = os.MkdirAll(testDir, 0777)
3840
if err != nil {
@@ -63,7 +65,7 @@ func checkMaskedPaths() error {
6365
return err
6466
}
6567

66-
func checkMaskedRelPaths() error {
68+
func checkMaskedRelPaths(t *tap.T) error {
6769
g, err := util.GetDefaultGenerator()
6870
if err != nil {
6971
return err
@@ -73,7 +75,8 @@ func checkMaskedRelPaths() error {
7375
maskedRelPath := "masked-relpath"
7476

7577
g.AddLinuxMaskedPaths(maskedRelPath)
76-
err = util.RuntimeInsideValidate(g, func(path string) error {
78+
g.AddAnnotation("TestName", "check masked relative paths")
79+
err = util.RuntimeInsideValidate(g, t, func(path string) error {
7780
testFile := filepath.Join(path, maskedRelPath)
7881
if _, err := os.Stat(testFile); err != nil && os.IsNotExist(err) {
7982
return err
@@ -87,7 +90,7 @@ func checkMaskedRelPaths() error {
8790
return fmt.Errorf("expected: err != nil, actual: err == nil")
8891
}
8992

90-
func checkMaskedSymlinks() error {
93+
func checkMaskedSymlinks(t *tap.T) error {
9194
g, err := util.GetDefaultGenerator()
9295
if err != nil {
9396
return err
@@ -98,7 +101,8 @@ func checkMaskedSymlinks() error {
98101
maskedSymlink := "/masked-symlink"
99102

100103
g.AddLinuxMaskedPaths(maskedSymlink)
101-
err = util.RuntimeInsideValidate(g, func(path string) error {
104+
g.AddAnnotation("TestName", "check masked symlinks")
105+
err = util.RuntimeInsideValidate(g, t, func(path string) error {
102106
testFile := filepath.Join(path, maskedSymlink)
103107
// ln -s .. /masked-symlink ; readlink -f /masked-symlink; ls -L /masked-symlink
104108
if err := os.Symlink("../masked-symlink", testFile); err != nil {
@@ -121,7 +125,7 @@ func checkMaskedSymlinks() error {
121125
return fmt.Errorf("expected: err != nil, actual: err == nil")
122126
}
123127

124-
func checkMaskedDeviceNodes(mode uint32) error {
128+
func checkMaskedDeviceNodes(t *tap.T, mode uint32) error {
125129
g, err := util.GetDefaultGenerator()
126130
if err != nil {
127131
return err
@@ -130,7 +134,8 @@ func checkMaskedDeviceNodes(mode uint32) error {
130134
maskedDevice := "/masked-device"
131135

132136
g.AddLinuxMaskedPaths(maskedDevice)
133-
return util.RuntimeInsideValidate(g, func(path string) error {
137+
g.AddAnnotation("TestName", "check masked device nodes")
138+
return util.RuntimeInsideValidate(g, t, func(path string) error {
134139
testFile := filepath.Join(path, maskedDevice)
135140

136141
if err := unix.Mknod(testFile, mode, 0); err != nil {
@@ -146,15 +151,19 @@ func checkMaskedDeviceNodes(mode uint32) error {
146151
}
147152

148153
func main() {
149-
if err := checkMaskedPaths(); err != nil {
154+
t := tap.New()
155+
t.Header(0)
156+
defer t.AutoPlan()
157+
158+
if err := checkMaskedPaths(t); err != nil {
150159
util.Fatal(err)
151160
}
152161

153-
if err := checkMaskedRelPaths(); err != nil {
162+
if err := checkMaskedRelPaths(t); err != nil {
154163
util.Fatal(err)
155164
}
156165

157-
if err := checkMaskedSymlinks(); err != nil {
166+
if err := checkMaskedSymlinks(t); err != nil {
158167
util.Fatal(err)
159168
}
160169

@@ -167,7 +176,7 @@ func main() {
167176
}
168177

169178
for _, m := range modes {
170-
if err := checkMaskedDeviceNodes(m); err != nil {
179+
if err := checkMaskedDeviceNodes(t, m); err != nil {
171180
util.Fatal(err)
172181
}
173182
}

validation/linux_readonly_paths/linux_readonly_paths.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"os"
77
"path/filepath"
88

9+
"github.com/mndrix/tap-go"
910
"github.com/opencontainers/runtime-tools/validation/util"
1011
"golang.org/x/sys/unix"
1112
)
1213

13-
func checkReadonlyPaths() error {
14+
func checkReadonlyPaths(t *tap.T) error {
1415
g, err := util.GetDefaultGenerator()
1516
if err != nil {
1617
return err
@@ -32,7 +33,8 @@ func checkReadonlyPaths() error {
3233
g.AddLinuxReadonlyPaths(readonlyDirSub)
3334
g.AddLinuxReadonlyPaths(readonlyFileSub)
3435
g.AddLinuxReadonlyPaths(readonlyFileSubSub)
35-
err = util.RuntimeInsideValidate(g, func(path string) error {
36+
g.AddAnnotation("TestName", "check read-only paths")
37+
err = util.RuntimeInsideValidate(g, t, func(path string) error {
3638
testDir := filepath.Join(path, readonlyDirSub)
3739
err = os.MkdirAll(testDir, 0777)
3840
if err != nil {
@@ -63,7 +65,7 @@ func checkReadonlyPaths() error {
6365
return err
6466
}
6567

66-
func checkReadonlyRelPaths() error {
68+
func checkReadonlyRelPaths(t *tap.T) error {
6769
g, err := util.GetDefaultGenerator()
6870
if err != nil {
6971
return err
@@ -73,7 +75,8 @@ func checkReadonlyRelPaths() error {
7375
readonlyRelPath := "readonly-relpath"
7476

7577
g.AddLinuxReadonlyPaths(readonlyRelPath)
76-
err = util.RuntimeInsideValidate(g, func(path string) error {
78+
g.AddAnnotation("TestName", "check read-only relative paths")
79+
err = util.RuntimeInsideValidate(g, t, func(path string) error {
7780
testFile := filepath.Join(path, readonlyRelPath)
7881
if _, err := os.Stat(testFile); err != nil && os.IsNotExist(err) {
7982
return err
@@ -87,7 +90,7 @@ func checkReadonlyRelPaths() error {
8790
return fmt.Errorf("expected: err != nil, actual: err == nil")
8891
}
8992

90-
func checkReadonlySymlinks() error {
93+
func checkReadonlySymlinks(t *tap.T) error {
9194
g, err := util.GetDefaultGenerator()
9295
if err != nil {
9396
return err
@@ -98,7 +101,8 @@ func checkReadonlySymlinks() error {
98101
readonlySymlink := "/readonly-symlink"
99102

100103
g.AddLinuxReadonlyPaths(readonlySymlink)
101-
err = util.RuntimeInsideValidate(g, func(path string) error {
104+
g.AddAnnotation("TestName", "check read-only symlinks")
105+
err = util.RuntimeInsideValidate(g, t, func(path string) error {
102106
testFile := filepath.Join(path, readonlySymlink)
103107
// ln -s .. /readonly-symlink ; readlink -f /readonly-symlink; ls -L /readonly-symlink
104108
if err := os.Symlink("../readonly-symlink", testFile); err != nil {
@@ -121,7 +125,7 @@ func checkReadonlySymlinks() error {
121125
return fmt.Errorf("expected: err != nil, actual: err == nil")
122126
}
123127

124-
func checkReadonlyDeviceNodes(mode uint32) error {
128+
func checkReadonlyDeviceNodes(t *tap.T, mode uint32) error {
125129
g, err := util.GetDefaultGenerator()
126130
if err != nil {
127131
return err
@@ -130,7 +134,8 @@ func checkReadonlyDeviceNodes(mode uint32) error {
130134
readonlyDevice := "/readonly-device"
131135

132136
g.AddLinuxReadonlyPaths(readonlyDevice)
133-
return util.RuntimeInsideValidate(g, func(path string) error {
137+
g.AddAnnotation("TestName", "check read-only device nodes")
138+
return util.RuntimeInsideValidate(g, t, func(path string) error {
134139
testFile := filepath.Join(path, readonlyDevice)
135140

136141
if err := unix.Mknod(testFile, mode, 0); err != nil {
@@ -146,15 +151,19 @@ func checkReadonlyDeviceNodes(mode uint32) error {
146151
}
147152

148153
func main() {
149-
if err := checkReadonlyPaths(); err != nil {
154+
t := tap.New()
155+
t.Header(0)
156+
defer t.AutoPlan()
157+
158+
if err := checkReadonlyPaths(t); err != nil {
150159
util.Fatal(err)
151160
}
152161

153-
if err := checkReadonlyRelPaths(); err != nil {
162+
if err := checkReadonlyRelPaths(t); err != nil {
154163
util.Fatal(err)
155164
}
156165

157-
if err := checkReadonlySymlinks(); err != nil {
166+
if err := checkReadonlySymlinks(t); err != nil {
158167
util.Fatal(err)
159168
}
160169

@@ -167,7 +176,7 @@ func main() {
167176
}
168177

169178
for _, m := range modes {
170-
if err := checkReadonlyDeviceNodes(m); err != nil {
179+
if err := checkReadonlyDeviceNodes(t, m); err != nil {
171180
util.Fatal(err)
172181
}
173182
}

validation/linux_rootfs_propagation/linux_rootfs_propagation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"github.com/opencontainers/runtime-tools/validation/util"
66
)
77

8-
func testLinuxRootPropagation(propMode string) error {
8+
func testLinuxRootPropagation(t *tap.T, propMode string) error {
99
g, err := util.GetDefaultGenerator()
1010
if err != nil {
1111
util.Fatal(err)
1212
}
1313
g.SetupPrivileged(true)
1414
g.SetLinuxRootPropagation(propMode)
15-
return util.RuntimeInsideValidate(g, nil)
15+
g.AddAnnotation("TestName", "check root propagation")
16+
return util.RuntimeInsideValidate(g, t, nil)
1617
}
1718

1819
func main() {
@@ -28,7 +29,7 @@ func main() {
2829
}
2930

3031
for _, c := range cases {
31-
if err := testLinuxRootPropagation(c); err != nil {
32+
if err := testLinuxRootPropagation(t, c); err != nil {
3233
t.Fail(err.Error())
3334
}
3435
}

validation/linux_seccomp/linux_seccomp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
}
1717
g.SetDefaultSeccompAction("allow")
1818
g.SetSyscallAction(syscallArgs)
19-
err = util.RuntimeInsideValidate(g, nil)
19+
err = util.RuntimeInsideValidate(g, nil, nil)
2020
if err != nil {
2121
util.Fatal(err)
2222
}

validation/linux_sysctl/linux_sysctl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func main() {
1010
util.Fatal(err)
1111
}
1212
g.AddLinuxSysctl("net.ipv4.ip_forward", "1")
13-
err = util.RuntimeInsideValidate(g, nil)
13+
err = util.RuntimeInsideValidate(g, nil, nil)
1414
if err != nil {
1515
util.Fatal(err)
1616
}

validation/linux_uid_mappings/linux_uid_mappings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func main() {
1212
g.AddOrReplaceLinuxNamespace("user", "")
1313
g.AddLinuxUIDMapping(uint32(1000), uint32(0), uint32(2000))
1414
g.AddLinuxGIDMapping(uint32(1000), uint32(0), uint32(3000))
15-
err = util.RuntimeInsideValidate(g, nil)
15+
err = util.RuntimeInsideValidate(g, nil, nil)
1616
if err != nil {
1717
util.Fatal(err)
1818
}

0 commit comments

Comments
 (0)