diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java | 62 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java | 30 |
2 files changed, 67 insertions, 25 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java index 546f78fa66..a5358344ce 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java @@ -246,6 +246,15 @@ public class CppLinkActionTest extends BuildViewTestCase { assertThat(linkAction.getEnvironment()).containsEntry("foo", "bar"); } + private enum NonStaticAttributes { + OUTPUT_FILE, + COMPILATION_INPUTS, + NATIVE_DEPS, + USE_TEST_ONLY_FLAGS, + FAKE, + RUNTIME_SOLIB_DIR + } + /** * This mainly checks that non-static links don't have identical keys. Many options are only * allowed on non-static links, and we test several of them here. @@ -262,30 +271,39 @@ public class CppLinkActionTest extends BuildViewTestCase { final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration(); ActionTester.runTest( - 64, - new ActionCombinationFactory() { + NonStaticAttributes.class, + new ActionCombinationFactory<NonStaticAttributes>() { @Override - public Action generate(int i) throws InterruptedException { + public Action generate(ImmutableSet<NonStaticAttributes> attributesToFlip) + throws InterruptedException { CppLinkActionBuilder builder = new CppLinkActionBuilder( ruleContext, - (i & 2) == 0 ? dynamicOutputFile : staticOutputFile, + attributesToFlip.contains(NonStaticAttributes.OUTPUT_FILE) + ? dynamicOutputFile + : staticOutputFile, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain")) {}; builder.addCompilationInputs( - (i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2)); - if ((i & 2) == 0) { + attributesToFlip.contains(NonStaticAttributes.COMPILATION_INPUTS) + ? ImmutableList.of(oFile) + : ImmutableList.of(oFile2)); + if (attributesToFlip.contains(NonStaticAttributes.OUTPUT_FILE)) { builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY); builder.setLibraryIdentifier("foo"); } else { builder.setLinkType(LinkTargetType.EXECUTABLE); } builder.setLinkStaticness(LinkStaticness.DYNAMIC); - builder.setNativeDeps((i & 4) == 0); - builder.setUseTestOnlyFlags((i & 8) == 0); - builder.setFake((i & 16) == 0); - builder.setRuntimeSolibDir((i & 32) == 0 ? null : PathFragment.create("so1")); + builder.setNativeDeps(attributesToFlip.contains(NonStaticAttributes.NATIVE_DEPS)); + builder.setUseTestOnlyFlags( + attributesToFlip.contains(NonStaticAttributes.USE_TEST_ONLY_FLAGS)); + builder.setFake(attributesToFlip.contains(NonStaticAttributes.FAKE)); + builder.setRuntimeSolibDir( + attributesToFlip.contains(NonStaticAttributes.RUNTIME_SOLIB_DIR) + ? null + : PathFragment.create("so1")); builder.setFeatureConfiguration(featureConfiguration); return builder.build(); @@ -293,6 +311,11 @@ public class CppLinkActionTest extends BuildViewTestCase { }); } + private enum StaticKeyAttributes { + OUTPUT_FILE, + COMPILATION_INPUTS + } + /** * This mainly checks that static library links don't have identical keys, and it also compares * them with simple dynamic library links. @@ -309,21 +332,28 @@ public class CppLinkActionTest extends BuildViewTestCase { final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration(); ActionTester.runTest( - 4, - new ActionCombinationFactory() { + StaticKeyAttributes.class, + new ActionCombinationFactory<StaticKeyAttributes>() { @Override - public Action generate(int i) throws InterruptedException { + public Action generate(ImmutableSet<StaticKeyAttributes> attributes) + throws InterruptedException { CppLinkActionBuilder builder = new CppLinkActionBuilder( ruleContext, - (i & 2) == 0 ? staticOutputFile : dynamicOutputFile, + attributes.contains(StaticKeyAttributes.OUTPUT_FILE) + ? staticOutputFile + : dynamicOutputFile, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain")) {}; builder.addCompilationInputs( - (i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2)); + attributes.contains(StaticKeyAttributes.COMPILATION_INPUTS) + ? ImmutableList.of(oFile) + : ImmutableList.of(oFile2)); builder.setLinkType( - (i & 2) == 0 ? LinkTargetType.STATIC_LIBRARY : LinkTargetType.DYNAMIC_LIBRARY); + attributes.contains(StaticKeyAttributes.OUTPUT_FILE) + ? LinkTargetType.STATIC_LIBRARY + : LinkTargetType.DYNAMIC_LIBRARY); builder.setLibraryIdentifier("foo"); builder.setFeatureConfiguration(featureConfiguration); return builder.build(); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java index 70284d8003..d5f471e87b 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.AbstractAction; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionExecutionContext; @@ -134,6 +135,15 @@ public class LTOBackendActionTest extends BuildViewTestCase { .containsExactly(bitcode1Artifact, bitcode2Artifact, index2Artifact); } + private enum KeyAttributes { + EXECUTABLE, + IMPORTS_INFO, + MNEMONIC, + RUNFILES_SUPPLIER, + INPUT, + ENVIRONMENT + } + @Test public void testComputeKey() throws Exception { final Artifact artifactA = getSourceArtifact("a"); @@ -142,26 +152,28 @@ public class LTOBackendActionTest extends BuildViewTestCase { final Artifact artifactBimports = getSourceArtifact("b.imports"); ActionTester.runTest( - 64, - new ActionCombinationFactory() { + KeyAttributes.class, + new ActionCombinationFactory<KeyAttributes>() { @Override - public Action generate(int i) { + public Action generate(ImmutableSet<KeyAttributes> attributesToFlip) { LTOBackendAction.Builder builder = new LTOBackendAction.Builder(); builder.addOutput(destinationArtifact); PathFragment executable = - (i & 1) == 0 ? artifactA.getExecPath() : artifactB.getExecPath(); + attributesToFlip.contains(KeyAttributes.EXECUTABLE) + ? artifactA.getExecPath() + : artifactB.getExecPath(); builder.setExecutable(executable); - if ((i & 2) == 0) { + if (attributesToFlip.contains(KeyAttributes.IMPORTS_INFO)) { builder.addImportsInfo(new HashMap<PathFragment, Artifact>(), artifactAimports); } else { builder.addImportsInfo(new HashMap<PathFragment, Artifact>(), artifactBimports); } - builder.setMnemonic((i & 4) == 0 ? "a" : "b"); + builder.setMnemonic(attributesToFlip.contains(KeyAttributes.MNEMONIC) ? "a" : "b"); - if ((i & 8) == 0) { + if (attributesToFlip.contains(KeyAttributes.RUNFILES_SUPPLIER)) { builder.addRunfilesSupplier( new RunfilesSupplierImpl(PathFragment.create("a"), Runfiles.EMPTY, artifactA)); } else { @@ -169,14 +181,14 @@ public class LTOBackendActionTest extends BuildViewTestCase { new RunfilesSupplierImpl(PathFragment.create("a"), Runfiles.EMPTY, artifactB)); } - if ((i & 16) == 0) { + if (attributesToFlip.contains(KeyAttributes.INPUT)) { builder.addInput(artifactA); } else { builder.addInput(artifactB); } Map<String, String> env = new HashMap<>(); - if ((i & 32) == 0) { + if (attributesToFlip.contains(KeyAttributes.ENVIRONMENT)) { env.put("foo", "bar"); } builder.setEnvironment(env); |