Update test expectsions for Art 13
Bug: 228290516
Change-Id: I00dc0483555bbc43ef233b9ac3d11b92088d49ad
diff --git a/.gitignore b/.gitignore
index 2e7f798..ceddaef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -266,8 +266,8 @@
tools/*/art-10.0.0.tar.gz
tools/*/host/art-12.0.0-beta4
tools/*/host/art-12.0.0-beta4.tar.gz
-tools/*/host/art-13-master
-tools/*/host/art-13-master.tar.gz
+tools/*/host/art-13-dev
+tools/*/host/art-13-dev.tar.gz
tools/*/art.tar.gz
tools/*/dalvik
tools/*/dalvik-4.0.4
diff --git a/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java b/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java
index 1d6cb9a..e1064b0 100644
--- a/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java
@@ -15,7 +15,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -35,8 +34,79 @@
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Parameters(name = "{0}: {1}")
+ public static Collection<Object[]> data() {
+ return buildParameters(
+ getTestParameters().withDexRuntimes().withAllApiLevels().build(), tests.keySet());
+ }
+
private static final String SMALI_DIR = ToolHelper.SMALI_BUILD_DIR;
+ private static Map<String, String> tests;
+
+ static {
+ ImmutableMap.Builder<String, String> testsBuilder = ImmutableMap.builder();
+ testsBuilder
+ .put(
+ "arithmetic",
+ StringUtils.lines(
+ "-1", "3", "2", "3", "3.0", "1", "0", "-131580", "-131580", "2", "4", "-2"))
+ .put(
+ "controlflow",
+ StringUtils.lines("2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2"))
+ .put("fibonacci", StringUtils.lines("55", "55", "55", "55"))
+ .put("fill-array-data", "[1, 2, 3][4, 5, 6]")
+ .put("filled-new-array", "[1, 2, 3][4, 5, 6][1, 2, 3, 4, 5, 6][6, 5, 4, 3, 2, 1]")
+ .put("packed-switch", "12345")
+ .put("sparse-switch", "12345")
+ .put("unreachable-code-1", "777")
+ .put(
+ "multiple-returns",
+ StringUtils.lines("TFtf", "1", "4611686018427387904", "true", "false"))
+ .put("try-catch", "")
+ .put("phi-removal-regression", StringUtils.lines("returnBoolean"))
+ .put(
+ "overlapping-long-registers",
+ StringUtils.lines("-9151314442816847872", "-9151314442816319488"))
+ .put(
+ "type-confusion-regression",
+ StringUtils.lines("java.lang.RuntimeException: Test.<init>()"))
+ .put(
+ "type-confusion-regression2",
+ StringUtils.lines("java.lang.NullPointerException: Attempt to read from null array"))
+ .put(
+ "type-confusion-regression3",
+ StringUtils.lines(
+ "java.lang.NullPointerException: Attempt to read from field 'byte[] Test.a'"
+ + " on a null object reference"))
+ .put("type-confusion-regression4", "")
+ .put(
+ "type-confusion-regression5", StringUtils.lines("java.lang.RuntimeException: getId()I"))
+ .put("chain-of-loops", StringUtils.lines("java.lang.RuntimeException: f(II)"))
+ .put("new-instance-and-init", StringUtils.lines("Test(0)", "Test(0)", "Test(0)"))
+ .put(
+ "bad-codegen",
+ StringUtils.lines(
+ "java.lang.NullPointerException: Attempt to read from field "
+ + "'Test Test.a' on a null object reference"))
+ .put(
+ "merge-blocks-regression",
+ StringUtils.lines(
+ "java.lang.NullPointerException: Attempt to invoke virtual"
+ + " method 'Test Test.bW_()' on a null object reference"))
+ .put("self-is-catch-block", StringUtils.lines("100", "-1"))
+ .put("infinite-loop", "")
+ .put(
+ "regression/33336471",
+ StringUtils.lines(
+ "START", "0", "2", "LOOP", "1", "2", "LOOP", "2", "2", "DONE", "START", "0", "2",
+ "LOOP", "1", "2", "LOOP", "2", "2", "DONE"))
+ .put("regression/33846227", "")
+ .put("illegal-invokes", StringUtils.lines("ICCE", "ICCE"))
+ .build();
+ tests = testsBuilder.build();
+ }
+
private static Map<String, Set<String>> missingClasses =
ImmutableMap.of(
"try-catch", ImmutableSet.of("test.X"),
@@ -44,60 +114,63 @@
"bad-codegen", ImmutableSet.of("java.util.LTest"));
// Tests where the original smali code fails on Art, but runs after R8 processing.
- private static Map<DexVm.Version, List<String>> originalFailingOnArtVersions = ImmutableMap.of(
- Version.V5_1_1, ImmutableList.of(
- // Smali code contains an empty switch payload.
- "sparse-switch",
- "regression/33846227"
- ),
- Version.V4_4_4, ImmutableList.of(
- // Smali code contains an empty switch payload.
- "sparse-switch",
- "regression/33846227"
- ),
- Version.V4_0_4, ImmutableList.of(
- // Smali code contains an empty switch payload.
- "sparse-switch",
- "regression/33846227"
- )
- );
+ private static final Map<DexVm.Version, List<String>> originalFailingOnArtVersions =
+ ImmutableMap.of(
+ Version.V5_1_1,
+ ImmutableList.of(
+ // Smali code contains an empty switch payload.
+ "sparse-switch", "regression/33846227"),
+ Version.V4_4_4,
+ ImmutableList.of(
+ // Smali code contains an empty switch payload.
+ "sparse-switch", "regression/33846227"),
+ Version.V4_0_4,
+ ImmutableList.of(
+ // Smali code contains an empty switch payload.
+ "sparse-switch", "regression/33846227"));
// Tests where the output has a different output than the original on certain VMs.
- private static Map<DexVm.Version, Map<String, String>> customProcessedOutputExpectation =
+ private static final Map<DexVm.Version, Map<String, String>> customProcessedOutputExpectation =
ImmutableMap.of(
- Version.V4_4_4, ImmutableMap.of(
- "bad-codegen", "java.lang.NullPointerException\n",
- "type-confusion-regression2", "java.lang.NullPointerException\n",
- "type-confusion-regression3", "java.lang.NullPointerException\n",
- "merge-blocks-regression", "java.lang.NullPointerException\n"
- ),
- Version.V4_0_4, ImmutableMap.of(
- "bad-codegen", "java.lang.NullPointerException\n",
- "type-confusion-regression2", "java.lang.NullPointerException\n",
- "type-confusion-regression3", "java.lang.NullPointerException\n",
- "merge-blocks-regression", "java.lang.NullPointerException\n"
- )
- );
+ Version.V4_4_4,
+ ImmutableMap.of(
+ "bad-codegen", "java.lang.NullPointerException\n",
+ "type-confusion-regression2", "java.lang.NullPointerException\n",
+ "type-confusion-regression3", "java.lang.NullPointerException\n",
+ "merge-blocks-regression", "java.lang.NullPointerException\n"),
+ Version.V4_0_4,
+ ImmutableMap.of(
+ "bad-codegen", "java.lang.NullPointerException\n",
+ "type-confusion-regression2", "java.lang.NullPointerException\n",
+ "type-confusion-regression3", "java.lang.NullPointerException\n",
+ "merge-blocks-regression", "java.lang.NullPointerException\n"),
+ Version.V13_0_0,
+ ImmutableMap.of(
+ "bad-codegen",
+ StringUtils.lines(
+ "java.lang.NullPointerException: Attempt to read from field 'Test Test.a'"
+ + " on a null object reference in method 'Test TestObject.a(Test,"
+ + " Test, Test, Test, boolean)'"),
+ "type-confusion-regression3",
+ StringUtils.lines(
+ "java.lang.NullPointerException: Attempt to read from field 'byte[]"
+ + " Test.a' on a null object reference in method 'int"
+ + " TestObject.a(Test, Test)'")));
// Tests where the input fails with a verification error on Dalvik instead of the
// expected runtime exception.
- private static Map<DexVm.Version, List<String>> dalvikVerificationError = ImmutableMap.of(
- Version.V4_4_4, ImmutableList.of(
- // The invokes are in fact invalid, but the test expects the current Art behavior
- // of throwing an IncompatibleClassChange exception. Dalvik fails to verify.
- "illegal-invokes"
- ),
- Version.V4_0_4, ImmutableList.of(
- // The invokes are in fact invalid, but the test expects the current Art behavior
- // of throwing an IncompatibleClassChange exception. Dalvik fails to verify.
- "illegal-invokes"
- )
- );
-
- // Tests where the original smali code runs on Art, but fails after R8 processing
- private static Map<String, List<String>> failingOnArtVersions = ImmutableMap.of(
- // This list is currently empty!
- );
+ private static final Map<DexVm.Version, List<String>> dalvikVerificationErrors =
+ ImmutableMap.of(
+ Version.V4_4_4,
+ ImmutableList.of(
+ // The invokes are in fact invalid, but the test expects the current Art behavior
+ // of throwing an IncompatibleClassChange exception. Dalvik fails to verify.
+ "illegal-invokes"),
+ Version.V4_0_4,
+ ImmutableList.of(
+ // The invokes are in fact invalid, but the test expects the current Art behavior
+ // of throwing an IncompatibleClassChange exception. Dalvik fails to verify.
+ "illegal-invokes"));
private Set<String> failingOnX8 = ImmutableSet.of(
// Contains use of register as both an int and a float.
@@ -110,59 +183,23 @@
@Rule
public TestDescriptionWatcher watcher = new TestDescriptionWatcher();
- @Parameters(name = "{0}")
- public static Collection<String[]> data() {
- return Arrays.asList(new String[][]{
- {"arithmetic",
- StringUtils.lines("-1", "3", "2", "3", "3.0", "1", "0", "-131580", "-131580", "2", "4",
- "-2")},
- {"controlflow",
- StringUtils.lines("2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2")},
- {"fibonacci", StringUtils.lines("55", "55", "55", "55")},
- {"fill-array-data", "[1, 2, 3][4, 5, 6]"},
- {"filled-new-array", "[1, 2, 3][4, 5, 6][1, 2, 3, 4, 5, 6][6, 5, 4, 3, 2, 1]"},
- {"packed-switch", "12345"},
- {"sparse-switch", "12345"},
- {"unreachable-code-1", "777"},
- {"multiple-returns",
- StringUtils.lines("TFtf", "1", "4611686018427387904", "true", "false")},
- {"try-catch", ""},
- {"phi-removal-regression", StringUtils.lines("returnBoolean")},
- {"overlapping-long-registers",
- StringUtils.lines("-9151314442816847872", "-9151314442816319488")},
- {"type-confusion-regression",
- StringUtils.lines("java.lang.RuntimeException: Test.<init>()")},
- {"type-confusion-regression2",
- StringUtils.lines("java.lang.NullPointerException: Attempt to read from null array")},
- {"type-confusion-regression3",
- StringUtils.lines(
- "java.lang.NullPointerException: Attempt to read from field 'byte[] Test.a'" +
- " on a null object reference")},
- {"type-confusion-regression4", ""},
- {"type-confusion-regression5", StringUtils.lines("java.lang.RuntimeException: getId()I")},
- {"chain-of-loops", StringUtils.lines("java.lang.RuntimeException: f(II)")},
- {"new-instance-and-init", StringUtils.lines("Test(0)", "Test(0)", "Test(0)")},
- {"bad-codegen",
- StringUtils.lines("java.lang.NullPointerException: Attempt to read from field " +
- "'Test Test.a' on a null object reference")},
- {"merge-blocks-regression",
- StringUtils.lines("java.lang.NullPointerException: Attempt to invoke virtual"
- + " method 'Test Test.bW_()' on a null object reference")},
- {"self-is-catch-block", StringUtils.lines("100", "-1")},
- {"infinite-loop", ""},
- {"regression/33336471",
- StringUtils.lines("START", "0", "2", "LOOP", "1", "2", "LOOP", "2", "2", "DONE",
- "START", "0", "2", "LOOP", "1", "2", "LOOP", "2", "2", "DONE")},
- {"regression/33846227", ""},
- {"illegal-invokes", StringUtils.lines("ICCE", "ICCE")},
- });
- }
+ private final TestParameters parameters;
+ private final String directoryName;
+ private final String dexFileName;
+ private final String expectedOutput;
- private String directoryName;
- private String dexFileName;
- private String expectedOutput;
-
- public R8RunSmaliTestsTest(String name, String expectedOutput) {
+ public R8RunSmaliTestsTest(TestParameters parameters, String name) {
+ this.parameters = parameters;
+ String expectedOutput = tests.get(name);
+ if (customProcessedOutputExpectation.containsKey(parameters.asDexRuntime().getVersion())
+ && customProcessedOutputExpectation
+ .get(parameters.asDexRuntime().getVersion())
+ .containsKey(name)) {
+ // If the original and the processed code have different expected output, only run
+ // the code produced by R8.
+ expectedOutput =
+ customProcessedOutputExpectation.get(parameters.asDexRuntime().getVersion()).get(name);
+ }
this.directoryName = name;
this.dexFileName = name.substring(name.lastIndexOf('/') + 1) + ".dex";
this.expectedOutput = expectedOutput;
@@ -171,56 +208,40 @@
@Test
public void SmaliTest() throws Exception {
Path originalDexFile = Paths.get(SMALI_DIR, directoryName, dexFileName);
- Path outputPath = temp.getRoot().toPath().resolve("classes.dex");
+ // Path outputPath = temp.getRoot().toPath().resolve("classes.dex");
if (failingOnX8.contains(directoryName)) {
thrown.expect(CompilationFailedException.class);
}
- testForR8(Backend.DEX)
+ Version version = parameters.asDexRuntime().getVersion();
+ boolean dalvikVerificationError =
+ dalvikVerificationErrors.containsKey(version)
+ && dalvikVerificationErrors.get(version).contains(directoryName);
+ boolean originalFailing =
+ (originalFailingOnArtVersions.containsKey(version)
+ && originalFailingOnArtVersions.get(version).contains(directoryName));
+ testForR8(parameters.getBackend())
.addKeepAllClassesRule()
.addProgramDexFileData(Files.readAllBytes(originalDexFile))
.addDontWarn(missingClasses.getOrDefault(directoryName, Collections.emptySet()))
+ .setMinApi(parameters.getApiLevel())
.compile()
- .writeToZip(outputPath);
+ .run(parameters.getRuntime(), "Test")
+ .applyIf(
+ dalvikVerificationError,
+ r -> r.assertFailureWithErrorThatThrows(VerifyError.class),
+ r -> r.assertSuccessWithOutput(expectedOutput));
- if (!ToolHelper.artSupported()) {
- return;
+ // Also run the original DEX if possible.
+ if (!dalvikVerificationError && !originalFailing) {
+ String originalOutput =
+ ToolHelper.runArtNoVerificationErrors(
+ ImmutableList.of(originalDexFile.toString()),
+ "Test",
+ null,
+ parameters.getRuntime().asDex().getVm());
+ assertEquals(expectedOutput, originalOutput);
}
-
- String mainClass = "Test";
- String generated = outputPath.toString();
- String output = "";
-
- DexVm.Version dexVmVersion = ToolHelper.getDexVm().getVersion();
- if (dalvikVerificationError.containsKey(dexVmVersion)
- && dalvikVerificationError.get(dexVmVersion).contains(directoryName)) {
- try {
- ToolHelper.runArtNoVerificationErrors(generated, mainClass);
- } catch (AssertionError e) {
- assert e.toString().contains("VerifyError");
- }
- return;
- } else if (originalFailingOnArtVersions.containsKey(dexVmVersion)
- && originalFailingOnArtVersions.get(dexVmVersion).contains(directoryName)) {
- // If the original smali code fails on the target VM, only run the code produced by R8.
- output = ToolHelper.runArtNoVerificationErrors(generated, mainClass);
- } else if (customProcessedOutputExpectation.containsKey(dexVmVersion)
- && customProcessedOutputExpectation.get(dexVmVersion).containsKey(directoryName)) {
- // If the original and the processed code have different expected output, only run
- // the code produced by R8.
- expectedOutput =
- customProcessedOutputExpectation.get(dexVmVersion).get(directoryName);
- output = ToolHelper.runArtNoVerificationErrors(generated, mainClass);
- } else {
- if (failingOnArtVersions.containsKey(dexVmVersion)
- && failingOnArtVersions.get(dexVmVersion).contains(directoryName)) {
- thrown.expect(Throwable.class);
- }
- output =
- ToolHelper
- .checkArtOutputIdentical(originalDexFile.toString(), generated, mainClass, null);
- }
- assertEquals(expectedOutput, output);
}
}
diff --git a/src/test/java/com/android/tools/r8/graph/invokespecial/InvokeSpecialOnOtherInterfaceTest.java b/src/test/java/com/android/tools/r8/graph/invokespecial/InvokeSpecialOnOtherInterfaceTest.java
index e3a9a96..d574d5a 100644
--- a/src/test/java/com/android/tools/r8/graph/invokespecial/InvokeSpecialOnOtherInterfaceTest.java
+++ b/src/test/java/com/android/tools/r8/graph/invokespecial/InvokeSpecialOnOtherInterfaceTest.java
@@ -44,9 +44,10 @@
.applyIf(
parameters.isCfRuntime(),
r -> r.assertFailureWithErrorThatThrows(VerifyError.class),
- parameters.isDexRuntime() && !parameters.isDexRuntimeVersion(Version.V13_0_0),
+ !(parameters.isDexRuntimeVersion(Version.V13_0_0)
+ && parameters.canUseDefaultAndStaticInterfaceMethods()),
r -> r.assertSuccessWithOutputLines("Hello World!"),
- r -> r.assertFailureWithErrorThatThrows(VerifyError.class));
+ r -> r.assertFailureWithErrorThatThrows(NoSuchMethodError.class));
}
@Test