Cleanup R8RunExamplesTest.

1. Remove the processedFileIsSmaller part of the test. It is no longer
   useful and we are tracking size elsewhere.

2. Compare against JVM output as well as Art output on the original dex
   file.

R=mikaelpeltier@google.com, zerny@google.com

Change-Id: Ib8ebc91597be2fcc2ff7d538bfb394a9a7d9f675
diff --git a/src/test/examples/filledarray/FilledArray.java b/src/test/examples/filledarray/FilledArray.java
index 04a8f83..46c437c 100644
--- a/src/test/examples/filledarray/FilledArray.java
+++ b/src/test/examples/filledarray/FilledArray.java
@@ -106,7 +106,7 @@
       System.out.println("ints = " + Arrays.toString(ints));
       System.out.println("ints2 = " + Arrays.toString(ints2));
     } catch (Throwable t) {
-      t.printStackTrace(System.out);
+      System.out.println("Exception: " + t.getClass().toString());
     }
 
     try {
@@ -122,7 +122,7 @@
       System.out.println("i = " + i);
       System.out.println("ints = " + Arrays.toString(ints));
     } catch (Throwable t) {
-      t.printStackTrace(System.out);
+      System.out.println("Exception: " + t.getClass().toString());
     }
   }
 
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index ba4eea0..e910eb6 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -4,22 +4,20 @@
 package com.android.tools.r8;
 
 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;
+import com.android.tools.r8.R8RunArtTestsTest.DexTool;
 import com.android.tools.r8.ToolHelper.DexVm;
 import com.android.tools.r8.shaking.ProguardRuleParserException;
-import com.android.tools.r8.utils.DexInspector;
 import com.android.tools.r8.utils.JarBuilder;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -42,19 +40,21 @@
   private static final String DEX_EXTENSION = ".dex";
   private static final String DEFAULT_DEX_FILENAME = "classes.dex";
 
-  private static final String[] failsWithJar = {};
+  private static final Map<String, TestCondition> outputNotIdenticalToJVMOutput =
+      new ImmutableMap.Builder<String, TestCondition>()
+          // Traverses stack frames that contain Art specific frames.
+          .put("throwing.Throwing", TestCondition.any())
+          // Early art versions incorrectly print Float.MIN_VALUE.
+          .put(
+              "filledarray.FilledArray",
+              TestCondition.match(
+                  TestCondition.runtimes(DexVm.ART_6_0_1, DexVm.ART_5_1_1, DexVm.ART_4_4_4)))
+          .build();
 
   // For local testing on a specific Art version(s) change this set. e.g. to
   // ImmutableSet.of("default") or pass the option -Ddex_vm=<version> to the Java VM.
   private static Set<DexVm> artVersions = ToolHelper.getArtVersions();
 
