From 563c9ed1d6814776aa22d3a272fe55c15143fe79 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 25 Feb 2019 18:05:58 -0800 Subject: [PATCH] Use a custom, world-accessible, /tmp mount This solves two problems: 1. Using the host /tmp directly meant that concurrent tests could collide attempting to use the same file, and that misbehaving tests never have their /tmp output cleaned up. 2. Host /tmp is not world-accessible on all hosts. Some tests (e.g., sticky) access files in /tmp from other users, so we need to ensure that its /tmp is world-accessible. PiperOrigin-RevId: 235637873 Change-Id: I7555224685ac5b93af88c403196b09ce1bb2bfe7 --- test/syscalls/syscall_test_runner.go | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/test/syscalls/syscall_test_runner.go b/test/syscalls/syscall_test_runner.go index 16228ef46..9fe801b26 100644 --- a/test/syscalls/syscall_test_runner.go +++ b/test/syscalls/syscall_test_runner.go @@ -115,10 +115,34 @@ func runTestCaseRunsc(testBin string, tc gtest.TestCase, t *testing.T) { spec.Mounts = nil if *useTmpfs { // Forces '/tmp' to be mounted as tmpfs, otherwise test that rely on - // features available in gVisor's tmpfs and not gofers, may fail. - spec.Mounts = []specs.Mount{ - {Destination: "/tmp", Type: "tmpfs"}, + // features only available in gVisor's internal tmpfs may fail. + spec.Mounts = append(spec.Mounts, specs.Mount{ + Destination: "/tmp", + Type: "tmpfs", + }) + } else { + // Use a gofer-backed directory as '/tmp'. + // + // Tests might be running in parallel, so make sure each has a + // unique test temp dir. + // + // Some tests (e.g., sticky) access this mount from other + // users, so make sure it is world-accessible. + tmpDir, err := ioutil.TempDir(testutil.TmpDir(), "") + if err != nil { + t.Fatalf("could not create temp dir: %v", err) } + defer os.RemoveAll(tmpDir) + + if err := os.Chmod(tmpDir, 0777); err != nil { + t.Fatalf("could not chmod temp dir: %v", err) + } + + spec.Mounts = append(spec.Mounts, specs.Mount{ + Type: "bind", + Destination: "/tmp", + Source: tmpDir, + }) } // Set environment variable that indicates we are