|
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 |
|
5 from __future__ import unicode_literals |
|
6 import os |
|
7 |
|
8 from mozbuild.base import ( |
|
9 MachCommandBase, |
|
10 MachCommandConditions as conditions, |
|
11 ) |
|
12 |
|
13 from mach.decorators import ( |
|
14 CommandArgument, |
|
15 CommandProvider, |
|
16 Command, |
|
17 ) |
|
18 |
|
19 MARIONETTE_DISABLED_B2G = ''' |
|
20 The %s command requires a Marionette-enabled build. |
|
21 |
|
22 Please create an engineering build, which has Marionette enabled. You can do |
|
23 this by ommitting the VARIANT variable when building, or using: |
|
24 |
|
25 VARIANT=eng ./build.sh |
|
26 ''' |
|
27 |
|
28 def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, |
|
29 address=None, bin=None, topsrcdir=None): |
|
30 from marionette.runtests import ( |
|
31 MarionetteTestRunner, |
|
32 BaseMarionetteOptions, |
|
33 startTestRunner |
|
34 ) |
|
35 |
|
36 parser = BaseMarionetteOptions() |
|
37 options, args = parser.parse_args() |
|
38 |
|
39 if not tests: |
|
40 tests = [os.path.join(topsrcdir, |
|
41 'testing/marionette/client/marionette/tests/unit-tests.ini')] |
|
42 |
|
43 options.type = testtype |
|
44 if b2g_path: |
|
45 options.homedir = b2g_path |
|
46 if emulator: |
|
47 options.emulator = emulator |
|
48 else: |
|
49 options.bin = bin |
|
50 path, exe = os.path.split(options.bin) |
|
51 |
|
52 options.address = address |
|
53 |
|
54 parser.verify_usage(options, tests) |
|
55 |
|
56 runner = startTestRunner(MarionetteTestRunner, options, tests) |
|
57 if runner.failed > 0: |
|
58 return 1 |
|
59 |
|
60 return 0 |
|
61 |
|
62 @CommandProvider |
|
63 class B2GCommands(MachCommandBase): |
|
64 def __init__(self, context): |
|
65 MachCommandBase.__init__(self, context) |
|
66 |
|
67 for attr in ('b2g_home', 'device_name'): |
|
68 setattr(self, attr, getattr(context, attr, None)) |
|
69 @Command('marionette-webapi', category='testing', |
|
70 description='Run a Marionette webapi test', |
|
71 conditions=[conditions.is_b2g]) |
|
72 @CommandArgument('--emulator', choices=['x86', 'arm'], |
|
73 help='Run an emulator of the specified architecture.') |
|
74 @CommandArgument('--type', dest='testtype', |
|
75 help='Test type, usually one of: browser, b2g, b2g-qemu.', |
|
76 default='b2g') |
|
77 @CommandArgument('tests', nargs='*', metavar='TESTS', |
|
78 help='Path to test(s) to run.') |
|
79 def run_marionette_webapi(self, tests, emulator=None, testtype=None): |
|
80 if not emulator and self.device_name.find('emulator') == 0: |
|
81 emulator='arm' |
|
82 |
|
83 if self.substs.get('ENABLE_MARIONETTE') != '1': |
|
84 print(MARIONETTE_DISABLED_B2G % 'marionette-webapi') |
|
85 return 1 |
|
86 |
|
87 return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator, |
|
88 testtype=testtype, topsrcdir=self.topsrcdir, address=None) |
|
89 |
|
90 |
|
91 @CommandProvider |
|
92 class MachCommands(MachCommandBase): |
|
93 @Command('marionette-test', category='testing', |
|
94 description='Run a Marionette test.', |
|
95 conditions=[conditions.is_firefox]) |
|
96 @CommandArgument('--address', |
|
97 help='host:port of running Gecko instance to connect to.') |
|
98 @CommandArgument('--type', dest='testtype', |
|
99 help='Test type, usually one of: browser, b2g, b2g-qemu.', |
|
100 default='browser') |
|
101 @CommandArgument('tests', nargs='*', metavar='TESTS', |
|
102 help='Path to test(s) to run.') |
|
103 def run_marionette_test(self, tests, address=None, testtype=None): |
|
104 bin = self.get_binary_path('app') |
|
105 return run_marionette(tests, bin=bin, testtype=testtype, |
|
106 topsrcdir=self.topsrcdir, address=address) |