-  // A set of class names for examples that might produce bigger output and thus are excluded from
-  // size testing.
-  private static Set<String> mayBeBigger = ImmutableSet.of(
-      // Contains a reference to an extra type due to member rebinding.
-      "throwing.Throwing"
-  );
-
   @Parameters(name = "{0}{1}")
   public static Collection<String[]> data() {
     String[] tests = {
@@ -156,14 +156,18 @@
   }
 
   private Path getInputFile() {
-    if (fileType == JAR_EXTENSION) {
-      return Paths.get(EXAMPLE_DIR, name + JAR_EXTENSION);
+    if (fileType.equals(JAR_EXTENSION)) {
+      return getOriginalJarFile();
     } else {
-      assert fileType == DEX_EXTENSION;
+      assert fileType.equals(DEX_EXTENSION);
       return getOriginalDexFile();
     }
   }
 
+  public Path getOriginalJarFile() {
+    return Paths.get(EXAMPLE_DIR, name + JAR_EXTENSION);
+  }
+
   private Path getOriginalDexFile() {
     return Paths.get(EXAMPLE_DIR, name, DEFAULT_DEX_FILENAME);
   }
@@ -182,42 +186,11 @@
   @Before
   public void generateR8Version()
       throws IOException, ProguardRuleParserException, ExecutionException, CompilationException {
-    if (fileType == JAR_EXTENSION && Arrays.asList(failsWithJar).contains(name)) {
-      thrown.expect(Throwable.class);
-    }
     String out = temp.getRoot().getCanonicalPath();
     ToolHelper.runR8(getInputFile().toString(), out);
   }
 
   @Test
-  public void processedFileIsSmaller() throws IOException {
-    if (mayBeBigger.contains(mainClass)) {
-      return;
-    }
-    long original = Files.size(getOriginalDexFile());
-    long generated = Files.size(getGeneratedDexFile());
-
-    if (generated > original) {
-      DexInspector inspectOriginal = null;
-      DexInspector inspectGenerated = null;
-      try {
-        inspectOriginal = new DexInspector(getOriginalDexFile());
-        inspectGenerated = new DexInspector(getGeneratedDexFile());
-      } catch (Throwable e) {
-        System.err.println("Failed to parse dex files for post-failure processing");
-        e.printStackTrace();
-      }
-      if (inspectGenerated != null && inspectOriginal != null) {
-        assertEquals("Generated file is larger than original: " + generated + " vs. " + original,
-            inspectOriginal.clazz(mainClass).dumpMethods(),
-            inspectGenerated.clazz(mainClass).dumpMethods());
-      }
-    }
-    assertTrue("Generated file is larger than original: " + generated + " vs. " + original,
-        generated <= original);
-  }
-
-  @Test
   public void outputIsIdentical() throws IOException, InterruptedException, ExecutionException {
     if (!ToolHelper.artSupported()) {
       return;
@@ -237,16 +210,40 @@
       generated = temp.getRoot().toPath().resolve(name + ".jar").toFile();
       JarBuilder.buildJar(outputFiles, generated);
     }
+
+    ToolHelper.ProcessResult javaResult =
+        ToolHelper.runJava(ImmutableList.of(getOriginalJarFile().toString()), mainClass);
+    if (javaResult.exitCode != 0) {
+      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) {
-      boolean expectedToFail = false;
       if (failsOn.containsKey(version) && failsOn.get(version).contains(getTestName())) {
-        expectedToFail = true;
         thrown.expect(Throwable.class);
       }
+
+      // 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)) {
+        String javaOutput = javaResult.stdout;
+        assertEquals(
+            "JVM and Art output differ:\n" + "JVM:\n" + javaOutput + "\nArt:\n" + output,
+            output,
+            javaOutput);
+      }
     }
   }
+
+  private boolean shouldMatchJVMOutput(DexVm version) {
+    TestCondition condition = outputNotIdenticalToJVMOutput.get(mainClass);
+    if (condition == null) {
+      return true;
+    }
+    return !condition.test(DexTool.NONE, CompilerUnderTest.R8, version, CompilationMode.RELEASE);
+  }
 }
diff --git a/src/test/java/com/android/tools/r8/RunExamplesAndroidNTest.java b/src/test/java/com/android/tools/r8/RunExamplesAndroidNTest.java
index cb28cc4..d5f3a2e 100644
--- a/src/test/java/com/android/tools/r8/RunExamplesAndroidNTest.java
+++ b/src/test/java/com/android/tools/r8/RunExamplesAndroidNTest.java
@@ -22,7 +22,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutionException;
 import java.util.function.Consumer;
 import java.util.function.UnaryOperator;
 import org.junit.Rule;
diff --git a/src/test/java/com/android/tools/r8/jdwp/RunJdwpTests.java b/src/test/java/com/android/tools/r8/jdwp/RunJdwpTests.java
index 1e6e3f7..8890df8 100644
--- a/src/test/java/com/android/tools/r8/jdwp/RunJdwpTests.java
+++ b/src/test/java/com/android/tools/r8/jdwp/RunJdwpTests.java
@@ -6,7 +6,6 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assume.assumeTrue;
 
 import com.android.tools.r8.CompilationException;
 import com.android.tools.r8.CompilationMode;