Ejemplo n.º 1
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog <test> [appname1] [appname2] ..."
    parser = eideticker.TestOptionParser(usage=usage)
    parser.add_option("--num-runs", action="store",
                      type="int", dest="num_runs",
                      default=1,
                      help="number of runs (default: 1)")
    parser.add_option("--output-dir", action="store",
                      type="string", dest="outputdir",
                      help="output results to web site")
    parser.add_option("--enable-profiling", action="store_true",
                      dest="enable_profiling",
                      help="Collect performance profiles using the built in "
                      "profiler.")
    parser.add_option("--url-params", action="store",
                      dest="url_params", default="",
                      help="additional url parameters for test")
    parser.add_option("--use-apks", action="store_true", dest="use_apks",
                      help="use and install android APKs as part of test "
                      "(instead of specifying appnames)")
    parser.add_option("--date", action="store", dest="date",
                      metavar="YYYY-MM-DD",
                      help="get and test nightly build for date")
    parser.add_option("--start-date", action="store", dest="start_date",
                      metavar="YYYY-MM-DD",
                      help="start date for range of nightlies to test")
    parser.add_option("--end-date", action="store", dest="end_date",
                      metavar="YYYY-MM-DD",
                      help="end date for range of nightlies to test")

    options, args = parser.parse_args()

    if len(args) == 0:
        parser.error("Must specify at least one argument: the test")

    if options.enable_profiling and not options.outputdir:
        parser.error("Must specify output directory if profiling enabled")

    dates = []
    appnames = []
    apks = []
    if options.start_date and options.end_date and len(args) == 1:
        testname = args[0]
        start_date = eideticker.BuildRetriever.get_date(options.start_date)
        end_date = eideticker.BuildRetriever.get_date(options.end_date)
        days = (end_date - start_date).days
        for numdays in range(days + 1):
            dates.append(start_date + datetime.timedelta(days=numdays))
    elif options.date and len(args) == 1:
        testname = args[0]
        dates = [eideticker.BuildRetriever.get_date(options.date)]
    elif not options.date and len(args) >= 2:
        testname = args[0]
        if options.use_apks:
            apks = args[1:]
        else:
            appnames = args[1:]
    elif options.devicetype == "b2g":
        testname = args[0]
    elif not options.date or (not options.start_date and not options.end_date):
        parser.error("On Android, must specify date, date range, a set of "
                     "appnames (e.g. org.mozilla.fennec) or a set of apks (if "
                     "--use-apks is specified)")

    device_prefs = eideticker.getDevicePrefs(options)

    if options.outputdir:
        eideticker.copy_dashboard_files(options.outputdir,
                                        indexfile='metric.html')

    if options.devicetype == "b2g":
        runtest(device_prefs, testname, options)
    elif appnames:
        for appname in appnames:
            runtest(device_prefs, testname, options, appname=appname)
    elif apks:
        for apk in apks:
            runtest(device_prefs, testname, options, apk=apk)
    else:
        br = eideticker.BuildRetriever()
        productname = "nightly"
        product = eideticker.get_product(productname)
        for date in dates:
            apk = br.get_build(product, date)
            runtest(device_prefs, testname, options, apk=apk, appdate=date)
