Example #1
0
 def kill(self, stagedShutdown = False):
     if self.utilityPath:
         # Take a screenshot to capture the screen state just before
         # the application is killed. There are on-device screenshot
         # options but they rarely work well with Firefox on the
         # Android emulator. dump_screen provides an effective
         # screenshot of the emulator and its host desktop.
         dump_screen(self.utilityPath, get_default_logger())
     if stagedShutdown:
         # Trigger an ANR report with "kill -3" (SIGQUIT)
         self.dm.killProcess(self.procName, 3)
         time.sleep(3)
         # Trigger a breakpad dump with "kill -6" (SIGABRT)
         self.dm.killProcess(self.procName, 6)
         # Wait for process to end
         retries = 0
         while retries < 3:
             pid = self.dm.processExist(self.procName)
             if pid and pid > 0:
                 print "%s still alive after SIGABRT: waiting..." % self.procName
                 time.sleep(5)
             else:
                 return
             retries += 1
         self.dm.killProcess(self.procName, 9)
         pid = self.dm.processExist(self.procName)
         if pid and pid > 0:
             self.dm.killProcess(self.procName)
     else:
         self.dm.killProcess(self.procName)
Example #2
0
    def inner(command, *args, **kwargs):
        global logger

        if logger is None:
            logger = get_default_logger("vcs")

        repo = kwargs.pop("repo", None)
        log_error = kwargs.pop("log_error", True)
        if kwargs:
            raise TypeError, kwargs

        args = list(args)

        proc_kwargs = {}
        if repo is not None:
            proc_kwargs["cwd"] = repo

        command_line = [bin_name, command] + args
        logger.debug(" ".join(command_line))
        try:
            return subprocess.check_output(command_line, stderr=subprocess.STDOUT, **proc_kwargs)
        except subprocess.CalledProcessError as e:
            if log_error:
                logger.error(e.output)
            raise
Example #3
0
    def __init__(self, app_ctx=None, profile=None, clean_profile=True, env=None,
                 process_class=None, process_args=None, symbols_path=None,
                 dump_save_path=None, addons=None):
        self.app_ctx = app_ctx or DefaultContext()

        if isinstance(profile, basestring):
            self.profile = self.app_ctx.profile_class(profile=profile,
                                                      addons=addons)
        else:
            self.profile = profile or self.app_ctx.profile_class(**getattr(self.app_ctx,
                                                                           'profile_args', {}))

        self.logger = get_default_logger()

        # process environment
        if env is None:
            self.env = os.environ.copy()
        else:
            self.env = env.copy()

        self.clean_profile = clean_profile
        self.process_class = process_class or ProcessHandler
        self.process_args = process_args or {}
        self.symbols_path = symbols_path
        self.dump_save_path = dump_save_path

        self.crashed = 0
    def run_tests(self, programs, xre_path, symbols_path=None, interactive=False):
        """
        Run a set of C++ unit test programs.

        Arguments:
        * programs: An iterable containing (test path, test timeout factor) tuples
        * xre_path: A path to a directory containing a XUL Runtime Environment.
        * symbols_path: A path to a directory containing Breakpad-formatted
                        symbol files for producing stack traces on crash.

        Returns True if all test programs exited with a zero status, False
        otherwise.
        """
        self.xre_path = xre_path
        self.log = mozlog.get_default_logger()
        self.log.suite_start(programs)
        env = self.build_environment()
        pass_count = 0
        fail_count = 0
        for prog in programs:
            test_path = prog[0]
            timeout_factor = prog[1]
            single_result = self.run_one_test(test_path, env, symbols_path,
                                              interactive, timeout_factor)
            if single_result:
                pass_count += 1
            else:
                fail_count += 1
        self.log.suite_end()

        # Mozharness-parseable summary formatting.
        self.log.info("Result summary:")
        self.log.info("cppunittests INFO | Passed: %d" % pass_count)
        self.log.info("cppunittests INFO | Failed: %d" % fail_count)
        return fail_count == 0
Example #5
0
    def check_for_crashes(self, dump_directory=None, dump_save_path=None, test_name=None, quiet=False):
        """
        Check for a possible crash and output stack trace.

        :param dump_directory: Directory to search for minidump files
        :param dump_save_path: Directory to save the minidump files to
        :param test_name: Name to use in the crash output
        :param quiet: If `True` don't print the PROCESS-CRASH message to stdout
        :returns: True if a crash was detected, otherwise False
        """
        if not dump_directory:
            dump_directory = os.path.join(self.profile.profile, "minidumps")

        if not dump_save_path:
            dump_save_path = self.dump_save_path

        try:
            logger = get_default_logger()
            if logger is not None:
                if test_name is None:
                    test_name = "runner.py"
                self.crashed += mozcrash.log_crashes(
                    logger, dump_directory, self.symbols_path, dump_save_path=dump_save_path, test=test_name
                )
            else:
                crashed = mozcrash.check_for_crashes(
                    dump_directory, self.symbols_path, dump_save_path=dump_save_path, test_name=test_name, quiet=quiet
                )
                if crashed:
                    self.crashed += 1
        except:
            traceback.print_exc()

        return self.crashed
Example #6
0
    def start(self, debug_args=None, interactive=False, timeout=None, outputTimeout=None):
        """
        Run self.command in the proper environment.

        :param debug_args: arguments for a debugger
        :param interactive: uses subprocess.Popen directly
        :param timeout: see process_handler.run()
        :param outputTimeout: see process_handler.run()
        :returns: the process id
        """
        self.timeout = timeout
        self.output_timeout = outputTimeout
        cmd = self.command

        # ensure the runner is stopped
        self.stop()

        # attach a debugger, if specified
        if debug_args:
            cmd = list(debug_args) + cmd

        logger = get_default_logger()
        if logger:
            logger.info('Application command: %s' % ' '.join(cmd))
        if interactive:
            self.process_handler = subprocess.Popen(cmd, env=self.env)
            # TODO: other arguments
        else:
            # this run uses the managed processhandler
            self.process_handler = self.process_class(cmd, env=self.env, **self.process_args)
            self.process_handler.run(self.timeout, self.output_timeout)

        self.crashed = 0
        return self.process_handler.pid
 def __init__(self, methodName, **kwargs):
     unittest.TestCase.__init__(self, methodName)
     self.loglines = []
     self.duration = 0
     self.start_time = 0
     self.expected = kwargs.pop('expected', 'pass')
     self.logger = get_default_logger()
Example #8
0
def _get_default_logger():
    from mozlog import get_default_logger
    log = get_default_logger(component='mozleak')

    if not log:
        import logging
        log = logging.getLogger(__name__)
    return log
 def kill(self, stagedShutdown=False):
     # Take a screenshot to capture the screen state just before
     # the application is killed.
     if not self.device._device_serial.startswith('emulator-'):
         dump_device_screen(self.device, get_default_logger())
     elif self.utilityPath:
         # Do not use the on-device screenshot options since
         # they rarely work well with Firefox on the Android
         # emulator. dump_screen provides an effective
         # screenshot of the emulator and its host desktop.
         dump_screen(self.utilityPath, get_default_logger())
     if stagedShutdown:
         # Trigger an ANR report with "kill -3" (SIGQUIT)
         try:
             self.device.pkill(self.procName, sig=3, attempts=1)
         except ADBTimeoutError:
             raise
         except:  # NOQA: E722
             pass
         time.sleep(3)
         # Trigger a breakpad dump with "kill -6" (SIGABRT)
         try:
             self.device.pkill(self.procName, sig=6, attempts=1)
         except ADBTimeoutError:
             raise
         except:  # NOQA: E722
             pass
         # Wait for process to end
         retries = 0
         while retries < 3:
             if self.device.process_exist(self.procName):
                 print("%s still alive after SIGABRT: waiting..." % self.procName)
                 time.sleep(5)
             else:
                 return
             retries += 1
         try:
             self.device.pkill(self.procName, sig=9, attempts=1)
         except ADBTimeoutError:
             raise
         except:  # NOQA: E722
             print("%s still alive after SIGKILL!" % self.procName)
         if self.device.process_exist(self.procName):
             self.device.stop_application(self.procName)
     else:
         self.device.stop_application(self.procName)
Example #10
0
 def __init__(self, methodName, **kwargs):
     unittest.TestCase.__init__(self, methodName)
     self.loglines = []
     self.duration = 0
     self.expected = kwargs.pop("expected", "pass")
     self.logger = get_default_logger()
     self.profile = FirefoxProfile()
     self.binary = kwargs.pop("binary", None)
Example #11
0
def test_process_output_enabled(args, enabled):
    do_cli(*args)
    log_filter = get_default_logger("process").component_filter

    result = log_filter({"some": "data"})
    if enabled:
        assert result
    else:
        assert not result
Example #12
0
def log(text, log=True, status_bar=True, status_bar_timeout=2.0):
    if log:
        logger = get_default_logger('mozregui')
        if logger:
            logger.info(text)
    if status_bar:
        from mozregui.mainwindow import MainWindow
        mw = MainWindow.INSTANCE
        if mw:
            mw.ui.status_bar.showMessage(text, int(status_bar_timeout * 1000))
