aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar aehlig <aehlig@google.com>2017-12-20 06:02:07 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-20 07:15:58 -0800
commitfb0598878bf1b7fffe1ab7f310f705792fe47b95 (patch)
treecd5af2be68fa13f97d52e17c7a5166a403566a58 /src/test/java/com/google/devtools/build/lib
parent12471a77bdd4439f17cc1a665454601c867e1286 (diff)
Automated rollback of commit 52b62164af031c50b7a0584303caad67af5e1d4d.
*** Reason for rollback *** Breaks //src/test/shell/bazel:bazel_sandboxing_test *** Original change description *** Use linux-sandbox via the (new) LinuxSandboxUtil. RELNOTES: None. PiperOrigin-RevId: 179676894
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/LinuxSandboxUtilTest.java166
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java16
3 files changed, 8 insertions, 178 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/LinuxSandboxUtilTest.java b/src/test/java/com/google/devtools/build/lib/runtime/LinuxSandboxUtilTest.java
deleted file mode 100644
index def19f901e..0000000000
--- a/src/test/java/com/google/devtools/build/lib/runtime/LinuxSandboxUtilTest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// 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.
-
-package com.google.devtools.build.lib.runtime;
-
-import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.testutil.MoreAsserts.expectThrows;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
-import java.time.Duration;
-import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link LinuxSandboxUtil}. */
-@RunWith(JUnit4.class)
-public final class LinuxSandboxUtilTest {
- @Test
- public void testLinuxSandboxCommandLineBuilder_fakeRootAndFakeUsernameAreExclusive() {
- String linuxSandboxPath = "linux-sandbox";
- ImmutableList<String> commandArguments = ImmutableList.of("echo", "hello, flo");
-
- Exception e =
- expectThrows(
- IllegalStateException.class,
- () ->
- LinuxSandboxUtil.commandLineBuilder(linuxSandboxPath, commandArguments)
- .setUseFakeRoot(true)
- .setUseFakeUsername(true)
- .build());
- assertThat(e).hasMessageThat().contains("exclusive");
- }
-
- @Test
- public void testLinuxSandboxCommandLineBuilder_BuildsWithoutOptionalArguments() {
- String linuxSandboxPath = "linux-sandbox";
-
- ImmutableList<String> commandArguments = ImmutableList.of("echo", "hello, max");
-
- ImmutableList<String> expectedCommandLine =
- ImmutableList.<String>builder()
- .add(linuxSandboxPath)
- .add("--")
- .addAll(commandArguments)
- .build();
-
- List<String> commandLine =
- LinuxSandboxUtil.commandLineBuilder(linuxSandboxPath, commandArguments).build();
-
- assertThat(commandLine).containsExactlyElementsIn(expectedCommandLine).inOrder();
- }
-
- @Test
- public void testLinuxSandboxCommandLineBuilder_BuildsWithOptionalArguments() {
- String linuxSandboxPath = "linux-sandbox";
-
- ImmutableList<String> commandArguments = ImmutableList.of("echo", "hello, tom");
-
- Duration timeout = Duration.ofSeconds(10);
- Duration killDelay = Duration.ofSeconds(2);
- String statisticsPath = "stats.out";
-
- String workingDirectory = "/all-work-and-no-play";
- String stdoutPath = "stdout.txt";
- String stderrPath = "stderr.txt";
-
- // These two flags are exclusive.
- boolean useFakeUsername = true;
- boolean useFakeRoot = false;
-
- boolean createNetworkNamespace = true;
- boolean useFakeHostname = true;
- boolean useDebugMode = true;
-
- FileSystem fileSystem = new InMemoryFileSystem();
- Path workDir = fileSystem.getPath("/work");
- Path concreteDir = workDir.getRelative("concrete");
- Path sandboxDir = workDir.getRelative("sandbox");
-
- Path bindMountSource1 = concreteDir.getRelative("bindMountSource1");
- Path bindMountSource2 = concreteDir.getRelative("bindMountSource2");
- Path mountDir = sandboxDir.getRelative("mount");
- Path bindMountTarget1 = mountDir.getRelative("bindMountTarget1");
- Path bindMountTarget2 = mountDir.getRelative("bindMountTarget2");
- Path bindMountSameSourceAndTarget = mountDir.getRelative("bindMountSourceAndTarget");
-
- Path writableDir1 = sandboxDir.getRelative("writable1");
- Path writableDir2 = sandboxDir.getRelative("writable2");
-
- Path tmpfsDir1 = sandboxDir.getRelative("tmpfs1");
- Path tmpfsDir2 = sandboxDir.getRelative("tmpfs2");
-
- ImmutableList<Path> writableFilesAndDirectories = ImmutableList.of(writableDir1, writableDir2);
-
- ImmutableList<Path> tmpfsDirectories = ImmutableList.of(tmpfsDir1, tmpfsDir2);
-
- ImmutableSortedMap<Path, Path> bindMounts =
- ImmutableSortedMap.<Path, Path>naturalOrder()
- .put(bindMountTarget1, bindMountSource1)
- .put(bindMountTarget2, bindMountSource2)
- .put(bindMountSameSourceAndTarget, bindMountSameSourceAndTarget)
- .build();
-
- ImmutableList<String> expectedCommandLine =
- ImmutableList.<String>builder()
- .add(linuxSandboxPath)
- .add("-W", workingDirectory)
- .add("-T", Long.toString(timeout.getSeconds()))
- .add("-t", Long.toString(killDelay.getSeconds()))
- .add("-l", stdoutPath)
- .add("-L", stderrPath)
- .add("-w", writableDir1.getPathString())
- .add("-w", writableDir2.getPathString())
- .add("-e", tmpfsDir1.getPathString())
- .add("-e", tmpfsDir2.getPathString())
- .add("-M", bindMountSameSourceAndTarget.getPathString())
- .add("-M", bindMountSource1.getPathString())
- .add("-m", bindMountTarget1.getPathString())
- .add("-M", bindMountSource2.getPathString())
- .add("-m", bindMountTarget2.getPathString())
- .add("-S", statisticsPath)
- .add("-H")
- .add("-N")
- .add("-U")
- .add("-D")
- .add("--")
- .addAll(commandArguments)
- .build();
-
- List<String> commandLine =
- LinuxSandboxUtil.commandLineBuilder(linuxSandboxPath, commandArguments)
- .setWorkingDirectory(workingDirectory)
- .setStdoutPath(stdoutPath)
- .setStderrPath(stderrPath)
- .setTimeout(timeout)
- .setKillDelay(killDelay)
- .setWritableFilesAndDirectories(writableFilesAndDirectories)
- .setTmpfsDirectories(tmpfsDirectories)
- .setBindMounts(bindMounts)
- .setUseFakeHostname(useFakeHostname)
- .setCreateNetworkNamespace(createNetworkNamespace)
- .setUseFakeRoot(useFakeRoot)
- .setStatisticsPath(statisticsPath)
- .setUseFakeUsername(useFakeUsername)
- .setUseDebugMode(useDebugMode)
- .build();
-
- assertThat(commandLine).containsExactlyElementsIn(expectedCommandLine).inOrder();
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java
index 043e3e38ef..6d182f29a8 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java
@@ -71,7 +71,7 @@ public final class ProcessWrapperUtilTest {
.setCommandArguments(commandArguments)
.build();
- assertThat(commandLine).containsExactlyElementsIn(expectedCommandLine).inOrder();
+ assertThat(commandLine).containsExactlyElementsIn(expectedCommandLine);
}
@Test
@@ -108,6 +108,6 @@ public final class ProcessWrapperUtilTest {
.setStatisticsPath(statisticsPath)
.build();
- assertThat(commandLine).containsExactlyElementsIn(expectedCommandLine).inOrder();
+ assertThat(commandLine).containsExactlyElementsIn(expectedCommandLine);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
index 9151cde23e..6a3ca2b7ae 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
@@ -59,17 +59,13 @@ public class TestConstants {
*/
public static final String JAVATESTS_ROOT = "io_bazel/src/test/java/";
- /** Relative path to the {@code process-wrapper} tool. */
- public static final String PROCESS_WRAPPER_PATH =
- "io_bazel/src/main/tools/process-wrapper";
+ /** Relative path to the process-wrapper tool. */
+ public static final String PROCESS_WRAPPER_PATH
+ = "io_bazel/src/main/tools/process-wrapper";
- /** Relative path to the {@code linux-sandbox} tool. */
- public static final String LINUX_SANDBOX_PATH =
- "io_bazel/src/main/tools/linux-sandbox";
-
- /** Relative path to the {@code spend_cpu_time} testing tool. */
- public static final String CPU_TIME_SPENDER_PATH =
- "io_bazel/src/test/shell/integration/spend_cpu_time";
+ /** Relative path to the spend_cpu_time testing tool. */
+ public static final String CPU_TIME_SPENDER_PATH
+ = "io_bazel/src/test/shell/integration/spend_cpu_time";
public static final String TEST_RULE_CLASS_PROVIDER =
"com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider";