Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ validation-executables: $(VALIDATION_TESTS)
$(VALIDATION_TESTS): %.t: %.go
go build -tags "$(BUILDTAGS)" ${TESTFLAGS} -o $@ $<

.PHONY: test .gofmt .govet .golint
print-validation-tests:
@echo $(VALIDATION_TESTS)

.PHONY: test .gofmt .govet .golint print-validation-tests

PACKAGES = $(shell go list ./... | grep -v vendor)
test: .gofmt .govet .golint .gotest
Expand Down
10 changes: 10 additions & 0 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,16 @@ func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error {
}

for _, mount := range spec.Mounts {
isBind := false
for _, opt := range mount.Options {
if opt == "bind" || opt == "rbind" {
isBind = true
break
}
}
if !isBind {
continue
}
fileLabel, err := label.FileLabel(mount.Destination)
if err != nil {
return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination)
Expand Down
6 changes: 3 additions & 3 deletions validation/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
func main() {
t := tap.New()
t.Header(0)
defer t.AutoPlan()

bundleDir, err := util.PrepareBundle()
if err != nil {
util.Fatal(err)
Expand Down Expand Up @@ -72,7 +74,7 @@ func main() {

if c.effectCheck {
// waiting for the error of State, just in case the delete operation takes time
util.WaitingForStatus(testRuntime, util.LifecycleActionNone, time.Second*10, time.Second*1)
util.WaitingForStatus(testRuntime, util.LifecycleActionNone, time.Second*3, time.Second/2)
_, err = testRuntime.State()
// err == nil means the 'delete' operation does NOT take effect
util.SpecErrorOK(t, err == nil, specerror.NewError(specerror.DeleteNonStopHaveNoEffect, fmt.Errorf("attempting to `delete` a container that is not `stopped` MUST have no effect on the container"), rspecs.Version), err)
Expand All @@ -89,6 +91,4 @@ func main() {
}
}
}

t.AutoPlan()
}
4 changes: 4 additions & 0 deletions validation/kill/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func main() {
// KILL MUST be supported and KILL cannot be trapped
err = r.Kill("KILL")
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
if err != nil {
//Be sure to not leave the container around
r.Delete()
}
return err
},
}
Expand Down
10 changes: 8 additions & 2 deletions validation/linux_seccomp/linux_seccomp.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package main

import (
tap "github.com/mndrix/tap-go"
"github.com/opencontainers/runtime-tools/generate/seccomp"
"github.com/opencontainers/runtime-tools/validation/util"
)

func main() {
t := tap.New()
t.Header(0)
defer t.AutoPlan()
g, err := util.GetDefaultGenerator()
if err != nil {
util.Fatal(err)
Expand All @@ -16,8 +20,10 @@ func main() {
}
g.SetDefaultSeccompAction("allow")
g.SetSyscallAction(syscallArgs)
err = util.RuntimeInsideValidate(g, nil, nil)
err = util.RuntimeInsideValidate(g, t, nil)
t.Ok(err == nil, "seccomp action is added correctly")
if err != nil {
util.Fatal(err)
t.Fail(err.Error())
}

}
10 changes: 8 additions & 2 deletions validation/misc_props/misc_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ func main() {
util.Fatal(err)
}
basicConfig.SetProcessArgs([]string{"true"})
annotationConfig := basicConfig
annotationConfig, err := util.GetDefaultGenerator()
if err != nil {
util.Fatal(err)
}
annotationConfig.AddAnnotation(fmt.Sprintf("org.%s", containerID), "")
invalidConfig := basicConfig
invalidConfig, err := util.GetDefaultGenerator()
if err != nil {
util.Fatal(err)
}
invalidConfig.SetVersion("invalid")

cases := []struct {
Expand Down
10 changes: 9 additions & 1 deletion validation/pidfile/pidfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
"time"

tap "github.com/mndrix/tap-go"
"github.com/opencontainers/runtime-tools/validation/util"
Expand All @@ -31,7 +32,7 @@ func main() {
g.SetProcessArgs([]string{"true"})
config := util.LifecycleConfig{
Config: g,
Actions: util.LifecycleActionCreate | util.LifecycleActionDelete,
Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete,
PreCreate: func(r *util.Runtime) error {
r.SetID(uuid.NewV4().String())
r.PidFile = tempPidFile
Expand All @@ -55,6 +56,13 @@ func main() {
}
return nil
},
PreDelete: func(r *util.Runtime) error {
util.WaitingForStatus(*r, util.LifecycleStatusRunning, time.Second*10, time.Second*1)
err = r.Kill("KILL")
// wait before the container been deleted
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
return err
},
}

err = util.RuntimeLifecycleValidate(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
if err != nil {
util.Fatal(err)
}
g.AddProcessCapabilityBounding("CAP_TEST")
g.Config.Process.Capabilities.Bounding = append(g.Config.Process.Capabilities.Bounding, "CAP_TEST")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a bug in the helper function that we should fix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I think it is fine that the helper function checks whether the input is valid and rejects unknown capabilities

err = util.RuntimeInsideValidate(g, nil, nil)
if err == nil {
util.Fatal(specerror.NewError(specerror.LinuxProcCapError, fmt.Errorf("Any value which cannot be mapped to a relevant kernel interface MUST cause an error"), rspecs.Version))
Expand Down
3 changes: 3 additions & 0 deletions validation/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os/exec"
"time"

"github.com/mndrix/tap-go"
rspecs "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -44,6 +45,8 @@ func main() {
},
PostCreate: func(r *util.Runtime) error {
_, err = r.State()
r.Kill("KILL")
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second)
return err
},
}
Expand Down
4 changes: 4 additions & 0 deletions validation/util/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"time"

rspecs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
Expand Down Expand Up @@ -197,6 +198,9 @@ func (r *Runtime) Delete() (err error) {
// forceRemoveBundle is true, after the deletion attempt regardless of
// whether it was successful or not.
func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) error {
r.Kill("KILL")
WaitingForStatus(*r, LifecycleStatusStopped, time.Second*10, time.Second/10)

err := r.Delete()

if removeBundle && (err == nil || forceRemoveBundle) {
Expand Down
3 changes: 2 additions & 1 deletion validation/util/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ func RuntimeLifecycleValidate(config LifecycleConfig) error {
if _, err := r.State(); err != nil {
return
}
err := WaitingForStatus(r, LifecycleStatusCreated|LifecycleStatusStopped, time.Second*10, time.Second*1)
r.Kill("KILL")
err := WaitingForStatus(r, LifecycleStatusStopped, time.Second*10, time.Second*1)
if err == nil {
r.Delete()
} else {
Expand Down