示例#1
0
#!/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 http://mozilla.org/MPL/2.0/.

import optparse
import videocapture

usage = "usage: %prog [options] <capture name> <mode> <capture file>"
parser = optparse.OptionParser(usage)
options, args = parser.parse_args()
if len(args) != 3:
    parser.error("incorrect number of arguments")

(capture_name, mode, capture_file) = args

controller = videocapture.CaptureController()
controller.start_capture(capture_file,
                         mode,
                         capture_metadata={'name': capture_name})

print "Should be capturing. Press enter to stop!"
raw_input()
print "Done!"
controller.terminate_capture()

print "Converting capture..."
controller.convert_capture(None, None)
示例#2
0
 def __init__(self, capture_file, capture_device, mode, no_capture=False):
     if not no_capture:
         self.capture_controller = videocapture.CaptureController(
             capture_device)
         self.mode = mode
         self.capture_file = capture_file
示例#3
0
def run_test(testkey, capture_device, appname, capture_name,
             device_prefs, extra_prefs={}, test_type=None, profile_file=None,
             wifi_settings_file=None, request_log_file=None,
             actions_log_file=None, log_checkerboard_stats=False,
             extra_env_vars={}, capture_area=None, no_capture=False,
             capture_file=None, sync_time=True, fps=None):
    testinfo = get_testinfo(testkey)

    if device_prefs['devicetype'] == 'android' and not appname and \
            not testinfo.get('appname'):
        raise TestException("Must specify an appname (with --app-name) on "
                            "Android when not spec'd by test")

    if not os.path.exists(EIDETICKER_TEMP_DIR):
        os.mkdir(EIDETICKER_TEMP_DIR)
    if not os.path.isdir(EIDETICKER_TEMP_DIR):
        raise TestException("Could not open eideticker temporary directory")

    appname = testinfo.get('appname') or appname

    capture_name = capture_name
    if not capture_name:
        capture_name = testinfo['shortDesc']
    if not capture_file and not no_capture:
        capture_file = os.path.join(CAPTURE_DIR, "capture-%s.zip" %
                                    datetime.datetime.now().isoformat())
    elif no_capture:
        capture_file = None

    device = getDevice(**device_prefs)

    capture_metadata = {
        'name': capture_name,
        'testpath': testinfo['relpath'],
        'app': appname,
        'device': device.model,
        'devicetype': device_prefs['devicetype'],
        'startupTest': testinfo['type'] == 'startup'}

    # note: url params for startup tests currently not supported
    if testinfo.get('urlOverride'):
        testpath_rel = testinfo['urlOverride']
    else:
        testpath_rel = testinfo['relpath']
    if testinfo.get('urlParams'):
        testpath_rel += "?%s" % urllib.quote_plus(testinfo.get('urlParams'))

    capture_controller = videocapture.CaptureController(
        capture_device, capture_area, custom_tempdir=EIDETICKER_TEMP_DIR,
        fps=fps)

    testtype = test_type or testinfo['type']

    # get actions for web tests
    actions = None
    if testtype == 'web':
        actions_path = os.path.join(testinfo['here'], "actions.json")
        try:
            with open(actions_path) as f:
                actions = json.loads(f.read())
        except EnvironmentError:
            raise TestException("Couldn't open actions file '%s'" %
                                actions_path)

    test = get_test(testinfo, devicetype=device_prefs['devicetype'],
                    testtype=testtype,
                    testpath_rel=testpath_rel, device=device,
                    actions=actions, extra_prefs=extra_prefs,
                    extra_env_vars=extra_env_vars,
                    capture_file=capture_file,
                    capture_controller=capture_controller,
                    capture_metadata=capture_metadata,
                    appname=appname,
                    request_log_file=request_log_file,
                    actions_log_file=actions_log_file,
                    log_checkerboard_stats=log_checkerboard_stats,
                    profile_file=profile_file,
                    gecko_profiler_addon_dir=GECKO_PROFILER_ADDON_DIR,
                    docroot=TEST_DIR,
                    tempdir=EIDETICKER_TEMP_DIR)

    if device_prefs['devicetype'] == 'b2g':
        device.setupMarionette()

        if sync_time or test.requires_wifi:
            # we catch when the user requests synchronized time but doesn't
            # provide a wifi settings file when parsing options, but no
            # such luck if the test itself requires wifi; so throw an exception
            # in that case
            if not wifi_settings_file:
                raise Exception("WIFI required for this test but no settings "
                                "file (-w) provided!")
            wifi_settings = json.loads(open(wifi_settings_file).read())
            device.connectWIFI(wifi_settings)

        # unlock device, so it doesn't go to sleep
        device.unlock()

        # reset orientation to default for this type of device
        device.resetOrientation()

    # synchronize time unless instructed not to
    if sync_time:
        device.synchronizeTime()

    test.run()
    test.cleanup()

    if capture_file:
        try:
            capture_controller.convert_capture(
                test.start_frame, test.end_frame)
        except KeyboardInterrupt:
            raise TestException("Aborting because of keyboard interrupt")

    return test.testlog
