Ejemplo n.º 1
0
def smoketest(device_name, number):
    global dm
    global appFileName, processName

    dm = devicemanager.DeviceManagerSUT(device_name, 20701)
    deviceRoot = dm.getDeviceRoot()

    # This does all the steps of verify.py including the cleanup.
    if verifyDevice(device_name, checksut=False,
                    doCheckStalled=False) is False:
        log.error("failed to run verify on %s" % (device_name))
        return 1  # Not ok to proceed
    log.info("Successfully verified the device")

    if dm._sock:
        dm._sock.close()
    time.sleep(30)
    dm = devicemanager.DeviceManagerSUT(device_name, 20701)
    print "in smoketest, going to call installOneApp with dm: %s, %s" \
          % (dm, dm._sock)
    if installOneApp(dm,
                     deviceRoot,
                     os.path.abspath(appFileName),
                     None,
                     logcat=False):
        log.error("failed to install %s on device %s" %
                  (appFileName, device_name))
        return 1
    log.info("Successfully installed the application")

    if not runTests(device_name, processName, number):
        log.error("failed to run dom tests on %s" % (device_name))
        return 1
    log.info("Successfully ran the mochitests")
    return 0
Ejemplo n.º 2
0
def connect(deviceIP, sleep=False):
    if sleep:
        log.info("We're going to sleep for 90 seconds")
        time.sleep(90)

    log.info("Connecting to: " + deviceIP)
    return devicemanager.DeviceManagerSUT(deviceIP)
Ejemplo n.º 3
0
def run_tests_remote(tests, prefix, options):
    # Setup device with everything needed to run our tests.
    from mozdevice import devicemanager, devicemanagerADB, devicemanagerSUT

    if options.device_transport == 'adb':
        if options.device_ip:
            dm = devicemanagerADB.DeviceManagerADB(options.device_ip, options.device_port, deviceSerial=options.device_serial, packageName=None, deviceRoot=options.remote_test_root)
        else:
            dm = devicemanagerADB.DeviceManagerADB(deviceSerial=options.device_serial, packageName=None, deviceRoot=options.remote_test_root)
    else:
        dm = devicemanagerSUT.DeviceManagerSUT(options.device_ip, options.device_port, deviceRoot=options.remote_test_root)
        if options.device_ip == None:
            print('Error: you must provide a device IP to connect to via the --device option')
            sys.exit(1)

    # Update the test root to point to our test directory.
    options.remote_test_root = posixpath.join(options.remote_test_root, 'jit-tests')

    # Push js shell and libraries.
    if dm.dirExists(options.remote_test_root):
        dm.removeDir(options.remote_test_root)
    dm.mkDir(options.remote_test_root)
    push_libs(options, dm)
    push_progs(options, dm, [prefix[0]])
    dm.chmodDir(options.remote_test_root)
    dm.pushDir(os.path.dirname(TEST_DIR), options.remote_test_root, timeout=600)
    prefix[0] = os.path.join(options.remote_test_root, 'js')

    # Run all tests.
    gen = get_remote_results(tests, dm, prefix, options)
    ok = process_test_results(gen, len(tests), options)
    return ok
Ejemplo n.º 4
0
def testAgent(host, port):
  if port == -1:
    from mozdevice import devicemanagerADB
    return devicemanagerADB.DeviceManagerADB(host, port)
  else:
    from mozdevice import devicemanagerSUT
    return devicemanagerSUT.DeviceManagerSUT(host, port)
Ejemplo n.º 5
0
def main(argv):
    global ip_addr

    if (len(argv) < 4):
        log.info(
            "usage: logcat.py <device ip address> <output filename> <logcat options>"
        )
        return 1
    ip_addr = argv[1]
    output_filename = argv[2]
    logcat_options = argv[3]
    max_runtime = 3600  # 3600 seconds == 1 hour

    status = 0
    dm = devicemanager.DeviceManagerSUT(ip_addr)
    if not dm:
        log.error("logcat.py: unable to open device manager")
        return 2
    command = 'execext su t=%d logcat %s' % (max_runtime, logcat_options)
    log.debug('logcat.py running SUT command: %s' % command)
    try:
        with open(output_filename, 'w') as f:
            dm._sendCmds([{'cmd': command}], f)
    except devicemanager.DMError, e:
        log.error("Remote Device Error: Exception caught running logcat: %s" %
                  str(e))
        status = -1
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def main():
    parser = RemoteCPPUnittestOptions()
    mozlog.commandline.add_logging_group(parser)
    options, args = parser.parse_args()
    if not args:
        print >>sys.stderr, """Usage: %s <test binary> [<test binary>...]""" % sys.argv[0]
        sys.exit(1)
    if options.local_lib is not None and not os.path.isdir(options.local_lib):
        print >>sys.stderr, """Error: --localLib directory %s not found""" % options.local_lib
        sys.exit(1)
    if options.local_apk is not None and not os.path.isfile(options.local_apk):
        print >>sys.stderr, """Error: --apk file %s not found""" % options.local_apk
        sys.exit(1)
    if not options.xre_path:
        print >>sys.stderr, """Error: --xre-path is required"""
        sys.exit(1)
    if options.with_b2g_emulator:
        from mozrunner import B2GEmulatorRunner
        runner = B2GEmulatorRunner(b2g_home=options.with_b2g_emulator)
        runner.start()
    if options.dm_trans == "adb":
        if options.with_b2g_emulator:
            # because we just started the emulator, we need more than the
            # default number of retries here.
            retryLimit = 50
        else:
            retryLimit = 5
        try:
            if options.device_ip:
                dm = devicemanagerADB.DeviceManagerADB(options.device_ip, options.device_port, packageName=None, deviceRoot=options.remote_test_root, retryLimit=retryLimit)
            else:
                dm = devicemanagerADB.DeviceManagerADB(packageName=None, deviceRoot=options.remote_test_root, retryLimit=retryLimit)
        except:
            if options.with_b2g_emulator:
                runner.cleanup()
                runner.wait()
            raise
    else:
        dm = devicemanagerSUT.DeviceManagerSUT(options.device_ip, options.device_port, deviceRoot=options.remote_test_root)
        if not options.device_ip:
            print "Error: you must provide a device IP to connect to via the --deviceIP option"
            sys.exit(1)

    log = mozlog.commandline.setup_logging("remotecppunittests", options,
                                           {"tbpl": sys.stdout})

    options.xre_path = os.path.abspath(options.xre_path)
    cppunittests.update_mozinfo()
    progs = cppunittests.extract_unittests_from_args(args,
                                                     mozinfo.info,
                                                     options.manifest_path)
    tester = RemoteCPPUnitTests(dm, options, [item[0] for item in progs])
    try:
        result = tester.run_tests(progs, options.xre_path, options.symbols_path)
    except Exception, e:
        log.error(str(e))
        result = False
Ejemplo n.º 8
0
def run_test_harness(options, args):
    if options.with_b2g_emulator:
        from mozrunner import B2GEmulatorRunner
        runner = B2GEmulatorRunner(arch=options.emulator,
                                   b2g_home=options.with_b2g_emulator)
        runner.start()
    if options.dm_trans == "adb":
        if options.with_b2g_emulator:
            # because we just started the emulator, we need more than the
            # default number of retries here.
            retryLimit = 50
        else:
            retryLimit = 5
        try:
            if options.device_ip:
                dm = devicemanagerADB.DeviceManagerADB(
                    options.device_ip,
                    options.device_port,
                    packageName=None,
                    deviceRoot=options.remote_test_root,
                    retryLimit=retryLimit)
            else:
                dm = devicemanagerADB.DeviceManagerADB(
                    packageName=None,
                    deviceRoot=options.remote_test_root,
                    retryLimit=retryLimit)
        except:
            if options.with_b2g_emulator:
                runner.cleanup()
                runner.wait()
            raise
    else:
        dm = devicemanagerSUT.DeviceManagerSUT(
            options.device_ip,
            options.device_port,
            deviceRoot=options.remote_test_root)
        if not options.device_ip:
            print "Error: you must provide a device IP to connect to via the --deviceIP option"
            sys.exit(1)

    options.xre_path = os.path.abspath(options.xre_path)
    cppunittests.update_mozinfo()
    progs = cppunittests.extract_unittests_from_args(args, mozinfo.info,
                                                     options.manifest_path)
    tester = RemoteCPPUnitTests(dm, options, [item[0] for item in progs])
    try:
        result = tester.run_tests(progs, options.xre_path,
                                  options.symbols_path)
    finally:
        if options.with_b2g_emulator:
            runner.cleanup()
            runner.wait()
    return result
Ejemplo n.º 9
0
def cleanup():
    # Kill remote logcat process. Most process operations in devicemanager
    # work on applications, like org.mozilla.fennec, but not on native
    # processes like logcat. We work around that by directly executing
    # ps and kill.
    dm = devicemanager.DeviceManagerSUT(ip_addr)
    pid = findpid(dm, "logcat")
    if pid and pid > 0:
        log.debug('logcat.py killing logcat with pid %d' % pid)
        try:
            dm.shellCheckOutput(['kill', str(pid)], root=True)
        except devicemanager.DMError, e:
            log.error("Error killing logcat (pid %s): %s" % (str(pid), str(e)))
Ejemplo n.º 10
0
 def get_devicemanager(self, devicemanager, ip, port, remote_test_root):
     from mozdevice import devicemanagerADB, devicemanagerSUT
     dm = None
     if devicemanager == "adb":
         if ip:
             dm = devicemanagerADB.DeviceManagerADB(ip, port, packageName=None, deviceRoot=remote_test_root)
         else:
             dm = devicemanagerADB.DeviceManagerADB(packageName=None, deviceRoot=remote_test_root)
     else:
         if ip:
             dm = devicemanagerSUT.DeviceManagerSUT(ip, port, deviceRoot=remote_test_root)
         else:
             raise Exception("You must provide a device IP to connect to via the --ip option")
     return dm
Ejemplo n.º 11
0
def main():

    parser = RemoteXPCShellOptions()
    options, args = parser.parse_args()
    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)
      else:
        dm = devicemanagerADB.DeviceManagerADB()
    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)
Ejemplo n.º 12
0
def main():
    parser = RemoteCPPUnittestOptions()
    options, args = parser.parse_args()
    if not args:
        print >> sys.stderr, """Usage: %s <test binary> [<test binary>...]""" % sys.argv[
            0]
        sys.exit(1)
    if options.local_lib is None and options.local_apk is None:
        print >> sys.stderr, """Error: --localLib or --apk is required"""
        sys.exit(1)
    if options.local_lib is not None and not os.path.isdir(options.local_lib):
        print >> sys.stderr, """Error: --localLib directory %s not found""" % options.local_lib
        sys.exit(1)
    if options.local_apk is not None and not os.path.isfile(options.local_apk):
        print >> sys.stderr, """Error: --apk file %s not found""" % options.local_apk
        sys.exit(1)
    if not options.xre_path:
        print >> sys.stderr, """Error: --xre-path is required"""
        sys.exit(1)
    if options.dm_trans == "adb":
        if options.device_ip:
            dm = devicemanagerADB.DeviceManagerADB(
                options.device_ip,
                options.device_port,
                packageName=None,
                deviceRoot=options.remote_test_root)
        else:
            dm = devicemanagerADB.DeviceManagerADB(
                packageName=None, deviceRoot=options.remote_test_root)
    else:
        dm = devicemanagerSUT.DeviceManagerSUT(
            options.device_ip,
            options.device_port,
            deviceRoot=options.remote_test_root)
        if not options.device_ip:
            print "Error: you must provide a device IP to connect to via the --deviceIP option"
            sys.exit(1)
    options.xre_path = os.path.abspath(options.xre_path)
    progs = cppunittests.extract_unittests_from_args(args,
                                                     options.manifest_file)
    tester = RemoteCPPUnitTests(dm, options, progs)
    try:
        result = tester.run_tests(progs, options.xre_path,
                                  options.symbols_path)
    except Exception, e:
        log.error(str(e))
        result = False
Ejemplo n.º 13
0
def cleanupDevice(device=None, dm=None):
    assert ((device is not None) or (dm is not None))  # Require one to be set

    if not device:
        device = os.environ['SUT_NAME']
    pidDir = os.path.join('/builds/', device)
    errorFile = os.path.join(pidDir, 'error.flg')
    reboot_needed = False

    processNames = [
        'org.mozilla.fennec_aurora',
        'org.mozilla.fennec_unofficial',
        'org.mozilla.fennec',
        'org.mozilla.firefox_beta',
        'org.mozilla.firefox',
        'org.mozilla.roboexample.test',
    ]

    if dm is None:
        log.info("Connecting to: " + device)
        dm = devicemanager.DeviceManagerSUT(device)
        dm.debug = 5

    packages = dm._runCmds([{'cmd': 'exec pm list packages'}])
    for package in packages.split('\n'):
        if not package.strip().startswith("package:"):
            continue  # unknown entry
        package_basename = package.strip()[8:]
        for proc in processNames:
            if package_basename == "%s" % proc or \
                    package_basename.startswith("%s_" % proc):
                log.info("Uninstalling %s..." % package_basename)
                try:
                    if 'panda' in device:
                        dm.uninstallApp(package_basename)
                        reboot_needed = True
                    else:
                        dm.uninstallAppAndReboot(package_basename)
                        waitForDevice(dm)
                except devicemanager.DMError, err:
                    setFlag(
                        errorFile,
                        "Remote Device Error: Unable to uninstall %s and reboot: %s"
                        % (package_basename, err))
                    return RETCODE_ERROR
                finally:
                    break  # Don't try this proc again, since we already matched