Ejemplo n.º 2
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog <test> [appname1] [appname2] ..."
    parser = eideticker.TestOptionParser(usage=usage)
    parser.add_option("--num-runs",
                      action="store",
                      type="int",
                      dest="num_runs",
                      default=1,
                      help="number of runs (default: 1)")
    parser.add_option("--output-dir",
                      action="store",
                      type="string",
                      dest="outputdir",
                      help="output results to web site")
    parser.add_option("--enable-profiling",
                      action="store_true",
                      dest="enable_profiling",
                      help="Collect performance profiles using the built in "
                      "profiler.")
    parser.add_option(
        "--get-internal-checkerboard-stats",
        action="store_true",
        dest="get_internal_checkerboard_stats",
        help="get and calculate internal checkerboard stats (Android only)")
    parser.add_option("--url-params",
                      action="store",
                      dest="url_params",
                      default="",
                      help="additional url parameters for test")
    parser.add_option("--use-apks",
                      action="store_true",
                      dest="use_apks",
                      help="use and install android APKs as part of test "
                      "(instead of specifying appnames)")
    parser.add_option("--date",
                      action="store",
                      dest="date",
                      metavar="YYYY-MM-DD",
                      help="get and test nightly build for date")
    parser.add_option("--start-date",
                      action="store",
                      dest="start_date",
                      metavar="YYYY-MM-DD",
                      help="start date for range of nightlies to test")
    parser.add_option("--end-date",
                      action="store",
                      dest="end_date",
                      metavar="YYYY-MM-DD",
                      help="end date for range of nightlies to test")

    options, args = parser.parse_args()

    if len(args) == 0:
        parser.error("Must specify at least one argument: the test")

    if options.enable_profiling and not options.outputdir:
        parser.error("Must specify output directory if profiling enabled")

    dates = []
    appnames = []
    apks = []
    if options.start_date and options.end_date and len(args) == 1:
        testname = args[0]
        start_date = eideticker.BuildRetriever.get_date(options.start_date)
        end_date = eideticker.BuildRetriever.get_date(options.end_date)
        days = (end_date - start_date).days
        for numdays in range(days + 1):
            dates.append(start_date + datetime.timedelta(days=numdays))
    elif options.date and len(args) == 1:
        testname = args[0]
        dates = [eideticker.BuildRetriever.get_date(options.date)]
    elif not options.date and len(args) >= 2:
        testname = args[0]
        if options.use_apks:
            apks = args[1:]
        else:
            appnames = args[1:]
    elif options.devicetype == "b2g":
        testname = args[0]
    elif not options.date or (not options.start_date and not options.end_date):
        parser.error("On Android, must specify date, date range, a set of "
                     "appnames (e.g. org.mozilla.fennec) or a set of apks (if "
                     "--use-apks is specified)")

    device_prefs = eideticker.getDevicePrefs(options)

    if options.outputdir:
        eideticker.copy_dashboard_files(options.outputdir,
                                        indexfile='metric.html')

    if options.devicetype == "b2g":
        runtest(device_prefs, testname, options)
    elif appnames:
        for appname in appnames:
            runtest(device_prefs, testname, options, appname=appname)
    elif apks:
        for apk in apks:
            runtest(device_prefs, testname, options, apk=apk)
    else:
        br = eideticker.BuildRetriever()
        productname = "nightly"
        product = eideticker.get_product(productname)
        for date in dates:
            apk = br.get_build(product, date)
            runtest(device_prefs, testname, options, apk=apk, appdate=date)
Ejemplo n.º 3
0
    parser.print_usage()
    sys.exit(1)

if options.full_mirror and not options.download_metadata:
    parser.error("Need to download metadata for full mirror")
    sys.exit(1)

if options.device_id and not options.dashboard_id:
    parser.error("--device-id must be used in conjunction with --dashboard-id")
    sys.exit(1)

(baseurl, outputdir) = args
if baseurl[-1] != '/':
    baseurl += '/'

eideticker.copy_dashboard_files(outputdir)

metadatadir = os.path.join(outputdir, 'metadata')
videodir = os.path.join(outputdir, 'videos')
profiledir = os.path.join(outputdir, 'profiles')

r = requests.get(urljoin(baseurl, 'dashboard.json'))
if not validate_json_response(r):
    print "Can't download dashboard list, exiting"
    sys.exit(1)
save_file(os.path.join(outputdir, 'dashboard.json'), r.content)

dashboard_ids = map(lambda d: d['id'], r.json()['dashboards'])
if options.dashboard_id:
    if options.dashboard_id in dashboard_ids:
        dashboard_ids = [ options.dashboard_id ]
Ejemplo n.º 4
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] TEST..."

    parser = eideticker.TestOptionParser(usage=usage)
    eideticker.add_dashboard_options(parser)
    parser.add_option("--enable-profiling",
                      action="store_true", dest="enable_profiling",
                      help="Create SPS profile to go along with capture")
    parser.add_option("--device-id", action="store", dest="device_id",
                      help="id of device (used in output json)",
                      default=os.environ.get('DEVICE_ID'))
    parser.add_option("--branch", action="store", dest="branch_id",
                      help="branch under test (used in output json)",
                      default=os.environ.get('BRANCH'))
    parser.add_option("--device-name", action="store", dest="device_name",
                      help="name of device to display in dashboard (if not "
                      "specified, display model name)",
                      default=os.environ.get('DEVICE_NAME'))
    parser.add_option("--apk", action="store", dest="apk",
                      help="Product apk to get metadata from "
                      "(Android-specific)")
    parser.add_option("--baseline", action="store_true", dest="baseline",
                      help="Create baseline results for dashboard")
    parser.add_option("--num-runs", action="store",
                      type="int", dest="num_runs",
                      help="number of runs (default: %default)", default=1)
    parser.add_option("--app-version", action="store", dest="app_version",
                      help="Specify app version (if not automatically "
                      "available; Android-specific)")
    parser.add_option("--sources-xml", action="store", dest="sources_xml",
                      help="Path to sources XML file for getting revision "
                      "information (B2G-specific)")
    parser.add_option("--product", action="store",
                      type="string", dest="product_name",
                      default="nightly",
                      help="product name (android-specific, default: "
                      "%default)")
    options, args = parser.parse_args()

    if not args: # need to specify at least one test to run!
        parser.print_usage()
        sys.exit(1)

    if not options.device_id:
        print "ERROR: Must specify device id (either with --device-id or with " \
            "DEVICE_ID environment variable)"
        sys.exit(1)
    if not options.branch_id:
        print "ERROR: Must specify branch (either with --branch or with " \
            "BRANCH environment variable)"
        sys.exit(1)

    # get device info
    device_prefs = eideticker.getDevicePrefs(options)
    device = eideticker.getDevice(**device_prefs)
    device_name = options.device_name
    if not device_name:
        device_name = device.model

    # copy dashboard files to output directory (if applicable)
    eideticker.copy_dashboard_files(options.dashboard_dir)

    if options.devicetype == 'android':
        product = eideticker.get_product(options.product_name)
        device_info = { 'name': device_name,
                        'version': device.getprop('ro.build.version.release')}
    elif options.devicetype == 'b2g':
        product = eideticker.get_product('b2g-nightly')
        device_info = { 'name': device_name }
    else:
        print "ERROR: Unknown device type '%s'" % options.devicetype

    # update device index
    eideticker.update_dashboard_device_list(options.dashboard_dir, options.device_id,
                                            options.branch_id, device_info)

    # get application/build info
    if options.devicetype == "android":
        if options.apk:
            if options.app_version:
                raise Exception("Should specify either --app-version or "
                                "--apk, not both!")
            appinfo = eideticker.get_fennec_appinfo(options.apk)
            options.appname = appinfo['appname']
            print "Using application name '%s' from apk '%s'" % (
                options.appname, options.apk)
            options.capture_name = "%s %s" % (product['name'], appinfo['appdate'])
        else:
            if not options.app_version:
                raise Exception("Should specify --app-version if not --apk!")

            # no apk, assume it's something static on the device
            appinfo = {
                'appdate': time.strftime("%Y-%m-%d"),
                'version': options.app_version}

    elif options.devicetype == "b2g":
        if not options.sources_xml:
            raise Exception("Must specify --sources-xml on b2g!")

        appinicontents = device.pullFile('/system/b2g/application.ini')
        sfh = StringIO.StringIO(appinicontents)
        appinfo = eideticker.get_appinfo(sfh)
        appinfo.update(get_revision_data(options.sources_xml))
        options.appname = None
    else:
        print "Unknown device type '%s'!" % options.devicetype

    # run through the tests...
    failed_tests = []
    for testkey in args:
        testinfo = eideticker.get_testinfo(testkey)

        eideticker.update_dashboard_test_list(options.dashboard_dir, options.device_id,
                                              options.branch_id,
                                              testinfo)

        current_date = time.strftime("%Y-%m-%d")
        options.capture_name = "%s - %s (taken on %s)" % (testkey, product['name'],
                                                  current_date)

        if options.prepare_test:
            eideticker.prepare_test(testkey, options)

        # Run the test the specified number of times
        for i in range(options.num_runs):
            try:
                runtest(device, device_prefs, options,
                        product, appinfo, testinfo,
                        options.capture_name + " #%s" % i)
            except eideticker.TestException:
                print "Unable to run test '%s'. Skipping and continuing." % testkey
                failed_tests.append(testkey)
                break

        # synchronize with dashboard (if we have a server to upload to)
        if options.dashboard_server:
            eideticker.upload_dashboard(options)
        else:
            print "No dashboard server specified. Skipping upload."

    if failed_tests:
        print "The following tests failed: %s" % ", ".join(failed_tests)
        sys.exit(1)
