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
This commit is contained in:
Michael Pratt
2019-02-25 18:06:43 -08:00
committed by Shentubot
parent 26be25e4ec
commit 563c9ed1d6
+27 -3
View File
@@ -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