From 4903c7823eabaeb71f285b5659bd524e2de3a26f Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 29 Jun 2021 19:18:17 -0700 Subject: [PATCH] Converting some TAPL sequence mismatches to human-readable diags. Test: local runs Bug: 187761685 Change-Id: Ie2c64a22f56b0bed1cd175486b42beedb06285cc --- .../launcher3/tapl/LogEventChecker.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java b/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java index a809e2e30c..710e3cd691 100644 --- a/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java +++ b/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java @@ -15,6 +15,10 @@ */ package com.android.launcher3.tapl; +import static com.android.launcher3.testing.TestProtocol.SEQUENCE_MAIN; +import static com.android.launcher3.testing.TestProtocol.SEQUENCE_PILFER; +import static com.android.launcher3.testing.TestProtocol.SEQUENCE_TIS; + import android.os.SystemClock; import com.android.launcher3.testing.TestProtocol; @@ -87,6 +91,24 @@ public class LogEventChecker { final ListMap actualEvents = finishSync(waitForExpectedCountMs); if (actualEvents == null) return "null event sequences because launcher likely died"; + final String lowLevelDiags = lowLevelMismatchDiagnostics(actualEvents); + // If we have a sequence mismatch for a successful gesture, we want to provide all low-level + // details. + if (successfulGesture) { + return lowLevelDiags; + } + + final String sequenceMismatchInEnglish = highLevelMismatchDiagnostics(actualEvents); + + if (sequenceMismatchInEnglish != null) { + LauncherInstrumentation.log(lowLevelDiags); + return "Hint: " + sequenceMismatchInEnglish; + } else { + return lowLevelDiags; + } + } + + private String lowLevelMismatchDiagnostics(ListMap actualEvents) { final StringBuilder sb = new StringBuilder(); boolean hasMismatches = false; for (Map.Entry> expectedEvents : mExpectedEvents.entrySet()) { @@ -118,6 +140,42 @@ public class LogEventChecker { return hasMismatches ? "Mismatching events: " + sb.toString() : null; } + private String highLevelMismatchDiagnostics(ListMap actualEvents) { + if (!mExpectedEvents.getNonNull(SEQUENCE_TIS).isEmpty() + && actualEvents.getNonNull(SEQUENCE_TIS).isEmpty()) { + return "TouchInteractionService didn't receive any of the touch events sent by the " + + "test"; + } + if (getMismatchPosition(mExpectedEvents.getNonNull(SEQUENCE_TIS), + actualEvents.getNonNull(SEQUENCE_TIS)) != -1) { + // If TIS has a mismatch that we can't convert to high-level diags, don't convert + // other sequences either. + return null; + } + + if (mExpectedEvents.getNonNull(SEQUENCE_PILFER).size() == 1 + && actualEvents.getNonNull(SEQUENCE_PILFER).isEmpty()) { + return "Launcher didn't detect the navigation gesture sent by the test"; + } + if (mExpectedEvents.getNonNull(SEQUENCE_PILFER).isEmpty() + && actualEvents.getNonNull(SEQUENCE_PILFER).size() == 1) { + return "Launcher detected a navigation gesture, but the test didn't send one"; + } + if (getMismatchPosition(mExpectedEvents.getNonNull(SEQUENCE_PILFER), + actualEvents.getNonNull(SEQUENCE_PILFER)) != -1) { + // If Pilfer has a mismatch that we can't convert to high-level diags, don't analyze + // other sequences. + return null; + } + + if (!mExpectedEvents.getNonNull(SEQUENCE_MAIN).isEmpty() + && actualEvents.getNonNull(SEQUENCE_MAIN).isEmpty()) { + return "None of the touch or keyboard events sent by the test was received by " + + "Launcher's main thread"; + } + return null; + } + // If the list of actual events matches the list of expected events, returns -1, otherwise // the position of the mismatch. private static int getMismatchPosition(List expected, List actual) {