aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2016-08-26 13:01:20 +0000
committerGravatar John Cater <jcater@google.com>2016-08-26 18:42:15 +0000
commit6488b3bc824a0f19ad2924d5f7c87181f06beed9 (patch)
treec1e033f79baef50f7b93f9a83d27d8cc4ec5fb8d /src/test/java/com/google
parent3330528d760db4eb45b91f0777536414904be97f (diff)
sandbox: Allow network access for builds by default.
This solves a performance issue that slowed down builds by about 40% at least on Linux, due to clone() with CLONE_NEWNET becoming extremely slow (>1 second) for highly parallel builds. See this thread for a discussion: https://lkml.org/lkml/2014/8/20/40 For the sake of consistency, we apply the same policy on OS X, too. If we find a better way to block network access for processes on Linux that doesn't have this performance hit, we will revisit this. RELNOTES: Sandboxed builds allow network access for builds by default. Tests will still be run without networking, unless "requires-network" is specified as a tag. -- MOS_MIGRATED_REVID=131393514
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java73
-rw-r--r--src/test/java/com/google/devtools/build/lib/sandbox/LocalLinuxSandboxedStrategyTest.java84
-rw-r--r--src/test/java/com/google/devtools/build/lib/sandbox/SandboxLocalTests.java38
3 files changed, 0 insertions, 195 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java b/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java
index a80074a9fa..c9e96501fa 100644
--- a/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java
@@ -13,29 +13,11 @@
// limitations under the License.
package com.google.devtools.build.lib.sandbox;
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.eventbus.EventBus;
-import com.google.common.util.concurrent.MoreExecutors;
-import com.google.devtools.build.lib.actions.ActionContextProvider;
-import com.google.devtools.build.lib.actions.BlazeExecutor;
-import com.google.devtools.build.lib.actions.Executor.ActionContext;
-import com.google.devtools.build.lib.actions.SpawnActionContext;
-import com.google.devtools.build.lib.analysis.BlazeDirectories;
-import com.google.devtools.build.lib.events.PrintingEventHandler;
-import com.google.devtools.build.lib.events.Reporter;
-import com.google.devtools.build.lib.exec.ExecutionOptions;
-import com.google.devtools.build.lib.testutil.BlazeTestUtils;
-import com.google.devtools.build.lib.testutil.TestFileOutErr;
import com.google.devtools.build.lib.testutil.TestUtils;
-import com.google.devtools.build.lib.util.BlazeClock;
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.common.options.OptionsParser;
import java.io.IOException;
import org.junit.Before;
@@ -43,70 +25,15 @@ import org.junit.Before;
* Common parts of all {@link LinuxSandboxedStrategy} tests.
*/
public class LinuxSandboxedStrategyTestCase {
- private Reporter reporter = new Reporter(PrintingEventHandler.ERRORS_AND_WARNINGS_TO_STDERR);
- private Path outputBase;
-
protected FileSystem fileSystem;
protected Path workspaceDir;
- protected BlazeExecutor executor;
- protected BlazeDirectories blazeDirs;
-
- protected TestFileOutErr outErr = new TestFileOutErr();
-
- protected String out() {
- return outErr.outAsLatin1();
- }
-
- protected String err() {
- return outErr.errAsLatin1();
- }
-
@Before
public final void createDirectoriesAndExecutor() throws Exception {
Path testRoot = createTestRoot();
workspaceDir = testRoot.getRelative("workspace");
workspaceDir.createDirectory();
-
- outputBase = testRoot.getRelative("outputBase");
- outputBase.createDirectory();
-
- blazeDirs = new BlazeDirectories(outputBase, outputBase, workspaceDir, "mock-product-name");
- BlazeTestUtils.getIntegrationBinTools(blazeDirs);
-
- OptionsParser optionsParser =
- OptionsParser.newOptionsParser(ExecutionOptions.class, SandboxOptions.class);
-
- EventBus bus = new EventBus();
-
- this.executor =
- new BlazeExecutor(
- blazeDirs.getExecRoot(),
- blazeDirs.getOutputPath(),
- reporter,
- bus,
- BlazeClock.instance(),
- optionsParser,
- /* verboseFailures */ true,
- /* showSubcommands */ false,
- ImmutableList.<ActionContext>of(),
- ImmutableMap.<String, SpawnActionContext>of(
- "",
- new LinuxSandboxedStrategy(
- optionsParser.getOptions(SandboxOptions.class),
- blazeDirs,
- MoreExecutors.newDirectExecutorService(),
- true,
- false,
- "mock-product-name")),
- ImmutableList.<ActionContextProvider>of());
- }
-
- protected LinuxSandboxedStrategy getLinuxSandboxedStrategy() {
- SpawnActionContext spawnActionContext = executor.getSpawnActionContext("");
- assertThat(spawnActionContext).isInstanceOf(LinuxSandboxedStrategy.class);
- return (LinuxSandboxedStrategy) spawnActionContext;
}
private Path createTestRoot() throws IOException {
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/LocalLinuxSandboxedStrategyTest.java b/src/test/java/com/google/devtools/build/lib/sandbox/LocalLinuxSandboxedStrategyTest.java
deleted file mode 100644
index abf8630fe4..0000000000
--- a/src/test/java/com/google/devtools/build/lib/sandbox/LocalLinuxSandboxedStrategyTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2015 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.sandbox;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.devtools.build.lib.actions.ActionExecutionContext;
-import com.google.devtools.build.lib.actions.ActionExecutionMetadata;
-import com.google.devtools.build.lib.actions.BaseSpawn;
-import com.google.devtools.build.lib.actions.ResourceSet;
-import com.google.devtools.build.lib.actions.Spawn;
-import com.google.devtools.build.lib.actions.UserExecException;
-import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
-import com.google.devtools.build.lib.exec.SingleBuildFileCache;
-import com.google.devtools.build.lib.shell.BadExitStatusException;
-import com.google.devtools.build.lib.testutil.TestSpec;
-import com.google.devtools.build.lib.util.OS;
-import com.google.devtools.build.lib.vfs.Path;
-import java.util.Arrays;
-import java.util.Map;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Tests for {@code LinuxSandboxedStrategy} that must run locally, because they need to actually run
- * the linux-sandbox binary.
- */
-@TestSpec(localOnly = true, supportedOs = OS.LINUX)
-@RunWith(JUnit4.class)
-public class LocalLinuxSandboxedStrategyTest extends LinuxSandboxedStrategyTestCase {
- protected Spawn createSpawn(String... arguments) {
- Map<String, String> environment = ImmutableMap.<String, String>of();
- Map<String, String> executionInfo = ImmutableMap.<String, String>of();
- ActionExecutionMetadata action = new ActionsTestUtil.NullAction();
- ResourceSet localResources = ResourceSet.ZERO;
- return new BaseSpawn(
- Arrays.asList(arguments), environment, executionInfo, action, localResources);
- }
-
- protected ActionExecutionContext createContext() {
- Path execRoot = executor.getExecRoot();
- return new ActionExecutionContext(
- executor,
- new SingleBuildFileCache(execRoot.getPathString(), execRoot.getFileSystem()),
- null,
- outErr,
- ImmutableMap.of(),
- null);
- }
-
- @Test
- public void testExecutionSuccess() throws Exception {
- Spawn spawn = createSpawn("/bin/sh", "-c", "echo Hello, world.; touch dummy");
- getLinuxSandboxedStrategy().exec(spawn, createContext());
- assertThat(out()).isEqualTo("Hello, world.\n");
- assertThat(err()).isEmpty();
- }
-
- @Test
- public void testExecutionFailurePrintsCorrectMessage() throws Exception {
- Spawn spawn = createSpawn("/bin/sh", "-c", "echo ERROR >&2; exit 1");
- try {
- getLinuxSandboxedStrategy().exec(spawn, createContext());
- fail();
- } catch (UserExecException e) {
- assertThat(err()).isEqualTo("ERROR\n");
- assertThat(e.getCause()).isInstanceOf(BadExitStatusException.class);
- }
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/SandboxLocalTests.java b/src/test/java/com/google/devtools/build/lib/sandbox/SandboxLocalTests.java
deleted file mode 100644
index 55bf209084..0000000000
--- a/src/test/java/com/google/devtools/build/lib/sandbox/SandboxLocalTests.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2015 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.sandbox;
-
-import com.google.common.base.Predicates;
-import com.google.devtools.build.lib.testutil.BlazeTestSuiteBuilder;
-import com.google.devtools.build.lib.testutil.CustomSuite;
-
-import org.junit.runner.RunWith;
-
-import java.util.Set;
-
-/**
- * Test suite that runs all tests that are local-only.
- */
-@RunWith(CustomSuite.class)
-public class SandboxLocalTests extends BlazeTestSuiteBuilder {
- public static Set<Class<?>> suite() {
- return new SandboxLocalTests()
- .getBuilder()
- .matchClasses(
- Predicates.and(
- BlazeTestSuiteBuilder.TEST_IS_LOCAL_ONLY,
- BlazeTestSuiteBuilder.TEST_SUPPORTS_CURRENT_OS))
- .create();
- }
-}