This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
/
marionette.py
executable file
·246 lines (217 loc) · 9.36 KB
/
marionette.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env python
# ***** BEGIN LICENSE BLOCK *****
# 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/.
# ***** END LICENSE BLOCK *****
import copy
import os
import re
import sys
# load modules from parent dir
sys.path.insert(1, os.path.dirname(sys.path[0]))
from mozharness.base.errors import PythonErrorList, TarErrorList
from mozharness.base.log import INFO, ERROR, OutputParser
from mozharness.base.script import BaseScript
from mozharness.mozilla.buildbot import TBPL_SUCCESS, TBPL_WARNING, TBPL_FAILURE
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options
class MarionetteOutputParser(OutputParser):
"""
A class that extends OutputParser such that it can parse the number of
passed/failed/todo tests from the output.
"""
summary = re.compile(r'(passed|failed|todo): (\d+)')
def __init__(self, **kwargs):
self.failed = 0
self.passed = 0
self.todo = 0
super(MarionetteOutputParser, self).__init__(**kwargs)
def parse_single_line(self, line):
m = self.summary.match(line)
if m:
try:
setattr(self, m.group(1), int(m.group(2)))
except ValueError:
# ignore bad values
pass
super(MarionetteOutputParser, self).parse_single_line(line)
class MarionetteTest(TestingMixin, BaseScript):
config_options = [
[["--type"],
{"action": "store",
"dest": "test_type",
"default": "browser",
"help": "The type of tests to run",
}],
[["--marionette-address"],
{"action": "store",
"dest": "marionette_address",
"default": None,
"help": "The host:port of the Marionette server running inside Gecko. Unused for emulator testing",
}],
[["--emulator"],
{"action": "store",
"type": "choice",
"choices": ['arm'],
"dest": "emulator",
"default": None,
"help": "Use an emulator for testing",
}],
[["--emulator-path"],
{"action": "store",
"dest": "emulator_path",
"default": None,
"help": "Path to the emulator for emulator testing",
}],
[["--test-manifest"],
{"action": "store",
"dest": "test_manifest",
"default": "unit-tests.ini",
"help": "Path to test manifest to run relative to the Marionette "
"tests directory",
}]] + copy.deepcopy(testing_config_options)
error_list = [
{'substr': 'FAILED (errors=', 'level': ERROR},
]
mozbase_dir = os.path.join('tests', 'mozbase')
virtualenv_modules = [
{ 'manifestparser': os.path.join(mozbase_dir, 'manifestdestiny') },
{ 'mozhttpd': os.path.join(mozbase_dir, 'mozhttpd') },
{ 'mozinfo': os.path.join(mozbase_dir, 'mozinfo') },
{ 'mozinstall': os.path.join(mozbase_dir, 'mozinstall') },
{ 'mozprofile': os.path.join(mozbase_dir, 'mozprofile') },
{ 'mozprocess': os.path.join(mozbase_dir, 'mozprocess') },
{ 'mozrunner': os.path.join(mozbase_dir, 'mozrunner') },
]
def __init__(self, require_config_file=False):
super(MarionetteTest, self).__init__(
config_options=self.config_options,
all_actions=['clobber',
'read-buildbot-config',
'download-and-extract',
'create-virtualenv',
'install',
'run-marionette'],
default_actions=['clobber',
'download-and-extract',
'create-virtualenv',
'install',
'run-marionette'],
require_config_file=require_config_file,
config={'virtualenv_modules': self.virtualenv_modules,
'require_test_zip': True,})
# these are necessary since self.config is read only
c = self.config
self.installer_url = c.get('installer_url')
self.installer_path = c.get('installer_path')
self.binary_path = c.get('binary_path')
self.test_url = self.config.get('test_url')
def _pre_config_lock(self, rw_config):
if self.config.get('emulator'):
if not self.config.get('emulator_path'):
self.fatal("You must specify --emulator-path for emulator tests!")
else:
if not self.config.get('marionette_address'):
self.fatal("You need to specify a --marionette-address for non-emulator tests! (Try --marionette-address localhost:2828 )")
def query_abs_dirs(self):
if self.abs_dirs:
return self.abs_dirs
abs_dirs = super(MarionetteTest, self).query_abs_dirs()
dirs = {}
dirs['abs_test_install_dir'] = os.path.join(
abs_dirs['abs_work_dir'], 'tests')
dirs['abs_marionette_dir'] = os.path.join(
dirs['abs_test_install_dir'], 'marionette', 'marionette')
dirs['abs_marionette_tests_dir'] = os.path.join(
dirs['abs_test_install_dir'], 'marionette', 'tests', 'testing',
'marionette', 'client', 'marionette', 'tests')
dirs['abs_gecko_dir'] = os.path.join(
abs_dirs['abs_work_dir'], 'gecko')
for key in dirs.keys():
if key not in abs_dirs:
abs_dirs[key] = dirs[key]
self.abs_dirs = abs_dirs
return self.abs_dirs
def _build_arg(self, option, value):
"""
Build a command line argument
"""
if not value:
return []
return [str(option), str(value)]
def download_and_extract(self):
super(MarionetteTest, self).download_and_extract()
if self.config.get('emulator'):
dirs = self.query_abs_dirs()
# This assumes the emulator zip's top level directory is the
# same as the final directory in emulator_path.
self._download_unzip(self.config['emulator_url'],
os.path.dirname(self.config['emulator_path']))
self.mkdir_p(dirs['abs_gecko_dir'])
tar = self.query_exe('tar', return_type='list')
self.run_command(tar + ['zxf', self.installer_path],
cwd=dirs['abs_gecko_dir'],
error_list=TarErrorList,
halt_on_failure=True)
def install(self):
if self.config.get('emulator'):
self.info("Emulator tests; skipping.")
else:
super(MarionetteTest, self).install()
def run_marionette(self):
"""
Run the Marionette tests
"""
dirs = self.query_abs_dirs()
error_list = self.error_list
error_list.extend(PythonErrorList)
# build the marionette command arguments
python = self.query_python_path('python')
cmd = [python, '-u', os.path.join(dirs['abs_marionette_dir'],
'runtests.py')]
if self.config.get('emulator'):
cmd.extend(self._build_arg('--emulator', self.config['emulator']))
cmd.extend(self._build_arg('--gecko-path', dirs['abs_gecko_dir']))
cmd.extend(self._build_arg('--homedir', self.config['emulator_path']))
else:
cmd.extend(self._build_arg('--binary', self.binary_path))
cmd.extend(self._build_arg('--type', self.config['test_type']))
cmd.extend(self._build_arg('--address', self.config['marionette_address']))
manifest = os.path.join(dirs['abs_marionette_tests_dir'],
self.config['test_manifest'])
cmd.append(manifest)
marionette_parser = MarionetteOutputParser(config=self.config,
log_obj=self.log_obj,
error_list=error_list)
code = self.run_command(cmd,
output_parser=marionette_parser)
level = INFO
if code == 0:
status = "success"
tbpl_status = TBPL_SUCCESS
elif code == 10:
status = "test failures"
tbpl_status = TBPL_WARNING
else:
status = "harness failures"
level = ERROR
tbpl_status = TBPL_FAILURE
# generate the TinderboxPrint line for TBPL
emphasize_fail_text = '<em class="testfail">%s</em>'
if marionette_parser.passed == 0 and marionette_parser.failed == 0:
tsummary = emphasize_fail_text % "T-FAIL"
else:
failed = "0"
if marionette_parser.failed > 0:
failed = emphasize_fail_text % str(marionette_parser.failed)
tsummary = "%d/%s/%d" % (marionette_parser.passed,
failed,
marionette_parser.todo)
self.info("TinderboxPrint: marionette<br/>%s\n" % tsummary)
self.add_summary("Marionette exited with return code %s: %s" % (code,
status),
level=level)
self.buildbot_status(tbpl_status)
if __name__ == '__main__':
marionetteTest = MarionetteTest()
marionetteTest.run()