Example #13
0
def test_mozversion_output_filtered(mozversion_msg, shown):
    do_cli()
    log_filter = get_default_logger("mozversion").component_filter
    log_data = {"message": mozversion_msg}

    result = log_filter(log_data)
    if shown:
        assert result == log_data
    else:
        assert not result
Example #14
0
        def gather_media_debug(test, status):
            rv = {}
            marionette = test._marionette_weakref()

            if marionette.session is not None:
                try:
                    with marionette.using_context(marionette.CONTEXT_CHROME):
                        debug_lines = marionette.execute_script(debug_script)
                        if debug_lines:
                            name = 'mozMediaSourceObject.mozDebugReaderData'
                            rv[name] = '\n'.join(debug_lines)
                        else:
                            logger = mozlog.get_default_logger()
                            logger.info('No data available about '
                                        'mozMediaSourceObject')
                except:
                    logger = mozlog.get_default_logger()
                    logger.warning('Failed to gather test failure media debug',
                                   exc_info=True)
            return rv
Example #15
0
    def __init__(self, methodName, marionette_weakref, fixtures, **kwargs):
        super(CommonTestCase, self).__init__(methodName)
        self.methodName = methodName

        self._marionette_weakref = marionette_weakref
        self.fixtures = fixtures

        self.duration = 0
        self.start_time = 0
        self.expected = kwargs.pop('expected', 'pass')
        self.logger = get_default_logger()
Example #16
0
        def gather_debug(test, status):
            rv = {}
            marionette = test._marionette_weakref()

            if marionette.session is not None:
                try:
                    self._add_logging_info(rv, marionette)
                except Exception:
                    logger = get_default_logger()
                    logger.warning("Failed to gather test failure debug.",
                                   exc_info=True)
            return rv
Example #17
0
 def __init__(self, logLevel=None, deviceRoot=None):
     try:
         self._logger = mozlog.get_default_logger(component="mozdevice")
         if not self._logger:  # no global structured logger, fall back to reg logging
             self._logger = mozlog.unstructured.getLogger("mozdevice")
             if logLevel is not None:
                 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
Example #18
0
 def _lint(self, files, linter, **lintargs):
     payload = linter["payload"]
     handler = LintHandler(linter)
     logger = linter.get("logger")
     if logger is None:
         logger = get_default_logger()
     if logger is None:
         logger = structuredlog.StructuredLogger(linter["name"])
         commandline.setup_logging(logger, {}, {"mach": sys.stdout})
     logger.add_handler(handler)
     try:
         payload(files, logger, **lintargs)
     except KeyboardInterrupt:
         pass
     return handler.results
Example #19
0
    def setup_server_logging(self):
        server_logger = get_default_logger(component="wptserve")
        assert server_logger is not None
        log_filter = handlers.LogLevelFilter(lambda x:x, "info")
        # Downgrade errors to warnings for the server
        log_filter = LogLevelRewriter(log_filter, ["error"], "warning")
        server_logger.component_filter = log_filter

        try:
            #Set as the default logger for wptserve
            serve.set_logger(server_logger)
            serve.logger = server_logger
        except Exception:
            # This happens if logging has already been set up for wptserve
            pass
Example #20
0
        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:
                    with marionette.using_context(marionette.CONTEXT_CHROME):
                        rv["screenshot"] = marionette.screenshot()
                    with marionette.using_context(marionette.CONTEXT_CONTENT):
                        rv["source"] = marionette.page_source
                except Exception:
                    logger = get_default_logger()
                    logger.warning("Failed to gather test failure debug.", exc_info=True)
            return rv
Example #21
0
    def _lint(self, files, config, **lintargs):
        handler = LintHandler(config)
        logger = config.get("logger")
        if logger is None:
            logger = get_default_logger()
        if logger is None:
            logger = structuredlog.StructuredLogger(config["name"])
            commandline.setup_logging(logger, {}, {"mach": sys.stdout})
        logger.add_handler(handler)

        func = findobject(config["payload"])
        try:
            func(files, config, logger, **lintargs)
        except KeyboardInterrupt:
            pass
        return handler.results
Example #22
0
    def pytest_configure(self, config):
        args = {}
        formatters = mozlog.commandline.log_formatters.iteritems()
        for name, (_class, _help) in formatters:
            argname = 'log_{0}'.format(name)
            if config.getoption(argname):
                args[argname] = config.getoption(argname)

        formatter_options = mozlog.commandline.fmt_options.iteritems()
        for name, (_class, _help, formatters, action) in formatter_options:
            for formatter in formatters:
                if formatter in mozlog.commandline.log_formatters:
                    argname = 'log_{0}_{1}'.format(formatter, name)
                    if config.getoption(argname):
                        args[argname] = config.getoption(argname)

        mozlog.commandline.setup_logging('pytest', args)
        self.logger = mozlog.get_default_logger(component='pytest')
