Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 952471f6 authored by vadimt's avatar vadimt
Browse files

Removing automatic failure investigator

It wasn't updated for a while,
creates a false impression that the failure
is already tracked, and hopefully soon
will be replaced by new clustering.

Test: presubmit
Bug: 161478674
Change-Id: Icc3716c1f534867d5e4b21d18c9cede273da8704
parent 43182892
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import com.android.launcher3.tapl.OverviewTask;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.testcomponent.TestCommandReceiver;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureRewriterRule;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.quickstep.views.RecentsView;

@@ -100,8 +99,7 @@ public class FallbackRecentsTest {
        }

        mOrderSensitiveRules = RuleChain
                .outerRule(new FailureRewriterRule())
                .around(new NavigationModeSwitchRule(mLauncher))
                .outerRule(new NavigationModeSwitchRule(mLauncher))
                .around(new FailureWatcher(mDevice));

        mOtherLauncherActivity = context.getPackageManager().queryIntentActivities(
+2 −4
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureRewriterRule;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
@@ -224,9 +223,8 @@ public abstract class AbstractLauncherUiTest {
    }

    @Rule
    public TestRule mOrderSensitiveRules = RuleChain.
            outerRule(new FailureRewriterRule())
            .around(new TestStabilityRule())
    public TestRule mOrderSensitiveRules = RuleChain
            .outerRule(new TestStabilityRule())
            .around(mActivityMonitor)
            .around(getRulesInsideActivityMonitor());

+0 −121
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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 {
    private static boolean matches(String regex, CharSequence string) {
        return Pattern.compile(regex).matcher(string).find();
    }

    static class LogcatMatch {
        String logcatPattern;
        int bug;

        LogcatMatch(String logcatPattern, int bug) {
            this.logcatPattern = logcatPattern;
            this.bug = bug;
        }
    }

    static class ExceptionMatch {
        String exceptionPattern;
        LogcatMatch[] logcatMatches;

        ExceptionMatch(String exceptionPattern, LogcatMatch[] logcatMatches) {
            this.exceptionPattern = exceptionPattern;
            this.logcatMatches = logcatMatches;
        }
    }

    private static final ExceptionMatch[] EXCEPTION_MATCHES = {
            new ExceptionMatch(
                    "java.lang.AssertionError: http://go/tapl : Tests are broken by a "
                            + "non-Launcher system error: (Phone is locked|Screen is empty)",
                    new LogcatMatch[]{
                            new LogcatMatch(
                                    "BroadcastQueue: Can't deliver broadcast to com.android"
                                            + ".systemui.*Crashing it",
                                    147845913),
                            new LogcatMatch(
                                    "Attempt to invoke virtual method 'boolean android\\"
                                            + ".graphics\\.Bitmap\\.isRecycled\\(\\)' on a null "
                                            + "object reference",
                                    148424291),
                            new LogcatMatch(
                                    "java\\.lang\\.IllegalArgumentException\\: Ranking map "
                                            + "doesn't contain key",
                                    148570537),
                    }),
            new ExceptionMatch("Launcher didn't initialize",
                    new LogcatMatch[]{
                            new LogcatMatch(
                                    "ActivityManager: Reason: executing service com.google"
                                            + ".android.apps.nexuslauncher/com.android.launcher3"
                                            + ".notification.NotificationListener",
                                    148238677),
                    }),
    };

    static int getBugForFailure(CharSequence exception) {
        if ("com.google.android.setupwizard".equals(
                UiDevice.getInstance(getInstrumentation()).getLauncherPackageName())) {
            return 145935261;
        }

        final String logSinceBoot;
        try {
            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 " + systemBootTime.replace(" ", ""));
        } catch (IOException | OutOfMemoryError e) {
            return 0;
        }

        if (matches("android\\:\\:uirenderer\\:\\:renderthread\\:\\:EglManager\\:\\:swapBuffers",
                logSinceBoot)) {
            return 148529608;
        }

        for (ExceptionMatch exceptionMatch : EXCEPTION_MATCHES) {
            if (matches(exceptionMatch.exceptionPattern, exception)) {
                for (LogcatMatch logcatMatch : exceptionMatch.logcatMatches) {
                    if (matches(logcatMatch.logcatPattern, logSinceBoot)) {
                        return logcatMatch.bug;
                    }
                }
                break;
            }
        }

        return 0;
    }
}
+0 −47
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.util.rule;

import android.util.Log;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class FailureRewriterRule implements TestRule {
    private static final String TAG = "FailureRewriter";

    @Override
    public Statement apply(Statement base, Description description) {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                try {
                    base.evaluate();
                } catch (Throwable e) {
                    final int bug = FailureInvestigator.getBugForFailure(e.toString());
                    if (bug == 0) throw e;

                    Log.e(TAG, "Known bug found for the original failure "
                            + android.util.Log.getStackTraceString(e));
                    throw new AssertionError(
                            "Detected a failure that matches a known bug b/" + bug);
                }
            }
        };
    }
}