diff --git a/build/mobile/devicemanager.py b/build/mobile/devicemanager.py index f735b984c55..3e65420bd58 100755 --- a/build/mobile/devicemanager.py +++ b/build/mobile/devicemanager.py @@ -7,6 +7,7 @@ import hashlib import socket import os import re +import StringIO class FileError(Exception): " Signifies an error which occurs while doing a file operation." @@ -473,6 +474,33 @@ class DeviceManager: success: time in ms failure: None """ + + def recordLogcat(self): + """ + external function + returns: + success: file is created in /logcat.log + failure: + """ + #TODO: spawn this off in a separate thread/process so we can collect all the logcat information + + # Right now this is just clearing the logcat so we can only see what happens after this call. + buf = StringIO.StringIO() + self.shell(['/system/bin/logcat', '-c'], buf) + + def getLogcat(self): + """ + external function + returns: data from the local file + success: file is in 'filename' + failure: None + """ + buf = StringIO.StringIO() + if self.shell(["/system/bin/logcat", "-d", "dalvikvm:S", "ConnectivityService:S", "WifiMonitor:S", "WifiStateTracker:S", "wpa_supplicant:S", "NetworkStateTracker:S"], buf) != 0: + return None + + return str(buf.getvalue()[0:-1]).rstrip().split('\r') + class NetworkTools: def __init__(self): diff --git a/build/mobile/devicemanagerSUT.py b/build/mobile/devicemanagerSUT.py index 992ccb13e73..270e051c5c8 100644 --- a/build/mobile/devicemanagerSUT.py +++ b/build/mobile/devicemanagerSUT.py @@ -263,7 +263,7 @@ class DeviceManagerSUT(DeviceManager): if cwd: self.sendCmds(['execcwd %s %s' % (cwd, cmdline)], outputfile) else: - self.sendCmds(['exec %s' % cmdline], outputfile) + self.sendCmds(['exec su -c "%s"' % cmdline], outputfile) except AgentError: return None diff --git a/layout/tools/reftest/remotereftest.py b/layout/tools/reftest/remotereftest.py index 885f9501a6b..a60d789b935 100644 --- a/layout/tools/reftest/remotereftest.py +++ b/layout/tools/reftest/remotereftest.py @@ -187,7 +187,7 @@ class ReftestServer: pid = self._process.pid if pid < 0: print "Error starting server." - sys.exit(2) + return 2 self._automation.log.info("INFO | remotereftests.py | Server pid: %d", pid) if (self.pidFile != ""): @@ -208,7 +208,7 @@ class ReftestServer: else: print "Timed out while waiting for server startup." self.stop() - sys.exit(1) + return 1 def stop(self): try: @@ -272,7 +272,7 @@ class RemoteReftest(RefTest): options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) - sys.exit(1) + return 1 paths.append("bin") paths.append(os.path.join("..", "bin")) @@ -285,15 +285,20 @@ class RemoteReftest(RefTest): options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) - sys.exit(1) + return 1 options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) - self.server.start() + retVal = self.server.start() + if retVal: + return retVal + retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) + if retVal: + return retVal - self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath + return 0 def stopWebServer(self, options): self.server.stop() @@ -351,14 +356,14 @@ user_pref("capability.principal.codebase.p2.id", "http://%s:%s"); except: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile -def main(): +def main(args): automation = RemoteAutomation(None) parser = RemoteOptions(automation) options, args = parser.parse_args() if (options.deviceIP == None): print "Error: you must provide a device IP to connect to via the --device option" - sys.exit(1) + return 1 try: if (options.dm_trans == "adb"): @@ -370,7 +375,7 @@ def main(): dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) except devicemanager.DMError: print "Error: exception while initializing devicemanager. Most likely the device is not in a testable state." - sys.exit(1) + return 1 automation.setDeviceManager(dm) @@ -381,7 +386,7 @@ def main(): options = parser.verifyRemoteOptions(options) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" - sys.exit(1) + return 1 if not options.ignoreWindowSize: parts = dm.getInfo('screen')['screen'][0].split() @@ -389,7 +394,7 @@ def main(): height = int(parts[1].split(':')[1]) if (width < 1050 or height < 1050): print "ERROR: Invalid screen resolution %sx%s, please adjust to 1366x1050 or higher" % (width, height) - sys.exit(1) + return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) @@ -408,10 +413,12 @@ def main(): manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath else: print "ERROR: Could not find test manifest '%s'" % manifest - sys.exit(1) + return 1 # Start the webserver - reftest.startWebServer(options) + retVal = reftest.startWebServer(options) + if retVal: + return retVal procName = options.app.split('/')[-1] if (dm.processExist(procName)): @@ -419,18 +426,23 @@ def main(): #an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" + logcat = [] try: cmdlineArgs = ["-reftest", manifest] if options.bootstrap: cmdlineArgs = [] + dm.recordLogcat() reftest.runTests(manifest, options, cmdlineArgs) + logcat = dm.getLogcat() except: print "TEST-UNEXPECTED-FAIL | | exception while running reftests" reftest.stopWebServer(options) - sys.exit(1) + return 1 reftest.stopWebServer(options) + print ''.join(logcat[-500:-1]) + return 0 if __name__ == "__main__": - main() - + sys.exit(main(sys.argv[1:])) + diff --git a/testing/mochitest/runtestsremote.py b/testing/mochitest/runtestsremote.py index 4f940b66bf8..32a23914538 100644 --- a/testing/mochitest/runtestsremote.py +++ b/testing/mochitest/runtestsremote.py @@ -440,6 +440,7 @@ def main(): appname = options.app retVal = None + logcat = [] for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue @@ -450,7 +451,9 @@ def main(): options.browserArgs.append("org.mozilla.roboexample.test/android.test.InstrumentationTestRunner") try: + dm.recordLogcat() retVal = mochitest.runTests(options) + logcat = dm.getLogcat() mochitest.addLogData() except: print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running robocop tests." % sys.exc_info()[1] @@ -465,10 +468,12 @@ def main(): print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 - retVal = mochitest.printLog() + retVal = mochitest.printLog() else: try: + dm.recordLogcat() retVal = mochitest.runTests(options) + logcat = dm.getLogcat() except: print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info()[1] mochitest.stopWebServer(options) @@ -479,6 +484,7 @@ def main(): pass sys.exit(1) + print ''.join(logcat[-500:-1]) sys.exit(retVal) if __name__ == "__main__":