author ffxbld
Tue, 09 Feb 2016 07:50:02 -0800
changeset 6468 db52385327f7
parent 5004 219341eca255
permissions -rwxr-xr-x
Added tag FIREFOX_45_0b4_RELEASE_RUNTIME, FIREFOX_45_0b4_BUILD1_RUNTIME for changeset dd6fc1540e99
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at
import sys
import os
import subprocess
import re

import site
site.addsitedir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../lib/python"))

from mozdevice import devicemanagerSUT as devicemanager
from sut_lib import log, getSUTLogger
from installApp import installOneApp
from verify import verifyDevice
import time

def runTests(device, proc_name, number):
    numfailed = -1"Starting to run tests")
    httpport = 8000 + int(number)

    # TODO: fix the host/port information so we don't have conflicts in
    # parallel runs
    cmd = ["python",
           os.path.join(os.path.dirname(__file__), "tests/mochitest/"),
           "--app=%s" % proc_name,
           "--deviceIP=%s" % device,
           "--xre-path=%s" % os.path.join(os.path.dirname(__file__), "xre"),
           "--utility-path=%s" % os.path.join(os.path.dirname(__file__), "bin"),
           # "--test-path=dom/tests/mochitest/dom-level0",
           "--http-port=%s" % httpport]"Going to run test: %s" % subprocess.list2cmdline(cmd))
    proc = ""
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        proc = p.communicate()[0]
        log.error("Exception found while running unittests: %s" % sys.exc_info()[1])"Finished running mochitests")
    refinished = re.compile('([0-9]+) INFO SimpleTest FINISHED')
    refailed = re.compile('([0-9]+) INFO Failed: ([0-9]+)')
    for line in proc.split('\n'):
        finished = refinished.match(line)
        failed = refailed.match(line)
        if failed:
            numfailed = int(
        if finished:
            if numfailed > 0:
                log.error("Found %s failures while running mochitest"
                          % numfailed)
                return False
            return True
    return False

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 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"Successfully verified the device")

    if dm._sock:
    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"Successfully installed the application")

    if not runTests(device_name, processName, number):
        log.error("failed to run dom tests on %s" % (device_name))
        return 1"Successfully ran the mochitests")
    return 0

if __name__ == '__main__':
    global appFileName, processName
    appFileName = os.path.join(os.path.dirname(__file__),
    processName = "org.mozilla.fennec"

    device_name = os.getenv('SUT_NAME')
    if (len(sys.argv) != 2):
        if device_name in (None, ''):
            print "usage: <device name>"
            print "   Must have $SUT_NAME set in environ to omit device name"
            print "INFO: Using device '%s' found in env variable" % device_name
        device_name = sys.argv[1]

    num = re.compile('.*([0-9]+)$')
    match = num.match(device_name)
    deviceNum =
    getSUTLogger(filename="smoketest-%s.log" % deviceNum,
    sys.exit(smoketest(device_name, deviceNum))