示例#4
0
import os
import subprocess
import sys
import time
import urllib
import urlparse
import videocapture
import StringIO
import eideticker

BINDIR = os.path.dirname(__file__)
CAPTURE_DIR = os.path.abspath(os.path.join(BINDIR, "../captures"))
TEST_DIR = os.path.abspath(os.path.join(BINDIR, "../src/tests"))
EIDETICKER_TEMP_DIR = "/tmp/eideticker"

capture_controller = videocapture.CaptureController(
    custom_tempdir=EIDETICKER_TEMP_DIR)


class CaptureServer(object):
    finished = False
    controller_finishing = False
    start_frame = None
    end_frame = None

    def __init__(self, capture_metadata, capture_file, checkerboard_log_file,
                 capture_controller, device, actions):
        self.capture_metadata = capture_metadata
        self.capture_file = capture_file
        self.checkerboard_log_file = checkerboard_log_file
        self.capture_controller = capture_controller
        self.device = device
示例#5
0
def run_test(testkey, options, capture_filename=None, profile_filename=None,
             capture_name=None):
    testinfo = get_testinfo(testkey)

    if options.devicetype == 'android' and not options.appname and \
            not testinfo.get('appname'):
        raise TestException("Must specify an appname (with --app-name) on "
                            "Android when not spec'd by test")

    if not os.path.exists(EIDETICKER_TEMP_DIR):
        os.mkdir(EIDETICKER_TEMP_DIR)
    if not os.path.isdir(EIDETICKER_TEMP_DIR):
        raise TestException("Could not open eideticker temporary directory")

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

    appname = testinfo.get('appname') or options.appname

    capture_metadata = {
        'name': capture_name or testinfo['shortDesc'],
        'testpath': testinfo['relpath'],
        'app': appname,
        'device': device.model,
        'devicetype': options.devicetype,
        'startupTest': testinfo['type'] == 'startup'}

    # something of a hack. if profiling is enabled, carve off an area to
    # ignore in the capture
    if profile_filename:
        capture_metadata['ignoreAreas'] = [[0, 0, 3 * 64, 3]]

    if options.capture:
        if not capture_filename:
            capture_filename = os.path.join(CAPTURE_DIR,
                                            "capture-%s.zip" %
                                            datetime.datetime.now().isoformat())
        capture_controller = videocapture.CaptureController(capture_filename, options,
                                                            capture_metadata=capture_metadata,
                                                            custom_tempdir=EIDETICKER_TEMP_DIR)

    elif not options.capture:
        capture_controller = None

    test = get_test(testinfo, options, device,
                    capture_controller=capture_controller,
                    profile_filename=profile_filename)

    if device_prefs['devicetype'] == 'b2g':
        device.restartB2G()

        if options.sync_time or test.requires_wifi:
            _connect_wifi(device, options)

    elif device_prefs['devicetype'] == 'android':
        device.stopApplication(appname)

    # synchronize time unless instructed not to
    if options.sync_time:
        device.synchronizeTime()

    try:
        test.run()
    except MarionetteException, e:
        # there are many ways a test could throw a marionette exception, try
        # to catch them all here (we'll consider them non-fatal, so we'll retry
        # a few times before giving up)
        print "Marionette exception caught running test:\n%s" % e
        raise TestException("Marionette exception caught running test: %s" % e.msg,
                            can_retry=True)
#!/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 http://mozilla.org/MPL/2.0/.

import optparse
import os
import sys
import videocapture

usage = "usage: %prog [options] <capture name> <capture file>"
parser = optparse.OptionParser(usage)
options, args = parser.parse_args()
if len(args) != 2:
    parser.error("incorrect number of arguments")

controller = videocapture.CaptureController("Unknown")
controller.launch(args[0], args[1])

print "Should be capturing. Press enter to stop!"
raw_input()
print "Done!"
controller.terminate_capture()

print "Converting capture..."
controller.convert_capture(None, None)