Example #23
0
 def checkForCrashes(self, directory, symbolsPath):
     crashed = False
     remote_dump_dir = self._remoteProfile + '/minidumps'
     print "checking for crashes in '%s'" % remote_dump_dir
     if self._devicemanager.dirExists(remote_dump_dir):
         local_dump_dir = tempfile.mkdtemp()
         self._devicemanager.getDirectory(remote_dump_dir, local_dump_dir)
         try:
             logger = get_default_logger()
             if logger is not None:
                 crashed = mozcrash.log_crashes(logger, local_dump_dir, symbolsPath, test=self.lastTestSeen)
             else:
                 crashed = mozcrash.check_for_crashes(local_dump_dir, symbolsPath, test_name=self.lastTestSeen)
         except:
             traceback.print_exc()
         finally:
             shutil.rmtree(local_dump_dir)
             self._devicemanager.removeDir(remote_dump_dir)
     return crashed
    def checkForCrashes(self, directory, symbolsPath):
        self.checkForANRs()
        self.checkForTombstones()

        logcat = self._device.get_logcat(
            filter_out_regexps=fennecLogcatFilters)

        javaException = mozcrash.check_for_java_exception(
            logcat, test_name=self.lastTestSeen)
        if javaException:
            return True

        # If crash reporting is disabled (MOZ_CRASHREPORTER!=1), we can't say
        # anything.
        if not self.CRASHREPORTER:
            return False

        try:
            dumpDir = tempfile.mkdtemp()
            remoteCrashDir = posixpath.join(self._remoteProfile, 'minidumps')
            if not self._device.is_dir(remoteCrashDir):
                # If crash reporting is enabled (MOZ_CRASHREPORTER=1), the
                # minidumps directory is automatically created when Fennec
                # (first) starts, so its lack of presence is a hint that
                # something went wrong.
                print("Automation Error: No crash directory (%s) found on remote device" %
                      remoteCrashDir)
                return True
            self._device.pull(remoteCrashDir, dumpDir)

            logger = get_default_logger()
            crashed = mozcrash.log_crashes(
                logger, dumpDir, symbolsPath, test=self.lastTestSeen)

        finally:
            try:
                shutil.rmtree(dumpDir)
            except Exception as e:
                print("WARNING: unable to remove directory %s: %s" % (
                    dumpDir, str(e)))
        return crashed
Example #25
0
    def gather_debug(self):
        debug = {}
        # In the event we're gathering debug without starting a session, skip marionette commands
        if self.marionette.session is not None:
            try:
                self.marionette.set_context(self.marionette.CONTEXT_CHROME)
                debug['screenshot'] = self.marionette.screenshot()
                self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
                debug['source'] = self.marionette.page_source
                self.marionette.switch_to_frame()
                self.marionette.push_permission('settings-read', True)
                self.marionette.push_permission('settings-api-read', True)
                debug['settings'] = json.dumps(self.marionette.execute_async_script("""
var req = window.navigator.mozSettings.createLock().get('*');
req.onsuccess = function() {
  marionetteScriptFinished(req.result);
}""", sandbox='system'), sort_keys=True, indent=4, separators=(',', ': '))
            except:
                logger = get_default_logger()
                logger.warning('Failed to gather test failure debug.', exc_info=True)
        return debug
Example #26
0
    def checkForCrashes(self, directory, symbolsPath):
        self.checkForANRs()
        self.checkForTombstones()

        logcat = self._devicemanager.getLogcat(filterOutRegexps=fennecLogcatFilters)

        javaException = mozcrash.check_for_java_exception(logcat, test_name=self.lastTestSeen)
        if javaException:
            return True

        # If crash reporting is disabled (MOZ_CRASHREPORTER!=1), we can't say
        # anything.
        if not self.CRASHREPORTER:
            return False

        try:
            dumpDir = tempfile.mkdtemp()
            remoteCrashDir = posixpath.join(self._remoteProfile, 'minidumps')
            if not self._devicemanager.dirExists(remoteCrashDir):
                # If crash reporting is enabled (MOZ_CRASHREPORTER=1), the
                # minidumps directory is automatically created when Fennec
                # (first) starts, so its lack of presence is a hint that
                # something went wrong.
                print "Automation Error: No crash directory (%s) found on remote device" % remoteCrashDir
                # Whilst no crash was found, the run should still display as a failure
                return True
            self._devicemanager.getDirectory(remoteCrashDir, dumpDir)

            logger = get_default_logger()
            if logger is not None:
                crashed = mozcrash.log_crashes(logger, dumpDir, symbolsPath, test=self.lastTestSeen)
            else:
                crashed = Automation.checkForCrashes(self, dumpDir, symbolsPath)

        finally:
            try:
                shutil.rmtree(dumpDir)
            except:
                print "WARNING: unable to remove directory: %s" % dumpDir
        return crashed
