Bug 1519369 - support 'debugger' parser argument for mach test command r=ahal,gbrown

Differential Revision: https://phabricator.services.mozilla.com/D39229

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edwin Gao 2019-07-26 15:18:18 +00:00
Родитель a2ab584ff7
Коммит a1cc4534a7
5 изменённых файлов: 17 добавлений и 40 удалений

Просмотреть файл

@ -454,46 +454,6 @@ To see more help for a specific command, run:
# to command line handling (e.g alias, defaults) will be ignored.
self.load_settings(args.settings_file)
def _check_debugger(program):
"""Checks if debugger specified in command line is installed.
Uses mozdebug to locate debuggers.
If the call does not raise any exceptions, mach is permitted
to continue execution.
Otherwise, mach execution is halted.
Args:
program (str): debugger program name.
"""
import mozdebug
info = mozdebug.get_debugger_info(program)
if info is None:
print("Specified debugger '{}' is not found.\n".format(program) +
"Is it installed? Is it in your PATH?")
sys.exit(1)
# For the codepath where ./mach <test_type> --debugger=<program>,
# assert that debugger value exists first, then check if installed on system.
if (hasattr(args.command_args, "debugger") and
getattr(args.command_args, "debugger") is not None):
_check_debugger(getattr(args.command_args, "debugger"))
# For the codepath where ./mach test --debugger=<program> <test_type>,
# debugger must be specified from command line with the = operator.
# Otherwise, an IndexError is raised, which is converted to an exit code of 1.
elif (hasattr(args.command_args, "extra_args") and
getattr(args.command_args, "extra_args")):
extra_args = getattr(args.command_args, "extra_args")
try:
debugger = [ea.split("=")[1] for ea in extra_args if "debugger" in ea]
except IndexError:
print("Debugger must be specified with '=' when invoking ./mach test.\n" +
"Please correct the command and try again.")
sys.exit(1)
if debugger:
_check_debugger(''.join(debugger))
if not hasattr(args, 'mach_handler'):
raise MachError('ArgumentParser result missing mach handler info.')

Просмотреть файл

@ -80,6 +80,8 @@ def get_test_parser():
help="Extra arguments to pass to the underlying test command(s). "
"If an underlying command doesn't recognize the argument, it "
"will fail.")
parser.add_argument('--debugger', default=None, action='store',
nargs='?', help="Specify a debugger to use.")
add_logging_group(parser)
return parser
@ -321,6 +323,11 @@ class Test(MachCommandBase):
print(UNKNOWN_TEST)
return 1
if log_args.get('debugger', None):
import mozdebug
if not mozdebug.get_debugger_info(log_args.get('debugger')):
sys.exit(1)
# Create shared logger
format_args = {'level': self._mach_context.settings['test']['level']}
if not run_suites and len(run_tests) == 1:

Просмотреть файл

@ -356,6 +356,11 @@ class MachCommands(MachCommandBase):
test_paths = kwargs['test_paths']
kwargs['test_paths'] = []
if kwargs.get('debugger', None):
import mozdebug
if not mozdebug.get_debugger_info(kwargs.get('debugger')):
sys.exit(1)
mochitest = self._spawn(MochitestRunner)
tests = []
if resolve_tests:

Просмотреть файл

@ -191,6 +191,7 @@ def get_debugger_info(debugger, debuggerArgs=None, debuggerInteractive=False):
if not debuggerPath:
print('Error: Could not find debugger %s.' % debugger)
print('Is it installed? Is it in your PATH?')
return None
debuggerName = os.path.basename(debuggerPath).lower()

Просмотреть файл

@ -284,6 +284,10 @@ class MachCommands(MachCommandBase):
for item in params["test_objects"]:
params["include"].append(item["name"])
del params["test_objects"]
if params.get('debugger', None):
import mozdebug
if not mozdebug.get_debugger_info(params.get('debugger')):
sys.exit(1)
wpt_setup = self._spawn(WebPlatformTestsRunnerSetup)
wpt_setup._mach_context = self._mach_context