aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skyframe
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skyframe')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java61
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java70
2 files changed, 128 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
index 5ca1354714..aae32548db 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
-import com.google.common.base.Predicates;
+import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -64,6 +64,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -82,6 +84,14 @@ public class ArtifactFunctionTest {
private static final SkyKey OWNER_KEY = new SkyKey(SkyFunctions.ACTION_LOOKUP, "OWNER");
private static final ActionLookupKey ALL_OWNER = new SingletonActionLookupKey();
+ private PathFragment allowedMissingInput = null;
+ private Predicate<PathFragment> allowedMissingInputsPredicate = new Predicate<PathFragment>() {
+ @Override
+ public boolean apply(PathFragment input) {
+ return input.equals(allowedMissingInput);
+ }
+ };
+
private Set<Action> actions;
private boolean fastDigest = false;
private RecordingDifferencer differencer = new RecordingDifferencer();
@@ -102,8 +112,7 @@ public class ArtifactFunctionTest {
ImmutableMap.<SkyFunctionName, SkyFunction>builder()
.put(SkyFunctions.FILE_STATE, new FileStateFunction(tsgm, externalFilesHelper))
.put(SkyFunctions.FILE, new FileFunction(pkgLocator))
- .put(SkyFunctions.ARTIFACT,
- new ArtifactFunction(Predicates.<PathFragment>alwaysFalse()))
+ .put(SkyFunctions.ARTIFACT, new ArtifactFunction(allowedMissingInputsPredicate))
.put(SkyFunctions.ACTION_EXECUTION, new SimpleActionExecutionFunction())
.put(SkyFunctions.PACKAGE,
new PackageFunction(null, null, null, null, null, null, null))
@@ -152,6 +161,52 @@ public class ArtifactFunctionTest {
}
@Test
+ public void testMissingMandatoryAllowedMissingArtifact() throws Throwable {
+ Artifact input = createSourceArtifact("allowedMissing");
+ allowedMissingInput = input.getRootRelativePath();
+ assertThat(evaluateArtifactValue(input, /*mandatory=*/ true))
+ .isEqualTo(FileArtifactValue.MISSING_FILE_MARKER);
+ }
+
+ @Test
+ public void testUnreadableMandatoryAllowedMissingArtifact() throws Throwable {
+ Artifact input = createSourceArtifact("allowedMissing");
+ file(input.getPath(), "allowedMissing");
+ input.getPath().chmod(0);
+
+ allowedMissingInput = input.getRootRelativePath();
+ assertThat(evaluateArtifactValue(input, /*mandatory=*/ true))
+ .isEqualTo(FileArtifactValue.MISSING_FILE_MARKER);
+ }
+
+ @Test
+ public void testUnreadableInputWithFsWithAvailableDigest() throws Throwable {
+ final byte[] expectedDigest = MessageDigest.getInstance("md5").digest(
+ "someunreadablecontent".getBytes(StandardCharsets.UTF_8));
+ setupRoot(
+ new CustomInMemoryFs() {
+ @Override
+ public byte[] getMD5Digest(Path path) throws IOException {
+ return path.getBaseName().equals("unreadable")
+ ? expectedDigest
+ : super.getMD5Digest(path);
+ }
+ });
+
+ Artifact input = createSourceArtifact("unreadable");
+ Path inputPath = input.getPath();
+ file(inputPath, "dummynotused");
+ inputPath.chmod(0);
+
+ FileArtifactValue value =
+ (FileArtifactValue) evaluateArtifactValue(input, /*mandatory=*/ true);
+
+ FileStatus stat = inputPath.stat();
+ assertThat(value.getSize()).isEqualTo(stat.getSize());
+ assertThat(value.getDigest()).isEqualTo(expectedDigest);
+ }
+
+ @Test
public void testMissingMandatoryArtifact() throws Throwable {
Artifact input = createSourceArtifact("input1");
try {
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
index 873d48d10f..d9cce8b9c4 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
@@ -76,6 +76,8 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -437,6 +439,44 @@ public class FileFunctionTest {
}
@Test
+ public void testUnreadableFileWithNoFastDigest() throws Exception {
+ Path p = file("unreadable");
+ p.chmod(0);
+ p.setLastModifiedTime(0L);
+
+ FileValue value = valueForPath(p);
+ assertTrue(value.exists());
+ assertThat(value.getDigest()).isNull();
+
+ p.setLastModifiedTime(10L);
+ assertThat(valueForPath(p)).isNotEqualTo(value);
+
+ p.setLastModifiedTime(0L);
+ assertThat(valueForPath(p)).isEqualTo(value);
+ }
+
+ @Test
+ public void testUnreadableFileWithFastDigest() throws Exception {
+ final byte[] expectedDigest = MessageDigest.getInstance("md5").digest(
+ "blah".getBytes(StandardCharsets.UTF_8));
+
+ createFsAndRoot(
+ new CustomInMemoryFs(manualClock) {
+ @Override
+ protected byte[] getFastDigest(Path path) {
+ return path.getBaseName().equals("unreadable") ? expectedDigest : null;
+ }
+ });
+
+ Path p = file("unreadable");
+ p.chmod(0);
+
+ FileValue value = valueForPath(p);
+ assertThat(value.exists()).isTrue();
+ assertThat(value.getDigest()).isNotNull();
+ }
+
+ @Test
public void testFileModificationModTime() throws Exception {
fastMd5 = false;
Path p = file("file");
@@ -882,6 +922,36 @@ public class FileFunctionTest {
assertThat(errorInfo.getException().getMessage()).contains("/root/a is no longer a file");
}
+ @Test
+ public void testFilesystemInconsistencies_GetFastDigestAndIsReadableFailure() throws Exception {
+ createFsAndRoot(
+ new CustomInMemoryFs(manualClock) {
+ @Override
+ protected boolean isReadable(Path path) throws IOException {
+ if (path.getBaseName().equals("unreadable")) {
+ throw new IOException("isReadable failed");
+ }
+ return super.isReadable(path);
+ }
+ });
+
+ Path p = file("unreadable");
+ p.chmod(0);
+
+ SequentialBuildDriver driver = makeDriver();
+ SkyKey skyKey = skyKey("unreadable");
+ EvaluationResult<FileValue> result =
+ driver.evaluate(
+ ImmutableList.of(skyKey), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
+ assertTrue(result.hasError());
+ ErrorInfo errorInfo = result.getError(skyKey);
+ assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class);
+ assertThat(errorInfo.getException().getMessage())
+ .contains("encountered error 'isReadable failed'");
+ assertThat(errorInfo.getException().getMessage())
+ .contains("/root/unreadable is no longer a file");
+ }
+
private void runTestSymlinkCycle(boolean ancestorCycle, boolean startInCycle) throws Exception {
symlink("a", "b");
symlink("b", "c");