regress revision 9850:87d6b41749e9
112855Sgabeblack@google.com#! /usr/bin/env python 212855Sgabeblack@google.com# Copyright (c) 2005-2007 The Regents of The University of Michigan 312855Sgabeblack@google.com# All rights reserved. 412855Sgabeblack@google.com# 512855Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com# modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com# this software without specific prior written permission. 1512855Sgabeblack@google.com# 1612855Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com# 2812855Sgabeblack@google.com# Authors: Steve Reinhardt 2912855Sgabeblack@google.com 3012855Sgabeblack@google.comimport sys 3112855Sgabeblack@google.comimport os 3212855Sgabeblack@google.comimport optparse 3312855Sgabeblack@google.comimport datetime 3412855Sgabeblack@google.comfrom subprocess import call 3512855Sgabeblack@google.com 3612855Sgabeblack@google.comprogname = os.path.basename(sys.argv[0]) 3712855Sgabeblack@google.com 3812855Sgabeblack@google.comoptparser = optparse.OptionParser() 3912855Sgabeblack@google.comadd_option = optparser.add_option 4012855Sgabeblack@google.comadd_option('-v', '--verbose', action='store_true', default=False, 4112855Sgabeblack@google.com help='echo commands before executing') 4212855Sgabeblack@google.comadd_option('--builds', 4312855Sgabeblack@google.com default='ALPHA,ALPHA_MOESI_hammer,' \ 4412855Sgabeblack@google.com 'ALPHA_MESI_CMP_directory,' \ 4512855Sgabeblack@google.com 'ALPHA_MOESI_CMP_directory,' \ 4612855Sgabeblack@google.com 'ALPHA_MOESI_CMP_token,' \ 4712855Sgabeblack@google.com 'MIPS,' \ 4812855Sgabeblack@google.com 'NULL,' \ 4912855Sgabeblack@google.com 'POWER,' \ 5012855Sgabeblack@google.com 'SPARC,' \ 5112855Sgabeblack@google.com 'X86,X86_MESI_CMP_directory,' \ 5212855Sgabeblack@google.com 'ARM', 5312855Sgabeblack@google.com help="comma-separated build targets to test (default: '%default')") 5412855Sgabeblack@google.comadd_option('--modes', 5512855Sgabeblack@google.com default='se,fs', 5612855Sgabeblack@google.com help="comma-separated modes to test (default: '%default')") 5712855Sgabeblack@google.comadd_option('--test-variants', default='opt', 5812855Sgabeblack@google.com help="comma-separated build variants to test (default: '%default')"\ 5912855Sgabeblack@google.com ", set to '' for none") 6012855Sgabeblack@google.comadd_option('--compile-variants', default='debug,fast', 6112855Sgabeblack@google.com help="comma-separated build variants to compile only (not test) " \ 6212855Sgabeblack@google.com "(default: '%default'), set to '' for none", metavar='VARIANTS') 6312855Sgabeblack@google.comadd_option('--scons-opts', default='', metavar='OPTS', 6412855Sgabeblack@google.com help='scons options') 6512855Sgabeblack@google.comadd_option('-j', '--jobs', type='int', default=1, metavar='N', 6612855Sgabeblack@google.com help='number of parallel jobs to use (0 to use all cores)') 6712855Sgabeblack@google.comadd_option('-k', '--keep-going', action='store_true', 6812855Sgabeblack@google.com help='keep going after errors') 6912855Sgabeblack@google.comadd_option('--update-ref', action='store_true', 7012855Sgabeblack@google.com help='update reference outputs') 7112855Sgabeblack@google.comadd_option('-D', '--build-dir', default='', metavar='DIR', 7212855Sgabeblack@google.com help='build directory location') 7312855Sgabeblack@google.comadd_option('-n', "--no-exec", default=False, action='store_true', 7412855Sgabeblack@google.com help="don't actually invoke scons, just echo SCons command line") 7512855Sgabeblack@google.com 7612855Sgabeblack@google.com(options, tests) = optparser.parse_args() 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com 7912855Sgabeblack@google.com# split a comma-separated list, but return an empty list if given the 8012855Sgabeblack@google.com# empty string 8112855Sgabeblack@google.comdef split_if_nonempty(s): 8212855Sgabeblack@google.com if not s: 8312855Sgabeblack@google.com return [] 8412855Sgabeblack@google.com return s.split(',') 8512855Sgabeblack@google.com 8612855Sgabeblack@google.com# split list options on ',' to get Python lists 8712855Sgabeblack@google.combuilds = split_if_nonempty(options.builds) 8812855Sgabeblack@google.commodes = split_if_nonempty(options.modes) 8912855Sgabeblack@google.comtest_variants = split_if_nonempty(options.test_variants) 9012855Sgabeblack@google.comcompile_variants = split_if_nonempty(options.compile_variants) 9112855Sgabeblack@google.com 9212855Sgabeblack@google.comoptions.build_dir = os.path.join(options.build_dir, 'build') 9312855Sgabeblack@google.com 9412855Sgabeblack@google.com# Call os.system() and raise exception if return status is non-zero 9512855Sgabeblack@google.comdef system(cmd): 9612855Sgabeblack@google.com try: 9712855Sgabeblack@google.com retcode = call(cmd, shell=True) 9812855Sgabeblack@google.com if retcode < 0: 9912855Sgabeblack@google.com print >>sys.stderr, "Child was terminated by signal", -retcode 10012855Sgabeblack@google.com print >>sys.stderr, "When attemping to execute: %s" % cmd 10112855Sgabeblack@google.com sys.exit(1) 10212855Sgabeblack@google.com elif retcode > 0: 10312855Sgabeblack@google.com print >>sys.stderr, "Child returned", retcode 10412855Sgabeblack@google.com print >>sys.stderr, "When attemping to execute: %s" % cmd 10512855Sgabeblack@google.com sys.exit(1) 10612855Sgabeblack@google.com except OSError, e: 10712855Sgabeblack@google.com print >>sys.stderr, "Execution failed:", e 10812855Sgabeblack@google.com print >>sys.stderr, "When attemping to execute: %s" % cmd 10912855Sgabeblack@google.com sys.exit(1) 11012855Sgabeblack@google.com 11112855Sgabeblack@google.comtargets = [] 11212855Sgabeblack@google.com 11312855Sgabeblack@google.com# start with compile-only targets, if any 11412855Sgabeblack@google.comif compile_variants: 11512855Sgabeblack@google.com targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant) 11612855Sgabeblack@google.com for variant in compile_variants 11712855Sgabeblack@google.com for build in builds] 11812855Sgabeblack@google.com 11912855Sgabeblack@google.com# By default run the 'quick' tests, all expands to quick and long 12012855Sgabeblack@google.comif not tests: 12112855Sgabeblack@google.com tests = ['quick'] 12212855Sgabeblack@google.comelif 'all' in tests: 12312855Sgabeblack@google.com tests = ['quick', 'long'] 12412855Sgabeblack@google.com 12512855Sgabeblack@google.com# set up test targets for scons, since we don't have any quick SPARC 12612855Sgabeblack@google.com# full-system tests exclude it 12712855Sgabeblack@google.comtargets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test, 12812855Sgabeblack@google.com mode) 12912855Sgabeblack@google.com for build in builds 13012855Sgabeblack@google.com for variant in test_variants 13112855Sgabeblack@google.com for test in tests 13212855Sgabeblack@google.com for mode in modes 13312855Sgabeblack@google.com if not (build == 'SPARC' and test == 'quick' and mode == 'fs')] 13412855Sgabeblack@google.com 13512855Sgabeblack@google.comdef cpu_count(): 13612855Sgabeblack@google.com if 'bsd' in sys.platform or sys.platform == 'darwin': 13712855Sgabeblack@google.com try: 13812855Sgabeblack@google.com return int(os.popen('sysctl -n hw.ncpu').read()) 13912855Sgabeblack@google.com except ValueError: 14012855Sgabeblack@google.com pass 14112855Sgabeblack@google.com else: 14212855Sgabeblack@google.com try: 14312855Sgabeblack@google.com return os.sysconf('SC_NPROCESSORS_ONLN') 14412855Sgabeblack@google.com except (ValueError, OSError, AttributeError): 14512855Sgabeblack@google.com pass 14612855Sgabeblack@google.com 14712855Sgabeblack@google.com raise NotImplementedError('cannot determine number of cpus') 14812855Sgabeblack@google.com 14912855Sgabeblack@google.comscons_opts = options.scons_opts 15012855Sgabeblack@google.comif options.jobs != 1: 15112855Sgabeblack@google.com if options.jobs == 0: 15212855Sgabeblack@google.com options.jobs = cpu_count() 15312855Sgabeblack@google.com scons_opts += ' -j %d' % options.jobs 15412855Sgabeblack@google.comif options.keep_going: 15512855Sgabeblack@google.com scons_opts += ' -k' 15612855Sgabeblack@google.comif options.update_ref: 15712855Sgabeblack@google.com scons_opts += ' --update-ref' 15812855Sgabeblack@google.com 15912855Sgabeblack@google.com# We generally compile gem5.fast only to make sure it compiles OK; 16012855Sgabeblack@google.com# it's not very useful to run as a regression test since assertions 16112855Sgabeblack@google.com# are disabled. Thus there's not much point spending time on 16212855Sgabeblack@google.com# link-time optimization. 16312855Sgabeblack@google.comscons_opts += ' --no-lto' 16412855Sgabeblack@google.com 165cmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets)) 166if options.no_exec: 167 print cmd 168else: 169 system(cmd) 170 sys.exit(0) 171