Skip to content

Instantly share code, notes, and snippets.

@shinglyu
Created October 27, 2015 10:27
Show Gist options
  • Save shinglyu/be17f252c0c7eac1f9db to your computer and use it in GitHub Desktop.
Save shinglyu/be17f252c0c7eac1f9db to your computer and use it in GitHub Desktop.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
from marionette.runner import (
BaseMarionetteOptions,
BaseMarionetteTestRunner,
MarionetteTestResult,
MarionetteTextTestRunner,
BrowserMobProxyOptionsMixin
)
from marionette.marionette_test import MarionetteTestCase, MarionetteJSTestCase
from marionette.runner.mixins.reporting import (
HTMLReportingTestResultMixin,
HTMLReportingTestRunnerMixin,
HTMLReportingOptionsMixin
)
import mozlog
import pdb
import objgraph
from pympler import muppy, tracker, refbrowser
import pycallgraph
class LeakyTestOptions(BaseMarionetteOptions, HTMLReportingOptionsMixin):
def __init__(self, **kwargs):
BaseMarionetteOptions.__init__(self, **kwargs)
HTMLReportingOptionsMixin.__init__(self, **kwargs)
class LeakyTestResult(MarionetteTestResult, HTMLReportingTestResultMixin):
def __init__(self, *args, **kwargs):
MarionetteTestResult.__init__(self, *args, **kwargs)
HTMLReportingTestResultMixin.__init__(self, *args, **kwargs)
class LeakyTextTestRunner(MarionetteTextTestRunner):
resultclass = LeakyTestResult
# def __init__(self, **kwargs):
# MarionetteTextTestRunner.__init__(self, **kwargs)
class LeakyTestRunner(BaseMarionetteTestRunner, HTMLReportingTestRunnerMixin):
textrunnerclass = LeakyTextTestRunner
def __init__(self, **kwargs):
BaseMarionetteTestRunner.__init__(self, **kwargs)
HTMLReportingTestRunnerMixin.__init__(self, **kwargs)
self.test_handlers = [MarionetteTestCase, MarionetteJSTestCase]
default_options = { 'startup_timeout': 60,
'browsermob_port': None,
'shuffle': False,
'socket_timeout': 360.0,
'app': 'b2gdesktop',
'symbols_path': None,
'sdcard': None,
'emulator_res': None,
'test_tags': None,
'emulator_binary': None,
'sources': None,
'app_args': [],
'log_mach_level': None,
'jsdebugger': False,
'log_errorsummary': None,
'log_xunit': None,
'log_mach': None,
'logcat_stdout': False,
'log_tbpl_level': None,
'homedir': None,
'log_tbpl': None,
'total_chunks': None,
'log_unittest': None,
'gecko_log': None,
'logdir': None,
'pydebugger': None,
'e10s': False,
'logger': None, #TODO
'xml_output': None,
'type': None,
'log_tbpl_buffer': None,
'profile': '/home/shinglyu/workspace/B2G/gaia/profile',
'repeat': 0,
'log_html': None,
'binary': '/home/shinglyu/tools/desktop-b2g/b2g',
'log_raw': None,
'logger_name': 'Marionette-based Tests',
'address': None,
'adb_port': None,
'log_mach_buffer': None,
'browsermob_script': None,
'log_mach_verbose': None,
'this_chunk': None,
'log_raw_level': None,
'tree': 'b2g',
'no_window': False,
'testvars': None,
'server_root': None,
'adb_host': None,
'emulator_img': None,
'emulator': None,
'timeout': None,
'addons': None,
'device_serial': None,
'shuffle_seed': 497302624393129604,
#Manually aded
'marionette': None,
'capabilities': None
}
def cli(runner_class=LeakyTestRunner, parser_class=LeakyTestOptions):
parser = parser_class()
options, tests = parser.parse_args()
#for (key, val) in default_options.iteritems():
#options[key]
#runner = runner_class(**vars(options))
print options
logger = mozlog.commandline.setup_logging(
"logger", options, {"tbpl": sys.stdout})
#options['logger'] = logger
options.logger = logger
#print objgraph.show_growth()
#tr = tracker.SummaryTracker()
print "Before runner init"
#tr.print_diff()
for i in range(1,10):
#for i in range(1,2):
#with pycallgraph.PyCallGraph(output=pycallgraph.output.GraphvizOutput()):
runner = runner_class(**vars(options))
#cb = refbrowser.consolebrowser(runner)
#cb.print_tree()
#ib = refbrowser.interactivebrowser(runner)
#ib.main()
#pdb.set_trace()
tests = ['tests/unit/test_simpletest_sanity.py']
print "runner created"
#tr.print_diff()
runner.run_tests(tests)
print "Runner run_tests"
#tr.print_diff()
#print objgraph.show_growth()
print "All runner finished"
#tr.print_diff()
if __name__ == "__main__":
tr = tracker.SummaryTracker()
tr.print_diff()
cli(runner_class=LeakyTestRunner, parser_class=LeakyTestOptions)
tr.print_diff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment