blob: c94457fe6d296479393ea99044536d2bfe002a55 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001#!/usr/bin/env python
2#
3# Copyright 2012 the V8 project authors. All rights reserved.
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
8# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above
11# copyright notice, this list of conditions and the following
12# disclaimer in the documentation and/or other materials provided
13# with the distribution.
14# * Neither the name of Google Inc. nor the names of its
15# contributors may be used to endorse or promote products derived
16# from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31from collections import OrderedDict
32import itertools
33import multiprocessing
34import optparse
35import os
36from os.path import join
37import platform
38import random
39import shlex
40import subprocess
41import sys
42import time
43
44from testrunner.local import execution
45from testrunner.local import progress
46from testrunner.local import testsuite
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047from testrunner.local.testsuite import ALL_VARIANTS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048from testrunner.local import utils
49from testrunner.local import verbose
50from testrunner.network import network_execution
51from testrunner.objects import context
52
53
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054# Base dir of the v8 checkout to be used as cwd.
55BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
56
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057ARCH_GUESS = utils.DefaultArch()
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058
59# Map of test name synonyms to lists of test suites. Should be ordered by
60# expected runtimes (suites with slow test cases first). These groups are
61# invoked in seperate steps on the bots.
62TEST_MAP = {
Ben Murdoch097c5b22016-05-18 11:27:45 +010063 # This needs to stay in sync with test/bot_default.isolate.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064 "bot_default": [
65 "mjsunit",
66 "cctest",
67 "webkit",
Ben Murdoch097c5b22016-05-18 11:27:45 +010068 "fuzzer",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069 "message",
70 "preparser",
71 "intl",
72 "unittests",
73 ],
Ben Murdoch097c5b22016-05-18 11:27:45 +010074 # This needs to stay in sync with test/default.isolate.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 "default": [
76 "mjsunit",
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077 "cctest",
Ben Murdoch097c5b22016-05-18 11:27:45 +010078 "fuzzer",
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 "message",
80 "preparser",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081 "intl",
82 "unittests",
83 ],
Ben Murdoch097c5b22016-05-18 11:27:45 +010084 # This needs to stay in sync with test/ignition.isolate.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000085 "ignition": [
86 "mjsunit",
87 "cctest",
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088 ],
Ben Murdoch097c5b22016-05-18 11:27:45 +010089 # This needs to stay in sync with test/optimize_for_size.isolate.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090 "optimize_for_size": [
91 "mjsunit",
92 "cctest",
93 "webkit",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094 "intl",
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 ],
96 "unittests": [
Emily Bernierd0a1eb72015-03-24 16:35:39 -040097 "unittests",
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098 ],
99}
100
101TIMEOUT_DEFAULT = 60
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000102
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103VARIANTS = ["default", "stress", "turbofan"]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000104
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000105EXHAUSTIVE_VARIANTS = VARIANTS + [
106 "nocrankshaft",
107 "turbofan_opt",
108]
109
110DEBUG_FLAGS = ["--nohard-abort", "--nodead-code-elimination",
111 "--nofold-constants", "--enable-slow-asserts",
112 "--debug-code", "--verify-heap"]
113RELEASE_FLAGS = ["--nohard-abort", "--nodead-code-elimination",
114 "--nofold-constants"]
115
116MODES = {
117 "debug": {
118 "flags": DEBUG_FLAGS,
119 "timeout_scalefactor": 4,
120 "status_mode": "debug",
121 "execution_mode": "debug",
122 "output_folder": "debug",
123 },
124 "optdebug": {
125 "flags": DEBUG_FLAGS,
126 "timeout_scalefactor": 4,
127 "status_mode": "debug",
128 "execution_mode": "debug",
129 "output_folder": "optdebug",
130 },
131 "release": {
132 "flags": RELEASE_FLAGS,
133 "timeout_scalefactor": 1,
134 "status_mode": "release",
135 "execution_mode": "release",
136 "output_folder": "release",
137 },
138 # Normal trybot release configuration. There, dchecks are always on which
139 # implies debug is set. Hence, the status file needs to assume debug-like
140 # behavior/timeouts.
141 "tryrelease": {
142 "flags": RELEASE_FLAGS,
143 "timeout_scalefactor": 1,
144 "status_mode": "debug",
145 "execution_mode": "release",
146 "output_folder": "release",
147 },
148 # This mode requires v8 to be compiled with dchecks and slow dchecks.
149 "slowrelease": {
150 "flags": RELEASE_FLAGS + ["--enable-slow-asserts"],
151 "timeout_scalefactor": 2,
152 "status_mode": "debug",
153 "execution_mode": "release",
154 "output_folder": "release",
155 },
156}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157
158GC_STRESS_FLAGS = ["--gc-interval=500", "--stress-compaction",
159 "--concurrent-recompilation-queue-length=64",
160 "--concurrent-recompilation-delay=500",
161 "--concurrent-recompilation"]
162
163SUPPORTED_ARCHS = ["android_arm",
164 "android_arm64",
165 "android_ia32",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000166 "android_x64",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167 "arm",
168 "ia32",
169 "x87",
170 "mips",
171 "mipsel",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172 "mips64",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173 "mips64el",
174 "nacl_ia32",
175 "nacl_x64",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000176 "ppc",
177 "ppc64",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000178 "x64",
179 "x32",
180 "arm64"]
181# Double the timeout for these:
182SLOW_ARCHS = ["android_arm",
183 "android_arm64",
184 "android_ia32",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000185 "android_x64",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000186 "arm",
187 "mips",
188 "mipsel",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000189 "mips64",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000190 "mips64el",
191 "nacl_ia32",
192 "nacl_x64",
193 "x87",
194 "arm64"]
195
196
197def BuildOptions():
198 result = optparse.OptionParser()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000199 result.usage = '%prog [options] [tests]'
200 result.description = """TESTS: %s""" % (TEST_MAP["default"])
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000201 result.add_option("--arch",
202 help=("The architecture to run tests for, "
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000203 "'auto' or 'native' for auto-detect: %s" % SUPPORTED_ARCHS),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000204 default="ia32,x64,arm")
205 result.add_option("--arch-and-mode",
206 help="Architecture and mode in the format 'arch.mode'",
207 default=None)
208 result.add_option("--asan",
209 help="Regard test expectations for ASAN",
210 default=False, action="store_true")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000211 result.add_option("--cfi-vptr",
212 help="Run tests with UBSAN cfi_vptr option.",
213 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000214 result.add_option("--buildbot",
215 help="Adapt to path structure used on buildbots",
216 default=False, action="store_true")
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400217 result.add_option("--dcheck-always-on",
218 help="Indicates that V8 was compiled with DCHECKs enabled",
219 default=False, action="store_true")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000220 result.add_option("--novfp3",
221 help="Indicates that V8 was compiled without VFP3 support",
222 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000223 result.add_option("--cat", help="Print the source of the tests",
224 default=False, action="store_true")
225 result.add_option("--flaky-tests",
226 help="Regard tests marked as flaky (run|skip|dontcare)",
227 default="dontcare")
228 result.add_option("--slow-tests",
229 help="Regard slow tests (run|skip|dontcare)",
230 default="dontcare")
231 result.add_option("--pass-fail-tests",
232 help="Regard pass|fail tests (run|skip|dontcare)",
233 default="dontcare")
234 result.add_option("--gc-stress",
235 help="Switch on GC stress mode",
236 default=False, action="store_true")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000237 result.add_option("--gcov-coverage",
238 help="Uses executables instrumented for gcov coverage",
239 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000240 result.add_option("--command-prefix",
241 help="Prepended to each shell command used to run a test",
242 default="")
243 result.add_option("--download-data", help="Download missing test suite data",
244 default=False, action="store_true")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000245 result.add_option("--download-data-only",
246 help="Download missing test suite data and exit",
247 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248 result.add_option("--extra-flags",
249 help="Additional flags to pass to each test command",
250 default="")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000251 result.add_option("--ignition", help="Skip tests which don't run in ignition",
252 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 result.add_option("--isolates", help="Whether to test isolates",
254 default=False, action="store_true")
255 result.add_option("-j", help="The number of parallel tasks to run",
256 default=0, type="int")
257 result.add_option("-m", "--mode",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000258 help="The test modes in which to run (comma-separated,"
259 " uppercase for ninja and buildbot builds): %s" % MODES.keys(),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260 default="release,debug")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000261 result.add_option("--no-harness", "--noharness",
262 help="Run without test harness of a given suite",
263 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000264 result.add_option("--no-i18n", "--noi18n",
265 help="Skip internationalization tests",
266 default=False, action="store_true")
267 result.add_option("--no-network", "--nonetwork",
268 help="Don't distribute tests on the network",
269 default=(utils.GuessOS() != "linux"),
270 dest="no_network", action="store_true")
271 result.add_option("--no-presubmit", "--nopresubmit",
272 help='Skip presubmit checks',
273 default=False, dest="no_presubmit", action="store_true")
274 result.add_option("--no-snap", "--nosnap",
275 help='Test a build compiled without snapshot.',
276 default=False, dest="no_snap", action="store_true")
277 result.add_option("--no-sorting", "--nosorting",
278 help="Don't sort tests according to duration of last run.",
279 default=False, dest="no_sorting", action="store_true")
280 result.add_option("--no-stress", "--nostress",
281 help="Don't run crankshaft --always-opt --stress-op test",
282 default=False, dest="no_stress", action="store_true")
283 result.add_option("--no-variants", "--novariants",
284 help="Don't run any testing variants",
285 default=False, dest="no_variants", action="store_true")
286 result.add_option("--variants",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000287 help="Comma-separated list of testing variants: %s" % VARIANTS)
288 result.add_option("--exhaustive-variants",
289 default=False, action="store_true",
290 help="Use exhaustive set of default variants.")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291 result.add_option("--outdir", help="Base directory with compile output",
292 default="out")
293 result.add_option("--predictable",
294 help="Compare output of several reruns of each test",
295 default=False, action="store_true")
296 result.add_option("-p", "--progress",
297 help=("The style of progress indicator"
298 " (verbose, dots, color, mono)"),
299 choices=progress.PROGRESS_INDICATORS.keys(), default="mono")
300 result.add_option("--quickcheck", default=False, action="store_true",
301 help=("Quick check mode (skip slow/flaky tests)"))
302 result.add_option("--report", help="Print a summary of the tests to be run",
303 default=False, action="store_true")
304 result.add_option("--json-test-results",
305 help="Path to a file for storing json results.")
306 result.add_option("--rerun-failures-count",
307 help=("Number of times to rerun each failing test case. "
308 "Very slow tests will be rerun only once."),
309 default=0, type="int")
310 result.add_option("--rerun-failures-max",
311 help="Maximum number of failing test cases to rerun.",
312 default=100, type="int")
313 result.add_option("--shard-count",
314 help="Split testsuites into this number of shards",
315 default=1, type="int")
316 result.add_option("--shard-run",
317 help="Run this shard from the split up tests.",
318 default=1, type="int")
319 result.add_option("--shell", help="DEPRECATED! use --shell-dir", default="")
320 result.add_option("--shell-dir", help="Directory containing executables",
321 default="")
322 result.add_option("--dont-skip-slow-simulator-tests",
323 help="Don't skip more slow tests when using a simulator.",
324 default=False, action="store_true",
325 dest="dont_skip_simulator_slow_tests")
326 result.add_option("--stress-only",
327 help="Only run tests with --always-opt --stress-opt",
328 default=False, action="store_true")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000329 result.add_option("--swarming",
330 help="Indicates running test driver on swarming.",
331 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000332 result.add_option("--time", help="Print timing information after running",
333 default=False, action="store_true")
334 result.add_option("-t", "--timeout", help="Timeout in seconds",
335 default= -1, type="int")
336 result.add_option("--tsan",
337 help="Regard test expectations for TSAN",
338 default=False, action="store_true")
339 result.add_option("-v", "--verbose", help="Verbose output",
340 default=False, action="store_true")
341 result.add_option("--valgrind", help="Run tests through valgrind",
342 default=False, action="store_true")
343 result.add_option("--warn-unused", help="Report unused rules",
344 default=False, action="store_true")
345 result.add_option("--junitout", help="File name of the JUnit output")
346 result.add_option("--junittestsuite",
347 help="The testsuite name in the JUnit output file",
348 default="v8tests")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000349 result.add_option("--random-seed", default=0, dest="random_seed", type="int",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350 help="Default seed for initializing random generator")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000351 result.add_option("--random-seed-stress-count", default=1, type="int",
352 dest="random_seed_stress_count",
353 help="Number of runs with different random seeds")
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400354 result.add_option("--msan",
355 help="Regard test expectations for MSAN",
356 default=False, action="store_true")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000357 return result
358
359
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000360def RandomSeed():
361 seed = 0
362 while not seed:
363 seed = random.SystemRandom().randint(-2147483648, 2147483647)
364 return seed
365
366
367def BuildbotToV8Mode(config):
368 """Convert buildbot build configs to configs understood by the v8 runner.
369
370 V8 configs are always lower case and without the additional _x64 suffix for
371 64 bit builds on windows with ninja.
372 """
373 mode = config[:-4] if config.endswith('_x64') else config
374 return mode.lower()
375
376def SetupEnvironment(options):
377 """Setup additional environment variables."""
378 symbolizer = 'external_symbolizer_path=%s' % (
379 os.path.join(
380 BASE_DIR, 'third_party', 'llvm-build', 'Release+Asserts', 'bin',
381 'llvm-symbolizer',
382 )
383 )
384
385 if options.asan:
386 os.environ['ASAN_OPTIONS'] = symbolizer
387
388 if options.cfi_vptr:
389 os.environ['UBSAN_OPTIONS'] = ":".join([
390 'print_stacktrace=1',
391 'print_summary=1',
392 'symbolize=1',
393 symbolizer,
394 ])
395
396 if options.msan:
397 os.environ['MSAN_OPTIONS'] = symbolizer
398
399 if options.tsan:
400 suppressions_file = os.path.join(
401 BASE_DIR, 'tools', 'sanitizers', 'tsan_suppressions.txt')
402 os.environ['TSAN_OPTIONS'] = " ".join([
403 symbolizer,
404 'suppressions=%s' % suppressions_file,
405 'exit_code=0',
406 'report_thread_leaks=0',
407 'history_size=7',
408 'report_destroy_locked=0',
409 ])
410
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411def ProcessOptions(options):
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412 global ALL_VARIANTS
413 global EXHAUSTIVE_VARIANTS
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000414 global VARIANTS
415
416 # Architecture and mode related stuff.
417 if options.arch_and_mode:
418 options.arch_and_mode = [arch_and_mode.split(".")
419 for arch_and_mode in options.arch_and_mode.split(",")]
420 options.arch = ",".join([tokens[0] for tokens in options.arch_and_mode])
421 options.mode = ",".join([tokens[1] for tokens in options.arch_and_mode])
422 options.mode = options.mode.split(",")
423 for mode in options.mode:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000424 if not BuildbotToV8Mode(mode) in MODES:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425 print "Unknown mode %s" % mode
426 return False
427 if options.arch in ["auto", "native"]:
428 options.arch = ARCH_GUESS
429 options.arch = options.arch.split(",")
430 for arch in options.arch:
431 if not arch in SUPPORTED_ARCHS:
432 print "Unknown architecture %s" % arch
433 return False
434
435 # Store the final configuration in arch_and_mode list. Don't overwrite
436 # predefined arch_and_mode since it is more expressive than arch and mode.
437 if not options.arch_and_mode:
438 options.arch_and_mode = itertools.product(options.arch, options.mode)
439
440 # Special processing of other options, sorted alphabetically.
441
442 if options.buildbot:
443 # Buildbots run presubmit tests as a separate step.
444 options.no_presubmit = True
445 options.no_network = True
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000446 if options.download_data_only:
447 options.no_presubmit = True
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000448 if options.command_prefix:
449 print("Specifying --command-prefix disables network distribution, "
450 "running tests locally.")
451 options.no_network = True
452 options.command_prefix = shlex.split(options.command_prefix)
453 options.extra_flags = shlex.split(options.extra_flags)
454
455 if options.gc_stress:
456 options.extra_flags += GC_STRESS_FLAGS
457
458 if options.asan:
459 options.extra_flags.append("--invoke-weak-callbacks")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000460 options.extra_flags.append("--omit-quit")
461
462 if options.novfp3:
463 options.extra_flags.append("--noenable-vfp3")
464
465 if options.exhaustive_variants:
466 # This is used on many bots. It includes a larger set of default variants.
467 # Other options for manipulating variants still apply afterwards.
468 VARIANTS = EXHAUSTIVE_VARIANTS
469
470 if options.msan:
471 VARIANTS = ["default"]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000472
473 if options.tsan:
474 VARIANTS = ["default"]
475
476 if options.j == 0:
477 options.j = multiprocessing.cpu_count()
478
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000479 if options.random_seed_stress_count <= 1 and options.random_seed == 0:
480 options.random_seed = RandomSeed()
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000481
482 def excl(*args):
483 """Returns true if zero or one of multiple arguments are true."""
484 return reduce(lambda x, y: x + y, args) <= 1
485
486 if not excl(options.no_stress, options.stress_only, options.no_variants,
487 bool(options.variants)):
488 print("Use only one of --no-stress, --stress-only, --no-variants, "
489 "or --variants.")
490 return False
491 if options.quickcheck:
492 VARIANTS = ["default", "stress"]
493 options.flaky_tests = "skip"
494 options.slow_tests = "skip"
495 options.pass_fail_tests = "skip"
496 if options.no_stress:
497 VARIANTS = ["default", "nocrankshaft"]
498 if options.no_variants:
499 VARIANTS = ["default"]
500 if options.stress_only:
501 VARIANTS = ["stress"]
502 if options.variants:
503 VARIANTS = options.variants.split(",")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000504 if not set(VARIANTS).issubset(ALL_VARIANTS):
505 print "All variants must be in %s" % str(ALL_VARIANTS)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000506 return False
507 if options.predictable:
508 VARIANTS = ["default"]
509 options.extra_flags.append("--predictable")
510 options.extra_flags.append("--verify_predictable")
511 options.extra_flags.append("--no-inline-new")
512
513 if not options.shell_dir:
514 if options.shell:
515 print "Warning: --shell is deprecated, use --shell-dir instead."
516 options.shell_dir = os.path.dirname(options.shell)
517 if options.valgrind:
518 run_valgrind = os.path.join("tools", "run-valgrind.py")
519 # This is OK for distributed running, so we don't need to set no_network.
520 options.command_prefix = (["python", "-u", run_valgrind] +
521 options.command_prefix)
522 def CheckTestMode(name, option):
523 if not option in ["run", "skip", "dontcare"]:
524 print "Unknown %s mode %s" % (name, option)
525 return False
526 return True
527 if not CheckTestMode("flaky test", options.flaky_tests):
528 return False
529 if not CheckTestMode("slow test", options.slow_tests):
530 return False
531 if not CheckTestMode("pass|fail test", options.pass_fail_tests):
532 return False
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000533 if options.no_i18n:
534 TEST_MAP["bot_default"].remove("intl")
535 TEST_MAP["default"].remove("intl")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000536 return True
537
538
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000539def ShardTests(tests, options):
540 # Read gtest shard configuration from environment (e.g. set by swarming).
541 # If none is present, use values passed on the command line.
542 shard_count = int(os.environ.get('GTEST_TOTAL_SHARDS', options.shard_count))
543 shard_run = os.environ.get('GTEST_SHARD_INDEX')
544 if shard_run is not None:
545 # The v8 shard_run starts at 1, while GTEST_SHARD_INDEX starts at 0.
546 shard_run = int(shard_run) + 1
547 else:
548 shard_run = options.shard_run
549
550 if options.shard_count > 1:
551 # Log if a value was passed on the cmd line and it differs from the
552 # environment variables.
553 if options.shard_count != shard_count:
554 print("shard_count from cmd line differs from environment variable "
555 "GTEST_TOTAL_SHARDS")
556 if options.shard_run > 1 and options.shard_run != shard_run:
557 print("shard_run from cmd line differs from environment variable "
558 "GTEST_SHARD_INDEX")
559
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000560 if shard_count < 2:
561 return tests
562 if shard_run < 1 or shard_run > shard_count:
563 print "shard-run not a valid number, should be in [1:shard-count]"
564 print "defaulting back to running all tests"
565 return tests
566 count = 0
567 shard = []
568 for test in tests:
569 if count % shard_count == shard_run - 1:
570 shard.append(test)
571 count += 1
572 return shard
573
574
575def Main():
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000576 # Use the v8 root as cwd as some test cases use "load" with relative paths.
577 os.chdir(BASE_DIR)
578
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000579 parser = BuildOptions()
580 (options, args) = parser.parse_args()
581 if not ProcessOptions(options):
582 parser.print_help()
583 return 1
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000584 SetupEnvironment(options)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000585
586 exit_code = 0
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000587 if not options.no_presubmit:
588 print ">>> running presubmit tests"
589 exit_code = subprocess.call(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590 [sys.executable, join(BASE_DIR, "tools", "presubmit.py")])
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000591
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000592 suite_paths = utils.GetSuitePaths(join(BASE_DIR, "test"))
593
594 # Use default tests if no test configuration was provided at the cmd line.
595 if len(args) == 0:
596 args = ["default"]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000597
598 # Expand arguments with grouped tests. The args should reflect the list of
599 # suites as otherwise filters would break.
600 def ExpandTestGroups(name):
601 if name in TEST_MAP:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000602 return [suite for suite in TEST_MAP[name]]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000603 else:
604 return [name]
605 args = reduce(lambda x, y: x + y,
606 [ExpandTestGroups(arg) for arg in args],
607 [])
608
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000609 args_suites = OrderedDict() # Used as set
610 for arg in args:
611 args_suites[arg.split('/')[0]] = True
612 suite_paths = [ s for s in args_suites if s in suite_paths ]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000613
614 suites = []
615 for root in suite_paths:
616 suite = testsuite.TestSuite.LoadTestSuite(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000617 os.path.join(BASE_DIR, "test", root))
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000618 if suite:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000619 suite.SetupWorkingDirectory()
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000620 suites.append(suite)
621
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000622 if options.download_data or options.download_data_only:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000623 for s in suites:
624 s.DownloadData()
625
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000626 if options.download_data_only:
627 return exit_code
628
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000629 for (arch, mode) in options.arch_and_mode:
630 try:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000631 code = Execute(arch, mode, args, options, suites)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000632 except KeyboardInterrupt:
633 return 2
634 exit_code = exit_code or code
635 return exit_code
636
637
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000638def Execute(arch, mode, args, options, suites):
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000639 print(">>> Running tests for %s.%s" % (arch, mode))
640
641 shell_dir = options.shell_dir
642 if not shell_dir:
643 if options.buildbot:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000644 # TODO(machenbach): Get rid of different output folder location on
645 # buildbot. Currently this is capitalized Release and Debug.
646 shell_dir = os.path.join(BASE_DIR, options.outdir, mode)
647 mode = BuildbotToV8Mode(mode)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000648 else:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000649 shell_dir = os.path.join(
650 BASE_DIR,
651 options.outdir,
652 "%s.%s" % (arch, MODES[mode]["output_folder"]),
653 )
654 if not os.path.exists(shell_dir):
655 raise Exception('Could not find shell_dir: "%s"' % shell_dir)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656
657 # Populate context object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000658 mode_flags = MODES[mode]["flags"]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000659 timeout = options.timeout
660 if timeout == -1:
661 # Simulators are slow, therefore allow a longer default timeout.
662 if arch in SLOW_ARCHS:
663 timeout = 2 * TIMEOUT_DEFAULT;
664 else:
665 timeout = TIMEOUT_DEFAULT;
666
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000667 timeout *= MODES[mode]["timeout_scalefactor"]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000668
669 if options.predictable:
670 # Predictable mode is slower.
671 timeout *= 2
672
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000673 # TODO(machenbach): Remove temporary verbose output on windows after
674 # debugging driver-hung-up on XP.
675 verbose_output = (
676 options.verbose or
677 utils.IsWindows() and options.progress == "verbose"
678 )
679 ctx = context.Context(arch, MODES[mode]["execution_mode"], shell_dir,
680 mode_flags, verbose_output,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000681 timeout, options.isolates,
682 options.command_prefix,
683 options.extra_flags,
684 options.no_i18n,
685 options.random_seed,
686 options.no_sorting,
687 options.rerun_failures_count,
688 options.rerun_failures_max,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000689 options.predictable,
690 options.no_harness,
691 use_perf_data=not options.swarming)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000692
693 # TODO(all): Combine "simulator" and "simulator_run".
694 simulator_run = not options.dont_skip_simulator_slow_tests and \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000695 arch in ['arm64', 'arm', 'mipsel', 'mips', 'mips64', 'mips64el', \
696 'ppc', 'ppc64'] and \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400697 ARCH_GUESS and arch != ARCH_GUESS
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000698 # Find available test suites and read test cases from them.
699 variables = {
700 "arch": arch,
701 "asan": options.asan,
702 "deopt_fuzzer": False,
703 "gc_stress": options.gc_stress,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000704 "gcov_coverage": options.gcov_coverage,
705 "ignition": options.ignition,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000706 "isolates": options.isolates,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000707 "mode": MODES[mode]["status_mode"],
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000708 "no_i18n": options.no_i18n,
709 "no_snap": options.no_snap,
710 "simulator_run": simulator_run,
711 "simulator": utils.UseSimulator(arch),
712 "system": utils.GuessOS(),
713 "tsan": options.tsan,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400714 "msan": options.msan,
715 "dcheck_always_on": options.dcheck_always_on,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000716 "novfp3": options.novfp3,
717 "predictable": options.predictable,
718 "byteorder": sys.byteorder,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000719 }
720 all_tests = []
721 num_tests = 0
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000722 for s in suites:
723 s.ReadStatusFile(variables)
724 s.ReadTestCases(ctx)
725 if len(args) > 0:
726 s.FilterTestCasesByArgs(args)
727 all_tests += s.tests
728 s.FilterTestCasesByStatus(options.warn_unused, options.flaky_tests,
729 options.slow_tests, options.pass_fail_tests)
730 if options.cat:
731 verbose.PrintTestSource(s.tests)
732 continue
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000733 variant_gen = s.CreateVariantGenerator(VARIANTS)
734 variant_tests = [ t.CopyAddingFlags(v, flags)
735 for t in s.tests
736 for v in variant_gen.FilterVariantsByTest(t)
737 for flags in variant_gen.GetFlagSets(t, v) ]
738
739 if options.random_seed_stress_count > 1:
740 # Duplicate test for random seed stress mode.
741 def iter_seed_flags():
742 for i in range(0, options.random_seed_stress_count):
743 # Use given random seed for all runs (set by default in execution.py)
744 # or a new random seed if none is specified.
745 if options.random_seed:
746 yield []
747 else:
748 yield ["--random-seed=%d" % RandomSeed()]
749 s.tests = [
750 t.CopyAddingFlags(t.variant, flags)
751 for t in variant_tests
752 for flags in iter_seed_flags()
753 ]
754 else:
755 s.tests = variant_tests
756
757 s.tests = ShardTests(s.tests, options)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000758 num_tests += len(s.tests)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000759
760 if options.cat:
761 return 0 # We're done here.
762
763 if options.report:
764 verbose.PrintReport(all_tests)
765
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000766 # Run the tests, either locally or distributed on the network.
767 start_time = time.time()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000768 progress_indicator = progress.IndicatorNotifier()
769 progress_indicator.Register(progress.PROGRESS_INDICATORS[options.progress]())
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000770 if options.junitout:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000771 progress_indicator.Register(progress.JUnitTestProgressIndicator(
772 options.junitout, options.junittestsuite))
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000773 if options.json_test_results:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000774 progress_indicator.Register(progress.JsonTestProgressIndicator(
775 options.json_test_results, arch, MODES[mode]["execution_mode"],
776 ctx.random_seed))
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000777
778 run_networked = not options.no_network
779 if not run_networked:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000780 if verbose_output:
781 print("Network distribution disabled, running tests locally.")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000782 elif utils.GuessOS() != "linux":
783 print("Network distribution is only supported on Linux, sorry!")
784 run_networked = False
785 peers = []
786 if run_networked:
787 peers = network_execution.GetPeers()
788 if not peers:
789 print("No connection to distribution server; running tests locally.")
790 run_networked = False
791 elif len(peers) == 1:
792 print("No other peers on the network; running tests locally.")
793 run_networked = False
794 elif num_tests <= 100:
795 print("Less than 100 tests, running them locally.")
796 run_networked = False
797
798 if run_networked:
799 runner = network_execution.NetworkedRunner(suites, progress_indicator,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000800 ctx, peers, BASE_DIR)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000801 else:
802 runner = execution.Runner(suites, progress_indicator, ctx)
803
804 exit_code = runner.Run(options.j)
805 overall_duration = time.time() - start_time
806
807 if options.time:
808 verbose.PrintTestDurations(suites, overall_duration)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000809
810 if num_tests == 0:
811 print("Warning: no tests were run!")
812
813 if exit_code == 1 and options.json_test_results:
814 print("Force exit code 0 after failures. Json test results file generated "
815 "with failure information.")
816 exit_code = 0
817
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000818 return exit_code
819
820
821if __name__ == "__main__":
822 sys.exit(Main())