Migrate more legacy regression tests.

Fixes: b/67936230
Bug: b/167145686
Change-Id: I949328c33eea2681c37c0ea576667d179d082e11
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index 9b09a48..20d9e1e 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -27,9 +27,6 @@
     String[] tests = {
       "arithmetic.Arithmetic",
       "inlining.Inlining",
-      "regress_37955340.Regress",
-      "regress_62300145.Regress",
-      "regress_64881691.Regress",
       "regress_65104300.Regress",
       "regress_70703087.Test",
       "regress_70736958.Test",
diff --git a/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java b/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
index 81e32d0..2ed3a8a 100644
--- a/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
+++ b/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
@@ -60,22 +60,6 @@
   }
 
   @Test
-  public void testRegress37955340() throws Exception {
-    testDebugging("regress_37955340", "Regress");
-  }
-
-  @Test
-  public void testRegress62300145() throws Exception {
-    // TODO(b/67936230): Executes differently for Java 8 and 9, so don't compare to DEX output.
-    testDebuggingJvmOnly("regress_62300145", "Regress");
-  }
-
-  @Test
-  public void testRegress64881691() throws Exception {
-    testDebugging("regress_64881691", "Regress");
-  }
-
-  @Test
   public void testRegress65104300() throws Exception {
     testDebugging("regress_65104300", "Regress");
   }
diff --git a/src/test/examples/regress_37955340/Regress.java b/src/test/java/com/android/tools/r8/examples/regress_37955340/Regress.java
similarity index 89%
rename from src/test/examples/regress_37955340/Regress.java
rename to src/test/java/com/android/tools/r8/examples/regress_37955340/Regress.java
index a8b5e0b..a37737a 100644
--- a/src/test/examples/regress_37955340/Regress.java
+++ b/src/test/java/com/android/tools/r8/examples/regress_37955340/Regress.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
-package regress_37955340;
+package com.android.tools.r8.examples.regress_37955340;
 
 public class Regress {
 
diff --git a/src/test/java/com/android/tools/r8/examples/regress_37955340/Regress37955340TestRunner.java b/src/test/java/com/android/tools/r8/examples/regress_37955340/Regress37955340TestRunner.java
new file mode 100644
index 0000000..a814068
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/regress_37955340/Regress37955340TestRunner.java
@@ -0,0 +1,57 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.examples.regress_37955340;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class Regress37955340TestRunner extends ExamplesTestBase {
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+  }
+
+  public Regress37955340TestRunner(TestParameters parameters) {
+    super(parameters);
+  }
+
+  @Override
+  public Class<?> getMainClass() {
+    return Regress.class;
+  }
+
+  @Override
+  public List<Class<?>> getTestClasses() throws Exception {
+    return ImmutableList.of(getMainClass(), Regress.A.class, Regress.B.class);
+  }
+
+  @Override
+  public String getExpected() {
+    return StringUtils.lines("2");
+  }
+
+  @Test
+  public void testDesugaring() throws Exception {
+    runTestDesugaring();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    runTestR8();
+  }
+
+  @Test
+  public void testDebug() throws Exception {
+    runTestDebugComparator();
+  }
+}
diff --git a/src/test/examples/regress_62300145/Regress.java b/src/test/java/com/android/tools/r8/examples/regress_62300145/Regress.java
similarity index 80%
rename from src/test/examples/regress_62300145/Regress.java
rename to src/test/java/com/android/tools/r8/examples/regress_62300145/Regress.java
index b02d345..037cc1d 100644
--- a/src/test/examples/regress_62300145/Regress.java
+++ b/src/test/java/com/android/tools/r8/examples/regress_62300145/Regress.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
-package regress_62300145;
+package com.android.tools.r8.examples.regress_62300145;
 
 import static java.lang.annotation.RetentionPolicy.CLASS;
 
