aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/sandbox
diff options
context:
space:
mode:
authorGravatar philwo <philwo@google.com>2018-04-16 06:40:19 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-16 06:41:42 -0700
commitd3de5cc7e25e56fba666e1f39a9ebf3c76fdd69c (patch)
tree02716ad2664f1823976642c4344af7a3702d07a1 /src/test/java/com/google/devtools/build/lib/sandbox
parent8caa745545a1757fe93c6684d5ab98a47fa2718c (diff)
Big round of sandbox fixes / performance improvements. - The number of stat() syscalls in the SymlinkedSandboxedSpawn was way too high. Do less, feel better. - When using --experimental_sandbox_base, ensure that symlinks in the path are resolved. Before this, you had to check whether on your system /dev/shm is a symlink to /run/shm and then use that instead. Now it no longer matters, as symlinks are resolved. - Remove an unnecessary directory creation from each sandboxed invocation. Turns out that the "tmpdir" that we created was no longer used after some changes to Bazel's TMPDIR handling. - Use simpler sandbox paths, by using the unique ID for each Spawn provided by SpawnExecutionPolicy instead of a randomly generated temp folder name. This also saves a round-trip from our VFS to NIO and back. Clean up the sandbox base before each build to ensure that the unique IDs are actually unique. ;) - Use Java 8's Process#isAlive to check whether a process is alive instead of trying to get the exitcode and catching an exception. Closes #4913. PiperOrigin-RevId: 193031017
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/sandbox')
-rw-r--r--src/test/java/com/google/devtools/build/lib/sandbox/SandboxTestCase.java7
-rw-r--r--src/test/java/com/google/devtools/build/lib/sandbox/SymlinkedSandboxedSpawnTest.java31
2 files changed, 4 insertions, 34 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/SandboxTestCase.java b/src/test/java/com/google/devtools/build/lib/sandbox/SandboxTestCase.java
index 39f2227af5..8489c7d914 100644
--- a/src/test/java/com/google/devtools/build/lib/sandbox/SandboxTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/sandbox/SandboxTestCase.java
@@ -15,9 +15,8 @@ package com.google.devtools.build.lib.sandbox;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.util.FileSystems;
+import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import org.junit.Before;
/** Common parts of all sandbox tests. */
@@ -27,8 +26,8 @@ public class SandboxTestCase {
@Before
public final void createTestRoot() throws Exception {
- fileSystem = FileSystems.getNativeFileSystem();
+ fileSystem = new InMemoryFileSystem();
testRoot = fileSystem.getPath(TestUtils.tmpDir());
- FileSystemUtils.deleteTreesBelow(testRoot);
+ testRoot.createDirectoryAndParents();
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/SymlinkedSandboxedSpawnTest.java b/src/test/java/com/google/devtools/build/lib/sandbox/SymlinkedSandboxedSpawnTest.java
index 5e24deea4a..89fd5eecff 100644
--- a/src/test/java/com/google/devtools/build/lib/sandbox/SymlinkedSandboxedSpawnTest.java
+++ b/src/test/java/com/google/devtools/build/lib/sandbox/SymlinkedSandboxedSpawnTest.java
@@ -58,7 +58,7 @@ public class SymlinkedSandboxedSpawnTest extends SandboxTestCase {
sandboxDir,
execRoot,
ImmutableList.of("/bin/true"),
- ImmutableMap.<String, String>of(),
+ ImmutableMap.of(),
ImmutableMap.of(PathFragment.create("such/input.txt"), helloTxt),
ImmutableSet.of(PathFragment.create("very/output.txt")),
ImmutableSet.of(execRoot.getRelative("wow/writable")));
@@ -72,35 +72,6 @@ public class SymlinkedSandboxedSpawnTest extends SandboxTestCase {
}
@Test
- public void cleanFileSystem() throws Exception {
- Path helloTxt = workspaceDir.getRelative("hello.txt");
- FileSystemUtils.createEmptyFile(helloTxt);
-
- SymlinkedSandboxedSpawn symlinkedExecRoot = new SymlinkedSandboxedSpawn(
- sandboxDir,
- execRoot,
- ImmutableList.of("/bin/true"),
- ImmutableMap.<String, String>of(),
- ImmutableMap.of(PathFragment.create("such/input.txt"), helloTxt),
- ImmutableSet.of(PathFragment.create("very/output.txt")),
- ImmutableSet.of(execRoot.getRelative("wow/writable")));
- symlinkedExecRoot.createFileSystem();
-
- // Pretend to do some work inside the execRoot.
- execRoot.getRelative("tempdir").createDirectory();
- FileSystemUtils.createEmptyFile(execRoot.getRelative("very/output.txt"));
- FileSystemUtils.createEmptyFile(execRoot.getRelative("wow/writable/temp.txt"));
-
- // Reuse the same execRoot.
- symlinkedExecRoot.createFileSystem();
-
- assertThat(execRoot.getRelative("such/input.txt").exists()).isTrue();
- assertThat(execRoot.getRelative("tempdir").exists()).isFalse();
- assertThat(execRoot.getRelative("very/output.txt").exists()).isFalse();
- assertThat(execRoot.getRelative("wow/writable/temp.txt").exists()).isFalse();
- }
-
- @Test
public void copyOutputs() throws Exception {
// These tests are very simple because we just rely on SandboxedSpawnTest.testMoveOutputs to
// properly verify all corner cases.