diff --git a/test/runner/defs.bzl b/test/runner/defs.bzl index c3c99bc34..3e2070c5a 100644 --- a/test/runner/defs.bzl +++ b/test/runner/defs.bzl @@ -72,6 +72,7 @@ def _syscall_test( lisafs = True, fuse = False, container = None, + one_sandbox = True, **kwargs): # Prepend "runsc" to non-native platform names. full_platform = platform if platform == "native" else "runsc_" + platform @@ -143,6 +144,7 @@ def _syscall_test( "--strace=" + str(debug), "--debug=" + str(debug), "--container=" + str(container), + "--one-sandbox=" + str(one_sandbox), ] # Trace points are platform agnostic, so enable them for ptrace only. @@ -170,6 +172,7 @@ def syscall_test( add_overlay = False, add_uds_tree = False, add_hostinet = False, + one_sandbox = True, fuse = False, allow_native = True, debug = True, @@ -204,6 +207,7 @@ def syscall_test( tags = tags, debug = debug, container = container, + one_sandbox = one_sandbox, **kwargs ) @@ -217,6 +221,7 @@ def syscall_test( fuse = fuse, debug = debug, container = container, + one_sandbox = one_sandbox, **kwargs ) @@ -230,6 +235,7 @@ def syscall_test( debug = debug, fuse = fuse, container = container, + one_sandbox = one_sandbox, lisafs = False, **kwargs ) @@ -243,6 +249,7 @@ def syscall_test( debug = debug, fuse = fuse, container = container, + one_sandbox = one_sandbox, overlay = True, **kwargs ) @@ -257,6 +264,7 @@ def syscall_test( debug = debug, fuse = fuse, container = container, + one_sandbox = one_sandbox, **kwargs ) if not use_tmpfs: @@ -269,6 +277,7 @@ def syscall_test( tags = platforms.get(default_platform, []) + tags, debug = debug, container = container, + one_sandbox = one_sandbox, file_access = "shared", fuse = fuse, **kwargs diff --git a/test/runner/gtest/gtest.go b/test/runner/gtest/gtest.go index 44c35ff1d..094fc2804 100644 --- a/test/runner/gtest/gtest.go +++ b/test/runner/gtest/gtest.go @@ -179,3 +179,36 @@ func ParseBenchmarks(binary string, extraArgs ...string) ([]TestCase, error) { } return t, nil } + +// BuildTestArgs builds arguments to be passed to the test binary to execute +// only the test cases in `indices`. +func BuildTestArgs(indices []int, testCases []TestCase) []string { + var testFilter, benchFilter string + for _, tci := range indices { + tc := testCases[tci] + if tc.all { + // No argument will make all tests run. + return nil + } + if tc.benchmark { + if len(benchFilter) > 0 { + benchFilter += "|" + } + benchFilter += "^" + tc.Name + "$" + } else { + if len(testFilter) > 0 { + testFilter += ":" + } + testFilter += tc.FullName() + } + } + + var args []string + if len(testFilter) > 0 { + args = append(args, fmt.Sprintf("%s=%s", filterTestFlag, testFilter)) + } + if len(benchFilter) > 0 { + args = append(args, fmt.Sprintf("%s=%s", filterBenchmarkFlag, benchFilter)) + } + return args +} diff --git a/test/runner/main.go b/test/runner/main.go index 87c461058..953377777 100644 --- a/test/runner/main.go +++ b/test/runner/main.go @@ -43,6 +43,7 @@ import ( var ( debug = flag.Bool("debug", false, "enable debug logs") + oneSandbox = flag.Bool("one-sandbox", false, "run all test cases in one sandbox") strace = flag.Bool("strace", false, "enable strace logs") platform = flag.String("platform", "ptrace", "platform to run on") platformSupport = flag.String("platform-support", "", "String passed to the test as GVISOR_PLATFORM_SUPPORT environment variable. Used to determine which syscall tests are expected to work with the current platform.") @@ -80,7 +81,7 @@ func getSetupContainerPath() string { } // runTestCaseNative runs the test case directly on the host machine. -func runTestCaseNative(testBin string, tc gtest.TestCase, t *testing.T) { +func runTestCaseNative(testBin string, tc *gtest.TestCase, args []string, t *testing.T) { // These tests might be running in parallel, so make sure they have a // unique test temp dir. tmpDir, err := ioutil.TempDir(testutil.TmpDir(), "") @@ -125,7 +126,11 @@ func runTestCaseNative(testBin string, tc gtest.TestCase, t *testing.T) { env = append(env, fmt.Sprintf("%s=%s", platformSupportEnvVar, *platformSupport)) } - cmd := exec.Command(testBin, tc.Args()...) + if args == nil { + args = tc.Args() + } + + cmd := exec.Command(testBin, args...) cmd.Env = env cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -169,7 +174,7 @@ func runTestCaseNative(testBin string, tc gtest.TestCase, t *testing.T) { // runsc logs will be saved to a path in TEST_UNDECLARED_OUTPUTS_DIR. // // Returns an error if the sandboxed application exits non-zero. -func runRunsc(tc gtest.TestCase, spec *specs.Spec) error { +func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error { bundleDir, cleanup, err := testutil.SetupBundleDir(spec) if err != nil { return fmt.Errorf("SetupBundleDir failed: %v", err) @@ -372,10 +377,13 @@ func setupUDSTree(spec *specs.Spec) (cleanup func(), err error) { } // runsTestCaseRunsc runs the test case in runsc. -func runTestCaseRunsc(testBin string, tc gtest.TestCase, t *testing.T) { +func runTestCaseRunsc(testBin string, tc *gtest.TestCase, args []string, t *testing.T) { // Run a new container with the test executable and filter for the // given test suite and name. - spec := testutil.NewSpecWithArgs(append([]string{testBin}, tc.Args()...)...) + if args == nil { + args = tc.Args() + } + spec := testutil.NewSpecWithArgs(append([]string{testBin}, args...)...) // Mark the root as writeable, as some tests attempt to // write to the rootfs, and expect EACCES, not EROFS. @@ -550,23 +558,44 @@ func main() { fatalf("Abs() failed: %v", err) } - // Run the tests. var tests []testing.InternalTest - for _, tci := range indices { - // Capture tc. - tc := testCases[tci] + if *oneSandbox { + tc := gtest.TestCase{ + Suite: "main", + Name: "test", + } + tests = append(tests, testing.InternalTest{ Name: fmt.Sprintf("%s_%s", tc.Suite, tc.Name), F: func(t *testing.T) { + args := gtest.BuildTestArgs(indices, testCases) if *platform == "native" { // Run the test case on host. - runTestCaseNative(testBin, tc, t) + runTestCaseNative(testBin, &tc, args, t) } else { // Run the test case in runsc. - runTestCaseRunsc(testBin, tc, t) + runTestCaseRunsc(testBin, &tc, args, t) } }, }) + } else { + // Run the tests. + for _, tci := range indices { + // Capture tc. + tc := testCases[tci] + tests = append(tests, testing.InternalTest{ + Name: fmt.Sprintf("%s_%s", tc.Suite, tc.Name), + F: func(t *testing.T) { + if *platform == "native" { + // Run the test case on host. + runTestCaseNative(testBin, &tc, nil, t) + } else { + // Run the test case in runsc. + runTestCaseRunsc(testBin, &tc, nil, t) + } + }, + }) + } } testing.Main(matchString, tests, nil, nil) diff --git a/test/syscalls/BUILD b/test/syscalls/BUILD index 116700219..352fff6bb 100644 --- a/test/syscalls/BUILD +++ b/test/syscalls/BUILD @@ -58,6 +58,7 @@ syscall_test( ) syscall_test( + one_sandbox = False, test = "//test/syscalls/linux:cgroup_test", ) @@ -108,6 +109,7 @@ syscall_test( syscall_test( add_uds_tree = True, + one_sandbox = False, test = "//test/syscalls/linux:connect_external_test", use_tmpfs = True, ) @@ -449,6 +451,7 @@ syscall_test( syscall_test( container = True, + one_sandbox = False, test = "//test/syscalls/linux:proc_isolated_test", ) @@ -675,6 +678,7 @@ syscall_test( syscall_test( size = "large", container = True, + one_sandbox = False, shard_count = most_shards, test = "//test/syscalls/linux:socket_inet_loopback_isolated_test", )