mach_commands.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. from __future__ import absolute_import, unicode_literals
  5. import os
  6. import sys
  7. from mozbuild.base import (
  8. MachCommandBase,
  9. MachCommandConditions as conditions,
  10. )
  11. from mach.decorators import (
  12. Command,
  13. CommandProvider,
  14. )
  15. def setup_argument_parser_functional():
  16. from firefox_ui_harness.arguments.base import FirefoxUIArguments
  17. from mozlog.structured import commandline
  18. parser = FirefoxUIArguments()
  19. commandline.add_logging_group(parser)
  20. return parser
  21. def setup_argument_parser_update():
  22. from firefox_ui_harness.arguments.update import UpdateArguments
  23. from mozlog.structured import commandline
  24. parser = UpdateArguments()
  25. commandline.add_logging_group(parser)
  26. return parser
  27. def run_firefox_ui_test(testtype=None, topsrcdir=None, **kwargs):
  28. from mozlog.structured import commandline
  29. from argparse import Namespace
  30. import firefox_ui_harness
  31. if testtype == 'functional':
  32. parser = setup_argument_parser_functional()
  33. else:
  34. parser = setup_argument_parser_update()
  35. test_types = {
  36. 'functional': {
  37. 'default_tests': [
  38. os.path.join('puppeteer', 'manifest.ini'),
  39. os.path.join('functional', 'manifest.ini'),
  40. ],
  41. 'cli_module': firefox_ui_harness.cli_functional,
  42. },
  43. 'update': {
  44. 'default_tests': [
  45. os.path.join('update', 'manifest.ini'),
  46. ],
  47. 'cli_module': firefox_ui_harness.cli_update,
  48. }
  49. }
  50. fxui_dir = os.path.join(topsrcdir, 'testing', 'firefox-ui')
  51. # Set the resources path which is used to serve test data via wptserve
  52. if not kwargs['server_root']:
  53. kwargs['server_root'] = os.path.join(fxui_dir, 'resources')
  54. # If called via "mach test" a dictionary of tests is passed in
  55. if 'test_objects' in kwargs:
  56. tests = []
  57. for obj in kwargs['test_objects']:
  58. tests.append(obj['file_relpath'])
  59. kwargs['tests'] = tests
  60. elif not kwargs.get('tests'):
  61. # If no tests have been selected, set default ones
  62. kwargs['tests'] = [os.path.join(fxui_dir, 'tests', test)
  63. for test in test_types[testtype]['default_tests']]
  64. kwargs['logger'] = commandline.setup_logging('Firefox UI - {} Tests'.format(testtype),
  65. {"mach": sys.stdout})
  66. args = Namespace()
  67. for k, v in kwargs.iteritems():
  68. setattr(args, k, v)
  69. parser.verify_usage(args)
  70. failed = test_types[testtype]['cli_module'].cli(args=vars(args))
  71. if failed > 0:
  72. return 1
  73. else:
  74. return 0
  75. @CommandProvider
  76. class MachCommands(MachCommandBase):
  77. """Mach command provider for Firefox ui tests."""
  78. @Command('firefox-ui-functional', category='testing',
  79. conditions=[conditions.is_firefox],
  80. description='Run the functional test suite of Firefox UI tests.',
  81. parser=setup_argument_parser_functional,
  82. )
  83. def run_firefox_ui_functional(self, **kwargs):
  84. kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app')
  85. return run_firefox_ui_test(testtype='functional',
  86. topsrcdir=self.topsrcdir, **kwargs)
  87. @Command('firefox-ui-update', category='testing',
  88. conditions=[conditions.is_firefox],
  89. description='Run the update test suite of Firefox UI tests.',
  90. parser=setup_argument_parser_update,
  91. )
  92. def run_firefox_ui_update(self, **kwargs):
  93. kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app')
  94. return run_firefox_ui_test(testtype='update',
  95. topsrcdir=self.topsrcdir, **kwargs)