| 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 |
import copy |
| 6 |
import gzip |
| 7 |
import json |
| 8 |
import os |
| 9 |
import sys |
| 10 |
from datetime import datetime, timedelta |
| 11 |
|
| 12 |
# load modules from parent dir |
| 13 |
sys.path.insert(1, os.path.dirname(sys.path[0])) |
| 14 |
|
| 15 |
import mozinfo |
| 16 |
from mozharness.base.errors import BaseErrorList |
| 17 |
from mozharness.base.log import INFO |
| 18 |
from mozharness.base.script import PreScriptAction |
| 19 |
from mozharness.base.vcs.vcsbase import MercurialScript |
| 20 |
from mozharness.mozilla.automation import TBPL_RETRY |
| 21 |
from mozharness.mozilla.structuredlog import StructuredOutputParser |
| 22 |
from mozharness.mozilla.testing.android import AndroidMixin |
| 23 |
from mozharness.mozilla.testing.codecoverage import ( |
| 24 |
CodeCoverageMixin, |
| 25 |
code_coverage_config_options, |
| 26 |
) |
| 27 |
from mozharness.mozilla.testing.errors import WptHarnessErrorList |
| 28 |
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options |
| 29 |
|
| 30 |
|
| 31 |
class WebPlatformTest(TestingMixin, MercurialScript, CodeCoverageMixin, AndroidMixin): |
| 32 |
config_options = ( |
| 33 |
[ |
| 34 |
[ |
| 35 |
["--test-type"], |
| 36 |
{ |
| 37 |
"action": "extend", |
| 38 |
"dest": "test_type", |
| 39 |
"help": "Specify the test types to run.", |
| 40 |
}, |
| 41 |
], |
| 42 |
[ |
| 43 |
["--disable-e10s"], |
| 44 |
{ |
| 45 |
"action": "store_false", |
| 46 |
"dest": "e10s", |
| 47 |
"default": True, |
| 48 |
"help": "Run without e10s enabled", |
| 49 |
}, |
| 50 |
], |
| 51 |
[ |
| 52 |
["--disable-fission"], |
| 53 |
{ |
| 54 |
"action": "store_true", |
| 55 |
"dest": "disable_fission", |
| 56 |
"default": False, |
| 57 |
"help": "Run without fission enabled", |
| 58 |
}, |
| 59 |
], |
| 60 |
[ |
| 61 |
["--total-chunks"], |
| 62 |
{ |
| 63 |
"action": "store", |
| 64 |
"dest": "total_chunks", |
| 65 |
"help": "Number of total chunks", |
| 66 |
}, |
| 67 |
], |
| 68 |
[ |
| 69 |
["--this-chunk"], |
| 70 |
{ |
| 71 |
"action": "store", |
| 72 |
"dest": "this_chunk", |
| 73 |
"help": "Number of this chunk", |
| 74 |
}, |
| 75 |
], |
| 76 |
[ |
| 77 |
["--allow-software-gl-layers"], |
| 78 |
{ |
| 79 |
"action": "store_true", |
| 80 |
"dest": "allow_software_gl_layers", |
| 81 |
"default": False, |
| 82 |
"help": "Permits a software GL implementation (such as LLVMPipe) " |
| 83 |
"to use the GL compositor.", |
| 84 |
}, |
| 85 |
], |
| 86 |
[ |
| 87 |
["--headless"], |
| 88 |
{ |
| 89 |
"action": "store_true", |
| 90 |
"dest": "headless", |
| 91 |
"default": False, |
| 92 |
"help": "Run tests in headless mode.", |
| 93 |
}, |
| 94 |
], |
| 95 |
[ |
| 96 |
["--headless-width"], |
| 97 |
{ |
| 98 |
"action": "store", |
| 99 |
"dest": "headless_width", |
| 100 |
"default": "1600", |
| 101 |
"help": "Specify headless virtual screen width (default: 1600).", |
| 102 |
}, |
| 103 |
], |
| 104 |
[ |
| 105 |
["--headless-height"], |
| 106 |
{ |
| 107 |
"action": "store", |
| 108 |
"dest": "headless_height", |
| 109 |
"default": "1200", |
| 110 |
"help": "Specify headless virtual screen height (default: 1200).", |
| 111 |
}, |
| 112 |
], |
| 113 |
[ |
| 114 |
["--setpref"], |
| 115 |
{ |
| 116 |
"action": "append", |
| 117 |
"metavar": "PREF=VALUE", |
| 118 |
"dest": "extra_prefs", |
| 119 |
"default": [], |
| 120 |
"help": "Defines an extra user preference.", |
| 121 |
}, |
| 122 |
], |
| 123 |
[ |
| 124 |
["--skip-implementation-status"], |
| 125 |
{ |
| 126 |
"action": "extend", |
| 127 |
"dest": "skip_implementation_status", |
| 128 |
"default": [], |
| 129 |
"help": "Defines a way to not run a specific implementation status " |
| 130 |
" (i.e. not implemented).", |
| 131 |
}, |
| 132 |
], |
| 133 |
[ |
| 134 |
["--backlog"], |
| 135 |
{ |
| 136 |
"action": "store_true", |
| 137 |
"dest": "backlog", |
| 138 |
"default": False, |
| 139 |
"help": "Defines if test category is backlog.", |
| 140 |
}, |
| 141 |
], |
| 142 |
[ |
| 143 |
["--skip-timeout"], |
| 144 |
{ |
| 145 |
"action": "store_true", |
| 146 |
"dest": "skip_timeout", |
| 147 |
"default": False, |
| 148 |
"help": "Ignore tests that are expected status of TIMEOUT", |
| 149 |
}, |
| 150 |
], |
| 151 |
[ |
| 152 |
["--skip-crash"], |
| 153 |
{ |
| 154 |
"action": "store_true", |
| 155 |
"dest": "skip_crash", |
| 156 |
"default": False, |
| 157 |
"help": "Ignore tests that are expected status of CRASH", |
| 158 |
}, |
| 159 |
], |
| 160 |
[ |
| 161 |
["--default-exclude"], |
| 162 |
{ |
| 163 |
"action": "store_true", |
| 164 |
"dest": "default_exclude", |
| 165 |
"default": False, |
| 166 |
"help": "Only run the tests explicitly given in arguments", |
| 167 |
}, |
| 168 |
], |
| 169 |
[ |
| 170 |
["--include"], |
| 171 |
{ |
| 172 |
"action": "append", |
| 173 |
"dest": "include", |
| 174 |
"default": [], |
| 175 |
"help": "Add URL prefix to include.", |
| 176 |
}, |
| 177 |
], |
| 178 |
[ |
| 179 |
["--exclude"], |
| 180 |
{ |
| 181 |
"action": "append", |
| 182 |
"dest": "exclude", |
| 183 |
"default": [], |
| 184 |
"help": "Add URL prefix to exclude.", |
| 185 |
}, |
| 186 |
], |
| 187 |
[ |
| 188 |
["--tag"], |
| 189 |
{ |
| 190 |
"action": "append", |
| 191 |
"dest": "tag", |
| 192 |
"default": [], |
| 193 |
"help": "Add test tag (which includes URL prefix) to include.", |
| 194 |
}, |
| 195 |
], |
| 196 |
[ |
| 197 |
["--exclude-tag"], |
| 198 |
{ |
| 199 |
"action": "append", |
| 200 |
"dest": "exclude_tag", |
| 201 |
"default": [], |
| 202 |
"help": "Add test tag (which includes URL prefix) to exclude.", |
| 203 |
}, |
| 204 |
], |
| 205 |
[ |
| 206 |
["--repeat"], |
| 207 |
{ |
| 208 |
"action": "store", |
| 209 |
"dest": "repeat", |
| 210 |
"default": 0, |
| 211 |
"type": int, |
| 212 |
"help": "Repeat tests (used for confirm-failures) X times.", |
| 213 |
}, |
| 214 |
], |
| 215 |
[ |
| 216 |
["--timeout-multiplier"], |
| 217 |
{ |
| 218 |
"action": "store", |
| 219 |
"dest": "timeout_multiplier", |
| 220 |
"type": float, |
| 221 |
"help": "Sets the timeout multiplier (0.25 for `--backlog` tests by default)", |
| 222 |
}, |
| 223 |
], |
| 224 |
] |
| 225 |
+ copy.deepcopy(testing_config_options) |
| 226 |
+ copy.deepcopy(code_coverage_config_options) |
| 227 |
) |
| 228 |
|
| 229 |
def __init__(self, require_config_file=True): |
| 230 |
super(WebPlatformTest, self).__init__( |
| 231 |
config_options=self.config_options, |
| 232 |
all_actions=[ |
| 233 |
"clobber", |
| 234 |
"download-and-extract", |
| 235 |
"download-and-process-manifest", |
| 236 |
"create-virtualenv", |
| 237 |
"pull", |
| 238 |
"start-emulator", |
| 239 |
"verify-device", |
| 240 |
"install", |
| 241 |
"run-tests", |
| 242 |
], |
| 243 |
require_config_file=require_config_file, |
| 244 |
config={"require_test_zip": True}, |
| 245 |
) |
| 246 |
|
| 247 |
# Surely this should be in the superclass |
| 248 |
c = self.config |
| 249 |
self.installer_url = c.get("installer_url") |
| 250 |
self.test_url = c.get("test_url") |
| 251 |
self.test_packages_url = c.get("test_packages_url") |
| 252 |
self.installer_path = c.get("installer_path") |
| 253 |
self.binary_path = c.get("binary_path") |
| 254 |
self.repeat = c.get("repeat") |
| 255 |
self.abs_app_dir = None |
| 256 |
self.xre_path = None |
| 257 |
if self.is_emulator: |
| 258 |
self.device_serial = "emulator-5554" |
| 259 |
|
| 260 |
def query_abs_app_dir(self): |
| 261 |
"""We can't set this in advance, because OSX install directories |
| 262 |
change depending on branding and opt/debug. |
| 263 |
""" |
| 264 |
if self.abs_app_dir: |
| 265 |
return self.abs_app_dir |
| 266 |
if not self.binary_path: |
| 267 |
self.fatal("Can't determine abs_app_dir (binary_path not set!)") |
| 268 |
self.abs_app_dir = os.path.dirname(self.binary_path) |
| 269 |
return self.abs_app_dir |
| 270 |
|
| 271 |
def query_abs_dirs(self): |
| 272 |
if self.abs_dirs: |
| 273 |
return self.abs_dirs |
| 274 |
abs_dirs = super(WebPlatformTest, self).query_abs_dirs() |
| 275 |
|
| 276 |
dirs = {} |
| 277 |
dirs["abs_app_install_dir"] = os.path.join( |
| 278 |
abs_dirs["abs_work_dir"], "application" |
| 279 |
) |
| 280 |
dirs["abs_test_install_dir"] = os.path.join(abs_dirs["abs_work_dir"], "tests") |
| 281 |
dirs["abs_test_bin_dir"] = os.path.join(dirs["abs_test_install_dir"], "bin") |
| 282 |
dirs["abs_wpttest_dir"] = os.path.join( |
| 283 |
dirs["abs_test_install_dir"], "web-platform" |
| 284 |
) |
| 285 |
dirs["abs_blob_upload_dir"] = os.path.join( |
| 286 |
abs_dirs["abs_work_dir"], "blobber_upload_dir" |
| 287 |
) |
| 288 |
dirs["abs_test_extensions_dir"] = os.path.join( |
| 289 |
dirs["abs_test_install_dir"], "extensions" |
| 290 |
) |
| 291 |
work_dir = os.environ.get("MOZ_FETCHES_DIR") or abs_dirs["abs_work_dir"] |
| 292 |
if self.is_android: |
| 293 |
dirs["abs_xre_dir"] = os.path.join(work_dir, "hostutils") |
| 294 |
if self.is_emulator: |
| 295 |
dirs["abs_sdk_dir"] = os.path.join(work_dir, "android-sdk-linux") |
| 296 |
dirs["abs_avds_dir"] = os.path.join(work_dir, "android-device") |
| 297 |
dirs["abs_bundletool_path"] = os.path.join(work_dir, "bundletool.jar") |
| 298 |
# AndroidMixin uses this when launching the emulator. We only want |
| 299 |
# GLES3 if we're running WebRender (default) |
| 300 |
self.use_gles3 = True |
| 301 |
|
| 302 |
abs_dirs.update(dirs) |
| 303 |
self.abs_dirs = abs_dirs |
| 304 |
|
| 305 |
return self.abs_dirs |
| 306 |
|
| 307 |
@PreScriptAction("create-virtualenv") |
| 308 |
def _pre_create_virtualenv(self, action): |
| 309 |
dirs = self.query_abs_dirs() |
| 310 |
|
| 311 |
requirements = os.path.join( |
| 312 |
dirs["abs_test_install_dir"], "config", "marionette_requirements.txt" |
| 313 |
) |
| 314 |
|
| 315 |
self.register_virtualenv_module(requirements=[requirements]) |
| 316 |
|
| 317 |
webtransport_requirements = os.path.join( |
| 318 |
dirs["abs_test_install_dir"], |
| 319 |
"web-platform", |
| 320 |
"tests", |
| 321 |
"tools", |
| 322 |
"webtransport", |
| 323 |
"requirements.txt", |
| 324 |
) |
| 325 |
|
| 326 |
self.register_virtualenv_module(requirements=[webtransport_requirements]) |
| 327 |
|
| 328 |
def _query_geckodriver(self): |
| 329 |
path = None |
| 330 |
c = self.config |
| 331 |
dirs = self.query_abs_dirs() |
| 332 |
repl_dict = {} |
| 333 |
repl_dict.update(dirs) |
| 334 |
path = c.get("geckodriver", "geckodriver") |
| 335 |
if path: |
| 336 |
path = path % repl_dict |
| 337 |
return path |
| 338 |
|
| 339 |
def _query_cmd(self, test_types): |
| 340 |
if not self.binary_path: |
| 341 |
self.fatal("Binary path could not be determined") |
| 342 |
# And exit |
| 343 |
|
| 344 |
c = self.config |
| 345 |
run_file_name = "runtests.py" |
| 346 |
|
| 347 |
dirs = self.query_abs_dirs() |
| 348 |
abs_app_dir = self.query_abs_app_dir() |
| 349 |
str_format_values = { |
| 350 |
"binary_path": self.binary_path, |
| 351 |
"test_path": dirs["abs_wpttest_dir"], |
| 352 |
"test_install_path": dirs["abs_test_install_dir"], |
| 353 |
"abs_app_dir": abs_app_dir, |
| 354 |
"abs_work_dir": dirs["abs_work_dir"], |
| 355 |
"xre_path": self.xre_path, |
| 356 |
} |
| 357 |
|
| 358 |
cmd = [self.query_python_path("python"), "-u"] |
| 359 |
cmd.append(os.path.join(dirs["abs_wpttest_dir"], run_file_name)) |
| 360 |
|
| 361 |
mozinfo.find_and_update_from_json(dirs["abs_test_install_dir"]) |
| 362 |
|
| 363 |
raw_log_file, error_summary_file = self.get_indexed_logs( |
| 364 |
dirs["abs_blob_upload_dir"], "wpt" |
| 365 |
) |
| 366 |
|
| 367 |
cmd += [ |
| 368 |
"--log-raw=-", |
| 369 |
"--log-wptreport=%s" |
| 370 |
% os.path.join(dirs["abs_blob_upload_dir"], "wptreport.json"), |
| 371 |
"--log-errorsummary=%s" % error_summary_file, |
| 372 |
"--symbols-path=%s" % self.symbols_path, |
| 373 |
"--stackwalk-binary=%s" % self.query_minidump_stackwalk(), |
| 374 |
"--stackfix-dir=%s" % os.path.join(dirs["abs_test_install_dir"], "bin"), |
| 375 |
"--no-pause-after-test", |
| 376 |
"--instrument-to-file=%s" |
| 377 |
% os.path.join(dirs["abs_blob_upload_dir"], "wpt_instruments.txt"), |
| 378 |
"--specialpowers-path=%s" |
| 379 |
% os.path.join( |
| 380 |
dirs["abs_test_extensions_dir"], "[email protected]" |
| 381 |
), |
| 382 |
# Ensure that we don't get a Python traceback from handlers that will be |
| 383 |
# added to the log summary |
| 384 |
"--suppress-handler-traceback", |
| 385 |
] |
| 386 |
|
| 387 |
if self.repeat > 0: |
| 388 |
# repeat should repeat the original test, so +1 for first run |
| 389 |
cmd.append("--repeat=%s" % (self.repeat + 1)) |
| 390 |
|
| 391 |
if ( |
| 392 |
self.is_android |
| 393 |
or mozinfo.info["tsan"] |
| 394 |
or "wdspec" in test_types |
| 395 |
or not c["disable_fission"] |
| 396 |
# reftest on osx needs to be 1 process |
| 397 |
or "reftest" in test_types |
| 398 |
and sys.platform.startswith("darwin") |
| 399 |
): |
| 400 |
processes = 1 |
| 401 |
else: |
| 402 |
processes = 2 |
| 403 |
cmd.append("--processes=%s" % processes) |
| 404 |
|
| 405 |
if self.is_android: |
| 406 |
cmd += [ |
| 407 |
"--device-serial=%s" % self.device_serial, |
| 408 |
"--package-name=%s" % self.query_package_name(), |
| 409 |
"--product=firefox_android", |
| 410 |
] |
| 411 |
else: |
| 412 |
cmd += ["--binary=%s" % self.binary_path, "--product=firefox"] |
| 413 |
|
| 414 |
cmd += ["--install-fonts"] |
| 415 |
|
| 416 |
for test_type in test_types: |
| 417 |
cmd.append("--test-type=%s" % test_type) |
| 418 |
|
| 419 |
if c["extra_prefs"]: |
| 420 |
cmd.extend([f"--setpref={p}" for p in c["extra_prefs"]]) |
| 421 |
|
| 422 |
if c["disable_fission"]: |
| 423 |
cmd.append("--disable-fission") |
| 424 |
|
| 425 |
if not c["e10s"]: |
| 426 |
cmd.append("--disable-e10s") |
| 427 |
|
| 428 |
if c["skip_timeout"]: |
| 429 |
cmd.append("--skip-timeout") |
| 430 |
|
| 431 |
if c["skip_crash"]: |
| 432 |
cmd.append("--skip-crash") |
| 433 |
|
| 434 |
if c["default_exclude"]: |
| 435 |
cmd.append("--default-exclude") |
| 436 |
|
| 437 |
for implementation_status in c["skip_implementation_status"]: |
| 438 |
cmd.append("--skip-implementation-status=%s" % implementation_status) |
| 439 |
|
| 440 |
# Bug 1643177 - reduce timeout multiplier for web-platform-tests backlog |
| 441 |
if "timeout_multiplier" in c: |
| 442 |
cmd.append("--timeout-multiplier=%s" % c["timeout_multiplier"]) |
| 443 |
elif c["backlog"]: |
| 444 |
cmd.append("--timeout-multiplier=0.25") |
| 445 |
|
| 446 |
test_paths = set() |
| 447 |
if not (self.verify_enabled or self.per_test_coverage): |
| 448 |
# mozharness_test_paths is a set of test groups (directories) to run |
| 449 |
# if we have confirm_paths, this is a specific path we want to run and ignore the group |
| 450 |
mozharness_test_paths = json.loads( |
| 451 |
os.environ.get("MOZHARNESS_TEST_PATHS", '""') |
| 452 |
) |
| 453 |
confirm_paths = json.loads(os.environ.get("MOZHARNESS_CONFIRM_PATHS", '""')) |
| 454 |
|
| 455 |
if mozharness_test_paths: |
| 456 |
if confirm_paths: |
| 457 |
mozharness_test_paths = confirm_paths |
| 458 |
|
| 459 |
path = os.path.join(dirs["abs_fetches_dir"], "wpt_tests_by_group.json") |
| 460 |
|
| 461 |
if not os.path.exists(path): |
| 462 |
self.critical("Unable to locate web-platform-test groups file.") |
| 463 |
|
| 464 |
cmd.append(f"--test-groups={path}") |
| 465 |
|
| 466 |
for key in mozharness_test_paths.keys(): |
| 467 |
if "web-platform" not in key: |
| 468 |
self.info(f"Ignoring test_paths for {key} harness") |
| 469 |
continue |
| 470 |
paths = mozharness_test_paths.get(key, []) |
| 471 |
for p in paths: |
| 472 |
if not p.startswith("/"): |
| 473 |
# Assume this is a filesystem path rather than a test id |
| 474 |
path = os.path.relpath(p, "testing/web-platform") |
| 475 |
if ".." in path: |
| 476 |
self.fatal(f"Invalid WPT path: {path}") |
| 477 |
path = os.path.join(dirs["abs_wpttest_dir"], path) |
| 478 |
else: |
| 479 |
path = p |
| 480 |
|
| 481 |
test_paths.add(path) |
| 482 |
else: |
| 483 |
# As per WPT harness, the --run-by-dir flag is incompatible with |
| 484 |
# the --test-groups flag. |
| 485 |
cmd.append("--run-by-dir=%i" % (3 if not mozinfo.info["asan"] else 0)) |
| 486 |
for opt in ["total_chunks", "this_chunk"]: |
| 487 |
val = c.get(opt) |
| 488 |
if val: |
| 489 |
cmd.append("--%s=%s" % (opt.replace("_", "-"), val)) |
| 490 |
|
| 491 |
options = list(c.get("options", [])) |
| 492 |
|
| 493 |
if "wdspec" in test_types: |
| 494 |
geckodriver_path = self._query_geckodriver() |
| 495 |
if not geckodriver_path or not os.path.isfile(geckodriver_path): |
| 496 |
self.fatal( |
| 497 |
"Unable to find geckodriver binary " |
| 498 |
"in common test package: %s" % str(geckodriver_path) |
| 499 |
) |
| 500 |
cmd.append("--webdriver-binary=%s" % geckodriver_path) |
| 501 |
cmd.append("--webdriver-arg=-vv") # enable trace logs |
| 502 |
|
| 503 |
test_type_suite = { |
| 504 |
"testharness": "web-platform-tests", |
| 505 |
"crashtest": "web-platform-tests-crashtest", |
| 506 |
"print-reftest": "web-platform-tests-print-reftest", |
| 507 |
"reftest": "web-platform-tests-reftest", |
| 508 |
"wdspec": "web-platform-tests-wdspec", |
| 509 |
} |
| 510 |
for test_type in test_types: |
| 511 |
try_options, try_tests = self.try_args(test_type_suite[test_type]) |
| 512 |
|
| 513 |
cmd.extend( |
| 514 |
self.query_options( |
| 515 |
options, try_options, str_format_values=str_format_values |
| 516 |
) |
| 517 |
) |
| 518 |
cmd.extend( |
| 519 |
self.query_tests_args(try_tests, str_format_values=str_format_values) |
| 520 |
) |
| 521 |
|
| 522 |
for url_prefix in c["include"]: |
| 523 |
cmd.append(f"--include={url_prefix}") |
| 524 |
for url_prefix in c["exclude"]: |
| 525 |
cmd.append(f"--exclude={url_prefix}") |
| 526 |
for tag in c["tag"]: |
| 527 |
cmd.append(f"--tag={tag}") |
| 528 |
for tag in c["exclude_tag"]: |
| 529 |
cmd.append(f"--exclude-tag={tag}") |
| 530 |
|
| 531 |
if mozinfo.info["os"] == "win": |
| 532 |
# Because of a limit on the length of CLI command line string length in Windows, we |
| 533 |
# should prefer to pass paths by a file instead. |
| 534 |
import tempfile |
| 535 |
|
| 536 |
with tempfile.NamedTemporaryFile(delete=False) as tmp: |
| 537 |
tmp.write("\n".join(test_paths).encode()) |
| 538 |
cmd.append(f"--include-file={tmp.name}") |
| 539 |
else: |
| 540 |
cmd.extend(test_paths) |
| 541 |
|
| 542 |
return cmd |
| 543 |
|
| 544 |
def download_and_extract(self): |
| 545 |
super(WebPlatformTest, self).download_and_extract( |
| 546 |
extract_dirs=[ |
| 547 |
"mach", |
| 548 |
"bin/*", |
| 549 |
"config/*", |
| 550 |
"extensions/*", |
| 551 |
"mozbase/*", |
| 552 |
"marionette/*", |
| 553 |
"tools/*", |
| 554 |
"web-platform/*", |
| 555 |
"mozpack/*", |
| 556 |
"mozbuild/*", |
| 557 |
], |
| 558 |
suite_categories=["web-platform"], |
| 559 |
) |
| 560 |
dirs = self.query_abs_dirs() |
| 561 |
if self.is_android: |
| 562 |
self.xre_path = dirs["abs_xre_dir"] |
| 563 |
# Make sure that the logging directory exists |
| 564 |
if self.mkdir_p(dirs["abs_blob_upload_dir"]) == -1: |
| 565 |
self.fatal("Could not create blobber upload directory") |
| 566 |
# Exit |
| 567 |
|
| 568 |
def download_and_process_manifest(self): |
| 569 |
"""Downloads the tests-by-manifest JSON mapping generated by the decision task. |
| 570 |
|
| 571 |
web-platform-tests are chunked in the decision task as of Bug 1608837 |
| 572 |
and this means tests are resolved by the TestResolver as part of this process. |
| 573 |
|
| 574 |
The manifest file contains tests keyed by the groups generated in |
| 575 |
TestResolver.get_wpt_group(). |
| 576 |
|
| 577 |
Upon successful call, a JSON file containing only the web-platform test |
| 578 |
groups are saved in the fetch directory. |
| 579 |
|
| 580 |
Bug: |
| 581 |
1634554 |
| 582 |
""" |
| 583 |
dirs = self.query_abs_dirs() |
| 584 |
url = os.environ.get("TESTS_BY_MANIFEST_URL", "") |
| 585 |
if not url: |
| 586 |
self.fatal("TESTS_BY_MANIFEST_URL not defined.") |
| 587 |
|
| 588 |
artifact_name = url.split("/")[-1] |
| 589 |
|
| 590 |
# Save file to the MOZ_FETCHES dir. |
| 591 |
self.download_file( |
| 592 |
url, file_name=artifact_name, parent_dir=dirs["abs_fetches_dir"] |
| 593 |
) |
| 594 |
|
| 595 |
with gzip.open(os.path.join(dirs["abs_fetches_dir"], artifact_name), "r") as f: |
| 596 |
tests_by_manifest = json.loads(f.read()) |
| 597 |
|
| 598 |
# We need to filter out non-web-platform-tests without knowing what the |
| 599 |
# groups are. Fortunately, all web-platform test 'manifests' begin with a |
| 600 |
# forward slash. |
| 601 |
test_groups = { |
| 602 |
key: tests_by_manifest[key] |
| 603 |
for key in tests_by_manifest.keys() |
| 604 |
if key.startswith("/") |
| 605 |
} |
| 606 |
|
| 607 |
outfile = os.path.join(dirs["abs_fetches_dir"], "wpt_tests_by_group.json") |
| 608 |
with open(outfile, "w+") as f: |
| 609 |
json.dump(test_groups, f, indent=2, sort_keys=True) |
| 610 |
|
| 611 |
def install(self): |
| 612 |
if self.is_android: |
| 613 |
self.install_android_app(self.installer_path) |
| 614 |
else: |
| 615 |
super(WebPlatformTest, self).install() |
| 616 |
|
| 617 |
def _install_fonts(self): |
| 618 |
if self.is_android: |
| 619 |
return |
| 620 |
# Ensure the Ahem font is available |
| 621 |
dirs = self.query_abs_dirs() |
| 622 |
|
| 623 |
if not sys.platform.startswith("darwin"): |
| 624 |
font_path = os.path.join(os.path.dirname(self.binary_path), "fonts") |
| 625 |
else: |
| 626 |
font_path = os.path.join( |
| 627 |
os.path.dirname(self.binary_path), |
| 628 |
os.pardir, |
| 629 |
"Resources", |
| 630 |
"res", |
| 631 |
"fonts", |
| 632 |
) |
| 633 |
if not os.path.exists(font_path): |
| 634 |
os.makedirs(font_path) |
| 635 |
ahem_src = os.path.join(dirs["abs_wpttest_dir"], "tests", "fonts", "Ahem.ttf") |
| 636 |
ahem_dest = os.path.join(font_path, "Ahem.ttf") |
| 637 |
with open(ahem_src, "rb") as src, open(ahem_dest, "wb") as dest: |
| 638 |
dest.write(src.read()) |
| 639 |
|
| 640 |
def run_tests(self): |
| 641 |
dirs = self.query_abs_dirs() |
| 642 |
|
| 643 |
parser = StructuredOutputParser( |
| 644 |
config=self.config, |
| 645 |
log_obj=self.log_obj, |
| 646 |
log_compact=True, |
| 647 |
error_list=BaseErrorList + WptHarnessErrorList, |
| 648 |
allow_crashes=True, |
| 649 |
) |
| 650 |
|
| 651 |
env = {"MINIDUMP_SAVE_PATH": dirs["abs_blob_upload_dir"]} |
| 652 |
env["RUST_BACKTRACE"] = "full" |
| 653 |
|
| 654 |
if self.config["allow_software_gl_layers"]: |
| 655 |
env["MOZ_LAYERS_ALLOW_SOFTWARE_GL"] = "1" |
| 656 |
if self.config["headless"]: |
| 657 |
env["MOZ_HEADLESS"] = "1" |
| 658 |
env["MOZ_HEADLESS_WIDTH"] = self.config["headless_width"] |
| 659 |
env["MOZ_HEADLESS_HEIGHT"] = self.config["headless_height"] |
| 660 |
|
| 661 |
if self.is_android: |
| 662 |
env["ADB_PATH"] = self.adb_path |
| 663 |
|
| 664 |
env["MOZ_GMP_PATH"] = os.pathsep.join( |
| 665 |
os.path.join(dirs["abs_test_bin_dir"], "plugins", p, "1.0") |
| 666 |
for p in ("gmp-fake", "gmp-fakeopenh264") |
| 667 |
) |
| 668 |
|
| 669 |
env = self.query_env(partial_env=env, log_level=INFO) |
| 670 |
|
| 671 |
start_time = datetime.now() |
| 672 |
max_per_test_time = timedelta(minutes=60) |
| 673 |
max_per_test_tests = 10 |
| 674 |
if self.per_test_coverage: |
| 675 |
max_per_test_tests = 30 |
| 676 |
executed_tests = 0 |
| 677 |
executed_too_many_tests = False |
| 678 |
|
| 679 |
if self.per_test_coverage or self.verify_enabled: |
| 680 |
suites = self.query_per_test_category_suites(None, None) |
| 681 |
if "wdspec" in suites: |
| 682 |
# geckodriver is required for wdspec, but not always available |
| 683 |
geckodriver_path = self._query_geckodriver() |
| 684 |
if not geckodriver_path or not os.path.isfile(geckodriver_path): |
| 685 |
suites.remove("wdspec") |
| 686 |
self.info("Skipping 'wdspec' tests - no geckodriver") |
| 687 |
else: |
| 688 |
test_types = self.config.get("test_type", []) |
| 689 |
suites = [None] |
| 690 |
for suite in suites: |
| 691 |
if executed_too_many_tests and not self.per_test_coverage: |
| 692 |
continue |
| 693 |
|
| 694 |
if suite: |
| 695 |
test_types = [suite] |
| 696 |
|
| 697 |
summary = {} |
| 698 |
for per_test_args in self.query_args(suite): |
| 699 |
# Make sure baseline code coverage tests are never |
| 700 |
# skipped and that having them run has no influence |
| 701 |
# on the max number of actual tests that are to be run. |
| 702 |
is_baseline_test = ( |
| 703 |
"baselinecoverage" in per_test_args[-1] |
| 704 |
if self.per_test_coverage |
| 705 |
else False |
| 706 |
) |
| 707 |
if executed_too_many_tests and not is_baseline_test: |
| 708 |
continue |
| 709 |
|
| 710 |
if not is_baseline_test: |
| 711 |
if (datetime.now() - start_time) > max_per_test_time: |
| 712 |
# Running tests has run out of time. That is okay! Stop running |
| 713 |
# them so that a task timeout is not triggered, and so that |
| 714 |
# (partial) results are made available in a timely manner. |
| 715 |
self.info( |
| 716 |
"TinderboxPrint: Running tests took too long: Not all tests " |
| 717 |
"were executed.<br/>" |
| 718 |
) |
| 719 |
return |
| 720 |
if executed_tests >= max_per_test_tests: |
| 721 |
# When changesets are merged between trees or many tests are |
| 722 |
# otherwise updated at once, there probably is not enough time |
| 723 |
# to run all tests, and attempting to do so may cause other |
| 724 |
# problems, such as generating too much log output. |
| 725 |
self.info( |
| 726 |
"TinderboxPrint: Too many modified tests: Not all tests " |
| 727 |
"were executed.<br/>" |
| 728 |
) |
| 729 |
executed_too_many_tests = True |
| 730 |
|
| 731 |
executed_tests = executed_tests + 1 |
| 732 |
|
| 733 |
cmd = self._query_cmd(test_types) |
| 734 |
cmd.extend(per_test_args) |
| 735 |
|
| 736 |
final_env = copy.copy(env) |
| 737 |
|
| 738 |
if self.per_test_coverage: |
| 739 |
self.set_coverage_env(final_env, is_baseline_test) |
| 740 |
|
| 741 |
return_code = self.run_command( |
| 742 |
cmd, |
| 743 |
cwd=dirs["abs_work_dir"], |
| 744 |
output_timeout=1000, |
| 745 |
output_parser=parser, |
| 746 |
env=final_env, |
| 747 |
) |
| 748 |
|
| 749 |
if self.per_test_coverage: |
| 750 |
self.add_per_test_coverage_report( |
| 751 |
final_env, suite, per_test_args[-1] |
| 752 |
) |
| 753 |
|
| 754 |
tbpl_status, log_level, summary = parser.evaluate_parser( |
| 755 |
return_code, previous_summary=summary |
| 756 |
) |
| 757 |
self.record_status(tbpl_status, level=log_level) |
| 758 |
|
| 759 |
if len(per_test_args) > 0: |
| 760 |
self.log_per_test_status(per_test_args[-1], tbpl_status, log_level) |
| 761 |
if tbpl_status == TBPL_RETRY: |
| 762 |
self.info("Per-test run abandoned due to RETRY status") |
| 763 |
return |
| 764 |
|
| 765 |
|
| 766 |
# main {{{1 |
| 767 |
if __name__ == "__main__": |
| 768 |
web_platform_tests = WebPlatformTest() |
| 769 |
web_platform_tests.run_and_exit() |