Migrate legacy jumbostring example test to new test infra.
Bug: b/167145686
Change-Id: I0617ec993660e0aa9bf5691bd74922dfe07409b1
diff --git a/src/test/examples/jumbostring/JumboString.java b/src/test/examples/jumbostring/JumboString.java
deleted file mode 100644
index 9bfd9ca..0000000
--- a/src/test/examples/jumbostring/JumboString.java
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2016, 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 jumbostring;
-
-import java.io.IOException;
-import java.io.PrintStream;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-
-class JumboString {
- public static void main(String[] args) {
- // Make sure this string sorts after the field names and string values in the StringPoolX.java
- // files to ensure this is a jumbo string.
- System.out.println("zzzz - jumbo string");
- }
-
- // Code for generating the StringPoolX.java files.
- //
- // We only need to generate two files to get jumbo strings. Each file has 16k static final fields
- // with values, and both the field name and the value will be in the string pool.
- public static void generate() throws IOException {
- int stringsPerFile = (1 << 14);
- for (int fileNumber = 0; fileNumber < 2; fileNumber++) {
- Path path = FileSystems.getDefault().getPath("StringPool" + fileNumber + ".java");
- PrintStream out = new PrintStream(
- Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.APPEND));
-
- out.println(
- "// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file");
- out.println(
- "// for details. All rights reserved. Use of this source code is governed by a");
- out.println("// BSD-style license that can be found in the LICENSE file.");
- out.println("package jumbostring;");
- out.println();
- out.println("class StringPool" + fileNumber + " {");
-
- int offset = fileNumber * stringsPerFile;
- for (int i = offset; i < offset + stringsPerFile; i++) {
- out.println(" public static final String s" + i + " = \"" + i + "\";");
- }
- out.println("}");
- out.close();
- }
- }
-}
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index cac9b82..e58817e 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -27,7 +27,6 @@
String[] tests = {
"arithmetic.Arithmetic",
"inlining.Inlining",
- "jumbostring.JumboString",
"loadconst.LoadConst",
"loop.UdpServer",
"nestedtrycatches.NestedTryCatches",
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 25caafc..79fdbab 100644
--- a/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
+++ b/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
@@ -60,11 +60,6 @@
}
@Test
- public void testJumboString() throws Exception {
- testDebugging("jumbostring", "JumboString");
- }
-
- @Test
public void testLoadConst() throws Exception {
testDebugging("loadconst", "LoadConst");
}
diff --git a/src/test/java/com/android/tools/r8/examples/jumbostring/JumboString.java b/src/test/java/com/android/tools/r8/examples/jumbostring/JumboString.java
new file mode 100644
index 0000000..024040a
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/jumbostring/JumboString.java
@@ -0,0 +1,12 @@
+// Copyright (c) 2016, 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.jumbostring;
+
+class JumboString {
+ public static void main(String[] args) {
+ // Make sure this string sorts after the field names and string values in the StringPoolX.java
+ // files to ensure this is a jumbo string.
+ System.out.println("zzzz - jumbo string");
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/examples/jumbostring/JumboStringTestRunner.java b/src/test/java/com/android/tools/r8/examples/jumbostring/JumboStringTestRunner.java
new file mode 100644
index 0000000..dd474a2
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/jumbostring/JumboStringTestRunner.java
@@ -0,0 +1,95 @@
+// 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.jumbostring;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.ToolHelper;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class JumboStringTestRunner extends ExamplesTestBase {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+ }
+
+ public JumboStringTestRunner(TestParameters parameters) {
+ super(parameters);
+ }
+
+ @Override
+ public Class<?> getMainClass() {
+ return JumboString.class;
+ }
+
+ @Override
+ public List<Class<?>> getTestClasses() {
+ return ImmutableList.of(getMainClass(), StringPool0.class, StringPool1.class);
+ }
+
+ @Override
+ public String getExpected() {
+ return StringUtils.lines("zzzz - jumbo string");
+ }
+
+ @Test
+ public void testDesugaring() throws Exception {
+ runTestDesugaring();
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ runTestR8();
+ }
+
+ @Test
+ public void testDebug() throws Exception {
+ runTestDebugComparator();
+ }
+
+ // Code for generating the StringPoolX.java files.
+ //
+ // We only need to generate two files to get jumbo strings. Each file has 16k static final fields
+ // with values, and both the field name and the value will be in the string pool.
+ public static void generate() throws IOException {
+ Path jumboExampleDir =
+ ToolHelper.getSourceFileForTestClass(JumboStringTestRunner.class).getParent();
+ int stringsPerFile = (1 << 14);
+ for (int fileNumber = 0; fileNumber < 2; fileNumber++) {
+ Path path = jumboExampleDir.resolve("StringPool" + fileNumber + ".java");
+ PrintStream out =
+ new PrintStream(
+ Files.newOutputStream(
+ path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING));
+
+ out.println("// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file");
+ out.println("// for details. All rights reserved. Use of this source code is governed by a");
+ out.println("// BSD-style license that can be found in the LICENSE file.");
+ out.println("package " + JumboStringTestRunner.class.getPackage().getName() + ";");
+ out.println();
+ out.println("// GENERATED FILE - DO NOT EDIT (See JumboStringTestRunner.generate)");
+ out.println("class StringPool" + fileNumber + " {");
+
+ int offset = fileNumber * stringsPerFile;
+ for (int i = offset; i < offset + stringsPerFile; i++) {
+ out.println(" public static final String s" + i + " = \"" + i + "\";");
+ }
+ out.println("}");
+ out.close();
+ }
+ }
+}
diff --git a/src/test/examples/jumbostring/StringPool0.java b/src/test/java/com/android/tools/r8/examples/jumbostring/StringPool0.java
similarity index 99%
rename from src/test/examples/jumbostring/StringPool0.java
rename to src/test/java/com/android/tools/r8/examples/jumbostring/StringPool0.java
index e6e3b4b..bf42c57 100644
--- a/src/test/examples/jumbostring/StringPool0.java
+++ b/src/test/java/com/android/tools/r8/examples/jumbostring/StringPool0.java
@@ -1,8 +1,9 @@
// Copyright (c) 2016, 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 jumbostring;
+package com.android.tools.r8.examples.jumbostring;
+// GENERATED FILE - DO NOT EDIT (See JumboStringTestRunner.generate)
class StringPool0 {
public static final String s0 = "0";
public static final String s1 = "1";
diff --git a/src/test/examples/jumbostring/StringPool1.java b/src/test/java/com/android/tools/r8/examples/jumbostring/StringPool1.java
similarity index 99%
rename from src/test/examples/jumbostring/StringPool1.java
rename to src/test/java/com/android/tools/r8/examples/jumbostring/StringPool1.java
index 8539fb2..77fa3bb 100644
--- a/src/test/examples/jumbostring/StringPool1.java
+++ b/src/test/java/com/android/tools/r8/examples/jumbostring/StringPool1.java
@@ -1,8 +1,9 @@
// Copyright (c) 2016, 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 jumbostring;
+package com.android.tools.r8.examples.jumbostring;
+// GENERATED FILE - DO NOT EDIT (See JumboStringTestRunner.generate)
class StringPool1 {
public static final String s16384 = "16384";
public static final String s16385 = "16385";