Ejemplo n.º 14
0
    if (len(sys.argv) != 3):
        print "usage: config.py <ip address> <testname>"
        sys.exit(1)

    cwd = os.getcwd()
    testname = sys.argv[2]
    errorFile = os.path.join(cwd, '..', 'error.flg')
    proxyIP = getOurIP()
    proxyPort = calculatePort()
    refWidth = 1600  # x
    refHeight = 1200  # y
    deviceName = os.path.basename(cwd)
    deviceIP = sys.argv[1]

    print "connecting to: %s" % deviceIP
    dm = devicemanager.DeviceManagerSUT(deviceIP)
    # Moar data!
    dm.debug = 3
    devRoot = dm.getDeviceRoot()

    # checking for /mnt/sdcard/...
    print "devroot %s" % devRoot
    if devRoot is None or devRoot == '/tests':
        setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct - exiting" % devRoot)
        sys.exit(1)

    width, height = getResolution(dm)
    print("current resolution X:%d Y:%d" % (width, height))

    # adjust resolution up if we are part of a reftest run
    if (testname == 'reftest') and width < refWidth:
Ejemplo n.º 15
0
    ]
    browser_config['dirs'] = dict([(i, utils.interpolatePath(j))
                                   for i, j in browser_config['dirs'].items()])
    browser_config['bcontroller_config'] = utils.interpolatePath(
        browser_config['bcontroller_config'])

    # get device manager if specified
    dm = None
    if browser_config['remote'] == True:
        if browser_config['port'] == -1:
            from mozdevice import devicemanagerADB
            dm = devicemanagerADB.DeviceManagerADB(browser_config['host'],
                                                   browser_config['port'])
        else:
            from mozdevice import devicemanagerSUT
            dm = devicemanagerSUT.DeviceManagerSUT(browser_config['host'],
                                                   browser_config['port'])

    # normalize browser path to work across platforms
    browser_config['browser_path'] = os.path.normpath(
        browser_config['browser_path'])

    # get test date in seconds since epoch
    if testdate:
        date = int(
            time.mktime(time.strptime(testdate, '%a, %d %b %Y %H:%M:%S GMT')))
    else:
        date = int(time.time())
    utils.debug("using testdate: %d", date)
    utils.debug("actual date: %d", int(time.time()))

    # pull buildid & sourcestamp from browser
Ejemplo n.º 16
0
 def setUp(self):
     self.dm = devicemanagerSUT.DeviceManagerSUT(host=ip, port=port)
     self.dm.debug = 3
     self.dmerror = devicemanager.DMError
     self.nettools = devicemanager.NetworkTools
     self._setUp()
Ejemplo n.º 17
0
 def setUp(self):
     self.dm = devicemanagerSUT.DeviceManagerSUT(host=ip,
                                                 port=port,
                                                 logLevel=log_level)
     self.dmerror = devicemanager.DMError
     self._setUp()
Ejemplo n.º 18
0
def one_time_setup(ip_addr, major_source):
    ''' One time setup of state

    ip_addr - of the device we want to install app at
    major_source - we've hacked this script to install
            may-also-be-needed tools, but the source we're asked to
            install has the meta data we need

    Side Effects:
        global, needed for error reporting:
            errorFile
    '''

    # set up the flag files, used throughout
    cwd = os.getcwd()
    global errorFile
    errorFile = os.path.join(cwd, '..', 'error.flg')
    deviceName = os.path.basename(cwd)

    proxyIP = getOurIP()
    proxyPort = calculatePort()

    workdir = os.path.dirname(major_source)
    inifile = os.path.join(workdir, 'fennec', 'application.ini')
    remoteappini = os.path.join(workdir, 'talos', 'remoteapp.ini')
    log.info('copying %s to %s' % (inifile, remoteappini))
    runCommand(['cp', inifile, remoteappini])

    log.info("connecting to: %s" % ip_addr)
    dm = devicemanager.DeviceManagerSUT(ip_addr)
    # Moar data!
    dm.debug = 3

    devRoot = checkDeviceRoot(dm)

    if devRoot is None or devRoot == '/tests':
        setFlag(
            errorFile,
            "Remote Device Error: devRoot from devicemanager [%s] is not correct - exiting"
            % devRoot)
        return None, None

    try:
        log.info("%s, %s" % (proxyIP, proxyPort))
        getDeviceTimestamp(dm)
        setDeviceTimestamp(dm)
        getDeviceTimestamp(dm)
        dm.getInfo('process')
        dm.getInfo('memory')
        dm.getInfo('uptime')

        width, height = getResolution(dm)
        # adjust resolution down to allow fennec to install without memory
        # issues
        if (width == 1600 or height == 1200):
            dm.adjustResolution(1024, 768, 'crt')
            log.info('forcing device reboot')
            if not powermanagement.soft_reboot_and_verify(
                    device=deviceName, dm=dm, ipAddr=proxyIP, port=proxyPort):
                return None, None

            width, height = getResolution(dm)
            if width != 1024 and height != 768:
                setFlag(
                    errorFile,
                    "Remote Device Error: Resolution change failed.  Should be %d/%d but is %d/%d"
                    % (1024, 768, width, height))
                return None, None

    except devicemanager.AgentError, err:
        log.error(
            "remoteDeviceError: while doing one time setup for installation: %s"
            % err)
        return None, None