| 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 |
|
| 5 |
# You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
import copy |
| 8 |
import glob |
| 9 |
import json |
| 10 |
import multiprocessing |
| 11 |
import os |
| 12 |
import re |
| 13 |
import shutil |
| 14 |
import sys |
| 15 |
from datetime import datetime, timedelta |
| 16 |
|
| 17 |
# load modules from parent dir |
| 18 |
here = os.path.abspath(os.path.dirname(__file__)) |
| 19 |
sys.path.insert(1, os.path.dirname(here)) |
| 20 |
|
| 21 |
import threading |
| 22 |
|
| 23 |
from mozfile import load_source |
| 24 |
from mozharness.base.errors import BaseErrorList |
| 25 |
from mozharness.base.log import INFO, WARNING |
| 26 |
from mozharness.base.script import PreScriptAction |
| 27 |
from mozharness.base.vcs.vcsbase import MercurialScript |
| 28 |
from mozharness.mozilla.automation import TBPL_EXCEPTION, TBPL_RETRY |
| 29 |
from mozharness.mozilla.mozbase import MozbaseMixin |
| 30 |
from mozharness.mozilla.structuredlog import StructuredOutputParser |
| 31 |
from mozharness.mozilla.testing.codecoverage import ( |
| 32 |
CodeCoverageMixin, |
| 33 |
code_coverage_config_options, |
| 34 |
) |
| 35 |
from mozharness.mozilla.testing.errors import HarnessErrorList |
| 36 |
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options |
| 37 |
from mozharness.mozilla.testing.unittest import DesktopUnittestOutputParser |
| 38 |
|
| 39 |
SUITE_CATEGORIES = [ |
| 40 |
"gtest", |
| 41 |
"cppunittest", |
| 42 |
"jittest", |
| 43 |
"mochitest", |
| 44 |
"reftest", |
| 45 |
"xpcshell", |
| 46 |
] |
| 47 |
SUITE_DEFAULT_E10S = ["mochitest", "reftest"] |
| 48 |
SUITE_NO_E10S = ["xpcshell"] |
| 49 |
SUITE_REPEATABLE = ["mochitest", "reftest", "xpcshell"] |
| 50 |
|
| 51 |
|
| 52 |
# DesktopUnittest {{{1 |
| 53 |
class DesktopUnittest(TestingMixin, MercurialScript, MozbaseMixin, CodeCoverageMixin): |
| 54 |
config_options = ( |
| 55 |
[ |
| 56 |
[ |
| 57 |
[ |
| 58 |
"--mochitest-suite", |
| 59 |
], |
| 60 |
{ |
| 61 |
"action": "extend", |
| 62 |
"dest": "specified_mochitest_suites", |
| 63 |
"type": "string", |
| 64 |
"help": "Specify which mochi suite to run. " |
| 65 |
"Suites are defined in the config file.\n" |
| 66 |
"Examples: 'all', 'plain1', 'plain5', 'chrome', or 'a11y'", |
| 67 |
}, |
| 68 |
], |
| 69 |
[ |
| 70 |
[ |
| 71 |
"--reftest-suite", |
| 72 |
], |
| 73 |
{ |
| 74 |
"action": "extend", |
| 75 |
"dest": "specified_reftest_suites", |
| 76 |
"type": "string", |
| 77 |
"help": "Specify which reftest suite to run. " |
| 78 |
"Suites are defined in the config file.\n" |
| 79 |
"Examples: 'all', 'crashplan', or 'jsreftest'", |
| 80 |
}, |
| 81 |
], |
| 82 |
[ |
| 83 |
[ |
| 84 |
"--xpcshell-suite", |
| 85 |
], |
| 86 |
{ |
| 87 |
"action": "extend", |
| 88 |
"dest": "specified_xpcshell_suites", |
| 89 |
"type": "string", |
| 90 |
"help": "Specify which xpcshell suite to run. " |
| 91 |
"Suites are defined in the config file\n." |
| 92 |
"Examples: 'xpcshell'", |
| 93 |
}, |
| 94 |
], |
| 95 |
[ |
| 96 |
[ |
| 97 |
"--cppunittest-suite", |
| 98 |
], |
| 99 |
{ |
| 100 |
"action": "extend", |
| 101 |
"dest": "specified_cppunittest_suites", |
| 102 |
"type": "string", |
| 103 |
"help": "Specify which cpp unittest suite to run. " |
| 104 |
"Suites are defined in the config file\n." |
| 105 |
"Examples: 'cppunittest'", |
| 106 |
}, |
| 107 |
], |
| 108 |
[ |
| 109 |
[ |
| 110 |
"--gtest-suite", |
| 111 |
], |
| 112 |
{ |
| 113 |
"action": "extend", |
| 114 |
"dest": "specified_gtest_suites", |
| 115 |
"type": "string", |
| 116 |
"help": "Specify which gtest suite to run. " |
| 117 |
"Suites are defined in the config file\n." |
| 118 |
"Examples: 'gtest'", |
| 119 |
}, |
| 120 |
], |
| 121 |
[ |
| 122 |
[ |
| 123 |
"--jittest-suite", |
| 124 |
], |
| 125 |
{ |
| 126 |
"action": "extend", |
| 127 |
"dest": "specified_jittest_suites", |
| 128 |
"type": "string", |
| 129 |
"help": "Specify which jit-test suite to run. " |
| 130 |
"Suites are defined in the config file\n." |
| 131 |
"Examples: 'jittest'", |
| 132 |
}, |
| 133 |
], |
| 134 |
[ |
| 135 |
[ |
| 136 |
"--run-all-suites", |
| 137 |
], |
| 138 |
{ |
| 139 |
"action": "store_true", |
| 140 |
"dest": "run_all_suites", |
| 141 |
"default": False, |
| 142 |
"help": "This will run all suites that are specified " |
| 143 |
"in the config file. You do not need to specify " |
| 144 |
"any other suites.\nBeware, this may take a while ;)", |
| 145 |
}, |
| 146 |
], |
| 147 |
[ |
| 148 |
[ |
| 149 |
"--disable-e10s", |
| 150 |
], |
| 151 |
{ |
| 152 |
"action": "store_false", |
| 153 |
"dest": "e10s", |
| 154 |
"default": True, |
| 155 |
"help": "Run tests without multiple processes (e10s).", |
| 156 |
}, |
| 157 |
], |
| 158 |
[ |
| 159 |
[ |
| 160 |
"--headless", |
| 161 |
], |
| 162 |
{ |
| 163 |
"action": "store_true", |
| 164 |
"dest": "headless", |
| 165 |
"default": False, |
| 166 |
"help": "Run tests in headless mode.", |
| 167 |
}, |
| 168 |
], |
| 169 |
[ |
| 170 |
[ |
| 171 |
"--no-random", |
| 172 |
], |
| 173 |
{ |
| 174 |
"action": "store_true", |
| 175 |
"dest": "no_random", |
| 176 |
"default": False, |
| 177 |
"help": "Run tests with no random intermittents and bisect in case of real failure.", # NOQA: E501 |
| 178 |
}, |
| 179 |
], |
| 180 |
[ |
| 181 |
["--total-chunks"], |
| 182 |
{ |
| 183 |
"action": "store", |
| 184 |
"dest": "total_chunks", |
| 185 |
"help": "Number of total chunks", |
| 186 |
}, |
| 187 |
], |
| 188 |
[ |
| 189 |
["--this-chunk"], |
| 190 |
{ |
| 191 |
"action": "store", |
| 192 |
"dest": "this_chunk", |
| 193 |
"help": "Number of this chunk", |
| 194 |
}, |
| 195 |
], |
| 196 |
[ |
| 197 |
["--filter"], |
| 198 |
{ |
| 199 |
"action": "store", |
| 200 |
"dest": "filter", |
| 201 |
"default": "", |
| 202 |
"help": "Specify a regular expression (as could be passed " |
| 203 |
"to the JS RegExp constructor) to test against URLs in " |
| 204 |
"the manifest; only test items that have a matching test " |
| 205 |
"URL will be run.", |
| 206 |
}, |
| 207 |
], |
| 208 |
[ |
| 209 |
["--allow-software-gl-layers"], |
| 210 |
{ |
| 211 |
"action": "store_true", |
| 212 |
"dest": "allow_software_gl_layers", |
| 213 |
"default": False, |
| 214 |
"help": "Permits a software GL implementation (such as LLVMPipe) to use " |
| 215 |
"the GL compositor.", |
| 216 |
}, |
| 217 |
], |
| 218 |
[ |
| 219 |
["--enable-inc-origin-init"], |
| 220 |
{ |
| 221 |
"action": "store_true", |
| 222 |
"dest": "enable_inc_origin_init", |
| 223 |
"default": False, |
| 224 |
"help": "Enable the incremental origin initialization in Gecko.", |
| 225 |
}, |
| 226 |
], |
| 227 |
[ |
| 228 |
["--filter-set"], |
| 229 |
{ |
| 230 |
"action": "store", |
| 231 |
"dest": "filter_set", |
| 232 |
"default": "", |
| 233 |
"help": "Use a predefined filter.", |
| 234 |
}, |
| 235 |
], |
| 236 |
[ |
| 237 |
["--threads"], |
| 238 |
{ |
| 239 |
"action": "store", |
| 240 |
"dest": "threads", |
| 241 |
"help": "Number of total chunks", |
| 242 |
}, |
| 243 |
], |
| 244 |
[ |
| 245 |
["--variant"], |
| 246 |
{ |
| 247 |
"action": "store", |
| 248 |
"dest": "variant", |
| 249 |
"default": "", |
| 250 |
"help": "specify a variant if mozharness needs to setup paths", |
| 251 |
}, |
| 252 |
], |
| 253 |
[ |
| 254 |
["--gpu-required"], |
| 255 |
{ |
| 256 |
"action": "store_true", |
| 257 |
"dest": "gpu_required", |
| 258 |
"default": False, |
| 259 |
"help": "Run additional verification on modified tests using gpu instances.", |
| 260 |
}, |
| 261 |
], |
| 262 |
[ |
| 263 |
["--setpref"], |
| 264 |
{ |
| 265 |
"action": "append", |
| 266 |
"metavar": "PREF=VALUE", |
| 267 |
"dest": "extra_prefs", |
| 268 |
"default": [], |
| 269 |
"help": "Defines an extra user preference.", |
| 270 |
}, |
| 271 |
], |
| 272 |
[ |
| 273 |
[ |
| 274 |
"--repeat", |
| 275 |
], |
| 276 |
{ |
| 277 |
"action": "store", |
| 278 |
"type": "int", |
| 279 |
"dest": "repeat", |
| 280 |
"default": 0, |
| 281 |
"help": "Repeat the tests the given number of times. Supported " |
| 282 |
"by mochitest, reftest, crashtest, ignored otherwise.", |
| 283 |
}, |
| 284 |
], |
| 285 |
[ |
| 286 |
["--enable-xorigin-tests"], |
| 287 |
{ |
| 288 |
"action": "store_true", |
| 289 |
"dest": "enable_xorigin_tests", |
| 290 |
"default": False, |
| 291 |
"help": "Run tests in a cross origin iframe.", |
| 292 |
}, |
| 293 |
], |
| 294 |
[ |
| 295 |
["--enable-a11y-checks"], |
| 296 |
{ |
| 297 |
"action": "store_true", |
| 298 |
"default": False, |
| 299 |
"dest": "a11y_checks", |
| 300 |
"help": "Run tests with accessibility checks enabled.", |
| 301 |
}, |
| 302 |
], |
| 303 |
[ |
| 304 |
["--run-failures"], |
| 305 |
{ |
| 306 |
"action": "store", |
| 307 |
"default": "", |
| 308 |
"type": "string", |
| 309 |
"dest": "run_failures", |
| 310 |
"help": "Run only failures matching keyword. " |
| 311 |
"Examples: 'apple_silicon'", |
| 312 |
}, |
| 313 |
], |
| 314 |
[ |
| 315 |
["--crash-as-pass"], |
| 316 |
{ |
| 317 |
"action": "store_true", |
| 318 |
"default": False, |
| 319 |
"dest": "crash_as_pass", |
| 320 |
"help": "treat harness level crash as a pass", |
| 321 |
}, |
| 322 |
], |
| 323 |
[ |
| 324 |
["--timeout-as-pass"], |
| 325 |
{ |
| 326 |
"action": "store_true", |
| 327 |
"default": False, |
| 328 |
"dest": "timeout_as_pass", |
| 329 |
"help": "treat harness level timeout as a pass", |
| 330 |
}, |
| 331 |
], |
| 332 |
[ |
| 333 |
["--disable-fission"], |
| 334 |
{ |
| 335 |
"action": "store_true", |
| 336 |
"default": False, |
| 337 |
"dest": "disable_fission", |
| 338 |
"help": "do not run tests with fission enabled.", |
| 339 |
}, |
| 340 |
], |
| 341 |
[ |
| 342 |
["--conditioned-profile"], |
| 343 |
{ |
| 344 |
"action": "store_true", |
| 345 |
"default": False, |
| 346 |
"dest": "conditioned_profile", |
| 347 |
"help": "run tests with a conditioned profile", |
| 348 |
}, |
| 349 |
], |
| 350 |
[ |
| 351 |
["--tag"], |
| 352 |
{ |
| 353 |
"action": "append", |
| 354 |
"default": [], |
| 355 |
"dest": "test_tags", |
| 356 |
"help": "Filter out tests that don't have the given tag. Can be used multiple " |
| 357 |
"times in which case the test must contain at least one of the given tags.", |
| 358 |
}, |
| 359 |
], |
| 360 |
[ |
| 361 |
["--use-http3-server"], |
| 362 |
{ |
| 363 |
"action": "store_true", |
| 364 |
"default": False, |
| 365 |
"dest": "useHttp3Server", |
| 366 |
"help": "Whether to use the Http3 server", |
| 367 |
}, |
| 368 |
], |
| 369 |
[ |
| 370 |
["--use-http2-server"], |
| 371 |
{ |
| 372 |
"action": "store_true", |
| 373 |
"default": False, |
| 374 |
"dest": "useHttp2Server", |
| 375 |
"help": "Whether to use the Http2 server", |
| 376 |
}, |
| 377 |
], |
| 378 |
[ |
| 379 |
["--mochitest-flavor"], |
| 380 |
{ |
| 381 |
"action": "store", |
| 382 |
"dest": "mochitest_flavor", |
| 383 |
"help": "Specify which mochitest flavor to run." |
| 384 |
"Examples: 'plain', 'browser'", |
| 385 |
}, |
| 386 |
], |
| 387 |
] |
| 388 |
+ copy.deepcopy(testing_config_options) |
| 389 |
+ copy.deepcopy(code_coverage_config_options) |
| 390 |
) |
| 391 |
|
| 392 |
def __init__(self, require_config_file=True): |
| 393 |
# abs_dirs defined already in BaseScript but is here to make pylint happy |
| 394 |
self.abs_dirs = None |
| 395 |
super(DesktopUnittest, self).__init__( |
| 396 |
config_options=self.config_options, |
| 397 |
all_actions=[ |
| 398 |
"clobber", |
| 399 |
"download-and-extract", |
| 400 |
"create-virtualenv", |
| 401 |
"start-pulseaudio", |
| 402 |
"install", |
| 403 |
"stage-files", |
| 404 |
"run-tests", |
| 405 |
"uninstall", |
| 406 |
], |
| 407 |
require_config_file=require_config_file, |
| 408 |
config={"require_test_zip": True}, |
| 409 |
) |
| 410 |
|
| 411 |
c = self.config |
| 412 |
self.global_test_options = [] |
| 413 |
self.installer_url = c.get("installer_url") |
| 414 |
self.test_url = c.get("test_url") |
| 415 |
self.test_packages_url = c.get("test_packages_url") |
| 416 |
self.symbols_url = c.get("symbols_url") |
| 417 |
# this is so mozinstall in install() doesn't bug out if we don't run |
| 418 |
# the download_and_extract action |
| 419 |
self.installer_path = c.get("installer_path") |
| 420 |
self.binary_path = c.get("binary_path") |
| 421 |
self.abs_app_dir = None |
| 422 |
self.abs_res_dir = None |
| 423 |
self.mochitest_flavor = c.get("mochitest_flavor", None) |
| 424 |
|
| 425 |
# Construct an identifier to be used to identify Perfherder data |
| 426 |
# for resource monitoring recording. This attempts to uniquely |
| 427 |
# identify this test invocation configuration. |
| 428 |
perfherder_parts = [] |
| 429 |
perfherder_options = [] |
| 430 |
suites = ( |
| 431 |
("specified_mochitest_suites", "mochitest"), |
| 432 |
("specified_reftest_suites", "reftest"), |
| 433 |
("specified_xpcshell_suites", "xpcshell"), |
| 434 |
("specified_cppunittest_suites", "cppunit"), |
| 435 |
("specified_gtest_suites", "gtest"), |
| 436 |
("specified_jittest_suites", "jittest"), |
| 437 |
) |
| 438 |
for s, prefix in suites: |
| 439 |
if s in c: |
| 440 |
perfherder_parts.append(prefix) |
| 441 |
perfherder_parts.extend(c[s]) |
| 442 |
|
| 443 |
if "this_chunk" in c: |
| 444 |
perfherder_parts.append(c["this_chunk"]) |
| 445 |
|
| 446 |
if c["e10s"]: |
| 447 |
perfherder_options.append("e10s") |
| 448 |
|
| 449 |
self.resource_monitor_perfherder_id = ( |
| 450 |
".".join(perfherder_parts), |
| 451 |
perfherder_options, |
| 452 |
) |
| 453 |
|
| 454 |
# helper methods {{{2 |
| 455 |
def _pre_config_lock(self, rw_config): |
| 456 |
super(DesktopUnittest, self)._pre_config_lock(rw_config) |
| 457 |
c = self.config |
| 458 |
if not c.get("run_all_suites"): |
| 459 |
return # configs are valid |
| 460 |
for category in SUITE_CATEGORIES: |
| 461 |
specific_suites = c.get("specified_%s_suites" % (category)) |
| 462 |
if specific_suites: |
| 463 |
if specific_suites != "all": |
| 464 |
self.fatal( |
| 465 |
"Config options are not valid. Please ensure" |
| 466 |
" that if the '--run-all-suites' flag was enabled," |
| 467 |
" then do not specify to run only specific suites " |
| 468 |
"like:\n '--mochitest-suite browser-chrome'" |
| 469 |
) |
| 470 |
|
| 471 |
def query_abs_dirs(self): |
| 472 |
if self.abs_dirs: |
| 473 |
return self.abs_dirs |
| 474 |
abs_dirs = super(DesktopUnittest, self).query_abs_dirs() |
| 475 |
|
| 476 |
c = self.config |
| 477 |
dirs = {} |
| 478 |
dirs["abs_work_dir"] = abs_dirs["abs_work_dir"] |
| 479 |
dirs["abs_app_install_dir"] = os.path.join( |
| 480 |
abs_dirs["abs_work_dir"], "application" |
| 481 |
) |
| 482 |
dirs["abs_test_install_dir"] = os.path.join(abs_dirs["abs_work_dir"], "tests") |
| 483 |
dirs["abs_test_extensions_dir"] = os.path.join( |
| 484 |
dirs["abs_test_install_dir"], "extensions" |
| 485 |
) |
| 486 |
dirs["abs_test_bin_dir"] = os.path.join(dirs["abs_test_install_dir"], "bin") |
| 487 |
dirs["abs_test_bin_plugins_dir"] = os.path.join( |
| 488 |
dirs["abs_test_bin_dir"], "plugins" |
| 489 |
) |
| 490 |
dirs["abs_test_bin_components_dir"] = os.path.join( |
| 491 |
dirs["abs_test_bin_dir"], "components" |
| 492 |
) |
| 493 |
dirs["abs_mochitest_dir"] = os.path.join( |
| 494 |
dirs["abs_test_install_dir"], "mochitest" |
| 495 |
) |
| 496 |
dirs["abs_reftest_dir"] = os.path.join(dirs["abs_test_install_dir"], "reftest") |
| 497 |
dirs["abs_xpcshell_dir"] = os.path.join( |
| 498 |
dirs["abs_test_install_dir"], "xpcshell" |
| 499 |
) |
| 500 |
dirs["abs_cppunittest_dir"] = os.path.join( |
| 501 |
dirs["abs_test_install_dir"], "cppunittest" |
| 502 |
) |
| 503 |
dirs["abs_gtest_dir"] = os.path.join(dirs["abs_test_install_dir"], "gtest") |
| 504 |
dirs["abs_blob_upload_dir"] = os.path.join( |
| 505 |
abs_dirs["abs_work_dir"], "blobber_upload_dir" |
| 506 |
) |
| 507 |
dirs["abs_jittest_dir"] = os.path.join( |
| 508 |
dirs["abs_test_install_dir"], "jit-test", "jit-test" |
| 509 |
) |
| 510 |
|
| 511 |
if os.path.isabs(c["virtualenv_path"]): |
| 512 |
dirs["abs_virtualenv_dir"] = c["virtualenv_path"] |
| 513 |
else: |
| 514 |
dirs["abs_virtualenv_dir"] = os.path.join( |
| 515 |
abs_dirs["abs_work_dir"], c["virtualenv_path"] |
| 516 |
) |
| 517 |
abs_dirs.update(dirs) |
| 518 |
self.abs_dirs = abs_dirs |
| 519 |
|
| 520 |
return self.abs_dirs |
| 521 |
|
| 522 |
def query_abs_app_dir(self): |
| 523 |
"""We can't set this in advance, because OSX install directories |
| 524 |
change depending on branding and opt/debug. |
| 525 |
""" |
| 526 |
if self.abs_app_dir: |
| 527 |
return self.abs_app_dir |
| 528 |
if not self.binary_path: |
| 529 |
self.fatal("Can't determine abs_app_dir (binary_path not set!)") |
| 530 |
self.abs_app_dir = os.path.dirname(self.binary_path) |
| 531 |
return self.abs_app_dir |
| 532 |
|
| 533 |
def query_abs_res_dir(self): |
| 534 |
"""The directory containing resources like plugins and extensions. On |
| 535 |
OSX this is Contents/Resources, on all other platforms its the same as |
| 536 |
the app dir. |
| 537 |
|
| 538 |
As with the app dir, we can't set this in advance, because OSX install |
| 539 |
directories change depending on branding and opt/debug. |
| 540 |
""" |
| 541 |
if self.abs_res_dir: |
| 542 |
return self.abs_res_dir |
| 543 |
|
| 544 |
abs_app_dir = self.query_abs_app_dir() |
| 545 |
if self._is_darwin(): |
| 546 |
res_subdir = self.config.get("mac_res_subdir", "Resources") |
| 547 |
self.abs_res_dir = os.path.join(os.path.dirname(abs_app_dir), res_subdir) |
| 548 |
else: |
| 549 |
self.abs_res_dir = abs_app_dir |
| 550 |
return self.abs_res_dir |
| 551 |
|
| 552 |
@PreScriptAction("create-virtualenv") |
| 553 |
def _pre_create_virtualenv(self, action): |
| 554 |
dirs = self.query_abs_dirs() |
| 555 |
|
| 556 |
self.register_virtualenv_module(name="mock") |
| 557 |
self.register_virtualenv_module(name="simplejson") |
| 558 |
|
| 559 |
requirements_files = [ |
| 560 |
os.path.join( |
| 561 |
dirs["abs_test_install_dir"], "config", "marionette_requirements.txt" |
| 562 |
) |
| 563 |
] |
| 564 |
|
| 565 |
if self._query_specified_suites("mochitest", "mochitest-media") is not None: |
| 566 |
# mochitest-media is the only thing that needs this |
| 567 |
requirements_files.append( |
| 568 |
os.path.join( |
| 569 |
dirs["abs_mochitest_dir"], |
| 570 |
"websocketprocessbridge", |
| 571 |
"websocketprocessbridge_requirements_3.txt", |
| 572 |
) |
| 573 |
) |
| 574 |
|
| 575 |
if ( |
| 576 |
self._query_specified_suites("mochitest", "mochitest-browser-a11y") |
| 577 |
is not None |
| 578 |
and sys.platform == "win32" |
| 579 |
): |
| 580 |
# Only Windows a11y browser tests need this. |
| 581 |
requirements_files.append( |
| 582 |
os.path.join( |
| 583 |
dirs["abs_mochitest_dir"], |
| 584 |
"browser", |
| 585 |
"accessible", |
| 586 |
"tests", |
| 587 |
"browser", |
| 588 |
"windows", |
| 589 |
"a11y_setup_requirements.txt", |
| 590 |
) |
| 591 |
) |
| 592 |
|
| 593 |
for requirements_file in requirements_files: |
| 594 |
self.register_virtualenv_module(requirements=[requirements_file]) |
| 595 |
|
| 596 |
_python_interp = self.query_exe("python") |
| 597 |
if "win" in self.platform_name() and os.path.exists(_python_interp): |
| 598 |
multiprocessing.set_executable(_python_interp) |
| 599 |
|
| 600 |
def _query_symbols_url(self): |
| 601 |
"""query the full symbols URL based upon binary URL""" |
| 602 |
# may break with name convention changes but is one less 'input' for script |
| 603 |
if self.symbols_url: |
| 604 |
return self.symbols_url |
| 605 |
|
| 606 |
# Use simple text substitution to determine the symbols_url from the |
| 607 |
# installer_url. This will not always work: For signed builds, the |
| 608 |
# installer_url is likely an artifact in a signing task, which may not |
| 609 |
# have a symbols artifact. It might be better to use the test target |
| 610 |
# preferentially, like query_prefixed_build_dir_url() does (for future |
| 611 |
# consideration, if this code proves troublesome). |
| 612 |
symbols_url = None |
| 613 |
self.info("finding symbols_url based upon self.installer_url") |
| 614 |
if self.installer_url: |
| 615 |
for ext in [".zip", ".dmg", ".tar.bz2", ".tar.xz"]: |
| 616 |
if ext in self.installer_url: |
| 617 |
symbols_url = self.installer_url.replace( |
| 618 |
ext, ".crashreporter-symbols.zip" |
| 619 |
) |
| 620 |
if not symbols_url: |
| 621 |
self.fatal( |
| 622 |
"self.installer_url was found but symbols_url could \ |
| 623 |
not be determined" |
| 624 |
) |
| 625 |
else: |
| 626 |
self.fatal("self.installer_url was not found in self.config") |
| 627 |
self.info("setting symbols_url as %s" % (symbols_url)) |
| 628 |
self.symbols_url = symbols_url |
| 629 |
return self.symbols_url |
| 630 |
|
| 631 |
def _get_mozharness_test_paths(self, suite_category, suite): |
| 632 |
# test_paths is the group name, confirm_paths can be the path+testname |
| 633 |
# test_paths will always be the group name, unrelated to if confirm_paths is set or not. |
| 634 |
test_paths = json.loads(os.environ.get("MOZHARNESS_TEST_PATHS", '""')) |
| 635 |
confirm_paths = json.loads(os.environ.get("MOZHARNESS_CONFIRM_PATHS", '""')) |
| 636 |
|
| 637 |
if "-coverage" in suite: |
| 638 |
suite = suite[: suite.index("-coverage")] |
| 639 |
|
| 640 |
if not test_paths or suite not in test_paths: |
| 641 |
return None |
| 642 |
|
| 643 |
suite_test_paths = test_paths[suite] |
| 644 |
if confirm_paths and suite in confirm_paths and confirm_paths[suite]: |
| 645 |
suite_test_paths = confirm_paths[suite] |
| 646 |
|
| 647 |
if suite_category == "reftest": |
| 648 |
dirs = self.query_abs_dirs() |
| 649 |
suite_test_paths = [ |
| 650 |
os.path.join(dirs["abs_reftest_dir"], "tests", p) |
| 651 |
for p in suite_test_paths |
| 652 |
] |
| 653 |
|
| 654 |
return suite_test_paths |
| 655 |
|
| 656 |
def _query_abs_base_cmd(self, suite_category, suite): |
| 657 |
if self.binary_path: |
| 658 |
c = self.config |
| 659 |
dirs = self.query_abs_dirs() |
| 660 |
run_file = c["run_file_names"][suite_category] |
| 661 |
base_cmd = [self.query_python_path("python"), "-u"] |
| 662 |
base_cmd.append(os.path.join(dirs["abs_%s_dir" % suite_category], run_file)) |
| 663 |
abs_app_dir = self.query_abs_app_dir() |
| 664 |
abs_res_dir = self.query_abs_res_dir() |
| 665 |
|
| 666 |
raw_log_file, error_summary_file = self.get_indexed_logs( |
| 667 |
dirs["abs_blob_upload_dir"], suite |
| 668 |
) |
| 669 |
|
| 670 |
str_format_values = { |
| 671 |
"binary_path": self.binary_path, |
| 672 |
"symbols_path": self._query_symbols_url(), |
| 673 |
"abs_work_dir": dirs["abs_work_dir"], |
| 674 |
"abs_app_dir": abs_app_dir, |
| 675 |
"abs_res_dir": abs_res_dir, |
| 676 |
"raw_log_file": raw_log_file, |
| 677 |
"error_summary_file": error_summary_file, |
| 678 |
"gtest_dir": os.path.join(dirs["abs_test_install_dir"], "gtest"), |
| 679 |
} |
| 680 |
|
| 681 |
if self.mochitest_flavor: |
| 682 |
str_format_values.update({"mochitest_flavor": self.mochitest_flavor}) |
| 683 |
|
| 684 |
# TestingMixin._download_and_extract_symbols() will set |
| 685 |
# self.symbols_path when downloading/extracting. |
| 686 |
if self.symbols_path: |
| 687 |
str_format_values["symbols_path"] = self.symbols_path |
| 688 |
|
| 689 |
if suite_category not in SUITE_NO_E10S: |
| 690 |
if suite_category in SUITE_DEFAULT_E10S and not c["e10s"]: |
| 691 |
base_cmd.append("--disable-e10s") |
| 692 |
elif suite_category not in SUITE_DEFAULT_E10S and c["e10s"]: |
| 693 |
base_cmd.append("--e10s") |
| 694 |
if c.get("repeat"): |
| 695 |
if suite_category in SUITE_REPEATABLE: |
| 696 |
base_cmd.extend(["--repeat=%s" % c.get("repeat")]) |
| 697 |
else: |
| 698 |
self.log( |
| 699 |
f"--repeat not supported in {suite_category}", |
| 700 |
level=WARNING, |
| 701 |
) |
| 702 |
|
| 703 |
# do not add --disable fission if we don't have --disable-e10s |
| 704 |
if c["disable_fission"] and suite_category not in [ |
| 705 |
"gtest", |
| 706 |
"cppunittest", |
| 707 |
"jittest", |
| 708 |
]: |
| 709 |
base_cmd.append("--disable-fission") |
| 710 |
|
| 711 |
if c["useHttp3Server"]: |
| 712 |
base_cmd.append("--use-http3-server") |
| 713 |
elif c["useHttp2Server"]: |
| 714 |
base_cmd.append("--use-http2-server") |
| 715 |
|
| 716 |
if c["restartAfterFailure"]: |
| 717 |
base_cmd.append("--restart-after-failure") |
| 718 |
|
| 719 |
# Ignore chunking if we have user specified test paths |
| 720 |
if not (self.verify_enabled or self.per_test_coverage): |
| 721 |
test_paths = self._get_mozharness_test_paths(suite_category, suite) |
| 722 |
if test_paths or c["test_tags"]: |
| 723 |
if test_paths: |
| 724 |
base_cmd.extend(test_paths) |
| 725 |
if c["test_tags"]: |
| 726 |
# Exclude suites that don't support --tag to prevent |
| 727 |
# errors caused by passing unknown argument. |
| 728 |
# Note there's a similar list in chunking.py in |
| 729 |
# DefaultLoader's get_manifest method. The lists should |
| 730 |
# be kept in sync. |
| 731 |
if suite_category not in [ |
| 732 |
"gtest", |
| 733 |
"cppunittest", |
| 734 |
"jittest", |
| 735 |
"crashtest", |
| 736 |
"crashtest-qr", |
| 737 |
"jsreftest", |
| 738 |
"reftest", |
| 739 |
"reftest-qr", |
| 740 |
]: |
| 741 |
base_cmd.extend([f"--tag={t}" for t in c["test_tags"]]) |
| 742 |
else: |
| 743 |
self.warning( |
| 744 |
"--tag does not currently work with the " |
| 745 |
"'{suite_category}' suite." |
| 746 |
) |
| 747 |
elif c.get("total_chunks") and c.get("this_chunk"): |
| 748 |
base_cmd.extend( |
| 749 |
[ |
| 750 |
"--total-chunks", |
| 751 |
c["total_chunks"], |
| 752 |
"--this-chunk", |
| 753 |
c["this_chunk"], |
| 754 |
] |
| 755 |
) |
| 756 |
|
| 757 |
if c["no_random"]: |
| 758 |
if suite_category == "mochitest": |
| 759 |
base_cmd.append("--bisect-chunk=default") |
| 760 |
else: |
| 761 |
self.warning( |
| 762 |
"--no-random does not currently work with suites other than " |
| 763 |
"mochitest." |
| 764 |
) |
| 765 |
|
| 766 |
if c.get("mochitest_flavor", None): |
| 767 |
base_cmd.append("--flavor={}".format(c["mochitest_flavor"])) |
| 768 |
|
| 769 |
if c["headless"]: |
| 770 |
base_cmd.append("--headless") |
| 771 |
|
| 772 |
if c["filter"]: |
| 773 |
if suite_category == "reftest": |
| 774 |
base_cmd.append("--filter={}".format(c["filter"])) |
| 775 |
else: |
| 776 |
self.warning( |
| 777 |
"--filter does not currently work with suites other than " |
| 778 |
"reftest." |
| 779 |
) |
| 780 |
|
| 781 |
if c["enable_inc_origin_init"]: |
| 782 |
if suite_category == "gtest": |
| 783 |
base_cmd.append("--enable-inc-origin-init") |
| 784 |
else: |
| 785 |
self.warning( |
| 786 |
"--enable-inc-origin-init does not currently work with " |
| 787 |
"suites other than gtest." |
| 788 |
) |
| 789 |
|
| 790 |
if c["filter_set"]: |
| 791 |
if suite_category == "gtest": |
| 792 |
base_cmd.append("--filter-set={}".format(c["filter_set"])) |
| 793 |
else: |
| 794 |
self.warning( |
| 795 |
"--filter-set does not currently work with suites other then " |
| 796 |
"gtest." |
| 797 |
) |
| 798 |
|
| 799 |
if c.get("threads"): |
| 800 |
base_cmd.extend(["--threads", c["threads"]]) |
| 801 |
|
| 802 |
if c["variant"]: |
| 803 |
base_cmd.append("--variant={}".format(c["variant"])) |
| 804 |
|
| 805 |
if c["enable_xorigin_tests"]: |
| 806 |
base_cmd.append("--enable-xorigin-tests") |
| 807 |
|
| 808 |
if suite_category not in ["cppunittest", "gtest", "jittest"]: |
| 809 |
# Enable stylo threads everywhere we can. Some tests don't |
| 810 |
# support --setpref, so ignore those. |
| 811 |
base_cmd.append("--setpref=layout.css.stylo-threads=4") |
| 812 |
|
| 813 |
if c["extra_prefs"]: |
| 814 |
base_cmd.extend([f"--setpref={p}" for p in c["extra_prefs"]]) |
| 815 |
|
| 816 |
if c["a11y_checks"]: |
| 817 |
base_cmd.append("--enable-a11y-checks") |
| 818 |
|
| 819 |
if c["run_failures"]: |
| 820 |
base_cmd.extend(["--run-failures={}".format(c["run_failures"])]) |
| 821 |
|
| 822 |
if c["timeout_as_pass"]: |
| 823 |
base_cmd.append("--timeout-as-pass") |
| 824 |
|
| 825 |
if c["crash_as_pass"]: |
| 826 |
base_cmd.append("--crash-as-pass") |
| 827 |
|
| 828 |
if c["conditioned_profile"]: |
| 829 |
base_cmd.append("--conditioned-profile") |
| 830 |
|
| 831 |
if suite_category not in c["suite_definitions"]: |
| 832 |
self.fatal("'%s' not defined in the config!") |
| 833 |
|
| 834 |
if suite in ( |
| 835 |
"browser-chrome-coverage", |
| 836 |
"xpcshell-coverage", |
| 837 |
"mochitest-devtools-chrome-coverage", |
| 838 |
"plain-coverage", |
| 839 |
): |
| 840 |
base_cmd.append("--jscov-dir-prefix=%s" % dirs["abs_blob_upload_dir"]) |
| 841 |
|
| 842 |
options = c["suite_definitions"][suite_category]["options"] |
| 843 |
if options: |
| 844 |
for option in options: |
| 845 |
option = option % str_format_values |
| 846 |
if not option.endswith("None"): |
| 847 |
base_cmd.append(option) |
| 848 |
if self.structured_output( |
| 849 |
suite_category, self._query_try_flavor(suite_category, suite) |
| 850 |
): |
| 851 |
base_cmd.append("--log-raw=-") |
| 852 |
return base_cmd |
| 853 |
else: |
| 854 |
self.warning( |
| 855 |
"Suite options for %s could not be determined." |
| 856 |
"\nIf you meant to have options for this suite, " |
| 857 |
"please make sure they are specified in your " |
| 858 |
"config under %s_options" % (suite_category, suite_category) |
| 859 |
) |
| 860 |
|
| 861 |
return base_cmd |
| 862 |
else: |
| 863 |
self.fatal( |
| 864 |
"'binary_path' could not be determined.\n This should " |
| 865 |
"be like '/path/build/application/firefox/firefox'" |
| 866 |
"\nIf you are running this script without the 'install' " |
| 867 |
"action (where binary_path is set), please ensure you are" |
| 868 |
" either:\n(1) specifying it in the config file under " |
| 869 |
"binary_path\n(2) specifying it on command line with the" |
| 870 |
" '--binary-path' flag" |
| 871 |
) |
| 872 |
|
| 873 |
def _query_specified_suites(self, category, sub_category=None): |
| 874 |
"""Checks if the provided suite does indeed exist. |
| 875 |
|
| 876 |
If at least one suite was given and if it does exist, return the suite |
| 877 |
as legitimate and line it up for execution. |
| 878 |
|
| 879 |
Otherwise, do not run any suites and return a fatal error. |
| 880 |
""" |
| 881 |
c = self.config |
| 882 |
all_suites = c.get(f"all_{category}_suites", None) |
| 883 |
specified_suites = c.get(f"specified_{category}_suites", None) |
| 884 |
|
| 885 |
# Bug 1603842 - disallow selection of more than 1 suite at at time |
| 886 |
if specified_suites is None: |
| 887 |
# Path taken by test-verify |
| 888 |
return self.query_per_test_category_suites(category, all_suites) |
| 889 |
if specified_suites and len(specified_suites) > 1: |
| 890 |
self.fatal( |
| 891 |
"""Selection of multiple suites is not permitted. \ |
| 892 |
Please select at most 1 test suite.""" |
| 893 |
) |
| 894 |
return |
| 895 |
|
| 896 |
# Normal path taken by most test suites as only one suite is specified |
| 897 |
suite = specified_suites[0] |
| 898 |
if suite not in all_suites: |
| 899 |
self.fatal("""Selected suite does not exist!""") |
| 900 |
|
| 901 |
# allow for fine grain suite selection |
| 902 |
ret_val = all_suites[suite] |
| 903 |
if sub_category in all_suites: |
| 904 |
if all_suites[sub_category] != ret_val: |
| 905 |
return None |
| 906 |
|
| 907 |
return {suite: ret_val} |
| 908 |
|
| 909 |
def _query_try_flavor(self, category, suite): |
| 910 |
flavors = { |
| 911 |
"mochitest": [ |
| 912 |
("plain.*", "mochitest"), |
| 913 |
("browser-chrome.*", "browser-chrome"), |
| 914 |
("mochitest-browser-a11y.*", "browser-a11y"), |
| 915 |
("mochitest-browser-media.*", "browser-media"), |
| 916 |
("mochitest-browser-translations.*", "browser-translations"), |
| 917 |
("mochitest-devtools-chrome.*", "devtools-chrome"), |
| 918 |
("chrome", "chrome"), |
| 919 |
], |
| 920 |
"xpcshell": [("xpcshell", "xpcshell")], |
| 921 |
"reftest": [("reftest", "reftest"), ("crashtest", "crashtest")], |
| 922 |
} |
| 923 |
for suite_pattern, flavor in flavors.get(category, []): |
| 924 |
if re.compile(suite_pattern).match(suite): |
| 925 |
return flavor |
| 926 |
|
| 927 |
def structured_output(self, suite_category, flavor=None): |
| 928 |
unstructured_flavors = self.config.get("unstructured_flavors") |
| 929 |
if not unstructured_flavors: |
| 930 |
return True |
| 931 |
if suite_category not in unstructured_flavors: |
| 932 |
return True |
| 933 |
if not unstructured_flavors.get( |
| 934 |
suite_category |
| 935 |
) or flavor in unstructured_flavors.get(suite_category): |
| 936 |
return False |
| 937 |
return True |
| 938 |
|
| 939 |
def get_test_output_parser( |
| 940 |
self, suite_category, flavor=None, strict=False, **kwargs |
| 941 |
): |
| 942 |
if not self.structured_output(suite_category, flavor): |
| 943 |
return DesktopUnittestOutputParser(suite_category=suite_category, **kwargs) |
| 944 |
self.info("Structured output parser in use for %s." % suite_category) |
| 945 |
return StructuredOutputParser( |
| 946 |
suite_category=suite_category, strict=strict, **kwargs |
| 947 |
) |
| 948 |
|
| 949 |
# Actions {{{2 |
| 950 |
|
| 951 |
# clobber defined in BaseScript, deletes mozharness/build if exists |
| 952 |
# preflight_download_and_extract is in TestingMixin. |
| 953 |
# create_virtualenv is in VirtualenvMixin. |
| 954 |
# preflight_install is in TestingMixin. |
| 955 |
# install is in TestingMixin. |
| 956 |
|
| 957 |
@PreScriptAction("download-and-extract") |
| 958 |
def _pre_download_and_extract(self, action): |
| 959 |
"""Abort if --artifact try syntax is used with compiled-code tests""" |
| 960 |
dir = self.query_abs_dirs()["abs_blob_upload_dir"] |
| 961 |
self.mkdir_p(dir) |
| 962 |
|
| 963 |
if not self.try_message_has_flag("artifact"): |
| 964 |
return |
| 965 |
self.info("Artifact build requested in try syntax.") |
| 966 |
rejected = [] |
| 967 |
compiled_code_suites = [ |
| 968 |
"cppunit", |
| 969 |
"gtest", |
| 970 |
"jittest", |
| 971 |
] |
| 972 |
for category in SUITE_CATEGORIES: |
| 973 |
suites = self._query_specified_suites(category) or [] |
| 974 |
for suite in suites: |
| 975 |
if any([suite.startswith(c) for c in compiled_code_suites]): |
| 976 |
rejected.append(suite) |
| 977 |
break |
| 978 |
if rejected: |
| 979 |
self.record_status(TBPL_EXCEPTION) |
| 980 |
self.fatal( |
| 981 |
"There are specified suites that are incompatible with " |
| 982 |
"--artifact try syntax flag: {}".format(", ".join(rejected)), |
| 983 |
exit_code=self.return_code, |
| 984 |
) |
| 985 |
|
| 986 |
def download_and_extract(self): |
| 987 |
""" |
| 988 |
download and extract test zip / download installer |
| 989 |
optimizes which subfolders to extract from tests archive |
| 990 |
""" |
| 991 |
c = self.config |
| 992 |
|
| 993 |
extract_dirs = None |
| 994 |
|
| 995 |
if c.get("run_all_suites"): |
| 996 |
target_categories = SUITE_CATEGORIES |
| 997 |
else: |
| 998 |
target_categories = [ |
| 999 |
cat |
| 1000 |
for cat in SUITE_CATEGORIES |
| 1001 |
if self._query_specified_suites(cat) is not None |
| 1002 |
] |
| 1003 |
super(DesktopUnittest, self).download_and_extract( |
| 1004 |
extract_dirs=extract_dirs, suite_categories=target_categories |
| 1005 |
) |
| 1006 |
|
| 1007 |
def start_pulseaudio(self): |
| 1008 |
command = [] |
| 1009 |
# Implies that underlying system is Linux. |
| 1010 |
if os.environ.get("NEED_PULSEAUDIO") == "true": |
| 1011 |
command.extend( |
| 1012 |
[ |
| 1013 |
"pulseaudio", |
| 1014 |
"--daemonize", |
| 1015 |
"--log-level=4", |
| 1016 |
"--log-time=1", |
| 1017 |
"-vvvvv", |
| 1018 |
"--exit-idle-time=-1", |
| 1019 |
] |
| 1020 |
) |
| 1021 |
|
| 1022 |
# Only run the initialization for Debian. |
| 1023 |
# Ubuntu appears to have an alternate method of starting pulseaudio. |
| 1024 |
if self._is_debian(): |
| 1025 |
self._kill_named_proc("pulseaudio") |
| 1026 |
self.run_command(command) |
| 1027 |
|
| 1028 |
# All Linux systems need module-null-sink to be loaded, otherwise |
| 1029 |
# media tests fail. |
| 1030 |
|
| 1031 |
self.run_command("pactl load-module module-null-sink") |
| 1032 |
modules = self.get_output_from_command("pactl list modules short") |
| 1033 |
if not [l for l in modules.splitlines() if "module-x11" in l]: |
| 1034 |
# gnome-session isn't running, missing logind and other system services |
| 1035 |
# force the task to retry (return 4) |
| 1036 |
self.return_code = 4 |
| 1037 |
self.fatal( |
| 1038 |
"Unable to start PulseAudio and load x11 modules", |
| 1039 |
exit_code=self.return_code, |
| 1040 |
) |
| 1041 |
|
| 1042 |
def stage_files(self): |
| 1043 |
for category in SUITE_CATEGORIES: |
| 1044 |
suites = self._query_specified_suites(category) |
| 1045 |
stage = getattr(self, f"_stage_{category}", None) |
| 1046 |
if suites and stage: |
| 1047 |
stage(suites) |
| 1048 |
|
| 1049 |
def _stage_files(self, bin_name=None, fail_if_not_exists=True): |
| 1050 |
dirs = self.query_abs_dirs() |
| 1051 |
abs_app_dir = self.query_abs_app_dir() |
| 1052 |
|
| 1053 |
# For mac these directories are in Contents/Resources, on other |
| 1054 |
# platforms abs_res_dir will point to abs_app_dir. |
| 1055 |
abs_res_dir = self.query_abs_res_dir() |
| 1056 |
abs_res_components_dir = os.path.join(abs_res_dir, "components") |
| 1057 |
abs_res_plugins_dir = os.path.join(abs_res_dir, "plugins") |
| 1058 |
abs_res_extensions_dir = os.path.join(abs_res_dir, "extensions") |
| 1059 |
|
| 1060 |
if bin_name: |
| 1061 |
src = os.path.join(dirs["abs_test_bin_dir"], bin_name) |
| 1062 |
if os.path.exists(src): |
| 1063 |
self.info( |
| 1064 |
"copying %s to %s" % (src, os.path.join(abs_app_dir, bin_name)) |
| 1065 |
) |
| 1066 |
shutil.copy2(src, os.path.join(abs_app_dir, bin_name)) |
| 1067 |
elif fail_if_not_exists: |
| 1068 |
raise OSError("File %s not found" % src) |
| 1069 |
self.copytree( |
| 1070 |
dirs["abs_test_bin_components_dir"], |
| 1071 |
abs_res_components_dir, |
| 1072 |
overwrite="overwrite_if_exists", |
| 1073 |
) |
| 1074 |
self.mkdir_p(abs_res_plugins_dir) |
| 1075 |
self.copytree( |
| 1076 |
dirs["abs_test_bin_plugins_dir"], |
| 1077 |
abs_res_plugins_dir, |
| 1078 |
overwrite="overwrite_if_exists", |
| 1079 |
) |
| 1080 |
if os.path.isdir(dirs["abs_test_extensions_dir"]): |
| 1081 |
self.mkdir_p(abs_res_extensions_dir) |
| 1082 |
self.copytree( |
| 1083 |
dirs["abs_test_extensions_dir"], |
| 1084 |
abs_res_extensions_dir, |
| 1085 |
overwrite="overwrite_if_exists", |
| 1086 |
) |
| 1087 |
|
| 1088 |
def _stage_xpcshell(self, suites): |
| 1089 |
if "WindowsApps" in self.binary_path: |
| 1090 |
self.log( |
| 1091 |
"Skipping stage xpcshell for MSIX tests because we cannot copy files into the installation directory." |
| 1092 |
) |
| 1093 |
return |
| 1094 |
|
| 1095 |
self._stage_files(self.config["xpcshell_name"]) |
| 1096 |
if "plugin_container_name" in self.config: |
| 1097 |
self._stage_files(self.config["plugin_container_name"]) |
| 1098 |
# http3server isn't built for Windows tests or Linux asan/tsan |
| 1099 |
# builds. Only stage if the `http3server_name` config is set and if |
| 1100 |
# the file actually exists. |
| 1101 |
if self.config.get("http3server_name"): |
| 1102 |
self._stage_files(self.config["http3server_name"], fail_if_not_exists=False) |
| 1103 |
|
| 1104 |
def _stage_cppunittest(self, suites): |
| 1105 |
abs_res_dir = self.query_abs_res_dir() |
| 1106 |
dirs = self.query_abs_dirs() |
| 1107 |
abs_cppunittest_dir = dirs["abs_cppunittest_dir"] |
| 1108 |
|
| 1109 |
# move manifest and js fils to resources dir, where tests expect them |
| 1110 |
files = glob.glob(os.path.join(abs_cppunittest_dir, "*.js")) |
| 1111 |
files.extend(glob.glob(os.path.join(abs_cppunittest_dir, "*.manifest"))) |
| 1112 |
for f in files: |
| 1113 |
self.move(f, abs_res_dir) |
| 1114 |
|
| 1115 |
def _stage_gtest(self, suites): |
| 1116 |
abs_res_dir = self.query_abs_res_dir() |
| 1117 |
abs_app_dir = self.query_abs_app_dir() |
| 1118 |
dirs = self.query_abs_dirs() |
| 1119 |
abs_gtest_dir = dirs["abs_gtest_dir"] |
| 1120 |
dirs["abs_test_bin_dir"] = os.path.join(dirs["abs_test_install_dir"], "bin") |
| 1121 |
|
| 1122 |
files = glob.glob(os.path.join(dirs["abs_test_bin_plugins_dir"], "gmp-*")) |
| 1123 |
files.append(os.path.join(abs_gtest_dir, "dependentlibs.list.gtest")) |
| 1124 |
for f in files: |
| 1125 |
self.move(f, abs_res_dir) |
| 1126 |
|
| 1127 |
self.copytree( |
| 1128 |
os.path.join(abs_gtest_dir, "gtest_bin"), os.path.join(abs_app_dir) |
| 1129 |
) |
| 1130 |
|
| 1131 |
def _kill_proc_tree(self, pid): |
| 1132 |
# Kill a process tree (including grandchildren) with signal.SIGTERM |
| 1133 |
try: |
| 1134 |
import signal |
| 1135 |
|
| 1136 |
import psutil |
| 1137 |
|
| 1138 |
if pid == os.getpid(): |
| 1139 |
return (None, None) |
| 1140 |
|
| 1141 |
parent = psutil.Process(pid) |
| 1142 |
children = parent.children(recursive=True) |
| 1143 |
children.append(parent) |
| 1144 |
|
| 1145 |
for p in children: |
| 1146 |
p.send_signal(signal.SIGTERM) |
| 1147 |
|
| 1148 |
# allow for 60 seconds to kill procs |
| 1149 |
timeout = 60 |
| 1150 |
gone, alive = psutil.wait_procs(children, timeout=timeout) |
| 1151 |
for p in gone: |
| 1152 |
self.info("psutil found pid %s dead" % p.pid) |
| 1153 |
for p in alive: |
| 1154 |
self.error("failed to kill pid %d after %d" % (p.pid, timeout)) |
| 1155 |
|
| 1156 |
return (gone, alive) |
| 1157 |
except Exception as e: |
| 1158 |
self.error("Exception while trying to kill process tree: %s" % str(e)) |
| 1159 |
|
| 1160 |
def _kill_named_proc(self, pname): |
| 1161 |
try: |
| 1162 |
import psutil |
| 1163 |
except Exception as e: |
| 1164 |
self.info( |
| 1165 |
"Error importing psutil, not killing process %s: %s" % pname, str(e) |
| 1166 |
) |
| 1167 |
return |
| 1168 |
|
| 1169 |
for proc in psutil.process_iter(): |
| 1170 |
try: |
| 1171 |
if proc.name() == pname: |
| 1172 |
procd = proc.as_dict(attrs=["pid", "ppid", "name", "username"]) |
| 1173 |
self.info("in _kill_named_proc, killing %s" % procd) |
| 1174 |
self._kill_proc_tree(proc.pid) |
| 1175 |
except Exception as e: |
| 1176 |
self.info("Warning: Unable to kill process %s: %s" % (pname, str(e))) |
| 1177 |
# may not be able to access process info for all processes |
| 1178 |
continue |
| 1179 |
|
| 1180 |
def _remove_xen_clipboard(self): |
| 1181 |
""" |
| 1182 |
When running on a Windows 7 VM, we have XenDPriv.exe running which |
| 1183 |
interferes with the clipboard, lets terminate this process and remove |
| 1184 |
the binary so it doesn't restart |
| 1185 |
""" |
| 1186 |
if not self._is_windows(): |
| 1187 |
return |
| 1188 |
|
| 1189 |
self._kill_named_proc("XenDPriv.exe") |
| 1190 |
xenpath = os.path.join( |
| 1191 |
os.environ["ProgramFiles"], "Citrix", "XenTools", "XenDPriv.exe" |
| 1192 |
) |
| 1193 |
try: |
| 1194 |
if os.path.isfile(xenpath): |
| 1195 |
os.remove(xenpath) |
| 1196 |
except Exception as e: |
| 1197 |
self.error("Error: Failure to remove file %s: %s" % (xenpath, str(e))) |
| 1198 |
|
| 1199 |
def _report_system_info(self): |
| 1200 |
""" |
| 1201 |
Create the system-info.log artifact file, containing a variety of |
| 1202 |
system information that might be useful in diagnosing test failures. |
| 1203 |
""" |
| 1204 |
try: |
| 1205 |
import psutil |
| 1206 |
|
| 1207 |
path = os.path.join( |
| 1208 |
self.query_abs_dirs()["abs_blob_upload_dir"], "system-info.log" |
| 1209 |
) |
| 1210 |
with open(path, "w") as f: |
| 1211 |
f.write("System info collected at %s\n\n" % datetime.now()) |
| 1212 |
f.write("\nBoot time %s\n" % datetime.fromtimestamp(psutil.boot_time())) |
| 1213 |
f.write("\nVirtual memory: %s\n" % str(psutil.virtual_memory())) |
| 1214 |
f.write("\nDisk partitions: %s\n" % str(psutil.disk_partitions())) |
| 1215 |
f.write("\nDisk usage (/): %s\n" % str(psutil.disk_usage(os.path.sep))) |
| 1216 |
if not self._is_windows(): |
| 1217 |
# bug 1417189: frequent errors querying users on Windows |
| 1218 |
f.write("\nUsers: %s\n" % str(psutil.users())) |
| 1219 |
f.write("\nNetwork connections:\n") |
| 1220 |
try: |
| 1221 |
for nc in psutil.net_connections(): |
| 1222 |
f.write(" %s\n" % str(nc)) |
| 1223 |
except Exception as e: |
| 1224 |
f.write("Exception getting network info: %s\n" % e) |
| 1225 |
f.write("\nProcesses:\n") |
| 1226 |
try: |
| 1227 |
for p in psutil.process_iter(): |
| 1228 |
ctime = str(datetime.fromtimestamp(p.create_time())) |
| 1229 |
try: |
| 1230 |
cmdline = p.cmdline() |
| 1231 |
except psutil.NoSuchProcess: |
| 1232 |
cmdline = "" |
| 1233 |
f.write( |
| 1234 |
" PID %d %s %s created at %s [%s]\n" |
| 1235 |
% (p.pid, p.name(), cmdline, ctime, p.status()) |
| 1236 |
) |
| 1237 |
except Exception as e: |
| 1238 |
f.write("Exception getting process info: %s\n" % e) |
| 1239 |
except Exception: |
| 1240 |
# psutil throws a variety of intermittent exceptions |
| 1241 |
self.info("Unable to complete system-info.log: %s" % sys.exc_info()[0]) |
| 1242 |
|
| 1243 |
# pull defined in VCSScript. |
| 1244 |
# preflight_run_tests defined in TestingMixin. |
| 1245 |
|
| 1246 |
def run_tests(self): |
| 1247 |
self._remove_xen_clipboard() |
| 1248 |
self._report_system_info() |
| 1249 |
self.start_time = datetime.now() |
| 1250 |
for category in SUITE_CATEGORIES: |
| 1251 |
if not self._run_category_suites(category): |
| 1252 |
break |
| 1253 |
|
| 1254 |
def get_timeout_for_category(self, suite_category): |
| 1255 |
if suite_category == "cppunittest": |
| 1256 |
return 2500 |
| 1257 |
return self.config["suite_definitions"][suite_category].get("run_timeout", 1000) |
| 1258 |
|
| 1259 |
def _run_category_suites(self, suite_category): |
| 1260 |
"""run suite(s) to a specific category""" |
| 1261 |
dirs = self.query_abs_dirs() |
| 1262 |
suites = self._query_specified_suites(suite_category) |
| 1263 |
abs_app_dir = self.query_abs_app_dir() |
| 1264 |
abs_res_dir = self.query_abs_res_dir() |
| 1265 |
|
| 1266 |
max_per_test_time = timedelta(minutes=60) |
| 1267 |
max_per_test_tests = 10 |
| 1268 |
if self.per_test_coverage: |
| 1269 |
max_per_test_tests = 30 |
| 1270 |
executed_tests = 0 |
| 1271 |
executed_too_many_tests = False |
| 1272 |
xpcshell_selftests = 0 |
| 1273 |
|
| 1274 |
def do_gnome_video_recording(suite_name, upload_dir, ev): |
| 1275 |
import os |
| 1276 |
import subprocess |
| 1277 |
|
| 1278 |
import dbus |
| 1279 |
|
| 1280 |
target_file = os.path.join( |
| 1281 |
upload_dir, |
| 1282 |
f"video_{suite_name}.webm", |
| 1283 |
) |
| 1284 |
|
| 1285 |
tmp_file = os.path.join( |
| 1286 |
upload_dir, |
| 1287 |
f"video_{suite_name}_tmp.webm", |
| 1288 |
) |
| 1289 |
|
| 1290 |
self.info(f"Recording suite {suite_name} to {target_file}") |
| 1291 |
|
| 1292 |
session_bus = dbus.SessionBus() |
| 1293 |
session_bus.call_blocking( |
| 1294 |
"org.gnome.Shell.Screencast", |
| 1295 |
"/org/gnome/Shell/Screencast", |
| 1296 |
"org.gnome.Shell.Screencast", |
| 1297 |
"Screencast", |
| 1298 |
signature="sa{sv}", |
| 1299 |
args=[ |
| 1300 |
tmp_file, |
| 1301 |
{"draw-cursor": True, "framerate": 35}, |
| 1302 |
], |
| 1303 |
) |
| 1304 |
|
| 1305 |
ev.wait() |
| 1306 |
|
| 1307 |
# Use ffmpeg to add duration headers in the screen recording. |
| 1308 |
try: |
| 1309 |
subprocess.run( |
| 1310 |
[ |
| 1311 |
"ffmpeg", |
| 1312 |
"-i", |
| 1313 |
tmp_file, |
| 1314 |
"-vcodec", |
| 1315 |
"copy", |
| 1316 |
"-acodec", |
| 1317 |
"copy", |
| 1318 |
target_file, |
| 1319 |
], |
| 1320 |
check=True, |
| 1321 |
) |
| 1322 |
# If subprocess.run did not raise CalledProcessError, remove |
| 1323 |
# the temporary file. |
| 1324 |
os.remove(tmp_file) |
| 1325 |
except subprocess.CalledProcessError as e: |
| 1326 |
self.error( |
| 1327 |
f"Error occurred while running ffmpeg: {e.stderr} ({e.returncode})" |
| 1328 |
) |
| 1329 |
# If subprocess.run failed, rename the temporary file to the |
| 1330 |
# expected target file name. |
| 1331 |
os.rename(tmp_file, target_file) |
| 1332 |
|
| 1333 |
def do_macos_video_recording(suite_name, upload_dir, ev): |
| 1334 |
import os |
| 1335 |
import subprocess |
| 1336 |
|
| 1337 |
target_file = os.path.join( |
| 1338 |
upload_dir, |
| 1339 |
f"video_{suite_name}.mov", |
| 1340 |
) |
| 1341 |
self.info(f"Recording suite {suite_name} to {target_file}") |
| 1342 |
|
| 1343 |
process = subprocess.Popen( |
| 1344 |
["/usr/sbin/screencapture", "-v", "-k", target_file], |
| 1345 |
stdin=subprocess.PIPE, |
| 1346 |
) |
| 1347 |
ev.wait() |
| 1348 |
process.stdin.write(b"p") |
| 1349 |
process.stdin.flush() |
| 1350 |
process.wait() |
| 1351 |
|
| 1352 |
if suites: |
| 1353 |
self.info("#### Running %s suites" % suite_category) |
| 1354 |
for suite in suites: |
| 1355 |
if executed_too_many_tests and not self.per_test_coverage: |
| 1356 |
return False |
| 1357 |
|
| 1358 |
replace_dict = { |
| 1359 |
"abs_app_dir": abs_app_dir, |
| 1360 |
# Mac specific, but points to abs_app_dir on other |
| 1361 |
# platforms. |
| 1362 |
"abs_res_dir": abs_res_dir, |
| 1363 |
"binary_path": self.binary_path, |
| 1364 |
"install_dir": self.install_dir, |
| 1365 |
} |
| 1366 |
options_list = [] |
| 1367 |
env = {"TEST_SUITE": suite} |
| 1368 |
if isinstance(suites[suite], dict): |
| 1369 |
options_list = suites[suite].get("options", []) |
| 1370 |
if ( |
| 1371 |
self.verify_enabled |
| 1372 |
or self.per_test_coverage |
| 1373 |
or self._get_mozharness_test_paths(suite_category, suite) |
| 1374 |
): |
| 1375 |
# Ignore tests list in modes where we are running specific tests. |
| 1376 |
tests_list = [] |
| 1377 |
else: |
| 1378 |
tests_list = suites[suite].get("tests", []) |
| 1379 |
env = copy.deepcopy(suites[suite].get("env", {})) |
| 1380 |
else: |
| 1381 |
options_list = suites[suite] |
| 1382 |
tests_list = [] |
| 1383 |
|
| 1384 |
flavor = ( |
| 1385 |
self.mochitest_flavor |
| 1386 |
if self.mochitest_flavor |
| 1387 |
else self._query_try_flavor(suite_category, suite) |
| 1388 |
) |
| 1389 |
if self.mochitest_flavor: |
| 1390 |
replace_dict.update({"mochitest_flavor": flavor}) |
| 1391 |
|
| 1392 |
try_options, try_tests = self.try_args(flavor) |
| 1393 |
|
| 1394 |
suite_name = suite_category + "-" + suite |
| 1395 |
tbpl_status, log_level = None, None |
| 1396 |
error_list = BaseErrorList + HarnessErrorList |
| 1397 |
parser = self.get_test_output_parser( |
| 1398 |
suite_category, |
| 1399 |
flavor=flavor, |
| 1400 |
config=self.config, |
| 1401 |
error_list=error_list, |
| 1402 |
log_obj=self.log_obj, |
| 1403 |
) |
| 1404 |
|
| 1405 |
if suite_category == "reftest": |
| 1406 |
ref_formatter = load_source( |
| 1407 |
"ReftestFormatter", |
| 1408 |
os.path.abspath( |
| 1409 |
os.path.join(dirs["abs_reftest_dir"], "output.py") |
| 1410 |
), |
| 1411 |
) |
| 1412 |
parser.formatter = ref_formatter.ReftestFormatter() |
| 1413 |
|
| 1414 |
if self.query_minidump_stackwalk(): |
| 1415 |
env["MINIDUMP_STACKWALK"] = self.minidump_stackwalk_path |
| 1416 |
if self.config["nodejs_path"]: |
| 1417 |
env["MOZ_NODE_PATH"] = self.config["nodejs_path"] |
| 1418 |
env["MOZ_UPLOAD_DIR"] = self.query_abs_dirs()["abs_blob_upload_dir"] |
| 1419 |
env["MINIDUMP_SAVE_PATH"] = self.query_abs_dirs()["abs_blob_upload_dir"] |
| 1420 |
env["RUST_BACKTRACE"] = "full" |
| 1421 |
if not os.path.isdir(env["MOZ_UPLOAD_DIR"]): |
| 1422 |
self.mkdir_p(env["MOZ_UPLOAD_DIR"]) |
| 1423 |
|
| 1424 |
if self.config["allow_software_gl_layers"]: |
| 1425 |
env["MOZ_LAYERS_ALLOW_SOFTWARE_GL"] = "1" |
| 1426 |
|
| 1427 |
env = self.query_env(partial_env=env, log_level=INFO) |
| 1428 |
cmd_timeout = self.get_timeout_for_category(suite_category) |
| 1429 |
|
| 1430 |
summary = {} |
| 1431 |
for per_test_args in self.query_args(suite): |
| 1432 |
# Make sure baseline code coverage tests are never |
| 1433 |
# skipped and that having them run has no influence |
| 1434 |
# on the max number of actual tests that are to be run. |
| 1435 |
is_baseline_test = ( |
| 1436 |
"baselinecoverage" in per_test_args[-1] |
| 1437 |
if self.per_test_coverage |
| 1438 |
else False |
| 1439 |
) |
| 1440 |
if executed_too_many_tests and not is_baseline_test: |
| 1441 |
continue |
| 1442 |
|
| 1443 |
if not is_baseline_test: |
| 1444 |
if (datetime.now() - self.start_time) > max_per_test_time: |
| 1445 |
# Running tests has run out of time. That is okay! Stop running |
| 1446 |
# them so that a task timeout is not triggered, and so that |
| 1447 |
# (partial) results are made available in a timely manner. |
| 1448 |
self.info( |
| 1449 |
"TinderboxPrint: Running tests took too long: Not all tests " |
| 1450 |
"were executed.<br/>" |
| 1451 |
) |
| 1452 |
# Signal per-test time exceeded, to break out of suites and |
| 1453 |
# suite categories loops also. |
| 1454 |
return False |
| 1455 |
if executed_tests >= max_per_test_tests: |
| 1456 |
# When changesets are merged between trees or many tests are |
| 1457 |
# otherwise updated at once, there probably is not enough time |
| 1458 |
# to run all tests, and attempting to do so may cause other |
| 1459 |
# problems, such as generating too much log output. |
| 1460 |
self.info( |
| 1461 |
"TinderboxPrint: Too many modified tests: Not all tests " |
| 1462 |
"were executed.<br/>" |
| 1463 |
) |
| 1464 |
executed_too_many_tests = True |
| 1465 |
|
| 1466 |
executed_tests = executed_tests + 1 |
| 1467 |
|
| 1468 |
abs_base_cmd = self._query_abs_base_cmd(suite_category, suite) |
| 1469 |
cmd = abs_base_cmd[:] |
| 1470 |
cmd.extend( |
| 1471 |
self.query_options( |
| 1472 |
options_list, try_options, str_format_values=replace_dict |
| 1473 |
) |
| 1474 |
) |
| 1475 |
cmd.extend( |
| 1476 |
self.query_tests_args( |
| 1477 |
tests_list, try_tests, str_format_values=replace_dict |
| 1478 |
) |
| 1479 |
) |
| 1480 |
|
| 1481 |
final_cmd = copy.copy(cmd) |
| 1482 |
final_cmd.extend(per_test_args) |
| 1483 |
|
| 1484 |
# Bug 1714406: In test-verify of xpcshell tests on Windows, repeated |
| 1485 |
# self-tests can trigger https://bugs.python.org/issue37380, |
| 1486 |
# for python < 3.7; avoid by running xpcshell self-tests only once |
| 1487 |
# per test-verify run. |
| 1488 |
if ( |
| 1489 |
(self.verify_enabled or self.per_test_coverage) |
| 1490 |
and sys.platform.startswith("win") |
| 1491 |
and sys.version_info < (3, 7) |
| 1492 |
and "--self-test" in final_cmd |
| 1493 |
): |
| 1494 |
xpcshell_selftests += 1 |
| 1495 |
if xpcshell_selftests > 1: |
| 1496 |
final_cmd.remove("--self-test") |
| 1497 |
|
| 1498 |
final_env = copy.copy(env) |
| 1499 |
|
| 1500 |
finish_video = threading.Event() |
| 1501 |
video_recording_thread = None |
| 1502 |
if os.getenv("MOZ_RECORD_TEST"): |
| 1503 |
video_recording_target = None |
| 1504 |
if sys.platform == "linux": |
| 1505 |
video_recording_target = do_gnome_video_recording |
| 1506 |
elif sys.platform == "darwin": |
| 1507 |
video_recording_target = do_macos_video_recording |
| 1508 |
|
| 1509 |
if video_recording_target: |
| 1510 |
video_recording_thread = threading.Thread( |
| 1511 |
target=video_recording_target, |
| 1512 |
args=( |
| 1513 |
suite, |
| 1514 |
env["MOZ_UPLOAD_DIR"], |
| 1515 |
finish_video, |
| 1516 |
), |
| 1517 |
) |
| 1518 |
self.info(f"Starting recording thread {suite}") |
| 1519 |
video_recording_thread.start() |
| 1520 |
else: |
| 1521 |
self.warning( |
| 1522 |
"Screen recording not implemented for this platform" |
| 1523 |
) |
| 1524 |
|
| 1525 |
if self.per_test_coverage: |
| 1526 |
self.set_coverage_env(final_env) |
| 1527 |
|
| 1528 |
return_code = self.run_command( |
| 1529 |
final_cmd, |
| 1530 |
cwd=dirs["abs_work_dir"], |
| 1531 |
output_timeout=cmd_timeout, |
| 1532 |
output_parser=parser, |
| 1533 |
env=final_env, |
| 1534 |
) |
| 1535 |
|
| 1536 |
if self.per_test_coverage: |
| 1537 |
self.add_per_test_coverage_report( |
| 1538 |
final_env, suite, per_test_args[-1] |
| 1539 |
) |
| 1540 |
|
| 1541 |
# mochitest, reftest, and xpcshell suites do not return |
| 1542 |
# appropriate return codes. Therefore, we must parse the output |
| 1543 |
# to determine what the tbpl_status and worst_log_level must |
| 1544 |
# be. We do this by: |
| 1545 |
# 1) checking to see if our mozharness script ran into any |
| 1546 |
# errors itself with 'num_errors' <- OutputParser |
| 1547 |
# 2) if num_errors is 0 then we look in the subclassed 'parser' |
| 1548 |
# findings for harness/suite errors <- DesktopUnittestOutputParser |
| 1549 |
# 3) checking to see if the return code is in success_codes |
| 1550 |
|
| 1551 |
if video_recording_thread: |
| 1552 |
self.info(f"Stopping recording thread {suite}") |
| 1553 |
finish_video.set() |
| 1554 |
video_recording_thread.join() |
| 1555 |
self.info(f"Stopped recording thread {suite}") |
| 1556 |
|
| 1557 |
success_codes = None |
| 1558 |
tbpl_status, log_level, summary = parser.evaluate_parser( |
| 1559 |
return_code, success_codes, summary |
| 1560 |
) |
| 1561 |
parser.append_tinderboxprint_line(suite_name) |
| 1562 |
|
| 1563 |
self.record_status(tbpl_status, level=log_level) |
| 1564 |
if len(per_test_args) > 0: |
| 1565 |
self.log_per_test_status( |
| 1566 |
per_test_args[-1], tbpl_status, log_level |
| 1567 |
) |
| 1568 |
if tbpl_status == TBPL_RETRY: |
| 1569 |
self.info("Per-test run abandoned due to RETRY status") |
| 1570 |
return False |
| 1571 |
else: |
| 1572 |
# report as INFO instead of log_level to avoid extra Treeherder lines |
| 1573 |
self.info( |
| 1574 |
"The %s suite: %s ran with return status: %s" |
| 1575 |
% (suite_category, suite, tbpl_status), |
| 1576 |
) |
| 1577 |
|
| 1578 |
if executed_too_many_tests: |
| 1579 |
return False |
| 1580 |
else: |
| 1581 |
self.debug("There were no suites to run for %s" % suite_category) |
| 1582 |
return True |
| 1583 |
|
| 1584 |
def uninstall(self): |
| 1585 |
# Technically, we might miss this step if earlier steps fail badly. |
| 1586 |
# If that becomes a big issue we should consider moving this to |
| 1587 |
# something that is more likely to execute, such as |
| 1588 |
# postflight_run_cmd_suites |
| 1589 |
if "WindowsApps" in self.binary_path: |
| 1590 |
self.uninstall_app(self.binary_path) |
| 1591 |
else: |
| 1592 |
self.log("Skipping uninstall for non-MSIX test") |
| 1593 |
|
| 1594 |
|
| 1595 |
# main {{{1 |
| 1596 |
if __name__ == "__main__": |
| 1597 |
desktop_unittest = DesktopUnittest() |
| 1598 |
desktop_unittest.run_and_exit() |