Fix R8FeatureSplitServiceLoaderTest non-determinism
Prior to 9f325cf2c2e9a131afc7cdd48623472506dc3d2f, META-INF/services
were all written to the base module. With them written per-module, the
test with the same service in multiple modules started failing flakily
for API levels pre-N because the resolution order of the multiple
META-INF/services files is non-deterministic. To work around this,
accept either order for API < N.
Bug: b/160889305
Change-Id: I20b52572f8f14b9cdd414d53d125fb4089005233
diff --git a/src/test/java/com/android/tools/r8/dexsplitter/R8FeatureSplitServiceLoaderTest.java b/src/test/java/com/android/tools/r8/dexsplitter/R8FeatureSplitServiceLoaderTest.java
index a93c7d7..be5fb9b 100644
--- a/src/test/java/com/android/tools/r8/dexsplitter/R8FeatureSplitServiceLoaderTest.java
+++ b/src/test/java/com/android/tools/r8/dexsplitter/R8FeatureSplitServiceLoaderTest.java
@@ -6,6 +6,8 @@
import static com.android.tools.r8.optimize.serviceloader.ServiceLoaderTestBase.getServiceLoaderLoads;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertEquals;
@@ -17,6 +19,7 @@
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper.DexVm.Version;
import com.android.tools.r8.origin.Origin;
+import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.Pair;
import com.android.tools.r8.utils.StringUtils;
import com.google.common.collect.ImmutableList;
@@ -130,8 +133,19 @@
if (parameters.getRuntime().isDex()
&& parameters.getRuntime().asDex().getVm().getVersion() == Version.V7_0_0) {
runResult.assertFailureWithErrorThatMatches(containsString("ServiceConfigurationError"));
+ } else if (parameters.getRuntime().isDex()
+ && parameters
+ .getRuntime()
+ .asDex()
+ .getMinApiLevel()
+ .isLessThanOrEqualTo(AndroidApiLevel.M)) {
+ // The resolution order is non-deterministic before N.
+ runResult.assertSuccessWithOutputThatMatches(
+ anyOf(
+ equalTo("Feature2I.foo()\nFeature1I.foo()\n"),
+ equalTo("Feature1I.foo()\nFeature2I.foo()\n")));
} else {
- runResult.assertSuccessWithOutputLines("Feature1I.foo()", "Feature2I.foo()");
+ runResult.assertSuccessWithOutput("Feature1I.foo()\nFeature2I.foo()\n");
}
}