Example #27
0
    def inner(command, *args, **kwargs):
        global logger

        if logger is None:
            logger = get_default_logger("vcs")

        repo = kwargs.pop("repo", None)
        log_error = kwargs.pop("log_error", True)
        stdout = kwargs.pop("stdout", None)
        stdin = kwargs.pop("stdin", None)
        if kwargs:
            raise TypeError(kwargs)

        args = list(args)

        proc_kwargs = {}
        if repo is not None:
            proc_kwargs["cwd"] = repo
        if stdout is not None:
            proc_kwargs["stdout"] = stdout
        if stdin is not None:
            proc_kwargs["stdin"] = stdin

        command_line = [bin_name, command] + args
        logger.debug(" ".join(command_line))
        try:
            func = subprocess.check_output if not stdout else subprocess.check_call
            return func(command_line, stderr=subprocess.STDOUT, **proc_kwargs)
        except OSError as e:
            if log_error:
                logger.error(e)
            raise
        except subprocess.CalledProcessError as e:
            if log_error:
                logger.error(e.output)
            raise
Example #28
0
    def __init__(self, config):
        self.config = config

        self.log = get_default_logger(component='recorder-mobile-app - ')
        self.profile = self.config['profile']
Example #29
0
 def __init__(self, build_info_fetcher, data):
     self.build_info_fetcher = build_info_fetcher
     self.data = data
     self._build_info = None
     self._logger = get_default_logger('Bisector')
Example #30
0
 def __init__(self):
     self._info = {}
     self._logger = mozlog.get_default_logger(component='mozversion')
     if not self._logger:
         self._logger = mozlog.unstructured.getLogger('mozversion')
Example #31
0
    def __init__(self,
                 app,
                 binary,
                 run_local=False,
                 obj_path=None,
                 gecko_profile=False,
                 gecko_profile_interval=None,
                 gecko_profile_entries=None,
                 symbols_path=None,
                 host=None,
                 power_test=False,
                 memory_test=False,
                 is_release_build=False,
                 debug_mode=False,
                 post_startup_delay=None,
                 interrupt_handler=None,
                 **kwargs):

        # Override the magic --host HOST_IP with the value of the environment variable.
        if host == 'HOST_IP':
            host = os.environ['HOST_IP']

        self.config = {
            'app': app,
            'binary': binary,
            'platform': mozinfo.os,
            'processor': mozinfo.processor,
            'run_local': run_local,
            'obj_path': obj_path,
            'gecko_profile': gecko_profile,
            'gecko_profile_interval': gecko_profile_interval,
            'gecko_profile_entries': gecko_profile_entries,
            'symbols_path': symbols_path,
            'host': host,
            'power_test': power_test,
            'memory_test': memory_test,
            'is_release_build': is_release_build,
            'enable_control_server_wait': memory_test,
        }

        self.raptor_venv = os.path.join(os.getcwd(), 'raptor-venv')
        self.log = get_default_logger(component='raptor-main')
        self.control_server = None
        self.playback = None
        self.benchmark = None
        self.benchmark_port = 0
        self.gecko_profiler = None
        self.post_startup_delay = post_startup_delay
        self.device = None
        self.profile_class = app
        self.firefox_android_apps = FIREFOX_ANDROID_APPS
        self.interrupt_handler = interrupt_handler

        # debug mode is currently only supported when running locally
        self.debug_mode = debug_mode if self.config['run_local'] else False

        # if running debug-mode reduce the pause after browser startup
        if self.debug_mode:
            self.post_startup_delay = min(self.post_startup_delay, 3000)
            self.log.info(
                "debug-mode enabled, reducing post-browser startup pause to %d ms"
                % self.post_startup_delay)

        self.log.info("main raptor init, config is: %s" % str(self.config))

        # create results holder
        self.results_handler = RaptorResultsHandler()
Example #32
0
import os
import urlparse
import re

import webdriver
import mozlog

