From 01372013d3ccea1f0fccdefbf8ba8322653cbb71 Mon Sep 17 00:00:00 2001 From: vadimt Date: Wed, 29 Jan 2020 15:24:00 -0800 Subject: [PATCH] Recognizing another SystemUI failure Also switching investigator to logs starting with the system reboot, as SysUI crashes before the tests start. Change-Id: Ifab835c1ab3c1ce3495f012c6a522fae6e44a9ff --- .../util/rule/FailureInvestigator.java | 29 ++++++++++++++----- .../util/rule/FailureRewriterRule.java | 9 +----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java index be6f865b35..dcc7b7c98e 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java +++ b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java @@ -18,9 +18,13 @@ package com.android.launcher3.util.rule; import static androidx.test.InstrumentationRegistry.getInstrumentation; +import android.os.SystemClock; + import androidx.test.uiautomator.UiDevice; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.regex.Pattern; class FailureInvestigator { @@ -28,17 +32,21 @@ class FailureInvestigator { return Pattern.compile(regex).matcher(string).find(); } - static int getBugForFailure(CharSequence exception, String testsStartTime) { + static int getBugForFailure(CharSequence exception) { if ("com.google.android.setupwizard".equals( UiDevice.getInstance(getInstrumentation()).getLauncherPackageName())) { return 145935261; } - final String logSinceTestsStart; + final String logSinceBoot; try { - logSinceTestsStart = + final String systemBootTime = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format( + new Date(System.currentTimeMillis() - SystemClock.elapsedRealtime())); + + logSinceBoot = UiDevice.getInstance(getInstrumentation()) - .executeShellCommand("logcat -d -t " + testsStartTime.replace(" ", "")); + .executeShellCommand("logcat -d -t " + systemBootTime.replace(" ", "")); } catch (IOException e) { return 0; } @@ -49,19 +57,24 @@ class FailureInvestigator { exception)) { if (matches( "BroadcastQueue: Can't deliver broadcast to com.android.systemui.*Crashing it", - logSinceTestsStart)) { + logSinceBoot)) { return 147845913; } if (matches( "Attempt to invoke virtual method 'boolean android\\.graphics\\.Bitmap\\" + ".isRecycled\\(\\)' on a null object reference", - logSinceTestsStart)) { + logSinceBoot)) { return 148424291; } + if (matches( + "java\\.lang\\.IllegalArgumentException\\: Ranking map doesn't contain key", + logSinceBoot)) { + return 148570537; + } } else if (matches("java.lang.AssertionError: Launcher build match not found", exception)) { if (matches( "TestStabilityRule: Launcher package: com.google.android.setupwizard", - logSinceTestsStart)) { + logSinceBoot)) { return 145935261; } } else if (matches("Launcher didn't initialize", exception)) { @@ -69,7 +82,7 @@ class FailureInvestigator { "ActivityManager: Reason: executing service com.google.android.apps" + ".nexuslauncher/com.android.launcher3.notification" + ".NotificationListener", - logSinceTestsStart)) { + logSinceBoot)) { return 148238677; } } diff --git a/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java index 4cb309a34a..99ddee419b 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java +++ b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java @@ -22,15 +22,9 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import java.text.SimpleDateFormat; -import java.util.Date; - public class FailureRewriterRule implements TestRule { private static final String TAG = "FailureRewriter"; - private static final String testsStartTime = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()); - @Override public Statement apply(Statement base, Description description) { return new Statement() { @@ -39,8 +33,7 @@ public class FailureRewriterRule implements TestRule { try { base.evaluate(); } catch (Throwable e) { - final int bug = - FailureInvestigator.getBugForFailure(e.toString(), testsStartTime); + final int bug = FailureInvestigator.getBugForFailure(e.toString()); if (bug == 0) throw e; Log.e(TAG, "Known bug found for the original failure "