def __init__(self, automation, devicemanager, options, scriptDir): RefTest.__init__(self) self.automation = automation self._devicemanager = devicemanager self.scriptDir = scriptDir self.remoteApp = options.app self.remoteProfile = options.remoteProfile self.remoteTestRoot = options.remoteTestRoot self.remoteLogFile = options.remoteLogFile self.remoteCache = os.path.join(options.remoteTestRoot, "cache/") self.localLogName = options.localLogName self.pidFile = options.pidFile if self.automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 else: self.SERVER_STARTUP_TIMEOUT = 90 self.automation.deleteANRs() self.automation.deleteTombstones() self._devicemanager.removeDir(self.remoteCache) self._populate_logger(options) outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath) # RemoteAutomation.py's 'messageLogger' is also used by mochitest. Mimic a mochitest # MessageLogger object to re-use this code path. outputHandler.write = outputHandler.__call__ self.automation._processArgs['messageLogger'] = outputHandler
def __init__(self, automation, devicemanager, options, scriptDir): RefTest.__init__(self) self.automation = automation self._devicemanager = devicemanager self.scriptDir = scriptDir self.remoteApp = options.app self.remoteProfile = options.remoteProfile self.remoteTestRoot = options.remoteTestRoot self.remoteLogFile = options.remoteLogFile self.remoteCache = os.path.join(options.remoteTestRoot, "cache/") self.localLogName = options.localLogName self.pidFile = options.pidFile if self.automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 else: self.SERVER_STARTUP_TIMEOUT = 90 self.automation.deleteANRs() self.automation.deleteTombstones() self._devicemanager.removeDir(self.remoteCache) self._populate_logger(options) self.outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath) # RemoteAutomation.py's 'messageLogger' is also used by mochitest. Mimic a mochitest # MessageLogger object to re-use this code path. self.outputHandler.write = self.outputHandler.__call__ self.automation._processArgs['messageLogger'] = self.outputHandler
def runApp(self, profile, binary, cmdargs, env, timeout=None, debuggerInfo=None, symbolsPath=None, options=None, valgrindPath=None, valgrindArgs=None, valgrindSuppFiles=None): outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath) status = self.automation.runApp(None, env, binary, profile.profile, cmdargs, utilityPath=options.utilityPath, xrePath=options.xrePath, debuggerInfo=debuggerInfo, symbolsPath=symbolsPath, timeout=timeout, outputHandler=outputHandler) return status
def run_tests(self, tests, options): manifests = self.resolver.resolveManifests(options, tests) self.profile = self.create_profile(options, manifests, profile_to_clone=options.profile) env = self.buildBrowserEnv(options, self.profile.profile) self._populate_logger(options) outputHandler = OutputHandler(self.log, options.utilityPath, symbolsPath=options.symbolsPath) kp_kwargs = { 'processOutputLine': [outputHandler], 'onTimeout': [self._on_timeout], 'kill_on_timeout': False } if not options.debugger: if not options.timeout: if mozinfo.info['debug']: options.timeout = 420 else: options.timeout = 300 self.timeout = options.timeout + 30.0 self.log.info("%s | Running tests: start." % os.path.basename(__file__)) cmd, args = self.build_command_line(options.app, ignore_window_size=options.ignoreWindowSize, browser_arg=options.browser_arg) self.runner = FirefoxRunner(profile=self.profile, binary=cmd, cmdargs=args, env=env, process_class=ProcessHandler, process_args=kp_kwargs, symbols_path=options.symbolsPath) status = 0 try: self.runner.start(outputTimeout=self.timeout) self.log.info("%s | Application pid: %d" % ( os.path.basename(__file__), self.runner.process_handler.pid)) # kick starts the reftest harness self.run_marionette_script() status = self.runner.wait() finally: self.runner.check_for_crashes(test_name=self.last_test) self.runner.cleanup() if status > 0: self.log.testFail("%s | application terminated with exit code %s" % ( self.last_test, status)) elif status < 0: self.log.info("%s | application killed with signal %s" % ( self.last_test, -status)) self.log.info("%s | Running tests: end." % os.path.basename(__file__)) return status
def runApp(self, profile, binary, cmdargs, env, timeout=None, debuggerInfo=None, symbolsPath=None, options=None, valgrindPath=None, valgrindArgs=None, valgrindSuppFiles=None): def timeoutHandler(): self.handleTimeout(timeout, proc, options.utilityPath, debuggerInfo) interactive = False debug_args = None if debuggerInfo: interactive = debuggerInfo.interactive debug_args = [debuggerInfo.path] + debuggerInfo.args def record_last_test(message): """Records the last test seen by this harness for the benefit of crash logging.""" if message['action'] == 'test_start': if " " in message['test']: self.lastTestSeen = message['test'].split(" ")[0] else: self.lastTestSeen = message['test'] self.log.add_handler(record_last_test) outputHandler = OutputHandler(self.log, options.utilityPath, symbolsPath=symbolsPath) kp_kwargs = { 'kill_on_timeout': False, 'cwd': SCRIPT_DIRECTORY, 'onTimeout': [timeoutHandler], 'processOutputLine': [outputHandler], } if interactive: # If an interactive debugger is attached, # don't use timeouts, and don't capture ctrl-c. timeout = None signal.signal(signal.SIGINT, lambda sigid, frame: None) runner_cls = mozrunner.runners.get( mozinfo.info.get('appname', 'firefox'), mozrunner.Runner) runner = runner_cls(profile=profile, binary=binary, process_class=mozprocess.ProcessHandlerMixin, cmdargs=cmdargs, env=env, process_args=kp_kwargs) runner.start(debug_args=debug_args, interactive=interactive, outputTimeout=timeout) proc = runner.process_handler if self.use_marionette: marionette_args = { 'socket_timeout': options.marionette_socket_timeout, 'startup_timeout': options.marionette_startup_timeout, 'symbols_path': options.symbolsPath, } if options.marionette: host, port = options.marionette.split(':') marionette_args['host'] = host marionette_args['port'] = int(port) marionette = Marionette(**marionette_args) marionette.start_session(timeout=options.marionette_port_timeout) addons = Addons(marionette) if options.specialPowersExtensionPath: addons.install(options.specialPowersExtensionPath, temp=True) addons.install(options.reftestExtensionPath, temp=True) marionette.delete_session() status = runner.wait() runner.process_handler = None if status: msg = "TEST-UNEXPECTED-FAIL | %s | application terminated with exit code %s" % \ (self.lastTestSeen, status) # use process_output so message is logged verbatim self.log.process_output(None, msg) else: self.lastTestSeen = self.TEST_SEEN_FINAL crashed = mozcrash.log_crashes(self.log, os.path.join(profile.profile, 'minidumps'), symbolsPath, test=self.lastTestSeen) runner.cleanup() if not status and crashed: status = 1 return status, self.lastTestSeen
def __init__(self, options, scriptDir): RefTest.__init__(self, options.suite) self.run_by_manifest = False self.scriptDir = scriptDir self.localLogName = options.localLogName verbose = False if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug': verbose = True print "set verbose!" self.device = ADBDevice(adb=options.adb_path or 'adb', device=options.deviceSerial, test_root=options.remoteTestRoot, verbose=verbose) if options.remoteTestRoot is None: options.remoteTestRoot = posixpath.join(self.device.test_root, "reftest") options.remoteProfile = posixpath.join(options.remoteTestRoot, "profile") options.remoteLogFile = posixpath.join(options.remoteTestRoot, "reftest.log") options.logFile = options.remoteLogFile self.remoteProfile = options.remoteProfile self.remoteTestRoot = options.remoteTestRoot if not options.ignoreWindowSize: parts = self.device.get_info('screen')['screen'][0].split() width = int(parts[0].split(':')[1]) height = int(parts[1].split(':')[1]) if (width < 1366 or height < 1050): self.error("ERROR: Invalid screen resolution %sx%s, " "please adjust to 1366x1050 or higher" % (width, height)) self._populate_logger(options) self.outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath) # RemoteAutomation.py's 'messageLogger' is also used by mochitest. Mimic a mochitest # MessageLogger object to re-use this code path. self.outputHandler.write = self.outputHandler.__call__ args = {'messageLogger': self.outputHandler} self.automation = RemoteAutomation(self.device, appName=options.app, remoteProfile=self.remoteProfile, remoteLog=options.remoteLogFile, processArgs=args) self.environment = self.automation.environment if self.automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 else: self.SERVER_STARTUP_TIMEOUT = 90 self.remoteCache = os.path.join(options.remoteTestRoot, "cache/") # Check that Firefox is installed expected = options.app.split('/')[-1] if not self.device.is_app_installed(expected): raise Exception("%s is not installed on this device" % expected) self.device.clear_logcat() self.device.rm(self.remoteCache, force=True, recursive=True) procName = options.app.split('/')[-1] self.device.stop_application(procName) if self.device.process_exist(procName): self.log.error("unable to kill %s before starting tests!" % procName)
def runTests(self, tests, options, cmdargs=None): cmdargs = cmdargs or [] self._populate_logger(options) self.outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath) if options.cleanupCrashes: mozcrash.cleanup_pending_crash_reports() manifests = self.resolver.resolveManifests(options, tests) if options.filter: manifests[""] = options.filter if not getattr(options, 'runTestsInParallel', False): return self.runSerialTests(manifests, options, cmdargs) cpuCount = multiprocessing.cpu_count() # We have the directive, technology, and machine to run multiple test instances. # Experimentation says that reftests are not overly CPU-intensive, so we can run # multiple jobs per CPU core. # # Our Windows machines in automation seem to get upset when we run a lot of # simultaneous tests on them, so tone things down there. if sys.platform == 'win32': jobsWithoutFocus = cpuCount else: jobsWithoutFocus = 2 * cpuCount totalJobs = jobsWithoutFocus + 1 perProcessArgs = [sys.argv[:] for i in range(0, totalJobs)] host = 'localhost' port = 2828 if options.marionette: host, port = options.marionette.split(':') # First job is only needs-focus tests. Remaining jobs are # non-needs-focus and chunked. perProcessArgs[0].insert(-1, "--focus-filter-mode=needs-focus") for (chunkNumber, jobArgs) in enumerate(perProcessArgs[1:], start=1): jobArgs[-1:-1] = [ "--focus-filter-mode=non-needs-focus", "--total-chunks=%d" % jobsWithoutFocus, "--this-chunk=%d" % chunkNumber, "--marionette=%s:%d" % (host, port) ] port += 1 for jobArgs in perProcessArgs: try: jobArgs.remove("--run-tests-in-parallel") except Exception: pass jobArgs[0:0] = [sys.executable, "-u"] threads = [ReftestThread(args) for args in perProcessArgs[1:]] for t in threads: t.start() while True: # The test harness in each individual thread will be doing timeout # handling on its own, so we shouldn't need to worry about any of # the threads hanging for arbitrarily long. for t in threads: t.join(10) if not any(t.is_alive() for t in threads): break # Run the needs-focus tests serially after the other ones, so we don't # have to worry about races between the needs-focus tests *actually* # needing focus and the dummy windows in the non-needs-focus tests # trying to focus themselves. focusThread = ReftestThread(perProcessArgs[0]) focusThread.start() focusThread.join() # Output the summaries that the ReftestThread filters suppressed. summaryObjects = [defaultdict(int) for s in summaryLines] for t in threads: for (summaryObj, (text, categories)) in zip(summaryObjects, summaryLines): threadMatches = t.summaryMatches[text] for (attribute, description) in categories: amount = int( threadMatches.group(attribute) if threadMatches else 0) summaryObj[attribute] += amount amount = int( threadMatches.group('total') if threadMatches else 0) summaryObj['total'] += amount print 'REFTEST INFO | Result summary:' for (summaryObj, (text, categories)) in zip(summaryObjects, summaryLines): details = ', '.join([ "%d %s" % (summaryObj[attribute], description) for (attribute, description) in categories ]) print 'REFTEST INFO | ' + text + ': ' + str( summaryObj['total']) + ' (' + details + ')' return int(any(t.retcode != 0 for t in threads))
def runApp(self, profile, binary, cmdargs, env, timeout=None, debuggerInfo=None, symbolsPath=None, options=None, valgrindPath=None, valgrindArgs=None, valgrindSuppFiles=None): def timeoutHandler(): self.handleTimeout(timeout, proc, options.utilityPath, debuggerInfo) interactive = False debug_args = None if debuggerInfo: interactive = debuggerInfo.interactive debug_args = [debuggerInfo.path] + debuggerInfo.args def record_last_test(message): """Records the last test seen by this harness for the benefit of crash logging.""" if message['action'] == 'test_start': if isinstance(message['test'], tuple): self.lastTestSeen = message['test'][0] else: self.lastTestSeen = message['test'] self.log.add_handler(record_last_test) outputHandler = OutputHandler(self.log, options.utilityPath, symbolsPath=symbolsPath) kp_kwargs = { 'kill_on_timeout': False, 'cwd': SCRIPT_DIRECTORY, 'onTimeout': [timeoutHandler], 'processOutputLine': [outputHandler], } if interactive: # If an interactive debugger is attached, # don't use timeouts, and don't capture ctrl-c. timeout = None signal.signal(signal.SIGINT, lambda sigid, frame: None) if mozinfo.info.get( 'appname') == 'b2g' and mozinfo.info.get('toolkit') != 'gonk': runner_cls = mozrunner.Runner else: runner_cls = mozrunner.runners.get( mozinfo.info.get('appname', 'firefox'), mozrunner.Runner) runner = runner_cls(profile=profile, binary=binary, process_class=mozprocess.ProcessHandlerMixin, cmdargs=cmdargs, env=env, process_args=kp_kwargs) runner.start(debug_args=debug_args, interactive=interactive, outputTimeout=timeout) proc = runner.process_handler status = runner.wait() runner.process_handler = None if status: msg = "TEST-UNEXPECTED-FAIL | %s | application terminated with exit code %s" % \ (self.lastTestSeen, status) # use process_output so message is logged verbatim self.log.process_output(None, msg) else: self.lastTestSeen = 'Main app process exited normally' crashed = mozcrash.log_crashes(self.log, os.path.join(profile.profile, 'minidumps'), symbolsPath, test=self.lastTestSeen) runner.cleanup() if not status and crashed: status = 1 return status
def runApp(self, profile, binary, cmdargs, env, timeout=None, debuggerInfo=None, symbolsPath=None, options=None, valgrindPath=None, valgrindArgs=None, valgrindSuppFiles=None): def timeoutHandler(): self.handleTimeout(timeout, proc, options.utilityPath, debuggerInfo) interactive = False debug_args = None if debuggerInfo: interactive = debuggerInfo.interactive debug_args = [debuggerInfo.path] + debuggerInfo.args def record_last_test(message): """Records the last test seen by this harness for the benefit of crash logging.""" if message['action'] == 'test_start': if " " in message['test']: self.lastTestSeen = message['test'].split(" ")[0] else: self.lastTestSeen = message['test'] self.log.add_handler(record_last_test) outputHandler = OutputHandler(self.log, options.utilityPath, symbolsPath=symbolsPath) kp_kwargs = { 'kill_on_timeout': False, 'cwd': SCRIPT_DIRECTORY, 'onTimeout': [timeoutHandler], 'processOutputLine': [outputHandler], } if mozinfo.isWin: # Prevents log interleaving on Windows at the expense of losing # true log order. See bug 798300 and bug 1324961 for more details. kp_kwargs['processStderrLine'] = [outputHandler] if interactive: # If an interactive debugger is attached, # don't use timeouts, and don't capture ctrl-c. timeout = None signal.signal(signal.SIGINT, lambda sigid, frame: None) runner_cls = mozrunner.runners.get( mozinfo.info.get('appname', 'firefox'), mozrunner.Runner) runner = runner_cls(profile=profile, binary=binary, process_class=mozprocess.ProcessHandlerMixin, cmdargs=cmdargs, env=env, process_args=kp_kwargs) runner.start(debug_args=debug_args, interactive=interactive, outputTimeout=timeout) proc = runner.process_handler # Used to defer a possible IOError exception from Marionette marionette_exception = None if self.use_marionette: marionette_args = { 'socket_timeout': options.marionette_socket_timeout, 'startup_timeout': options.marionette_startup_timeout, 'symbols_path': options.symbolsPath, } if options.marionette: host, port = options.marionette.split(':') marionette_args['host'] = host marionette_args['port'] = int(port) try: marionette = Marionette(**marionette_args) marionette.start_session() addons = Addons(marionette) if options.specialPowersExtensionPath: addons.install(options.specialPowersExtensionPath, temp=True) addons.install(options.reftestExtensionPath, temp=True) marionette.delete_session() except IOError: # Any IOError as thrown by Marionette means that something is # wrong with the process, like a crash or the socket is no # longer open. We defer raising this specific error so that # post-test checks for leaks and crashes are performed and # reported first. marionette_exception = sys.exc_info() status = runner.wait() runner.process_handler = None if status: msg = "TEST-UNEXPECTED-FAIL | %s | application terminated with exit code %s" % \ (self.lastTestSeen, status) # use process_output so message is logged verbatim self.log.process_output(None, msg) else: self.lastTestSeen = self.TEST_SEEN_FINAL crashed = mozcrash.log_crashes(self.log, os.path.join(profile.profile, 'minidumps'), symbolsPath, test=self.lastTestSeen) if not status and crashed: status = 1 runner.cleanup() if marionette_exception is not None: exc, value, tb = marionette_exception raise exc, value, tb return status, self.lastTestSeen
def runApp(self, profile, binary, cmdargs, env, timeout=None, debuggerInfo=None, symbolsPath=None, options=None, valgrindPath=None, valgrindArgs=None, valgrindSuppFiles=None): def timeoutHandler(): self.handleTimeout( timeout, proc, options.utilityPath, debuggerInfo) interactive = False debug_args = None if debuggerInfo: interactive = debuggerInfo.interactive debug_args = [debuggerInfo.path] + debuggerInfo.args def record_last_test(message): """Records the last test seen by this harness for the benefit of crash logging.""" if message['action'] == 'test_start': if " " in message['test']: self.lastTestSeen = message['test'].split(" ")[0] else: self.lastTestSeen = message['test'] self.log.add_handler(record_last_test) outputHandler = OutputHandler(self.log, options.utilityPath, symbolsPath=symbolsPath) kp_kwargs = { 'kill_on_timeout': False, 'cwd': SCRIPT_DIRECTORY, 'onTimeout': [timeoutHandler], 'processOutputLine': [outputHandler], } if mozinfo.isWin: # Prevents log interleaving on Windows at the expense of losing # true log order. See bug 798300 and bug 1324961 for more details. kp_kwargs['processStderrLine'] = [outputHandler] if interactive: # If an interactive debugger is attached, # don't use timeouts, and don't capture ctrl-c. timeout = None signal.signal(signal.SIGINT, lambda sigid, frame: None) runner_cls = mozrunner.runners.get(mozinfo.info.get('appname', 'firefox'), mozrunner.Runner) runner = runner_cls(profile=profile, binary=binary, process_class=mozprocess.ProcessHandlerMixin, cmdargs=cmdargs, env=env, process_args=kp_kwargs) runner.start(debug_args=debug_args, interactive=interactive, outputTimeout=timeout) proc = runner.process_handler outputHandler.proc_name = 'GECKO({})'.format(proc.pid) # Used to defer a possible IOError exception from Marionette marionette_exception = None if self.use_marionette: marionette_args = { 'socket_timeout': options.marionette_socket_timeout, 'startup_timeout': options.marionette_startup_timeout, 'symbols_path': options.symbolsPath, } if options.marionette: host, port = options.marionette.split(':') marionette_args['host'] = host marionette_args['port'] = int(port) try: marionette = Marionette(**marionette_args) marionette.start_session() addons = Addons(marionette) if options.specialPowersExtensionPath: addons.install(options.specialPowersExtensionPath, temp=True) addons.install(options.reftestExtensionPath, temp=True) marionette.delete_session() except IOError: # Any IOError as thrown by Marionette means that something is # wrong with the process, like a crash or the socket is no # longer open. We defer raising this specific error so that # post-test checks for leaks and crashes are performed and # reported first. marionette_exception = sys.exc_info() status = runner.wait() runner.process_handler = None outputHandler.proc_name = None if status: msg = "TEST-UNEXPECTED-FAIL | %s | application terminated with exit code %s" % \ (self.lastTestSeen, status) # use process_output so message is logged verbatim self.log.process_output(None, msg) else: self.lastTestSeen = self.TEST_SEEN_FINAL crashed = mozcrash.log_crashes(self.log, os.path.join(profile.profile, 'minidumps'), symbolsPath, test=self.lastTestSeen) if not status and crashed: status = 1 runner.cleanup() if marionette_exception is not None: exc, value, tb = marionette_exception raise exc, value, tb return status, self.lastTestSeen
def __init__(self, options, scriptDir): RefTest.__init__(self, options.suite) self.run_by_manifest = False self.scriptDir = scriptDir self.localLogName = options.localLogName verbose = False if (options.log_mach_verbose or options.log_tbpl_level == "debug" or options.log_mach_level == "debug" or options.log_raw_level == "debug"): verbose = True print("set verbose!") expected = options.app.split("/")[-1] self.device = ADBDeviceFactory( adb=options.adb_path or "adb", device=options.deviceSerial, test_root=options.remoteTestRoot, verbose=verbose, run_as_package=expected, ) if options.remoteTestRoot is None: options.remoteTestRoot = posixpath.join(self.device.test_root, "reftest") options.remoteProfile = posixpath.join(options.remoteTestRoot, "profile") options.remoteLogFile = posixpath.join(options.remoteTestRoot, "reftest.log") options.logFile = options.remoteLogFile self.remoteProfile = options.remoteProfile self.remoteTestRoot = options.remoteTestRoot if not options.ignoreWindowSize: parts = self.device.get_info("screen")["screen"][0].split() width = int(parts[0].split(":")[1]) height = int(parts[1].split(":")[1]) if width < 1366 or height < 1050: self.error("ERROR: Invalid screen resolution %sx%s, " "please adjust to 1366x1050 or higher" % (width, height)) self._populate_logger(options) self.outputHandler = OutputHandler(self.log, options.utilityPath, options.symbolsPath) self.SERVER_STARTUP_TIMEOUT = 90 self.remoteCache = os.path.join(options.remoteTestRoot, "cache/") # Check that Firefox is installed expected = options.app.split("/")[-1] if not self.device.is_app_installed(expected): raise Exception("%s is not installed on this device" % expected) self.device.run_as_package = expected self.device.clear_logcat() self.device.rm(self.remoteCache, force=True, recursive=True) procName = options.app.split("/")[-1] self.device.stop_application(procName) if self.device.process_exist(procName): self.log.error("unable to kill %s before starting tests!" % procName)
import discord import deposit import get import transaction from output import OutputHandler as OutputHandler #print(discord.__version__) # check to make sure at least once you're on the right version! token = open("token.txt", "r").read() # I've opted to just save my token to a text file. client = discord.Client() # starts the discord client. COMMAND_HELP = {'deposit': 'deposit <amt> [title]'} outputHandle = OutputHandler() # def bot_print(msg): # print(msg) def cmd_help(command): try: outputHandle.output(COMMAND_HELP[command]) except: outputHandle.output(f"Error on {command}: command not found") def parseMsg(message): msg = message.content.strip().lower() print('DEBUG:', msg, COMMAND_HELP.keys()) if str(message.author) != 'FlyingPotato#1776':