summaryrefslogtreecommitdiffhomepage
path: root/runsc/test
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-07-23 13:30:29 -0700
committerShentubot <shentubot@google.com>2018-07-23 13:31:42 -0700
commitd7a34790a0cc3cfdef9d9e54f17c4bc0a6819900 (patch)
treebfbbfd9e0ad6ad74a15f0c705ad989904eb57a69 /runsc/test
parentf543ada15005e6e2d31a63148a74fbdc43d070de (diff)
Add KVM and overlay dimensions to container_test
PiperOrigin-RevId: 205714667 Change-Id: I317a2ca98ac3bdad97c4790fcc61b004757d99ef
Diffstat (limited to 'runsc/test')
-rw-r--r--runsc/test/testutil/BUILD1
-rw-r--r--runsc/test/testutil/testutil.go42
-rw-r--r--runsc/test/testutil/testutil_race.go21
3 files changed, 46 insertions, 18 deletions
diff --git a/runsc/test/testutil/BUILD b/runsc/test/testutil/BUILD
index 6aec54abe..3ebcc1362 100644
--- a/runsc/test/testutil/BUILD
+++ b/runsc/test/testutil/BUILD
@@ -7,6 +7,7 @@ go_library(
srcs = [
"docker.go",
"testutil.go",
+ "testutil_race.go",
],
importpath = "gvisor.googlesource.com/gvisor/runsc/test/testutil",
visibility = [
diff --git a/runsc/test/testutil/testutil.go b/runsc/test/testutil/testutil.go
index 9d70d29f2..c7cef9c75 100644
--- a/runsc/test/testutil/testutil.go
+++ b/runsc/test/testutil/testutil.go
@@ -29,6 +29,9 @@ import (
"gvisor.googlesource.com/gvisor/runsc/specutils"
)
+// RaceEnabled is set to true if it was built with '--race' option.
+var RaceEnabled = false
+
// ConfigureExePath configures the executable for runsc in the test environment.
func ConfigureExePath() error {
@@ -66,6 +69,18 @@ func ConfigureExePath() error {
return nil
}
+// TestConfig return the default configuration to use in tests.
+func TestConfig() *boot.Config {
+ return &boot.Config{
+ Debug: true,
+ LogFormat: "text",
+ LogPackets: true,
+ Network: boot.NetworkNone,
+ Strace: true,
+ MultiContainer: true,
+ }
+}
+
// NewSpecWithArgs creates a simple spec with the given args suitable for use
// in tests.
func NewSpecWithArgs(args ...string) *specs.Spec {
@@ -96,38 +111,29 @@ func SetupRootDir() (string, error) {
// SetupContainer creates a bundle and root dir for the container, generates a
// test config, and writes the spec to config.json in the bundle dir.
-func SetupContainer(spec *specs.Spec) (rootDir, bundleDir string, conf *boot.Config, err error) {
+func SetupContainer(spec *specs.Spec, conf *boot.Config) (rootDir, bundleDir string, err error) {
rootDir, err = SetupRootDir()
if err != nil {
- return "", "", nil, err
+ return "", "", err
}
- bundleDir, conf, err = SetupContainerInRoot(rootDir, spec)
- return rootDir, bundleDir, conf, err
+ bundleDir, err = SetupContainerInRoot(rootDir, spec, conf)
+ return rootDir, bundleDir, err
}
// SetupContainerInRoot creates a bundle for the container, generates a test
// config, and writes the spec to config.json in the bundle dir.
-func SetupContainerInRoot(rootDir string, spec *specs.Spec) (bundleDir string, conf *boot.Config, err error) {
+func SetupContainerInRoot(rootDir string, spec *specs.Spec, conf *boot.Config) (bundleDir string, err error) {
bundleDir, err = ioutil.TempDir("", "bundle")
if err != nil {
- return "", nil, fmt.Errorf("error creating bundle dir: %v", err)
+ return "", fmt.Errorf("error creating bundle dir: %v", err)
}
if err = writeSpec(bundleDir, spec); err != nil {
- return "", nil, fmt.Errorf("error writing spec: %v", err)
- }
-
- conf = &boot.Config{
- Debug: true,
- LogFormat: "text",
- LogPackets: true,
- Network: boot.NetworkNone,
- RootDir: rootDir,
- Strace: true,
- MultiContainer: true,
+ return "", fmt.Errorf("error writing spec: %v", err)
}
- return bundleDir, conf, nil
+ conf.RootDir = rootDir
+ return bundleDir, nil
}
// writeSpec writes the spec to disk in the given directory.
diff --git a/runsc/test/testutil/testutil_race.go b/runsc/test/testutil/testutil_race.go
new file mode 100644
index 000000000..59cfdaa7b
--- /dev/null
+++ b/runsc/test/testutil/testutil_race.go
@@ -0,0 +1,21 @@
+// Copyright 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build race
+
+package testutil
+
+func init() {
+ RaceEnabled = true
+}