test-wrapper-gypbuild.py revision c7cc028aaeedbbfa11c11d0b7b243b3d9e837ed9
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("-s", "--suite", help="A test suite", 77 default=[], action="append") 78 result.add_option("-t", "--timeout", help="Timeout in seconds", 79 default=60, type="int") 80 result.add_option("--snapshot", help="Run the tests with snapshot turned on", 81 default=False, action="store_true") 82 result.add_option("--special-command", default=None) 83 result.add_option("--valgrind", help="Run tests through valgrind", 84 default=False, action="store_true") 85 result.add_option("--cat", help="Print the source of the tests", 86 default=False, action="store_true") 87 result.add_option("--warn-unused", help="Report unused rules", 88 default=False, action="store_true") 89 result.add_option("-j", help="The number of parallel tasks to run", 90 default=1, type="int") 91 result.add_option("--time", help="Print timing information after running", 92 default=False, action="store_true") 93 result.add_option("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests", 94 dest="suppress_dialogs", default=True, action="store_true") 95 result.add_option("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests", 96 dest="suppress_dialogs", action="store_false") 97 result.add_option("--isolates", help="Whether to test isolates", default=False, action="store_true") 98 result.add_option("--store-unexpected-output", 99 help="Store the temporary JS files from tests that fails", 100 dest="store_unexpected_output", default=True, action="store_true") 101 result.add_option("--no-store-unexpected-output", 102 help="Deletes the temporary JS files from tests that fails", 103 dest="store_unexpected_output", action="store_false") 104 result.add_option("--stress-only", 105 help="Only run tests with --always-opt --stress-opt", 106 default=False, action="store_true") 107 result.add_option("--nostress", 108 help="Don't run crankshaft --always-opt --stress-op test", 109 default=False, action="store_true") 110 result.add_option("--crankshaft", 111 help="Run with the --crankshaft flag", 112 default=False, action="store_true") 113 result.add_option("--shard-count", 114 help="Split testsuites into this number of shards", 115 default=1, type="int") 116 result.add_option("--shard-run", 117 help="Run this shard from the split up tests.", 118 default=1, type="int") 119 result.add_option("--noprof", help="Disable profiling support", 120 default=False) 121 122 # Flags present in the original test.py that are unsupported in this wrapper: 123 # -S [-> scons_flags] (we build with gyp/make, not scons) 124 # --no-build (always true) 125 # --build-only (always false) 126 # --build-system (always 'gyp') 127 # --simulator (always true if arch==arm, always false otherwise) 128 # --shell (automatically chosen depending on arch and mode) 129 130 return result 131 132 133def ProcessOptions(options): 134 if options.arch_and_mode == ".": 135 options.arch = [] 136 options.mode = [] 137 else: 138 if options.arch_and_mode != None and options.arch_and_mode != "": 139 tokens = options.arch_and_mode.split(".") 140 options.arch = tokens[0] 141 options.mode = tokens[1] 142 options.mode = options.mode.split(',') 143 options.arch = options.arch.split(',') 144 for mode in options.mode: 145 if not mode in ['debug', 'release']: 146 print "Unknown mode %s" % mode 147 return False 148 for arch in options.arch: 149 if not arch in ['ia32', 'x64', 'arm', 'mips']: 150 print "Unknown architecture %s" % arch 151 return False 152 153 return True 154 155 156def PassOnOptions(options): 157 result = [] 158 if options.verbose: 159 result += ['--verbose'] 160 if options.progress != 'mono': 161 result += ['--progress=' + options.progress] 162 if options.report: 163 result += ['--report'] 164 if options.suite != []: 165 for suite in options.suite: 166 result += ['--suite=../../test/' + suite] 167 if options.timeout != 60: 168 result += ['--timeout=%s' % options.timeout] 169 if options.snapshot: 170 result += ['--snapshot'] 171 if options.special_command: 172 result += ['--special-command="%s"' % options.special_command] 173 if options.valgrind: 174 result += ['--valgrind'] 175 if options.cat: 176 result += ['--cat'] 177 if options.warn_unused: 178 result += ['--warn-unused'] 179 if options.j != 1: 180 result += ['-j%s' % options.j] 181 if options.time: 182 result += ['--time'] 183 if not options.suppress_dialogs: 184 result += ['--no-suppress-dialogs'] 185 if options.isolates: 186 result += ['--isolates'] 187 if not options.store_unexpected_output: 188 result += ['--no-store-unexpected_output'] 189 if options.stress_only: 190 result += ['--stress-only'] 191 if options.nostress: 192 result += ['--nostress'] 193 if options.crankshaft: 194 result += ['--crankshaft'] 195 if options.shard_count != 1: 196 result += ['--shard_count=%s' % options.shard_count] 197 if options.shard_run != 1: 198 result += ['--shard_run=%s' % options.shard_run] 199 if options.noprof: 200 result += ['--noprof'] 201 return result 202 203 204def Main(): 205 parser = BuildOptions() 206 (options, args) = parser.parse_args() 207 if not ProcessOptions(options): 208 parser.print_help() 209 return 1 210 211 workspace = abspath(join(dirname(sys.argv[0]), '..')) 212 213 if not options.no_presubmit: 214 print ">>> running presubmit tests" 215 subprocess.call([workspace + '/tools/presubmit.py']) 216 217 args_for_children = [workspace + '/tools/test.py'] + PassOnOptions(options) 218 args_for_children += ['--no-build', '--build-system=gyp'] 219 for arg in args: 220 args_for_children += [arg] 221 returncodes = 0 222 env = os.environ 223 224 for mode in options.mode: 225 for arch in options.arch: 226 print ">>> running tests for %s.%s" % (arch, mode) 227 shellpath = workspace + '/' + options.outdir + '/' + arch + '.' + mode 228 env['LD_LIBRARY_PATH'] = shellpath + '/lib.target' 229 shell = shellpath + "/d8" 230 child = subprocess.Popen(' '.join(args_for_children + 231 ['--arch=' + arch] + 232 ['--mode=' + mode] + 233 ['--shell=' + shell]), 234 shell=True, 235 cwd=workspace, 236 env=env) 237 returncodes += child.wait() 238 239 if len(options.mode) == 0 and len(options.arch) == 0: 240 print ">>> running tests" 241 shellpath = workspace + '/' + options.outdir 242 env['LD_LIBRARY_PATH'] = shellpath + '/lib.target' 243 shell = shellpath + '/d8' 244 child = subprocess.Popen(' '.join(args_for_children + 245 ['--shell=' + shell]), 246 shell=True, 247 cwd=workspace, 248 env=env) 249 returncodes = child.wait() 250 251 return returncodes 252 253 254if __name__ == '__main__': 255 sys.exit(Main()) 256