-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce --default_test_resources flag
Add `--default_test_resources=<resource>=<value(s)>` that allows setting the default resource utilization for tests. The flag follow a syntax simialar to `--local_resources=<resource>=<value>`, in that it allow assigning different resource types, and `--test_timeout=<value(s)>`, which accepts either 1 or 4 intergers to assign to all test sizes or to each individually. Relates to #19679 Closes #20839. PiperOrigin-RevId: 606233269 Change-Id: Ia53e42820ba9aa646b0600fe4e9f95f146d7b2b9
- Loading branch information
1 parent
aab2d14
commit e8b3682
Showing
5 changed files
with
158 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/google/devtools/build/lib/analysis/test/TestResourcesConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2024 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.analysis.test; | ||
|
||
import com.google.common.base.Splitter; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Maps; | ||
import com.google.devtools.build.lib.packages.TestSize; | ||
import com.google.devtools.build.lib.util.Pair; | ||
import com.google.devtools.build.lib.util.ResourceConverter; | ||
import com.google.devtools.common.options.Converter; | ||
import com.google.devtools.common.options.Converters; | ||
import com.google.devtools.common.options.OptionsParsingException; | ||
import java.util.ArrayList; | ||
import java.util.EnumMap; | ||
import java.util.Map; | ||
|
||
public class TestResourcesConverter | ||
extends Converter.Contextless<Pair<String, Map<TestSize, Double>>> { | ||
private static final Converters.AssignmentConverter assignmentConverter = | ||
new Converters.AssignmentConverter(); | ||
private static final ResourceConverter.DoubleConverter resourceConverter = | ||
new ResourceConverter.DoubleConverter( | ||
/* keywords= */ ImmutableMap.of( | ||
ResourceConverter.HOST_CPUS_KEYWORD, | ||
() -> (double) ResourceConverter.HOST_CPUS_SUPPLIER.get(), | ||
ResourceConverter.HOST_RAM_KEYWORD, | ||
() -> (double) ResourceConverter.HOST_RAM_SUPPLIER.get()), | ||
/* minValue= */ 0.0, | ||
/* maxValue= */ Double.MAX_VALUE); | ||
|
||
@Override | ||
public String getTypeDescription() { | ||
return "a resource name followed by equal and 1 float or 4 float, e.g memory=10,30,60,100"; | ||
} | ||
|
||
@Override | ||
public Pair<String, Map<TestSize, Double>> convert(String input) throws OptionsParsingException { | ||
Map.Entry<String, String> assignment = assignmentConverter.convert(input); | ||
ArrayList<Double> values = new ArrayList<>(TestSize.values().length); | ||
for (String s : Splitter.on(",").splitToList(assignment.getValue())) { | ||
values.add(resourceConverter.convert(s)); | ||
} | ||
|
||
if (values.size() != 1 && values.size() != TestSize.values().length) { | ||
throw new OptionsParsingException("Invalid number of comma-separated entries in " + input); | ||
} | ||
|
||
EnumMap<TestSize, Double> amounts = Maps.newEnumMap(TestSize.class); | ||
for (TestSize size : TestSize.values()) { | ||
amounts.put(size, values.get(Math.min(values.size() - 1, size.ordinal()))); | ||
} | ||
return Pair.of(assignment.getKey(), amounts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters