def main():

    if sys.version_info < (2, 7):
        print >> sys.stderr, "Error: You must use python version 2.7 or newer but less than 3.0"
        sys.exit(1)

    parser = RemoteXPCShellOptions()
    options, args = parser.parse_args()
    if not options.localAPK:
        for file in os.listdir(os.path.join(options.objdir, "dist")):
            if (file.endswith(".apk") and file.startswith("fennec")):
                options.localAPK = os.path.join(options.objdir, "dist")
                options.localAPK = os.path.join(options.localAPK, file)
                print >> sys.stderr, "using APK: " + options.localAPK
                break
        else:
            print >> sys.stderr, "Error: please specify an APK"
            sys.exit(1)

    options = parser.verifyRemoteOptions(options)

    if len(args) < 1 and options.manifest is None:
        print >> sys.stderr, """Usage: %s <test dirs>
             or: %s --manifest=test.manifest """ % (sys.argv[0], sys.argv[0])
        sys.exit(1)

    if (options.dm_trans == "adb"):
        if (options.deviceIP):
            dm = devicemanagerADB.DeviceManagerADB(
                options.deviceIP,
                options.devicePort,
                packageName=None,
                deviceRoot=options.remoteTestRoot)
        else:
            dm = devicemanagerADB.DeviceManagerADB(
                packageName=None, deviceRoot=options.remoteTestRoot)
    else:
        dm = devicemanagerSUT.DeviceManagerSUT(
            options.deviceIP,
            options.devicePort,
            deviceRoot=options.remoteTestRoot)
        if (options.deviceIP == None):
            print "Error: you must provide a device IP to connect to via the --device option"
            sys.exit(1)

    if options.interactive and not options.testPath:
        print >> sys.stderr, "Error: You must specify a test filename in interactive mode!"
        sys.exit(1)

    xpcsh = XPCShellRemote(dm, options, args)

    # we don't run concurrent tests on mobile
    options.sequential = True

    if not xpcsh.runTests(xpcshell='xpcshell',
                          testClass=RemoteXPCShellTestThread,
                          testdirs=args[0:],
                          mobileArgs=xpcsh.mobileArgs,
                          **options.__dict__):
        sys.exit(1)
Beispiel #2
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"):
        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)
Beispiel #3
0
def main():

    dm_none = devicemanagerADB.DeviceManagerADB(None, None)
    parser = RemoteXPCShellOptions()
    options, args = parser.parse_args()

    if len(args) < 1 and options.manifest is None:
        print >> sys.stderr, """Usage: %s <test dirs>
           or: %s --manifest=test.manifest """ % (sys.argv[0], sys.argv[0])
        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)
        if (options.deviceIP == None):
            print "Error: you must provide a device IP to connect to via the --device option"
            sys.exit(1)

    if options.interactive and not options.testPath:
        print >> sys.stderr, "Error: You must specify a test filename in interactive mode!"
        sys.exit(1)

    if not options.objdir:
        print >> sys.stderr, "Error: You must specify an objdir"
        sys.exit(1)

    if not options.localAPK:
        for file in os.listdir(os.path.join(options.objdir, "dist")):
            if (file.endswith(".apk") and file.startswith("fennec")):
                options.localAPK = os.path.join(options.objdir, "dist")
                options.localAPK = os.path.join(options.localAPK, file)
                print >> sys.stderr, "using APK: " + options.localAPK
                break

    if not options.localAPK:
        print >> sys.stderr, "Error: please specify an APK"
        sys.exit(1)

    xpcsh = XPCShellRemote(dm, options, args)

    if not xpcsh.runTests(
            xpcshell='xpcshell', testdirs=args[0:], **options.__dict__):
        sys.exit(1)
    def run(self):
        # Assume the script has been pushed to the phone, set up the path for adb
        phonescript = self.testroot + "/" + os.path.split(self.script)[1]

        # Instantiate our devicemanger for the kill functionality
        # Note that our appname is everything left of the starting intent
        appname = browsermap[self.browser].split("/")[0]
        dm = devicemanagerADB.DeviceManagerADB(packageName=appname)

        #profile directory for fennec
        profiledir = "/data/data/org.mozilla.fennec/files/mozilla"
        profilename = ""

        self.log("Running %s for %s iterations" %
                 (self.browser, self.iterations))
        for i in range(self.iterations):
            # Set up our browser command so it's ready when we need it
            browsercmd = [
                "sh", phonescript, browsermap[self.browser], self.url
            ]
            # First, we flash our "setup" screen as a marker for the video
            # and we hold it for flashlen seconds
            self.log(
                self._run_adb(device, "shell", [
                    "am", "start", "-a", "android.intent.action.MAIN", "-n",
                    "com.android.settings/.Settings"
                ]))
            sleep(float(self.flashlen))

            # Run the browser
            self.log(self._run_adb(device, "shell", browsercmd))

            # Reading Delay - let the numbers be displayed long enough on video
            # to be read.
            sleep(float(self.readlen))

            # Kill the browser - we use the devicemanagerADB for this because it's
            # easier than re-writing all that code

            # self.log(dm.getProcessList())
            if not dm.killProcess(appname):
                self.log("ERROR: Could not kill process ending program now")
                sys.exit(1)
            self.log("Killed:" + appname)

            # We will now return to the settings screen (remember our flash
            # from earlier?)  So go back to the home screen - the key code
            # for the home button is 3
            self.log(self._run_adb(device, "shell",
                                   ["input", "keyevent", "3"]))

            # Pause for pause length now, to let GC's finish
            # TODO: can we cause a system GC ourselves?
            sleep(float(self.pauselen))

        # If we installed a fennec, uninstall it
        if self.installedFennec:
            self.log(self._run_adb(device, "uninstall",
                                   [self.installedFennec]))
def main():
    scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
    auto = B2GRemoteAutomation(None, "fennec")
    parser = B2GOptions(auto, scriptdir)
    options, args = parser.parse_args()

    # create our Marionette instance
    kwargs = {'emulator': options.emulator}
    if options.b2gPath:
        kwargs['homedir'] = options.b2gPath
    if options.marionette:
        host,port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
    marionette = Marionette(**kwargs)

    auto.marionette = marionette

    # create the DeviceManager
    kwargs = {'adbPath': options.adbPath}
    if options.deviceIP:
        kwargs.update({'host': options.deviceIP,
                       'port': options.devicePort})
    dm = devicemanagerADB.DeviceManagerADB(**kwargs)

    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)

    auto.setProduct("b2g")

    mochitest = B2GMochitest(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)

    retVal = 1
    try:
        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:
            pass
            sys.exit(1)

    sys.exit(retVal)
Beispiel #6
0
def main():
    parser = B2GOptions()
    options, args = parser.parse_args()

    if options.objdir is None:
        try:
            options.objdir = os.path.join(options.b2g_path, 'objdir-gecko')
        except:
            print >> sys.stderr, "Need to specify a --b2gpath"
            sys.exit(1)

    # Create the Marionette instance
    kwargs = {}
    if options.emulator:
        kwargs['emulator'] = options.emulator
        if options.no_window:
            kwargs['noWindow'] = True
    if options.b2g_path:
        kwargs['homedir'] = options.emu_path or options.b2g_path
    if options.address:
        host, port = options.address.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
        kwargs['baseurl'] = 'http://%s:%d/' % (host, int(port))
        if options.emulator:
            kwargs['connectToRunningEmulator'] = True
    marionette = Marionette(**kwargs)

    # Create the DeviceManager instance
    kwargs = {'adbPath': options.adb_path}
    if options.deviceIP:
        kwargs['host'] = options.deviceIP
        kwargs['port'] = options.devicePort
    kwargs['deviceRoot'] = DEVICE_TEST_ROOT
    dm = devicemanagerADB.DeviceManagerADB(**kwargs)

    options.remoteTestRoot = dm.getDeviceRoot()

    xpcsh = B2GXPCShellRemote(dm, options, args)

    try:
        success = xpcsh.runTests(xpcshell='xpcshell',
                                 testdirs=args[0:],
                                 **options.__dict__)
    except:
        print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info(
        )[1]
        traceback.print_exc()
        sys.exit(1)

    sys.exit(int(success))
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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
Beispiel #10
0
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)
Beispiel #11
0
def main(args=sys.argv[1:]):
    auto = B2GRemoteAutomation(None, "fennec", context_chrome=True)
    parser = B2GOptions(auto)
    options, args = parser.parse_args(args)

    # create our Marionette instance
    kwargs = {}
    if options.emulator:
        kwargs['emulator'] = options.emulator
        auto.setEmulator(True)
        if options.noWindow:
            kwargs['noWindow'] = True
    if options.emulator_res:
        kwargs['emulator_res'] = options.emulator_res
    if options.b2gPath:
        kwargs['homedir'] = options.b2gPath
    if options.marionette:
        host, port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
    if options.geckoPath:
        kwargs['gecko_path'] = options.geckoPath
    marionette = Marionette(**kwargs)
    auto.marionette = marionette

    # create the DeviceManager
    kwargs = {'adbPath': options.adbPath}
    if options.deviceIP:
        kwargs.update({'host': options.deviceIP, 'port': options.devicePort})
    dm = devicemanagerADB.DeviceManagerADB(**kwargs)
    auto.setDeviceManager(dm)

    options = parser.verifyRemoteOptions(options)
    if (options == None):
        print "ERROR: Invalid options specified, use --help for a list of valid options"
        sys.exit(1)

    # TODO fix exception
    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 < 1366 or height < 1050):
            print "ERROR: Invalid screen resolution %sx%s, please adjust to 1366x1050 or higher" % (
                width, height)
            return 1

    auto.setProduct("b2g")
    auto.test_script = os.path.join(SCRIPT_DIRECTORY, 'b2g_start_script.js')
    auto.test_script_args = [options.remoteWebServer, options.httpPort]
    auto.logFinish = "REFTEST TEST-START | Shutdown"

    reftest = B2GReftest(auto, dm, options, SCRIPT_DIRECTORY)
    # Create /data/local/tests, to force its use by DeviceManagerADB;
    # B2G won't run correctly with the profile installed to /mnt/sdcard.
    dm.mkDirs(reftest.testDir)

    logParent = os.path.dirname(options.remoteLogFile)
    dm.mkDir(logParent)
    auto.setRemoteLog(options.remoteLogFile)
    auto.setServerInfo(options.webServer, options.httpPort, options.sslPort)

    # 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://%s:%s/%s" % (options.remoteWebServer,
                                        options.httpPort, args[0])
    elif os.path.exists(args[0]):
        manifestPath = os.path.abspath(
            args[0]).split(SCRIPT_DIRECTORY)[1].strip('/')
        manifest = "http://%s:%s/%s" % (options.remoteWebServer,
                                        options.httpPort, manifestPath)
    else:
        print "ERROR: Could not find test manifest '%s'" % manifest
        return 1

    # Start the webserver
    retVal = 1
    try:
        retVal = reftest.startWebServer(options)
        if retVal:
            return retVal
        procName = options.app.split('/')[-1]
        if (dm.processExist(procName)):
            dm.killProcess(procName)

        cmdlineArgs = ["-reftest", manifest]
        if getattr(options, 'bootstrap', False):
            cmdlineArgs = []

        retVal = reftest.runTests(manifest, options, cmdlineArgs)
    except:
        print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info(
        )[1]
        traceback.print_exc()
        reftest.stopWebServer(options)
        try:
            reftest.cleanup(None)
        except:
            pass
        return 1

    reftest.stopWebServer(options)
    return retVal
Beispiel #12
0
def run_remote_mochitests(automation, parser, options):
    # create our Marionette instance
    kwargs = {}
    if options.emulator:
        kwargs['emulator'] = options.emulator
        automation.setEmulator(True)
        if options.noWindow:
            kwargs['noWindow'] = True
        if options.geckoPath:
            kwargs['gecko_path'] = options.geckoPath
        if options.logcat_dir:
            kwargs['logcat_dir'] = options.logcat_dir
        if options.busybox:
            kwargs['busybox'] = options.busybox
    # needless to say sdcard is only valid if using an emulator
    if options.sdcard:
        kwargs['sdcard'] = options.sdcard
    if options.b2gPath:
        kwargs['homedir'] = options.b2gPath
    if options.marionette:
        host, port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)

    marionette = Marionette.getMarionetteOrExit(**kwargs)

    automation.marionette = marionette

    # create the DeviceManager
    kwargs = {'adbPath': options.adbPath, 'deviceRoot': options.remoteTestRoot}
    if options.deviceIP:
        kwargs.update({'host': options.deviceIP, 'port': options.devicePort})
    dm = devicemanagerADB.DeviceManagerADB(**kwargs)
    automation.setDeviceManager(dm)
    options = parser.verifyRemoteOptions(options, automation)
    if (options == None):
        print "ERROR: Invalid options specified, use --help for a list of valid options"
        sys.exit(1)

    automation.setProduct("b2g")

    mochitest = B2GMochitest(automation, dm, options)

    options = parser.verifyOptions(options, mochitest)
    if (options == None):
        sys.exit(1)

    logParent = os.path.dirname(options.remoteLogFile)
    dm.mkDir(logParent)
    automation.setRemoteLog(options.remoteLogFile)
    automation.setServerInfo(options.webServer, options.httpPort,
                             options.sslPort)
    retVal = 1
    try:
        mochitest.cleanup(None, options)
        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:
            pass
        retVal = 1

    sys.exit(retVal)
Beispiel #13
0
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)
Beispiel #14
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"):
        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)