def main(args=sys.argv[1:]): """ Return codes 0 - success 1 - test failures 2 - fatal error """ parser = PeptestOptions() options, args = parser.parse_args() options = parser.verifyOptions(options) if options == None: return 2 # setup the logging if options.logFile: handler = mozlog.FileHandler(options.logFile) handler.setFormatter(mozlog.MozFormatter()) logger = mozlog.getLogger('PEP', handler) else: logger = mozlog.getLogger('PEP') if options.logLevel: logger.setLevel(getattr(mozlog, options.logLevel, 'INFO')) try: peptest = applications[options.app](options) return peptest.start() except Exception: cla, exc = sys.exc_info()[:2] logger.error("%s: %s" % (cla.__name__, exc)) logger.debug("Traceback:\n%s" % (traceback.format_exc())) return 2
def test_logger_defaults(self): """Tests the default logging format and behavior.""" default_logger = mozlog.getLogger("default.logger") self.assertEqual(default_logger.name, "default.logger") self.assertEqual(len(default_logger.handlers), 1) self.assertTrue(isinstance(default_logger.handlers[0], mozlog.StreamHandler)) f = mozfile.NamedTemporaryFile() list_logger = mozlog.getLogger("file.logger", handler=mozlog.FileHandler(f.name)) self.assertEqual(len(list_logger.handlers), 1) self.assertTrue(isinstance(list_logger.handlers[0], mozlog.FileHandler)) f.close() self.assertRaises(ValueError, mozlog.getLogger, "file.logger", handler=ListHandler())
def __init__(self, profile, devicemanager, marionette, context_chrome=True, test_script=None, test_script_args=None, **kwargs): RemoteRunner.__init__(self, profile, devicemanager, **kwargs) self.log = mozlog.getLogger('B2GRunner') tmpfd, processLog = tempfile.mkstemp(suffix='pidlog') os.close(tmpfd) tmp_env = self.env or {} self.env = { 'MOZ_CRASHREPORTER': '1', 'MOZ_CRASHREPORTER_NO_REPORT': '1', 'MOZ_HIDE_RESULTS_TABLE': '1', 'MOZ_PROCESS_LOG': processLog, 'NSPR_LOG_MODULES': 'signaling:5,mtransport:3', 'R_LOG_LEVEL': '5', 'R_LOG_DESTINATION': 'stderr', 'R_LOG_VERBOSE': '1', 'NO_EM_RESTART': '1', } self.env.update(tmp_env) self.last_test = "automation" self.marionette = marionette self.context_chrome = context_chrome self.test_script = test_script self.test_script_args = test_script_args self.remote_profiles_ini = '/data/b2g/mozilla/profiles.ini' self.bundles_dir = '/system/b2g/distribution/bundles' self.user_js = '/data/local/user.js'
def __init__(self, tests, testfile=None, es_server=None, rest_server=None, testgroup='marionette'): self.logger = mozlog.getLogger('B2G_AUTOMATION') self.tests = tests self.testfile = testfile self.es_server = es_server self.rest_server = rest_server self.testgroup = testgroup self.lock = RLock() self.logger.info("Testlist: %s" % self.tests) pulse = B2GPulseConsumer(applabel='b2g_build_listener') pulse.configure(topic='#', callback=self.on_build) if not self.testfile: self.logger.info('waiting for pulse messages...') pulse.listen() else: t = Thread(target=pulse.listen) t.daemon = True t.start() f = open(self.testfile, 'r') data = json.loads(f.read()) self.on_build(data, None)
def __init__(self, **kwargs): # Set up the log file or use stdout if none specified self.log = mozlog.getLogger('FB_UPDATE', kwargs.get('log')) self.log.setLevel(mozlog.DEBUG if kwargs.get('debug') else mozlog.INFO) self.repo = kwargs.get('repo') self.serverpath = kwargs.get('serverpath')
def main(args=sys.argv[1:]): """ Return codes 0 - success 1 - test failures 2 - fatal error """ parser = PeptestOptions() options, args = parser.parse_args() options = parser.verifyOptions(options) if options == None: return 2 # setup the logging logger = mozlog.getLogger('PEP', options.logFile) if options.logLevel: logger.setLevel(getattr(mozlog, options.logLevel, 'INFO')) try: peptest = applications[options.app](options) return peptest.start() except Exception: cla, exc = sys.exc_info()[:2] logger.error("%s: %s" % (cla.__name__, exc)) logger.debug("Traceback:\n%s" % (traceback.format_exc())) return 2
def __init__(self, profile, devicemanager, clean_profile=None, process_class=None, env=None, remote_test_root=None, restore=True, **kwargs): Runner.__init__(self, profile, clean_profile=clean_profile, process_class=process_class, env=env, **kwargs) self.log = mozlog.getLogger('RemoteRunner') self.dm = devicemanager self.last_test = None self.remote_test_root = remote_test_root or self.dm.getDeviceRoot() self.remote_profile = posixpath.join(self.remote_test_root, 'profile') self.restore = restore self.added_files = set() self.backup_files = set()
def cli(): parser = OptionParser(usage='%prog [options] <test_file> <test_file> ...') parser.add_option("--binary", action="store", dest="binary", default=None, help="path to B2G desktop build binary") parser.add_option("--profile", action="store", dest="profile", default=None, help="path to gaia profile directory") options, tests = parser.parse_args() if not options.binary or not options.profile: parser.print_usage() parser.exit('--binary and --profile required') if not tests: # Read in a list of tests to skip from disabled.json, if it exists; # disabled.json should contain filenames with paths relative to the # apps directory, e.g., "wallpaper/test/unit/pick_test.js". disabled = [] disabled_file = os.path.join(os.path.dirname(__file__), 'disabled.json') if os.access(disabled_file, os.F_OK): with open(disabled_file, 'r') as f: disabled_contents = f.read() try: disabled = json.loads(disabled_contents) except: traceback.print_exc() print "Error while decoding disabled.json; please make sure this file has valid JSON syntax." sys.exit(1) # build a list of tests appsdir = os.path.join(os.path.dirname(os.path.abspath(options.profile)), 'apps') for root, dirs, files in os.walk(appsdir): for file in files: full_path = os.path.relpath(os.path.join(root, file), appsdir) if full_path[-8:] == '_test.js' and full_path not in disabled: tests.append(full_path) runner = GaiaUnitTestRunner(binary=options.binary, profile=options.profile) runner.run() # Lame but necessary hack to prevent tornado's logger from duplicating # every message from mozlog. logger = logging.getLogger() handler = logging.NullHandler() logger.addHandler(handler) print 'starting WebSocket Server' application = tornado.web.Application([ (r"/", TestAgentServer, {'tests': tests, 'runner': runner, 'logger': mozlog.getLogger('gaia-unit-tests')}), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8789) tornado.ioloop.IOLoop.instance().start()
def __init__(self, device_serial=None): self.device_serial = device_serial self._logger = structured.get_default_logger(component='b2gmonkey') if not self._logger: self._logger = mozlog.getLogger('b2gmonkey') self.version = mozversion.get_version(dm_type='adb', device_serial=device_serial) device_id = self.version.get('device_id') if not device_id: raise B2GMonkeyError('Firefox OS device not found.') self.device_properties = DEVICE_PROPERTIES.get(device_id) if not self.device_properties: raise B2GMonkeyError('Unsupported device: \'%s\'' % device_id) android_version = self.version.get('device_firmware_version_release') if device_id == 'flame' and android_version == '4.4.2': self.device_properties.update(DEVICE_PROPERTIES.get('flame-kk')) self.temp_dir = tempfile.mkdtemp() if 'MINIDUMP_SAVE_PATH' not in os.environ: self.crash_dumps_path = os.path.join(self.temp_dir, 'crashes') os.environ['MINIDUMP_SAVE_PATH'] = self.crash_dumps_path else: self.crash_dumps_path = os.environ['MINIDUMP_SAVE_PATH']
def __init__(self, device_serial=None): self.device_serial = device_serial self._logger = structured.get_default_logger(component='b2gmonkey') if not self._logger: self._logger = mozlog.getLogger('b2gmonkey') self.version = mozversion.get_version( dm_type='adb', device_serial=device_serial) device_id = self.version.get('device_id') if not device_id: raise B2GMonkeyError('Firefox OS device not found.') self.device_properties = DEVICE_PROPERTIES.get(device_id) if not self.device_properties: raise B2GMonkeyError('Unsupported device: \'%s\'' % device_id) android_version = self.version.get('device_firmware_version_release') if device_id == 'flame' and android_version == '4.4.2': self.device_properties.update(DEVICE_PROPERTIES.get('flame-kk')) self.temp_dir = tempfile.mkdtemp() if 'MINIDUMP_SAVE_PATH' not in os.environ: self.crash_dumps_path = os.path.join(self.temp_dir, 'crashes') os.environ['MINIDUMP_SAVE_PATH'] = self.crash_dumps_path else: self.crash_dumps_path = os.environ['MINIDUMP_SAVE_PATH']
def gather_debug(test, status): rv = {} marionette = test._marionette_weakref() # In the event we're gathering debug without starting a session, skip marionette commands if marionette.session is not None: try: marionette.switch_to_frame() rv["settings"] = json.dumps( marionette.execute_async_script( """ SpecialPowers.pushPermissions([ {type: 'settings-read', allow: true, context: document}, {type: 'settings-api-read', allow: true, context: document}, ], function() { var req = window.navigator.mozSettings.createLock().get('*'); req.onsuccess = function() { marionetteScriptFinished(req.result); } });""", special_powers=True, ), sort_keys=True, indent=4, separators=(",", ": "), ) except: logger = mozlog.structured.get_default_logger() if not logger: logger = mozlog.getLogger("gaiatest") logger.warning("Failed to gather test failure debug.", exc_info=True) return rv
def gather_debug(test, status): rv = {} marionette = test._marionette_weakref() # In the event we're gathering debug without starting a session, skip marionette commands if marionette.session is not None: try: marionette.switch_to_frame() rv['settings'] = json.dumps( marionette.execute_async_script(""" SpecialPowers.pushPermissions([ {type: 'settings-read', allow: true, context: document}, {type: 'settings-api-read', allow: true, context: document}, ], function() { var req = window.navigator.mozSettings.createLock().get('*'); req.onsuccess = function() { marionetteScriptFinished(req.result); } });""", special_powers=True), sort_keys=True, indent=4, separators=(',', ': ')) except: logger = mozlog.structured.get_default_logger() if not logger: logger = mozlog.getLogger('gaiatest') logger.warning('Failed to gather test failure debug.', exc_info=True) return rv
def cli(): parser = OptionParser(usage="%prog [options] <test_file> <test_file> ...") parser.add_option("--binary", action="store", dest="binary", default=None, help="path to B2G desktop build binary") parser.add_option("--profile", action="store", dest="profile", default=None, help="path to gaia profile directory") options, tests = parser.parse_args() if not options.binary or not options.profile: parser.print_usage() parser.exit("--binary and --profile required") if not tests: # build a list of tests appsdir = os.path.join(os.path.dirname(os.path.abspath(options.profile)), "apps") for root, dirs, files in os.walk(appsdir): for file in files: if file[-8:] == "_test.js": tests.append(os.path.relpath(os.path.join(root, file), appsdir)) runner = GaiaUnitTestRunner(binary=options.binary, profile=options.profile) runner.run() # Lame but necessary hack to prevent tornado's logger from duplicating # every message from mozlog. logger = logging.getLogger() handler = logging.NullHandler() logger.addHandler(handler) print "starting WebSocket Server" application = tornado.web.Application( [(r"/", TestAgentServer, {"tests": tests, "runner": runner, "logger": mozlog.getLogger("gaia-unit-tests")})] ) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8789) tornado.ioloop.IOLoop.instance().start()
def __init__(self, marionette, datazilla_config=None, sources=None, log_level='INFO'): # Set up logging handler = mozlog.StreamHandler() handler.setFormatter(mozlog.MozFormatter(include_timestamp=True)) self.logger = mozlog.getLogger(self.__class__.__name__, handler) self.logger.setLevel(getattr(mozlog, log_level.upper())) self.marionette = marionette settings = gaiatest.GaiaData(self.marionette).all_settings mac_address = self.marionette.execute_script( 'return navigator.mozWifiManager && ' 'navigator.mozWifiManager.macAddress;') self.submit_report = True self.ancillary_data = {} self.ancillary_data['generated_by'] = 'b2gperf %s' % __version__ self.device = gaiatest.GaiaDevice(self.marionette) dm = mozdevice.DeviceManagerADB() self.device.add_device_manager(dm) version = mozversion.get_version(sources=sources, dm_type='adb') self.ancillary_data['build_revision'] = version.get('build_changeset') self.ancillary_data['gaia_revision'] = version.get('gaia_changeset') self.ancillary_data['gecko_revision'] = version.get('gecko_changeset') self.ancillary_data['ro.build.version.incremental'] = version.get( 'device_firmware_version_incremental') self.ancillary_data['ro.build.version.release'] = version.get( 'device_firmware_version_release') self.ancillary_data['ro.build.date.utc'] = version.get( 'device_firmware_date') self.required = { 'generated by': self.ancillary_data.get('generated_by'), 'gaia revision': self.ancillary_data.get('gaia_revision'), 'gecko revision': self.ancillary_data.get('gecko_revision'), 'build revision': self.ancillary_data.get('build_revision'), 'protocol': datazilla_config['protocol'], 'host': datazilla_config['host'], 'project': datazilla_config['project'], 'branch': datazilla_config['branch'], 'oauth key': datazilla_config['oauth_key'], 'oauth secret': datazilla_config['oauth_secret'], 'machine name': datazilla_config['machine_name'] or mac_address, 'device name': datazilla_config['device_name'], 'os version': settings.get('deviceinfo.os'), 'id': settings.get('deviceinfo.platform_build_id')} for key, value in self.required.items(): if value: self.logger.debug('DataZilla field: %s (%s)' % (key, value)) if not value: self.submit_report = False self.logger.warn('Missing required DataZilla field: %s' % key) if not self.submit_report: self.logger.info('Reports will not be submitted to DataZilla')
def __init__(self, options, **kwargs): self.options = options self.server = None self.logger = mozlog.getLogger('PEP') # create the profile self.profile = self.profile_class( profile=self.options.profilePath, addons=[os.path.join(here, 'extension')]) # fork a server to serve the test related files if self.options.serverPath: self.runServer() tests = [] # TODO is there a better way of doing this? if self.options.testPath.endswith('.js'): # a single test file was passed in testObj = {} testObj['path'] = os.path.realpath(self.options.testPath) testObj['name'] = os.path.basename(self.options.testPath) testObj['here'] = os.path.dirname(testObj['path']) tests.append(testObj) else: # a test manifest was passed in # open and convert the manifest to json manifest = TestManifest() manifest.read(self.options.testPath) tests = manifest.get() # create a manifest object to be read by the JS side manifestObj = {} manifestObj['tests'] = tests # write manifest to a JSON file jsonManifest = open(os.path.join(here, 'manifest.json'), 'w') jsonManifest.write(str(manifestObj).replace("'", "\"")) jsonManifest.close() # setup environment env = os.environ.copy() env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1' env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str( options.tracerThreshold) env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval) env['MOZ_CRASHREPORTER_NO_REPORT'] = '1' # construct the browser arguments cmdargs = [] # TODO Make browserArgs a list cmdargs.extend(self.options.browserArgs) cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)]) # run with managed process handler self.runner = self.runner_class(profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess)
def __init__(self, profile, clean_profile=True, process_class=None, kp_kwargs=None, env=None): self.clean_profile = clean_profile self.env = env or {} self.kp_kwargs = kp_kwargs or {} self.process_class = process_class or ProcessHandler self.process_handler = None self.profile = profile self.log = mozlog.getLogger('MozRunner')
def main(): parser = OptionParser(usage="%prog <options>") parser.add_option("--offline", action="store_true", dest="offline", default=False, help="Start without using pulse") parser.add_option( "--test-manifest", action="store", dest="testmanifest", default=os.path.join("tests", "all-tests.ini"), help="Specify the test manifest, defaults to tests/all-tests.ini", ) parser.add_option( "--log-file", action="store", dest="logfile", default="b2gautomation.log", help="Log file to store results, defaults to b2gautomation.log", ) LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR") LEVEL_STRING = ", ".join(LOG_LEVELS) parser.add_option( "--log-level", action="store", type="choice", dest="loglevel", default="DEBUG", choices=LOG_LEVELS, help="One of %s for logging level, defaults to debug" % LEVEL_STRING, ) options, args = parser.parse_args() if not options.testmanifest: parser.print_usage() parser.exit() if not os.path.exists(options.testmanifest): print "Could not find manifest file: %s" % options.testmanifest parser.print_usage() parser.exit() # Set up the logger if os.path.exists(options.logfile): os.remove(options.logfile) logger = mozlog.getLogger("B2G_AUTOMATION", options.logfile) if options.loglevel: logger.setLevel(getattr(mozlog, options.loglevel, "DEBUG")) try: b2gauto = B2GAutomation(options.testmanifest, offline=options.offline) # this is test code d = b2gauto.install_build("http://10.242.30.20/out/qemu_package.tar.gz") b2gauto.run_marionette(d) except: s = traceback.format_exc() logger.error(s) return 1 return 0
def setUp(self): self.logger = mozlog.getLogger('mozprofile.addons') self.logger.setLevel(mozlog.ERROR) self.profile = mozprofile.profile.Profile() self.am = self.profile.addon_manager self.profile_path = self.profile.profile self.tmpdir = tempfile.mkdtemp()
def __init__(self, options, **kwargs): self.options = options self.server = None self.logger = mozlog.getLogger('PEP') # create the profile self.profile = self.profile_class(profile=self.options.profilePath, addons=[os.path.join(here, 'extension')]) # fork a server to serve the test related files if self.options.serverPath: self.runServer() tests = [] # TODO is there a better way of doing this? if self.options.testPath.endswith('.js'): # a single test file was passed in testObj = {} testObj['path'] = os.path.realpath(self.options.testPath) testObj['name'] = os.path.basename(self.options.testPath) tests.append(testObj) else: # a test manifest was passed in # open and convert the manifest to json manifest = TestManifest() manifest.read(self.options.testPath) tests = manifest.get() # create a manifest object to be read by the JS side manifestObj = {} manifestObj['tests'] = tests # write manifest to a JSON file jsonManifest = open(os.path.join(here, 'manifest.json'), 'w') jsonManifest.write(str(manifestObj).replace("'", "\"")) jsonManifest.close() # setup environment env = os.environ.copy() env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1' env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str(options.tracerThreshold) env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval) env['MOZ_CRASHREPORTER_NO_REPORT'] = '1' # construct the browser arguments cmdargs = [] # TODO Make browserArgs a list cmdargs.extend(self.options.browserArgs) cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)]) # run with managed process handler self.runner = self.runner_class(profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess)
def __init__(self, cmd, args=None, cwd=None, env=os.environ.copy(), ignore_children=False, **kwargs): ProcessHandler.__init__(self, cmd, args=args, cwd=cwd, env=env, ignore_children=ignore_children, **kwargs) self.logger = mozlog.getLogger('PEP')
def test_logger_defaults(self): """Tests the default logging format and behavior.""" default_logger = mozlog.getLogger('default.logger') self.assertEqual(default_logger.name, 'default.logger') self.assertEqual(len(default_logger.handlers), 1) self.assertTrue(isinstance(default_logger.handlers[0], mozlog.StreamHandler)) f = mozfile.NamedTemporaryFile() list_logger = mozlog.getLogger('file.logger', handler=mozlog.FileHandler(f.name)) self.assertEqual(len(list_logger.handlers), 1) self.assertTrue(isinstance(list_logger.handlers[0], mozlog.FileHandler)) f.close() self.assertRaises(ValueError, mozlog.getLogger, 'file.logger', handler=ListHandler())
def setUp(self): self.handler = ListHandler() self.handler.setFormatter(mozlog.JSONFormatter()) self.logger = mozlog.getLogger('test.Logger') # Prevents tests from producing output via a default handler. for h in self.logger.handlers: self.logger.removeHandler(h) self.logger.addHandler(self.handler) self.logger.setLevel(mozlog.DEBUG)
def __init__(self, profile, clean_profile=True, process_class=None, kp_kwargs=None, env=None, symbols_path=None): self.clean_profile = clean_profile self.env = env or {} self.kp_kwargs = kp_kwargs or {} self.process_class = process_class or ProcessHandler self.process_handler = None self.returncode = None self.profile = profile self.log = mozlog.getLogger("MozRunner") self.symbols_path = symbols_path
def __init__(self, profile, devicemanager, marionette=None, context_chrome=True, test_script=None, test_script_args=None, marionette_port=None, emulator=None, **kwargs): RemoteRunner.__init__(self, profile, devicemanager, **kwargs) self.log = mozlog.getLogger('B2GRunner') tmpfd, processLog = tempfile.mkstemp(suffix='pidlog') os.close(tmpfd) tmp_env = self.env or {} self.env = { 'MOZ_CRASHREPORTER': '1', 'MOZ_CRASHREPORTER_NO_REPORT': '1', 'MOZ_HIDE_RESULTS_TABLE': '1', 'MOZ_PROCESS_LOG': processLog, 'NSPR_LOG_MODULES': 'signaling:5,mtransport:3', 'R_LOG_LEVEL': '5', 'R_LOG_DESTINATION': 'stderr', 'R_LOG_VERBOSE': '1', 'NO_EM_RESTART': '1', } self.env.update(tmp_env) self.last_test = "automation" self.marionette = marionette if self.marionette is not None: if marionette_port is None: marionette_port = self.marionette.port elif self.marionette.port != marionette_port: raise ValueError( "Got a marionette object and a port but they don't match") if emulator is None: emulator = marionette.emulator elif marionette.emulator != emulator: raise ValueError( "Got a marionette object and an emulator argument but they don't match" ) self.marionette_port = marionette_port self.emulator = emulator self.context_chrome = context_chrome self.test_script = test_script self.test_script_args = test_script_args self.remote_profiles_ini = '/data/b2g/mozilla/profiles.ini' self.bundles_dir = '/system/b2g/distribution/bundles' self.user_js = '/data/local/user.js'
def set_logger(self, logger_instance=None, name=None): """Method for setting the underlying logger instance to be used.""" if logger_instance and not isinstance(logger_instance, mozlog.Logger): raise ValueError("logger_instance must be an instance of" + "mozlog.Logger") if name is None: name = ".".join([self.__module__, self.__class__.__name__]) self._logger = logger_instance or mozlog.getLogger(name)
def __init__(self, profile, clean_profile=True, process_class=None, kp_kwargs=None, env=None, symbols_path=None): self.clean_profile = clean_profile self.env = env or {} self.kp_kwargs = kp_kwargs or {} self.process_class = process_class or ProcessHandler self.process_handler = None self.returncode = None self.profile = profile self.log = mozlog.getLogger('MozRunner') self.symbols_path = symbols_path
def __init__(self, marionette, datazilla_config=None, sources=None, log_level="INFO"): # Set up logging handler = mozlog.StreamHandler() handler.setFormatter(mozlog.MozFormatter(include_timestamp=True)) self.logger = mozlog.getLogger(self.__class__.__name__, handler) self.logger.setLevel(getattr(mozlog, log_level.upper())) self.marionette = marionette settings = gaiatest.GaiaData(self.marionette).all_settings mac_address = self.marionette.execute_script( "return navigator.mozWifiManager && " "navigator.mozWifiManager.macAddress;" ) self.submit_report = True self.ancillary_data = {} self.device = gaiatest.GaiaDevice(self.marionette) dm = mozdevice.DeviceManagerADB() self.device.add_device_manager(dm) version = mozversion.get_version(sources=sources, dm_type="adb") self.ancillary_data["build_revision"] = version.get("build_changeset") self.ancillary_data["gaia_revision"] = version.get("gaia_changeset") self.ancillary_data["gecko_revision"] = version.get("gecko_changeset") self.ancillary_data["ro.build.version.incremental"] = version.get("device_firmware_version_incremental") self.ancillary_data["ro.build.version.release"] = version.get("device_firmware_version_release") self.ancillary_data["ro.build.date.utc"] = version.get("device_firmware_date") self.required = { "gaia revision": self.ancillary_data.get("gaia_revision"), "gecko revision": self.ancillary_data.get("gecko_revision"), "build revision": self.ancillary_data.get("build_revision"), "protocol": datazilla_config["protocol"], "host": datazilla_config["host"], "project": datazilla_config["project"], "branch": datazilla_config["branch"], "oauth key": datazilla_config["oauth_key"], "oauth secret": datazilla_config["oauth_secret"], "machine name": datazilla_config["machine_name"] or mac_address, "device name": datazilla_config["device_name"], "os version": settings.get("deviceinfo.os"), "id": settings.get("deviceinfo.platform_build_id"), } for key, value in self.required.items(): if value: self.logger.debug("DataZilla field: %s (%s)" % (key, value)) if not value: self.submit_report = False self.logger.warn("Missing required DataZilla field: %s" % key) if not self.submit_report: self.logger.info("Reports will not be submitted to DataZilla")
def __init__(self, **kwargs): # Set up the log file or use stdout if none specified self.log = mozlog.getLogger('FIREBUG', kwargs.get('log')) self.log.setLevel(mozlog.DEBUG if kwargs.get('debug') else mozlog.INFO) # Initialization self.binary = kwargs.get('binary') self.profile = kwargs.get('profile') self.serverpath = kwargs.get('serverpath') self.testlist = kwargs.get('testlist') self.couchURI = kwargs.get('couchURI') self.databasename = kwargs.get('databasename') self.section = kwargs.get('section') self.platform = platform.system().lower() # Read in fb-test-runner.config for local configuration localConfig = ConfigParser() localConfig.read(self.LOCAL_CONFIG) if not self.serverpath: self.serverpath = localConfig.get("runner_args", "server") # Ensure serverpath has correct format self.serverpath = self.serverpath.rstrip("/") + "/" # Get the platform independent app directory and version self.appdir, self.appVersion = self.get_app_info() # Read in the Firebug team's config file try: self.download(self.serverpath + self.REMOTE_CONFIG, "test-bot.config") except urllib2.URLError: self.log.error("Could not download test-bot.config, check that '" + self.serverpath + self.REMOTE_CONFIG + "' is valid") self.log.error(traceback.format_exc()) raise self.config = ConfigParser() self.config.read("test-bot.config") # Make sure we have a testlist if not self.testlist: try: self.testlist = self.config.get(self.section, "TEST_LIST") except Exception: self.log.error("No testlist specified in config file") raise if self.config.has_option(self.section, "DB_NAME"): self.databasename = self.config.get(self.section, "DB_NAME") if self.config.has_option(self.section, "DB_URL"): self.couchURI = self.config.get(self.section, "DB_URL")
def __init__(self, logLevel=mozlog.ERROR, deviceRoot=None): try: self._logger = mozlog.structured.structuredlog.get_default_logger(component="mozdevice") if not self._logger: # no global structured logger, fall back to reg logging self._logger = mozlog.getLogger("mozdevice") self._logger.setLevel(logLevel) except AttributeError: # Structured logging doesn't work on Python 2.6 self._logger = None self._logLevel = logLevel self._remoteIsWin = None self._isDeviceRootSetup = False self._deviceRoot = deviceRoot
def __init__(self, logLevel=mozlog.ERROR, deviceRoot=None): try: self._logger = mozlog.structured.structuredlog.get_default_logger(component="DeviceManager") if not self._logger: # no global structured logger, fall back to reg logging self._logger = mozlog.getLogger("DeviceManager") self._logger.setLevel(logLevel) except AttributeError: # Structured logging doesn't work on Python 2.6 self._logger = None self._logLevel = logLevel self._remoteIsWin = None self._isDeviceRootSetup = False self._deviceRoot = deviceRoot
def test_timestamps(self): """Verifies that timestamps are included when asked for.""" log_name = 'test' handler = ListHandler() handler.setFormatter(mozlog.MozFormatter()) log = mozlog.getLogger(log_name, handler=handler) log.info('no timestamp') self.assertTrue(handler.messages[-1].startswith('%s ' % log_name)) handler.setFormatter(mozlog.MozFormatter(include_timestamp=True)) log.info('timestamp') # Just verify that this raises no exceptions. datetime.datetime.strptime(handler.messages[-1][:23], '%Y-%m-%d %H:%M:%S,%f')
def __init__(self, directory, version, platform=None, application='firefox', locale='en-US', extension=None, authentication=None, retry_attempts=0, retry_delay=10., is_stub_installer=False, timeout=None, log_level='INFO', base_url=BASE_URL): # Private properties for caching self._target = None self._binary = None self.directory = directory self.locale = locale self.platform = platform or self.detect_platform() self.version = version self.extension = extension or DEFAULT_FILE_EXTENSIONS[self.platform] self.authentication = authentication self.retry_attempts = retry_attempts self.retry_delay = retry_delay self.is_stub_installer = is_stub_installer self.timeout_download = timeout self.timeout_network = 60. self.logger = mozlog.getLogger(' ') self.logger.setLevel(getattr(mozlog, log_level.upper())) # build the base URL self.application = application self.base_url = urljoin(base_url, self.application) attempt = 0 while True: attempt += 1 try: self.get_build_info() break except (NotFoundError, requests.exceptions.RequestException), e: if self.retry_attempts > 0: # Log only if multiple attempts are requested self.logger.warning("Build not found: '%s'" % e.message) self.logger.info('Will retry in %s seconds...' % (self.retry_delay)) time.sleep(self.retry_delay) self.logger.info("Retrying... (attempt %s)" % attempt) if attempt >= self.retry_attempts: if hasattr(e, 'response') and \ e.response.status_code == 404: message = "Specified build has not been found" raise NotFoundError(message, e.response.url) else: raise
def cli(): parser = OptionParser(usage='%prog [options] <test_file> <test_file> ...') parser.add_option("--binary", action="store", dest="binary", default=None, help="path to B2G desktop build binary") parser.add_option("--profile", action="store", dest="profile", default=None, help="path to gaia profile directory") options, tests = parser.parse_args() if not options.binary or not options.profile: parser.print_usage() parser.exit('--binary and --profile required') if not tests: # build a list of tests appsdir = os.path.join( os.path.dirname(os.path.abspath(options.profile)), 'apps') for root, dirs, files in os.walk(appsdir): for file in files: if file[-8:] == '_test.js': tests.append( os.path.relpath(os.path.join(root, file), appsdir)) runner = GaiaUnitTestRunner(binary=options.binary, profile=options.profile) runner.run() # Lame but necessary hack to prevent tornado's logger from duplicating # every message from mozlog. logger = logging.getLogger() handler = logging.NullHandler() logger.addHandler(handler) print 'starting WebSocket Server' application = tornado.web.Application([ (r"/", TestAgentServer, { 'tests': tests, 'runner': runner, 'logger': mozlog.getLogger('gaia-unit-tests') }), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8789) tornado.ioloop.IOLoop.instance().start()
def __init__(self, test_manifest, offline=False): self.logger = mozlog.getLogger("B2G_AUTOMATION") self.testlist = self.get_test_list(test_manifest) print "Testlist: %s" % self.testlist self.offline = offline pulse = B2GPulseConsumer(applabel="b2g_build_listener") pulse.configure(topic="#", callback=self.on_build) if not offline: pulse.listen() else: t = Thread(target=pulse.listen) t.daemon = True t.start()
def __init__(self, args=sys.argv[1:], debug=False, manifest_path=None, timeout=None, mozlog_level='INFO'): usage = "usage: %prog [options] (binary|folder)" parser = optparse.OptionParser(usage=usage) self.add_options(parser) self.options, self.args = parser.parse_args(args) if len(self.args) != 1: parser.error("Exactly one binary or a folder containing a single " \ " binary has to be specified.") self.binary = self.args[0] self.debug = debug self.timeout = timeout self.manifest_path = manifest_path self.persisted = {} if self.options.workspace: path = os.path.expanduser(self.options.workspace) self.workspace = os.path.abspath(path) if not os.path.exists(self.workspace): os.makedirs(self.workspace) else: self.workspace = tempfile.mkdtemp('.workspace') # default listeners self.listeners = [(self.graphics_event, 'mozmill.graphics')] url = self.options.repository_url if self.options.repository_url \ else MOZMILL_TESTS_REPOSITORIES[self.options.application] self.repository = repository.MercurialRepository(url) self.addon_list = [] self.downloaded_addons = [] self.preferences = {} self.testrun_index = 0 self.last_failed_tests = None self.exception_type = None self.exception = None self.tb = None self.mozlogger = mozlog.getLogger('') self.mozlogger.setLevel(getattr(mozlog, mozlog_level.upper()))
def __init__(self, args=sys.argv[1:], debug=False, manifest_path=None, timeout=None, mozlog_level='INFO'): usage = "usage: %prog [options] (binary|folder)" parser = optparse.OptionParser(usage=usage) self.add_options(parser) self.options, self.args = parser.parse_args(args) if len(self.args) != 1: parser.error("Exactly one binary or a folder containing a single " \ " binary has to be specified.") self.binary = self.args[0] self.debug = debug self.timeout = timeout self.manifest_path = manifest_path self.persisted = {} if self.options.workspace: path = os.path.expanduser(self.options.workspace) self.workspace = os.path.abspath(path) if not os.path.exists(self.workspace): os.makedirs(self.workspace) else: self.workspace = tempfile.mkdtemp('.workspace') # default listeners self.listeners = [(self.graphics_event, 'mozmill.graphics')] url = self.options.repository_url if self.options.repository_url \ else MOZMILL_TESTS_REPOSITORIES[self.options.application] self.repository = repository.MercurialRepository(url) self.addon_list = [] self.downloaded_addons = [] self.preferences = {} self.testrun_index = 0 self.last_failed_tests = None self.exception_type = None self.exception = None self.tb = None self.mozlogger = mozlog.getLogger('mozmill-automation') self.mozlogger.setLevel(getattr(mozlog, mozlog_level.upper()))
def __init__(self, profile, devicemanager, clean_profile=None, process_class=None, env=None, remote_test_root=None, restore=True): super(RemoteRunner, self).__init__(profile, clean_profile=clean_profile, process_class=process_class, env=env) self.log = mozlog.getLogger('RemoteRunner') self.dm = devicemanager self.remote_test_root = remote_test_root or self.dm.getDeviceRoot() self.remote_profile = posixpath.join(self.remote_test_root, 'profile') self.restore = restore self.backup_files = set([])
def __init__(self, profile, devicemanager, marionette=None, context_chrome=True, test_script=None, test_script_args=None, marionette_port=None, emulator=None, **kwargs): remote_test_root = kwargs.get('remote_test_root') if not remote_test_root: kwargs['remote_test_root'] = '/data/local' RemoteRunner.__init__(self, profile, devicemanager, **kwargs) self.log = mozlog.getLogger('B2GRunner') tmpfd, processLog = tempfile.mkstemp(suffix='pidlog') os.close(tmpfd) tmp_env = self.env or {} self.env = { 'MOZ_CRASHREPORTER': '1', 'MOZ_CRASHREPORTER_NO_REPORT': '1', 'MOZ_HIDE_RESULTS_TABLE': '1', 'MOZ_PROCESS_LOG': processLog, 'NSPR_LOG_MODULES': 'signaling:5,mtransport:3', 'R_LOG_LEVEL': '5', 'R_LOG_DESTINATION': 'stderr', 'R_LOG_VERBOSE': '1', 'NO_EM_RESTART': '1', } self.env.update(tmp_env) self.last_test = "automation" self.marionette = marionette if self.marionette is not None: if marionette_port is None: marionette_port = self.marionette.port elif self.marionette.port != marionette_port: raise ValueError("Got a marionette object and a port but they don't match") if emulator is None: emulator = marionette.emulator elif marionette.emulator != emulator: raise ValueError("Got a marionette object and an emulator argument but they don't match") self.marionette_port = marionette_port self.emulator = emulator self.context_chrome = context_chrome self.test_script = test_script self.test_script_args = test_script_args self.remote_profiles_ini = '/data/b2g/mozilla/profiles.ini' self.bundles_dir = '/system/b2g/distribution/bundles'
def __init__(self, cmd, args=None, cwd=None, env=os.environ.copy(), ignore_children=False, **kwargs): ProcessHandler.__init__(self, cmd, args=args, cwd=cwd, env=env, ignore_children=ignore_children, **kwargs) self.logger = mozlog.getLogger('PEP') results.fails[str(None)] = []
def setUp(self): """Starts server that lists all files in the directory""" self.logger = mozlog.getLogger(self.__class__.__name__) self.logger.setLevel('INFO') self.httpd = mozhttpd.MozHttpd(port=8080, docroot=HERE, urlhandlers=[{'method': 'GET', 'path': '/api/resources/([^/]+)/?', 'function': resource_get}]) self.logger.debug("Serving '%s' at %s:%s" % (self.httpd.docroot, self.httpd.host, self.httpd.port)) self.httpd.start(block=False) self.server_address = "http://%s:%s" % (self.httpd.host, self.httpd.port) self.wdir = urljoin(self.server_address, WDIR) # Create a temporary directory for potential downloads self.temp_dir = tempfile.mkdtemp()
def __init__(self, **kwargs): # Set up the log file or use stdout if none specified self.log = mozlog.getLogger('FIREBUG', kwargs.get('log')) self.log.setLevel(mozlog.DEBUG if kwargs.get('debug') else mozlog.INFO) # Initialization self.binary = kwargs.get("binary") self.profile = kwargs.get("profile") self.serverpath = kwargs.get("serverpath") self.couchURI = kwargs.get("couchURI") self.databasename = kwargs.get("databasename") self.testlist = kwargs.get("testlist") self.waitTime = kwargs.get("waitTime") self.debug = kwargs.get("debug") self.platform = platform.system().lower() self.tempdir = tempfile.gettempdir(); # Temporary directory to store tinderbox builds and temporary profiles self.serverpath = self.serverpath.rstrip("/") + "/" # Ensure serverpath has correct format self.changeset = {} # Map to keep track of the last changeset of each build that was run (to prevent running twice on the same changeset)
def setUp(self): """Starts server that lists all files in the directory""" self.logger = mozlog.getLogger(self.__class__.__name__) self.logger.setLevel('ERROR') self.httpd = mozhttpd.MozHttpd(port=8080, docroot=HERE, urlhandlers=[{ 'method': 'GET', 'path': '/api/resources/([^/]+)/?', 'function': resource_get }]) self.logger.debug( "Serving '%s' at %s:%s" % (self.httpd.docroot, self.httpd.host, self.httpd.port)) self.httpd.start(block=False) self.server_address = "http://%s:%s" % (self.httpd.host, self.httpd.port) self.wdir = urljoin(self.server_address, WDIR) # Create a temporary directory for potential downloads self.temp_dir = tempfile.mkdtemp()
def __init__(self, profile, devicemanager, clean_profile=None, process_class=None, env=None, remote_test_root=None, restore=True, **kwargs): Runner.__init__(self, profile, clean_profile=clean_profile, process_class=process_class, env=env, **kwargs) self.log = mozlog.getLogger('RemoteRunner') self.dm = devicemanager self.last_test = None self.remote_test_root = remote_test_root or self.dm.getDeviceRoot() self.log.info('using %s as test_root' % self.remote_test_root) self.remote_profile = posixpath.join(self.remote_test_root, 'profile') self.restore = restore self.added_files = set() self.backup_files = set()
def __init__(self, **kwargs): # Set up the log file or use stdout if none specified self.log = mozlog.getLogger('FIREBUG', kwargs.get('log')) self.log.setLevel(mozlog.DEBUG if kwargs.get('debug') else mozlog.INFO) # Initialization self.binary = kwargs.get("binary") self.profile = kwargs.get("profile") self.serverpath = kwargs.get("serverpath") self.couchURI = kwargs.get("couchURI") self.databasename = kwargs.get("databasename") self.testlist = kwargs.get("testlist") self.waitTime = kwargs.get("waitTime") self.debug = kwargs.get("debug") self.platform = platform.system().lower() self.tempdir = tempfile.gettempdir() # Temporary directory to store tinderbox builds and temporary profiles self.serverpath = self.serverpath.rstrip( "/") + "/" # Ensure serverpath has correct format self.changeset = { } # Map to keep track of the last changeset of each build that was run (to prevent running twice on the same changeset)
def main(argv=sys.argv[1:]): # Parse command line parser = optparse.OptionParser("%prog [options]") parser.add_option("-d", "--document-root", dest="serverpath", default="/var/www", help="Path to the Apache2 document root Firebug directory") parser.add_option("--repo", dest="repo", default=os.path.join(os.getcwd(), "files"), help="Location to create or update the local FBTest repository") parser.add_option("-i", "--interval", dest="waitTime", help="The number of hours to wait between checking for updates") parser.add_option("--debug", dest="debug", action="store_true", help="Enables debug logging") (opt, remainder) = parser.parse_args(argv) if not os.path.exists(opt.repo): os.mkdir(opt.repo) updater = FBUpdater(repo=opt.repo, serverpath=opt.serverpath, debug=opt.debug) log = mozlog.getLogger("FB_UPDATE") while (1): try: updater.update() except Exception as e: log.error(traceback.format_exc()) if opt.waitTime != None: log.info("Sleeping for %s hour%s" % (opt.waitTime, "s" if int(opt.waitTime) > 1 else "")) time.sleep(int(opt.waitTime) * 3600) else: break; mozlog.shutdown()
class CaptureServer(object): start_capture_called = False end_capture_called = False input_called = False logger = mozlog.getLogger('CaptureServer') def __init__(self, test): self.test = test @mozhttpd.handlers.json_response def start_capture(self, request): self.logger.info("Received start capture callback from test") assert not self.start_capture_called self.start_capture_called = True self.test.start_capture() return (200, {'capturing': True}) @mozhttpd.handlers.json_response def end_capture(self, request): self.logger.info("Received end capture callback from test") assert not self.end_capture_called self.end_capture_called = True self.test.end_capture() return (200, {'capturing': False}) @mozhttpd.handlers.json_response def input(self, request): commandset = urlparse.parse_qs(request.body)['commands'][0] self.logger.info("Received input callback from test") assert not self.input_called self.input_called = True self.test.input_actions(commandset) return (200, {})
def check_for_crashes(dump_directory, symbols_path, stackwalk_binary=None, dump_save_path=None, test_name=None, quiet=False): """ Print a stack trace for minidump files left behind by a crashing program. `dump_directory` will be searched for minidump files. Any minidump files found will have `stackwalk_binary` executed on them, with `symbols_path` passed as an extra argument. `stackwalk_binary` should be a path to the minidump_stackwalk binary. If `stackwalk_binary` is not set, the MINIDUMP_STACKWALK environment variable will be checked and its value used if it is not empty. `symbols_path` should be a path to a directory containing symbols to use for dump processing. This can either be a path to a directory containing Breakpad-format symbols, or a URL to a zip file containing a set of symbols. If `dump_save_path` is set, it should be a path to a directory in which to copy minidump files for safekeeping after a stack trace has been printed. If not set, the environment variable MINIDUMP_SAVE_PATH will be checked and its value used if it is not empty. If `test_name` is set it will be used as the test name in log output. If not set the filename of the calling function will be used. If `quiet` is set, no PROCESS-CRASH message will be printed to stdout if a crash is detected. Returns True if any minidumps were found, False otherwise. """ dumps = glob.glob(os.path.join(dump_directory, '*.dmp')) if not dumps: return False if stackwalk_binary is None: stackwalk_binary = os.environ.get('MINIDUMP_STACKWALK', None) # try to get the caller's filename if no test name is given if test_name is None: try: test_name = os.path.basename(sys._getframe(1).f_code.co_filename) except: test_name = "unknown" try: log = mozlog.getLogger('mozcrash') remove_symbols = False # If our symbols are at a remote URL, download them now # We want to download URLs like http://... but not Windows paths like c:\... if symbols_path and mozfile.is_url(symbols_path): log.info("Downloading symbols from: %s", symbols_path) remove_symbols = True # Get the symbols and write them to a temporary zipfile data = urllib2.urlopen(symbols_path) symbols_file = tempfile.TemporaryFile() symbols_file.write(data.read()) # extract symbols to a temporary directory (which we'll delete after # processing all crashes) symbols_path = tempfile.mkdtemp() zfile = zipfile.ZipFile(symbols_file, 'r') mozfile.extract_zip(zfile, symbols_path) zfile.close() for d in dumps: extra = os.path.splitext(d)[0] + '.extra' stackwalk_output = [] stackwalk_output.append("Crash dump filename: " + d) top_frame = None if symbols_path and stackwalk_binary and os.path.exists(stackwalk_binary): # run minidump_stackwalk p = subprocess.Popen([stackwalk_binary, d, symbols_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = p.communicate() if len(out) > 3: # minidump_stackwalk is chatty, # so ignore stderr when it succeeds. stackwalk_output.append(out) # The top frame of the crash is always the line after "Thread N (crashed)" # Examples: # 0 libc.so + 0xa888 # 0 libnss3.so!nssCertificate_Destroy [certificate.c : 102 + 0x0] # 0 mozjs.dll!js::GlobalObject::getDebuggers() [GlobalObject.cpp:89df18f9b6da : 580 + 0x0] # 0 libxul.so!void js::gc::MarkInternal<JSObject>(JSTracer*, JSObject**) [Marking.cpp : 92 + 0x28] lines = out.splitlines() for i, line in enumerate(lines): if "(crashed)" in line: match = re.search(r"^ 0 (?:.*!)?(?:void )?([^\[]+)", lines[i+1]) if match: top_frame = "@ %s" % match.group(1).strip() break else: stackwalk_output.append("stderr from minidump_stackwalk:") stackwalk_output.append(err) if p.returncode != 0: stackwalk_output.append("minidump_stackwalk exited with return code %d" % p.returncode) else: if not symbols_path: stackwalk_output.append("No symbols path given, can't process dump.") if not stackwalk_binary: stackwalk_output.append("MINIDUMP_STACKWALK not set, can't process dump.") elif stackwalk_binary and not os.path.exists(stackwalk_binary): stackwalk_output.append("MINIDUMP_STACKWALK binary not found: %s" % stackwalk_binary) if not top_frame: top_frame = "Unknown top frame" if not quiet: print "PROCESS-CRASH | %s | application crashed [%s]" % (test_name, top_frame) print '\n'.join(stackwalk_output) if dump_save_path is None: dump_save_path = os.environ.get('MINIDUMP_SAVE_PATH', None) if dump_save_path: # This code did not previously create the directory, # so there may be a file hanging out with its name. if os.path.isfile(dump_save_path): os.unlink(dump_save_path) if not os.path.isdir(dump_save_path): try: os.makedirs(dump_save_path) except OSError: pass shutil.move(d, dump_save_path) log.info("Saved minidump as %s", os.path.join(dump_save_path, os.path.basename(d))) if os.path.isfile(extra): shutil.move(extra, dump_save_path) log.info("Saved app info as %s", os.path.join(dump_save_path, os.path.basename(extra))) else: mozfile.remove(d) mozfile.remove(extra) finally: if remove_symbols: mozfile.remove(symbols_path) return True
def __init__(self, options, **kwargs): self.options = options self.server = None self.logger = mozlog.getLogger('PEP') # create the profile enable_proxy = False locations = ServerLocations() if self.options.proxyLocations: if not self.options.serverPath: self.logger.warning('Can\'t set up proxy without server path') else: enable_proxy = True for proxyLocation in self.options.proxyLocations: locations.read(proxyLocation, False) locations.add_host(host='127.0.0.1', port=self.options.serverPort, options='primary,privileged') self.profile = self.profile_class( profile=self.options.profilePath, addons=[os.path.join(here, 'extension')], locations=locations, proxy=enable_proxy) # fork a server to serve the test related files if self.options.serverPath: self.runServer() tests = [] # TODO is there a better way of doing this? if self.options.testPath.endswith('.js'): # a single test file was passed in testObj = {} testObj['path'] = os.path.realpath(self.options.testPath) testObj['name'] = os.path.basename(self.options.testPath) testObj['here'] = os.path.dirname(testObj['path']) tests.append(testObj) else: # a test manifest was passed in # open and convert the manifest to json manifest = TestManifest() manifest.read(self.options.testPath) tests = manifest.get() # create a manifest object to be read by the JS side manifestObj = {} manifestObj['tests'] = tests manifestObj['options'] = options.__dict__ # write manifest to a JSON file jsonManifest = open(os.path.join(here, 'manifest.json'), 'w') jsonManifest.write(json.dumps(manifestObj)) jsonManifest.close() # setup environment env = os.environ.copy() env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1' env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str( options.tracerThreshold) env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval) env['MOZ_CRASHREPORTER_NO_REPORT'] = '1' # construct the browser arguments cmdargs = [] # TODO Make browserArgs a list cmdargs.extend(self.options.browserArgs) cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)]) # run with managed process handler self.runner = self.runner_class(profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess)
class Test(object): finished_capture = False start_frame = None end_frame = None testlog = TestLog() logger = mozlog.getLogger('Test') def __init__(self, testinfo, options, device, capture_controller, track_start_frame=False, track_end_frame=False): # note: url params for startup tests currently not supported if testinfo.get('urlOverride'): self.testpath_rel = testinfo['urlOverride'] else: self.testpath_rel = testinfo['relpath'] if testinfo.get('urlParams'): self.testpath_rel += "?%s" % urllib.quote_plus( testinfo.get('urlParams')) self.requires_wifi = bool(testinfo.get('requiresWifi')) self.device = device self.capture_controller = capture_controller self.capture_timeout = int(testinfo['captureTimeout']) self.track_start_frame = track_start_frame self.track_end_frame = track_end_frame def cleanup(self): pass def wait(self): # Keep on capturing until we finish or timeout if self.capture_timeout: timeout = int(self.capture_timeout) else: timeout = 100 timer = 0 interval = 0.1 try: while not self.finished_capture and timer < timeout: time.sleep(interval) timer += interval except KeyboardInterrupt: self.end_capture() raise if self.capture_timeout and not self.finished_capture: # this test was meant to time out, ok self.test_finished() self.end_capture() elif not self.finished_capture: # Something weird happened -- we probably didn't get a capture # callback. However, we can still retry the test. self.logger.info("Did not finish test / capture. Error!") self.end_capture() raise TestException("Did not finish test / capture", can_retry=True) def start_capture(self): # callback indicating we should start capturing (if we're not doing so # already) self.logger.info("Start capture") if self.capture_controller and not self.capture_controller.capturing: self.capture_start_time = time.time() self.capture_controller.start_capture() def end_capture(self): # callback indicating we should terminate the capture self.logger.info("Ending capture") self.finished_capture = True if self.capture_controller: self.capture_controller.terminate_capture() def test_started(self): # callback indicating test has started if self.capture_controller and self.track_start_frame: self.start_frame = self.capture_controller.capture_framenum() self.test_start_time = time.time() self.logger.info("Test started callback (framenum: %s)" % self.start_frame) def test_finished(self): # callback indicating test has finished if self.capture_controller and self.track_end_frame: self.end_frame = self.capture_controller.capture_framenum() # we don't need to find the end frame if we're slated to get the # start one... if self.capture_controller.find_start_signal: self.capture_controller.find_end_signal = False self.logger.info("Test finished callback (framenum: %s)" % self.end_frame) def execute_actions(self, actions, test_finished_after_actions=True): self.logger.info("Executing actions") def executeCallback(): self.test_started() actions = self.device.executeCommands(actions, executeCallback=executeCallback) for action in actions: # adjust time to be relative to start of test action['start'] -= self.test_start_time action['end'] -= self.test_start_time self.testlog.actions = actions if test_finished_after_actions: self.test_finished()
def __init__(self, logLevel=mozlog.ERROR): self._logger = mozlog.getLogger("DeviceManager") self._logLevel = logLevel self._logger.setLevel(logLevel)
def __init__(self): self._info = {} self._logger = structured.get_default_logger(component='mozversion') if not self._logger: self._logger = mozlog.getLogger('mozversion')
import os import signal import sys import threading here = os.path.abspath(os.path.dirname(__file__)) from runreftest import RefTest, ReftestOptions from marionette import Marionette from mozprocess import ProcessHandler from mozrunner import FirefoxRunner import mozinfo import mozlog log = mozlog.getLogger('REFTEST') class B2GDesktopReftest(RefTest): marionette = None def __init__(self, marionette_args): RefTest.__init__(self) self.last_test = os.path.basename(__file__) self.marionette_args = marionette_args self.profile = None self.runner = None self.test_script = os.path.join(here, 'b2g_start_script.js') self.timeout = None def run_marionette_script(self):