| 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 |
| 4 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 |
|
| 6 |
""" |
| 7 |
The JS Shell Test Harness. |
| 8 |
|
| 9 |
See the adjacent README.txt for more details. |
| 10 |
""" |
| 11 |
|
| 12 |
import math |
| 13 |
import os |
| 14 |
import platform |
| 15 |
import posixpath |
| 16 |
import re |
| 17 |
import shlex |
| 18 |
import sys |
| 19 |
import tempfile |
| 20 |
from contextlib import contextmanager |
| 21 |
from copy import copy |
| 22 |
from datetime import datetime |
| 23 |
from itertools import chain |
| 24 |
from os.path import abspath, dirname, isfile, realpath |
| 25 |
from subprocess import call, list2cmdline |
| 26 |
|
| 27 |
from lib.adaptor import xdr_annotate |
| 28 |
from lib.progressbar import ProgressBar |
| 29 |
from lib.results import ResultsSink, TestOutput |
| 30 |
from lib.tempfile import TemporaryDirectory |
| 31 |
from lib.tests import ( |
| 32 |
RefTestCase, |
| 33 |
change_env, |
| 34 |
get_cpu_count, |
| 35 |
get_environment_overlay, |
| 36 |
get_jitflags, |
| 37 |
) |
| 38 |
|
| 39 |
if sys.platform.startswith("linux") or sys.platform.startswith("darwin"): |
| 40 |
from lib.tasks_unix import run_all_tests |
| 41 |
else: |
| 42 |
from lib.tasks_win import run_all_tests |
| 43 |
|
| 44 |
here = dirname(abspath(__file__)) |
| 45 |
|
| 46 |
|
| 47 |
@contextmanager |
| 48 |
def changedir(dirname): |
| 49 |
pwd = os.getcwd() |
| 50 |
os.chdir(dirname) |
| 51 |
try: |
| 52 |
yield |
| 53 |
finally: |
| 54 |
os.chdir(pwd) |
| 55 |
|
| 56 |
|
| 57 |
class PathOptions: |
| 58 |
def __init__(self, location, requested_paths, excluded_paths): |
| 59 |
self.requested_paths = requested_paths |
| 60 |
self.excluded_files, self.excluded_dirs = PathOptions._split_files_and_dirs( |
| 61 |
location, excluded_paths |
| 62 |
) |
| 63 |
|
| 64 |
@staticmethod |
| 65 |
def _split_files_and_dirs(location, paths): |
| 66 |
"""Split up a set of paths into files and directories""" |
| 67 |
files, dirs = set(), set() |
| 68 |
for path in paths: |
| 69 |
fullpath = os.path.join(location, path) |
| 70 |
if path.endswith("/"): |
| 71 |
dirs.add(path[:-1]) |
| 72 |
elif os.path.isdir(fullpath): |
| 73 |
dirs.add(path) |
| 74 |
elif os.path.exists(fullpath): |
| 75 |
files.add(path) |
| 76 |
|
| 77 |
return files, dirs |
| 78 |
|
| 79 |
def should_run(self, filename): |
| 80 |
# If any tests are requested by name, skip tests that do not match. |
| 81 |
if self.requested_paths and not any( |
| 82 |
req in filename for req in self.requested_paths |
| 83 |
): |
| 84 |
return False |
| 85 |
|
| 86 |
# Skip excluded tests. |
| 87 |
if filename in self.excluded_files: |
| 88 |
return False |
| 89 |
|
| 90 |
for dir in self.excluded_dirs: |
| 91 |
if filename.startswith(dir + "/"): |
| 92 |
return False |
| 93 |
|
| 94 |
return True |
| 95 |
|
| 96 |
|
| 97 |
def parse_args(): |
| 98 |
""" |
| 99 |
Parse command line arguments. |
| 100 |
Returns a tuple of: (options, js_shell, requested_paths, excluded_paths) |
| 101 |
options :object: The raw OptionParser output. |
| 102 |
js_shell :str: The absolute location of the shell to test with. |
| 103 |
requested_paths :set<str>: Test paths specially requested on the CLI. |
| 104 |
excluded_paths :set<str>: Test paths specifically excluded by the CLI. |
| 105 |
""" |
| 106 |
from argparse import ArgumentParser |
| 107 |
|
| 108 |
op = ArgumentParser( |
| 109 |
description="Run jstests JS shell tests", |
| 110 |
epilog="Shell output format: [ pass | fail | timeout | skip ] progress | time", |
| 111 |
) |
| 112 |
op.add_argument( |
| 113 |
"--xul-info", |
| 114 |
dest="xul_info_src", |
| 115 |
help="config data for xulRuntime" " (avoids search for config/autoconf.mk)", |
| 116 |
) |
| 117 |
|
| 118 |
harness_og = op.add_argument_group("Harness Controls", "Control how tests are run.") |
| 119 |
harness_og.add_argument( |
| 120 |
"-j", |
| 121 |
"--worker-count", |
| 122 |
type=int, |
| 123 |
default=max(1, get_cpu_count()), |
| 124 |
help="Number of tests to run in parallel" " (default %(default)s)", |
| 125 |
) |
| 126 |
harness_og.add_argument( |
| 127 |
"-t", |
| 128 |
"--timeout", |
| 129 |
type=float, |
| 130 |
default=150.0, |
| 131 |
help="Set maximum time a test is allows to run" " (in seconds).", |
| 132 |
) |
| 133 |
harness_og.add_argument( |
| 134 |
"--show-slow", |
| 135 |
action="store_true", |
| 136 |
help="Show tests taking longer than a minimum time" " (in seconds).", |
| 137 |
) |
| 138 |
harness_og.add_argument( |
| 139 |
"--slow-test-threshold", |
| 140 |
type=float, |
| 141 |
default=5.0, |
| 142 |
help="Time in seconds a test can take until it is" |
| 143 |
"considered slow (default %(default)s).", |
| 144 |
) |
| 145 |
harness_og.add_argument( |
| 146 |
"-a", |
| 147 |
"--args", |
| 148 |
dest="shell_args", |
| 149 |
default="", |
| 150 |
help="Extra args to pass to the JS shell.", |
| 151 |
) |
| 152 |
harness_og.add_argument( |
| 153 |
"--feature-args", |
| 154 |
dest="feature_args", |
| 155 |
default="", |
| 156 |
help="Extra args to pass to the JS shell even when feature-testing.", |
| 157 |
) |
| 158 |
harness_og.add_argument( |
| 159 |
"--jitflags", |
| 160 |
dest="jitflags", |
| 161 |
default="none", |
| 162 |
type=str, |
| 163 |
help="IonMonkey option combinations. One of all," |
| 164 |
" debug, ion, and none (default %(default)s).", |
| 165 |
) |
| 166 |
harness_og.add_argument( |
| 167 |
"--tbpl", |
| 168 |
action="store_true", |
| 169 |
help="Runs each test in all configurations tbpl" " tests.", |
| 170 |
) |
| 171 |
harness_og.add_argument( |
| 172 |
"--tbpl-debug", |
| 173 |
action="store_true", |
| 174 |
help="Runs each test in some faster configurations" " tbpl tests.", |
| 175 |
) |
| 176 |
harness_og.add_argument( |
| 177 |
"-g", "--debug", action="store_true", help="Run a test in debugger." |
| 178 |
) |
| 179 |
harness_og.add_argument( |
| 180 |
"--debugger", default="gdb -q --args", help="Debugger command." |
| 181 |
) |
| 182 |
harness_og.add_argument( |
| 183 |
"-J", "--jorendb", action="store_true", help="Run under JS debugger." |
| 184 |
) |
| 185 |
harness_og.add_argument( |
| 186 |
"--passthrough", |
| 187 |
action="store_true", |
| 188 |
help="Run tests with stdin/stdout attached to" " caller.", |
| 189 |
) |
| 190 |
harness_og.add_argument( |
| 191 |
"--test-reflect-stringify", |
| 192 |
dest="test_reflect_stringify", |
| 193 |
help="instead of running tests, use them to test the " |
| 194 |
"Reflect.stringify code in specified file", |
| 195 |
) |
| 196 |
harness_og.add_argument( |
| 197 |
"--valgrind", action="store_true", help="Run tests in valgrind." |
| 198 |
) |
| 199 |
harness_og.add_argument( |
| 200 |
"--valgrind-args", default="", help="Extra args to pass to valgrind." |
| 201 |
) |
| 202 |
harness_og.add_argument( |
| 203 |
"--rr", |
| 204 |
action="store_true", |
| 205 |
help="Run tests under RR record-and-replay debugger.", |
| 206 |
) |
| 207 |
harness_og.add_argument( |
| 208 |
"-C", |
| 209 |
"--check-output", |
| 210 |
action="store_true", |
| 211 |
help="Run tests to check output for different jit-flags", |
| 212 |
) |
| 213 |
harness_og.add_argument( |
| 214 |
"--remote", action="store_true", help="Run tests on a remote device" |
| 215 |
) |
| 216 |
harness_og.add_argument( |
| 217 |
"--deviceIP", |
| 218 |
action="store", |
| 219 |
type=str, |
| 220 |
dest="device_ip", |
| 221 |
help="IP address of remote device to test", |
| 222 |
) |
| 223 |
harness_og.add_argument( |
| 224 |
"--devicePort", |
| 225 |
action="store", |
| 226 |
type=int, |
| 227 |
dest="device_port", |
| 228 |
default=20701, |
| 229 |
help="port of remote device to test", |
| 230 |
) |
| 231 |
harness_og.add_argument( |
| 232 |
"--deviceSerial", |
| 233 |
action="store", |
| 234 |
type=str, |
| 235 |
dest="device_serial", |
| 236 |
default=None, |
| 237 |
help="ADB device serial number of remote device to test", |
| 238 |
) |
| 239 |
harness_og.add_argument( |
| 240 |
"--remoteTestRoot", |
| 241 |
dest="remote_test_root", |
| 242 |
action="store", |
| 243 |
type=str, |
| 244 |
default="/data/local/tmp/test_root", |
| 245 |
help="The remote directory to use as test root" " (e.g. %(default)s)", |
| 246 |
) |
| 247 |
harness_og.add_argument( |
| 248 |
"--localLib", |
| 249 |
dest="local_lib", |
| 250 |
action="store", |
| 251 |
type=str, |
| 252 |
help="The location of libraries to push -- preferably" " stripped", |
| 253 |
) |
| 254 |
harness_og.add_argument( |
| 255 |
"--no-xdr", |
| 256 |
dest="use_xdr", |
| 257 |
action="store_false", |
| 258 |
help="Whether to disable caching of self-hosted parsed content in XDR format.", |
| 259 |
) |
| 260 |
|
| 261 |
input_og = op.add_argument_group("Inputs", "Change what tests are run.") |
| 262 |
input_og.add_argument( |
| 263 |
"-f", |
| 264 |
"--file", |
| 265 |
dest="test_file", |
| 266 |
action="append", |
| 267 |
help="Get tests from the given file.", |
| 268 |
) |
| 269 |
input_og.add_argument( |
| 270 |
"-x", |
| 271 |
"--exclude-file", |
| 272 |
action="append", |
| 273 |
help="Exclude tests from the given file.", |
| 274 |
) |
| 275 |
input_og.add_argument( |
| 276 |
"--wpt", |
| 277 |
dest="wpt", |
| 278 |
choices=["enabled", "disabled", "if-running-everything"], |
| 279 |
default="if-running-everything", |
| 280 |
help="Enable or disable shell web-platform-tests " |
| 281 |
"(default: enable if no test paths are specified).", |
| 282 |
) |
| 283 |
input_og.add_argument( |
| 284 |
"--include", |
| 285 |
action="append", |
| 286 |
dest="requested_paths", |
| 287 |
default=[], |
| 288 |
help="Include the given test file or directory.", |
| 289 |
) |
| 290 |
input_og.add_argument( |
| 291 |
"--exclude", |
| 292 |
action="append", |
| 293 |
dest="excluded_paths", |
| 294 |
default=[], |
| 295 |
help="Exclude the given test file or directory.", |
| 296 |
) |
| 297 |
input_og.add_argument( |
| 298 |
"-d", |
| 299 |
"--exclude-random", |
| 300 |
dest="random", |
| 301 |
action="store_false", |
| 302 |
help='Exclude tests marked as "random."', |
| 303 |
) |
| 304 |
input_og.add_argument( |
| 305 |
"--run-skipped", action="store_true", help='Run tests marked as "skip."' |
| 306 |
) |
| 307 |
input_og.add_argument( |
| 308 |
"--run-only-skipped", |
| 309 |
action="store_true", |
| 310 |
help='Run only tests marked as "skip."', |
| 311 |
) |
| 312 |
input_og.add_argument( |
| 313 |
"--run-slow-tests", |
| 314 |
action="store_true", |
| 315 |
help='Do not skip tests marked as "slow."', |
| 316 |
) |
| 317 |
input_og.add_argument( |
| 318 |
"--no-extensions", |
| 319 |
action="store_true", |
| 320 |
help="Run only tests conforming to the ECMAScript 5" " standard.", |
| 321 |
) |
| 322 |
input_og.add_argument( |
| 323 |
"--repeat", type=int, default=1, help="Repeat tests the given number of times." |
| 324 |
) |
| 325 |
|
| 326 |
output_og = op.add_argument_group("Output", "Modify the harness and tests output.") |
| 327 |
output_og.add_argument( |
| 328 |
"-s", |
| 329 |
"--show-cmd", |
| 330 |
action="store_true", |
| 331 |
help="Show exact commandline used to run each test.", |
| 332 |
) |
| 333 |
output_og.add_argument( |
| 334 |
"-o", |
| 335 |
"--show-output", |
| 336 |
action="store_true", |
| 337 |
help="Print each test's output to the file given by" " --output-file.", |
| 338 |
) |
| 339 |
output_og.add_argument( |
| 340 |
"-F", |
| 341 |
"--failed-only", |
| 342 |
action="store_true", |
| 343 |
help="If a --show-* option is given, only print" " output for failed tests.", |
| 344 |
) |
| 345 |
output_og.add_argument( |
| 346 |
"--no-show-failed", |
| 347 |
action="store_true", |
| 348 |
help="Don't print output for failed tests" " (no-op with --show-output).", |
| 349 |
) |
| 350 |
output_og.add_argument( |
| 351 |
"-O", |
| 352 |
"--output-file", |
| 353 |
help="Write all output to the given file" " (default: stdout).", |
| 354 |
) |
| 355 |
output_og.add_argument( |
| 356 |
"--failure-file", help="Write all not-passed tests to the given file." |
| 357 |
) |
| 358 |
output_og.add_argument( |
| 359 |
"--no-progress", |
| 360 |
dest="hide_progress", |
| 361 |
action="store_true", |
| 362 |
help="Do not show the progress bar.", |
| 363 |
) |
| 364 |
output_og.add_argument( |
| 365 |
"--tinderbox", |
| 366 |
dest="format", |
| 367 |
action="store_const", |
| 368 |
const="automation", |
| 369 |
help="Use automation-parseable output format.", |
| 370 |
) |
| 371 |
output_og.add_argument( |
| 372 |
"--format", |
| 373 |
dest="format", |
| 374 |
default="none", |
| 375 |
choices=["automation", "none"], |
| 376 |
help="Output format. Either automation or none" " (default %(default)s).", |
| 377 |
) |
| 378 |
output_og.add_argument( |
| 379 |
"--log-wptreport", |
| 380 |
dest="wptreport", |
| 381 |
action="store", |
| 382 |
help="Path to write a Web Platform Tests report (wptreport)", |
| 383 |
) |
| 384 |
output_og.add_argument( |
| 385 |
"--this-chunk", type=int, default=1, help="The test chunk to run." |
| 386 |
) |
| 387 |
output_og.add_argument( |
| 388 |
"--total-chunks", type=int, default=1, help="The total number of test chunks." |
| 389 |
) |
| 390 |
|
| 391 |
special_og = op.add_argument_group( |
| 392 |
"Special", "Special modes that do not run tests." |
| 393 |
) |
| 394 |
special_og.add_argument( |
| 395 |
"--make-manifests", |
| 396 |
metavar="BASE_TEST_PATH", |
| 397 |
help="Generate reftest manifest files.", |
| 398 |
) |
| 399 |
|
| 400 |
op.add_argument("--js-shell", metavar="JS_SHELL", help="JS shell to run tests with") |
| 401 |
op.add_argument( |
| 402 |
"-z", "--gc-zeal", help="GC zeal mode to use when running the shell" |
| 403 |
) |
| 404 |
|
| 405 |
options, args = op.parse_known_args() |
| 406 |
|
| 407 |
# Need a shell unless in a special mode. |
| 408 |
if not options.make_manifests: |
| 409 |
if not args: |
| 410 |
op.error("missing JS_SHELL argument") |
| 411 |
options.js_shell = os.path.abspath(args.pop(0)) |
| 412 |
|
| 413 |
requested_paths = set(args) |
| 414 |
|
| 415 |
# Valgrind, gdb, and rr are mutually exclusive. |
| 416 |
if sum(map(bool, (options.valgrind, options.debug, options.rr))) > 1: |
| 417 |
op.error("--valgrind, --debug, and --rr are mutually exclusive.") |
| 418 |
|
| 419 |
# Fill the debugger field, as needed. |
| 420 |
if options.debug: |
| 421 |
if options.debugger == "lldb": |
| 422 |
debugger_prefix = ["lldb", "--"] |
| 423 |
else: |
| 424 |
debugger_prefix = options.debugger.split() |
| 425 |
else: |
| 426 |
debugger_prefix = [] |
| 427 |
|
| 428 |
if options.valgrind: |
| 429 |
debugger_prefix = ["valgrind"] + options.valgrind_args.split() |
| 430 |
if os.uname()[0] == "Darwin": |
| 431 |
debugger_prefix.append("--dsymutil=yes") |
| 432 |
options.show_output = True |
| 433 |
if options.rr: |
| 434 |
debugger_prefix = ["rr", "record"] |
| 435 |
|
| 436 |
js_cmd_args = shlex.split(options.shell_args) + shlex.split(options.feature_args) |
| 437 |
if options.jorendb: |
| 438 |
options.passthrough = True |
| 439 |
options.hide_progress = True |
| 440 |
options.worker_count = 1 |
| 441 |
debugger_path = realpath( |
| 442 |
os.path.join( |
| 443 |
abspath(dirname(abspath(__file__))), |
| 444 |
"..", |
| 445 |
"..", |
| 446 |
"examples", |
| 447 |
"jorendb.js", |
| 448 |
) |
| 449 |
) |
| 450 |
js_cmd_args.extend(["-d", "-f", debugger_path, "--"]) |
| 451 |
prefix = RefTestCase.build_js_cmd_prefix( |
| 452 |
options.js_shell, js_cmd_args, debugger_prefix |
| 453 |
) |
| 454 |
|
| 455 |
# If files with lists of tests to run were specified, add them to the |
| 456 |
# requested tests set. |
| 457 |
if options.test_file: |
| 458 |
for test_file in options.test_file: |
| 459 |
requested_paths |= set( |
| 460 |
[line.strip() for line in open(test_file).readlines()] |
| 461 |
) |
| 462 |
|
| 463 |
excluded_paths = set(options.excluded_paths) |
| 464 |
|
| 465 |
# If files with lists of tests to exclude were specified, add them to the |
| 466 |
# excluded tests set. |
| 467 |
if options.exclude_file: |
| 468 |
for filename in options.exclude_file: |
| 469 |
with open(filename) as fp: |
| 470 |
for line in fp: |
| 471 |
if line.startswith("#"): |
| 472 |
continue |
| 473 |
line = line.strip() |
| 474 |
if not line: |
| 475 |
continue |
| 476 |
excluded_paths.add(line) |
| 477 |
|
| 478 |
# Handle output redirection, if requested and relevant. |
| 479 |
options.output_fp = sys.stdout |
| 480 |
if options.output_file: |
| 481 |
if not options.show_cmd: |
| 482 |
options.show_output = True |
| 483 |
try: |
| 484 |
options.output_fp = open(options.output_file, "w") |
| 485 |
except OSError as ex: |
| 486 |
raise SystemExit("Failed to open output file: " + str(ex)) |
| 487 |
|
| 488 |
# Hide the progress bar if it will get in the way of other output. |
| 489 |
options.hide_progress = ( |
| 490 |
options.format == "automation" |
| 491 |
or not ProgressBar.conservative_isatty() |
| 492 |
or options.hide_progress |
| 493 |
) |
| 494 |
|
| 495 |
return (options, prefix, requested_paths, excluded_paths) |
| 496 |
|
| 497 |
|
| 498 |
def load_wpt_tests(xul_tester, requested_paths, excluded_paths, update_manifest=True): |
| 499 |
"""Return a list of `RefTestCase` objects for the jsshell testharness.js |
| 500 |
tests filtered by the given paths and debug-ness.""" |
| 501 |
repo_root = abspath(os.path.join(here, "..", "..", "..")) |
| 502 |
wp = os.path.join(repo_root, "testing", "web-platform") |
| 503 |
wpt = os.path.join(wp, "tests") |
| 504 |
|
| 505 |
sys_paths = [ |
| 506 |
"python/mozterm", |
| 507 |
"python/mozboot", |
| 508 |
"testing/mozbase/mozcrash", |
| 509 |
"testing/mozbase/mozdevice", |
| 510 |
"testing/mozbase/mozfile", |
| 511 |
"testing/mozbase/mozinfo", |
| 512 |
"testing/mozbase/mozleak", |
| 513 |
"testing/mozbase/mozlog", |
| 514 |
"testing/mozbase/mozprocess", |
| 515 |
"testing/mozbase/mozprofile", |
| 516 |
"testing/mozbase/mozrunner", |
| 517 |
"testing/mozbase/mozversion", |
| 518 |
"testing/web-platform/", |
| 519 |
"testing/web-platform/tests/tools", |
| 520 |
"testing/web-platform/tests/tools/third_party/html5lib", |
| 521 |
"testing/web-platform/tests/tools/third_party/webencodings", |
| 522 |
"testing/web-platform/tests/tools/wptrunner", |
| 523 |
"testing/web-platform/tests/tools/wptserve", |
| 524 |
"third_party/python/requests", |
| 525 |
] |
| 526 |
abs_sys_paths = [os.path.join(repo_root, path) for path in sys_paths] |
| 527 |
|
| 528 |
failed = False |
| 529 |
for path in abs_sys_paths: |
| 530 |
if not os.path.isdir(path): |
| 531 |
failed = True |
| 532 |
print("Could not add '%s' to the path") |
| 533 |
if failed: |
| 534 |
return [] |
| 535 |
|
| 536 |
sys.path[0:0] = abs_sys_paths |
| 537 |
|
| 538 |
import manifestupdate |
| 539 |
from wptrunner import products, testloader, wptcommandline, wptlogging, wpttest |
| 540 |
|
| 541 |
manifest_root = tempfile.gettempdir() |
| 542 |
(maybe_dist, maybe_bin) = os.path.split(os.path.dirname(xul_tester.js_bin)) |
| 543 |
if maybe_bin == "bin": |
| 544 |
(maybe_root, maybe_dist) = os.path.split(maybe_dist) |
| 545 |
if maybe_dist == "dist": |
| 546 |
if os.path.exists(os.path.join(maybe_root, "_tests")): |
| 547 |
# Assume this is a gecko objdir. |
| 548 |
manifest_root = maybe_root |
| 549 |
|
| 550 |
logger = wptlogging.setup({}, {}) |
| 551 |
|
| 552 |
test_manifests = manifestupdate.run( |
| 553 |
repo_root, manifest_root, logger, update=update_manifest |
| 554 |
) |
| 555 |
|
| 556 |
kwargs = vars(wptcommandline.create_parser().parse_args([])) |
| 557 |
kwargs.update( |
| 558 |
{ |
| 559 |
"config": os.path.join( |
| 560 |
manifest_root, "_tests", "web-platform", "wptrunner.local.ini" |
| 561 |
), |
| 562 |
"gecko_e10s": False, |
| 563 |
"product": "firefox", |
| 564 |
"verify": False, |
| 565 |
"wasm": xul_tester.test("wasmIsSupported()"), |
| 566 |
} |
| 567 |
) |
| 568 |
wptcommandline.set_from_config(kwargs) |
| 569 |
|
| 570 |
def filter_jsshell_tests(it): |
| 571 |
for item_type, path, tests in it: |
| 572 |
tests = set(item for item in tests if item.jsshell) |
| 573 |
if tests: |
| 574 |
yield item_type, path, tests |
| 575 |
|
| 576 |
run_info_extras = products.Product(kwargs["config"], "firefox").run_info_extras( |
| 577 |
logger, **kwargs |
| 578 |
) |
| 579 |
run_info = wpttest.get_run_info( |
| 580 |
kwargs["run_info"], |
| 581 |
"firefox", |
| 582 |
debug=xul_tester.test("isDebugBuild"), |
| 583 |
extras=run_info_extras, |
| 584 |
) |
| 585 |
release_or_beta = xul_tester.test("getBuildConfiguration('release_or_beta')") |
| 586 |
run_info["release_or_beta"] = release_or_beta |
| 587 |
run_info["nightly_build"] = not release_or_beta |
| 588 |
early_beta_or_earlier = xul_tester.test( |
| 589 |
"getBuildConfiguration('early_beta_or_earlier')" |
| 590 |
) |
| 591 |
run_info["early_beta_or_earlier"] = early_beta_or_earlier |
| 592 |
|
| 593 |
path_filter = testloader.TestFilter( |
| 594 |
test_manifests, include=requested_paths, exclude=excluded_paths |
| 595 |
) |
| 596 |
subsuites = testloader.load_subsuites(logger, run_info, None, set()) |
| 597 |
loader = testloader.TestLoader( |
| 598 |
test_manifests, |
| 599 |
["testharness"], |
| 600 |
run_info, |
| 601 |
subsuites=subsuites, |
| 602 |
manifest_filters=[path_filter, filter_jsshell_tests], |
| 603 |
) |
| 604 |
|
| 605 |
extra_helper_paths = [ |
| 606 |
os.path.join(here, "web-platform-test-shims.js"), |
| 607 |
os.path.join(wpt, "resources", "testharness.js"), |
| 608 |
os.path.join(here, "testharnessreport.js"), |
| 609 |
] |
| 610 |
|
| 611 |
pref_prefix = "javascript.options." |
| 612 |
recognized_prefs = set(["wasm_js_string_builtins", "wasm_js_promise_integration"]) |
| 613 |
|
| 614 |
def resolve(test_path, script): |
| 615 |
if script.startswith("/"): |
| 616 |
return os.path.join(wpt, script[1:]) |
| 617 |
|
| 618 |
return os.path.join(wpt, os.path.dirname(test_path), script) |
| 619 |
|
| 620 |
tests = [] |
| 621 |
for test in loader.tests[""]["testharness"]: |
| 622 |
test_path = os.path.relpath(test.path, wpt) |
| 623 |
scripts = [resolve(test_path, s) for s in test.scripts] |
| 624 |
extra_helper_paths_for_test = extra_helper_paths + scripts |
| 625 |
|
| 626 |
# We must create at least one test with the default options, along with |
| 627 |
# one test for each option given in a test-also annotation. |
| 628 |
variants = [None] |
| 629 |
flags = [] |
| 630 |
for m in test.itermeta(): |
| 631 |
# Search for prefs to enable that we recognize |
| 632 |
for pref in m.prefs: |
| 633 |
pref_value = m.prefs[pref] |
| 634 |
if not pref.startswith(pref_prefix): |
| 635 |
continue |
| 636 |
short_pref = pref.replace(pref_prefix, "") |
| 637 |
if not short_pref in recognized_prefs: |
| 638 |
continue |
| 639 |
flags.append("--setpref=" + short_pref + "=" + pref_value) |
| 640 |
|
| 641 |
if m.has_key("test-also"): # NOQA: W601 |
| 642 |
variants += m.get("test-also").split() |
| 643 |
for variant in variants: |
| 644 |
test_case = RefTestCase( |
| 645 |
wpt, |
| 646 |
test_path, |
| 647 |
extra_helper_paths=extra_helper_paths_for_test[:], |
| 648 |
wpt=test, |
| 649 |
) |
| 650 |
if variant: |
| 651 |
test_case.options.append(variant) |
| 652 |
for flag in flags: |
| 653 |
test_case.options.append(flag) |
| 654 |
tests.append(test_case) |
| 655 |
return tests |
| 656 |
|
| 657 |
|
| 658 |
def load_tests(options, requested_paths, excluded_paths): |
| 659 |
""" |
| 660 |
Returns a tuple: (test_count, test_gen) |
| 661 |
test_count: [int] Number of tests that will be in test_gen |
| 662 |
test_gen: [iterable<Test>] Tests found that should be run. |
| 663 |
""" |
| 664 |
import lib.manifest as manifest |
| 665 |
|
| 666 |
if options.js_shell is None: |
| 667 |
xul_tester = manifest.NullXULInfoTester() |
| 668 |
else: |
| 669 |
if options.xul_info_src is None: |
| 670 |
xul_info = manifest.XULInfo.create(options.js_shell) |
| 671 |
else: |
| 672 |
xul_abi, xul_os, xul_debug = options.xul_info_src.split(r":") |
| 673 |
xul_debug = xul_debug.lower() == "true" |
| 674 |
xul_info = manifest.XULInfo(xul_abi, xul_os, xul_debug) |
| 675 |
feature_args = shlex.split(options.feature_args) |
| 676 |
xul_tester = manifest.XULInfoTester(xul_info, options, feature_args) |
| 677 |
|
| 678 |
test_dir = dirname(abspath(__file__)) |
| 679 |
path_options = PathOptions(test_dir, requested_paths, excluded_paths) |
| 680 |
test_count = manifest.count_tests(test_dir, path_options) |
| 681 |
test_gen = manifest.load_reftests(test_dir, path_options, xul_tester) |
| 682 |
|
| 683 |
# WPT tests are already run in the browser in their own harness. |
| 684 |
wpt_enabled = options.wpt == "enabled" or ( |
| 685 |
options.wpt == "if-running-everything" |
| 686 |
and len(requested_paths) == 0 |
| 687 |
and not options.make_manifests |
| 688 |
) |
| 689 |
if wpt_enabled: |
| 690 |
wpt_tests = load_wpt_tests(xul_tester, requested_paths, excluded_paths) |
| 691 |
test_count += len(wpt_tests) |
| 692 |
test_gen = chain(test_gen, wpt_tests) |
| 693 |
|
| 694 |
if options.test_reflect_stringify is not None: |
| 695 |
|
| 696 |
def trs_gen(tests): |
| 697 |
for test in tests: |
| 698 |
test.test_reflect_stringify = options.test_reflect_stringify |
| 699 |
# Even if the test is not normally expected to pass, we still |
| 700 |
# expect reflect-stringify to be able to handle it. |
| 701 |
test.expect = True |
| 702 |
test.random = False |
| 703 |
test.slow = False |
| 704 |
yield test |
| 705 |
|
| 706 |
test_gen = trs_gen(test_gen) |
| 707 |
|
| 708 |
if options.make_manifests: |
| 709 |
manifest.make_manifests(options.make_manifests, test_gen) |
| 710 |
sys.exit() |
| 711 |
|
| 712 |
# Create a new test list. Apply each TBPL configuration to every test. |
| 713 |
flags_list = None |
| 714 |
if options.tbpl: |
| 715 |
flags_list = get_jitflags("all") |
| 716 |
elif options.tbpl_debug: |
| 717 |
flags_list = get_jitflags("debug") |
| 718 |
else: |
| 719 |
flags_list = get_jitflags(options.jitflags, none=None) |
| 720 |
|
| 721 |
if flags_list: |
| 722 |
|
| 723 |
def flag_gen(tests): |
| 724 |
for test in tests: |
| 725 |
for jitflags in flags_list: |
| 726 |
tmp_test = copy(test) |
| 727 |
tmp_test.jitflags = copy(test.jitflags) |
| 728 |
tmp_test.jitflags.extend(jitflags) |
| 729 |
yield tmp_test |
| 730 |
|
| 731 |
test_count = test_count * len(flags_list) |
| 732 |
test_gen = flag_gen(test_gen) |
| 733 |
|
| 734 |
if options.test_file: |
| 735 |
paths = set() |
| 736 |
for test_file in options.test_file: |
| 737 |
paths |= set([line.strip() for line in open(test_file).readlines()]) |
| 738 |
test_gen = (_ for _ in test_gen if _.path in paths) |
| 739 |
|
| 740 |
if options.no_extensions: |
| 741 |
pattern = os.sep + "extensions" + os.sep |
| 742 |
test_gen = (_ for _ in test_gen if pattern not in _.path) |
| 743 |
|
| 744 |
if not options.random: |
| 745 |
test_gen = (_ for _ in test_gen if not _.random) |
| 746 |
|
| 747 |
if options.run_only_skipped: |
| 748 |
options.run_skipped = True |
| 749 |
test_gen = (_ for _ in test_gen if not _.enable) |
| 750 |
|
| 751 |
if not options.run_slow_tests: |
| 752 |
test_gen = (_ for _ in test_gen if not _.slow) |
| 753 |
|
| 754 |
if options.repeat: |
| 755 |
test_gen = (test for test in test_gen for i in range(options.repeat)) |
| 756 |
test_count *= options.repeat |
| 757 |
|
| 758 |
return test_count, test_gen |
| 759 |
|
| 760 |
|
| 761 |
def main(): |
| 762 |
options, prefix, requested_paths, excluded_paths = parse_args() |
| 763 |
if options.js_shell is not None and not ( |
| 764 |
isfile(options.js_shell) and os.access(options.js_shell, os.X_OK) |
| 765 |
): |
| 766 |
if ( |
| 767 |
platform.system() != "Windows" |
| 768 |
or isfile(options.js_shell) |
| 769 |
or not isfile(options.js_shell + ".exe") |
| 770 |
or not os.access(options.js_shell + ".exe", os.X_OK) |
| 771 |
): |
| 772 |
print("Could not find executable shell: " + options.js_shell) |
| 773 |
return 1 |
| 774 |
|
| 775 |
test_count, test_gen = load_tests(options, requested_paths, excluded_paths) |
| 776 |
test_environment = get_environment_overlay(options.js_shell, options.gc_zeal) |
| 777 |
|
| 778 |
if test_count == 0: |
| 779 |
print("no tests selected") |
| 780 |
return 1 |
| 781 |
|
| 782 |
test_dir = dirname(abspath(__file__)) |
| 783 |
|
| 784 |
if options.debug: |
| 785 |
if test_count > 1: |
| 786 |
print( |
| 787 |
"Multiple tests match command line arguments," |
| 788 |
" debugger can only run one" |
| 789 |
) |
| 790 |
for tc in test_gen: |
| 791 |
print(f" {tc.path}") |
| 792 |
return 2 |
| 793 |
|
| 794 |
with changedir(test_dir), change_env( |
| 795 |
test_environment |
| 796 |
), TemporaryDirectory() as tempdir: |
| 797 |
cmd = next(test_gen).get_command(prefix, tempdir) |
| 798 |
if options.show_cmd: |
| 799 |
print(list2cmdline(cmd)) |
| 800 |
call(cmd) |
| 801 |
return 0 |
| 802 |
|
| 803 |
# The test_gen generator is converted into a list in |
| 804 |
# run_all_tests. Go ahead and do it here so we can apply |
| 805 |
# chunking. |
| 806 |
# |
| 807 |
# If chunking is enabled, determine which tests are part of this chunk. |
| 808 |
# This code was adapted from testing/mochitest/runtestsremote.py. |
| 809 |
if options.total_chunks > 1: |
| 810 |
tests_per_chunk = math.ceil(test_count / float(options.total_chunks)) |
| 811 |
start = int(round((options.this_chunk - 1) * tests_per_chunk)) |
| 812 |
end = int(round(options.this_chunk * tests_per_chunk)) |
| 813 |
test_gen = list(test_gen)[start:end] |
| 814 |
|
| 815 |
if options.remote: |
| 816 |
results = ResultsSink("jstests", options, test_count) |
| 817 |
try: |
| 818 |
from lib.remote import init_device, init_remote_dir |
| 819 |
|
| 820 |
device = init_device(options) |
| 821 |
tempdir = posixpath.join(options.remote_test_root, "tmp") |
| 822 |
jtd_tests = posixpath.join(options.remote_test_root, "tests", "tests") |
| 823 |
init_remote_dir(device, jtd_tests) |
| 824 |
device.push(test_dir, jtd_tests, timeout=600) |
| 825 |
device.chmod(jtd_tests, recursive=True) |
| 826 |
prefix[0] = options.js_shell |
| 827 |
if options.use_xdr: |
| 828 |
test_gen = xdr_annotate(test_gen, options) |
| 829 |
for test in test_gen: |
| 830 |
out = run_test_remote(test, device, prefix, tempdir, options) |
| 831 |
results.push(out) |
| 832 |
results.finish(True) |
| 833 |
except KeyboardInterrupt: |
| 834 |
results.finish(False) |
| 835 |
|
| 836 |
return 0 if results.all_passed() else 1 |
| 837 |
|
| 838 |
with changedir(test_dir), change_env( |
| 839 |
test_environment |
| 840 |
), TemporaryDirectory() as tempdir: |
| 841 |
results = ResultsSink("jstests", options, test_count) |
| 842 |
try: |
| 843 |
for out in run_all_tests(test_gen, prefix, tempdir, results.pb, options): |
| 844 |
results.push(out) |
| 845 |
results.finish(True) |
| 846 |
except KeyboardInterrupt: |
| 847 |
results.finish(False) |
| 848 |
|
| 849 |
return 0 if results.all_passed() else 1 |
| 850 |
|
| 851 |
return 0 |
| 852 |
|
| 853 |
|
| 854 |
def run_test_remote(test, device, prefix, tempdir, options): |
| 855 |
from mozdevice import ADBDevice, ADBProcessError |
| 856 |
|
| 857 |
cmd = test.get_command(prefix, tempdir) |
| 858 |
test_root_parent = os.path.dirname(test.root) |
| 859 |
jtd_tests = posixpath.join(options.remote_test_root, "tests") |
| 860 |
cmd = [_.replace(test_root_parent, jtd_tests) for _ in cmd] |
| 861 |
|
| 862 |
env = {"TZ": "PST8PDT", "LD_LIBRARY_PATH": os.path.dirname(prefix[0])} |
| 863 |
|
| 864 |
adb_cmd = ADBDevice._escape_command_line(cmd) |
| 865 |
start = datetime.now() |
| 866 |
try: |
| 867 |
# Allow ADBError or ADBTimeoutError to terminate the test run, |
| 868 |
# but handle ADBProcessError in order to support the use of |
| 869 |
# non-zero exit codes in the JavaScript shell tests. |
| 870 |
out = device.shell_output( |
| 871 |
adb_cmd, env=env, cwd=options.remote_test_root, timeout=int(options.timeout) |
| 872 |
) |
| 873 |
returncode = 0 |
| 874 |
except ADBProcessError as e: |
| 875 |
# Treat ignorable intermittent adb communication errors as |
| 876 |
# skipped tests. |
| 877 |
out = str(e.adb_process.stdout) |
| 878 |
returncode = e.adb_process.exitcode |
| 879 |
re_ignore = re.compile(r"error: (closed|device .* not found)") |
| 880 |
if returncode == 1 and re_ignore.search(out): |
| 881 |
print(f"Skipping {test.path} due to ignorable adb error {out}") |
| 882 |
test.skip_if_cond = "true" |
| 883 |
returncode = test.SKIPPED_EXIT_STATUS |
| 884 |
|
| 885 |
elapsed = (datetime.now() - start).total_seconds() |
| 886 |
|
| 887 |
# We can't distinguish between stdout and stderr so we pass |
| 888 |
# the same buffer to both. |
| 889 |
return TestOutput(test, cmd, out, out, returncode, elapsed, False) |
| 890 |
|
| 891 |
|
| 892 |
if __name__ == "__main__": |
| 893 |
sys.exit(main()) |