1#!/usr/bin/env python 2# 3# Copyright 2011 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 31# This is a convenience script to run the existing tools/test.py script 32# when using the gyp/make based build. 33# It is intended as a stop-gap rather than a long-term solution. 34 35 36import optparse 37import os 38from os.path import join, dirname, abspath 39import subprocess 40import sys 41 42 43PROGRESS_INDICATORS = ['verbose', 'dots', 'color', 'mono'] 44 45 46def BuildOptions(): 47 result = optparse.OptionParser() 48 49 # Flags specific to this wrapper script: 50 result.add_option("--arch-and-mode", 51 help='Architecture and mode in the format "arch.mode"', 52 default=None) 53 result.add_option("--outdir", 54 help='Base output directory', 55 default='out') 56 result.add_option("--no-presubmit", 57 help='Skip presubmit checks', 58 default=False, action="store_true") 59 60 # Flags this wrapper script handles itself: 61 result.add_option("-m", "--mode", 62 help="The test modes in which to run (comma-separated)", 63 default='release,debug') 64 result.add_option("--arch", 65 help='The architectures to run tests for (comma-separated)', 66 default='ia32,x64,arm') 67 68 # Flags that are passed on to the wrapped test.py script: 69 result.add_option("-v", "--verbose", help="Verbose output", 70 default=False, action="store_true") 71 result.add_option("-p", "--progress", 72 help="The style of progress indicator (verbose, dots, color, mono)", 73 choices=PROGRESS_INDICATORS, default="mono") 74 result.add_option("--report", help="Print a summary of the tests to be run", 75 default=False, action="store_true") 76 result.add_option("--download-data", help="Download missing test suite data", 77 default=False, action="store_true") 78 result.add_option("-s", "--suite", help="A test suite", 79 default=[], action="append") 80 result.add_option("-t", "--timeout", help="Timeout in seconds", 81 default=60, type="int") 82 result.add_option("--snapshot", help="Run the tests with snapshot turned on", 83 default=False, action="store_true") 84 result.add_option("--special-command", default=None) 85 result.add_option("--valgrind", help="Run tests through valgrind", 86 default=False, action="store_true") 87 result.add_option("--cat", help="Print the source of the tests", 88 default=False, action="store_true") 89 result.add_option("--warn-unused", help="Report unused rules", 90 default=False, action="store_true") 91 result.add_option("-j", help="The number of parallel tasks to run", 92 default=1, type="int") 93 result.add_option("--time", help="Print timing information after running", 94 default=False, action="store_true") 95 result.add_option("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests", 96 dest="suppress_dialogs", default=True, action="store_true") 97 result.add_option("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests", 98 dest="suppress_dialogs", action="store_false") 99 result.add_option("--isolates", help="Whether to test isolates", default=False, action="store_true") 100 result.add_option("--store-unexpected-output", 101 help="Store the temporary JS files from tests that fails", 102 dest="store_unexpected_output", default=True, action="store_true") 103 result.add_option("--no-store-unexpected-output", 104 help="Deletes the temporary JS files from tests that fails", 105 dest="store_unexpected_output", action="store_false") 106 result.add_option("--stress-only", 107 help="Only run tests with --always-opt --stress-opt", 108 default=False, action="store_true") 109 result.add_option("--nostress", 110 help="Don't run crankshaft --always-opt --stress-op test", 111 default=False, action="store_true") 112 result.add_option("--crankshaft", 113 help="Run with the --crankshaft flag", 114 default=False, action="store_true") 115 result.add_option("--shard-count", 116 help="Split testsuites into this number of shards", 117 default=1, type="int") 118 result.add_option("--shard-run", 119 help="Run this shard from the split up tests.", 120 default=1, type="int") 121 result.add_option("--noprof", help="Disable profiling support", 122 default=False) 123 124 # Flags present in the original test.py that are unsupported in this wrapper: 125 # -S [-> scons_flags] (we build with gyp/make, not scons) 126 # --no-build (always true) 127 # --build-only (always false) 128 # --build-system (always 'gyp') 129 # --simulator (always true if arch==arm, always false otherwise) 130 # --shell (automatically chosen depending on arch and mode) 131 132 return result 133 134 135def ProcessOptions(options): 136 if options.arch_and_mode == ".": 137 options.arch = [] 138 options.mode = [] 139 else: 140 if options.arch_and_mode != None and options.arch_and_mode != "": 141 tokens = options.arch_and_mode.split(".") 142 options.arch = tokens[0] 143 options.mode = tokens[1] 144 options.mode = options.mode.split(',') 145 options.arch = options.arch.split(',') 146 for mode in options.mode: 147 if not mode in ['debug', 'release']: 148 print "Unknown mode %s" % mode 149 return False 150 for arch in options.arch: 151 if not arch in ['ia32', 'x64', 'arm', 'mips']: 152 print "Unknown architecture %s" % arch 153 return False 154 155 return True 156 157 158def PassOnOptions(options): 159 result = [] 160 if options.verbose: 161 result += ['--verbose'] 162 if options.progress != 'mono': 163 result += ['--progress=' + options.progress] 164 if options.report: 165 result += ['--report'] 166 if options.download_data: 167 result += ['--download-data'] 168 if options.suite != []: 169 for suite in options.suite: 170 result += ['--suite=../../test/' + suite] 171 if options.timeout != 60: 172 result += ['--timeout=%s' % options.timeout] 173 if options.snapshot: 174 result += ['--snapshot'] 175 if options.special_command: 176 result += ['--special-command="%s"' % options.special_command] 177 if options.valgrind: 178 result += ['--valgrind'] 179 if options.cat: 180 result += ['--cat'] 181 if options.warn_unused: 182 result += ['--warn-unused'] 183 if options.j != 1: 184 result += ['-j%s' % options.j] 185 if options.time: 186 result += ['--time'] 187 if not options.suppress_dialogs: 188 result += ['--no-suppress-dialogs'] 189 if options.isolates: 190 result += ['--isolates'] 191 if not options.store_unexpected_output: 192 result += ['--no-store-unexpected_output'] 193 if options.stress_only: 194 result += ['--stress-only'] 195 if options.nostress: 196 result += ['--nostress'] 197 if options.crankshaft: 198 result += ['--crankshaft'] 199 if options.shard_count != 1: 200 result += ['--shard-count=%s' % options.shard_count] 201 if options.shard_run != 1: 202 result += ['--shard-run=%s' % options.shard_run] 203 if options.noprof: 204 result += ['--noprof'] 205 return result 206 207 208def Main(): 209 parser = BuildOptions() 210 (options, args) = parser.parse_args() 211 if not ProcessOptions(options): 212 parser.print_help() 213 return 1 214 215 workspace = abspath(join(dirname(sys.argv[0]), '..')) 216 217 if not options.no_presubmit: 218 print ">>> running presubmit tests" 219 subprocess.call([workspace + '/tools/presubmit.py']) 220 221 args_for_children = [workspace + '/tools/test.py'] + PassOnOptions(options) 222 args_for_children += ['--no-build', '--build-system=gyp'] 223 for arg in args: 224 args_for_children += [arg] 225 returncodes = 0 226 env = os.environ 227 228 for mode in options.mode: 229 for arch in options.arch: 230 print ">>> running tests for %s.%s" % (arch, mode) 231 shellpath = workspace + '/' + options.outdir + '/' + arch + '.' + mode 232 env['LD_LIBRARY_PATH'] = shellpath + '/lib.target' 233 shell = shellpath + "/d8" 234 child = subprocess.Popen(' '.join(args_for_children + 235 ['--arch=' + arch] + 236 ['--mode=' + mode] + 237 ['--shell=' + shell]), 238 shell=True, 239 cwd=workspace, 240 env=env) 241 returncodes += child.wait() 242 243 if len(options.mode) == 0 and len(options.arch) == 0: 244 print ">>> running tests" 245 shellpath = workspace + '/' + options.outdir 246 env['LD_LIBRARY_PATH'] = shellpath + '/lib.target' 247 shell = shellpath + '/d8' 248 child = subprocess.Popen(' '.join(args_for_children + 249 ['--shell=' + shell]), 250 shell=True, 251 cwd=workspace, 252 env=env) 253 returncodes = child.wait() 254 255 return returncodes 256 257 258if __name__ == '__main__': 259 sys.exit(Main()) 260