regress revision 11706
16019Shines@cs.fsu.edu#! /usr/bin/env python 26019Shines@cs.fsu.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan 36019Shines@cs.fsu.edu# All rights reserved. 46019Shines@cs.fsu.edu# 56019Shines@cs.fsu.edu# Redistribution and use in source and binary forms, with or without 66019Shines@cs.fsu.edu# modification, are permitted provided that the following conditions are 76019Shines@cs.fsu.edu# met: redistributions of source code must retain the above copyright 86019Shines@cs.fsu.edu# notice, this list of conditions and the following disclaimer; 96019Shines@cs.fsu.edu# redistributions in binary form must reproduce the above copyright 106019Shines@cs.fsu.edu# notice, this list of conditions and the following disclaimer in the 116019Shines@cs.fsu.edu# documentation and/or other materials provided with the distribution; 126019Shines@cs.fsu.edu# neither the name of the copyright holders nor the names of its 136019Shines@cs.fsu.edu# contributors may be used to endorse or promote products derived from 146019Shines@cs.fsu.edu# this software without specific prior written permission. 156019Shines@cs.fsu.edu# 166019Shines@cs.fsu.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176019Shines@cs.fsu.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186019Shines@cs.fsu.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196019Shines@cs.fsu.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206019Shines@cs.fsu.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216019Shines@cs.fsu.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226019Shines@cs.fsu.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236019Shines@cs.fsu.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246019Shines@cs.fsu.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256019Shines@cs.fsu.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266019Shines@cs.fsu.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276019Shines@cs.fsu.edu# 286019Shines@cs.fsu.edu# Authors: Steve Reinhardt 296019Shines@cs.fsu.edu 306019Shines@cs.fsu.eduimport sys 316019Shines@cs.fsu.eduimport os 326019Shines@cs.fsu.eduimport optparse 336019Shines@cs.fsu.eduimport datetime 346019Shines@cs.fsu.edufrom subprocess import call 356019Shines@cs.fsu.edu 366019Shines@cs.fsu.eduprogname = os.path.basename(sys.argv[0]) 376019Shines@cs.fsu.edu 386019Shines@cs.fsu.eduoptparser = optparse.OptionParser() 396019Shines@cs.fsu.eduadd_option = optparser.add_option 406019Shines@cs.fsu.eduadd_option('-v', '--verbose', action='store_true', default=False, 416019Shines@cs.fsu.edu help='echo commands before executing') 426019Shines@cs.fsu.eduadd_option('--builds', 436019Shines@cs.fsu.edu default='ALPHA,' \ 446019Shines@cs.fsu.edu 'MIPS,' \ 456019Shines@cs.fsu.edu 'NULL,' \ 466019Shines@cs.fsu.edu 'NULL_MOESI_hammer,' \ 476019Shines@cs.fsu.edu 'NULL_MESI_Two_Level,' \ 486019Shines@cs.fsu.edu 'NULL_MOESI_CMP_directory,' \ 496019Shines@cs.fsu.edu 'NULL_MOESI_CMP_token,' \ 506019Shines@cs.fsu.edu 'POWER,' \ 516019Shines@cs.fsu.edu 'SPARC,' \ 526019Shines@cs.fsu.edu 'X86,X86_MESI_Two_Level,' \ 536019Shines@cs.fsu.edu 'ARM,' \ 546019Shines@cs.fsu.edu 'HSAIL_X86', 556019Shines@cs.fsu.edu help="comma-separated build targets to test (default: '%default')") 566019Shines@cs.fsu.eduadd_option('--modes', 576019Shines@cs.fsu.edu default='se,fs', 586019Shines@cs.fsu.edu help="comma-separated modes to test (default: '%default')") 596019Shines@cs.fsu.eduadd_option('--test-variants', default='opt', 606019Shines@cs.fsu.edu help="comma-separated build variants to test (default: '%default')"\ 616019Shines@cs.fsu.edu ", set to '' for none") 626019Shines@cs.fsu.eduadd_option('--compile-variants', default='debug,fast', 636019Shines@cs.fsu.edu help="comma-separated build variants to compile only (not test) " \ 646019Shines@cs.fsu.edu "(default: '%default'), set to '' for none", metavar='VARIANTS') 656019Shines@cs.fsu.eduadd_option('--scons-opts', default='', metavar='OPTS', 666019Shines@cs.fsu.edu help='scons options') 676019Shines@cs.fsu.eduadd_option('-j', '--jobs', type='int', default=1, metavar='N', 686019Shines@cs.fsu.edu help='number of parallel jobs to use (0 to use all cores)') 696019Shines@cs.fsu.eduadd_option('-k', '--keep-going', action='store_true', 706019Shines@cs.fsu.edu help='keep going after errors') 716019Shines@cs.fsu.eduadd_option('--update-ref', action='store_true', 726019Shines@cs.fsu.edu help='update reference outputs') 736019Shines@cs.fsu.eduadd_option('-D', '--build-dir', default='', metavar='DIR', 746019Shines@cs.fsu.edu help='build directory location') 756019Shines@cs.fsu.eduadd_option('-n', "--no-exec", default=False, action='store_true', 766019Shines@cs.fsu.edu help="don't actually invoke scons, just echo SCons command line") 776019Shines@cs.fsu.edu 786019Shines@cs.fsu.edu(options, tests) = optparser.parse_args() 796019Shines@cs.fsu.edu 806019Shines@cs.fsu.edu 816019Shines@cs.fsu.edu# split a comma-separated list, but return an empty list if given the 826019Shines@cs.fsu.edu# empty string 836019Shines@cs.fsu.edudef split_if_nonempty(s): 846019Shines@cs.fsu.edu if not s: 856019Shines@cs.fsu.edu return [] 866019Shines@cs.fsu.edu return s.split(',') 876019Shines@cs.fsu.edu 886019Shines@cs.fsu.edu# split list options on ',' to get Python lists 896019Shines@cs.fsu.edubuilds = split_if_nonempty(options.builds) 906019Shines@cs.fsu.edumodes = split_if_nonempty(options.modes) 916019Shines@cs.fsu.edutest_variants = split_if_nonempty(options.test_variants) 926019Shines@cs.fsu.educompile_variants = split_if_nonempty(options.compile_variants) 936019Shines@cs.fsu.edu 946019Shines@cs.fsu.eduoptions.build_dir = os.path.join(options.build_dir, 'build') 956019Shines@cs.fsu.edu 966019Shines@cs.fsu.edu# Call os.system() and raise exception if return status is non-zero 976019Shines@cs.fsu.edudef system(cmd): 986019Shines@cs.fsu.edu try: 996019Shines@cs.fsu.edu retcode = call(cmd, shell=True) 1006019Shines@cs.fsu.edu if retcode < 0: 1016019Shines@cs.fsu.edu print >>sys.stderr, "Child was terminated by signal", -retcode 1026019Shines@cs.fsu.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1036019Shines@cs.fsu.edu sys.exit(1) 1046019Shines@cs.fsu.edu elif retcode > 0: 1056019Shines@cs.fsu.edu print >>sys.stderr, "Child returned", retcode 1066019Shines@cs.fsu.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1076019Shines@cs.fsu.edu sys.exit(1) 1086019Shines@cs.fsu.edu except OSError, e: 1096019Shines@cs.fsu.edu print >>sys.stderr, "Execution failed:", e 1106019Shines@cs.fsu.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 1116019Shines@cs.fsu.edu sys.exit(1) 1126019Shines@cs.fsu.edu 1136019Shines@cs.fsu.edutargets = [] 1146019Shines@cs.fsu.edu 1156019Shines@cs.fsu.edu# start with compile-only targets, if any 1166019Shines@cs.fsu.eduif compile_variants: 1176019Shines@cs.fsu.edu targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant) 1186019Shines@cs.fsu.edu for variant in compile_variants 1196019Shines@cs.fsu.edu for build in builds] 1206019Shines@cs.fsu.edu 1216019Shines@cs.fsu.edu# By default run the 'quick' tests, all expands to quick and long 1226019Shines@cs.fsu.eduif not tests: 1236019Shines@cs.fsu.edu tests = ['quick'] 1246019Shines@cs.fsu.eduelif 'all' in tests: 1256019Shines@cs.fsu.edu tests = ['quick', 'long'] 1266019Shines@cs.fsu.edu 1276019Shines@cs.fsu.edu# set up test targets for scons, since we don't have any quick SPARC 1286019Shines@cs.fsu.edu# full-system tests exclude it 129targets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test, 130 mode) 131 for build in builds 132 for variant in test_variants 133 for test in tests 134 for mode in modes 135 if not (build == 'SPARC' and test == 'quick' and mode == 'fs')] 136 137def cpu_count(): 138 if 'bsd' in sys.platform or sys.platform == 'darwin': 139 try: 140 return int(os.popen('sysctl -n hw.ncpu').read()) 141 except ValueError: 142 pass 143 else: 144 try: 145 return os.sysconf('SC_NPROCESSORS_ONLN') 146 except (ValueError, OSError, AttributeError): 147 pass 148 149 raise NotImplementedError('cannot determine number of cpus') 150 151scons_opts = options.scons_opts 152if options.jobs != 1: 153 if options.jobs == 0: 154 options.jobs = cpu_count() 155 scons_opts += ' -j %d' % options.jobs 156if options.keep_going: 157 scons_opts += ' -k' 158if options.update_ref: 159 scons_opts += ' --update-ref' 160 161# We generally compile gem5.fast only to make sure it compiles OK; 162# it's not very useful to run as a regression test since assertions 163# are disabled. Thus there's not much point spending time on 164# link-time optimization. 165scons_opts += ' --no-lto' 166 167cmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets)) 168if options.no_exec: 169 print cmd 170else: 171 system(cmd) 172 sys.exit(0) 173