from tests.support.asserts import assert_error
from tests.support.http_request import HTTPRequest
from tests.support.wait import wait
from tests.support import merge_dictionaries

default_host = "http://127.0.0.1"
default_port = "4444"

logger = mozlog.get_default_logger()


def ignore_exceptions(f):
    def inner(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except webdriver.error.WebDriverException as e:
            logger.warning("Ignored exception %s" % e)

    inner.__name__ = f.__name__
    return inner


@ignore_exceptions
def _ensure_valid_window(session):
Example #33
0
 def __init__(self, *args, **kwargs):
     """Initialize the test case and create a ping server."""
     super(FOGTestCase, self).__init__(*args, **kwargs)
     self._logger = mozlog.get_default_logger(component="FOGTestCase")
Example #34
0
def get_logger():
    structured_logger = mozlog.get_default_logger("mozcrash")
    if structured_logger is None:
        return mozlog.unstructured.getLogger('mozcrash')
    return structured_logger
Example #35
0
import urlparse

import error
import protocol
import transport

from six import string_types

from mozlog import get_default_logger

logger = get_default_logger()


def command(func):
    def inner(self, *args, **kwargs):
        if hasattr(self, "session"):
            session = self.session
        else:
            session = self

        if session.session_id is None:
            session.start()
        assert session.session_id is not None

        return func(self, *args, **kwargs)

    inner.__name__ = func.__name__
    inner.__doc__ = func.__doc__

    return inner
Example #36
0
    def __init__(self,
                 app,
                 binary,
                 run_local=False,
                 obj_path=None,
                 gecko_profile=False,
                 gecko_profile_interval=None,
                 gecko_profile_entries=None,
                 symbols_path=None,
                 host=None,
                 is_release_build=False,
                 debug_mode=False):
        self.config = {}
        self.config['app'] = app
        self.config['binary'] = binary
        self.config['platform'] = mozinfo.os
        self.config['processor'] = mozinfo.processor
        self.config['run_local'] = run_local
        self.config['obj_path'] = obj_path
        self.config['gecko_profile'] = gecko_profile
        self.config['gecko_profile_interval'] = gecko_profile_interval
        self.config['gecko_profile_entries'] = gecko_profile_entries
        self.config['symbols_path'] = symbols_path
        self.config['host'] = host
        self.config['is_release_build'] = is_release_build
        self.raptor_venv = os.path.join(os.getcwd(), 'raptor-venv')
        self.log = get_default_logger(component='raptor-main')
        self.control_server = None
        self.playback = None
        self.benchmark = None
        self.gecko_profiler = None
        self.post_startup_delay = 30000
        self.device = None

        # debug mode is currently only supported when running locally
        self.debug_mode = debug_mode if self.config['run_local'] else False

        # if running debug-mode reduce the pause after browser startup
        if self.debug_mode:
            self.post_startup_delay = 3000
            self.log.info(
                "debug-mode enabled, reducing post-browser startup pause to %d ms"
                % self.post_startup_delay)

        # Create the profile; for geckoview we want a firefox profile type
        if self.config['app'] == 'geckoview':
            self.profile = create_profile('firefox')
        else:
            self.profile = create_profile(self.config['app'])

        # Merge in base profiles
        with open(os.path.join(self.profile_data_dir, 'profiles.json'),
                  'r') as fh:
            base_profiles = json.load(fh)['raptor']

        for name in base_profiles:
            path = os.path.join(self.profile_data_dir, name)
            self.log.info("Merging profile: {}".format(path))
            self.profile.merge(path)

        # add profile dir to our config
        self.config['local_profile_dir'] = self.profile.profile

        # create results holder
        self.results_handler = RaptorResultsHandler()

        # when testing desktop browsers we use mozrunner to start the browser; when
        # testing on android (i.e. geckoview) we use mozdevice to control the device app

        if self.config['app'] == "geckoview":
            # create the android device handler; it gets initiated and sets up adb etc
            self.log.info("creating android device handler using mozdevice")
            self.device = ADBAndroid(verbose=True)
            self.device.clear_logcat()
        else:
            # create the desktop browser runner
            self.log.info("creating browser runner using mozrunner")
            self.output_handler = OutputHandler()
            process_args = {
                'processOutputLine': [self.output_handler],
            }
            runner_cls = runners[app]
            self.runner = runner_cls(binary,
                                     profile=self.profile,
                                     process_args=process_args)

        self.log.info("raptor config: %s" % str(self.config))
Example #37
0
def _get_logger():
    logger = mozlog.get_default_logger(component='moznetwork')
    if not logger:
        logger = mozlog.unstructured.getLogger('moznetwork')
    return logger
Example #38
0
def main(args=sys.argv[1:]):
    args = parse_args()
    commandline.setup_logging('raptor', args, {'tbpl': sys.stdout})
    LOG = get_default_logger(component='raptor-main')

    LOG.info("raptor-start")
    LOG.info("received command line arguments: %s" % str(args))

    # if a test name specified on command line, and it exists, just run that one
    # otherwise run all available raptor tests that are found for this browser
    raptor_test_list = get_raptor_test_list(args, mozinfo.os)

    # ensure we have at least one valid test to run
    if len(raptor_test_list) == 0:
        LOG.critical("abort: no tests found")
        sys.exit(1)

    LOG.info("raptor tests scheduled to run:")
    for next_test in raptor_test_list:
        LOG.info(next_test['name'])

    raptor = Raptor(args.app,
                    args.binary,
                    args.run_local,
                    args.obj_path,
                    args.gecko_profile,
                    args.gecko_profile_interval,
                    args.gecko_profile_entries,
                    args.symbols_path)

    raptor.start_control_server()

    for next_test in raptor_test_list:
        if 'page_timeout' not in next_test.keys():
            next_test['page_timeout'] = 120000
        if 'page_cycles' not in next_test.keys():
            next_test['page_cycles'] = 1

        raptor.run_test(next_test, timeout=int(next_test['page_timeout']))

    success = raptor.process_results()
    raptor.clean_up()

    if not success:
        # didn't get test results; test timed out or crashed, etc. we want job to fail
        LOG.critical("TEST-UNEXPECTED-FAIL: no raptor test results were found")
        os.sys.exit(1)

    # if we have results but one test page timed out (i.e. one tp6 test page didn't load
    # but others did) we still dumped PERFHERDER_DATA for the successfull pages but we
    # want the overall test job to marked as a failure
    pages_that_timed_out = raptor.get_page_timeout_list()
    if len(pages_that_timed_out) > 0:
        for _page in pages_that_timed_out:
            LOG.critical("TEST-UNEXPECTED-FAIL: test '%s' timed out loading test page: %s"
                         % (_page['test_name'], _page['url']))
        os.sys.exit(1)

    # when running raptor locally with gecko profiling on, use the view-gecko-profile
    # tool to automatically load the latest gecko profile in perf-html.io
    if args.gecko_profile and args.run_local:
        if os.environ.get('DISABLE_PROFILE_LAUNCH', '0') == '1':
            LOG.info("Not launching perf-html.io because DISABLE_PROFILE_LAUNCH=1")
        else:
            view_gecko_profile(args.binary)
Example #39
0
 def __init__(self):
     self._info = {}
     self._logger = mozlog.get_default_logger(component="mozversion")
     if not self._logger:
         self._logger = mozlog.unstructured.getLogger("mozversion")
Example #40
0
def main(args=sys.argv[1:]):
    args = parse_args()
    commandline.setup_logging('raptor', args, {'tbpl': sys.stdout})
    LOG = get_default_logger(component='raptor-main')

    LOG.info("raptor-start")

    if args.debug_mode:
        LOG.info("debug-mode enabled")

    LOG.info("received command line arguments: %s" % str(args))

    # if a test name specified on command line, and it exists, just run that one
    # otherwise run all available raptor tests that are found for this browser
    raptor_test_list = get_raptor_test_list(args, mozinfo.os)
    raptor_test_names = [
        raptor_test['name'] for raptor_test in raptor_test_list
    ]

    # ensure we have at least one valid test to run
    if len(raptor_test_list) == 0:
        LOG.critical("abort: no tests found")
        sys.exit(1)

    LOG.info("raptor tests scheduled to run:")
    for next_test in raptor_test_list:
        LOG.info(next_test['name'])

    if args.app == "firefox":
        raptor_class = RaptorDesktopFirefox
    elif args.app == "chrome":
        raptor_class = RaptorDesktopChrome
    else:
        raptor_class = RaptorAndroid

    raptor = raptor_class(args.app,
                          args.binary,
                          run_local=args.run_local,
                          obj_path=args.obj_path,
                          gecko_profile=args.gecko_profile,
                          gecko_profile_interval=args.gecko_profile_interval,
                          gecko_profile_entries=args.gecko_profile_entries,
                          symbols_path=args.symbols_path,
                          host=args.host,
                          power_test=args.power_test,
                          is_release_build=args.is_release_build,
                          debug_mode=args.debug_mode,
                          activity=args.activity)

    raptor.create_browser_profile()
    raptor.create_browser_handler()
    raptor.start_control_server()

    for next_test in raptor_test_list:
        raptor.run_test(next_test, timeout=int(next_test['page_timeout']))

    success = raptor.process_results(raptor_test_names)
    raptor.clean_up()

    if not success:
        # didn't get test results; test timed out or crashed, etc. we want job to fail
        LOG.critical(
            "TEST-UNEXPECTED-FAIL: no raptor test results were found for %s" %
            ', '.join(raptor_test_names))
        os.sys.exit(1)

    # if we have results but one test page timed out (i.e. one tp6 test page didn't load
    # but others did) we still dumped PERFHERDER_DATA for the successfull pages but we
    # want the overall test job to marked as a failure
    pages_that_timed_out = raptor.get_page_timeout_list()
    if len(pages_that_timed_out) > 0:
        for _page in pages_that_timed_out:
            LOG.critical(
                "TEST-UNEXPECTED-FAIL: test '%s' timed out loading test page: %s "
                "pending metrics: %s" %
                (_page['test_name'], _page['url'], _page['pending_metrics']))
        os.sys.exit(1)

    # when running raptor locally with gecko profiling on, use the view-gecko-profile
    # tool to automatically load the latest gecko profile in profiler.firefox.com
    if args.gecko_profile and args.run_local:
        if os.environ.get('DISABLE_PROFILE_LAUNCH', '0') == '1':
            LOG.info(
                "Not launching profiler.firefox.com because DISABLE_PROFILE_LAUNCH=1"
            )
        else:
            view_gecko_profile(args.binary)
Example #41
0
 def __init__(self):
     self.logger = get_default_logger(component='TestRunner')
Example #42
0
 def __init__(self, branch='mozilla-inbound'):
     self.branch = branch
     self._repo_url = branches.get_url(branch)
     self.logger = get_default_logger("JsonPushes")
Example #43
0
 def kill(self, stagedShutdown=False):
     # Take a screenshot to capture the screen state just before
     # the application is killed.
     # Do not use the on-device screenshot options since
     # they rarely work well with Firefox on the Android
     # emulator. dump_screen provides an effective
     # screenshot of the emulator and its host desktop.
     if not self.device._device_serial.startswith('emulator-'):
         dump_device_screen(self.device, get_default_logger())
     elif self.utilityPath:
         dump_screen(self.utilityPath, get_default_logger())
     if stagedShutdown:
         # Trigger an ANR report with "kill -3" (SIGQUIT)
         try:
             self.device.pkill(self.procName, sig=3, attempts=1, root=True)
         except ADBTimeoutError:
             raise
         except:  # NOQA: E722
             pass
         time.sleep(3)
         # Trigger a breakpad dump with "kill -6" (SIGABRT)
         try:
             self.device.pkill(self.procName, sig=6, attempts=1, root=True)
         except ADBTimeoutError:
             raise
         except:  # NOQA: E722
             pass
         # Wait for process to end
         retries = 0
         while retries < 3:
             if self.device.process_exist(self.procName):
                 print("%s still alive after SIGABRT: waiting..." %
                       self.procName)
                 time.sleep(5)
             else:
                 break
             retries += 1
         if self.device.process_exist(self.procName):
             try:
                 self.device.pkill(self.procName,
                                   sig=9,
                                   attempts=1,
                                   root=True)
             except ADBTimeoutError:
                 raise
             except:  # NOQA: E722
                 print("%s still alive after SIGKILL!" % self.procName)
         if self.device.process_exist(self.procName):
             self.device.stop_application(self.procName)
     else:
         self.device.stop_application(self.procName)
     # Test harnesses use the MOZ_CRASHREPORTER environment variables to suppress
     # the interactive crash reporter, but that may not always be effective;
     # check for and cleanup errant crashreporters.
     crashreporter = "%s.CrashReporter" % self.procName
     if self.device.process_exist(crashreporter):
         print("Warning: %s unexpectedly found running. Killing..." %
               crashreporter)
         try:
             self.device.pkill(crashreporter, root=True)
         except ADBTimeoutError:
             raise
         except:  # NOQA: E722
             pass
     if self.device.process_exist(crashreporter):
         print("ERROR: %s still running!!" % crashreporter)
Example #44
0
 def pytest_configure(self, config):
     mozlog.commandline.setup_logging('pytest',
                                      config.known_args_namespace,
                                      defaults={},
                                      allow_unused_options=True)
     self.logger = mozlog.get_default_logger(component='pytest')
Example #45
0
 def __init__(self):
     self.proc = None
     self.kill_thread = Thread(target=self.wait_for_quit)
     self.kill_thread.daemon = True
     self.log = get_default_logger(component='view_gecko_profile')