зеркало из https://github.com/mozilla/pjs.git
Bug 754873 - fennec automated tests should capture logcat output while test is running. r=wlach
This commit is contained in:
Родитель
6216a7d028
Коммит
47cef21075
|
@ -7,6 +7,7 @@ import hashlib
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import StringIO
|
||||||
|
|
||||||
class FileError(Exception):
|
class FileError(Exception):
|
||||||
" Signifies an error which occurs while doing a file operation."
|
" Signifies an error which occurs while doing a file operation."
|
||||||
|
@ -473,6 +474,33 @@ class DeviceManager:
|
||||||
success: time in ms
|
success: time in ms
|
||||||
failure: None
|
failure: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def recordLogcat(self):
|
||||||
|
"""
|
||||||
|
external function
|
||||||
|
returns:
|
||||||
|
success: file is created in <testroot>/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:
|
class NetworkTools:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -263,7 +263,7 @@ class DeviceManagerSUT(DeviceManager):
|
||||||
if cwd:
|
if cwd:
|
||||||
self.sendCmds(['execcwd %s %s' % (cwd, cmdline)], outputfile)
|
self.sendCmds(['execcwd %s %s' % (cwd, cmdline)], outputfile)
|
||||||
else:
|
else:
|
||||||
self.sendCmds(['exec %s' % cmdline], outputfile)
|
self.sendCmds(['exec su -c "%s"' % cmdline], outputfile)
|
||||||
except AgentError:
|
except AgentError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ class ReftestServer:
|
||||||
pid = self._process.pid
|
pid = self._process.pid
|
||||||
if pid < 0:
|
if pid < 0:
|
||||||
print "Error starting server."
|
print "Error starting server."
|
||||||
sys.exit(2)
|
return 2
|
||||||
self._automation.log.info("INFO | remotereftests.py | Server pid: %d", pid)
|
self._automation.log.info("INFO | remotereftests.py | Server pid: %d", pid)
|
||||||
|
|
||||||
if (self.pidFile != ""):
|
if (self.pidFile != ""):
|
||||||
|
@ -208,7 +208,7 @@ class ReftestServer:
|
||||||
else:
|
else:
|
||||||
print "Timed out while waiting for server startup."
|
print "Timed out while waiting for server startup."
|
||||||
self.stop()
|
self.stop()
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
try:
|
try:
|
||||||
|
@ -272,7 +272,7 @@ class RemoteReftest(RefTest):
|
||||||
options.xrePath = self.findPath(paths)
|
options.xrePath = self.findPath(paths)
|
||||||
if options.xrePath == None:
|
if options.xrePath == None:
|
||||||
print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name)
|
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("bin")
|
||||||
paths.append(os.path.join("..", "bin"))
|
paths.append(os.path.join("..", "bin"))
|
||||||
|
|
||||||
|
@ -285,15 +285,20 @@ class RemoteReftest(RefTest):
|
||||||
options.utilityPath = self.findPath(paths, xpcshell)
|
options.utilityPath = self.findPath(paths, xpcshell)
|
||||||
if options.utilityPath == None:
|
if options.utilityPath == None:
|
||||||
print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name)
|
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()
|
options.serverProfilePath = tempfile.mkdtemp()
|
||||||
self.server = ReftestServer(localAutomation, options, self.scriptDir)
|
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.xrePath = remoteXrePath
|
||||||
options.utilityPath = remoteUtilityPath
|
options.utilityPath = remoteUtilityPath
|
||||||
|
return 0
|
||||||
|
|
||||||
def stopWebServer(self, options):
|
def stopWebServer(self, options):
|
||||||
self.server.stop()
|
self.server.stop()
|
||||||
|
@ -351,14 +356,14 @@ user_pref("capability.principal.codebase.p2.id", "http://%s:%s");
|
||||||
except:
|
except:
|
||||||
print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile
|
print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile
|
||||||
|
|
||||||
def main():
|
def main(args):
|
||||||
automation = RemoteAutomation(None)
|
automation = RemoteAutomation(None)
|
||||||
parser = RemoteOptions(automation)
|
parser = RemoteOptions(automation)
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
if (options.deviceIP == None):
|
if (options.deviceIP == None):
|
||||||
print "Error: you must provide a device IP to connect to via the --device option"
|
print "Error: you must provide a device IP to connect to via the --device option"
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if (options.dm_trans == "adb"):
|
if (options.dm_trans == "adb"):
|
||||||
|
@ -370,7 +375,7 @@ def main():
|
||||||
dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort)
|
dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort)
|
||||||
except devicemanager.DMError:
|
except devicemanager.DMError:
|
||||||
print "Error: exception while initializing devicemanager. Most likely the device is not in a testable state."
|
print "Error: exception while initializing devicemanager. Most likely the device is not in a testable state."
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
automation.setDeviceManager(dm)
|
automation.setDeviceManager(dm)
|
||||||
|
|
||||||
|
@ -381,7 +386,7 @@ def main():
|
||||||
options = parser.verifyRemoteOptions(options)
|
options = parser.verifyRemoteOptions(options)
|
||||||
if (options == None):
|
if (options == None):
|
||||||
print "ERROR: Invalid options specified, use --help for a list of valid options"
|
print "ERROR: Invalid options specified, use --help for a list of valid options"
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
if not options.ignoreWindowSize:
|
if not options.ignoreWindowSize:
|
||||||
parts = dm.getInfo('screen')['screen'][0].split()
|
parts = dm.getInfo('screen')['screen'][0].split()
|
||||||
|
@ -389,7 +394,7 @@ def main():
|
||||||
height = int(parts[1].split(':')[1])
|
height = int(parts[1].split(':')[1])
|
||||||
if (width < 1050 or height < 1050):
|
if (width < 1050 or height < 1050):
|
||||||
print "ERROR: Invalid screen resolution %sx%s, please adjust to 1366x1050 or higher" % (width, height)
|
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.setAppName(options.app)
|
||||||
automation.setRemoteProfile(options.remoteProfile)
|
automation.setRemoteProfile(options.remoteProfile)
|
||||||
|
@ -408,10 +413,12 @@ def main():
|
||||||
manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath
|
manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath
|
||||||
else:
|
else:
|
||||||
print "ERROR: Could not find test manifest '%s'" % manifest
|
print "ERROR: Could not find test manifest '%s'" % manifest
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
# Start the webserver
|
# Start the webserver
|
||||||
reftest.startWebServer(options)
|
retVal = reftest.startWebServer(options)
|
||||||
|
if retVal:
|
||||||
|
return retVal
|
||||||
|
|
||||||
procName = options.app.split('/')[-1]
|
procName = options.app.split('/')[-1]
|
||||||
if (dm.processExist(procName)):
|
if (dm.processExist(procName)):
|
||||||
|
@ -419,18 +426,23 @@ def main():
|
||||||
|
|
||||||
#an example manifest name to use on the cli
|
#an example manifest name to use on the cli
|
||||||
# manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list"
|
# manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list"
|
||||||
|
logcat = []
|
||||||
try:
|
try:
|
||||||
cmdlineArgs = ["-reftest", manifest]
|
cmdlineArgs = ["-reftest", manifest]
|
||||||
if options.bootstrap:
|
if options.bootstrap:
|
||||||
cmdlineArgs = []
|
cmdlineArgs = []
|
||||||
|
dm.recordLogcat()
|
||||||
reftest.runTests(manifest, options, cmdlineArgs)
|
reftest.runTests(manifest, options, cmdlineArgs)
|
||||||
|
logcat = dm.getLogcat()
|
||||||
except:
|
except:
|
||||||
print "TEST-UNEXPECTED-FAIL | | exception while running reftests"
|
print "TEST-UNEXPECTED-FAIL | | exception while running reftests"
|
||||||
reftest.stopWebServer(options)
|
reftest.stopWebServer(options)
|
||||||
sys.exit(1)
|
return 1
|
||||||
|
|
||||||
reftest.stopWebServer(options)
|
reftest.stopWebServer(options)
|
||||||
|
print ''.join(logcat[-500:-1])
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
sys.exit(main(sys.argv[1:]))
|
||||||
|
|
||||||
|
|
|
@ -440,6 +440,7 @@ def main():
|
||||||
|
|
||||||
appname = options.app
|
appname = options.app
|
||||||
retVal = None
|
retVal = None
|
||||||
|
logcat = []
|
||||||
for test in robocop_tests:
|
for test in robocop_tests:
|
||||||
if options.testPath and options.testPath != test['name']:
|
if options.testPath and options.testPath != test['name']:
|
||||||
continue
|
continue
|
||||||
|
@ -450,7 +451,9 @@ def main():
|
||||||
options.browserArgs.append("org.mozilla.roboexample.test/android.test.InstrumentationTestRunner")
|
options.browserArgs.append("org.mozilla.roboexample.test/android.test.InstrumentationTestRunner")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
dm.recordLogcat()
|
||||||
retVal = mochitest.runTests(options)
|
retVal = mochitest.runTests(options)
|
||||||
|
logcat = dm.getLogcat()
|
||||||
mochitest.addLogData()
|
mochitest.addLogData()
|
||||||
except:
|
except:
|
||||||
print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running robocop tests." % sys.exc_info()[1]
|
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?"
|
print "No tests run. Did you pass an invalid TEST_PATH?"
|
||||||
retVal = 1
|
retVal = 1
|
||||||
|
|
||||||
retVal = mochitest.printLog()
|
retVal = mochitest.printLog()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
dm.recordLogcat()
|
||||||
retVal = mochitest.runTests(options)
|
retVal = mochitest.runTests(options)
|
||||||
|
logcat = dm.getLogcat()
|
||||||
except:
|
except:
|
||||||
print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info()[1]
|
print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info()[1]
|
||||||
mochitest.stopWebServer(options)
|
mochitest.stopWebServer(options)
|
||||||
|
@ -479,6 +484,7 @@ def main():
|
||||||
pass
|
pass
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
print ''.join(logcat[-500:-1])
|
||||||
sys.exit(retVal)
|
sys.exit(retVal)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Загрузка…
Ссылка в новой задаче