Add PG retrace tests for catch all range and no line number
Change-Id: I68f33a466c1e9177e6be2101cb7ca88ef7c10a7c
diff --git a/src/test/java/com/android/tools/r8/ProguardVersion.java b/src/test/java/com/android/tools/r8/ProguardVersion.java
index 20560fc..3be26d9 100644
--- a/src/test/java/com/android/tools/r8/ProguardVersion.java
+++ b/src/test/java/com/android/tools/r8/ProguardVersion.java
@@ -25,16 +25,25 @@
}
public Path getProguardScript() {
+ return isWindows()
+ ? getScriptDirectory().resolve("proguard.bat")
+ : getScriptDirectory().resolve("proguard.sh");
+ }
+
+ public Path getRetraceScript() {
+ return isWindows()
+ ? getScriptDirectory().resolve("retrace.bat")
+ : getScriptDirectory().resolve("retrace.sh");
+ }
+
+ private Path getScriptDirectory() {
Path scriptDirectory = Paths.get(ToolHelper.THIRD_PARTY_DIR).resolve("proguard");
if (this == V7_0_0) {
- scriptDirectory = scriptDirectory.resolve("proguard-" + version);
+ scriptDirectory = scriptDirectory.resolve("proguard-" + version).resolve("bin");
} else {
- scriptDirectory = scriptDirectory.resolve("proguard" + version);
+ scriptDirectory = scriptDirectory.resolve("proguard" + version).resolve("bin");
}
- if (isWindows()) {
- return scriptDirectory.resolve("bin/proguard.bat");
- }
- return scriptDirectory.resolve("bin/proguard.sh");
+ return scriptDirectory;
}
public String getVersion() {
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 8f3b1e4..0d799b6 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -155,8 +155,6 @@
public static final Path JACOCO_CLI = JACOCO_ROOT.resolve(Paths.get("lib", "jacococli.jar"));
public static final String PROGUARD_SETTINGS_FOR_INTERNAL_APPS = "third_party/proguardsettings/";
- private static final String RETRACE6_0_1 = "third_party/proguard/proguard6.0.1/bin/retrace";
- private static final String RETRACE = RETRACE6_0_1;
public static final Path RETRACE_MAPS_DIR = Paths.get(THIRD_PARTY_DIR, "r8mappings");
public static final long BOT_MAX_HEAP_SIZE = 7908360192L;
@@ -777,13 +775,6 @@
return new Backend[]{Backend.DEX};
}
- private static String getRetraceScript() {
- if (isWindows()) {
- return RETRACE + ".bat";
- }
- return RETRACE + ".sh";
- }
-
private static Path getDxExecutablePath() {
String toolsDir = toolsDir();
String executableName = toolsDir.equals("windows") ? "dx.bat" : "dx";
@@ -2021,17 +2012,19 @@
return runProguard(getProguard6Script(), inJar, outJar, configs, map);
}
- public static ProcessResult runRetraceRaw(Path map, Path stackTrace) throws IOException {
+ public static ProcessResult runRetraceRaw(Path retracePath, Path map, Path stackTrace)
+ throws IOException {
List<String> command = new ArrayList<>();
- command.add(getRetraceScript());
+ command.add(retracePath.toString());
command.add(map.toString());
command.add(stackTrace.toString());
ProcessBuilder builder = new ProcessBuilder(command);
return ToolHelper.runProcess(builder);
}
- public static String runRetrace(Path map, Path stackTrace) throws IOException {
- ProcessResult result = runRetraceRaw(map, stackTrace);
+ public static String runRetrace(ProguardVersion pgRetracer, Path map, Path stackTrace)
+ throws IOException {
+ ProcessResult result = runRetraceRaw(pgRetracer.getRetraceScript(), map, stackTrace);
if (result.exitCode != 0) {
fail("Retrace failed, exit code " + result.exitCode + ", stderr:\n" + result.stderr);
}
diff --git a/src/test/java/com/android/tools/r8/naming/retraceproguard/CatchAllRangeWithNoLineNumberTest.java b/src/test/java/com/android/tools/r8/naming/retraceproguard/CatchAllRangeWithNoLineNumberTest.java
new file mode 100644
index 0000000..34da9a6
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/naming/retraceproguard/CatchAllRangeWithNoLineNumberTest.java
@@ -0,0 +1,121 @@
+// Copyright (c) 2021, 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.naming.retraceproguard;
+
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.ProguardVersion;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.retrace.ProguardMapProducer;
+import com.android.tools.r8.retrace.RetraceOptions;
+import com.android.tools.r8.retrace.StringRetrace;
+import com.android.tools.r8.utils.StringUtils;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class CatchAllRangeWithNoLineNumberTest extends TestBase {
+
+ private final TestParameters parameters;
+ private final ProguardVersion proguardVersion;
+
+ @Parameters(name = "{0}, {1}")
+ public static List<Object[]> data() {
+ return buildParameters(getTestParameters().withNoneRuntime().build(), ProguardVersion.values());
+ }
+
+ public CatchAllRangeWithNoLineNumberTest(
+ TestParameters parameters, ProguardVersion proguardVersion) {
+ this.parameters = parameters;
+ this.proguardVersion = proguardVersion;
+ }
+
+ private final String[] stackTrace =
+ new String[] {
+ "\tat a.a(SourceFile)",
+ "\tat b.a(SourceFile)",
+ "\tat c.a(SourceFile)",
+ "\tat a.a(SourceFile:1)",
+ "\tat a.a(SourceFile:0)"
+ };
+
+ private final String mapping =
+ StringUtils.joinLines(
+ "foo.bar.Baz -> a:",
+ " 0:65535:void foo():33:33 -> a",
+ "foo.bar.Qux -> b:",
+ " 1:65535:void foo():33:33 -> a",
+ "foo.bar.Quux -> c:",
+ " void foo():33:33 -> a");
+
+ private final String retraced5_2_1 =
+ StringUtils.lines(
+ "foo.bar.Baz.a(Baz.java)",
+ "foo.bar.Qux.a(Qux.java)",
+ "foo.bar.Quux.a(Quux.java)",
+ "foo.bar.Baz.foo(Baz.java:33)",
+ "foo.bar.Baz.a(Baz.java:0)");
+
+ private final String retraced6_0_1 =
+ StringUtils.lines(
+ "foo.bar.Baz.a(Baz.java)",
+ "foo.bar.Qux.a(Qux.java)",
+ "foo.bar.Quux.a(Quux.java)",
+ "foo.bar.Baz.foo(Baz.java:33)",
+ "foo.bar.Baz.a(Baz.java:0)");
+
+ private final String retraced7_0_0 =
+ StringUtils.lines(
+ "foo.bar.Baz.foo(Baz.java)",
+ "foo.bar.Qux.foo(Qux.java)",
+ "foo.bar.Quux.a(Quux.java)",
+ "foo.bar.Baz.foo(Baz.java:33)",
+ "foo.bar.Baz.foo(Baz.java:33)");
+
+ private final String retracedR8 =
+ StringUtils.lines(
+ "\tat foo.bar.Baz.foo(Baz.java:33)",
+ "\tat foo.bar.Qux.foo(Qux.java:33)",
+ "\tat foo.bar.Quux.foo(Quux.java:33)",
+ "\tat foo.bar.Baz.foo(Baz.java:33)",
+ "\tat foo.bar.Baz.foo(Baz.java:33)");
+
+ @Test
+ public void testCatchAllRange() throws IOException {
+ StackTrace actualStackTrace = StackTrace.extractFromJvm(StringUtils.lines(stackTrace));
+ StackTrace retraced =
+ actualStackTrace.retrace(proguardVersion, mapping, temp.newFolder().toPath());
+ assertEquals(getExpected(), retraced.toString());
+ }
+
+ @Test
+ public void testCatchAllRangeR8() {
+ List<String> retrace =
+ StringRetrace.create(
+ RetraceOptions.builder()
+ .setProguardMapProducer(ProguardMapProducer.fromString(mapping))
+ .build())
+ .retrace(Arrays.asList(stackTrace));
+ assertEquals(retracedR8, StringUtils.lines(retrace));
+ }
+
+ private String getExpected() {
+ switch (proguardVersion) {
+ case V5_2_1:
+ return retraced5_2_1;
+ case V6_0_1:
+ return retraced6_0_1;
+ default:
+ assertEquals(ProguardVersion.V7_0_0, proguardVersion);
+ return retraced7_0_0;
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/naming/retraceproguard/StackTrace.java b/src/test/java/com/android/tools/r8/naming/retraceproguard/StackTrace.java
index 92b78b6..8869cbc 100644
--- a/src/test/java/com/android/tools/r8/naming/retraceproguard/StackTrace.java
+++ b/src/test/java/com/android/tools/r8/naming/retraceproguard/StackTrace.java
@@ -8,6 +8,7 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import com.android.tools.r8.ProguardVersion;
import com.android.tools.r8.SingleTestRunResult;
import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.DexVm;
@@ -219,6 +220,11 @@
}
public StackTrace retrace(String map, Path tempFolder) throws IOException {
+ return retrace(ProguardVersion.getLatest(), map, tempFolder);
+ }
+
+ public StackTrace retrace(ProguardVersion proguardVersion, String map, Path tempFolder)
+ throws IOException {
Path mapFile = tempFolder.resolve("map");
Path stackTraceFile = tempFolder.resolve("stackTrace");
FileUtils.writeTextFile(mapFile, map);
@@ -227,7 +233,8 @@
stackTraceLines.stream().map(line -> line.originalLine).collect(Collectors.toList()));
// Keep the original stderr in the retraced stacktrace.
return new StackTrace(
- internalExtractFromJvm(ToolHelper.runRetrace(mapFile, stackTraceFile)), originalStderr);
+ internalExtractFromJvm(ToolHelper.runRetrace(proguardVersion, mapFile, stackTraceFile)),
+ originalStderr);
}
public StackTrace filter(Predicate<StackTraceLine> filter) {
diff --git a/src/test/java/com/android/tools/r8/naming/retraceproguard/VerticalClassMergingRetraceTest.java b/src/test/java/com/android/tools/r8/naming/retraceproguard/VerticalClassMergingRetraceTest.java
index 3ad54fb..5905930 100644
--- a/src/test/java/com/android/tools/r8/naming/retraceproguard/VerticalClassMergingRetraceTest.java
+++ b/src/test/java/com/android/tools/r8/naming/retraceproguard/VerticalClassMergingRetraceTest.java
@@ -75,15 +75,8 @@
return height;
}
- private boolean filterSynthesizedMethodWhenLineNumberAvailable(
- StackTraceLine retracedStackTraceLine) {
- return retracedStackTraceLine.lineNumber > 0;
- }
-
private boolean filterSynthesizedMethod(StackTraceLine retracedStackTraceLine) {
- return haveSeenLines.add(retracedStackTraceLine)
- && (retracedStackTraceLine.className.contains("ResourceWrapper")
- || retracedStackTraceLine.className.contains("MainApp"));
+ return retracedStackTraceLine.lineNumber > 0;
}
@Test
@@ -95,7 +88,7 @@
StackTrace reprocessedStackTrace =
mode == CompilationMode.DEBUG
? retracedStackTrace
- : retracedStackTrace.filter(this::filterSynthesizedMethodWhenLineNumberAvailable);
+ : retracedStackTrace.filter(this::filterSynthesizedMethod);
assertThat(
reprocessedStackTrace.filter(this::isNotDalvikNativeStartMethod),
isSameExceptForFileName(
@@ -114,7 +107,7 @@
StackTrace reprocessedStackTrace =
mode == CompilationMode.DEBUG
? retracedStackTrace
- : retracedStackTrace.filter(this::filterSynthesizedMethodWhenLineNumberAvailable);
+ : retracedStackTrace.filter(this::filterSynthesizedMethod);
assertThat(
reprocessedStackTrace.filter(this::isNotDalvikNativeStartMethod),
isSameExceptForFileName(