forked from opencontainers/runtime-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validation: Use prove(1) as a TAP harness
Capture stdout and stderr from create invocations, because we don't want to pollute the TAP output with things like runc's: Incorrect Usage. ... (which is for some reason printed to stdout) or: runc: "create" requires exactly 1 argument(s) which is printed to stderr. Instead, show the captured stderr as a diagnostic, and hide the stdout completely. Unless stderr is empty, in which case show stdout in case it contains something useful. Most of these tests are broken because we aren't collecting the container exit code or post-start stdout. But the tests haven't been doing that since the create/start split in 15577bd (add runtime struct; add create test, 2017-08-24, opencontainers#447) anyway [1]. This commit just makes that more obvious. The patsubst and wildcard Makefile syntax is documented in [2]. The $(VALIDATION_TESTS) rule uses the static pattern rule syntax [3]. And use 'console' instead of 'sh' in the README, because these are shell sessions, not scripts. See [4,5]. I don't have a working runc locally, so the mock results based on a dummy runtime script. [1]: opencontainers#447 (comment) [2]: https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html [3]: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html#Static-Usage [4]: https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting [5]: https://github.com/github/linguist/blob/v5.3.3/lib/linguist/languages.yml#L4249-L4260 Signed-off-by: W. Trevor King <[email protected]>
- Loading branch information
Showing
24 changed files
with
679 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mndrix/tap-go" | ||
rspecs "github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/opencontainers/runtime-tools/generate" | ||
"github.com/opencontainers/runtime-tools/specerror" | ||
"github.com/opencontainers/runtime-tools/validation/util" | ||
"github.com/satori/go.uuid" | ||
) | ||
|
||
func main() { | ||
t := tap.New() | ||
|
||
g := generate.New() | ||
g.SetRootPath(".") | ||
g.SetProcessArgs([]string{"ls"}) | ||
|
||
bundleDir, err := util.PrepareBundle() | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
|
||
r, err := util.NewRuntime(util.RuntimeCommand, bundleDir) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
defer r.Clean(true) | ||
|
||
err = r.SetConfig(&g) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
|
||
containerID := uuid.NewV4().String() | ||
cases := []struct { | ||
id string | ||
errExpected bool | ||
err error | ||
}{ | ||
{"", false, specerror.NewError(specerror.CreateWithBundlePathAndID, fmt.Errorf("create MUST generate an error if the ID is not provided"), rspecs.Version)}, | ||
{containerID, true, specerror.NewError(specerror.CreateNewContainer, fmt.Errorf("create MUST create a new container"), rspecs.Version)}, | ||
{containerID, false, specerror.NewError(specerror.CreateWithUniqueID, fmt.Errorf("create MUST generate an error if the ID provided is not unique"), rspecs.Version)}, | ||
} | ||
|
||
for _, c := range cases { | ||
r.SetID(c.id) | ||
stderr, err := r.Create() | ||
t.Ok((err == nil) == c.errExpected, c.err.(*specerror.Error).Err.Err.Error()) | ||
t.Diagnostic(c.err.(*specerror.Error).Err.Reference) | ||
if err != nil { | ||
t.Diagnostic(err.Error()) | ||
} | ||
if len(stderr) > 0 { | ||
t.Diagnostic(string(stderr)) | ||
} | ||
|
||
if err == nil { | ||
state, _ := r.State() | ||
t.Ok(state.ID == c.id, "") | ||
t.Diagnosticf("container PID: %d, state ID: %d", c.id, state.ID) | ||
} | ||
} | ||
|
||
t.AutoPlan() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/opencontainers/runtime-tools/validation/util" | ||
) | ||
|
||
func main() { | ||
g := util.GetDefaultGenerator() | ||
err := util.RuntimeInsideValidate(g, nil) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/opencontainers/runtime-tools/validation/util" | ||
) | ||
|
||
func main() { | ||
g := util.GetDefaultGenerator() | ||
g.SetHostname("hostname-specific") | ||
err := util.RuntimeInsideValidate(g, nil) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
rspecs "github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/opencontainers/runtime-tools/validation/util" | ||
) | ||
|
||
func main() { | ||
g := util.GetDefaultGenerator() | ||
|
||
// add char device | ||
cdev := rspecs.LinuxDevice{} | ||
cdev.Path = "/dev/test1" | ||
cdev.Type = "c" | ||
cdev.Major = 10 | ||
cdev.Minor = 666 | ||
cmode := os.FileMode(int32(432)) | ||
cdev.FileMode = &cmode | ||
cuid := uint32(0) | ||
cdev.UID = &cuid | ||
cgid := uint32(0) | ||
cdev.GID = &cgid | ||
g.AddDevice(cdev) | ||
|
||
// add block device | ||
bdev := rspecs.LinuxDevice{} | ||
bdev.Path = "/dev/test2" | ||
bdev.Type = "b" | ||
bdev.Major = 8 | ||
bdev.Minor = 666 | ||
bmode := os.FileMode(int32(432)) | ||
bdev.FileMode = &bmode | ||
uid := uint32(0) | ||
bdev.UID = &uid | ||
gid := uint32(0) | ||
bdev.GID = &gid | ||
g.AddDevice(bdev) | ||
|
||
// add fifo device | ||
pdev := rspecs.LinuxDevice{} | ||
pdev.Path = "/dev/test3" | ||
pdev.Type = "p" | ||
pdev.Major = 8 | ||
pdev.Minor = 666 | ||
pmode := os.FileMode(int32(432)) | ||
pdev.FileMode = &pmode | ||
g.AddDevice(pdev) | ||
|
||
err := util.RuntimeInsideValidate(g, nil) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/opencontainers/runtime-tools/validation/util" | ||
) | ||
|
||
func main() { | ||
g := util.GetDefaultGenerator() | ||
g.AddLinuxGIDMapping(uint32(1000), uint32(0), uint32(3200)) | ||
err := util.RuntimeInsideValidate(g, nil) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/opencontainers/runtime-tools/validation/util" | ||
) | ||
|
||
func main() { | ||
g := util.GetDefaultGenerator() | ||
g.AddLinuxMaskedPaths("/masktest") | ||
err := util.RuntimeInsideValidate(g, func(path string) error { | ||
pathName := filepath.Join(path, "masktest") | ||
return os.MkdirAll(pathName, 0700) | ||
}) | ||
if err != nil { | ||
util.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.