def setup_marionette_argument_parser(): from marionette_harness.runtests import MarionetteArguments from mozlog.structured import commandline parser = MarionetteArguments() commandline.add_logging_group(parser) return parser
def main(): parser = argparse.ArgumentParser() dsn = config.get('database') parser.add_argument('--dsn', default=dsn, help="Postgresql DSN connection string") commandline.add_logging_group(parser) args = parser.parse_args() logging.basicConfig() logger = commandline.setup_logging('autoland', vars(args), {}) logger.info('starting autoland') dbconn = get_dbconn(args.dsn) last_error_msg = None while True: try: handle_pending_mozreview_pullrequests(logger, dbconn) handle_pending_transplants(logger, dbconn) handle_pending_github_updates(logger, dbconn) handle_pending_mozreview_updates(logger, dbconn) time.sleep(0.25) except KeyboardInterrupt: break except psycopg2.InterfaceError: dbconn = get_dbconn(args.dsn) except: # If things go really badly, we might see the same exception # thousands of times in a row. There's not really any point in # logging it more than once. error_msg = traceback.format_exc() if error_msg != last_error_msg: logger.error(error_msg) last_error_msg = error_msg
def run_marionette(tests, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from marionette.runtests import ( MarionetteTestRunner, BaseMarionetteArguments, MarionetteHarness ) parser = BaseMarionetteArguments() commandline.add_logging_group(parser) if not tests: tests = [os.path.join(topsrcdir, 'testing/marionette/harness/marionette/tests/unit-tests.ini')] args = parser.parse_args(args=tests) args.binary = binary path, exe = os.path.split(args.binary) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run() if failed > 0: return 1 else: return 0
def run_marionette(context, **kwargs): from marionette.runtests import MarionetteTestRunner, MarionetteHarness from mozlog.structured import commandline args = argparse.Namespace(**kwargs) args.binary = args.binary or context.firefox_bin test_root = os.path.join(context.package_root, "marionette", "tests") if not args.tests: args.tests = [ os.path.join( test_root, "testing", "marionette", "harness", "marionette_harness", "tests", "unit-tests.ini", ) ] normalize = partial(context.normalize_test_path, test_root) args.tests = list(map(normalize, args.tests)) commandline.add_logging_group(parser) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run() return 1 if status else 0
def run_firefox_ui_test(tests, testtype=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from firefox_ui_harness import cli_functional from firefox_ui_harness.arguments import FirefoxUIArguments parser = FirefoxUIArguments() commandline.add_logging_group(parser) if not tests: tests = [ os.path.join( topsrcdir, 'testing/firefox-ui/tests/firefox_ui_tests/manifest.ini') ] args = parser.parse_args(args=tests) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Firefox UI - Functional Tests", args, {"mach": sys.stdout}) failed = cli_functional.mn_cli(cli_functional.FirefoxUITestRunner, args=args) if failed > 0: return 1 else: return 0
def run_external_media_test(tests, testtype=None, topsrcdir=None, **kwargs): from external_media_harness.runtests import ( FirefoxMediaHarness, MediaTestArguments, MediaTestRunner, mn_cli, ) from mozlog.structured import commandline parser = MediaTestArguments() commandline.add_logging_group(parser) if not tests: tests = [os.path.join(topsrcdir, 'dom/media/test/external/external_media_tests/manifest.ini')] args = parser.parse_args(args=tests) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Firefox External Media Tests", args, {"mach": sys.stdout}) failed = mn_cli(MediaTestRunner, MediaTestArguments, FirefoxMediaHarness, args=args) if failed > 0: return 1 else: return 0
def run_session(tests, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from marionette.runtests import MarionetteHarness from session.runtests import SessionTestRunner, BaseSessionArguments, SessionArguments, SessionTestCase parser = BaseSessionArguments() commandline.add_logging_group(parser) if not tests: tests = [os.path.join(topsrcdir, "testing/marionette/harness/session/tests/unit-tests.ini")] args = parser.parse_args(args=tests) args.binary = binary for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Session Unit Tests", args, {"mach": sys.stdout}) failed = MarionetteHarness( runner_class=SessionTestRunner, parser_class=SessionArguments, testcase_class=SessionTestCase, args=vars(args) ).run() if failed > 0: return 1 else: return 0
def test_setup_logging_optparse(self): parser = optparse.OptionParser() commandline.add_logging_group(parser) args, _ = parser.parse_args(["--log-raw=-"]) logger = commandline.setup_logging("test_optparse", args, {}) self.assertEqual(len(logger.handlers), 1) self.assertIsInstance(logger.handlers[0], handlers.StreamHandler)
def create_parser_update(): from mozlog.structured import commandline parser = argparse.ArgumentParser("web-platform-tests-update", description="Update script for web-platform-tests tests.") parser.add_argument("--config", action="store", type=abs_path, help="Path to config file") parser.add_argument("--metadata", action="store", type=abs_path, dest="metadata_root", help="Path to the folder containing test metadata"), parser.add_argument("--tests", action="store", type=abs_path, dest="tests_root", help="Path to web-platform-tests"), parser.add_argument("--sync-path", action="store", type=abs_path, help="Path to store git checkout of web-platform-tests during update"), parser.add_argument("--remote_url", action="store", help="URL of web-platfrom-tests repository to sync against"), parser.add_argument("--branch", action="store", type=abs_path, help="Remote branch to sync against") parser.add_argument("--rev", action="store", help="Revision to sync to") parser.add_argument("--no-patch", action="store_true", help="Don't create an mq patch or git commit containing the changes.") parser.add_argument("--sync", dest="sync", action="store_true", default=False, help="Sync the tests with the latest from upstream") parser.add_argument("--ignore-existing", action="store_true", help="When updating test results only consider results from the logfiles provided, not existing expectations.") parser.add_argument("--continue", action="store_true", help="Continue a previously started run of the update script") parser.add_argument("--abort", action="store_true", help="Clear state from a previous incomplete run of the update script") # Should make this required iff run=logfile parser.add_argument("run_log", nargs="*", type=abs_path, help="Log file from run of tests") commandline.add_logging_group(parser) return parser
def create_parser(): p = argparse.ArgumentParser() p.add_argument("--check-clean", action="store_true", help="Check that updating the manifest doesn't lead to any changes") commandline.add_logging_group(p) return p
def cli(args=sys.argv[1:]): worker_map = { 'rq': rq_worker, 'sqs': busy_wait_worker, 'mongo': burst_worker, } parser = argparse.ArgumentParser() parser.add_argument('queue', choices=worker_map.keys(), help='The work queue the workers should grab jobs from.') parser.add_argument('-j', dest='num_workers', type=int, default=1, help='The number of worker processes to spawn.') # setup logging args commandline.log_formatters = { k: v for k, v in commandline.log_formatters.iteritems() if k in ('raw', 'mach') } commandline.add_logging_group(parser) args = vars(parser.parse_args(args)) commandline.setup_logging("catalog-worker", args) qname = args['queue'] process_class = Process if qname == 'rq': process_class = Thread for _ in range(args['num_workers']): worker = process_class(target=worker_map[qname], args=(qname,)) worker.start()
def create_parser_tests(): from marionette_harness.runtests import MarionetteArguments from mozlog.structured import commandline parser = MarionetteArguments() commandline.add_logging_group(parser) return parser
def create_parser(): p = argparse.ArgumentParser() p.add_argument("--rebuild", action="store_true", help="Rebuild manifest from scratch") download_group = p.add_mutually_exclusive_group() download_group.add_argument( "--download", dest="download", action="store_true", default=None, help="Always download even if the local manifest is recent") download_group.add_argument( "--no-download", dest="download", action="store_false", help="Don't try to download the manifest") p.add_argument( "--no-update", action="store_false", dest="update", default=True, help="Just download the manifest, don't update") p.add_argument( "--config", action="store", dest="config_path", default=None, help="Path to wptrunner config file") p.add_argument( "--rewrite-config", action="store_true", default=False, help="Force the local configuration to be regenerated") p.add_argument( "--cache-root", action="store", default=os.path.join(get_state_dir(), "cache", "wpt"), help="Path to use for the metadata cache") commandline.add_logging_group(p) return p
def setup_argument_parser_functional(): from firefox_ui_harness.arguments.base import FirefoxUIArguments from mozlog.structured import commandline parser = FirefoxUIArguments() commandline.add_logging_group(parser) return parser
def run_marionette(tests, binary=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from marionette.runtests import (MarionetteTestRunner, BaseMarionetteArguments, MarionetteHarness) parser = BaseMarionetteArguments() commandline.add_logging_group(parser) if not tests: tests = [ os.path.join( topsrcdir, 'testing/marionette/harness/marionette/tests/unit-tests.ini') ] args = argparse.Namespace(tests=tests) args.binary = binary for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run() if failed > 0: return 1 else: return 0
def run_firefox_ui_test(tests, testtype=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from firefox_ui_harness import cli_functional from firefox_ui_harness.arguments import FirefoxUIArguments parser = FirefoxUIArguments() commandline.add_logging_group(parser) if not tests: tests = [os.path.join(topsrcdir, 'testing/firefox-ui/tests/firefox_ui_tests/manifest.ini')] args = parser.parse_args(args=tests) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Firefox UI - Functional Tests", args, {"mach": sys.stdout}) failed = cli_functional.mn_cli(cli_functional.FirefoxUITestRunner, args=args) if failed > 0: return 1 else: return 0
def run_external_media_test(tests, testtype=None, topsrcdir=None, **kwargs): from external_media_harness.runtests import ( FirefoxMediaHarness, MediaTestArguments, MediaTestRunner, mn_cli, ) from mozlog.structured import commandline parser = MediaTestArguments() commandline.add_logging_group(parser) if not tests: tests = [os.path.join(topsrcdir, 'dom/media/test/external/external_media_tests/manifest.ini')] args = parser.parse_args(args=tests) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Firefox External Media Tests", args, {"mach": sys.stdout}) failed = mn_cli(MediaTestRunner, MediaTestArguments, FirefoxMediaHarness, args=vars(args)) if failed > 0: return 1 else: return 0
def cli(args=sys.argv[1:]): worker_map = { 'sqs': busy_wait_worker, 'mongo': burst_worker, } parser = argparse.ArgumentParser() parser.add_argument( 'queue', choices=worker_map.keys(), help='The work queue the worker should grab jobs from.') # setup logging args commandline.log_formatters = { k: v for k, v in commandline.log_formatters.iteritems() if k in ('raw', 'mach') } commandline.add_logging_group(parser) args = vars(parser.parse_args(args)) global logger logger = commandline.setup_logging("catalog-worker", args) qname = args['queue'] logger.info("Starting a '{}' worker".format(qname)) logger.info("Using '{}' as the storage backend".format( settings['datastore'])) q = all_queues[qname]() return worker_map[qname](q)
def run_marionette(context, **kwargs): from marionette.runtests import (MarionetteTestRunner, MarionetteHarness) from mozlog.structured import commandline args = argparse.Namespace(**kwargs) args.binary = args.binary or context.firefox_bin args.e10s = context.mozharness_config.get('e10s', args.e10s) test_root = os.path.join(context.package_root, 'marionette', 'tests') if not args.tests: args.tests = [ os.path.join(test_root, 'testing', 'marionette', 'harness', 'marionette', 'tests', 'unit-tests.ini') ] normalize = partial(context.normalize_test_path, test_root) args.tests = map(normalize, args.tests) commandline.add_logging_group(parser) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run() return 1 if status else 0
def main(): parser = argparse.ArgumentParser() dsn = 'dbname=autoland user=autoland host=localhost password=autoland' parser.add_argument('--dsn', default=dsn, help="Postgresql DSN connection string") commandline.add_logging_group(parser) args = parser.parse_args() logging.basicConfig() logger = commandline.setup_logging('autoland', vars(args), {}) logger.info('starting autoland') auth = selfserve.read_credentials() if auth is None: logger.critical('could not read selfserve credentials. aborting') return dbconn = psycopg2.connect(args.dsn) # this should exceed the stable delay in buildapi stable_delay = datetime.timedelta(minutes=5) old_job = datetime.timedelta(minutes=30) while True: try: cursor = dbconn.cursor() now = datetime.datetime.now() # handle potentially finished autoland jobs query = """select tree,revision from Autoland where pending=0 and running=0 and last_updated<=%(time)s and can_be_landed is null""" cursor.execute(query, ({'time': now - stable_delay})) for row in cursor.fetchall(): tree, rev = row handle_autoland_request(logger, auth, dbconn, tree, rev) # we also look for any older jobs - maybe something got missed # in pulse query = """select tree,revision from Autoland where last_updated<=%(time)s and can_be_landed is null""" cursor.execute(query, ({'time': now - old_job})) for row in cursor.fetchall(): tree, rev = row handle_autoland_request(logger, auth, dbconn, tree, rev) # handle_pending_bugzilla_comments(logger, dbconn) # handle_pending_transplants(logger, dbconn) time.sleep(30) except KeyboardInterrupt: break except: t, v, tb = sys.exc_info() logger.error('\n'.join(traceback.format_exception(t, v, tb)))
def run_marionette(context, **kwargs): from marionette.runtests import ( MarionetteTestRunner, MarionetteHarness ) from mozlog.structured import commandline args = argparse.Namespace(**kwargs) if not args.binary: args.binary = context.find_firefox() test_root = os.path.join(context.package_root, 'marionette', 'tests') if not args.tests: args.tests = [os.path.join(test_root, 'testing', 'marionette', 'harness', 'marionette', 'tests', 'unit-tests.ini')] normalize = partial(context.normalize_test_path, test_root) args.tests = map(normalize, args.tests) commandline.add_logging_group(parser) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run() return 1 if status else 0
def create_parser(): p = argparse.ArgumentParser() p.add_argument("--rebuild", action="store_true", help="Rebuild the manifest from scratch") commandline.add_logging_group(p) return p
def cli(): global webapi_results global webapi_results_embed_app parser = argparse.ArgumentParser() parser.add_argument("--version", help="version of FxOS under test", default="1.3", action="store") parser.add_argument("--debug", help="enable debug logging", action="store_true") parser.add_argument("--list-test-groups", help="print test groups available to run", action="store_true") parser.add_argument("--include", metavar="TEST-GROUP", help="include this test group", action="append") parser.add_argument("--result-file", help="absolute file path to store the resulting json." \ "Defaults to results.json on your current path", action="store") parser.add_argument("--generate-reference", help="Generate expected result files", action="store_true") commandline.add_logging_group(parser) args = parser.parse_args() test_groups = [ 'omni-analyzer', 'permissions', 'webapi', ] if args.list_test_groups: for t in test_groups: print t return 0 test_groups = set(args.include if args.include else test_groups) report = {'buildprops': {}} logging.basicConfig() if not args.debug: logging.disable(logging.ERROR) logger = commandline.setup_logging("certsuite", vars(args), {}) # Step 1: Get device information try: dm = mozdevice.DeviceManagerADB() except mozdevice.DMError, e: print "Error connecting to device via adb (error: %s). Please be " \ "sure device is connected and 'remote debugging' is enabled." % \ e.msg logger.error("Error connecting to device: %s" % e.msg) sys.exit(1)
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): # Import the harness directly and under a different name here to avoid # "marionette" being importable from two locations when "testing/marionette/client" # is on sys.path. # See bug 1050511 and bug 1114474. This needs to be removed with the # resolution of bug 1109183. clientdir = os.path.join(topsrcdir, 'testing/marionette/client') if clientdir in sys.path: sys.path.remove(clientdir) path = os.path.join(topsrcdir, 'testing/marionette/client/marionette/runtests.py') with open(path, 'r') as fh: imp.load_module('marionetteharness', fh, path, ('.py', 'r', imp.PY_SOURCE)) from marionetteharness import (MarionetteTestRunner, BaseMarionetteOptions, startTestRunner) parser = BaseMarionetteOptions() commandline.add_logging_group(parser) options, args = parser.parse_args() if not tests: tests = [ os.path.join( topsrcdir, 'testing/marionette/client/marionette/tests/unit-tests.ini') ] if b2g_path: options.homedir = b2g_path if emulator: options.emulator = emulator else: options.binary = binary path, exe = os.path.split(options.binary) for k, v in kwargs.iteritems(): setattr(options, k, v) parser.verify_usage(options, tests) options.logger = commandline.setup_logging("Marionette Unit Tests", options, {"mach": sys.stdout}) runner = startTestRunner(MarionetteTestRunner, options, tests) if runner.failed > 0: return 1 return 0
def main(): parser = argparse.ArgumentParser( description="Runner for guided Web API tests.") parser.add_argument("-l", "--list-test-groups", action="store_true", help="List all logical test groups") parser.add_argument("-a", "--list-all-tests", action="store_true", help="List all tests") parser.add_argument( "-i", "--include", metavar="GROUP", action="append", default=[], help="Only include specified group(s) in run, include several " "groups by repeating flag") parser.add_argument( "-n", "--no-browser", action="store_true", help="Don't start a browser but wait for manual connection") parser.add_argument("-v", dest="verbose", action="store_true", help="Verbose output") commandline.add_logging_group(parser) args = parser.parse_args(sys.argv[1:]) logger = commandline.setup_logging("webapi", vars(args), {"raw": sys.stdout}) if args.list_test_groups and len(args.include) > 0: print >> sys.stderr("%s: error: cannot list and include test " "groups at the same time" % sys.argv[0]) parser.print_usage() sys.exit(1) testgen = iter_tests(os.path.dirname(__file__)) if args.list_test_groups: for group, _ in testgen: print(group) return 0 elif args.list_all_tests: for group, tests in testgen: for test in tests: print("%s.%s" % (group, test)) return 0 test_loader = semiauto.TestLoader() tests = test_loader.loadTestsFromNames( map(lambda t: "webapi_tests.%s" % t, args.include or [g for g, _ in testgen]), None) results = semiauto.run(tests, logger=logger, spawn_browser=not args.no_browser, verbosity=2 if args.verbose else 1) return 0 if results.wasSuccessful() else 1
def create_parser(): p = argparse.ArgumentParser() p.add_argument("--check-clean", action="store_true", help="Check that updating the manifest doesn't lead to any changes") p.add_argument("--rebuild", action="store_true", help="Rebuild the manifest from scratch") commandline.add_logging_group(p) return p
def get_parser(): prog = "python -m semiauto" indent = " " * len(prog) usage = """\ usage: %s [-h|--help] [-v|--verbose] [-q|--quiet] %s [-f|--failfast] [-c|--catch] [-b|--buffer] %s [TEST...|discover DIRECTORY [-p|--pattern]] TEST can be a list of any number of test modules, classes, and test modules. The magic keyword "discover" can be used to autodetect tests according to various criteria. By default it will start looking recursively for tests in the current working directory (".").\ """ % (prog, indent, indent) parser = argparse.ArgumentParser(usage=usage) parser.add_argument("-n", "--no-browser", action="store_true", dest="no_browser", default=False, help="Don't " "start a browser but wait for manual connection") parser.add_argument("-v", action="store_true", dest="verbose", default=False, help="Verbose output") parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Minimal output") parser.add_argument("--failfast", "-f", action="store_true", dest="failfast", help="Stop on first failure") parser.add_argument("--catch", "-c", action="store_true", help="Catch C-c and display eresults") parser.add_argument("--buffer", "-b", action="store_true", help="Buffer stdout and stderr during test runs") parser.add_argument("--pattern", "-p", dest="pattern", help='Pattern to match tests ("test_*.py" default)') parser.add_argument("tests", nargs="*") commandline.add_logging_group(parser) return parser
def cli(): global logger global webapi_results global webapi_results_embed_app reload(sys) sys.setdefaultencoding('utf-8') parser = argparse.ArgumentParser() parser.add_argument("--version", help="version of FxOS under test", default="2.2", action="store") parser.add_argument("--debug", help="enable debug logging", action="store_true") parser.add_argument("--list-test-groups", help="print test groups available to run", action="store_true") parser.add_argument("--include", metavar="TEST-GROUP", help="include this test group", action="append") parser.add_argument("--result-file", help="absolute file path to store the resulting json." \ "Defaults to results.json on your current path", action="store") parser.add_argument("--html-result-file", help="absolute file path to store the resulting html.", action="store") parser.add_argument("--generate-reference", help="Generate expected result files", action="store_true") parser.add_argument( '-p', "--device-profile", action="store", type=os.path.abspath, help= "specify the device profile file path which could include skipped test case information" ) commandline.add_logging_group(parser) args = parser.parse_args() if not args.debug: logging.disable(logging.ERROR) logger = commandline.setup_logging("certsuite", vars(args), {}) try: _run(args, logger) except: logger.critical(traceback.format_exc()) raise
def test_logging_defaultlevel(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser) args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name]) logger = commandline.setup_logging("test_fmtopts", args, {}) logger.info("INFO message") logger.debug("DEBUG message") logger.error("ERROR message") # The debug level is not logged by default. self.assertEqual(["INFO message", "ERROR message"], self.loglines)
def test_logging_errorlevel(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser) args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=error"]) logger = commandline.setup_logging("test_fmtopts", args, {}) logger.info("INFO message") logger.debug("DEBUG message") logger.error("ERROR message") # Only the error level and above were requested. self.assertEqual(["ERROR message"], self.loglines)
def test_logging_errorlevel(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser) args = parser.parse_args( ["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=error"]) logger = commandline.setup_logging("test_fmtopts", args, {}) logger.info("INFO message") logger.debug("DEBUG message") logger.error("ERROR message") # Only the error level and above were requested. self.assertEqual(["ERROR message"], self.loglines)
def test_logging_debuglevel(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser) args = parser.parse_args( ["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=debug"]) logger = commandline.setup_logging("test_fmtopts", args, {}) logger.info("INFO message") logger.debug("DEBUG message") logger.error("ERROR message") # Requesting a lower log level than default works as expected. self.assertEqual(["INFO message", "DEBUG message", "ERROR message"], self.loglines)
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): # Import the harness directly and under a different name here to avoid # "marionette" being importable from two locations when "testing/marionette/client" # is on sys.path. # See bug 1050511 and bug 1114474. This needs to be removed with the # resolution of bug 1109183. clientdir = os.path.join(topsrcdir, 'testing/marionette/client') if clientdir in sys.path: sys.path.remove(clientdir) path = os.path.join(topsrcdir, 'testing/marionette/client/marionette/runtests.py') with open(path, 'r') as fh: imp.load_module('marionetteharness', fh, path, ('.py', 'r', imp.PY_SOURCE)) from marionetteharness import ( MarionetteTestRunner, BaseMarionetteOptions, startTestRunner ) parser = BaseMarionetteOptions() commandline.add_logging_group(parser) options, args = parser.parse_args() if not tests: tests = [os.path.join(topsrcdir, 'testing/marionette/client/marionette/tests/unit-tests.ini')] if b2g_path: options.homedir = b2g_path if emulator: options.emulator = emulator else: options.binary = binary path, exe = os.path.split(options.binary) for k, v in kwargs.iteritems(): setattr(options, k, v) parser.verify_usage(options, tests) options.logger = commandline.setup_logging("Marionette Unit Tests", options, {"mach": sys.stdout}) runner = startTestRunner(MarionetteTestRunner, options, tests) if runner.failed > 0: return 1 return 0
def test_logging_debuglevel(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser) args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=debug"]) logger = commandline.setup_logging("test_fmtopts", args, {}) logger.info("INFO message") logger.debug("DEBUG message") logger.error("ERROR message") # Requesting a lower log level than default works as expected. self.assertEqual(["INFO message", "DEBUG message", "ERROR message"], self.loglines)
def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('--port', type=int, default=8000, help='Port on which to listen') commandline.add_logging_group(parser) args = parser.parse_args() logging.basicConfig(level=logging.INFO) app.logger.info('starting REST listener on port %d' % args.port) app.run(host="0.0.0.0", port=args.port, debug=False)
def main(): parser = get_parser() commandline.add_logging_group(parser) args = parser.parse_args() logger = commandline.setup_logging("structured-example", args, {"raw": sys.stdout}) runner = TestRunner() try: runner.run() except: logger.critical("Error during test run:\n%s" % traceback.format_exc())
def main(): parser = get_parser() commandline.add_logging_group(parser) args = parser.parse_args() logger = commandline.setup_logging("structured-example", args, {"raw": sys.stdout}) runner = TestRunner(logger) try: runner.run() except: logger.critical("Error during test run:\n%s" % traceback.format_exc())
def cli(): global logger global webapi_results global webapi_results_embed_app reload(sys) sys.setdefaultencoding('utf-8') parser = argparse.ArgumentParser() parser.add_argument("--version", help="version of FxOS under test", default="2.2", action="store") parser.add_argument("--debug", help="enable debug logging", action="store_true") parser.add_argument("--list-test-groups", help="print test groups available to run", action="store_true") parser.add_argument("--include", metavar="TEST-GROUP", help="include this test group", action="append") parser.add_argument("--result-file", help="absolute file path to store the resulting json." \ "Defaults to results.json on your current path", action="store") parser.add_argument("--html-result-file", help="absolute file path to store the resulting html.", action="store") parser.add_argument("--generate-reference", help="Generate expected result files", action="store_true") parser.add_argument('-p', "--device-profile", action="store", type=os.path.abspath, help="specify the device profile file path which could include skipped test case information") commandline.add_logging_group(parser) args = parser.parse_args() if not args.debug: logging.disable(logging.ERROR) logger = commandline.setup_logging("certsuite", vars(args), {}) try: _run(args, logger) except: logger.critical(traceback.format_exc()) raise
def test_limit_formatters(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser, include_formatters=['raw']) other_formatters = [fmt for fmt in commandline.log_formatters if fmt != 'raw'] # check that every formatter except raw is not present for fmt in other_formatters: with self.assertRaises(SystemExit): parser.parse_args(["--log-%s=-" % fmt]) with self.assertRaises(SystemExit): parser.parse_args(["--log-%s-level=error" % fmt]) # raw is still ok args = parser.parse_args(["--log-raw=-"]) logger = commandline.setup_logging("test_setup_logging2", args, {}) self.assertEqual(len(logger.handlers), 1)
def test_limit_formatters(self): parser = argparse.ArgumentParser() commandline.add_logging_group(parser, include_formatters=['raw']) other_formatters = [ fmt for fmt in commandline.log_formatters if fmt != 'raw' ] # check that every formatter except raw is not present for fmt in other_formatters: with self.assertRaises(SystemExit): parser.parse_args(["--log-%s=-" % fmt]) with self.assertRaises(SystemExit): parser.parse_args(["--log-%s-level=error" % fmt]) # raw is still ok args = parser.parse_args(["--log-raw=-"]) logger = commandline.setup_logging("test_setup_logging2", args, {}) self.assertEqual(len(logger.handlers), 1)
def cli(args=sys.argv[1:]): parser = argparse.ArgumentParser() db = parser.add_argument_group('Database') db.add_argument('--db-host', dest='database_host', default=None, help='The machine hosting the database') db.add_argument('--db-port', dest='database_port', default=None, help='The port the database is running behind') db.add_argument('--db-type', dest='database_backend', choices=['elasticsearch'], default='elasticsearch', help='The type of database to use') pulse = parser.add_argument_group('Pulse') pulse.add_argument('--topic', dest='pulse_topic', default='unittest.#', help='The pulse topic to listen on') pulse.add_argument('--durable', dest='pulse_durable', action='store_true', help='If specified, create a durable pulse queue') pulse.add_argument('--user', dest='pulse_user', help='Pulse user to register the queue to') pulse.add_argument('--password', dest='pulse_password', help='The pulse user\'s password') # setup logging args commandline.log_formatters = { k: v for k, v in commandline.log_formatters.iteritems() if k in ('raw', 'mach') } commandline.add_logging_group(parser) args = vars(parser.parse_args(args)) global logger logger = commandline.setup_logging("catalog-listener", args) config.read_runtime_config(os.path.expanduser('~/.catalogrc')) pulse_args = config.pulse pulse_args.update({k[len('pulse_'):]: v for k, v in args.items() if k.startswith('pulse') if v is not None}) listen(pulse_args)
def main(): parser = argparse.ArgumentParser() dsn = config.get('database') parser.add_argument('--dsn', default=dsn, help="Postgresql DSN connection string") commandline.add_logging_group(parser) args = parser.parse_args() logging.basicConfig() logger = commandline.setup_logging('autoland', vars(args), {}) logger.info('starting autoland') dbconn = get_dbconn(args.dsn) last_error_msg = None next_mozreview_update = datetime.datetime.now() while True: try: handle_pending_mozreview_pullrequests(logger, dbconn) handle_pending_transplants(logger, dbconn) handle_pending_github_updates(logger, dbconn) # TODO: In normal configuration, all updates will be posted to the # same MozReview instance, so we don't bother tracking failure to # post for individual urls. In the future, we might need to # support this. if datetime.datetime.now() > next_mozreview_update: ok = handle_pending_mozreview_updates(logger, dbconn) if ok: next_mozreview_update += datetime.timedelta(seconds=1) else: next_mozreview_update += MOZREVIEW_RETRY_DELAY time.sleep(0.1) except KeyboardInterrupt: break except psycopg2.InterfaceError: dbconn = get_dbconn(args.dsn) except: # If things go really badly, we might see the same exception # thousands of times in a row. There's not really any point in # logging it more than once. error_msg = traceback.format_exc() if error_msg != last_error_msg: logger.error(error_msg) last_error_msg = error_msg
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from marionette.runtests import (MarionetteTestRunner, BaseMarionetteArguments, MarionetteHarness) parser = BaseMarionetteArguments() commandline.add_logging_group(parser) args = parser.parse_args() if not tests: tests = [ os.path.join( topsrcdir, 'testing/marionette/client/marionette/tests/unit-tests.ini') ] args.tests = tests if b2g_path: args.homedir = b2g_path if emulator: args.emulator = emulator else: args.binary = binary path, exe = os.path.split(args.binary) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) failed = MarionetteHarness(MarionetteTestRunner, args=args).run() if failed > 0: return 1 else: return 0
def run_session(tests, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from marionette.runtests import (MarionetteHarness) from session.runtests import ( SessionTestRunner, BaseSessionArguments, SessionArguments, SessionTestCase, ) parser = BaseSessionArguments() commandline.add_logging_group(parser) if not tests: tests = [ os.path.join( topsrcdir, 'testing/marionette/harness/session/tests/unit-tests.ini') ] args = parser.parse_args(args=tests) args.binary = binary for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Session Unit Tests", args, {"mach": sys.stdout}) failed = MarionetteHarness(runner_class=SessionTestRunner, parser_class=SessionArguments, testcase_class=SessionTestCase, args=vars(args)).run() if failed > 0: return 1 else: return 0
def main(): parser = argparse.ArgumentParser( description="Runner for guided Web API tests.") parser.add_argument("-l", "--list-test-groups", action="store_true", help="List all logical test groups") parser.add_argument("-a", "--list-all-tests", action="store_true", help="List all tests") parser.add_argument("-i", "--include", metavar="GROUP", action="append", default=[], help="Only include specified group(s) in run, include several " "groups by repeating flag") parser.add_argument("-n", "--no-browser", action="store_true", help="Don't start a browser but wait for manual connection") parser.add_argument("--version", action="store", dest="version", help="B2G version") parser.add_argument( "-v", dest="verbose", action="store_true", help="Verbose output") commandline.add_logging_group(parser) args = parser.parse_args(sys.argv[1:]) logger = commandline.setup_logging( "webapi", vars(args), {"raw": sys.stdout}) if args.list_test_groups and len(args.include) > 0: print >> sys.stderr("%s: error: cannot list and include test " "groups at the same time" % sys.argv[0]) parser.print_usage() sys.exit(1) testgen = iter_tests(os.path.dirname(__file__)) if args.list_test_groups: for group, _ in testgen: print(group) return 0 elif args.list_all_tests: for group, tests in testgen: for test in tests: print("%s.%s" % (group, test)) return 0 test_loader = semiauto.TestLoader(version=args.version) tests = test_loader.loadTestsFromNames( map(lambda t: "webapi_tests.%s" % t, args.include or [g for g, _ in testgen]), None) results = semiauto.run(tests, logger=logger, spawn_browser=not args.no_browser, verbosity=2 if args.verbose else 1) return 0 if results.wasSuccessful() else 1
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from marionette.runtests import (MarionetteTestRunner, BaseMarionetteOptions, startTestRunner) parser = BaseMarionetteOptions() commandline.add_logging_group(parser) options, args = parser.parse_args() if not tests: tests = [ os.path.join( topsrcdir, 'testing/marionette/client/marionette/tests/unit-tests.ini') ] if b2g_path: options.homedir = b2g_path if emulator: options.emulator = emulator else: options.binary = binary path, exe = os.path.split(options.binary) for k, v in kwargs.iteritems(): setattr(options, k, v) parser.verify_usage(options, tests) options.logger = commandline.setup_logging("Marionette Unit Tests", options, {"mach": sys.stdout}) runner = startTestRunner(MarionetteTestRunner, options, tests) if runner.failed > 0: return 1 return 0
def run_firefox_ui_test(tests, testtype=None, binary=None, topsrcdir=None, **kwargs): from marionette.runtests import MarionetteHarness from mozlog.structured import commandline from firefox_ui_harness.cli_functional import FirefoxUITestRunner from firefox_ui_harness.arguments import FirefoxUIArguments parser = FirefoxUIArguments() commandline.add_logging_group(parser) args = parser.parse_args() if not tests: tests = [ os.path.join( topsrcdir, 'testing/firefox-ui/tests/firefox_ui_tests/manifest.ini') ] args.tests = tests args.binary = binary path, exe = os.path.split(args.binary) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Firefox UI - Functional Tests", args, {"mach": sys.stdout}) try: failed = MarionetteHarness(FirefoxUITestRunner, FirefoxUIArguments, args=args).run() if failed > 0: sys.exit(10) except Exception: args.logger.error('Failure during harness setup', exc_info=True) sys.exit(1) sys.exit(0)
def main(): global auth global dbconn global logger parser = argparse.ArgumentParser() dsn = 'dbname=autoland user=autoland host=localhost password=autoland' parser.add_argument('--dsn', default=dsn, help='Postgresql DSN connection string') parser.add_argument('--message-log-path', default=None, help='Path to which to log received messages') commandline.add_logging_group(parser) args = parser.parse_args() logging.basicConfig() logger = commandline.setup_logging('autoland-pulse', vars(args), {}) logger.info('starting pulse listener') while not dbconn: try: dbconn = psycopg2.connect(args.dsn) except psycopg2.OperationalError: time.sleep(0.1) user, password = read_credentials() unique_label = 'autoland-%s' % platform.node() pulse = consumers.BuildConsumer(applabel=unique_label, user=user, password=password) pulse.configure(topic=['build.#.finished'], callback=handle_message) logger.debug('applabel: %s' % unique_label) while True: try: pulse.listen() except amqp.exceptions.ConnectionForced as e: logger.error('pulse error: ' + str(e)) except IOError as e: logger.error('pulse error: ' + str(e))
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from mozlog.structured import commandline from marionette.runtests import ( MarionetteTestRunner, BaseMarionetteArguments, startTestRunner ) parser = BaseMarionetteArguments() commandline.add_logging_group(parser) args = parser.parse_args() if not tests: tests = [os.path.join(topsrcdir, 'testing/marionette/client/marionette/tests/unit-tests.ini')] args.tests = tests if b2g_path: args.homedir = b2g_path if emulator: args.emulator = emulator else: args.binary = binary path, exe = os.path.split(args.binary) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Marionette Unit Tests", args, {"mach": sys.stdout}) runner = startTestRunner(MarionetteTestRunner, args) if runner.failed > 0: return 1 return 0
def get_parser(): prog = "python -m semiauto" indent = " " * len(prog) usage = """\ usage: %s [-h|--help] [-v|--verbose] [-q|--quiet] %s [-f|--failfast] [-c|--catch] [-b|--buffer] %s [TEST...|discover DIRECTORY [-p|--pattern]] TEST can be a list of any number of test modules, classes, and test modules. The magic keyword "discover" can be used to autodetect tests according to various criteria. By default it will start looking recursively for tests in the current working directory (".").\ """ % ( prog, indent, indent, ) parser = argparse.ArgumentParser(usage=usage) parser.add_argument( "-n", "--no-browser", action="store_true", dest="no_browser", default=False, help="Don't " "start a browser but wait for manual connection", ) parser.add_argument("-v", action="store_true", dest="verbose", default=False, help="Verbose output") parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Minimal output") parser.add_argument("--failfast", "-f", action="store_true", dest="failfast", help="Stop on first failure") parser.add_argument("--catch", "-c", action="store_true", help="Catch C-c and display eresults") parser.add_argument("--buffer", "-b", action="store_true", help="Buffer stdout and stderr during test runs") parser.add_argument("--pattern", "-p", dest="pattern", help='Pattern to match tests ("test_*.py" default)') parser.add_argument("tests", nargs="*") commandline.add_logging_group(parser) return parser
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs): from marionette.runtests import ( MarionetteTestRunner, BaseMarionetteOptions, startTestRunner ) parser = BaseMarionetteOptions() commandline.add_logging_group(parser) options, args = parser.parse_args() if not tests: tests = [os.path.join(topsrcdir, 'testing/marionette/client/marionette/tests/unit-tests.ini')] options.type = testtype if b2g_path: options.homedir = b2g_path if emulator: options.emulator = emulator else: options.binary = binary path, exe = os.path.split(options.binary) options.address = address parser.verify_usage(options, tests) options.logger = commandline.setup_logging("Marionette Unit Tests", options, {"mach": sys.stdout}) runner = startTestRunner(MarionetteTestRunner, options, tests) if runner.failed > 0: return 1 return 0
def cli(): parser = argparse.ArgumentParser() parser.add_argument("--no-reboot", help="don't reboot device before running test", action="store_true") parser.add_argument("--version", help="version of FxOS under test", default="1.3", action="store") parser.add_argument("--debug", help="enable debug logging", action="store_true") parser.add_argument("--result-file", help="absolute file path to store the resulting json." \ "Defaults to results.json on your current path", action="store") commandline.add_logging_group(parser) args = parser.parse_args() report = {'buildprops': {}} logging.basicConfig() if not args.debug: logging.disable(logging.ERROR) logger = commandline.setup_logging("certsuite", vars(args), {}) # Step 1: Get device information try: dm = mozdevice.DeviceManagerADB() except mozdevice.DMError, e: print "Error connecting to device via adb (error: %s). Please be " \ "sure device is connected and 'remote debugging' is enabled." % \ e.msg logger.error("Error connecting to device: %s" % e.msg) sys.exit(1)
def run_firefox_ui_test(tests, testtype=None, binary=None, topsrcdir=None, **kwargs): from marionette.runtests import MarionetteHarness from mozlog.structured import commandline from firefox_ui_harness.cli_functional import FirefoxUITestRunner from firefox_ui_harness.arguments import FirefoxUIArguments parser = FirefoxUIArguments() commandline.add_logging_group(parser) args = parser.parse_args() if not tests: tests = [os.path.join(topsrcdir, 'testing/firefox-ui/tests/firefox_ui_tests/manifest.ini')] args.tests = tests args.binary = binary path, exe = os.path.split(args.binary) for k, v in kwargs.iteritems(): setattr(args, k, v) parser.verify_usage(args) args.logger = commandline.setup_logging("Firefox UI - Functional Tests", args, {"mach": sys.stdout}) try: failed = MarionetteHarness(FirefoxUITestRunner, FirefoxUIArguments, args=args).run() if failed > 0: sys.exit(10) except Exception: args.logger.error('Failure during harness setup', exc_info=True) sys.exit(1) sys.exit(0)