aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Yue Gan <yueg@google.com>2017-03-20 10:58:11 +0000
committerGravatar Yue Gan <yueg@google.com>2017-03-20 11:47:24 +0000
commit5e60e3868b4bafacc138f786b304589dbd687016 (patch)
treec0d85fc4347b7ff67225bead1834ed19cc021e74 /src/test
parent2cea8bc6e17b4df623ed73155c6be7a97cfbe957 (diff)
*** Reason for rollback *** Break bazel-tests and many other jobs on CI. http://ci.bazel.io/job/bazel-tests/BAZEL_VERSION=HEAD,PLATFORM_NAME=linux-x86_64/651/console *** Original change description *** Add SpawnInputExpander helper class to arrange runfiles for spawn strategies This new class is a combination of SpawnHelper and our internal code; the plan is to migrate all spawn strategies to the new class. The strict flag should be enabled by default, but that's a breaking change, so we need to do it later. - Use it in SandboxStrategy. - Add ActionInput.getExecPath to return a PathFragment; this avoids lots of back and forth between path fragments and strings. This is a step towards #159... *** -- PiperOrigin-RevId: 150610616 MOS_MIGRATED_REVID=150610616
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/exec/DigestTest.java8
-rw-r--r--src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java242
2 files changed, 1 insertions, 249 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/exec/DigestTest.java b/src/test/java/com/google/devtools/build/lib/exec/DigestTest.java
index 27edca06d2..b610641144 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/DigestTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/DigestTest.java
@@ -23,7 +23,6 @@ import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
import com.google.devtools.build.lib.testutil.Suite;
import com.google.devtools.build.lib.testutil.TestSpec;
import com.google.devtools.build.lib.util.Pair;
-import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.io.OutputStream;
@@ -62,7 +61,7 @@ public class DigestTest {
"8b1a9953c4611296a827abf8c47804d7",
Digest.fromContent("Hello".getBytes(UTF_8)).toStringUtf8());
- assertEquals(UGLY_DIGEST, Digest.fromContent(UGLY.getBytes(UTF_8)).toStringUtf8());
+ assertEquals(UGLY_DIGEST, Digest.fromContent(UGLY.getBytes()).toStringUtf8());
// ByteBuffer digest not idempotent because ByteBuffer manages a "position" internally.
ByteBuffer buffer = ByteBuffer.wrap(UGLY.getBytes(UTF_8));
@@ -107,11 +106,6 @@ public class DigestTest {
public String getExecPathString() {
throw new UnsupportedOperationException();
}
-
- @Override
- public PathFragment getExecPath() {
- throw new UnsupportedOperationException();
- }
});
assertEquals(UGLY_DIGEST, result.first.toStringUtf8());
assertEquals(UGLY.length(), result.second.longValue());
diff --git a/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java b/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java
deleted file mode 100644
index fdfa655371..0000000000
--- a/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java
+++ /dev/null
@@ -1,242 +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.exec;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.collect.Maps;
-import com.google.devtools.build.lib.actions.ActionInput;
-import com.google.devtools.build.lib.actions.ActionInputFileCache;
-import com.google.devtools.build.lib.actions.ActionInputHelper;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.EmptyRunfilesSupplier;
-import com.google.devtools.build.lib.actions.Root;
-import com.google.devtools.build.lib.actions.RunfilesSupplier;
-import com.google.devtools.build.lib.analysis.Runfiles;
-import com.google.devtools.build.lib.analysis.RunfilesSupplierImpl;
-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.PathFragment;
-import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.mockito.Mockito;
-
-/**
- * Tests for {@link SpawnInputExpander}.
- */
-@RunWith(JUnit4.class)
-public class SpawnInputExpanderTest {
- private FileSystem fs;
- private SpawnInputExpander expander;
- private Map<PathFragment, ActionInput> inputMappings;
-
- @Before
- public final void createSpawnInputExpander() throws Exception {
- fs = new InMemoryFileSystem();
- expander = new SpawnInputExpander(/*strict=*/true);
- inputMappings = Maps.newHashMap();
- }
-
- private void scratchFile(String file, String... lines) throws Exception {
- Path path = fs.getPath(file);
- FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
- FileSystemUtils.writeLinesAs(path, StandardCharsets.UTF_8, lines);
- }
-
- @Test
- public void testEmptyRunfiles() throws Exception {
- RunfilesSupplier supplier = EmptyRunfilesSupplier.INSTANCE;
- expander.addRunfilesToInputs(inputMappings, supplier, null);
- assertThat(inputMappings).isEmpty();
- }
-
- @Test
- public void testRunfilesSingleFile() throws Exception {
- Artifact artifact =
- new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
- Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
- ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
- Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
-
- expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
- assertThat(inputMappings).hasSize(1);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact);
- }
-
- @Test
- public void testRunfilesDirectoryStrict() throws Exception {
- Artifact artifact =
- new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
- Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
- ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
- Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
-
- try {
- expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
- fail();
- } catch (IOException expected) {
- assertThat(expected.getMessage().contains("Not a file: /root/dir/file")).isTrue();
- }
- }
-
- @Test
- public void testRunfilesDirectoryNonStrict() throws Exception {
- Artifact artifact =
- new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
- Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
- ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
- Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
-
- expander = new SpawnInputExpander(/*strict=*/false);
- expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
- assertThat(inputMappings).hasSize(1);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact);
- }
-
- @Test
- public void testRunfilesTwoFiles() throws Exception {
- Artifact artifact1 =
- new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
- Artifact artifact2 =
- new Artifact(fs.getPath("/root/dir/baz"), Root.asSourceRoot(fs.getPath("/root")));
- Runfiles runfiles = new Runfiles.Builder("workspace")
- .addArtifact(artifact1)
- .addArtifact(artifact2)
- .build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
- ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
- Mockito.when(mockCache.isFile(artifact1)).thenReturn(true);
- Mockito.when(mockCache.isFile(artifact2)).thenReturn(true);
-
- expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
- assertThat(inputMappings).hasSize(2);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact1);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/baz"), artifact2);
- }
-
- @Test
- public void testRunfilesSymlink() throws Exception {
- Artifact artifact =
- new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
- Runfiles runfiles = new Runfiles.Builder("workspace")
- .addSymlink(new PathFragment("symlink"), artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
- ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
- Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
-
- expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
- assertThat(inputMappings).hasSize(1);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/symlink"), artifact);
- }
-
- @Test
- public void testRunfilesRootSymlink() throws Exception {
- Artifact artifact =
- new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
- Runfiles runfiles = new Runfiles.Builder("workspace")
- .addRootSymlink(new PathFragment("symlink"), artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
- ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
- Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
-
- expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
- assertThat(inputMappings).hasSize(2);
- assertThat(inputMappings).containsEntry(new PathFragment("runfiles/symlink"), artifact);
- // If there's no other entry, Runfiles adds an empty file in the workspace to make sure the
- // directory gets created.
- assertThat(inputMappings)
- .containsEntry(
- new PathFragment("runfiles/workspace/.runfile"), SpawnInputExpander.EMPTY_FILE);
- }
-
- @Test
- public void testEmptyManifest() throws Exception {
- // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST".
- scratchFile("/root/_foo/MANIFEST");
-
- Artifact artifact =
- new Artifact(fs.getPath("/root/foo"), Root.asSourceRoot(fs.getPath("/root")));
- expander.parseFilesetManifest(inputMappings, artifact, "workspace");
- assertThat(inputMappings).isEmpty();
- }
-
- @Test
- public void testManifestWithSingleFile() throws Exception {
- // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST".
- scratchFile(
- "/root/_foo/MANIFEST",
- "workspace/bar /dir/file",
- "<some digest>");
-
- Artifact artifact =
- new Artifact(fs.getPath("/root/foo"), Root.asSourceRoot(fs.getPath("/root")));
- expander.parseFilesetManifest(inputMappings, artifact, "workspace");
- assertThat(inputMappings).hasSize(1);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("foo/bar"), ActionInputHelper.fromPath("/dir/file"));
- }
-
- @Test
- public void testManifestWithTwoFiles() throws Exception {
- // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST".
- scratchFile(
- "/root/_foo/MANIFEST",
- "workspace/bar /dir/file",
- "<some digest>",
- "workspace/baz /dir/file",
- "<some digest>");
-
- Artifact artifact =
- new Artifact(fs.getPath("/root/foo"), Root.asSourceRoot(fs.getPath("/root")));
- expander.parseFilesetManifest(inputMappings, artifact, "workspace");
- assertThat(inputMappings).hasSize(2);
- assertThat(inputMappings)
- .containsEntry(new PathFragment("foo/bar"), ActionInputHelper.fromPath("/dir/file"));
- assertThat(inputMappings)
- .containsEntry(new PathFragment("foo/baz"), ActionInputHelper.fromPath("/dir/file"));
- }
-
- @Test
- public void testManifestWithDirectory() throws Exception {
- // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST".
- scratchFile(
- "/root/_foo/MANIFEST",
- "workspace/bar /some",
- "<some digest>");
-
- Artifact artifact =
- new Artifact(fs.getPath("/root/foo"), Root.asSourceRoot(fs.getPath("/root")));
- expander.parseFilesetManifest(inputMappings, artifact, "workspace");
- assertThat(inputMappings).hasSize(1);
- assertThat(inputMappings)
- .containsEntry(
- new PathFragment("foo/bar"), ActionInputHelper.fromPath("/some"));
- }
-}