Set the local CPU reservation for tests based on their "cpu:<n>" tag.
This lets users specify that their test needs a minimum of <n> CPU cores
to run and not be flaky. Example for a reservation of 4 CPUs:
sh_test(
name = "test",
size = "large",
srcs = ["test.sh"],
tags = ["cpu:4"],
)
This could also be used by remote execution strategies to tune their
resource adjustment.
RELNOTES: You can increase the CPU reservation for tests by adding a "cpu:<n>" (e.g. "cpu:4" for four cores) tag to their rule in a BUILD file. This can be used if tests would otherwise overwhelm your system if there's too much parallelism.
PiperOrigin-RevId: 154856091
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 f63d519..58aed28 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
@@ -22,6 +22,7 @@
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.ExecutionStrategy;
import com.google.devtools.build.lib.actions.Executor;
+import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.actions.SimpleSpawn;
import com.google.devtools.build.lib.actions.Spawn;
import com.google.devtools.build.lib.actions.SpawnActionContext;
@@ -114,6 +115,12 @@
info.put("timeout", "" + getTimeout(action));
info.putAll(action.getTestProperties().getExecutionInfo());
+ ResourceSet localResourceUsage =
+ action
+ .getTestProperties()
+ .getLocalResourceUsage(
+ action.getOwner().getLabel(), executionOptions.usingLocalTestJobs());
+
Spawn spawn =
new SimpleSpawn(
action,
@@ -122,13 +129,11 @@
ImmutableMap.copyOf(info),
new RunfilesSupplierImpl(
runfilesDir.relativeTo(execRoot), action.getExecutionSettings().getRunfiles()),
- /*inputs=*/ImmutableList.copyOf(action.getInputs()),
- /*tools=*/ImmutableList.<Artifact>of(),
- /*filesetManifests=*/ImmutableList.<Artifact>of(),
+ /*inputs=*/ ImmutableList.copyOf(action.getInputs()),
+ /*tools=*/ ImmutableList.<Artifact>of(),
+ /*filesetManifests=*/ ImmutableList.<Artifact>of(),
ImmutableList.copyOf(action.getSpawnOutputs()),
- action
- .getTestProperties()
- .getLocalResourceUsage(executionOptions.usingLocalTestJobs()));
+ localResourceUsage);
Executor executor = actionExecutionContext.getExecutor();