@@ -32,12 +32,6 @@
     Annotation[][] annotations = constructor.getParameterAnnotations();
     int index = 0;
     for (int i = 0; i < annotations.length; i++) {
-      // TODO(b/67936230): Java 8 and Java 9 runtime does not have the same behavior regarding
-      // implicit parameter such as 'outer this' for instance. Disable this test on Java 9 runtime
-      // due to this divergence.
-      if (System.getProperty("java.specification.version").equals("9") && i == 0) {
-        continue;
-      }
       // On 9 and below, annotations are also printed for the Regress.class (first argument to the
       // getDeclaredConstructor). b/120402200
       if (i != 0 || annotations[i].length != 0) {
diff --git a/src/test/java/com/android/tools/r8/examples/regress_62300145/Regress62300145TestRunner.java b/src/test/java/com/android/tools/r8/examples/regress_62300145/Regress62300145TestRunner.java
new file mode 100644
index 0000000..a88c723
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/regress_62300145/Regress62300145TestRunner.java
@@ -0,0 +1,63 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.examples.regress_62300145;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class Regress62300145TestRunner extends ExamplesTestBase {
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+  }
+
+  public Regress62300145TestRunner(TestParameters parameters) {
+    super(parameters);
+  }
+
+  @Override
+  public Class<?> getMainClass() {
+    return Regress.class;
+  }
+
+  @Override
+  public List<Class<?>> getTestClasses() throws Exception {
+    return ImmutableList.of(
+        getMainClass(), Regress.A.class, Regress.B.class, Regress.InnerClass.class);
+  }
+
+  @Override
+  public String getExpected() {
+    return StringUtils.joinLines(
+        "0: @com.android.tools.r8.examples.regress_62300145.Regress$A()",
+        "1: @com.android.tools.r8.examples.regress_62300145.Regress$A()",
+        "2: ");
+  }
+
+  @Test
+  public void testDesugaring() throws Exception {
+    runTestDesugaring();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    runTestR8(
+        b ->
+            b.addKeepAllAttributes()
+                .addKeepClassAndMembersRules(Regress.InnerClass.class)
+                .addKeepClassRules(Regress.A.class, Regress.B.class));
+  }
+
+  // Since DEX 9 and below have different runtime behavior it does not make sense to compare
+  // single stepping.
+}
diff --git a/src/test/examples/regress_64881691/Regress.java b/src/test/java/com/android/tools/r8/examples/regress_64881691/Regress.java
similarity index 89%
rename from src/test/examples/regress_64881691/Regress.java
rename to src/test/java/com/android/tools/r8/examples/regress_64881691/Regress.java
index f99a394..e0b14e0 100644
--- a/src/test/examples/regress_64881691/Regress.java
+++ b/src/test/java/com/android/tools/r8/examples/regress_64881691/Regress.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
-package regress_64881691;
+package com.android.tools.r8.examples.regress_64881691;
 
 class A {
 }
diff --git a/src/test/java/com/android/tools/r8/examples/regress_64881691/Regress64881691TestRunner.java b/src/test/java/com/android/tools/r8/examples/regress_64881691/Regress64881691TestRunner.java
new file mode 100644
index 0000000..15c1f88
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/regress_64881691/Regress64881691TestRunner.java
@@ -0,0 +1,57 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.examples.regress_64881691;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class Regress64881691TestRunner extends ExamplesTestBase {
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+  }
+
+  public Regress64881691TestRunner(TestParameters parameters) {
+    super(parameters);
+  }
+
+  @Override
+  public Class<?> getMainClass() {
+    return Regress.class;
+  }
+
+  @Override
+  public List<Class<?>> getTestClasses() throws Exception {
+    return ImmutableList.of(getMainClass(), A.class, B.class);
+  }
+
+  @Override
+  public String getExpected() {
+    return StringUtils.lines("B");
+  }
+
+  @Test
+  public void testDesugaring() throws Exception {
+    runTestDesugaring();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    runTestR8(b -> b.addKeepClassRules(A.class, B.class));
+  }
+
+  @Test
+  public void testDebug() throws Exception {
+    runTestDebugComparator();
+  }
+}