| 1 |
#!/usr/bin/env python3 |
| 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 |
|
| 7 |
import argparse |
| 8 |
import json |
| 9 |
import logging |
| 10 |
import multiprocessing |
| 11 |
import os |
| 12 |
import platform |
| 13 |
import shlex |
| 14 |
import shutil |
| 15 |
import subprocess |
| 16 |
import sys |
| 17 |
from collections import Counter, namedtuple |
| 18 |
from logging import info |
| 19 |
from os import environ as env |
| 20 |
from pathlib import Path |
| 21 |
from subprocess import Popen |
| 22 |
from threading import Timer |
| 23 |
|
| 24 |
Dirs = namedtuple("Dirs", ["scripts", "js_src", "source", "fetches"]) |
| 25 |
|
| 26 |
|
| 27 |
def directories(pathmodule, cwd, fixup=lambda s: s): |
| 28 |
scripts = pathmodule.join(fixup(cwd), fixup(pathmodule.dirname(__file__))) |
| 29 |
js_src = pathmodule.abspath(pathmodule.join(scripts, "..", "..")) |
| 30 |
source = pathmodule.abspath(pathmodule.join(js_src, "..", "..")) |
| 31 |
mozbuild = pathmodule.abspath( |
| 32 |
# os.path.expanduser does not work on Windows. |
| 33 |
env.get("MOZBUILD_STATE_PATH") |
| 34 |
or pathmodule.join(Path.home(), ".mozbuild") |
| 35 |
) |
| 36 |
fetches = pathmodule.abspath(env.get("MOZ_FETCHES_DIR", mozbuild)) |
| 37 |
return Dirs(scripts, js_src, source, fetches) |
| 38 |
|
| 39 |
|
| 40 |
def quote(s): |
| 41 |
# shlex quotes for the purpose of passing to the native shell, which is cmd |
| 42 |
# on Windows, and therefore will not replace backslashed paths with forward |
| 43 |
# slashes. When such a path is passed to sh, the backslashes will be |
| 44 |
# interpreted as escape sequences. |
| 45 |
return shlex.quote(s).replace("\\", "/") |
| 46 |
|
| 47 |
|
| 48 |
# Some scripts will be called with sh, which cannot use backslashed |
| 49 |
# paths. So for direct subprocess.* invocation, use normal paths from |
| 50 |
# DIR, but when running under the shell, use POSIX style paths. |
| 51 |
DIR = directories(os.path, os.getcwd()) |
| 52 |
|
| 53 |
AUTOMATION = env.get("AUTOMATION", False) |
| 54 |
|
| 55 |
parser = argparse.ArgumentParser(description="Run a spidermonkey shell build job") |
| 56 |
parser.add_argument( |
| 57 |
"--verbose", |
| 58 |
action="store_true", |
| 59 |
default=AUTOMATION, |
| 60 |
help="display additional logging info", |
| 61 |
) |
| 62 |
parser.add_argument( |
| 63 |
"--dep", action="store_true", help="do not clobber the objdir before building" |
| 64 |
) |
| 65 |
parser.add_argument( |
| 66 |
"--keep", |
| 67 |
action="store_true", |
| 68 |
help="do not delete the sanitizer output directory (for testing)", |
| 69 |
) |
| 70 |
parser.add_argument( |
| 71 |
"--platform", |
| 72 |
"-p", |
| 73 |
type=str, |
| 74 |
metavar="PLATFORM", |
| 75 |
default="", |
| 76 |
help='build platform, including a suffix ("-debug" or "") used ' |
| 77 |
'by buildbot to override the variant\'s "debug" setting. The platform can be ' |
| 78 |
"used to specify 32 vs 64 bits.", |
| 79 |
) |
| 80 |
parser.add_argument( |
| 81 |
"--timeout", |
| 82 |
"-t", |
| 83 |
type=int, |
| 84 |
metavar="TIMEOUT", |
| 85 |
default=12600, |
| 86 |
help="kill job after TIMEOUT seconds", |
| 87 |
) |
| 88 |
parser.add_argument( |
| 89 |
"--objdir", |
| 90 |
type=str, |
| 91 |
metavar="DIR", |
| 92 |
# The real default must be set later so that OBJDIR can be |
| 93 |
# relative to the srcdir. |
| 94 |
default=env.get("OBJDIR"), |
| 95 |
help="object directory", |
| 96 |
) |
| 97 |
group = parser.add_mutually_exclusive_group() |
| 98 |
group.add_argument( |
| 99 |
"--optimize", |
| 100 |
action="store_true", |
| 101 |
help="generate an optimized build. Overrides variant setting.", |
| 102 |
) |
| 103 |
group.add_argument( |
| 104 |
"--no-optimize", |
| 105 |
action="store_false", |
| 106 |
dest="optimize", |
| 107 |
help="generate a non-optimized build. Overrides variant setting.", |
| 108 |
) |
| 109 |
group.set_defaults(optimize=None) |
| 110 |
group = parser.add_mutually_exclusive_group() |
| 111 |
group.add_argument( |
| 112 |
"--debug", |
| 113 |
action="store_true", |
| 114 |
help="generate a debug build. Overrides variant setting.", |
| 115 |
) |
| 116 |
group.add_argument( |
| 117 |
"--no-debug", |
| 118 |
action="store_false", |
| 119 |
dest="debug", |
| 120 |
help="generate a non-debug build. Overrides variant setting.", |
| 121 |
) |
| 122 |
group.set_defaults(debug=None) |
| 123 |
group = parser.add_mutually_exclusive_group() |
| 124 |
group.add_argument( |
| 125 |
"--jemalloc", |
| 126 |
action="store_true", |
| 127 |
dest="jemalloc", |
| 128 |
help="use mozilla's jemalloc instead of the default allocator", |
| 129 |
) |
| 130 |
group.add_argument( |
| 131 |
"--no-jemalloc", |
| 132 |
action="store_false", |
| 133 |
dest="jemalloc", |
| 134 |
help="use the default allocator instead of mozilla's jemalloc", |
| 135 |
) |
| 136 |
group.set_defaults(jemalloc=None) |
| 137 |
parser.add_argument( |
| 138 |
"--run-tests", |
| 139 |
"--tests", |
| 140 |
type=str, |
| 141 |
metavar="TESTSUITE", |
| 142 |
default="", |
| 143 |
help="comma-separated set of test suites to add to the variant's default set", |
| 144 |
) |
| 145 |
parser.add_argument( |
| 146 |
"--skip-tests", |
| 147 |
"--skip", |
| 148 |
type=str, |
| 149 |
metavar="TESTSUITE", |
| 150 |
default="", |
| 151 |
help="comma-separated set of test suites to remove from the variant's default " |
| 152 |
"set", |
| 153 |
) |
| 154 |
parser.add_argument( |
| 155 |
"--build-only", |
| 156 |
"--build", |
| 157 |
dest="skip_tests", |
| 158 |
action="store_const", |
| 159 |
const="all", |
| 160 |
help="only do a build, do not run any tests", |
| 161 |
) |
| 162 |
parser.add_argument( |
| 163 |
"--nobuild", |
| 164 |
action="store_true", |
| 165 |
help="Do not do a build. Rerun tests on existing build.", |
| 166 |
) |
| 167 |
parser.add_argument( |
| 168 |
"variant", type=str, help="type of job requested, see variants/ subdir" |
| 169 |
) |
| 170 |
args = parser.parse_args() |
| 171 |
|
| 172 |
logging.basicConfig(level=logging.INFO, format="%(message)s") |
| 173 |
|
| 174 |
env["CPP_UNIT_TESTS_DIR_JS_SRC"] = DIR.js_src |
| 175 |
if AUTOMATION and platform.system() == "Windows": |
| 176 |
# build/win{32,64}/mozconfig.vs-latest uses TOOLTOOL_DIR to set VSPATH. |
| 177 |
env["TOOLTOOL_DIR"] = DIR.fetches |
| 178 |
|
| 179 |
OBJDIR = args.objdir or os.path.join(DIR.source, "obj-spider") |
| 180 |
OBJDIR = os.path.abspath(OBJDIR) |
| 181 |
OUTDIR = os.path.join(OBJDIR, "out") |
| 182 |
MAKE = env.get("MAKE", "make") |
| 183 |
PYTHON = sys.executable |
| 184 |
MACH = os.path.join(DIR.source, "mach") |
| 185 |
|
| 186 |
for d in DIR._fields: |
| 187 |
info(f"DIR.{d} = {getattr(DIR, d)}") |
| 188 |
|
| 189 |
|
| 190 |
def ensure_dir_exists( |
| 191 |
name, clobber=True, creation_marker_filename="CREATED-BY-AUTOSPIDER" |
| 192 |
): |
| 193 |
if creation_marker_filename is None: |
| 194 |
marker = None |
| 195 |
else: |
| 196 |
marker = os.path.join(name, creation_marker_filename) |
| 197 |
if clobber: |
| 198 |
if ( |
| 199 |
not AUTOMATION |
| 200 |
and marker |
| 201 |
and os.path.exists(name) |
| 202 |
and not os.path.exists(marker) |
| 203 |
): |
| 204 |
raise Exception( |
| 205 |
"Refusing to delete objdir %s because it was not created by autospider" |
| 206 |
% name |
| 207 |
) |
| 208 |
shutil.rmtree(name, ignore_errors=True) |
| 209 |
try: |
| 210 |
os.mkdir(name) |
| 211 |
if marker: |
| 212 |
open(marker, "a").close() |
| 213 |
except OSError: |
| 214 |
if clobber: |
| 215 |
raise |
| 216 |
|
| 217 |
|
| 218 |
with open(os.path.join(DIR.scripts, "variants", args.variant)) as fh: |
| 219 |
variant = json.load(fh) |
| 220 |
|
| 221 |
# Some of the variants request a particular word size (eg ARM simulators). |
| 222 |
word_bits = variant.get("bits") |
| 223 |
|
| 224 |
# On Linux and Windows, we build 32- and 64-bit versions on a 64 bit |
| 225 |
# host, so the caller has to specify what is desired. |
| 226 |
if word_bits is None and args.platform: |
| 227 |
platform_arch = args.platform.split("-")[0] |
| 228 |
if platform_arch in ("win32", "linux"): |
| 229 |
word_bits = 32 |
| 230 |
elif platform_arch in ("win64", "linux64"): |
| 231 |
word_bits = 64 |
| 232 |
|
| 233 |
# Fall back to the word size of the host. |
| 234 |
if word_bits is None: |
| 235 |
word_bits = 64 if platform.architecture()[0] == "64bit" else 32 |
| 236 |
|
| 237 |
# Need a platform name to use as a key in variant files. |
| 238 |
if args.platform: |
| 239 |
variant_platform = args.platform.split("-")[0] |
| 240 |
elif platform.system() == "Windows": |
| 241 |
variant_platform = "win64" if word_bits == 64 else "win32" |
| 242 |
elif platform.system() == "Linux": |
| 243 |
variant_platform = "linux64" if word_bits == 64 else "linux" |
| 244 |
elif platform.system() == "Darwin": |
| 245 |
variant_platform = "macosx64" |
| 246 |
else: |
| 247 |
variant_platform = "other" |
| 248 |
|
| 249 |
CONFIGURE_ARGS = variant["configure-args"] |
| 250 |
|
| 251 |
if variant_platform in ("win32", "win64"): |
| 252 |
compiler = "clang-cl" |
| 253 |
else: |
| 254 |
compiler = variant.get("compiler") |
| 255 |
if compiler != "gcc" and "clang-plugin" not in CONFIGURE_ARGS: |
| 256 |
CONFIGURE_ARGS += " --enable-clang-plugin" |
| 257 |
|
| 258 |
if compiler == "gcc": |
| 259 |
if AUTOMATION: |
| 260 |
fetches = env["MOZ_FETCHES_DIR"] |
| 261 |
env["CC"] = os.path.join(fetches, "gcc", "bin", "gcc") |
| 262 |
env["CXX"] = os.path.join(fetches, "gcc", "bin", "g++") |
| 263 |
else: |
| 264 |
env["CC"] = "gcc" |
| 265 |
env["CXX"] = "g++" |
| 266 |
|
| 267 |
opt = args.optimize |
| 268 |
if opt is None: |
| 269 |
opt = variant.get("optimize") |
| 270 |
if opt is not None: |
| 271 |
CONFIGURE_ARGS += " --enable-optimize" if opt else " --disable-optimize" |
| 272 |
|
| 273 |
opt = args.debug |
| 274 |
if opt is None: |
| 275 |
opt = variant.get("debug") |
| 276 |
if opt is not None: |
| 277 |
CONFIGURE_ARGS += " --enable-debug" if opt else " --disable-debug" |
| 278 |
|
| 279 |
opt = args.jemalloc |
| 280 |
if opt is not None: |
| 281 |
CONFIGURE_ARGS += " --enable-jemalloc" if opt else " --disable-jemalloc" |
| 282 |
|
| 283 |
# By default, we build with NSPR, even if not specified. But we actively allow |
| 284 |
# builds to disable NSPR. |
| 285 |
opt = variant.get("nspr") |
| 286 |
if opt is None or opt: |
| 287 |
CONFIGURE_ARGS += " --enable-nspr-build" |
| 288 |
|
| 289 |
env["LD_LIBRARY_PATH"] = ":".join( |
| 290 |
d |
| 291 |
for d in [ |
| 292 |
# for libnspr etc. |
| 293 |
os.path.join(OBJDIR, "dist", "bin"), |
| 294 |
# existing search path, if any |
| 295 |
env.get("LD_LIBRARY_PATH"), |
| 296 |
] |
| 297 |
if d is not None |
| 298 |
) |
| 299 |
|
| 300 |
os.environ["SOURCE"] = DIR.source |
| 301 |
if platform.system() == "Windows": |
| 302 |
MAKE = env.get("MAKE", "mozmake") |
| 303 |
|
| 304 |
# Configure flags, based on word length and cross-compilation |
| 305 |
if word_bits == 32: |
| 306 |
if platform.system() == "Windows": |
| 307 |
CONFIGURE_ARGS += " --target=i686-pc-windows-msvc" |
| 308 |
elif platform.system() == "Linux": |
| 309 |
if not platform.machine().startswith("arm"): |
| 310 |
CONFIGURE_ARGS += " --target=i686-pc-linux" |
| 311 |
|
| 312 |
# Add SSE2 support for x86/x64 architectures. |
| 313 |
if not platform.machine().startswith("arm"): |
| 314 |
if platform.system() == "Windows": |
| 315 |
sse_flags = "-arch:SSE2" |
| 316 |
else: |
| 317 |
sse_flags = "-msse -msse2 -mfpmath=sse" |
| 318 |
env["CCFLAGS"] = "{0} {1}".format(env.get("CCFLAGS", ""), sse_flags) |
| 319 |
env["CXXFLAGS"] = "{0} {1}".format(env.get("CXXFLAGS", ""), sse_flags) |
| 320 |
else: |
| 321 |
if platform.system() == "Windows": |
| 322 |
CONFIGURE_ARGS += " --target=x86_64-pc-windows-msvc" |
| 323 |
|
| 324 |
if platform.system() == "Linux" and AUTOMATION: |
| 325 |
CONFIGURE_ARGS = "--enable-stdcxx-compat " + CONFIGURE_ARGS |
| 326 |
|
| 327 |
# Timeouts. |
| 328 |
ACTIVE_PROCESSES = set() |
| 329 |
|
| 330 |
|
| 331 |
def killall(): |
| 332 |
for proc in ACTIVE_PROCESSES: |
| 333 |
proc.kill() |
| 334 |
ACTIVE_PROCESSES.clear() |
| 335 |
|
| 336 |
|
| 337 |
timer = Timer(args.timeout, killall) |
| 338 |
timer.daemon = True |
| 339 |
timer.start() |
| 340 |
|
| 341 |
ensure_dir_exists(OBJDIR, clobber=not args.dep and not args.nobuild) |
| 342 |
ensure_dir_exists(OUTDIR, clobber=not args.keep) |
| 343 |
|
| 344 |
# Any jobs that wish to produce additional output can save them into the upload |
| 345 |
# directory if there is such a thing, falling back to OBJDIR. |
| 346 |
env.setdefault("MOZ_UPLOAD_DIR", OBJDIR) |
| 347 |
ensure_dir_exists(env["MOZ_UPLOAD_DIR"], clobber=False, creation_marker_filename=None) |
| 348 |
info("MOZ_UPLOAD_DIR = {}".format(env["MOZ_UPLOAD_DIR"])) |
| 349 |
|
| 350 |
|
| 351 |
def run_command(command, check=False, **kwargs): |
| 352 |
kwargs.setdefault("cwd", OBJDIR) |
| 353 |
info("in directory {}, running {}".format(kwargs["cwd"], command)) |
| 354 |
if platform.system() == "Windows": |
| 355 |
# Windows will use cmd for the shell, which causes all sorts of |
| 356 |
# problems. Use sh instead, quoting appropriately. (Use sh in all |
| 357 |
# cases, not just when shell=True, because we want to be able to use |
| 358 |
# paths that sh understands and cmd does not.) |
| 359 |
if not isinstance(command, list): |
| 360 |
if kwargs.get("shell"): |
| 361 |
command = shlex.split(command) |
| 362 |
else: |
| 363 |
command = [command] |
| 364 |
|
| 365 |
command = " ".join(quote(c) for c in command) |
| 366 |
command = ["sh", "-c", command] |
| 367 |
kwargs["shell"] = False |
| 368 |
proc = Popen(command, **kwargs) |
| 369 |
ACTIVE_PROCESSES.add(proc) |
| 370 |
stdout, stderr = None, None |
| 371 |
try: |
| 372 |
stdout, stderr = proc.communicate() |
| 373 |
finally: |
| 374 |
ACTIVE_PROCESSES.discard(proc) |
| 375 |
status = proc.wait() |
| 376 |
if check and status != 0: |
| 377 |
raise subprocess.CalledProcessError(status, command, output=stderr) |
| 378 |
return stdout, stderr, status |
| 379 |
|
| 380 |
|
| 381 |
def run_mach_command(command, check=False, **kwargs): |
| 382 |
_stdout, _stderr, status = run_command( |
| 383 |
[PYTHON, MACH] + command, check=check, **kwargs |
| 384 |
) |
| 385 |
return status |
| 386 |
|
| 387 |
|
| 388 |
# Replacement strings in environment variables. |
| 389 |
REPLACEMENTS = { |
| 390 |
"DIR": DIR.scripts, |
| 391 |
"MOZ_FETCHES_DIR": DIR.fetches, |
| 392 |
"MOZ_UPLOAD_DIR": env["MOZ_UPLOAD_DIR"], |
| 393 |
"OUTDIR": OUTDIR, |
| 394 |
} |
| 395 |
|
| 396 |
# Add in environment variable settings for this variant. Normally used to |
| 397 |
# modify the flags passed to the shell or to set the GC zeal mode. |
| 398 |
for k, v in variant.get("env", {}).items(): |
| 399 |
env[k] = v.format(**REPLACEMENTS) |
| 400 |
|
| 401 |
# Do similar substitution for the extra_args keyed lists. |
| 402 |
extra_args = {"jit-test": [], "jstests": [], "gdb": []} |
| 403 |
extra_args.update(variant.get("extra-args", {})) |
| 404 |
for v in extra_args.values(): |
| 405 |
v[:] = [arg.format(**REPLACEMENTS) for arg in v] |
| 406 |
|
| 407 |
if AUTOMATION: |
| 408 |
# Currently only supported on linux64. |
| 409 |
if platform.system() == "Linux" and word_bits == 64: |
| 410 |
use_minidump = variant.get("use_minidump", True) |
| 411 |
else: |
| 412 |
use_minidump = False |
| 413 |
else: |
| 414 |
use_minidump = False |
| 415 |
|
| 416 |
|
| 417 |
def resolve_path(dirs, *components): |
| 418 |
if None in components: |
| 419 |
return None |
| 420 |
for dir in dirs: |
| 421 |
path = os.path.join(dir, *components) |
| 422 |
if os.path.exists(path): |
| 423 |
return path |
| 424 |
|
| 425 |
|
| 426 |
if use_minidump: |
| 427 |
env.setdefault("MINIDUMP_SAVE_PATH", env["MOZ_UPLOAD_DIR"]) |
| 428 |
|
| 429 |
injector_basename = { |
| 430 |
"Linux": "libbreakpadinjector.so", |
| 431 |
"Darwin": "breakpadinjector.dylib", |
| 432 |
}.get(platform.system()) |
| 433 |
|
| 434 |
injector_lib = resolve_path((DIR.fetches,), "injector", injector_basename) |
| 435 |
stackwalk = resolve_path((DIR.fetches,), "minidump-stackwalk", "minidump-stackwalk") |
| 436 |
if stackwalk is not None: |
| 437 |
env.setdefault("MINIDUMP_STACKWALK", stackwalk) |
| 438 |
dump_syms = resolve_path((DIR.fetches,), "dump_syms", "dump_syms") |
| 439 |
if dump_syms is not None: |
| 440 |
env.setdefault("DUMP_SYMS", dump_syms) |
| 441 |
|
| 442 |
if injector_lib is None: |
| 443 |
use_minidump = False |
| 444 |
|
| 445 |
info(f"use_minidump is {use_minidump}") |
| 446 |
info(" MINIDUMP_SAVE_PATH={}".format(env["MINIDUMP_SAVE_PATH"])) |
| 447 |
info(f" injector lib is {injector_lib}") |
| 448 |
info(" MINIDUMP_STACKWALK={}".format(env.get("MINIDUMP_STACKWALK"))) |
| 449 |
|
| 450 |
|
| 451 |
mozconfig = os.path.join(DIR.source, "mozconfig.autospider") |
| 452 |
CONFIGURE_ARGS += f" --prefix={quote(OBJDIR)}/dist" |
| 453 |
|
| 454 |
# Generate a mozconfig. |
| 455 |
with open(mozconfig, "w") as fh: |
| 456 |
if AUTOMATION and platform.system() == "Windows": |
| 457 |
fh.write('. "$topsrcdir/build/mozconfig.clang-cl"\n') |
| 458 |
fh.write("ac_add_options --enable-project=js\n") |
| 459 |
fh.write("ac_add_options " + CONFIGURE_ARGS + "\n") |
| 460 |
fh.write("mk_add_options MOZ_OBJDIR=" + quote(OBJDIR) + "\n") |
| 461 |
|
| 462 |
env["MOZCONFIG"] = mozconfig |
| 463 |
|
| 464 |
if not args.nobuild: |
| 465 |
# Do the build |
| 466 |
run_mach_command(["build"], check=True) |
| 467 |
|
| 468 |
if use_minidump: |
| 469 |
# Convert symbols to breakpad format. |
| 470 |
cmd_env = env.copy() |
| 471 |
cmd_env["MOZ_SOURCE_REPO"] = "file://" + DIR.source |
| 472 |
cmd_env["RUSTC_COMMIT"] = "0" |
| 473 |
cmd_env["MOZ_CRASHREPORTER"] = "1" |
| 474 |
cmd_env["MOZ_AUTOMATION_BUILD_SYMBOLS"] = "1" |
| 475 |
run_mach_command( |
| 476 |
[ |
| 477 |
"build", |
| 478 |
"recurse_syms", |
| 479 |
], |
| 480 |
check=True, |
| 481 |
env=cmd_env, |
| 482 |
) |
| 483 |
|
| 484 |
COMMAND_PREFIX = [] |
| 485 |
# On Linux, disable ASLR to make shell builds a bit more reproducible. |
| 486 |
# Bug 1795718 - Disable in automation for now as call to setarch requires extra |
| 487 |
# docker privileges. |
| 488 |
if not AUTOMATION and subprocess.call("type setarch >/dev/null 2>&1", shell=True) == 0: |
| 489 |
COMMAND_PREFIX.extend(["setarch", platform.machine(), "-R"]) |
| 490 |
|
| 491 |
|
| 492 |
def run_test_command(command, **kwargs): |
| 493 |
_, _, status = run_command(COMMAND_PREFIX + command, check=False, **kwargs) |
| 494 |
return status |
| 495 |
|
| 496 |
|
| 497 |
def run_jsapitests(args): |
| 498 |
test_env = env.copy() |
| 499 |
if use_minidump and platform.system() == "Linux": |
| 500 |
test_env["LD_PRELOAD"] = injector_lib |
| 501 |
st = run_mach_command(["jsapi-tests"], env=test_env) |
| 502 |
if st < 0: |
| 503 |
info = " ".join(["jsapi-tests"] + args) |
| 504 |
print(f"PROCESS-CRASH | {info} | application crashed") |
| 505 |
print(f"Return code: {st}") |
| 506 |
return st |
| 507 |
|
| 508 |
|
| 509 |
default_test_suites = frozenset(["jstests", "jittest", "jsapitests", "checks"]) |
| 510 |
nondefault_test_suites = frozenset(["gdb"]) |
| 511 |
all_test_suites = default_test_suites | nondefault_test_suites |
| 512 |
|
| 513 |
test_suites = set(default_test_suites) |
| 514 |
|
| 515 |
|
| 516 |
def normalize_tests(tests): |
| 517 |
if "all" in tests: |
| 518 |
return default_test_suites |
| 519 |
return tests |
| 520 |
|
| 521 |
|
| 522 |
# Override environment variant settings conditionally. |
| 523 |
for k, v in variant.get("conditional-env", {}).get(variant_platform, {}).items(): |
| 524 |
env[k] = v.format(**REPLACEMENTS) |
| 525 |
|
| 526 |
# Skip any tests that are not run on this platform (or the 'all' platform). |
| 527 |
test_suites -= set( |
| 528 |
normalize_tests(variant.get("skip-tests", {}).get(variant_platform, [])) |
| 529 |
) |
| 530 |
test_suites -= set(normalize_tests(variant.get("skip-tests", {}).get("all", []))) |
| 531 |
|
| 532 |
# Add in additional tests for this platform (or the 'all' platform). |
| 533 |
test_suites |= set( |
| 534 |
normalize_tests(variant.get("extra-tests", {}).get(variant_platform, [])) |
| 535 |
) |
| 536 |
test_suites |= set(normalize_tests(variant.get("extra-tests", {}).get("all", []))) |
| 537 |
|
| 538 |
# Now adjust the variant's default test list with command-line arguments. |
| 539 |
test_suites |= set(normalize_tests(args.run_tests.split(","))) |
| 540 |
test_suites -= set(normalize_tests(args.skip_tests.split(","))) |
| 541 |
if "all" in args.skip_tests.split(","): |
| 542 |
test_suites = [] |
| 543 |
|
| 544 |
# Bug 1557130 - Atomics tests can create many additional threads which can |
| 545 |
# lead to resource exhaustion, resulting in intermittent failures. This was |
| 546 |
# only seen on beefy machines (> 32 cores), so limit the number of parallel |
| 547 |
# workers for now. |
| 548 |
# |
| 549 |
# Bug 1391877 - Windows test runs are getting mysterious timeouts when run |
| 550 |
# through taskcluster, but only when running many jit-test jobs in parallel. |
| 551 |
# Even at 16, some tests can overflow the paging file. |
| 552 |
worker_max = multiprocessing.cpu_count() |
| 553 |
jstest_workers = worker_max |
| 554 |
jittest_workers = worker_max |
| 555 |
if platform.system() == "Windows": |
| 556 |
jstest_workers = min(worker_max, 16) |
| 557 |
extra_args["jstests"].append(f"-j{jstest_workers}") |
| 558 |
jittest_workers = min(worker_max, 8) |
| 559 |
extra_args["jit-test"].append(f"-j{jittest_workers}") |
| 560 |
print( |
| 561 |
f"using {jstest_workers}/{worker_max} workers for jstests, " |
| 562 |
f"{jittest_workers}/{worker_max} for jittest" |
| 563 |
) |
| 564 |
|
| 565 |
if use_minidump: |
| 566 |
# Set up later js invocations to run with the breakpad injector loaded. |
| 567 |
# Originally, I intended for this to be used with LD_PRELOAD, but when |
| 568 |
# cross-compiling from 64- to 32-bit, that will fail and produce stderr |
| 569 |
# output when running any 64-bit commands, which breaks eg mozconfig |
| 570 |
# processing. So use the --dll command line mechanism universally. |
| 571 |
for suite in ("jstests", "jit-test"): |
| 572 |
extra_args[suite].append(f"--args=--dll {injector_lib}") |
| 573 |
|
| 574 |
# Report longest running tests in automation. |
| 575 |
for suite in ("jstests", "jit-test"): |
| 576 |
extra_args[suite].append("--show-slow") |
| 577 |
|
| 578 |
# Always run all enabled tests, even if earlier ones failed. But return the |
| 579 |
# first failed status. |
| 580 |
results = [("(make-nonempty)", 0)] |
| 581 |
|
| 582 |
if "checks" in test_suites: |
| 583 |
results.append(("make check", run_test_command([MAKE, "check"]))) |
| 584 |
|
| 585 |
if "jittest" in test_suites: |
| 586 |
auto_args = [] |
| 587 |
if AUTOMATION: |
| 588 |
auto_args = [ |
| 589 |
"--no-slow", |
| 590 |
"--no-progress", |
| 591 |
"--format=automation", |
| 592 |
"--timeout=300", |
| 593 |
"--jitflags=all", |
| 594 |
] |
| 595 |
results.append( |
| 596 |
( |
| 597 |
"mach jit-test", |
| 598 |
run_mach_command(["jit-test", "--", *auto_args, *extra_args["jit-test"]]), |
| 599 |
) |
| 600 |
) |
| 601 |
if "jsapitests" in test_suites: |
| 602 |
st = run_jsapitests([]) |
| 603 |
if st == 0: |
| 604 |
st = run_jsapitests(["--frontend-only"]) |
| 605 |
results.append(("jsapi-tests", st)) |
| 606 |
if "jstests" in test_suites: |
| 607 |
auto_args = [] |
| 608 |
if AUTOMATION: |
| 609 |
auto_args = ["--no-progress", "--format=automation", "--timeout=300"] |
| 610 |
results.append( |
| 611 |
( |
| 612 |
"mach jstests", |
| 613 |
run_mach_command(["jstests", "--", *auto_args, *extra_args["jstests"]]), |
| 614 |
) |
| 615 |
) |
| 616 |
if "gdb" in test_suites: |
| 617 |
test_script = os.path.join(DIR.js_src, "gdb", "run-tests.py") |
| 618 |
auto_args = ["-s", "-o", "--no-progress"] if AUTOMATION else [] |
| 619 |
results.append( |
| 620 |
( |
| 621 |
"gdb", |
| 622 |
run_test_command( |
| 623 |
[PYTHON, test_script, *auto_args, *extra_args["gdb"], OBJDIR] |
| 624 |
), |
| 625 |
) |
| 626 |
) |
| 627 |
|
| 628 |
# FIXME bug 1291449: This would be unnecessary if we could run msan with -mllvm |
| 629 |
# -msan-keep-going, but in clang 3.8 it causes a hang during compilation. |
| 630 |
if variant.get("ignore-test-failures"): |
| 631 |
logging.warning("Ignoring test results %s" % (results,)) |
| 632 |
results = [("ignored", 0)] |
| 633 |
|
| 634 |
if args.variant == "msan": |
| 635 |
files = filter(lambda f: f.startswith("sanitize_log."), os.listdir(OUTDIR)) |
| 636 |
fullfiles = [os.path.join(OUTDIR, f) for f in files] |
| 637 |
|
| 638 |
# Summarize results |
| 639 |
sites = Counter() |
| 640 |
errors = Counter() |
| 641 |
for filename in fullfiles: |
| 642 |
with open(os.path.join(OUTDIR, filename), "rb") as fh: |
| 643 |
for line in fh: |
| 644 |
m = re.match( |
| 645 |
r"^SUMMARY: \w+Sanitizer: (?:data race|use-of-uninitialized-value) (.*)", # NOQA: E501 |
| 646 |
line.strip(), |
| 647 |
) |
| 648 |
if m: |
| 649 |
# Some reports include file:line:column, some just |
| 650 |
# file:line. Just in case it's nondeterministic, we will |
| 651 |
# canonicalize to just the line number. |
| 652 |
site = re.sub(r"^(\S+?:\d+)(:\d+)* ", r"\1 ", m.group(1)) |
| 653 |
sites[site] += 1 |
| 654 |
|
| 655 |
# Write a summary file and display it to stdout. |
| 656 |
summary_filename = os.path.join( |
| 657 |
env["MOZ_UPLOAD_DIR"], "%s_summary.txt" % args.variant |
| 658 |
) |
| 659 |
with open(summary_filename, "wb") as outfh: |
| 660 |
for location, count in sites.most_common(): |
| 661 |
print >> outfh, "%d %s" % (count, location) |
| 662 |
print(open(summary_filename, "rb").read()) |
| 663 |
|
| 664 |
if "max-errors" in variant: |
| 665 |
max_allowed = variant["max-errors"] |
| 666 |
print("Found %d errors out of %d allowed" % (len(sites), max_allowed)) |
| 667 |
if len(sites) > max_allowed: |
| 668 |
results.append(("too many msan errors", 1)) |
| 669 |
|
| 670 |
# Gather individual results into a tarball. Note that these are |
| 671 |
# distinguished only by pid of the JS process running within each test, so |
| 672 |
# given the 16-bit limitation of pids, it's totally possible that some of |
| 673 |
# these files will be lost due to being overwritten. |
| 674 |
command = [ |
| 675 |
"tar", |
| 676 |
"-C", |
| 677 |
OUTDIR, |
| 678 |
"-zcf", |
| 679 |
os.path.join(env["MOZ_UPLOAD_DIR"], "%s.tar.gz" % args.variant), |
| 680 |
] |
| 681 |
command += files |
| 682 |
subprocess.call(command) |
| 683 |
|
| 684 |
# Upload dist/bin/js as js.wasm for the WASI build. |
| 685 |
if args.variant == "wasi": |
| 686 |
command = [ |
| 687 |
"cp", |
| 688 |
os.path.join(OBJDIR, "dist/bin/js"), |
| 689 |
os.path.join(env["MOZ_UPLOAD_DIR"], "js.wasm"), |
| 690 |
] |
| 691 |
subprocess.call(command) |
| 692 |
|
| 693 |
# Generate stacks from minidumps. |
| 694 |
if use_minidump: |
| 695 |
run_mach_command( |
| 696 |
[ |
| 697 |
"python", |
| 698 |
"--virtualenv=build", |
| 699 |
os.path.join(DIR.source, "testing/mozbase/mozcrash/mozcrash/mozcrash.py"), |
| 700 |
os.getenv("TMPDIR", "/tmp"), |
| 701 |
os.path.join(OBJDIR, "dist/crashreporter-symbols"), |
| 702 |
] |
| 703 |
) |
| 704 |
|
| 705 |
for name, st in results: |
| 706 |
print("exit status %d for '%s'" % (st, name)) |
| 707 |
|
| 708 |
# Pick the "worst" exit status. SIGSEGV might give a status of -11, so use the |
| 709 |
# maximum absolute value instead of just the maximum. |
| 710 |
exit_status = max((st for _, st in results), key=abs) |
| 711 |
|
| 712 |
# The exit status on Windows can be something like 2147483651 (0x80000003), |
| 713 |
# which will be converted to status zero in the caller. Mask off the high bits, |
| 714 |
# but if the result is zero then fall back to returning 1. |
| 715 |
if exit_status & 0xFF: |
| 716 |
sys.exit(exit_status & 0xFF) |
| 717 |
else: |
| 718 |
sys.exit(1 if exit_status else 0) |