regress revision 9843
11897Sstever@eecs.umich.edu#! /usr/bin/env python 23077Sstever@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 341897Sstever@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') 423077Sstever@eecs.umich.eduadd_option('--builds', 433099Sstever@eecs.umich.edu default='ALPHA,ALPHA_MOESI_hammer,' \ 443099Sstever@eecs.umich.edu 'ALPHA_MESI_CMP_directory,' \ 451897Sstever@eecs.umich.edu 'ALPHA_MOESI_CMP_directory,' \ 461897Sstever@eecs.umich.edu 'ALPHA_MOESI_CMP_token,' \ 473099Sstever@eecs.umich.edu 'MIPS,' \ 483099Sstever@eecs.umich.edu 'POWER,' \ 491897Sstever@eecs.umich.edu 'SPARC,' \ 503099Sstever@eecs.umich.edu 'X86,X86_MESI_CMP_directory,' \ 513725Sstever@eecs.umich.edu 'ARM', 523725Sstever@eecs.umich.edu help="comma-separated build targets to test (default: '%default')") 531897Sstever@eecs.umich.eduadd_option('--modes', 541897Sstever@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', 651897Sstever@eecs.umich.edu help='number of parallel jobs to use (0 to use all cores)') 661897Sstever@eecs.umich.eduadd_option('-k', '--keep-going', action='store_true', 671897Sstever@eecs.umich.edu help='keep going after errors') 681897Sstever@eecs.umich.eduadd_option('--update-ref', action='store_true', 691897Sstever@eecs.umich.edu help='update reference outputs') 701897Sstever@eecs.umich.eduadd_option('-D', '--build-dir', default='', metavar='DIR', 711897Sstever@eecs.umich.edu help='build directory location') 721897Sstever@eecs.umich.eduadd_option('-n', "--no-exec", default=False, action='store_true', 731897Sstever@eecs.umich.edu help="don't actually invoke scons, just echo SCons command line") 741897Sstever@eecs.umich.edu 751897Sstever@eecs.umich.edu(options, tests) = optparser.parse_args() 761897Sstever@eecs.umich.edu 771897Sstever@eecs.umich.edu 781897Sstever@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 [] 833077Sstever@eecs.umich.edu return s.split(',') 843077Sstever@eecs.umich.edu 853077Sstever@eecs.umich.edu# split list options on ',' to get Python lists 863077Sstever@eecs.umich.edubuilds = split_if_nonempty(options.builds) 873077Sstever@eecs.umich.edumodes = split_if_nonempty(options.modes) 883077Sstever@eecs.umich.edutest_variants = split_if_nonempty(options.test_variants) 893077Sstever@eecs.umich.educompile_variants = split_if_nonempty(options.compile_variants) 903077Sstever@eecs.umich.edu 913077Sstever@eecs.umich.eduoptions.build_dir = os.path.join(options.build_dir, 'build') 921897Sstever@eecs.umich.edu 933725Sstever@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero 943725Sstever@eecs.umich.edudef system(cmd): 953725Sstever@eecs.umich.edu try: 963725Sstever@eecs.umich.edu retcode = call(cmd, shell=True) 973725Sstever@eecs.umich.edu if retcode < 0: 981897Sstever@eecs.umich.edu print >>sys.stderr, "Child was terminated by signal", -retcode 991897Sstever@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1001897Sstever@eecs.umich.edu sys.exit(1) 1011897Sstever@eecs.umich.edu elif retcode > 0: 1021897Sstever@eecs.umich.edu print >>sys.stderr, "Child returned", retcode 1031897Sstever@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 104 sys.exit(1) 105 except OSError, e: 106 print >>sys.stderr, "Execution failed:", e 107 print >>sys.stderr, "When attemping to execute: %s" % cmd 108 sys.exit(1) 109 110targets = [] 111 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 158# We generally compile gem5.fast only to make sure it compiles OK; 159# it's not very useful to run as a regression test since assertions 160# are disabled. Thus there's not much point spending time on 161# link-time optimization. 162scons_opts += ' --no-lto' 163 164cmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets)) 165if options.no_exec: 166 print cmd 167else: 168 system(cmd) 169 sys.exit(0) 170