aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2017-01-20 13:54:28 +0000
committerGravatar Vladimir Moskva <vladmos@google.com>2017-01-20 15:44:32 +0000
commitd9de6717261c71ec8077e98d8a361175340bcce8 (patch)
tree2c03087e9574b0bee98396e3e2128c9ca3d00d58 /src/main
parentc51d506eb83f1e5974e3317c53532f6e81ca50d8 (diff)
Move the coverage-related methods from TestStrategy to TestRunnerAction.
This seems like an obvious cleanup, and I also want to move most of the test-specific environment setup to TestRunnerAction, which is simpler after this change. -- PiperOrigin-RevId: 145076829 MOS_MIGRATED_REVID=145076829
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java36
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java28
3 files changed, 34 insertions, 40 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
index 9b2e1d3ab8..b6c8443d84 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
@@ -41,7 +41,6 @@ import com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths;
import com.google.devtools.build.lib.util.io.FileOutErr;
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.view.test.TestStatus.BlazeTestStatus;
import com.google.devtools.build.lib.view.test.TestStatus.TestCase;
import com.google.devtools.build.lib.view.test.TestStatus.TestResultData;
@@ -77,7 +76,7 @@ public class StandaloneTestStrategy extends TestStrategy {
public void exec(TestRunnerAction action, ActionExecutionContext actionExecutionContext)
throws ExecException, InterruptedException {
Path execRoot = actionExecutionContext.getExecutor().getExecRoot();
- Path coverageDir = execRoot.getRelative(getCoverageDirectory(action));
+ Path coverageDir = execRoot.getRelative(action.getCoverageDirectory());
Path runfilesDir =
getLocalRunfilesDirectory(
action,
@@ -258,9 +257,8 @@ public class StandaloneTestStrategy extends TestStrategy {
env.put("RUNFILES_MANIFEST_ONLY", "1");
}
- PathFragment coverageDir = TestStrategy.getCoverageDirectory(action);
- if (isCoverageMode(action)) {
- env.put("COVERAGE_DIR", coverageDir.toString());
+ if (action.isCoverageMode()) {
+ env.put("COVERAGE_DIR", action.getCoverageDirectory().toString());
env.put("COVERAGE_OUTPUT_FILE", action.getCoverageData().getExecPathString());
}
@@ -326,7 +324,7 @@ public class StandaloneTestStrategy extends TestStrategy {
builder.setTestCase(details);
}
- if (isCoverageMode(action)) {
+ if (action.isCoverageMode()) {
builder.setHasCoverage(true);
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
index 96d8798c68..1cf2033600 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
@@ -58,15 +58,8 @@ import javax.annotation.Nullable;
/** A strategy for executing a {@link TestRunnerAction}. */
public abstract class TestStrategy implements TestActionContext {
- public static final PathFragment COVERAGE_TMP_ROOT = new PathFragment("_coverage");
-
public static final String TEST_SETUP_BASENAME = "test-setup.sh";
- /** Returns true if coverage data should be gathered. */
- protected static boolean isCoverageMode(TestRunnerAction action) {
- return action.getCoverageData() != null;
- }
-
/**
* Ensures that all directories used to run test are in the correct state and their content will
* not result in stale files.
@@ -74,7 +67,7 @@ public abstract class TestStrategy implements TestActionContext {
protected void prepareFileSystem(
TestRunnerAction testAction, Path tmpDir, Path coverageDir, Path workingDirectory)
throws IOException {
- if (isCoverageMode(testAction)) {
+ if (testAction.isCoverageMode()) {
recreateDirectory(coverageDir);
}
recreateDirectory(tmpDir);
@@ -161,27 +154,6 @@ public abstract class TestStrategy implements TestActionContext {
public abstract void exec(TestRunnerAction action, ActionExecutionContext actionExecutionContext)
throws ExecException, InterruptedException;
- /** Returns true if coverage data should be gathered. */
- protected static boolean isMicroCoverageMode(TestRunnerAction action) {
- return action.getMicroCoverageData() != null;
- }
-
- /**
- * Returns directory to store coverage results for the given action relative to the execution
- * root. This directory is used to store all coverage results related to the test execution with
- * exception of the locally generated *.gcda files. Those are stored separately using relative
- * path within coverage directory.
- *
- * <p>Coverage directory name for the given test runner action is constructed as: {@code $(blaze
- * info execution_root)/_coverage/target_path/test_log_name} where {@code test_log_name} is
- * usually a target name but potentially can include extra suffix, such as a shard number (if test
- * execution was sharded).
- */
- protected static PathFragment getCoverageDirectory(TestRunnerAction action) {
- return COVERAGE_TMP_ROOT.getRelative(
- FileSystemUtils.removeExtension(action.getTestLog().getRootRelativePath()));
- }
-
/**
* Returns mutable map of default testing shell environment. By itself it is incomplete and is
* modified further by the specific test strategy implementations (mostly due to the fact that
@@ -212,13 +184,13 @@ public abstract class TestStrategy implements TestActionContext {
env.put(TEST_BRIDGE_TEST_FILTER_ENV, testFilter);
}
- if (isCoverageMode(action)) {
+ if (action.isCoverageMode()) {
env.put(
"COVERAGE_MANIFEST",
action.getExecutionSettings().getInstrumentedFileManifest().getExecPathString());
// Instruct remote-runtest.sh/local-runtest.sh not to cd into the runfiles directory.
env.put("RUNTEST_PRESERVE_CWD", "1");
- env.put("MICROCOVERAGE_REQUESTED", isMicroCoverageMode(action) ? "true" : "false");
+ env.put("MICROCOVERAGE_REQUESTED", action.isMicroCoverageMode() ? "true" : "false");
}
return env;
@@ -246,7 +218,7 @@ public abstract class TestStrategy implements TestActionContext {
TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
List<String> execArgs = new ArrayList<>();
- if (!coverageScript.isEmpty() && isCoverageMode(testAction)) {
+ if (!coverageScript.isEmpty() && testAction.isCoverageMode()) {
execArgs.add(coverageScript);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java b/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java
index 20607f4714..a69d45c959 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java
@@ -40,14 +40,12 @@ import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.test.TestStatus.TestResultData;
import com.google.devtools.common.options.TriState;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
-
import javax.annotation.Nullable;
/**
@@ -57,6 +55,7 @@ import javax.annotation.Nullable;
*/
// Not final so that we can mock it in tests.
public class TestRunnerAction extends AbstractAction implements NotifyOnActionCacheHit {
+ public static final PathFragment COVERAGE_TMP_ROOT = new PathFragment("_coverage");
private static final String GUID = "94857c93-f11c-4cbc-8c1b-e0a281633f9e";
@@ -475,6 +474,11 @@ public class TestRunnerAction extends AbstractAction implements NotifyOnActionCa
return coverageData;
}
+ /** Returns true if coverage data should be gathered. */
+ public boolean isCoverageMode() {
+ return coverageData != null;
+ }
+
/**
* @return microcoverage data artifact or null if code coverage was not requested.
*/
@@ -482,6 +486,26 @@ public class TestRunnerAction extends AbstractAction implements NotifyOnActionCa
return microCoverageData;
}
+ /** Returns true if micro-coverage data should be gathered. */
+ public boolean isMicroCoverageMode() {
+ return microCoverageData != null;
+ }
+
+ /**
+ * Returns a directory to temporarily store coverage results for the given action relative to the
+ * execution root. This directory is used to store all coverage results related to the test
+ * execution with exception of the locally generated *.gcda files. Those are stored separately
+ * using relative path within coverage directory.
+ *
+ * <p>The directory name for the given test runner action is constructed as: {@code
+ * _coverage/target_path/test_log_name} where {@code test_log_name} is usually a target name but
+ * potentially can include extra suffix, such as a shard number (if test execution was sharded).
+ */
+ public PathFragment getCoverageDirectory() {
+ return COVERAGE_TMP_ROOT.getRelative(
+ FileSystemUtils.removeExtension(getTestLog().getRootRelativePath()));
+ }
+
public TestTargetProperties getTestProperties() {
return testProperties;
}