def prepare_test(testkey, options): device_prefs = getDevicePrefs(options) device = getDevice(**device_prefs) # prepare test logic -- currently only done on b2g if device_prefs['devicetype'] == 'b2g': testinfo = get_testinfo(testkey) # HACK: we need to setup marionette here so we can instantiate a # b2gpopulate instance inside the device object (even though we # wind up deleting the same marionette instance in just a moment... # FIXME: find some less convoluted way of getting the same behaviour) device.setupMarionette() test = get_test(testinfo, options, device) # reset B2G device's state for test logger.info("Stopping B2G and cleaning up...") device.stopB2G() device.cleanup() if hasattr(test, 'populate_databases'): logger.info("Populating database...") test.populate_databases() device.startB2G() if test.requires_wifi: _connect_wifi(device, options) if hasattr(test, 'prepare_app'): logger.info("Doing initial setup on app for test") test.prepare_app() else: device.cleanup()
def parse_args(self): (options, args) = CaptureOptionParser.parse_args(self) # parse out environment variables dict = {} for kv in options.extra_env_vars.split(): (var, _, val) = kv.partition("=") dict[var] = val options.extra_env_vars = dict # parse out preferences try: dict = json.loads(options.extra_prefs) options.extra_prefs = dict except ValueError: self.error("Error processing extra preferences: not valid JSON!") raise if options.devicetype == 'b2g' and options.sync_time and \ not options.wifi_settings_file: raise self.error('You must specify a WiFi settings file when ' 'using B2G and sync time.') # if we're using a decklink card and have not specified the # resolution, try to get it by looking at the device model and # our default for it if not options.mode and options.capture_device == 'decklink': device_prefs = getDevicePrefs(options) device = getDevice(**device_prefs) options.mode = device.hdmiResolution return (options, args)
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)