Skip to content

Commit

Permalink
Fix internal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Jun 16, 2021
1 parent e16fd18 commit ae0bb52
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,30 @@ public ActionExecutionContext withFileOutErr(FileOutErr fileOutErr) {
syscalls);
}

/**
* Allows us to create a new context that overrides the MetadataHandler with another one.
*/
public ActionExecutionContext withMetadataHandler(MetadataHandler metadataHandler) {
return new ActionExecutionContext(
executor,
actionInputFileCache,
actionInputPrefetcher,
actionKeyContext,
metadataHandler,
rewindingEnabled,
lostInputsCheck,
fileOutErr,
eventHandler,
clientEnv,
topLevelFilesets,
artifactExpander,
env,
actionFileSystem,
skyframeDepsResult,
nestedSetExpander,
syscalls);
}

/**
* A way of checking whether any lost inputs have been detected during the execution of this
* action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ private TestParams createTestAction(int shards)

Artifact.DerivedArtifact testLog =
ruleContext.getPackageRelativeArtifact(dir.getRelative("test.log"), root);
Artifact.DerivedArtifact testXml =
ruleContext.getPackageRelativeArtifact(dir.getRelative("test.xml"), root);
Artifact.DerivedArtifact cacheStatus =
ruleContext.getPackageRelativeArtifact(dir.getRelative("test.cache_status"), root);

Expand Down Expand Up @@ -419,7 +417,6 @@ private TestParams createTestAction(int shards)
testXmlGeneratorExecutable,
collectCoverageScript,
testLog,
testXml,
cacheStatus,
coverageArtifact,
coverageDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public class TestRunnerAction extends AbstractAction
private final BuildConfiguration configuration;
private final TestConfiguration testConfiguration;
private final Artifact testLog;
private final Artifact testXml;
private final Artifact cacheStatus;
private final PathFragment testWarningsPath;
private final PathFragment unusedRunfilesLogPath;
Expand All @@ -120,6 +119,7 @@ public class TestRunnerAction extends AbstractAction
private final PathFragment undeclaredOutputsAnnotationsDir;
private final PathFragment undeclaredOutputsManifestPath;
private final PathFragment undeclaredOutputsAnnotationsPath;
private final PathFragment xmlOutputPath;
@Nullable private final PathFragment testShard;
private final PathFragment testExitSafe;
private final PathFragment testStderr;
Expand Down Expand Up @@ -181,7 +181,6 @@ private static ImmutableSet<Artifact> nonNullAsSet(Artifact... artifacts) {
Artifact testXmlGeneratorScript, // Must be in inputs
@Nullable Artifact collectCoverageScript, // Must be in inputs, if not null
Artifact testLog,
Artifact testXml,
Artifact cacheStatus,
Artifact coverageArtifact,
@Nullable Artifact coverageDirectory,
Expand All @@ -203,7 +202,7 @@ private static ImmutableSet<Artifact> nonNullAsSet(Artifact... artifacts) {
NestedSetBuilder.wrap(Order.STABLE_ORDER, tools),
inputs,
runfilesSupplier,
nonNullAsSet(testLog, testXml, cacheStatus, coverageArtifact, coverageDirectory),
nonNullAsSet(testLog, cacheStatus, coverageArtifact, coverageDirectory),
configuration.getActionEnvironment());
Preconditions.checkState((collectCoverageScript == null) == (coverageArtifact == null));
this.testSetupScript = testSetupScript;
Expand All @@ -212,7 +211,6 @@ private static ImmutableSet<Artifact> nonNullAsSet(Artifact... artifacts) {
this.configuration = checkNotNull(configuration);
this.testConfiguration = checkNotNull(configuration.getFragment(TestConfiguration.class));
this.testLog = testLog;
this.testXml = testXml;
this.cacheStatus = cacheStatus;
this.coverageData = coverageArtifact;
this.coverageDirectory = coverageDirectory;
Expand All @@ -230,6 +228,7 @@ private static ImmutableSet<Artifact> nonNullAsSet(Artifact... artifacts) {
this.testExitSafe = baseDir.getChild("test.exited_prematurely");
// testShard Path should be set only if sharding is enabled.
this.testShard = totalShards > 1 ? baseDir.getChild("test.shard") : null;
this.xmlOutputPath = baseDir.getChild("test.xml");
this.testWarningsPath = baseDir.getChild("test.warnings");
this.unusedRunfilesLogPath = baseDir.getChild("test.unused_runfiles_log");
this.testStderr = baseDir.getChild("test.err");
Expand Down Expand Up @@ -266,6 +265,7 @@ private static ImmutableSet<Artifact> nonNullAsSet(Artifact... artifacts) {
ImmutableSet.Builder<PathFragment> filesToDeleteBuilder =
ImmutableSet.<PathFragment>builder()
.add(
xmlOutputPath,
testWarningsPath,
unusedRunfilesLogPath,
testStderr,
Expand Down Expand Up @@ -320,7 +320,7 @@ public boolean showsOutputUnconditionally() {

public List<ActionInput> getSpawnOutputs() {
final List<ActionInput> outputs = new ArrayList<>();
outputs.add(this.testXml);
outputs.add(ActionInputHelper.fromPath(getXmlOutputPath()));
outputs.add(ActionInputHelper.fromPath(getExitSafeFile()));
if (isSharded()) {
outputs.add(ActionInputHelper.fromPath(getTestShard()));
Expand Down Expand Up @@ -607,7 +607,7 @@ public void setupEnvVariables(Map<String, String> env, Duration timeout) {
env.put("TEST_TOTAL_SHARDS", Integer.toString(getExecutionSettings().getTotalShards()));
env.put("TEST_SHARD_STATUS_FILE", getTestShard().getPathString());
}
env.put("XML_OUTPUT_FILE", testXml.getExecPathString());
env.put("XML_OUTPUT_FILE", getXmlOutputPath().getPathString());

if (!isEnableRunfiles()) {
// If runfiles are disabled, tell remote-runtest.sh/local-runtest.sh about that.
Expand Down Expand Up @@ -666,10 +666,6 @@ public Artifact getTestLog() {
return testLog;
}

public Artifact getTestXml() {
return testXml;
}

/** Returns all environment variables which must be set in order to run this test. */
public ActionEnvironment getExtraTestEnv() {
return extraTestEnv;
Expand Down Expand Up @@ -735,6 +731,11 @@ public PathFragment getInfrastructureFailureFile() {
return testInfrastructureFailure;
}

/** Returns path to the optionally created XML output file created by the test. */
public PathFragment getXmlOutputPath() {
return xmlOutputPath;
}

/** Returns coverage data artifact or null if code coverage was not requested. */
@Nullable
public Artifact getCoverageData() {
Expand Down Expand Up @@ -1034,7 +1035,7 @@ public Path getInfrastructureFailureFile() {

/** Returns path to the optionally created XML output file created by the test. */
public Path getXmlOutputPath() {
return getPath(testXml.getExecPath());
return getPath(xmlOutputPath);
}

public Path getCoverageDirectory() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/exec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,14 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/actions:execution_requirements",
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata",
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/skyframe:tree_artifact_value",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
Expand Down
Loading

0 comments on commit ae0bb52

Please sign in to comment.