diff options
Diffstat (limited to 'src/test/java/com/android/tools/r8/R8RunExamplesTest.java')
-rw-r--r-- | src/test/java/com/android/tools/r8/R8RunExamplesTest.java | 113 |
1 files changed, 71 insertions, 42 deletions
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java index e21e1bbb5..96d9e8b5b 100644 --- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java +++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java @@ -7,6 +7,7 @@ import static com.android.tools.r8.TestCondition.R8_COMPILER; import static com.android.tools.r8.TestCondition.match; import static com.android.tools.r8.utils.FileUtils.JAR_EXTENSION; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.android.tools.r8.R8RunArtTestsTest.CompilerUnderTest; @@ -15,10 +16,8 @@ import com.android.tools.r8.ToolHelper.DexVm; import com.android.tools.r8.ToolHelper.DexVm.Version; import com.android.tools.r8.errors.Unreachable; import com.android.tools.r8.shaking.ProguardRuleParserException; -import com.android.tools.r8.utils.JarBuilder; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -44,6 +43,11 @@ public class R8RunExamplesTest { DX, JAVAC, JAVAC_ALL, JAVAC_NONE } + enum Output { + DEX, + CF + } + private static final String EXAMPLE_DIR = ToolHelper.EXAMPLES_BUILD_DIR; // For local testing on a specific Art version(s) change this set. e.g. to @@ -67,7 +71,7 @@ public class R8RunExamplesTest { TestCondition.runtimes(Version.V6_0_1, Version.V5_1_1, Version.V4_4_4))) .build(); - @Parameters(name = "{0}_{1}_{2}_{3}") + @Parameters(name = "{0}_{1}_{2}_{3}_{5}") public static Collection<String[]> data() { String[] tests = { "arithmetic.Arithmetic", @@ -117,6 +121,10 @@ public class R8RunExamplesTest { "switchmaps.Switches", }; + String[] javaBytecodeTests = { + "hello.Hello", + }; + List<String[]> fullTestList = new ArrayList<>(tests.length * 2); for (String test : tests) { fullTestList.add(makeTest(Input.JAVAC, CompilerUnderTest.D8, CompilationMode.DEBUG, test)); @@ -132,13 +140,26 @@ public class R8RunExamplesTest { test)); fullTestList.add(makeTest(Input.DX, CompilerUnderTest.R8, CompilationMode.RELEASE, test)); } + // TODO(zerny): Once all tests pass create the java tests in the main test loop. + for (String test : javaBytecodeTests) { + fullTestList.add( + makeTest(Input.JAVAC_ALL, CompilerUnderTest.R8, CompilationMode.DEBUG, test, Output.CF)); + fullTestList.add( + makeTest( + Input.JAVAC_ALL, CompilerUnderTest.R8, CompilationMode.RELEASE, test, Output.CF)); + } return fullTestList; } private static String[] makeTest( Input input, CompilerUnderTest compiler, CompilationMode mode, String clazz) { + return makeTest(input, compiler, mode, clazz, Output.DEX); + } + + private static String[] makeTest( + Input input, CompilerUnderTest compiler, CompilationMode mode, String clazz, Output output) { String pkg = clazz.substring(0, clazz.lastIndexOf('.')); - return new String[]{pkg, input.name(), compiler.name(), mode.name(), clazz}; + return new String[] {pkg, input.name(), compiler.name(), mode.name(), clazz, output.name()}; } @Rule @@ -149,18 +170,25 @@ public class R8RunExamplesTest { private final CompilationMode mode; private final String pkg; private final String mainClass; + private final Output output; public R8RunExamplesTest( String pkg, String input, String compiler, String mode, - String mainClass) { + String mainClass, + String output) { this.pkg = pkg; this.input = Input.valueOf(input); this.compiler = CompilerUnderTest.valueOf(compiler); this.mode = CompilationMode.valueOf(mode); this.mainClass = mainClass; + this.output = Output.valueOf(output); + } + + private Path getOutputFile() { + return temp.getRoot().toPath().resolve("out.jar"); } private Path getInputFile() { @@ -190,18 +218,22 @@ public class R8RunExamplesTest { return input == Input.DX ? DexTool.DX : DexTool.NONE; } + private Path getOutputPath() { + return temp.getRoot().toPath().resolve("out.jar"); + } + @Rule public ExpectedException thrown = ExpectedException.none(); @Before public void compile() throws IOException, ProguardRuleParserException, ExecutionException, CompilationException { - Path out = temp.getRoot().toPath(); switch (compiler) { case D8: { + assertTrue(output == Output.DEX); ToolHelper.runD8(D8Command.builder() .addProgramFiles(getInputFile()) - .setOutputPath(out) + .setOutputPath(getOutputFile()) .setMode(mode) .build()); break; @@ -209,9 +241,10 @@ public class R8RunExamplesTest { case R8: { ToolHelper.runR8(R8Command.builder() .addProgramFiles(getInputFile()) - .setOutputPath(out) + .setOutputPath(getOutputFile()) .setMode(mode) - .build()); + .build(), + options -> options.outputClassFiles = (output == Output.CF)); break; } default: @@ -226,19 +259,7 @@ public class R8RunExamplesTest { } String original = getOriginalDexFile().toString(); - - File generated; - // Collect the generated dex files. - File[] outputFiles = - temp.getRoot().listFiles((File file) -> file.getName().endsWith(".dex")); - if (outputFiles.length == 1) { - // Just run Art on classes.dex. - generated = outputFiles[0]; - } else { - // Run Art on JAR file with multiple dex files. - generated = temp.getRoot().toPath().resolve(pkg + ".jar").toFile(); - JarBuilder.buildJar(outputFiles, generated); - } + Path generated = getOutputFile(); ToolHelper.ProcessResult javaResult = ToolHelper.runJava(ImmutableList.of(getOriginalJarFile("").toString()), mainClass); @@ -246,28 +267,36 @@ public class R8RunExamplesTest { fail("JVM failed for: " + mainClass); } - // TODO(ager): Once we have a bot running using dalvik (version 4.4.4) we should remove - // this explicit loop to get rid of repeated testing on the buildbots. - for (DexVm version : artVersions) { - TestCondition condition = failingRun.get(mainClass); - if (condition != null && condition.test(getTool(), compiler, version.getVersion(), mode)) { - thrown.expect(Throwable.class); - } else { - thrown = ExpectedException.none(); + if (output == Output.CF) { + ToolHelper.ProcessResult result = + ToolHelper.runJava(ImmutableList.of(generated.toString()), mainClass); + if (result.exitCode != 0) { + System.err.println(result.stderr); + fail("JVM failed on compiled output for: " + mainClass); } + assertEquals( + "JavaC/JVM and " + compiler.name() + "/JVM output differ", + javaResult.stdout, + result.stdout); + return; + } - // Check output against Art output on original dex file. - String output = - ToolHelper.checkArtOutputIdentical(original, generated.toString(), mainClass, version); - - // Check output against JVM output. - if (shouldMatchJVMOutput(version.getVersion())) { - String javaOutput = javaResult.stdout; - assertEquals( - "JVM and Art output differ:\n" + "JVM:\n" + javaOutput + "\nArt:\n" + output, - javaOutput, - output); - } + DexVm vm = ToolHelper.getDexVm(); + TestCondition condition = failingRun.get(mainClass); + if (condition != null && condition.test(getTool(), compiler, vm.getVersion(), mode)) { + thrown.expect(Throwable.class); + } else { + thrown = ExpectedException.none(); + } + + // Check output against Art output on original dex file. + String output = + ToolHelper.checkArtOutputIdentical(original, generated.toString(), mainClass, vm); + + // Check output against JVM output. + if (shouldMatchJVMOutput(vm.getVersion())) { + String javaOutput = javaResult.stdout; + assertEquals("JVM and Art output differ", javaOutput, output); } } |