Ejemplo n.º 5
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] <product> <test>"

    parser = eideticker.TestOptionParser(usage=usage)
    parser.add_option("--enable-profiling",
                      action="store_true",
                      dest="enable_profiling",
                      help="Create SPS profile to go along with capture")
    parser.add_option("--device-id",
                      action="store",
                      dest="device_id",
                      help="id of device (used in output json)",
                      default=os.environ.get('DEVICE_ID'))
    parser.add_option("--device-name",
                      action="store",
                      dest="device_name",
                      help="name of device to display in dashboard (if not "
                      "specified, display model name)",
                      default=os.environ.get('DEVICE_NAME'))
    parser.add_option("--apk",
                      action="store",
                      dest="apk",
                      help="Product apk to get metadata from "
                      "(Android-specific)")
    parser.add_option("--baseline",
                      action="store_true",
                      dest="baseline",
                      help="Create baseline results for dashboard")
    parser.add_option("--num-runs",
                      action="store",
                      type="int",
                      dest="num_runs",
                      help="number of runs (default: 1)")
    parser.add_option("--app-version",
                      action="store",
                      dest="app_version",
                      help="Specify app version (if not automatically "
                      "available; Android-specific)")
    parser.add_option("--sources-xml",
                      action="store",
                      dest="sources_xml",
                      help="Path to sources XML file for getting revision "
                      "information (B2G-specific)")
    parser.add_option(
        "--output-dir",
        action="store",
        type="string",
        dest="outputdir",
        default=eideticker.DASHBOARD_DIR,
        help="output results to directory instead of src/dashboard")

    options, args = parser.parse_args()

    if len(args) != 2:
        parser.print_usage()
        sys.exit(1)

    (productname, testkey) = args
    num_runs = 1
    if options.num_runs:
        num_runs = options.num_runs

    testinfo = eideticker.get_testinfo(testkey)

    device_id = options.device_id
    if not device_id:
        print "ERROR: Must specify device id (either with --device-id or with "
        "DEVICE_ID environment variable)"
        sys.exit(1)

    # we'll log http requests for webstartup tests only
    log_http_requests = False
    if testinfo['type'] == 'webstartup':
        log_http_requests = True

    # likewise, log actions only for web tests and b2g tests
    log_actions = False
    if testinfo['type'] == 'web' or testinfo['type'] == 'b2g':
        log_actions = True

    product = eideticker.get_product(productname)
    current_date = time.strftime("%Y-%m-%d")
    capture_name = "%s - %s (taken on %s)" % (testkey, product['name'],
                                              current_date)
    datafile = os.path.join(options.outputdir, device_id, '%s.json' % testkey)

    data = NestedDict()
    if os.path.isfile(datafile):
        data.update(json.loads(open(datafile).read()))

    device_prefs = eideticker.getDevicePrefs(options)
    device = eideticker.getDevice(**device_prefs)

    devices = {}
    devicefile = os.path.join(options.outputdir, 'devices.json')
    if os.path.isfile(devicefile):
        devices = json.loads(open(devicefile).read())['devices']
    testfile = os.path.join(options.outputdir, '%s' % device_id, 'tests.json')
    if os.path.isfile(testfile):
        tests = json.loads(open(testfile).read())['tests']
    else:
        tests = {}
    tests[testkey] = {
        'shortDesc': testinfo['shortDesc'],
        'defaultMeasureId': testinfo['defaultMeasure']
    }

    device_name = options.device_name
    if not device_name:
        device_name = device.model

    if options.devicetype == "android":
        devices[device_id] = {
            'name': device_name,
            'version': device.getprop('ro.build.version.release')
        }
        if options.apk:
            if options.app_version:
                raise Exception("Should specify either --app-version or "
                                "--apk, not both!")
            appinfo = eideticker.get_fennec_appinfo(options.apk)
            appname = appinfo['appname']
            print "Using application name '%s' from apk '%s'" % (appname,
                                                                 options.apk)
            capture_name = "%s %s" % (product['name'], appinfo['appdate'])
        else:
            if not options.app_version:
                raise Exception("Should specify --app-version if not --apk!")

            # no apk, assume it's something static on the device
            appinfo = {
                'appdate': time.strftime("%Y-%m-%d"),
                'version': options.app_version
            }
            appname = product['appname']

    elif options.devicetype == "b2g":
        if not options.sources_xml:
            raise Exception("Must specify --sources-xml on b2g!")

        devices[device_id] = {'name': device_name}
        appinicontents = device.pullFile('/system/b2g/application.ini')
        sfh = StringIO.StringIO(appinicontents)
        appinfo = eideticker.get_appinfo(sfh)
        appinfo.update(get_revision_data(options.sources_xml))
        appname = None
    else:
        print "Unknown device type '%s'!" % options.devicetype

    # copy dashboard files to output directory (if applicable)
    eideticker.copy_dashboard_files(options.outputdir)

    # update the device / test list for the dashboard
    with open(devicefile, 'w') as f:
        f.write(json.dumps({'devices': devices}))
    testfiledir = os.path.dirname(testfile)
    if not os.path.exists(testfiledir):
        os.mkdir(testfiledir)
    with open(testfile, 'w') as f:
        f.write(json.dumps({'tests': tests}))

    if options.prepare_test:
        eideticker.prepare_test(testkey, device_prefs,
                                options.wifi_settings_file)

    # Run the test the specified number of times
    for i in range(num_runs):
        runtest(device,
                device_prefs,
                options,
                product,
                appname,
                appinfo,
                testinfo,
                capture_name + " #%s" % i,
                datafile,
                data,
                log_http_requests=log_http_requests,
                log_actions=log_actions)
Ejemplo n.º 6
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] TEST..."

    parser = eideticker.TestOptionParser(usage=usage)
    eideticker.add_dashboard_options(parser)
    parser.add_option("--enable-profiling",
                      action="store_true",
                      dest="enable_profiling",
                      help="Create SPS profile to go along with capture")
    parser.add_option("--dashboard-id",
                      action="store",
                      dest="dashboard_id",
                      help="id of dashboard (used in output json)",
                      default=os.environ.get('DASHBOARD_ID'))
    parser.add_option("--dashboard-name",
                      action="store",
                      dest="dashboard_name",
                      help="name of dashboard to display",
                      default=os.environ.get('DASHBOARD_NAME'))
    parser.add_option("--device-id",
                      action="store",
                      dest="device_id",
                      help="id of device (used in output json)",
                      default=os.environ.get('DEVICE_ID'))
    parser.add_option("--branch",
                      action="store",
                      dest="branch_id",
                      help="branch under test (used in output json)",
                      default=os.environ.get('BRANCH'))
    parser.add_option("--device-name",
                      action="store",
                      dest="device_name",
                      help="name of device to display in dashboard (if not "
                      "specified, display model name)",
                      default=os.environ.get('DEVICE_NAME'))
    parser.add_option("--apk",
                      action="store",
                      dest="apk",
                      help="Product apk to get metadata from "
                      "(Android-specific)")
    parser.add_option("--baseline",
                      action="store_true",
                      dest="baseline",
                      help="Create baseline results for dashboard")
    parser.add_option("--num-runs",
                      action="store",
                      type="int",
                      dest="num_runs",
                      help="number of runs (default: %default)",
                      default=1)
    parser.add_option("--app-version",
                      action="store",
                      dest="app_version",
                      help="Specify app version (if not automatically "
                      "available; Android-specific)")
    parser.add_option("--sources-xml",
                      action="store",
                      dest="sources_xml",
                      help="Path to sources XML file for getting revision "
                      "information (B2G-specific)")
    parser.add_option("--product",
                      action="store",
                      type="string",
                      dest="product_name",
                      default="nightly",
                      help="product name (android-specific, default: "
                      "%default)")
    options, args = parser.parse_args()

    if not args:  # need to specify at least one test to run!
        parser.print_usage()
        sys.exit(1)

    if not options.dashboard_id:
        parser.error("Must specify dashboard id (either with --dashboard-id "
                     "or with DASHBOARD_ID environment variable)")
    if not options.dashboard_name:
        parser.error("Must specify dashboard name (either with "
                     "--dashboard-name or with DASHBOARD_NAME environment "
                     "varaiable)")
    if not options.device_id:
        parser.error("Must specify device id (either with --device-id or with "
                     "DEVICE_ID environment variable)")
    if not options.branch_id:
        parser.error("Must specify branch (either with --branch or with "
                     "BRANCH environment variable)")

    # get device info
    device_prefs = eideticker.getDevicePrefs(options)
    device = eideticker.getDevice(**device_prefs)
    device_name = options.device_name
    if not device_name:
        device_name = device.model

    # copy dashboard files to output directory (if applicable)
    eideticker.copy_dashboard_files(options.dashboard_dir)

    if options.devicetype == 'android':
        product = eideticker.get_product(options.product_name)
        device_info = {
            'name': device_name,
            'version': device.getprop('ro.build.version.release')
        }
    elif options.devicetype == 'b2g':
        product = eideticker.get_product('b2g-nightly')
        device_info = {'name': device_name}
    else:
        print "ERROR: Unknown device type '%s'" % options.devicetype

    # update dashboard / device index
    eideticker.update_dashboard_list(options.dashboard_dir,
                                     options.dashboard_id,
                                     options.dashboard_name)
    eideticker.update_dashboard_device_list(options.dashboard_dir,
                                            options.dashboard_id,
                                            options.device_id,
                                            options.branch_id, device_info)

    # get application/build info
    if options.devicetype == "android":
        if options.apk:
            if options.app_version:
                raise Exception("Should specify either --app-version or "
                                "--apk, not both!")
            appinfo = eideticker.get_fennec_appinfo(options.apk)
            options.appname = appinfo['appname']
            print "Using application name '%s' from apk '%s'" % (
                options.appname, options.apk)
            options.capture_name = "%s %s" % (product['name'],
                                              appinfo['appdate'])
        else:
            if not options.app_version:
                raise Exception("Should specify --app-version if not --apk!")

            # no apk, assume it's something static on the device
            appinfo = {
                'appdate': time.strftime("%Y-%m-%d"),
                'version': options.app_version
            }

    elif options.devicetype == "b2g":
        if not options.sources_xml:
            raise Exception("Must specify --sources-xml on b2g!")

        appinicontents = device.pullFile('/system/b2g/application.ini')
        sfh = StringIO.StringIO(appinicontents)
        appinfo = eideticker.get_appinfo(sfh)
        appinfo.update(get_revision_data(options.sources_xml))
        options.appname = None
    else:
        print "Unknown device type '%s'!" % options.devicetype

    # run through the tests...
    failed_tests = []
    for testkey in args:
        testinfo = eideticker.get_testinfo(testkey)

        eideticker.update_dashboard_test_list(options.dashboard_dir,
                                              options.dashboard_id,
                                              options.device_id,
                                              options.branch_id, testinfo)

        current_date = time.strftime("%Y-%m-%d")
        options.capture_name = "%s - %s (taken on %s)" % (
            testkey, product['name'], current_date)

        if options.prepare_test:
            eideticker.prepare_test(testkey, options)

        # Run the test the specified number of times
        for i in range(options.num_runs):
            try:
                runtest(device, device_prefs, options, product, appinfo,
                        testinfo, options.capture_name + " #%s" % i)
            except eideticker.TestException:
                print "Unable to run test '%s'. Skipping and continuing." % testkey
                failed_tests.append(testkey)
                break

        # synchronize with dashboard (if we have a server to upload to)
        if options.dashboard_server:
            eideticker.upload_dashboard(options)
        else:
            print "No dashboard server specified. Skipping upload."

    if failed_tests:
        print "The following tests failed: %s" % ", ".join(failed_tests)
        sys.exit(1)
Ejemplo n.º 7
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] <product> <test>"

    parser = eideticker.TestOptionParser(usage=usage)
    parser.add_option("--enable-profiling",
                      action="store_true", dest="enable_profiling",
                      help="Create SPS profile to go along with capture")
    parser.add_option("--device-id", action="store", dest="device_id",
                      help="id of device (used in output json)",
                      default=os.environ.get('DEVICE_ID'))
    parser.add_option("--device-name", action="store", dest="device_name",
                      help="name of device to display in dashboard (if not "
                      "specified, display model name)",
                      default=os.environ.get('DEVICE_NAME'))
    parser.add_option("--apk", action="store", dest="apk",
                      help="Product apk to get metadata from "
                      "(Android-specific)")
    parser.add_option("--baseline", action="store_true", dest="baseline",
                      help="Create baseline results for dashboard")
    parser.add_option("--num-runs", action="store",
                      type="int", dest="num_runs",
                      help="number of runs (default: 1)")
    parser.add_option("--app-version", action="store", dest="app_version",
                      help="Specify app version (if not automatically "
                      "available; Android-specific)")
    parser.add_option("--sources-xml", action="store", dest="sources_xml",
                      help="Path to sources XML file for getting revision "
                      "information (B2G-specific)")
    parser.add_option("--output-dir", action="store",
                      type="string", dest="outputdir", default=eideticker.DASHBOARD_DIR,
                      help="output results to directory instead of src/dashboard")

    options, args = parser.parse_args()

    if len(args) != 2:
        parser.print_usage()
        sys.exit(1)

    (productname, testkey) = args
    num_runs = 1
    if options.num_runs:
        num_runs = options.num_runs

    testinfo = eideticker.get_testinfo(testkey)

    device_id = options.device_id
    if not device_id:
        print "ERROR: Must specify device id (either with --device-id or with "
        "DEVICE_ID environment variable)"
        sys.exit(1)

    # we'll log http requests for webstartup tests only
    log_http_requests = False
    if testinfo['type'] == 'webstartup':
        log_http_requests = True

    # likewise, log actions only for web tests and b2g tests
    log_actions = False
    if testinfo['type'] == 'web' or testinfo['type'] == 'b2g':
        log_actions = True

    product = eideticker.get_product(productname)
    current_date = time.strftime("%Y-%m-%d")
    capture_name = "%s - %s (taken on %s)" % (testkey, product['name'],
                                              current_date)
    datafile = os.path.join(options.outputdir, device_id, '%s.json' % testkey)

    data = NestedDict()
    if os.path.isfile(datafile):
        data.update(json.loads(open(datafile).read()))

    device_prefs = eideticker.getDevicePrefs(options)
    device = eideticker.getDevice(**device_prefs)

    devices = {}
    devicefile = os.path.join(options.outputdir, 'devices.json')
    if os.path.isfile(devicefile):
        devices = json.loads(open(devicefile).read())['devices']
    testfile = os.path.join(options.outputdir, '%s' % device_id, 'tests.json')
    if os.path.isfile(testfile):
        tests = json.loads(open(testfile).read())['tests']
    else:
        tests = {}
    tests[testkey] = {'shortDesc': testinfo['shortDesc'],
                      'defaultMeasureId': testinfo['defaultMeasure']}

    device_name = options.device_name
    if not device_name:
        device_name = device.model

    if options.devicetype == "android":
        devices[device_id] = {
            'name': device_name,
            'version': device.getprop('ro.build.version.release')}
        if options.apk:
            if options.app_version:
                raise Exception("Should specify either --app-version or "
                                "--apk, not both!")
            appinfo = eideticker.get_fennec_appinfo(options.apk)
            appname = appinfo['appname']
            print "Using application name '%s' from apk '%s'" % (
                appname, options.apk)
            capture_name = "%s %s" % (product['name'], appinfo['appdate'])
        else:
            if not options.app_version:
                raise Exception("Should specify --app-version if not --apk!")

            # no apk, assume it's something static on the device
            appinfo = {
                'appdate': time.strftime("%Y-%m-%d"),
                'version': options.app_version}
            appname = product['appname']

    elif options.devicetype == "b2g":
        if not options.sources_xml:
            raise Exception("Must specify --sources-xml on b2g!")

        devices[device_id] = {'name': device_name}
        appinicontents = device.pullFile('/system/b2g/application.ini')
        sfh = StringIO.StringIO(appinicontents)
        appinfo = eideticker.get_appinfo(sfh)
        appinfo.update(get_revision_data(options.sources_xml))
        appname = None
    else:
        print "Unknown device type '%s'!" % options.devicetype

    # copy dashboard files to output directory (if applicable)
    eideticker.copy_dashboard_files(options.outputdir)

    # update the device / test list for the dashboard
    with open(devicefile, 'w') as f:
        f.write(json.dumps({'devices': devices}))
    testfiledir = os.path.dirname(testfile)
    if not os.path.exists(testfiledir):
        os.mkdir(testfiledir)
    with open(testfile, 'w') as f:
        f.write(json.dumps({'tests': tests}))

    if options.prepare_test:
        eideticker.prepare_test(
            testkey, device_prefs, options.wifi_settings_file)

    # Run the test the specified number of times
    for i in range(num_runs):
        runtest(device, device_prefs, options,
                product, appname, appinfo, testinfo,
                capture_name + " #%s" % i, datafile, data,
                log_http_requests=log_http_requests,
                log_actions=log_actions)
Ejemplo n.º 8
0
    parser.print_usage()
    sys.exit(1)

if options.full_mirror and not options.download_metadata:
    parser.error("Need to download metadata for full mirror")
    sys.exit(1)

if options.device_id and not options.dashboard_id:
    parser.error("--device-id must be used in conjunction with --dashboard-id")
    sys.exit(1)

(baseurl, outputdir) = args
if baseurl[-1] != '/':
    baseurl += '/'

eideticker.copy_dashboard_files(outputdir)

metadatadir = os.path.join(outputdir, 'metadata')
videodir = os.path.join(outputdir, 'videos')
profiledir = os.path.join(outputdir, 'profiles')

r = requests.get(urljoin(baseurl, 'dashboard.json'))
if not validate_json_response(r):
    print "Can't download dashboard list, exiting"
    sys.exit(1)
save_file(os.path.join(outputdir, 'dashboard.json'), r.content)

dashboard_ids = map(lambda d: d['id'], r.json()['dashboards'])
if options.dashboard_id:
    if options.dashboard_id in dashboard_ids:
        dashboard_ids = [options.dashboard_id]