def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) dm_none = devicemanager.DeviceManager(None, None) auto = RemoteAutomation(dm_none, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() dm = devicemanager.DeviceManager(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) sys.exit(mochitest.runTests(options))
def main(): dm_none = DeviceManager(None, None) automation = RemoteAutomation(dm_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) dm = DeviceManager(options.deviceIP, options.devicePort) automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set options = parser.verifyRemoteOptions(options) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) parts = dm.getInfo('screen')['screen'][0].split() width = int(parts[0].split(':')[1]) 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) automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) # Start the webserver reftest.startWebServer(options) # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot manifest = args[0] if os.path.exists(os.path.join(SCRIPT_DIRECTORY, args[0])): manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + args[0] elif os.path.exists(args[0]): manifestPath = os.path.abspath(args[0]).split(SCRIPT_DIRECTORY)[1].strip('/') manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) #an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" reftest.runTests(manifest, options) reftest.stopWebServer(options)
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) dm_none = devicemanagerADB.DeviceManagerADB() auto = RemoteAutomation(dm_none, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if options.dm_trans == "adb": if options.deviceIP: dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = dm_none else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if options == None: print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split(".") if productPieces != None: auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if options == None: sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) procName = options.app.split("/")[-1] if dm.processExist(procName): dm.killProcess(procName) try: retVal = mochitest.runTests(options) except: print "TEST-UNEXPECTED-ERROR | | Exception caught while running tests." mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) sys.exit(1) sys.exit(retVal)
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = devicemanagerADB.DeviceManagerADB() else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) print dm.getInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') if (options.dm_trans == 'adb' and options.robocopPath): dm._checkCmd([ "install", "-r", os.path.join(options.robocopPath, "robocop.apk") ]) appname = options.app retVal = None for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue options.app = "am" options.browserArgs = [ "instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class" ] options.browserArgs.append("%s.tests.%s" % (appname, test['name'])) options.browserArgs.append( "org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % appname) try: dm.recordLogcat() result = mochitest.runTests(options) if result != 0: print "ERROR: runTests() exited with code %s" % result # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result mochitest.addLogData() except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed overallResult = mochitest.printLog() if retVal == 0: retVal = overallResult else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 try: logcat = dm.getLogcat(filterOutRegexps=fennecLogcatFilters) print ''.join(logcat) print dm.getInfo() except devicemanager.DMError: print "WARNING: Error getting device information at end of test" sys.exit(retVal)
def main(): message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) parser = RemoteOptions(auto) structured.commandline.add_logging_group(parser) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) mochitest = MochiRemote(auto, dm, options) log = mochitest.log structured_logger = mochitest.structured_logger message_logger.logger = mochitest.structured_logger mochitest.message_logger = message_logger if (options == None): log.error("Invalid options specified, use --help for a list of valid options") sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info("Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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 options.robocopIni != "": # turning buffering off as it's not used in robocop message_logger.buffering = False # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocopIni) robocop_tests = mp.active_tests(exists=False, **mozinfo.info) tests = [] my_tests = tests for test in robocop_tests: tests.append(test['name']) if options.totalChunks: tests_per_chunk = math.ceil(len(tests) / (options.totalChunks * 1.0)) start = int(round((options.thisChunk-1) * tests_per_chunk)) end = int(round(options.thisChunk * tests_per_chunk)) if end > len(tests): end = len(tests) my_tests = tests[start:end] log.info("Running tests %d-%d/%d" % (start+1, end, len(tests))) dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath(os.path.join(SCRIPT_DIR, "fennec_ids.txt")) if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('layout.css.devPixelsPerPx=1.0') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') options.extraPrefs.append('browser.snippets.enabled=false') options.extraPrefs.append('browser.casting.enabled=true') if (options.dm_trans == 'adb' and options.robocopApk): dm._checkCmd(["install", "-r", options.robocopApk]) retVal = None # Filtering tests active_tests = [] for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if not test['name'] in my_tests: continue if 'disabled' in test: log.info('TEST-INFO | skipping %s | %s' % (test['name'], test['disabled'])) continue active_tests.append(test) structured_logger.suite_start([t['name'] for t in active_tests]) for test in active_tests: # When running in a loop, we need to create a fresh profile for each cycle if mochitest.localProfile: options.profilePath = mochitest.localProfile os.system("rm -Rf %s" % options.profilePath) options.profilePath = None mochitest.localProfile = options.profilePath options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("org.mozilla.gecko.tests.%s" % test['name']) options.browserArgs.append("org.mozilla.roboexample.test/org.mozilla.gecko.FennecInstrumentationTestRunner") # If the test is for checking the import from bookmarks then make sure there is data to import if test['name'] == "testImportFromAndroid": # Get the OS so we can run the insert in the apropriate database and following the correct table schema osInfo = dm.getInfo("os") devOS = " ".join(osInfo['os']) if ("pandaboard" in devOS): delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(delete)}]) # Insert the bookmarks log.info("Insert bookmarks in the default android browser database") for i in range(20): if ("pandaboard" in devOS): cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db 'insert or replace into bookmarks(_id,title,url,folder,parent,position) values (" + str(30 + i) + ",\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",0,1," + str(100 + i) + ");'"] else: cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db 'insert into bookmarks(title,url,bookmark) values (\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",1);'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd)}]) try: screenShotDir = "/mnt/sdcard/Robotium-Screenshots" dm.removeDir(screenShotDir) dm.recordLogcat() result = mochitest.runTests(options) if result != 0: log.error("runTests() exited with code %s" % result) log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo(printLogcat=True) mochitest.printScreenshots(screenShotDir) # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break finally: # Clean-up added bookmarks if test['name'] == "testImportFromAndroid": if ("pandaboard" in devOS): cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd_del)}]) if retVal is None: log.warning("No tests run. Did you pass an invalid TEST_PATH?") retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 message_logger.finish() mochitest.printDeviceInfo(printLogcat=True) sys.exit(retVal)
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" return 1 try: if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = devicemanagerADB.DeviceManagerADB(None, None, deviceRoot=options.remoteTestRoot) else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) except devicemanager.DMError: print "Error: exception while initializing devicemanager. Most likely the device is not in a testable state." return 1 automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set options = parser.verifyRemoteOptions(options) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" return 1 if not options.ignoreWindowSize: parts = dm.getInfo('screen')['screen'][0].split() width = int(parts[0].split(':')[1]) 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) return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) options = parser.verifyCommonOptions(options, reftest) # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot manifest = args[0] if os.path.exists(os.path.join(SCRIPT_DIRECTORY, args[0])): manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + args[0] elif os.path.exists(args[0]): manifestPath = os.path.abspath(args[0]).split(SCRIPT_DIRECTORY)[1].strip('/') manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath else: print "ERROR: Could not find test manifest '%s'" % manifest return 1 # Start the webserver retVal = reftest.startWebServer(options) if retVal: return retVal procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) print dm.getInfo() #an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" retVal = 0 try: cmdlineArgs = ["-reftest", manifest] if options.bootstrap: cmdlineArgs = [] dm.recordLogcat() retVal = reftest.runTests(manifest, options, cmdlineArgs) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) try: logcat = dm.getLogcat(filterOutRegexps=fennecLogcatFilters) print ''.join(logcat) print dm.getInfo() except devicemanager.DMError: print "WARNING: Error getting device information at end of test" return retVal
def runTests(options, parser): if (options.dm_trans == 'sut' and options.deviceIP == None): print "Error: If --dm_trans = sut, you must provide a device IP to connect to via the --deviceIP option" return 1 try: if (options.dm_trans == "adb"): if (options.deviceIP): dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) elif (options.deviceSerial): dm = droid.DroidADB(None, None, deviceSerial=options.deviceSerial, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(None, None, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) except devicemanager.DMError: print "Automation Error: exception while initializing devicemanager. Most likely the device is not in a testable state." return 1 automation = RemoteAutomation(None) automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set parser.validate_remote(options, automation) # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: print "%s is not installed on this device" % expected return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) parser.validate(options, reftest) if mozinfo.info['debug']: print "changing timeout for remote debug reftests from %s to 600 seconds" % options.timeout options.timeout = 600 # Hack in a symbolic link for jsreftest 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) 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 try: dm.recordLogcat() retVal = reftest.runTests(options.tests, options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) if options.printDeviceInfo: reftest.printDeviceInfo(printLogcat=True) return retVal
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = devicemanagerADB.DeviceManagerADB() else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) print dm.getInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') if (options.dm_trans == 'adb' and options.robocopPath): dm._checkCmd(["install", "-r", os.path.join(options.robocopPath, "robocop.apk")]) appname = options.app retVal = None for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("%s.tests.%s" % (appname, test['name'])) options.browserArgs.append("org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % appname) try: dm.recordLogcat() retVal = mochitest.runTests(options) mochitest.addLogData() except: print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running robocop tests." % sys.exc_info()[1] mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 if retVal == 0: # if we didn't have some kind of error running the tests, make # sure the tests actually passed retVal = mochitest.printLog() else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info()[1] mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 try: logcat = dm.getLogcat() print ''.join(logcat[-500:-1]) print dm.getInfo() except devicemanager.DMError: print "WARNING: Error getting device information at end of test" sys.exit(retVal)
def main(): auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): log.error("Invalid options specified, use --help for a list of valid options") sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) mochitest.printDeviceInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocopIni != "": # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocopIni) robocop_tests = mp.active_tests(exists=False) tests = [] my_tests = tests for test in robocop_tests: tests.append(test['name']) if options.totalChunks: tests_per_chunk = math.ceil(len(tests) / (options.totalChunks * 1.0)) start = int(round((options.thisChunk-1) * tests_per_chunk)) end = int(round(options.thisChunk * tests_per_chunk)) if end > len(tests): end = len(tests) my_tests = tests[start:end] log.info("Running tests %d-%d/%d", start+1, end, len(tests)) deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('layout.css.devPixelsPerPx="1.0"') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') if (options.dm_trans == 'adb' and options.robocopApk): dm._checkCmd(["install", "-r", options.robocopApk]) retVal = None for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if not test['name'] in my_tests: continue # When running in a loop, we need to create a fresh profile for each cycle if mochitest.localProfile: options.profilePath = mochitest.localProfile os.system("rm -Rf %s" % options.profilePath) options.profilePath = tempfile.mkdtemp() mochitest.localProfile = options.profilePath options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("%s.tests.%s" % (options.remoteappname, test['name'])) options.browserArgs.append("org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % options.remoteappname) # If the test is for checking the import from bookmarks then make sure there is data to import if test['name'] == "testImportFromAndroid": # Get the OS so we can run the insert in the apropriate database and following the correct table schema osInfo = dm.getInfo("os") devOS = " ".join(osInfo['os']) # Bug 900664: stock browser db not available on x86 emulator if ("sdk_x86" in devOS): continue if ("pandaboard" in devOS): delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(delete)}]) # Insert the bookmarks log.info("Insert bookmarks in the default android browser database") for i in range(20): if ("pandaboard" in devOS): cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db 'insert or replace into bookmarks(_id,title,url,folder,parent,position) values (" + str(30 + i) + ",\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",0,1," + str(100 + i) + ");'"] else: cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db 'insert into bookmarks(title,url,bookmark) values (\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",1);'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd)}]) try: dm.removeDir("/mnt/sdcard/Robotium-Screenshots") dm.recordLogcat() result = mochitest.runTests(options) if result != 0: log.error("runTests() exited with code %s", result) log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo(printLogcat=True) mochitest.printScreenshot() # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break finally: # Clean-up added bookmarks if test['name'] == "testImportFromAndroid": if ("pandaboard" in devOS): cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd_del)}]) if retVal is None: log.warn("No tests run. Did you pass an invalid TEST_PATH?") retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 mochitest.printDeviceInfo(printLogcat=True) sys.exit(retVal)
def run_test_harness(parser, options): parser.validate(options) message_logger = MessageLogger(logger=None) process_args = {"messageLogger": message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError("Invalid options specified, use --help for a list of valid options") options.runByDir = False # roboextender is used by mochitest-chrome tests like test_java_addons.html, # but not by any plain mochitests if options.flavor != "chrome": options.extensionsToExclude.append("*****@*****.**") dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger # Check that Firefox is installed expected = options.app.split("/")[-1] installed = dm.shellCheckOutput(["pm", "list", "packages", expected]) if expected not in installed: log.error("%s is not installed on this device" % expected) return 1 productPieces = options.remoteProductName.split(".") if productPieces is not None: auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) if options.log_mach is None: mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(["getprop", "ro.build.version.sdk"]) log.info("Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info["android_version"] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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) mochitest.mozLogName = "moz.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except mozdevice.DMError: # device error cleaning up... oh well! pass retVal = 1 if options.log_mach is None: mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
def run_test_harness(parser, options): dm_args = { 'deviceRoot': options.remoteTestRoot, 'host': options.deviceIP, 'port': options.devicePort, } dm_args['adbPath'] = options.adb_path if not dm_args['host']: dm_args['deviceSerial'] = options.deviceSerial if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug': dm_args['logLevel'] = logging.DEBUG try: dm = mozdevice.DroidADB(**dm_args) except mozdevice.DMError: traceback.print_exc() print( "Automation Error: exception while initializing devicemanager. " "Most likely the device is not in a testable state.") return 1 automation = RemoteAutomation(None) automation.setDeviceManager(dm) # Set up the defaults and ensure options are set parser.validate_remote(options, automation) # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: print "%s is not installed on this device" % expected return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) parser.validate(options, reftest) if mozinfo.info['debug']: print "changing timeout for remote debug reftests from %s to 600 seconds" % options.timeout options.timeout = 600 # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Despite our efforts to clean up servers started by this script, in practice # 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 servers before # trying to start new ones. reftest.killNamedProc('ssltunnel') reftest.killNamedProc('xpcshell') # Start the webserver retVal = reftest.startWebServer(options) if retVal: return retVal procName = options.app.split('/')[-1] 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 try: dm.recordLogcat() if options.verify: retVal = reftest.verifyTests(options.tests, options) else: retVal = reftest.runTests(options.tests, options) except Exception: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) if options.printDeviceInfo: reftest.printDeviceInfo(printLogcat=True) return retVal
def main(): dm_none = devicemanagerADB.DeviceManagerADB(None, None) automation = RemoteAutomation(dm_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) if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = dm_none else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set options = parser.verifyRemoteOptions(options) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) if not options.ignoreWindowSize: parts = dm.getInfo('screen')['screen'][0].split() width = int(parts[0].split(':')[1]) 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) automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot manifest = args[0] if os.path.exists(os.path.join(SCRIPT_DIRECTORY, args[0])): manifest = "http://" + str(options.remoteWebServer) + ":" + str( options.httpPort) + "/" + args[0] elif os.path.exists(args[0]): manifestPath = os.path.abspath( args[0]).split(SCRIPT_DIRECTORY)[1].strip('/') manifest = "http://" + str(options.remoteWebServer) + ":" + str( options.httpPort) + "/" + manifestPath else: print "ERROR: Could not find test manifest '%s'" % manifest sys.exit(1) # Start the webserver reftest.startWebServer(options) procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) #an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" try: cmdlineArgs = ["-reftest", manifest] if options.bootstrap: cmdlineArgs = [] reftest.runTests(manifest, options, cmdlineArgs) except: print "TEST-UNEXPECTED-FAIL | | exception while running reftests" reftest.stopWebServer(options) sys.exit(1) reftest.stopWebServer(options)
def main(): auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) mochitest.printDeviceInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocopIni != "": # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocopIni) robocop_tests = mp.active_tests(exists=False) tests = [] my_tests = tests for test in robocop_tests: tests.append(test['name']) if options.totalChunks: tests_per_chunk = math.ceil(len(tests) / (options.totalChunks * 1.0)) start = int(round((options.thisChunk-1) * tests_per_chunk)) end = int(round(options.thisChunk * tests_per_chunk)) if end > len(tests): end = len(tests) my_tests = tests[start:end] print "Running tests %d-%d/%d" % ((start+1), end, len(tests)) deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('layout.css.devPixelsPerPx="1.0"') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') if (options.dm_trans == 'adb' and options.robocopApk): dm._checkCmd(["install", "-r", options.robocopApk]) retVal = None for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if not test['name'] in my_tests: continue # When running in a loop, we need to create a fresh profile for each cycle if mochitest.localProfile: options.profilePath = mochitest.localProfile os.system("rm -Rf %s" % options.profilePath) options.profilePath = tempfile.mkdtemp() mochitest.localProfile = options.profilePath options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("%s.tests.%s" % (options.remoteappname, test['name'])) options.browserArgs.append("org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % options.remoteappname) # If the test is for checking the import from bookmarks then make sure there is data to import if test['name'] == "testImportFromAndroid": # Get the OS so we can run the insert in the apropriate database and following the correct table schema osInfo = dm.getInfo("os") devOS = " ".join(osInfo['os']) if ("pandaboard" in devOS): delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(delete)}]) # Insert the bookmarks print "Insert bookmarks in the default android browser database" for i in range(20): if ("pandaboard" in devOS): cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db 'insert or replace into bookmarks(_id,title,url,folder,parent,position) values (" + str(30 + i) + ",\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",0,1," + str(100 + i) + ");'"] else: cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db 'insert into bookmarks(title,url,bookmark) values (\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",1);'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd)}]) try: dm.removeDir("/mnt/sdcard/Robotium-Screenshots") dm.recordLogcat() result = mochitest.runTests(options) if result != 0: print "ERROR: runTests() exited with code %s" % result log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo(printLogcat=True) mochitest.printScreenshot() # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break finally: # Clean-up added bookmarks if test['name'] == "testImportFromAndroid": if ("pandaboard" in devOS): cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd_del)}]) if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 mochitest.printDeviceInfo(printLogcat=True) sys.exit(retVal)
def run_test_harness(parser, options): parser.validate(options) message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError("Invalid options specified, use --help for a list of valid options") options.runByManifest = False # roboextender is used by mochitest-chrome tests like test_java_addons.html, # but not by any plain mochitests if options.flavor != 'chrome': options.extensionsToExclude.append('*****@*****.**') dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) options.dm = None log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: log.error("%s is not installed on this device" % expected) return 1 productPieces = options.remoteProductName.split('.') if (productPieces is not None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.removeDir(logParent) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) if options.log_mach is None: mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info( "Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.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() if options.verify: retVal = mochitest.verifyTests(options) else: retVal = mochitest.runTests(options) except Exception: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except mozdevice.DMError: # device error cleaning up... oh well! pass retVal = 1 if options.log_mach is None: mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
def run_test_harness(options): message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError( "Invalid options specified, use --help for a list of valid options" ) dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger productPieces = options.remoteProductName.split('.') if (productPieces is not None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info("Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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 options.robocopIni != "": # turning buffering off as it's not used in robocop message_logger.buffering = False # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 if isinstance(options.manifestFile, TestManifest): mp = options.manifestFile else: mp = TestManifest(strict=False) mp.read(options.robocopIni) filters = [] if options.totalChunks: filters.append( chunk_by_slice(options.thisChunk, options.totalChunks)) robocop_tests = mp.active_tests(exists=False, filters=filters, **mozinfo.info) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('layout.css.devPixelsPerPx=1.0') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') options.extraPrefs.append('browser.snippets.enabled=false') options.extraPrefs.append('browser.casting.enabled=true') if (options.dm_trans == 'adb' and options.robocopApk): dm._checkCmd(["install", "-r", options.robocopApk]) if not options.autorun: # Force a single loop iteration. The iteration will start Fennec and # the httpd server, but not actually run a test. options.testPath = robocop_tests[0]['name'] retVal = None # Filtering tests active_tests = [] for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if 'disabled' in test: log.info('TEST-INFO | skipping %s | %s' % (test['name'], test['disabled'])) continue active_tests.append(test) log.suite_start([t['name'] for t in active_tests]) for test in active_tests: # When running in a loop, we need to create a fresh profile for # each cycle if mochitest.localProfile: options.profilePath = mochitest.localProfile os.system("rm -Rf %s" % options.profilePath) options.profilePath = None mochitest.localProfile = options.profilePath options.app = "am" mochitest.nsprLogName = "nspr-%s.log" % test['name'] if options.autorun: # This launches a test (using "am instrument") and instructs # Fennec to /quit/ the browser (using Robocop:Quit) and to # /finish/ all opened activities. options.browserArgs = [ "instrument", "-w", "-e", "quit_and_finish", "1", "-e", "deviceroot", deviceRoot, "-e", "class" ] options.browserArgs.append("org.mozilla.gecko.tests.%s" % test['name'].split('.java')[0]) options.browserArgs.append( "org.mozilla.roboexample.test/org.mozilla.gecko.FennecInstrumentationTestRunner" ) else: # This does not launch a test at all. It launches an activity # that starts Fennec and then waits indefinitely, since cat # never returns. options.browserArgs = [ "start", "-n", "org.mozilla.roboexample.test/org.mozilla.gecko.LaunchFennecWithConfigurationActivity", "&&", "cat" ] dm.default_timeout = sys.maxint # Forever. mochitest.log.info("") mochitest.log.info( "Serving mochi.test Robocop root at http://%s:%s/tests/robocop/" % (options.remoteWebServer, options.httpPort)) mochitest.log.info("") # If the test is for checking the import from bookmarks then make # sure there is data to import if test['name'] == "testImportFromAndroid": # Get the OS so we can run the insert in the apropriate # database and following the correct table schema osInfo = dm.getInfo("os") devOS = " ".join(osInfo['os']) if ("pandaboard" in devOS): delete = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'" ] else: delete = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'" ] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(delete)}]) # Insert the bookmarks log.info( "Insert bookmarks in the default android browser database") for i in range(20): if ("pandaboard" in devOS): cmd = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db 'insert or replace into bookmarks(_id,title,url,folder,parent,position) values (" + str(30 + i) + ",\"Bookmark" + str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",0,1," + str(100 + i) + ");'" ] else: cmd = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db 'insert into bookmarks(title,url,bookmark) values (\"Bookmark" + str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",1);'" ] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd)}]) try: screenShotDir = "/mnt/sdcard/Robotium-Screenshots" dm.removeDir(screenShotDir) dm.recordLogcat() result = mochitest.runTests(options) if result != 0: log.error("runTests() exited with code %s" % result) log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo(printLogcat=True) mochitest.printScreenshots(screenShotDir) # Ensure earlier failures aren't overwritten by success on this # run if retVal is None or retVal == 0: retVal = result except: log.error( "Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break finally: # Clean-up added bookmarks if test['name'] == "testImportFromAndroid": if ("pandaboard" in devOS): cmd_del = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'" ] else: cmd_del = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'" ] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd_del)}]) if retVal is None: log.warning("No tests run. Did you pass an invalid TEST_PATH?") retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: mochitest.nsprLogName = "nspr.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
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" return 1 try: if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = devicemanagerADB.DeviceManagerADB(None, None) else: 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." return 1 automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set options = parser.verifyRemoteOptions(options) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" return 1 if not options.ignoreWindowSize: parts = dm.getInfo('screen')['screen'][0].split() width = int(parts[0].split(':')[1]) 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) return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot manifest = args[0] if os.path.exists(os.path.join(SCRIPT_DIRECTORY, args[0])): manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + args[0] elif os.path.exists(args[0]): manifestPath = os.path.abspath(args[0]).split(SCRIPT_DIRECTORY)[1].strip('/') manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath else: print "ERROR: Could not find test manifest '%s'" % manifest return 1 # Start the webserver retVal = reftest.startWebServer(options) if retVal: return retVal procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) print dm.getInfo() #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) return 1 reftest.stopWebServer(options) print ''.join(logcat[-500:-1]) print dm.getInfo() return 0
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) dm_none = devicemanagerADB.DeviceManagerADB() auto = RemoteAutomation(dm_none, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb" or options.robocop): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = dm_none else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if (options.robocop): mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read('robocop.ini') robocop_tests = mp.active_tests(exists=False) fHandle = open("robotium.config", "w") fHandle.write("profile=%s\n" % (mochitest.remoteProfile)) fHandle.write("logfile=%s\n" % (options.remoteLogFile)) fHandle.close() deviceRoot = dm.getDeviceRoot() # Note, we are pushing to /sdcard since we have this location hard coded in robocop dm.pushFile("robotium.config", "/sdcard/robotium.config") dm.pushFile(os.path.abspath(options.robocop + "/fennec_ids.txt"), "/sdcard/fennec_ids.txt") options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) manifest = mochitest.buildProfile(options) mochitest.startWebServer(options) if (options.dm_trans == 'adb'): dm.checkCmd(["install", "-r", os.path.join(options.robocop, "robocop.apk")]) for test in robocop_tests: cmd = ["shell", "am", "instrument", "-w", "-e", "class"] cmd.append("%s.tests.%s" % (options.app, test['name'])) cmd.append("org.mozilla.roboexample.test/android.test.InstrumentationTestRunner") retVal = dm.checkCmd(cmd) else: # SUTAgent needs to install robocop and not crash when we launch robocop. retVal = dm.launchProcess(["am", "instrument", "-w", "org.mozilla.roboexample.test/android.test.InstrumentationTestRunner"]) mochitest.stopWebServer(options) else: try: retVal = mochitest.runTests(options) except: print "TEST-UNEXPECTED-ERROR | | Exception caught while running tests." mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) sys.exit(1) sys.exit(retVal)
def run_test_harness(parser, options): dm_args = { 'deviceRoot': options.remoteTestRoot, 'host': options.deviceIP, 'port': options.devicePort, } dm_args['adbPath'] = options.adb_path if not dm_args['host']: dm_args['deviceSerial'] = options.deviceSerial if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug': dm_args['logLevel'] = logging.DEBUG try: dm = mozdevice.DroidADB(**dm_args) except mozdevice.DMError: traceback.print_exc() print( "Automation Error: exception while initializing devicemanager. " "Most likely the device is not in a testable state.") return 1 automation = RemoteAutomation(None) automation.setDeviceManager(dm) if options.remoteProductName: automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set parser.validate_remote(options, automation) # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: print "%s is not installed on this device" % expected return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) parser.validate(options, reftest) if mozinfo.info['debug']: print "changing timeout for remote debug reftests from %s to 600 seconds" % options.timeout options.timeout = 600 # Hack in a symbolic link for jsreftest 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] 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 try: dm.recordLogcat() retVal = reftest.runTests(options.tests, options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) if options.printDeviceInfo: reftest.printDeviceInfo(printLogcat=True) return retVal
def run_test_harness(options): message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError( "Invalid options specified, use --help for a list of valid options" ) options.runByDir = False dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger productPieces = options.remoteProductName.split('.') if (productPieces is not None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) if options.log_mach is None: mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info("Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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) mochitest.nsprLogName = "nspr.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 if options.log_mach is None: mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
def run_test_harness(parser, options): parser.validate(options) message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError( "Invalid options specified, use --help for a list of valid options" ) options.runByDir = False # roboextender is used by mochitest-chrome tests like test_java_addons.html, # but not by any plain mochitests if options.flavor != 'chrome': options.extensionsToExclude.append('*****@*****.**') dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: log.error("%s is not installed on this device" % expected) return 1 productPieces = options.remoteProductName.split('.') if (productPieces is not None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) if options.log_mach is None: mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info("Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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) mochitest.mozLogName = "moz.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except mozdevice.DMError: # device error cleaning up... oh well! pass retVal = 1 if options.log_mach is None: mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = devicemanagerADB.DeviceManagerADB() else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) fHandle = open("robotium.config", "w") fHandle.write("profile=%s\n" % (mochitest.remoteProfile)) fHandle.write("logfile=%s\n" % (options.remoteLogFile)) fHandle.write("host=http://mochi.test:8888/tests\n") fHandle.write("rawhost=http://%s:%s/tests\n" % (options.remoteWebServer, options.httpPort)) fHandle.close() deviceRoot = dm.getDeviceRoot() # Note, we are pushing to /sdcard since we have this location hard coded in robocop dm.removeFile("/sdcard/fennec_ids.txt") dm.removeFile("/sdcard/robotium.config") dm.pushFile("robotium.config", "/sdcard/robotium.config") fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, "/sdcard/fennec_ids.txt") options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) if (options.dm_trans == 'adb' and options.robocopPath): dm.checkCmd(["install", "-r", os.path.join(options.robocopPath, "robocop.apk")]) appname = options.app retVal = None logcat = [] for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "class"] options.browserArgs.append("%s.tests.%s" % (appname, test['name'])) 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] mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: self.cleanup(None, options) except: pass sys.exit(1) if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 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) mochitest.stopWebSocketServer(options) try: self.cleanup(None, options) except: pass sys.exit(1) print ''.join(logcat[-500:-1]) sys.exit(retVal)
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = devicemanagerADB.DeviceManagerADB() else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) print dm.getInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) fHandle = open("robotium.config", "w") fHandle.write("profile=%s\n" % (mochitest.remoteProfile)) fHandle.write("logfile=%s\n" % (options.remoteLogFile)) fHandle.write("host=http://mochi.test:8888/tests\n") fHandle.write("rawhost=http://%s:%s/tests\n" % (options.remoteWebServer, options.httpPort)) fHandle.close() deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) dm.removeFile(os.path.join(deviceRoot, "robotium.config")) dm.pushFile("robotium.config", os.path.join(deviceRoot, "robotium.config")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) if (options.dm_trans == 'adb' and options.robocopPath): dm.checkCmd(["install", "-r", os.path.join(options.robocopPath, "robocop.apk")]) appname = options.app retVal = None logcat = [] for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("%s.tests.%s" % (appname, test['name'])) options.browserArgs.append("org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % appname) 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] mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: self.cleanup(None, options) except: pass sys.exit(1) if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 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) mochitest.stopWebSocketServer(options) try: self.cleanup(None, options) except: pass sys.exit(1) print ''.join(logcat[-500:-1]) print dm.getInfo() sys.exit(retVal)
def run_test_harness(options): message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError("Invalid options specified, use --help for a list of valid options") options.runByDir = False dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: log.error("%s is not installed on this device" % expected) return 1 productPieces = options.remoteProductName.split('.') if (productPieces is not None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) if options.log_mach is None: mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info( "Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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) mochitest.nsprLogName = "nspr.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 if options.log_mach is None: mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = devicemanagerADB.DeviceManagerADB(deviceRoot=options.remoteTestRoot) else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) print dm.getInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) tests = [] my_tests = tests for test in robocop_tests: tests.append(test['name']) if options.totalChunks: tests_per_chunk = math.ceil(len(tests) / (options.totalChunks * 1.0)) start = int(round((options.thisChunk-1) * tests_per_chunk)) end = int(round(options.thisChunk * tests_per_chunk)) if end > len(tests): end = len(tests) my_tests = tests[start:end] print "Running tests %d-%d/%d" % ((start+1), end, len(tests)) deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('browser.viewport.scaleRatio=100') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') if (options.dm_trans == 'adb' and options.robocopPath): dm._checkCmd(["install", "-r", os.path.join(options.robocopPath, "robocop.apk")]) retVal = None for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if not test['name'] in my_tests: continue options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("%s.tests.%s" % (options.remoteappname, test['name'])) options.browserArgs.append("org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % options.remoteappname) try: dm.removeDir("/mnt/sdcard/Robotium-Screenshots") dm.recordLogcat() result = mochitest.runTests(options) if result != 0: print "ERROR: runTests() exited with code %s" % result log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo() mochitest.printScreenshot() # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 mochitest.printDeviceInfo() sys.exit(retVal)
def main(): message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) parser = RemoteOptions(auto) structured.commandline.add_logging_group(parser) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger if (options == None): log.error("Invalid options specified, use --help for a list of valid options") sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info("Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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 options.robocopIni != "": # turning buffering off as it's not used in robocop message_logger.buffering = False # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocopIni) robocop_tests = mp.active_tests(exists=False, **mozinfo.info) tests = [] my_tests = tests for test in robocop_tests: tests.append(test['name']) if options.totalChunks: tests_per_chunk = math.ceil(len(tests) / (options.totalChunks * 1.0)) start = int(round((options.thisChunk-1) * tests_per_chunk)) end = int(round(options.thisChunk * tests_per_chunk)) if end > len(tests): end = len(tests) my_tests = tests[start:end] log.info("Running tests %d-%d/%d" % (start+1, end, len(tests))) dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath(os.path.join(SCRIPT_DIR, "fennec_ids.txt")) if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('layout.css.devPixelsPerPx=1.0') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') options.extraPrefs.append('browser.snippets.enabled=false') options.extraPrefs.append('browser.casting.enabled=true') if (options.dm_trans == 'adb' and options.robocopApk): dm._checkCmd(["install", "-r", options.robocopApk]) retVal = None # Filtering tests active_tests = [] for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if not test['name'] in my_tests: continue if 'disabled' in test: log.info('TEST-INFO | skipping %s | %s' % (test['name'], test['disabled'])) continue active_tests.append(test) log.suite_start([t['name'] for t in active_tests]) for test in active_tests: # When running in a loop, we need to create a fresh profile for each cycle if mochitest.localProfile: options.profilePath = mochitest.localProfile os.system("rm -Rf %s" % options.profilePath) options.profilePath = None mochitest.localProfile = options.profilePath options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append("org.mozilla.gecko.tests.%s" % test['name']) options.browserArgs.append("org.mozilla.roboexample.test/org.mozilla.gecko.FennecInstrumentationTestRunner") mochitest.nsprLogName = "nspr-%s.log" % test['name'] # If the test is for checking the import from bookmarks then make sure there is data to import if test['name'] == "testImportFromAndroid": # Get the OS so we can run the insert in the apropriate database and following the correct table schema osInfo = dm.getInfo("os") devOS = " ".join(osInfo['os']) if ("pandaboard" in devOS): delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: delete = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(delete)}]) # Insert the bookmarks log.info("Insert bookmarks in the default android browser database") for i in range(20): if ("pandaboard" in devOS): cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db 'insert or replace into bookmarks(_id,title,url,folder,parent,position) values (" + str(30 + i) + ",\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",0,1," + str(100 + i) + ");'"] else: cmd = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db 'insert into bookmarks(title,url,bookmark) values (\"Bookmark"+ str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",1);'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd)}]) try: screenShotDir = "/mnt/sdcard/Robotium-Screenshots" dm.removeDir(screenShotDir) dm.recordLogcat() result = mochitest.runTests(options) if result != 0: log.error("runTests() exited with code %s" % result) log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo(printLogcat=True) mochitest.printScreenshots(screenShotDir) # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break finally: # Clean-up added bookmarks if test['name'] == "testImportFromAndroid": if ("pandaboard" in devOS): cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: cmd_del = ['execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd_del)}]) if retVal is None: log.warning("No tests run. Did you pass an invalid TEST_PATH?") retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: mochitest.nsprLogName = "nspr.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 message_logger.finish() mochitest.printDeviceInfo(printLogcat=True) sys.exit(retVal)
def run_test_harness(options): message_logger = MessageLogger(logger=None) process_args = {'messageLogger': message_logger} auto = RemoteAutomation(None, "fennec", processArgs=process_args) if options is None: raise ValueError("Invalid options specified, use --help for a list of valid options") dm = options.dm auto.setDeviceManager(dm) mochitest = MochiRemote(auto, dm, options) log = mochitest.log message_logger.logger = log mochitest.message_logger = message_logger productPieces = options.remoteProductName.split('.') if (productPieces is not None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) auto.setAppName(options.remoteappname) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) mochitest.printDeviceInfo() # Add Android version (SDK level) to mozinfo so that manifest entries # can be conditional on android_version. androidVersion = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk']) log.info( "Android sdk version '%s'; will use this to filter manifests" % str(androidVersion)) mozinfo.info['android_version'] = androidVersion deviceRoot = dm.deviceRoot if options.dmdPath: dmdLibrary = "libdmd.so" dmdPathOnDevice = os.path.join(deviceRoot, dmdLibrary) 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 options.robocopIni != "": # turning buffering off as it's not used in robocop message_logger.buffering = False # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 if isinstance(options.manifestFile, TestManifest): mp = options.manifestFile else: mp = TestManifest(strict=False) mp.read(options.robocopIni) filters = [] if options.totalChunks: filters.append( chunk_by_slice(options.thisChunk, options.totalChunks)) robocop_tests = mp.active_tests(exists=False, filters=filters, **mozinfo.info) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('layout.css.devPixelsPerPx=1.0') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') options.extraPrefs.append('browser.snippets.enabled=false') options.extraPrefs.append('browser.casting.enabled=true') options.extraPrefs.append('extensions.autoupdate.enabled=false') if (options.dm_trans == 'adb' and options.robocopApk): dm._checkCmd(["install", "-r", options.robocopApk]) if not options.autorun: # Force a single loop iteration. The iteration will start Fennec and # the httpd server, but not actually run a test. options.test_paths = [robocop_tests[0]['name']] retVal = None # Filtering tests active_tests = [] for test in robocop_tests: if options.test_paths and test['name'] not in options.test_paths: continue if 'disabled' in test: log.info( 'TEST-INFO | skipping %s | %s' % (test['name'], test['disabled'])) continue active_tests.append(test) log.suite_start([t['name'] for t in active_tests]) for test in active_tests: # When running in a loop, we need to create a fresh profile for # each cycle if mochitest.localProfile: options.profilePath = mochitest.localProfile os.system("rm -Rf %s" % options.profilePath) options.profilePath = None mochitest.localProfile = options.profilePath options.app = "am" mochitest.nsprLogName = "nspr-%s.log" % test['name'] if options.autorun: # This launches a test (using "am instrument") and instructs # Fennec to /quit/ the browser (using Robocop:Quit) and to # /finish/ all opened activities. options.browserArgs = [ "instrument", "-w", "-e", "quit_and_finish", "1", "-e", "deviceroot", deviceRoot, "-e", "class"] options.browserArgs.append( "org.mozilla.gecko.tests.%s" % test['name'].split('.java')[0]) options.browserArgs.append( "org.mozilla.roboexample.test/org.mozilla.gecko.FennecInstrumentationTestRunner") else: # This does not launch a test at all. It launches an activity # that starts Fennec and then waits indefinitely, since cat # never returns. options.browserArgs = ["start", "-n", "org.mozilla.roboexample.test/org.mozilla.gecko.LaunchFennecWithConfigurationActivity", "&&", "cat"] dm.default_timeout = sys.maxint # Forever. mochitest.log.info("") mochitest.log.info("Serving mochi.test Robocop root at http://%s:%s/tests/robocop/" % (options.remoteWebServer, options.httpPort)) mochitest.log.info("") # If the test is for checking the import from bookmarks then make # sure there is data to import if test['name'] == "testImportFromAndroid": # Get the OS so we can run the insert in the apropriate # database and following the correct table schema osInfo = dm.getInfo("os") devOS = " ".join(osInfo['os']) if ("pandaboard" in devOS): delete = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: delete = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(delete)}]) # Insert the bookmarks log.info( "Insert bookmarks in the default android browser database") for i in range(20): if ("pandaboard" in devOS): cmd = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db 'insert or replace into bookmarks(_id,title,url,folder,parent,position) values (" + str( 30 + i) + ",\"Bookmark" + str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",0,1," + str( 100 + i) + ");'"] else: cmd = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db 'insert into bookmarks(title,url,bookmark) values (\"Bookmark" + str(i) + "\",\"http://www.bookmark" + str(i) + ".com\",1);'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd)}]) try: screenShotDir = "/mnt/sdcard/Robotium-Screenshots" dm.removeDir(screenShotDir) dm.recordLogcat() result = mochitest.runTests(options) if result != 0: log.error("runTests() exited with code %s" % result) log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo(printLogcat=True) mochitest.printScreenshots(screenShotDir) # Ensure earlier failures aren't overwritten by success on this # run if retVal is None or retVal == 0: retVal = result except: log.error( "Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break finally: # Clean-up added bookmarks if test['name'] == "testImportFromAndroid": if ("pandaboard" in devOS): cmd_del = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser2.db \'delete from bookmarks where _id > 14;\'"] else: cmd_del = [ 'execsu', 'sqlite3', "/data/data/com.android.browser/databases/browser.db \'delete from bookmarks where _id > 14;\'"] if (options.dm_trans == "sut"): dm._runCmds([{"cmd": " ".join(cmd_del)}]) if retVal is None: log.warning("No tests run. Did you pass an invalid TEST_PATH?") retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: mochitest.nsprLogName = "nspr.log" try: dm.recordLogcat() retVal = mochitest.runTests(options) except: log.error("Automation Error: Exception caught while running tests") traceback.print_exc() mochitest.stopServers() try: mochitest.cleanup(options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 mochitest.printDeviceInfo(printLogcat=True) message_logger.finish() return retVal
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) auto = RemoteAutomation(None, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB( options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) else: dm = devicemanagerADB.DeviceManagerADB( deviceRoot=options.remoteTestRoot) else: dm = devicemanagerSUT.DeviceManagerSUT( options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent) auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) print dm.getInfo() procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": # sut may wait up to 300 s for a robocop am process before returning dm.default_timeout = 320 mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) tests = [] my_tests = tests for test in robocop_tests: tests.append(test['name']) if options.totalChunks: tests_per_chunk = math.ceil( len(tests) / (options.totalChunks * 1.0)) start = int(round((options.thisChunk - 1) * tests_per_chunk)) end = int(round(options.thisChunk * tests_per_chunk)) if end > len(tests): end = len(tests) my_tests = tests[start:end] print "Running tests %d-%d/%d" % ((start + 1), end, len(tests)) deviceRoot = dm.getDeviceRoot() dm.removeFile(os.path.join(deviceRoot, "fennec_ids.txt")) fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopIds: fennec_ids = options.robocopIds dm.pushFile(fennec_ids, os.path.join(deviceRoot, "fennec_ids.txt")) options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) options.extraPrefs.append('browser.search.suggest.enabled=true') options.extraPrefs.append('browser.search.suggest.prompted=true') options.extraPrefs.append('browser.viewport.scaleRatio=100') options.extraPrefs.append('browser.chrome.dynamictoolbar=false') if (options.dm_trans == 'adb' and options.robocopPath): dm._checkCmd([ "install", "-r", os.path.join(options.robocopPath, "robocop.apk") ]) retVal = None for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue if not test['name'] in my_tests: continue options.app = "am" options.browserArgs = [ "instrument", "-w", "-e", "deviceroot", deviceRoot, "-e", "class" ] options.browserArgs.append("%s.tests.%s" % (options.remoteappname, test['name'])) options.browserArgs.append( "org.mozilla.roboexample.test/%s.FennecInstrumentationTestRunner" % options.remoteappname) try: dm.removeDir("/mnt/sdcard/Robotium-Screenshots") dm.recordLogcat() result = mochitest.runTests(options) if result != 0: print "ERROR: runTests() exited with code %s" % result log_result = mochitest.addLogData() if result != 0 or log_result != 0: mochitest.printDeviceInfo() mochitest.printScreenshot() # Ensure earlier failures aren't overwritten by success on this run if retVal is None or retVal == 0: retVal = result except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 break if retVal is None: print "No tests run. Did you pass an invalid TEST_PATH?" retVal = 1 else: # if we didn't have some kind of error running the tests, make # sure the tests actually passed print "INFO | runtests.py | Test summary: start." overallResult = mochitest.printLog() print "INFO | runtests.py | Test summary: end." if retVal == 0: retVal = overallResult else: try: dm.recordLogcat() retVal = mochitest.runTests(options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: mochitest.cleanup(None, options) except devicemanager.DMError: # device error cleaning up... oh well! pass retVal = 1 mochitest.printDeviceInfo() sys.exit(retVal)
def main(): automation = RemoteAutomation(None) parser = reftestcommandline.RemoteArgumentsParser() options = parser.parse_args() if (options.dm_trans == 'sut' and options.deviceIP == None): print "Error: If --dm_trans = sut, you must provide a device IP to connect to via the --deviceIP option" return 1 try: if (options.dm_trans == "adb"): if (options.deviceIP): dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) elif (options.deviceSerial): dm = droid.DroidADB(None, None, deviceSerial=options.deviceSerial, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(None, None, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) except devicemanager.DMError: print "Automation Error: exception while initializing devicemanager. Most likely the device is not in a testable state." return 1 automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set parser.validate_remote(options, automation) # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: print "%s is not installed on this device" % expected return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) parser.validate(options, reftest) if mozinfo.info['debug']: print "changing timeout for remote debug reftests from %s to 600 seconds" % options.timeout options.timeout = 600 # Hack in a symbolic link for jsreftest 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) reftest.printDeviceInfo() #an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" retVal = 0 try: dm.recordLogcat() retVal = reftest.runTests(options.tests, options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) reftest.printDeviceInfo(printLogcat=True) return retVal
def run_test_harness(parser, options): dm_args = { 'deviceRoot': options.remoteTestRoot, 'host': options.deviceIP, 'port': options.devicePort, } dm_args['adbPath'] = options.adb_path if not dm_args['host']: dm_args['deviceSerial'] = options.deviceSerial if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug': dm_args['logLevel'] = logging.DEBUG try: dm = mozdevice.DroidADB(**dm_args) except mozdevice.DMError: traceback.print_exc() print ("Automation Error: exception while initializing devicemanager. " "Most likely the device is not in a testable state.") return 1 automation = RemoteAutomation(None) automation.setDeviceManager(dm) if options.remoteProductName: automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set parser.validate_remote(options, automation) # Check that Firefox is installed expected = options.app.split('/')[-1] installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected]) if expected not in installed: print "%s is not installed on this device" % expected return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) parser.validate(options, reftest) if mozinfo.info['debug']: print "changing timeout for remote debug reftests from %s to 600 seconds" % options.timeout options.timeout = 600 # Hack in a symbolic link for jsreftest 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] 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 try: dm.recordLogcat() retVal = reftest.runTests(options.tests, options) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) if options.printDeviceInfo: reftest.printDeviceInfo(printLogcat=True) return retVal
def main(args): automation = RemoteAutomation(None) parser = RemoteOptions(automation) options, args = parser.parse_args() if options.dm_trans == "sut" and options.deviceIP == None: print "Error: If --dm_trans = sut, you must provide a device IP to connect to via the --deviceIP option" return 1 try: if options.dm_trans == "adb": if options.deviceIP: dm = droid.DroidADB(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) elif options.deviceSerial: dm = droid.DroidADB(None, None, deviceSerial=options.deviceSerial, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidADB(None, None, deviceRoot=options.remoteTestRoot) else: dm = droid.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot) except devicemanager.DMError: print "Automation Error: exception while initializing devicemanager. Most likely the device is not in a testable state." return 1 automation.setDeviceManager(dm) if options.remoteProductName != None: automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set options = parser.verifyRemoteOptions(options) if options == None: print "ERROR: Invalid options specified, use --help for a list of valid options" return 1 if not options.ignoreWindowSize: parts = dm.getInfo("screen")["screen"][0].split() width = int(parts[0].split(":")[1]) 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) return 1 automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) options = parser.verifyCommonOptions(options, reftest) if mozinfo.info["debug"]: print "changing timeout for remote debug reftests from %s to 600 seconds" % options.timeout options.timeout = 600 # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot manifest = args[0] if os.path.exists(os.path.join(SCRIPT_DIRECTORY, args[0])): manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + args[0] elif os.path.exists(args[0]): manifestPath = os.path.abspath(args[0]).split(SCRIPT_DIRECTORY)[1].strip("/") manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath else: print "ERROR: Could not find test manifest '%s'" % manifest return 1 # Start the webserver retVal = reftest.startWebServer(options) if retVal: return retVal procName = options.app.split("/")[-1] if dm.processExist(procName): dm.killProcess(procName) reftest.printDeviceInfo() # an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" retVal = 0 try: cmdlineArgs = ["-reftest", manifest] if options.bootstrap: cmdlineArgs = [] dm.recordLogcat() retVal = reftest.runTests(manifest, options, cmdlineArgs) except: print "Automation Error: Exception caught while running tests" traceback.print_exc() retVal = 1 reftest.stopWebServer(options) reftest.printDeviceInfo(printLogcat=True) return retVal
def main(): scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__))) dm_none = devicemanagerADB.DeviceManagerADB() auto = RemoteAutomation(dm_none, "fennec") parser = RemoteOptions(auto, scriptdir) options, args = parser.parse_args() if (options.dm_trans == "adb"): if (options.deviceIP): dm = devicemanagerADB.DeviceManagerADB(options.deviceIP, options.devicePort) else: dm = dm_none else: dm = devicemanagerSUT.DeviceManagerSUT(options.deviceIP, options.devicePort) auto.setDeviceManager(dm) options = parser.verifyRemoteOptions(options, auto) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) productPieces = options.remoteProductName.split('.') if (productPieces != None): auto.setProduct(productPieces[0]) else: auto.setProduct(options.remoteProductName) mochitest = MochiRemote(auto, dm, options) options = parser.verifyOptions(options, mochitest) if (options == None): sys.exit(1) logParent = os.path.dirname(options.remoteLogFile) dm.mkDir(logParent); auto.setRemoteLog(options.remoteLogFile) auto.setServerInfo(options.webServer, options.httpPort, options.sslPort) procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) if options.robocop != "": mp = manifestparser.TestManifest(strict=False) # TODO: pull this in dynamically mp.read(options.robocop) robocop_tests = mp.active_tests(exists=False) fHandle = open("robotium.config", "w") fHandle.write("profile=%s\n" % (mochitest.remoteProfile)) fHandle.write("logfile=%s\n" % (options.remoteLogFile)) fHandle.close() deviceRoot = dm.getDeviceRoot() # Note, we are pushing to /sdcard since we have this location hard coded in robocop dm.removeFile("/sdcard/fennec_ids.txt") dm.removeFile("/sdcard/robotium.config") dm.pushFile("robotium.config", "/sdcard/robotium.config") fennec_ids = os.path.abspath("fennec_ids.txt") if not os.path.exists(fennec_ids) and options.robocopPath: fennec_ids = os.path.abspath(os.path.join(options.robocopPath, "fennec_ids.txt")) dm.pushFile(fennec_ids, "/sdcard/fennec_ids.txt") options.extraPrefs.append('robocop.logfile="%s/robocop.log"' % deviceRoot) if (options.dm_trans == 'adb' and options.robocopPath): dm.checkCmd(["install", "-r", os.path.join(options.robocopPath, "robocop.apk")]) appname = options.app for test in robocop_tests: if options.testPath and options.testPath != test['name']: continue options.app = "am" options.browserArgs = ["instrument", "-w", "-e", "class"] options.browserArgs.append("%s.tests.%s" % (appname, test['name'])) options.browserArgs.append("org.mozilla.roboexample.test/android.test.InstrumentationTestRunner") try: retVal = mochitest.runTests(options) except: print "TEST-UNEXPECTED-ERROR | %s | Exception caught while running robocop tests." % sys.exc_info()[1] mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: self.cleanup(None, options) except: pass sys.exit(1) else: try: retVal = mochitest.runTests(options) except: print "TEST-UNEXPECTED-ERROR | %s | Exception caught while running tests." % sys.exc_info()[1] mochitest.stopWebServer(options) mochitest.stopWebSocketServer(options) try: self.cleanup(None, options) except: pass sys.exit(1) sys.exit(retVal)