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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
#!/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 *****
"""
run awsy tests in a virtualenv
"""
import copy
import json
import os
import re
import sys
# load modules from parent dir
sys.path.insert(1, os.path.dirname(sys.path[0]))
import mozharness
import mozinfo
from mozharness.base.log import ERROR, INFO
from mozharness.base.script import PreScriptAction
from mozharness.base.vcs.vcsbase import MercurialScript
from mozharness.mozilla.structuredlog import StructuredOutputParser
from mozharness.mozilla.testing.codecoverage import (
CodeCoverageMixin,
code_coverage_config_options,
)
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options
from mozharness.mozilla.tooltool import TooltoolMixin
PY2 = sys.version_info.major == 2
scripts_path = os.path.abspath(os.path.dirname(os.path.dirname(mozharness.__file__)))
external_tools_path = os.path.join(scripts_path, "external_tools")
class AWSY(TestingMixin, MercurialScript, TooltoolMixin, CodeCoverageMixin):
config_options = (
[
[
["--disable-e10s"],
{
"action": "store_false",
"dest": "e10s",
"default": True,
"help": "Run tests without multiple processes (e10s). (Desktop builds only)",
},
],
[
["--setpref"],
{
"action": "append",
"dest": "extra_prefs",
"default": [],
"help": "Extra user prefs.",
},
],
[
["--base"],
{
"action": "store_true",
"dest": "test_about_blank",
"default": False,
"help": "Runs the about:blank base case memory test.",
},
],
[
["--dmd"],
{
"action": "store_true",
"dest": "dmd",
"default": False,
"help": "Runs tests with DMD enabled.",
},
],
[
["--tp6"],
{
"action": "store_true",
"dest": "tp6",
"default": False,
"help": "Runs tests with the tp6 pageset.",
},
],
]
+ testing_config_options
+ copy.deepcopy(code_coverage_config_options)
)
error_list = [
{"regex": re.compile(r"""(TEST-UNEXPECTED|PROCESS-CRASH)"""), "level": ERROR},
]
def __init__(self, **kwargs):
kwargs.setdefault("config_options", self.config_options)
kwargs.setdefault(
"all_actions",
[
"clobber",
"download-and-extract",
"populate-webroot",
"create-virtualenv",
"install",
"run-tests",
],
)
kwargs.setdefault(
"default_actions",
[
"clobber",
"download-and-extract",
"populate-webroot",
"create-virtualenv",
"install",
"run-tests",
],
)
kwargs.setdefault("config", {})
super(AWSY, self).__init__(**kwargs)
self.installer_url = self.config.get("installer_url")
self.tests = None
self.testdir = self.query_abs_dirs()["abs_test_install_dir"]
self.awsy_path = os.path.join(self.testdir, "awsy")
self.awsy_libdir = os.path.join(self.awsy_path, "awsy")
self.webroot_dir = os.path.join(self.testdir, "html")
self.results_dir = os.path.join(self.testdir, "results")
self.binary_path = self.config.get("binary_path")
def query_abs_dirs(self):
if self.abs_dirs:
return self.abs_dirs
abs_dirs = super(AWSY, self).query_abs_dirs()
dirs = {}
dirs["abs_blob_upload_dir"] = os.path.join(
abs_dirs["abs_work_dir"], "blobber_upload_dir"
)
dirs["abs_test_install_dir"] = os.path.join(abs_dirs["abs_work_dir"], "tests")
abs_dirs.update(dirs)
self.abs_dirs = abs_dirs
return self.abs_dirs
def download_and_extract(self, extract_dirs=None, suite_categories=None):
ret = super(AWSY, self).download_and_extract(
suite_categories=["common", "awsy"]
)
return ret
@PreScriptAction("create-virtualenv")
def _pre_create_virtualenv(self, action):
requirements_files = [
os.path.join(self.testdir, "config", "marionette_requirements.txt")
]
for requirements_file in requirements_files:
self.register_virtualenv_module(requirements=[requirements_file])
self.register_virtualenv_module("awsy", self.awsy_path)
def populate_webroot(self):
"""Populate the production test machines' webroots"""
self.info("Downloading pageset with tooltool...")
manifest_file = os.path.join(self.awsy_path, "tp5n-pageset.manifest")
page_load_test_dir = os.path.join(self.webroot_dir, "page_load_test")
if not os.path.isdir(page_load_test_dir):
self.mkdir_p(page_load_test_dir)
self.tooltool_fetch(
manifest_file,
output_dir=page_load_test_dir,
cache=self.config.get("tooltool_cache"),
)
archive = os.path.join(page_load_test_dir, "tp5n.zip")
unzip = self.query_exe("unzip")
unzip_cmd = [unzip, "-q", "-o", archive, "-d", page_load_test_dir]
self.run_command(unzip_cmd, halt_on_failure=False)
self.run_command("ls %s" % page_load_test_dir)
def run_tests(self, args=None, **kw):
"""
AWSY test should be implemented here
"""
dirs = self.abs_dirs
env = {}
error_summary_file = os.path.join(
dirs["abs_blob_upload_dir"], "marionette_errorsummary.log"
)
runtime_testvars = {
"webRootDir": self.webroot_dir,
"resultsDir": self.results_dir,
"bin": self.binary_path,
}
# Check if this is a DMD build and if so enable it.
dmd_enabled = False
dmd_py_lib_dir = os.path.dirname(self.binary_path)
if mozinfo.os == "mac":
# On mac binary is in MacOS and dmd.py is in Resources, ie:
# Name.app/Contents/MacOS/libdmd.dylib
# Name.app/Contents/Resources/dmd.py
dmd_py_lib_dir = os.path.join(dmd_py_lib_dir, "../Resources/")
dmd_path = os.path.join(dmd_py_lib_dir, "dmd.py")
if self.config["dmd"] and os.path.isfile(dmd_path):
dmd_enabled = True
runtime_testvars["dmd"] = True
# Allow the child process to import dmd.py
python_path = os.environ.get("PYTHONPATH")
if python_path:
os.environ["PYTHONPATH"] = "%s%s%s" % (
python_path,
os.pathsep,
dmd_py_lib_dir,
)
else:
os.environ["PYTHONPATH"] = dmd_py_lib_dir
env["DMD"] = "--mode=dark-matter --stacks=full"
runtime_testvars["tp6"] = self.config["tp6"]
if self.config["tp6"]:
# mitmproxy needs path to mozharness when installing the cert, and tooltool
env["SCRIPTSPATH"] = scripts_path
env["EXTERNALTOOLSPATH"] = external_tools_path
runtime_testvars_path = os.path.join(self.awsy_path, "runtime-testvars.json")
runtime_testvars_file = open(runtime_testvars_path, "wb" if PY2 else "w")
runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
runtime_testvars_file.close()
cmd = ["marionette"]
test_vars_file = None
if self.config["test_about_blank"]:
test_vars_file = "base-testvars.json"
else:
if self.config["tp6"]:
test_vars_file = "tp6-testvars.json"
else:
test_vars_file = "testvars.json"
cmd.append(
"--testvars=%s" % os.path.join(self.awsy_path, "conf", test_vars_file)
)
cmd.append("--testvars=%s" % runtime_testvars_path)
cmd.append("--log-raw=-")
cmd.append("--log-errorsummary=%s" % error_summary_file)
cmd.append("--binary=%s" % self.binary_path)
cmd.append("--profile=%s" % (os.path.join(dirs["abs_work_dir"], "profile")))
if not self.config["e10s"]:
cmd.append("--disable-e10s")
cmd.extend(["--setpref={}".format(p) for p in self.config["extra_prefs"]])
cmd.append(
"--gecko-log=%s" % os.path.join(dirs["abs_blob_upload_dir"], "gecko.log")
)
# TestingMixin._download_and_extract_symbols() should set
# self.symbols_path
cmd.append("--symbols-path=%s" % self.symbols_path)
if self.config["test_about_blank"]:
test_file = os.path.join(self.awsy_libdir, "test_base_memory_usage.py")
prefs_file = "base-prefs.json"
else:
test_file = os.path.join(self.awsy_libdir, "test_memory_usage.py")
if self.config["tp6"]:
prefs_file = "tp6-prefs.json"
else:
prefs_file = "prefs.json"
cmd.append(
"--preferences=%s" % os.path.join(self.awsy_path, "conf", prefs_file)
)
if dmd_enabled:
cmd.append("--setpref=security.sandbox.content.level=0")
cmd.append("--setpref=layout.css.stylo-threads=4")
cmd.append(test_file)
env["MOZ_UPLOAD_DIR"] = dirs["abs_blob_upload_dir"]
if not os.path.isdir(env["MOZ_UPLOAD_DIR"]):
self.mkdir_p(env["MOZ_UPLOAD_DIR"])
if self.query_minidump_stackwalk():
env["MINIDUMP_STACKWALK"] = self.minidump_stackwalk_path
env["MINIDUMP_SAVE_PATH"] = dirs["abs_blob_upload_dir"]
env["RUST_BACKTRACE"] = "1"
env = self.query_env(partial_env=env)
parser = StructuredOutputParser(
config=self.config,
log_obj=self.log_obj,
error_list=self.error_list,
strict=False,
)
return_code = self.run_command(
command=cmd,
cwd=self.awsy_path,
output_timeout=self.config.get("cmd_timeout"),
env=env,
output_parser=parser,
)
level = INFO
tbpl_status, log_level, summary = parser.evaluate_parser(
return_code=return_code
)
self.log(
"AWSY exited with return code %s: %s" % (return_code, tbpl_status),
level=level,
)
self.record_status(tbpl_status)
if __name__ == "__main__":
awsy_test = AWSY()
awsy_test.run_and_exit()
|