Skip to content

Commit c9b4d66

Browse files
committed
runtimetest: count correctly TAP tests
Don't create a new tap.T in the middle of a test but reuse the existing one instead. Symptoms: ``` $ sudo validation/linux_readonly_paths.t TAP version 13 ok 1 - root filesystem ok 2 - hostname ok 3 - process ok 4 - mounts ok 5 - user ok 6 - rlimits ok 7 - capabilities ok 8 - default symlinks ok 9 - default file system ok 10 - default devices ok 11 - linux devices ok 12 - linux process ok 13 - masked paths ok 14 - oom score adj ok 1 # SKIP syscall action SCMP_ACT_ALLOW ok 2 # SKIP syscall action SCMP_ACT_ALLOW ok 3 # SKIP syscall action SCMP_ACT_ALLOW ok 4 # SKIP syscall action SCMP_ACT_ALLOW ok 5 # SKIP syscall action SCMP_ACT_ALLOW ok 6 # SKIP syscall action SCMP_ACT_ALLOW ok 15 - seccomp ok 16 - read only paths ok 17 - rootfs propagation ok 18 - sysctls ok 19 - uid mappings ok 20 - gid mappings 1..20 ``` After this patch is applied: ``` $ sudo validation/linux_readonly_paths.t TAP version 13 ok 1 - root filesystem ok 2 - hostname ok 3 - process ok 4 - mounts ok 5 - user ok 6 - rlimits ok 7 - capabilities ok 8 - default symlinks ok 9 - default file system ok 10 - default devices ok 11 - linux devices ok 12 - linux process ok 13 - masked paths ok 14 - oom score adj ok 15 # SKIP syscall action SCMP_ACT_ALLOW ok 16 # SKIP syscall action SCMP_ACT_ALLOW ok 17 # SKIP syscall action SCMP_ACT_ALLOW ok 18 # SKIP syscall action SCMP_ACT_ALLOW ok 19 # SKIP syscall action SCMP_ACT_ALLOW ok 20 # SKIP syscall action SCMP_ACT_ALLOW ok 21 - seccomp ok 22 - read only paths ok 23 - rootfs propagation ok 24 - sysctls ok 25 - uid mappings ok 26 - gid mappings 1..26 ``` Fixes #593 Signed-off-by: Alban Crequy <[email protected]>
1 parent cb96426 commit c9b4d66

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

cmd/runtimetest/main.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
)
7070

7171
type validation struct {
72-
test func(*rspec.Spec) error
72+
test func(*rspec.Spec, *tap.T) error
7373
description string
7474
}
7575

@@ -91,7 +91,7 @@ func loadSpecConfig(path string) (spec *rspec.Spec, err error) {
9191
return spec, nil
9292
}
9393

94-
func validatePosixUser(spec *rspec.Spec) error {
94+
func validatePosixUser(spec *rspec.Spec, t *tap.T) error {
9595
if spec.Process == nil {
9696
return nil
9797
}
@@ -124,7 +124,7 @@ func validatePosixUser(spec *rspec.Spec) error {
124124
return nil
125125
}
126126

127-
func validateProcess(spec *rspec.Spec) error {
127+
func validateProcess(spec *rspec.Spec, t *tap.T) error {
128128
if spec.Process == nil {
129129
return nil
130130
}
@@ -152,7 +152,7 @@ func validateProcess(spec *rspec.Spec) error {
152152
return nil
153153
}
154154

155-
func validateLinuxProcess(spec *rspec.Spec) error {
155+
func validateLinuxProcess(spec *rspec.Spec, t *tap.T) error {
156156
if spec.Process == nil {
157157
return nil
158158
}
@@ -186,7 +186,7 @@ func validateLinuxProcess(spec *rspec.Spec) error {
186186
return nil
187187
}
188188

189-
func validateCapabilities(spec *rspec.Spec) error {
189+
func validateCapabilities(spec *rspec.Spec, t *tap.T) error {
190190
if spec.Process == nil || spec.Process.Capabilities == nil {
191191
return nil
192192
}
@@ -251,7 +251,7 @@ func validateCapabilities(spec *rspec.Spec) error {
251251
return nil
252252
}
253253

254-
func validateHostname(spec *rspec.Spec) error {
254+
func validateHostname(spec *rspec.Spec, t *tap.T) error {
255255
hostname, err := os.Hostname()
256256
if err != nil {
257257
return err
@@ -262,7 +262,7 @@ func validateHostname(spec *rspec.Spec) error {
262262
return nil
263263
}
264264

265-
func validateRlimits(spec *rspec.Spec) error {
265+
func validateRlimits(spec *rspec.Spec, t *tap.T) error {
266266
if spec.Process == nil {
267267
return nil
268268
}
@@ -288,7 +288,7 @@ func validateRlimits(spec *rspec.Spec) error {
288288
return nil
289289
}
290290

291-
func validateSysctls(spec *rspec.Spec) error {
291+
func validateSysctls(spec *rspec.Spec, t *tap.T) error {
292292
if spec.Linux == nil {
293293
return nil
294294
}
@@ -318,7 +318,7 @@ func testWriteAccess(path string) error {
318318
return nil
319319
}
320320

321-
func validateRootFS(spec *rspec.Spec) error {
321+
func validateRootFS(spec *rspec.Spec, t *tap.T) error {
322322
if spec.Root == nil {
323323
return nil
324324
}
@@ -338,7 +338,7 @@ func validateRootFS(spec *rspec.Spec) error {
338338
return nil
339339
}
340340

341-
func validateRootfsPropagation(spec *rspec.Spec) error {
341+
func validateRootfsPropagation(spec *rspec.Spec, t *tap.T) error {
342342
if spec.Linux == nil || spec.Linux.RootfsPropagation == "" {
343343
return nil
344344
}
@@ -403,7 +403,7 @@ func validateRootfsPropagation(spec *rspec.Spec) error {
403403
return nil
404404
}
405405

406-
func validateDefaultFS(spec *rspec.Spec) error {
406+
func validateDefaultFS(spec *rspec.Spec, t *tap.T) error {
407407
mountInfos, err := mount.GetMounts()
408408
if err != nil {
409409
specerror.NewError(specerror.DefaultFilesystems, err, spec.Version)
@@ -423,7 +423,7 @@ func validateDefaultFS(spec *rspec.Spec) error {
423423
return nil
424424
}
425425

426-
func validateLinuxDevices(spec *rspec.Spec) error {
426+
func validateLinuxDevices(spec *rspec.Spec, t *tap.T) error {
427427
if spec.Linux == nil {
428428
return nil
429429
}
@@ -480,7 +480,7 @@ func validateLinuxDevices(spec *rspec.Spec) error {
480480
return nil
481481
}
482482

483-
func validateDefaultSymlinks(spec *rspec.Spec) error {
483+
func validateDefaultSymlinks(spec *rspec.Spec, t *tap.T) error {
484484
for symlink, dest := range defaultSymlinks {
485485
fi, err := os.Lstat(symlink)
486486
if err != nil {
@@ -506,7 +506,7 @@ func validateDefaultSymlinks(spec *rspec.Spec) error {
506506
return nil
507507
}
508508

509-
func validateDefaultDevices(spec *rspec.Spec) error {
509+
func validateDefaultDevices(spec *rspec.Spec, t *tap.T) error {
510510
if spec.Process != nil && spec.Process.Terminal {
511511
defaultDevices = append(defaultDevices, "/dev/console")
512512
}
@@ -531,7 +531,7 @@ func validateDefaultDevices(spec *rspec.Spec) error {
531531
return nil
532532
}
533533

534-
func validateMaskedPaths(spec *rspec.Spec) error {
534+
func validateMaskedPaths(spec *rspec.Spec, t *tap.T) error {
535535
if spec.Linux == nil {
536536
return nil
537537
}
@@ -550,11 +550,10 @@ func validateMaskedPaths(spec *rspec.Spec) error {
550550
return nil
551551
}
552552

553-
func validateSeccomp(spec *rspec.Spec) error {
553+
func validateSeccomp(spec *rspec.Spec, t *tap.T) error {
554554
if spec.Linux == nil || spec.Linux.Seccomp == nil {
555555
return nil
556556
}
557-
t := tap.New()
558557
for _, sys := range spec.Linux.Seccomp.Syscalls {
559558
if sys.Action == "SCMP_ACT_ERRNO" {
560559
for _, name := range sys.Names {
@@ -574,7 +573,7 @@ func validateSeccomp(spec *rspec.Spec) error {
574573
return nil
575574
}
576575

577-
func validateROPaths(spec *rspec.Spec) error {
576+
func validateROPaths(spec *rspec.Spec, t *tap.T) error {
578577
if spec.Linux == nil {
579578
return nil
580579
}
@@ -588,7 +587,7 @@ func validateROPaths(spec *rspec.Spec) error {
588587
return nil
589588
}
590589

591-
func validateOOMScoreAdj(spec *rspec.Spec) error {
590+
func validateOOMScoreAdj(spec *rspec.Spec, t *tap.T) error {
592591
if spec.Process != nil && spec.Process.OOMScoreAdj != nil {
593592
expected := *spec.Process.OOMScoreAdj
594593
f, err := os.Open("/proc/self/oom_score_adj")
@@ -679,14 +678,14 @@ func validateIDMappings(mappings []rspec.LinuxIDMapping, path string, property s
679678
return nil
680679
}
681680

682-
func validateUIDMappings(spec *rspec.Spec) error {
681+
func validateUIDMappings(spec *rspec.Spec, t *tap.T) error {
683682
if spec.Linux == nil {
684683
return nil
685684
}
686685
return validateIDMappings(spec.Linux.UIDMappings, "/proc/self/uid_map", "linux.uidMappings")
687686
}
688687

689-
func validateGIDMappings(spec *rspec.Spec) error {
688+
func validateGIDMappings(spec *rspec.Spec, t *tap.T) error {
690689
if spec.Linux == nil {
691690
return nil
692691
}
@@ -715,7 +714,7 @@ func mountMatch(configMount rspec.Mount, sysMount *mount.Info) error {
715714
return nil
716715
}
717716

718-
func validatePosixMounts(spec *rspec.Spec) error {
717+
func validatePosixMounts(spec *rspec.Spec, t *tap.T) error {
719718
mountInfos, err := mount.GetMounts()
720719
if err != nil {
721720
return err
@@ -909,7 +908,7 @@ func run(context *cli.Context) error {
909908
}
910909

911910
for _, v := range validations {
912-
err := v.test(spec)
911+
err := v.test(spec, t)
913912
if err == nil {
914913
t.Pass(v.description)
915914
} else {

0 commit comments

Comments
 (0)