Allow --local_test_jobs to take a keyword ('HOST_RAM', 'HOST_CPUS' 'auto'), or [keyword][-|*]<float>.
Allows users to tune flag relative to host resources or to our auto value.
This enables us to tune an auto value for this flag that reflects host
capacity, and allows users to select a value relative to their host capacity.
Currently, passing "auto" just returns the default value, 0, which does not cap
local test jobs.
RELNOTES: None.
PiperOrigin-RevId: 226506239
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java
index 35f1a55..54b5b6f 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java
@@ -274,11 +274,6 @@
List<String> warnings = new ArrayList<>();
int localTestJobs = getExecutionOptions().localTestJobs;
- if (localTestJobs < 0) {
- throw new InvalidConfigurationException(String.format(
- "Invalid parameter for --local_test_jobs: %d. Only values 0 or greater are "
- + "allowed.", localTestJobs));
- }
int jobs = getBuildOptions().jobs;
if (localTestJobs > jobs) {
warnings.add(
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index 34aeffb..e0d9c33 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -19,6 +19,7 @@
import com.google.devtools.build.lib.analysis.config.PerLabelOptions;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.util.RegexFilter;
+import com.google.devtools.build.lib.util.ResourceConverter;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.BoolOrEnumConverter;
import com.google.devtools.common.options.Option;
@@ -250,15 +251,18 @@
public boolean localMemoryEstimate;
@Option(
- name = "local_test_jobs",
- defaultValue = "0",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help =
- "The max number of local test jobs to run concurrently. "
- + "0 means local resources will limit the number of local test jobs to run "
- + "concurrently instead. Setting this greater than the value for --jobs is ineffectual."
- )
+ name = "local_test_jobs",
+ defaultValue = "auto",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help =
+ "The max number of local test jobs to run concurrently. "
+ + "Takes "
+ + ResourceConverter.FLAG_SYNTAX
+ + ". 0 means local resources will limit the number of local test jobs to run "
+ + "concurrently instead. Setting this greater than the value for --jobs "
+ + "is ineffectual.",
+ converter = LocalTestJobsConverter.class)
public int localTestJobs;
public boolean usingLocalTestJobs() {
@@ -387,6 +391,13 @@
}
}
+ /** Converter for --local_test_jobs, which takes {@value FLAG_SYNTAX} */
+ public static class LocalTestJobsConverter extends ResourceConverter {
+ public LocalTestJobsConverter() throws OptionsParsingException {
+ super(/* autoSupplier= */ () -> 0, /* minValue= */ 0, /* maxValue= */ Integer.MAX_VALUE);
+ }
+ }
+
/** Converter for --subcommands */
public static class ShowSubcommandsConverter extends BoolOrEnumConverter<ShowSubcommands> {
public ShowSubcommandsConverter() {
diff --git a/src/test/java/com/google/devtools/build/lib/exec/LocalTestJobsTest.java b/src/test/java/com/google/devtools/build/lib/exec/LocalTestJobsTest.java
new file mode 100644
index 0000000..db6f5fe
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/exec/LocalTestJobsTest.java
@@ -0,0 +1,48 @@
+// Copyright 2018 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 com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
+
+import com.google.devtools.build.lib.exec.ExecutionOptions.LocalTestJobsConverter;
+import com.google.devtools.common.options.OptionsParsingException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests {@link com.google.devtools.build.lib.exec.ExecutionOptions.LocalTestJobsConverter}. */
+@RunWith(JUnit4.class)
+public class LocalTestJobsTest {
+
+ private LocalTestJobsConverter localTestJobsConverter;
+
+ @Before
+ public void setUp() throws OptionsParsingException {
+ localTestJobsConverter = new LocalTestJobsConverter();
+ }
+
+ @Test
+ public void testLocalTestJobsMustBePositive() throws OptionsParsingException {
+ OptionsParsingException thrown =
+ assertThrows(OptionsParsingException.class, () -> localTestJobsConverter.convert("-1"));
+ assertThat(thrown).hasMessageThat().contains("must be at least 0");
+ }
+
+ @Test
+ public void testLocalTestJobsAutoIsZero() throws OptionsParsingException {
+ assertThat(localTestJobsConverter.convert("auto")).isEqualTo(0);
+ }
+}
diff --git a/src/test/shell/integration/bazel_testjobs_test.sh b/src/test/shell/integration/bazel_testjobs_test.sh
index 59848c7..1c02b71 100755
--- a/src/test/shell/integration/bazel_testjobs_test.sh
+++ b/src/test/shell/integration/bazel_testjobs_test.sh
@@ -127,12 +127,4 @@
expect_log 'High value for --local_test_jobs'
}
-function test_negative_local_test_jobs_causes_warning() {
- create_test_files
- bazel test --local_test_jobs=-1 --local_resources=10000,10,100 --runs_per_test=10 \
- //dir:test >& $TEST_log && fail "Expected test failure"
-
- expect_log 'Invalid parameter for --local_test_jobs'
-}
-
run_suite "Tests for --local_test_jobs option."