Bug 1465480 - Exit GeckoView tests after crash if MOZ_CRASHREPORTER_SHUTDOWN is set r=jchen
authorJames Willcox <snorp@snorp.net>
Tue, 05 Jun 2018 15:19:12 -0500
changeset 422041 3f9698c8d77d99bdb0225995202be91608a61415
parent 422040 b1638aab8138e367bfeb0f0b6d38e0fa63839ddc
child 422042 5a26880a2b24fc5a54595a3432c3484cea5d0e5f
push id34114
push userbtara@mozilla.com
push dateSat, 09 Jun 2018 15:31:58 +0000
treeherdermozilla-central@e02a5155d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1465480
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465480 - Exit GeckoView tests after crash if MOZ_CRASHREPORTER_SHUTDOWN is set r=jchen MozReview-Commit-ID: B5sPnbYojlr
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
@@ -1649,13 +1649,14 @@ class GeckoSessionTestRuleTest : BaseSes
             override fun onCrash(session: GeckoSession) = Unit
         })
     }
 
     @Test(expected = RuntimeException::class)
     @ReuseSession(false)
     fun contentCrashFails() {
         assumeThat(sessionRule.env.isMultiprocess, equalTo(true))
+        assumeThat(sessionRule.env.shouldShutdownOnCrash(), equalTo(false));
 
         sessionRule.session.loadUri(CONTENT_CRASH_URL)
         sessionRule.waitForPageStop()
     }
 }
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -37,16 +37,17 @@ import android.graphics.SurfaceTexture;
 import android.net.LocalSocketAddress;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Debug;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
 import android.os.MessageQueue;
+import android.os.Process;
 import android.os.SystemClock;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.rule.UiThreadTestRule;
 import android.util.Log;
 import android.util.Pair;
 import android.view.MotionEvent;
@@ -557,16 +558,20 @@ public class GeckoSessionTestRule extend
             }
             return "";
         }
 
         public boolean isAutomation() {
             return !getEnvVar("MOZ_IN_AUTOMATION").isEmpty();
         }
 
+        public boolean shouldShutdownOnCrash() {
+            return !getEnvVar("MOZ_CRASHREPORTER_SHUTDOWN").isEmpty();
+        }
+
         public boolean isMultiprocess() {
             return Boolean.valueOf(InstrumentationRegistry.getArguments()
                                                           .getString("use_multiprocess",
                                                                      "true"));
         }
 
         public boolean isDebugging() {
             return Debug.isDebuggerConnected();
@@ -1179,16 +1184,20 @@ public class GeckoSessionTestRule extend
                         assertThat("Callback first argument must be session object",
                                    args, arrayWithSize(greaterThan(0)));
                         assertThat("Callback first argument must be session object",
                                    args[0], instanceOf(GeckoSession.class));
                         session = (GeckoSession) args[0];
                     }
 
                     if (sOnCrash.equals(method) && !mIgnoreCrash && isUsingSession(session)) {
+                        if (env.shouldShutdownOnCrash()) {
+                            sRuntime.shutdown();
+                        }
+
                         throw new RuntimeException("Content process crashed");
                     }
 
                     records.add(new CallRecord(session, method, args));
 
                     call = waitDelegates.prepareMethodCall(session, method);
                     if (call == null) {
                         call = testDelegates.prepareMethodCall(session, method);
@@ -1237,23 +1246,34 @@ public class GeckoSessionTestRule extend
                                                 classes, recorder);
         mAllDelegates = new HashSet<>(DEFAULT_DELEGATES);
 
         if (sRuntime == null) {
             final GeckoRuntimeSettings.Builder runtimeSettingsBuilder =
                 new GeckoRuntimeSettings.Builder();
             runtimeSettingsBuilder.arguments(new String[] { "-purgecaches" })
                     .extras(InstrumentationRegistry.getArguments())
-                    .nativeCrashReportingEnabled(true)
-                    .javaCrashReportingEnabled(true)
                     .remoteDebuggingEnabled(true);
 
+            if (env.isAutomation()) {
+                runtimeSettingsBuilder
+                        .nativeCrashReportingEnabled(true)
+                        .javaCrashReportingEnabled(true);
+            }
+
             sRuntime = GeckoRuntime.create(
                 InstrumentationRegistry.getTargetContext(),
                 runtimeSettingsBuilder.build());
+
+            sRuntime.setDelegate(new GeckoRuntime.Delegate() {
+                @Override
+                public void onShutdown() {
+                    Process.killProcess(Process.myPid());
+                }
+            });
         }
 
         if (sCachedSession != null && !sCachedSession.isOpen()) {
             sCachedSession = null;
         }
 
         final boolean useDefaultSession = !mClosedSession && mDefaultSettings.equals(settings);
         if (useDefaultSession && mReuseSession && sCachedSession != null) {