Bug 1340233 - Take more care when killing browser before starting Android tests. r=jmaher, a=test-only
authorGeoff Brown <gbrown@mozilla.com>
Wed, 12 Apr 2017 09:15:53 -0600
changeset 396127 4bde2e27fdf2ab39ff95ec8f29020f3df560ea72
parent 396126 1372b319b9e471e4e52a6b859da46e576e3cf2a8
child 396128 29e9a1d26de8b83494ef55f63a9cfc47d8204199
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher, test-only
bugs1340233
milestone54.0
Bug 1340233 - Take more care when killing browser before starting Android tests. r=jmaher, a=test-only The devicemanager killProcess() is updated to use force-stop first, then use kill if force-stop does not work. Browser test harnesses are updated to check if killProcess() worked, and warn if it failed.
layout/tools/reftest/remotereftest.py
testing/mochitest/runrobocop.py
testing/mochitest/runtestsremote.py
testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
--- a/layout/tools/reftest/remotereftest.py
+++ b/layout/tools/reftest/remotereftest.py
@@ -387,18 +387,19 @@ def run_test_harness(parser, options):
     os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest")))
 
     # Start the webserver
     retVal = reftest.startWebServer(options)
     if retVal:
         return retVal
 
     procName = options.app.split('/')[-1]
-    if (dm.processExist(procName)):
-        dm.killProcess(procName)
+    dm.killProcess(procName)
+    if dm.processExist(procName):
+        print "unable to kill %s before starting tests!" % procName
 
     if options.printDeviceInfo:
         reftest.printDeviceInfo()
 
 # an example manifest name to use on the cli
 # manifest = "http://" + options.remoteWebServer +
 # "/reftests/layout/reftests/reftest-sanity/reftest.list"
     retVal = 0
--- a/testing/mochitest/runrobocop.py
+++ b/testing/mochitest/runrobocop.py
@@ -84,17 +84,20 @@ class RobocopTestRunner(MochitestDesktop
         # we still see infrequent cases where a process is orphaned and interferes
         # with future tests, typically because the old server is keeping the port in use.
         # Try to avoid those failures by checking for and killing orphan servers before
         # trying to start new ones.
         self.killNamedOrphans('ssltunnel')
         self.killNamedOrphans('xpcshell')
         self.auto.deleteANRs()
         self.auto.deleteTombstones()
-        self.dm.killProcess(self.options.app.split('/')[-1])
+        procName = self.options.app.split('/')[-1]
+        self.dm.killProcess(procName)
+        if self.dm.processExist(procName):
+            self.log.warning("unable to kill %s before running tests!" % procName)
         self.dm.removeDir(self.remoteScreenshots)
         self.dm.removeDir(self.remoteMozLog)
         self.dm.mkDir(self.remoteMozLog)
         self.dm.mkDir(os.path.dirname(self.options.remoteLogFile))
         # Add Android version (SDK level) to mozinfo so that manifest entries
         # can be conditional on android_version.
         androidVersion = self.dm.shellCheckOutput(
             ['getprop', 'ro.build.version.sdk'])
--- a/testing/mochitest/runtestsremote.py
+++ b/testing/mochitest/runtestsremote.py
@@ -350,16 +350,18 @@ def run_test_harness(parser, options):
         dm.removeFile(dmdPathOnDevice)
         dm.pushFile(os.path.join(options.dmdPath, dmdLibrary), dmdPathOnDevice)
         options.dmdPath = deviceRoot
 
     options.dumpOutputDirectory = deviceRoot
 
     procName = options.app.split('/')[-1]
     dm.killProcess(procName)
+    if dm.processExist(procName):
+        log.warning("unable to kill %s before running tests!" % procName)
 
     mochitest.mozLogName = "moz.log"
     try:
         dm.recordLogcat()
         retVal = mochitest.runTests(options)
     except:
         log.error("Automation Error: Exception caught while running tests")
         traceback.print_exc()
--- a/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
@@ -454,16 +454,22 @@ class DeviceManagerADB(DeviceManager):
             acmd.append(uri)
 
         acmd = ["shell", ' '.join(map(lambda x: '"' + x + '"', ["am", "start"] + acmd))]
         self._logger.info(acmd)
         self._checkCmd(acmd)
         return outputFile
 
     def killProcess(self, appname, sig=None):
+        try:
+            self.shellCheckOutput(["am", "force-stop", appname], timeout=self.short_timeout)
+        except:
+            # no problem - will kill it instead
+            self._logger.info("killProcess failed force-stop of %s" % appname)
+
         shell_args = ["shell"]
         if self._sdk_version >= version_codes.N:
             # Bug 1334613 - force use of root
             if self._haveRootShell is None and self._haveSu is None:
                 self._checkForRoot()
             if not self._haveRootShell and not self._haveSu:
                 raise DMError(
                     "killProcess '%s' requested to run as root but root "