mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add KVM and overlay dimensions to container_test
PiperOrigin-RevId: 205714667 Change-Id: I317a2ca98ac3bdad97c4790fcc61b004757d99ef
This commit is contained in:
committed by
Shentubot
parent
f543ada150
commit
d7a34790a0
@@ -66,7 +66,7 @@ func New() (*KVM, error) {
|
||||
ring0.Init(cpuid.HostFeatureSet())
|
||||
})
|
||||
if globalErr != nil {
|
||||
return nil, err
|
||||
return nil, globalErr
|
||||
}
|
||||
|
||||
// Create a new VM fd.
|
||||
|
||||
@@ -26,17 +26,21 @@ go_library(
|
||||
|
||||
go_test(
|
||||
name = "container_test",
|
||||
size = "small",
|
||||
size = "medium",
|
||||
srcs = ["container_test.go"],
|
||||
data = [
|
||||
"//runsc",
|
||||
],
|
||||
tags = [
|
||||
"requires-kvm",
|
||||
],
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/log",
|
||||
"//pkg/sentry/control",
|
||||
"//pkg/sentry/kernel/auth",
|
||||
"//pkg/unet",
|
||||
"//runsc/boot",
|
||||
"//runsc/container",
|
||||
"//runsc/specutils",
|
||||
"//runsc/test/testutil",
|
||||
|
||||
+803
-724
File diff suppressed because it is too large
Load Diff
@@ -31,7 +31,8 @@ func init() {
|
||||
|
||||
func TestGoferExits(t *testing.T) {
|
||||
spec := testutil.NewSpecWithArgs("/bin/sleep", "10000")
|
||||
rootDir, bundleDir, conf, err := testutil.SetupContainer(spec)
|
||||
conf := testutil.TestConfig()
|
||||
rootDir, bundleDir, err := testutil.SetupContainer(spec, conf)
|
||||
if err != nil {
|
||||
t.Fatalf("error setting up container: %v", err)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ go_library(
|
||||
srcs = [
|
||||
"docker.go",
|
||||
"testutil.go",
|
||||
"testutil_race.go",
|
||||
],
|
||||
importpath = "gvisor.googlesource.com/gvisor/runsc/test/testutil",
|
||||
visibility = [
|
||||
|
||||
@@ -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)
|
||||
return "", 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 bundleDir, conf, nil
|
||||
conf.RootDir = rootDir
|
||||
return bundleDir, nil
|
||||
}
|
||||
|
||||
// writeSpec writes the spec to disk in the given directory.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user