regress revision 8969
11897Sstever@eecs.umich.edu#! /usr/bin/env python 24130Ssaidi@eecs.umich.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan 31897Sstever@eecs.umich.edu# All rights reserved. 41897Sstever@eecs.umich.edu# 51897Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 61897Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are 71897Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright 81897Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 91897Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 101897Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 111897Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution; 121897Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its 131897Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from 141897Sstever@eecs.umich.edu# this software without specific prior written permission. 151897Sstever@eecs.umich.edu# 161897Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171897Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181897Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191897Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201897Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211897Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221897Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231897Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241897Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251897Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261897Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271897Sstever@eecs.umich.edu# 281897Sstever@eecs.umich.edu# Authors: Steve Reinhardt 291897Sstever@eecs.umich.edu 301897Sstever@eecs.umich.eduimport sys 311897Sstever@eecs.umich.eduimport os 321897Sstever@eecs.umich.eduimport optparse 331897Sstever@eecs.umich.eduimport datetime 344961Ssaidi@eecs.umich.edufrom subprocess import call 351897Sstever@eecs.umich.edu 361897Sstever@eecs.umich.eduprogname = os.path.basename(sys.argv[0]) 371897Sstever@eecs.umich.edu 381897Sstever@eecs.umich.eduoptparser = optparse.OptionParser() 391897Sstever@eecs.umich.eduadd_option = optparser.add_option 401897Sstever@eecs.umich.eduadd_option('-v', '--verbose', action='store_true', default=False, 411897Sstever@eecs.umich.edu help='echo commands before executing') 421897Sstever@eecs.umich.eduadd_option('--builds', 435187Sgblack@eecs.umich.edu default='ALPHA,ALPHA_MOESI_hammer,' \ 445187Sgblack@eecs.umich.edu 'ALPHA_MESI_CMP_directory,' \ 453099Sstever@eecs.umich.edu 'ALPHA_MOESI_CMP_directory,' \ 463099Sstever@eecs.umich.edu 'ALPHA_MOESI_CMP_token,' \ 471897Sstever@eecs.umich.edu 'MIPS,' \ 483709Sstever@eecs.umich.edu 'POWER,' \ 493099Sstever@eecs.umich.edu 'SPARC,' \ 503099Sstever@eecs.umich.edu 'X86,X86_MESI_CMP_directory,' \ 511897Sstever@eecs.umich.edu 'ARM', 523099Sstever@eecs.umich.edu help="comma-separated build targets to test (default: '%default')") 533725Sstever@eecs.umich.eduadd_option('--modes', 543725Sstever@eecs.umich.edu default='se,fs', 551897Sstever@eecs.umich.edu help="comma-separated modes to test (default: '%default')") 561897Sstever@eecs.umich.eduadd_option('--test-variants', default='opt', 571897Sstever@eecs.umich.edu help="comma-separated build variants to test (default: '%default')"\ 581897Sstever@eecs.umich.edu ", set to '' for none") 591897Sstever@eecs.umich.eduadd_option('--compile-variants', default='debug,fast', 601897Sstever@eecs.umich.edu help="comma-separated build variants to compile only (not test) " \ 611897Sstever@eecs.umich.edu "(default: '%default'), set to '' for none", metavar='VARIANTS') 621897Sstever@eecs.umich.eduadd_option('--scons-opts', default='', metavar='OPTS', 631897Sstever@eecs.umich.edu help='scons options') 641897Sstever@eecs.umich.eduadd_option('-j', '--jobs', type='int', default=1, metavar='N', 654961Ssaidi@eecs.umich.edu help='number of parallel jobs to use (0 to use all cores)') 664961Ssaidi@eecs.umich.eduadd_option('-k', '--keep-going', action='store_true', 674961Ssaidi@eecs.umich.edu help='keep going after errors') 684961Ssaidi@eecs.umich.eduadd_option('--update-ref', action='store_true', 694961Ssaidi@eecs.umich.edu help='update reference outputs') 704961Ssaidi@eecs.umich.eduadd_option('-D', '--build-dir', default='', metavar='DIR', 714961Ssaidi@eecs.umich.edu help='build directory location') 724961Ssaidi@eecs.umich.eduadd_option('-n', "--no-exec", default=False, action='store_true', 734961Ssaidi@eecs.umich.edu help="don't actually invoke scons, just echo SCons command line") 744961Ssaidi@eecs.umich.edu 754961Ssaidi@eecs.umich.edu(options, tests) = optparser.parse_args() 764961Ssaidi@eecs.umich.edu 774961Ssaidi@eecs.umich.edu 784961Ssaidi@eecs.umich.edu# split a comma-separated list, but return an empty list if given the 791897Sstever@eecs.umich.edu# empty string 801897Sstever@eecs.umich.edudef split_if_nonempty(s): 811897Sstever@eecs.umich.edu if not s: 821897Sstever@eecs.umich.edu return [] 831897Sstever@eecs.umich.edu return s.split(',') 841897Sstever@eecs.umich.edu 851897Sstever@eecs.umich.edu# split list options on ',' to get Python lists 864961Ssaidi@eecs.umich.edubuilds = split_if_nonempty(options.builds) 874961Ssaidi@eecs.umich.edumodes = split_if_nonempty(options.modes) 884961Ssaidi@eecs.umich.edutest_variants = split_if_nonempty(options.test_variants) 894961Ssaidi@eecs.umich.educompile_variants = split_if_nonempty(options.compile_variants) 904961Ssaidi@eecs.umich.edu 914961Ssaidi@eecs.umich.eduoptions.build_dir = os.path.join(options.build_dir, 'build') 924961Ssaidi@eecs.umich.edu 934961Ssaidi@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero 944961Ssaidi@eecs.umich.edudef system(cmd): 954961Ssaidi@eecs.umich.edu try: 964961Ssaidi@eecs.umich.edu retcode = call(cmd, shell=True) 974961Ssaidi@eecs.umich.edu if retcode < 0: 984961Ssaidi@eecs.umich.edu print >>sys.stderr, "Child was terminated by signal", -retcode 994961Ssaidi@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1004961Ssaidi@eecs.umich.edu sys.exit(1) 1014961Ssaidi@eecs.umich.edu elif retcode > 0: 1024961Ssaidi@eecs.umich.edu print >>sys.stderr, "Child returned", retcode 1034961Ssaidi@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1041897Sstever@eecs.umich.edu sys.exit(1) 1054961Ssaidi@eecs.umich.edu except OSError, e: 1064961Ssaidi@eecs.umich.edu print >>sys.stderr, "Execution failed:", e 1074961Ssaidi@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1083725Sstever@eecs.umich.edu sys.exit(1) 1094975Ssaidi@eecs.umich.edu 1101897Sstever@eecs.umich.edutargets = [] 1114961Ssaidi@eecs.umich.edu 112# start with compile-only targets, if any 113if compile_variants: 114 targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant) 115 for variant in compile_variants 116 for build in builds] 117 118# By default run the 'quick' tests, all expands to quick and long 119if not tests: 120 tests = ['quick'] 121elif 'all' in tests: 122 tests = ['quick', 'long'] 123 124# set up test targets for scons, since we don't have any quick SPARC 125# full-system tests exclude it 126targets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test, 127 mode) 128 for build in builds 129 for variant in test_variants 130 for test in tests 131 for mode in modes 132 if not (build == 'SPARC' and test == 'quick' and mode == 'fs')] 133 134def cpu_count(): 135 if 'bsd' in sys.platform or sys.platform == 'darwin': 136 try: 137 return int(os.popen('sysctl -n hw.ncpu').read()) 138 except ValueError: 139 pass 140 else: 141 try: 142 return os.sysconf('SC_NPROCESSORS_ONLN') 143 except (ValueError, OSError, AttributeError): 144 pass 145 146 raise NotImplementedError('cannot determine number of cpus') 147 148scons_opts = options.scons_opts 149if options.jobs != 1: 150 if options.jobs == 0: 151 options.jobs = cpu_count() 152 scons_opts += ' -j %d' % options.jobs 153if options.keep_going: 154 scons_opts += ' -k' 155if options.update_ref: 156 scons_opts += ' --update-ref' 157 158cmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets)) 159if options.no_exec: 160 print cmd 161else: 162 system(cmd) 163 sys.exit(0) 164