diff options
author | jcater <jcater@google.com> | 2018-03-14 14:00:05 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-14 14:01:26 -0700 |
commit | 87bc83321b09b6e3fb01bd148c5f024af5fbe6c5 (patch) | |
tree | b0c2b781349a9a3bd87a91e91c5b3f34fb0e13f5 /src/test/java/com/google/devtools/build | |
parent | 7af95a198f2436194da142bb6f8c9060fa0ed49b (diff) |
Clean up tests of temp dirs in CcCommonTest to properly set the host CPU.
Also have each method only test one CPU value, for easier debugging.
PiperOrigin-RevId: 189081488
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java index 15dd847aae..a2f2b736f9 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java @@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.baseNam import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.truth.IterableSubject; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.util.ActionsTestUtil; @@ -295,42 +296,44 @@ public class CcCommonTest extends BuildViewTestCase { "3.pic.ii", "3.pic.s"); } + /** + * Returns the {@link IterableSubject} for the {@link OutputGroupInfo#TEMP_FILES} generated when + * {@code testTarget} is built for {@code cpu}. + */ + private IterableSubject assertTempsForTarget(String cpu, String testTarget) throws Exception { + useConfiguration("--cpu=" + cpu, "--host_cpu=" + cpu, "--save_temps"); + ConfiguredTarget target = getConfiguredTarget(testTarget); + assertThat(target).isNotNull(); + + List<String> temps = + ActionsTestUtil.baseArtifactNames(getOutputGroup(target, OutputGroupInfo.TEMP_FILES)); + + // Return the IterableSubject for the temp files. + return assertThat(temps).named(cpu); + } + @Test - public void testTempsForCc() throws Exception { - for (String cpu : new String[] {"k8", "piii"}) { - useConfiguration("--cpu=" + cpu, "--save_temps"); - ConfiguredTarget foo = getConfiguredTarget("//foo:foo"); - CcToolchainProvider toolchain = - CppHelper.getToolchainUsingDefaultCcToolchainAttribute(getRuleContext(foo)); - List<String> temps = - ActionsTestUtil.baseArtifactNames(getOutputGroup(foo, OutputGroupInfo.TEMP_FILES)); - if (CppHelper.usePicForBinaries( - getTargetConfiguration().getFragment(CppConfiguration.class), toolchain)) { - assertThat(temps).named(cpu).containsExactly("foo.pic.ii", "foo.pic.s"); - } else { - assertThat(temps).named(cpu).containsExactly("foo.ii", "foo.s"); - } - } + public void testTempsForCc_k8() throws Exception { + assertTempsForTarget("k8", "//foo:foo").containsExactly("foo.pic.ii", "foo.pic.s"); } @Test - public void testTempsForC() throws Exception { + public void testTempsForCc_piii() throws Exception { + // PIII does not use PIC. + assertTempsForTarget("piii", "//foo:foo").containsExactly("foo.ii", "foo.s"); + } + + @Test + public void testTempsForC_k8() throws Exception { scratch.file("csrc/BUILD", "cc_library(name='csrc', srcs=['foo.c'])"); - for (String cpu : new String[] {"k8", "piii"}) { - useConfiguration("--cpu=" + cpu, "--save_temps"); - // Now try with a .c source file. - ConfiguredTarget csrc = getConfiguredTarget("//csrc:csrc"); - CcToolchainProvider toolchain = - CppHelper.getToolchainUsingDefaultCcToolchainAttribute(getRuleContext(csrc)); - List<String> temps = - ActionsTestUtil.baseArtifactNames(getOutputGroup(csrc, OutputGroupInfo.TEMP_FILES)); - if (CppHelper.usePicForBinaries( - getTargetConfiguration().getFragment(CppConfiguration.class), toolchain)) { - assertThat(temps).named(cpu).containsExactly("foo.pic.i", "foo.pic.s"); - } else { - assertThat(temps).named(cpu).containsExactly("foo.i", "foo.s"); - } - } + assertTempsForTarget("k8", "//csrc:csrc").containsExactly("foo.pic.i", "foo.pic.s"); + } + + @Test + public void testTempsForC_piii() throws Exception { + scratch.file("csrc/BUILD", "cc_library(name='csrc', srcs=['foo.c'])"); + // PIII does not use PIC. + assertTempsForTarget("piii", "//csrc:csrc").containsExactly("foo.i", "foo.s"); } @Test |