Test ART profile parse error diagnostics
Change-Id: I5856f8caefc92f0160fa687ad13aa72e14b9331b
diff --git a/src/main/java/com/android/tools/r8/experimental/startup/profile/art/HumanReadableARTProfileParser.java b/src/main/java/com/android/tools/r8/experimental/startup/profile/art/HumanReadableARTProfileParser.java
index 7aaff7c..29ffaa6 100644
--- a/src/main/java/com/android/tools/r8/experimental/startup/profile/art/HumanReadableARTProfileParser.java
+++ b/src/main/java/com/android/tools/r8/experimental/startup/profile/art/HumanReadableARTProfileParser.java
@@ -50,6 +50,9 @@
lineNumber++;
}
}
+ if (reporter != null) {
+ reporter.failIfPendingErrors();
+ }
} catch (IOException e) {
throw new UncheckedIOException(e);
}
@@ -57,7 +60,7 @@
private void parseError(String rule, int lineNumber, Origin origin) {
if (reporter != null) {
- reporter.warning(new HumanReadableARTProfileParserErrorDiagnostic(rule, lineNumber, origin));
+ reporter.error(new HumanReadableARTProfileParserErrorDiagnostic(rule, lineNumber, origin));
}
}
diff --git a/src/test/java/com/android/tools/r8/TestDiagnosticMessages.java b/src/test/java/com/android/tools/r8/TestDiagnosticMessages.java
index c53ec8c..a15b915 100644
--- a/src/test/java/com/android/tools/r8/TestDiagnosticMessages.java
+++ b/src/test/java/com/android/tools/r8/TestDiagnosticMessages.java
@@ -126,8 +126,9 @@
public abstract TestDiagnosticMessages assertWarningsMatch(
Collection<Matcher<Diagnostic>> matchers);
- public final TestDiagnosticMessages assertErrorsMatch(Matcher<Diagnostic> matcher) {
- return assertErrorsMatch(Collections.singletonList(matcher));
+ @SafeVarargs
+ public final TestDiagnosticMessages assertErrorsMatch(Matcher<Diagnostic>... matchers) {
+ return assertErrorsMatch(Arrays.asList(matchers));
}
public abstract TestDiagnosticMessages assertErrorsMatch(
diff --git a/src/test/java/com/android/tools/r8/startup/diagnostic/HumanReadableARTProfileParserErrorDiagnosticTest.java b/src/test/java/com/android/tools/r8/startup/diagnostic/HumanReadableARTProfileParserErrorDiagnosticTest.java
new file mode 100644
index 0000000..63283b6
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/startup/diagnostic/HumanReadableARTProfileParserErrorDiagnosticTest.java
@@ -0,0 +1,82 @@
+// Copyright (c) 2022, 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.startup.diagnostic;
+
+import static com.android.tools.r8.DiagnosticsMatcher.diagnosticMessage;
+import static com.android.tools.r8.DiagnosticsMatcher.diagnosticType;
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestDiagnosticMessages;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.origin.Origin;
+import com.android.tools.r8.startup.StartupProfileBuilder;
+import com.android.tools.r8.startup.StartupProfileProvider;
+import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.ConsumerUtils;
+import com.android.tools.r8.utils.UTF8TextInputStream;
+import java.io.ByteArrayInputStream;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class HumanReadableARTProfileParserErrorDiagnosticTest extends TestBase {
+
+ @Parameter(0)
+ public TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withNoneRuntime().build();
+ }
+
+ @Test(expected = CompilationFailedException.class)
+ public void test() throws Exception {
+ testForD8()
+ .addProgramClasses(Main.class)
+ .addStartupProfileProviders(
+ new StartupProfileProvider() {
+ @Override
+ public void getStartupProfile(StartupProfileBuilder startupProfileBuilder) {
+
+ startupProfileBuilder.addHumanReadableARTProfile(
+ new UTF8TextInputStream(
+ new ByteArrayInputStream("INVALID1\nINVALID2".getBytes())),
+ ConsumerUtils.emptyConsumer());
+ }
+
+ @Override
+ public Origin getOrigin() {
+ return Origin.unknown();
+ }
+ })
+ .release()
+ .setMinApi(AndroidApiLevel.LATEST)
+ .compileWithExpectedDiagnostics(this::inspectDiagnostics);
+ }
+
+ private void inspectDiagnostics(TestDiagnosticMessages diagnostics) {
+ diagnostics.assertErrorsMatch(
+ allOf(
+ diagnosticType(HumanReadableARTProfileParserErrorDiagnostic.class),
+ diagnosticMessage(
+ equalTo("Unable to parse rule at line 1 from ART profile: INVALID1"))),
+ allOf(
+ diagnosticType(HumanReadableARTProfileParserErrorDiagnostic.class),
+ diagnosticMessage(
+ equalTo("Unable to parse rule at line 2 from ART profile: INVALID2"))));
+ }
+
+ static class Main {
+
+ public static void main(String[] args) {}
+ }
+}