| 1 |
#!/usr/bin/env python |
| 2 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 |
# You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 |
""" |
| 6 |
run awsy tests in a virtualenv |
| 7 |
""" |
| 8 |
|
| 9 |
import copy |
| 10 |
import json |
| 11 |
import os |
| 12 |
import re |
| 13 |
import sys |
| 14 |
|
| 15 |
# load modules from parent dir |
| 16 |
sys.path.insert(1, os.path.dirname(sys.path[0])) |
| 17 |
|
| 18 |
import mozharness |
| 19 |
import mozinfo |
| 20 |
from mozharness.base.log import ERROR, INFO |
| 21 |
from mozharness.base.script import PreScriptAction |
| 22 |
from mozharness.base.vcs.vcsbase import MercurialScript |
| 23 |
from mozharness.mozilla.structuredlog import StructuredOutputParser |
| 24 |
from mozharness.mozilla.testing.codecoverage import ( |
| 25 |
CodeCoverageMixin, |
| 26 |
code_coverage_config_options, |
| 27 |
) |
| 28 |
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options |
| 29 |
from mozharness.mozilla.tooltool import TooltoolMixin |
| 30 |
|
| 31 |
PY2 = sys.version_info.major == 2 |
| 32 |
scripts_path = os.path.abspath(os.path.dirname(os.path.dirname(mozharness.__file__))) |
| 33 |
external_tools_path = os.path.join(scripts_path, "external_tools") |
| 34 |
|
| 35 |
|
| 36 |
class AWSY(TestingMixin, MercurialScript, TooltoolMixin, CodeCoverageMixin): |
| 37 |
config_options = ( |
| 38 |
[ |
| 39 |
[ |
| 40 |
["--disable-e10s"], |
| 41 |
{ |
| 42 |
"action": "store_false", |
| 43 |
"dest": "e10s", |
| 44 |
"default": True, |
| 45 |
"help": "Run tests without multiple processes (e10s). (Desktop builds only)", |
| 46 |
}, |
| 47 |
], |
| 48 |
[ |
| 49 |
["--setpref"], |
| 50 |
{ |
| 51 |
"action": "append", |
| 52 |
"dest": "extra_prefs", |
| 53 |
"default": [], |
| 54 |
"help": "Extra user prefs.", |
| 55 |
}, |
| 56 |
], |
| 57 |
[ |
| 58 |
["--base"], |
| 59 |
{ |
| 60 |
"action": "store_true", |
| 61 |
"dest": "test_about_blank", |
| 62 |
"default": False, |
| 63 |
"help": "Runs the about:blank base case memory test.", |
| 64 |
}, |
| 65 |
], |
| 66 |
[ |
| 67 |
["--dmd"], |
| 68 |
{ |
| 69 |
"action": "store_true", |
| 70 |
"dest": "dmd", |
| 71 |
"default": False, |
| 72 |
"help": "Runs tests with DMD enabled.", |
| 73 |
}, |
| 74 |
], |
| 75 |
[ |
| 76 |
["--tp5"], |
| 77 |
{ |
| 78 |
"action": "store_true", |
| 79 |
"dest": "tp5", |
| 80 |
"default": False, |
| 81 |
"help": "Runs tests with the tp5 pageset.", |
| 82 |
}, |
| 83 |
], |
| 84 |
] |
| 85 |
+ testing_config_options |
| 86 |
+ copy.deepcopy(code_coverage_config_options) |
| 87 |
) |
| 88 |
|
| 89 |
error_list = [ |
| 90 |
{"regex": re.compile(r"""(TEST-UNEXPECTED|PROCESS-CRASH)"""), "level": ERROR}, |
| 91 |
] |
| 92 |
|
| 93 |
def __init__(self, **kwargs): |
| 94 |
kwargs.setdefault("config_options", self.config_options) |
| 95 |
kwargs.setdefault( |
| 96 |
"all_actions", |
| 97 |
[ |
| 98 |
"clobber", |
| 99 |
"download-and-extract", |
| 100 |
"populate-webroot", |
| 101 |
"create-virtualenv", |
| 102 |
"install", |
| 103 |
"run-tests", |
| 104 |
], |
| 105 |
) |
| 106 |
kwargs.setdefault( |
| 107 |
"default_actions", |
| 108 |
[ |
| 109 |
"clobber", |
| 110 |
"download-and-extract", |
| 111 |
"populate-webroot", |
| 112 |
"create-virtualenv", |
| 113 |
"install", |
| 114 |
"run-tests", |
| 115 |
], |
| 116 |
) |
| 117 |
kwargs.setdefault("config", {}) |
| 118 |
super(AWSY, self).__init__(**kwargs) |
| 119 |
self.installer_url = self.config.get("installer_url") |
| 120 |
self.tests = None |
| 121 |
|
| 122 |
self.testdir = self.query_abs_dirs()["abs_test_install_dir"] |
| 123 |
self.awsy_path = os.path.join(self.testdir, "awsy") |
| 124 |
self.awsy_libdir = os.path.join(self.awsy_path, "awsy") |
| 125 |
self.webroot_dir = os.path.join(self.testdir, "html") |
| 126 |
self.results_dir = os.path.join(self.testdir, "results") |
| 127 |
self.binary_path = self.config.get("binary_path") |
| 128 |
|
| 129 |
def query_abs_dirs(self): |
| 130 |
if self.abs_dirs: |
| 131 |
return self.abs_dirs |
| 132 |
abs_dirs = super(AWSY, self).query_abs_dirs() |
| 133 |
|
| 134 |
dirs = {} |
| 135 |
dirs["abs_blob_upload_dir"] = os.path.join( |
| 136 |
abs_dirs["abs_work_dir"], "blobber_upload_dir" |
| 137 |
) |
| 138 |
dirs["abs_test_install_dir"] = os.path.join(abs_dirs["abs_work_dir"], "tests") |
| 139 |
abs_dirs.update(dirs) |
| 140 |
self.abs_dirs = abs_dirs |
| 141 |
return self.abs_dirs |
| 142 |
|
| 143 |
def download_and_extract(self, extract_dirs=None, suite_categories=None): |
| 144 |
ret = super(AWSY, self).download_and_extract( |
| 145 |
suite_categories=["common", "awsy"] |
| 146 |
) |
| 147 |
return ret |
| 148 |
|
| 149 |
@PreScriptAction("create-virtualenv") |
| 150 |
def _pre_create_virtualenv(self, action): |
| 151 |
requirements_files = [ |
| 152 |
os.path.join(self.testdir, "config", "marionette_requirements.txt") |
| 153 |
] |
| 154 |
|
| 155 |
for requirements_file in requirements_files: |
| 156 |
self.register_virtualenv_module(requirements=[requirements_file]) |
| 157 |
|
| 158 |
self.register_virtualenv_module("awsy", self.awsy_path) |
| 159 |
|
| 160 |
def populate_webroot(self): |
| 161 |
"""Populate the production test machines' webroots""" |
| 162 |
self.info("Downloading pageset with tooltool...") |
| 163 |
manifest_file = os.path.join(self.awsy_path, "tp5n-pageset.manifest") |
| 164 |
page_load_test_dir = os.path.join(self.webroot_dir, "page_load_test") |
| 165 |
if not os.path.isdir(page_load_test_dir): |
| 166 |
self.mkdir_p(page_load_test_dir) |
| 167 |
self.tooltool_fetch( |
| 168 |
manifest_file, |
| 169 |
output_dir=page_load_test_dir, |
| 170 |
cache=self.config.get("tooltool_cache"), |
| 171 |
) |
| 172 |
archive = os.path.join(page_load_test_dir, "tp5n.zip") |
| 173 |
unzip = self.query_exe("unzip") |
| 174 |
unzip_cmd = [unzip, "-q", "-o", archive, "-d", page_load_test_dir] |
| 175 |
self.run_command(unzip_cmd, halt_on_failure=False) |
| 176 |
self.run_command("ls %s" % page_load_test_dir) |
| 177 |
|
| 178 |
def run_tests(self, args=None, **kw): |
| 179 |
""" |
| 180 |
AWSY test should be implemented here |
| 181 |
""" |
| 182 |
dirs = self.abs_dirs |
| 183 |
env = {} |
| 184 |
error_summary_file = os.path.join( |
| 185 |
dirs["abs_blob_upload_dir"], "marionette_errorsummary.log" |
| 186 |
) |
| 187 |
|
| 188 |
runtime_testvars = { |
| 189 |
"webRootDir": self.webroot_dir, |
| 190 |
"resultsDir": self.results_dir, |
| 191 |
"bin": self.binary_path, |
| 192 |
} |
| 193 |
|
| 194 |
# Check if this is a DMD build and if so enable it. |
| 195 |
dmd_enabled = False |
| 196 |
dmd_py_lib_dir = os.path.dirname(self.binary_path) |
| 197 |
if mozinfo.os == "mac": |
| 198 |
# On mac binary is in MacOS and dmd.py is in Resources, ie: |
| 199 |
# Name.app/Contents/MacOS/libdmd.dylib |
| 200 |
# Name.app/Contents/Resources/dmd.py |
| 201 |
dmd_py_lib_dir = os.path.join(dmd_py_lib_dir, "../Resources/") |
| 202 |
|
| 203 |
dmd_path = os.path.join(dmd_py_lib_dir, "dmd.py") |
| 204 |
if self.config["dmd"] and os.path.isfile(dmd_path): |
| 205 |
dmd_enabled = True |
| 206 |
runtime_testvars["dmd"] = True |
| 207 |
|
| 208 |
# Allow the child process to import dmd.py |
| 209 |
python_path = os.environ.get("PYTHONPATH") |
| 210 |
|
| 211 |
if python_path: |
| 212 |
os.environ["PYTHONPATH"] = "%s%s%s" % ( |
| 213 |
python_path, |
| 214 |
os.pathsep, |
| 215 |
dmd_py_lib_dir, |
| 216 |
) |
| 217 |
else: |
| 218 |
os.environ["PYTHONPATH"] = dmd_py_lib_dir |
| 219 |
|
| 220 |
env["DMD"] = "--mode=dark-matter --stacks=full" |
| 221 |
|
| 222 |
runtime_testvars["tp5"] = self.config["tp5"] |
| 223 |
if not self.config["tp5"]: |
| 224 |
# mitmproxy needs path to mozharness when installing the cert, and tooltool |
| 225 |
env["SCRIPTSPATH"] = scripts_path |
| 226 |
env["EXTERNALTOOLSPATH"] = external_tools_path |
| 227 |
|
| 228 |
runtime_testvars_path = os.path.join(self.awsy_path, "runtime-testvars.json") |
| 229 |
runtime_testvars_file = open(runtime_testvars_path, "wb" if PY2 else "w") |
| 230 |
runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2)) |
| 231 |
runtime_testvars_file.close() |
| 232 |
|
| 233 |
cmd = ["marionette"] |
| 234 |
|
| 235 |
test_vars_file = None |
| 236 |
if self.config["test_about_blank"]: |
| 237 |
test_vars_file = "base-testvars.json" |
| 238 |
else: |
| 239 |
test_vars_file = "tp6-testvars.json" |
| 240 |
if self.config["tp5"]: |
| 241 |
test_vars_file = "testvars.json" |
| 242 |
|
| 243 |
cmd.append( |
| 244 |
"--testvars=%s" % os.path.join(self.awsy_path, "conf", test_vars_file) |
| 245 |
) |
| 246 |
cmd.append("--testvars=%s" % runtime_testvars_path) |
| 247 |
cmd.append("--log-raw=-") |
| 248 |
cmd.append("--log-errorsummary=%s" % error_summary_file) |
| 249 |
cmd.append("--binary=%s" % self.binary_path) |
| 250 |
cmd.append("--profile=%s" % (os.path.join(dirs["abs_work_dir"], "profile"))) |
| 251 |
if not self.config["e10s"]: |
| 252 |
cmd.append("--disable-e10s") |
| 253 |
cmd.extend([f"--setpref={p}" for p in self.config["extra_prefs"]]) |
| 254 |
cmd.append( |
| 255 |
"--gecko-log=%s" % os.path.join(dirs["abs_blob_upload_dir"], "gecko.log") |
| 256 |
) |
| 257 |
# TestingMixin._download_and_extract_symbols() should set |
| 258 |
# self.symbols_path |
| 259 |
cmd.append("--symbols-path=%s" % self.symbols_path) |
| 260 |
|
| 261 |
if self.config["test_about_blank"]: |
| 262 |
test_file = os.path.join(self.awsy_libdir, "test_base_memory_usage.py") |
| 263 |
prefs_file = "base-prefs.json" |
| 264 |
else: |
| 265 |
test_file = os.path.join(self.awsy_libdir, "test_memory_usage.py") |
| 266 |
prefs_file = "tp6-prefs.json" |
| 267 |
if self.config["tp5"]: |
| 268 |
prefs_file = "prefs.json" |
| 269 |
|
| 270 |
cmd.append( |
| 271 |
"--preferences=%s" % os.path.join(self.awsy_path, "conf", prefs_file) |
| 272 |
) |
| 273 |
if dmd_enabled: |
| 274 |
cmd.append("--setpref=security.sandbox.content.level=0") |
| 275 |
cmd.append("--setpref=layout.css.stylo-threads=4") |
| 276 |
|
| 277 |
cmd.append(test_file) |
| 278 |
|
| 279 |
env["MOZ_UPLOAD_DIR"] = dirs["abs_blob_upload_dir"] |
| 280 |
if not os.path.isdir(env["MOZ_UPLOAD_DIR"]): |
| 281 |
self.mkdir_p(env["MOZ_UPLOAD_DIR"]) |
| 282 |
if self.query_minidump_stackwalk(): |
| 283 |
env["MINIDUMP_STACKWALK"] = self.minidump_stackwalk_path |
| 284 |
env["MINIDUMP_SAVE_PATH"] = dirs["abs_blob_upload_dir"] |
| 285 |
env["RUST_BACKTRACE"] = "1" |
| 286 |
env = self.query_env(partial_env=env) |
| 287 |
parser = StructuredOutputParser( |
| 288 |
config=self.config, |
| 289 |
log_obj=self.log_obj, |
| 290 |
error_list=self.error_list, |
| 291 |
strict=False, |
| 292 |
) |
| 293 |
return_code = self.run_command( |
| 294 |
command=cmd, |
| 295 |
cwd=self.awsy_path, |
| 296 |
output_timeout=self.config.get("cmd_timeout"), |
| 297 |
env=env, |
| 298 |
output_parser=parser, |
| 299 |
) |
| 300 |
|
| 301 |
level = INFO |
| 302 |
tbpl_status, log_level, summary = parser.evaluate_parser( |
| 303 |
return_code=return_code |
| 304 |
) |
| 305 |
|
| 306 |
self.log( |
| 307 |
"AWSY exited with return code %s: %s" % (return_code, tbpl_status), |
| 308 |
level=level, |
| 309 |
) |
| 310 |
self.record_status(tbpl_status) |
| 311 |
|
| 312 |
|
| 313 |
if __name__ == "__main__": |
| 314 |
awsy_test = AWSY() |
| 315 |
awsy_test.run_and_exit() |