Skip to content

Commit 8765570

Browse files
author
Zhou Hao
committed
runtimetest: add posixValidations
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
1 parent 45b2686 commit 8765570

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

cmd/runtimetest/main.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ func loadSpecConfig(path string) (spec *rspec.Spec, err error) {
8181
return spec, nil
8282
}
8383

84-
func validateUser(spec *rspec.Spec) error {
85-
if runtime.GOOS == "windows" {
86-
return nil
87-
}
88-
84+
func validatePosixUser(spec *rspec.Spec) error {
8985
if spec.Process == nil {
9086
return nil
9187
}
@@ -118,7 +114,6 @@ func validateUser(spec *rspec.Spec) error {
118114
return nil
119115
}
120116

121-
// should be included by other platform specified process validation
122117
func validateProcess(spec *rspec.Spec) error {
123118
if spec.Process.Cwd != "" {
124119
cwd, err := os.Getwd()
@@ -277,10 +272,6 @@ func validateHostname(spec *rspec.Spec) error {
277272
}
278273

279274
func validateRlimits(spec *rspec.Spec) error {
280-
if runtime.GOOS == "windows" {
281-
return nil
282-
}
283-
284275
if spec.Process == nil {
285276
return nil
286277
}
@@ -642,12 +633,7 @@ func mountMatch(configMount rspec.Mount, sysMount *mount.Info) error {
642633
return nil
643634
}
644635

645-
func validateMounts(spec *rspec.Spec) error {
646-
if runtime.GOOS == "windows" {
647-
logrus.Warnf("mounts validation not yet implemented for OS %q", runtime.GOOS)
648-
return nil
649-
}
650-
636+
func validatePosixMounts(spec *rspec.Spec) error {
651637
mountInfos, err := mount.GetMounts()
652638
if err != nil {
653639
return err
@@ -740,20 +726,23 @@ func run(context *cli.Context) error {
740726
description: "hostname",
741727
},
742728
{
743-
test: validateMounts,
744-
description: "mounts",
729+
test: validateProcess,
730+
description: "process",
745731
},
732+
}
733+
734+
posixValidations := []validation{
746735
{
747-
test: validateRlimits,
748-
description: "rlimits",
736+
test: validatePosixMounts,
737+
description: "mounts",
749738
},
750739
{
751-
test: validateProcess,
752-
description: "process",
740+
test: validatePosixUser,
741+
description: "user",
753742
},
754743
{
755-
test: validateUser,
756-
description: "user",
744+
test: validateRlimits,
745+
description: "rlimits",
757746
},
758747
}
759748

@@ -829,6 +818,19 @@ func run(context *cli.Context) error {
829818
}
830819
}
831820

821+
if platform == "linux" || platform == "solaris" {
822+
for _, v := range posixValidations {
823+
err := v.test(spec)
824+
t.Ok(err == nil, v.description)
825+
if err != nil {
826+
if e, ok := err.(*specerror.Error); ok && e.Err.Level < complianceLevel {
827+
continue
828+
}
829+
validationErrors = multierror.Append(validationErrors, err)
830+
}
831+
}
832+
}
833+
832834
if platform == "linux" {
833835
for _, v := range linuxValidations {
834836
err := v.test(spec)

0 commit comments

Comments
 (0)