regress revision 8319
12SN/A#! /usr/bin/env python 21762SN/A# Copyright (c) 2005-2007 The Regents of The University of Michigan 32SN/A# All rights reserved. 42SN/A# 52SN/A# Redistribution and use in source and binary forms, with or without 62SN/A# modification, are permitted provided that the following conditions are 72SN/A# met: redistributions of source code must retain the above copyright 82SN/A# notice, this list of conditions and the following disclaimer; 92SN/A# redistributions in binary form must reproduce the above copyright 102SN/A# notice, this list of conditions and the following disclaimer in the 112SN/A# documentation and/or other materials provided with the distribution; 122SN/A# neither the name of the copyright holders nor the names of its 132SN/A# contributors may be used to endorse or promote products derived from 142SN/A# this software without specific prior written permission. 152SN/A# 162SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu# 282665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu 302SN/Aimport sys 312SN/Aimport os 32360SN/Aimport optparse 33360SN/Aimport datetime 342SN/Afrom subprocess import call 352SN/A 362SN/Aprogname = os.path.basename(sys.argv[0]) 372SN/A 382SN/Aoptparser = optparse.OptionParser() 392SN/Aadd_option = optparser.add_option 401858SN/Aadd_option('-v', '--verbose', action='store_true', default=False, 411858SN/A help='echo commands before executing') 421858SN/Aadd_option('--builds', 432SN/A default='ALPHA_SE,ALPHA_SE_MOESI_hammer,' \ 444117Sgblack@eecs.umich.edu 'ALPHA_SE_MESI_CMP_directory,' \ 45180SN/A 'ALPHA_SE_MOESI_CMP_directory,' \ 462SN/A 'ALPHA_SE_MOESI_CMP_token,' \ 475958Sgblack@eecs.umich.edu 'ALPHA_FS,' \ 482378SN/A 'MIPS_SE,' \ 496214Snate@binkert.org 'POWER_SE,' \ 5056SN/A 'SPARC_SE,SPARC_FS,' \ 515958Sgblack@eecs.umich.edu 'X86_SE,X86_FS,' \ 522SN/A 'ARM_SE,ARM_FS', 535154Sgblack@eecs.umich.edu help="comma-separated build targets to test (default: '%default')") 545154Sgblack@eecs.umich.eduadd_option('--test-variants', default='opt', 555154Sgblack@eecs.umich.edu help="comma-separated build variants to test (default: '%default')"\ 565154Sgblack@eecs.umich.edu ", set to '' for none") 575154Sgblack@eecs.umich.eduadd_option('--compile-variants', default='debug,fast', 585154Sgblack@eecs.umich.edu help="comma-separated build variants to compile only (not test) " \ 592680Sktlim@umich.edu "(default: '%default'), set to '' for none", metavar='VARIANTS') 602401SN/Aadd_option('--scons-opts', default='', metavar='OPTS', 613971Sgblack@eecs.umich.edu help='scons options') 623971Sgblack@eecs.umich.eduadd_option('-j', '--jobs', type='int', default=1, metavar='N', 633971Sgblack@eecs.umich.edu help='number of parallel jobs to use (0 to use all cores)') 643971Sgblack@eecs.umich.eduadd_option('-k', '--keep-going', action='store_true', 652378SN/A help='keep going after errors') 665758Shsul@eecs.umich.eduadd_option('--update-ref', action='store_true', 675771Shsul@eecs.umich.edu help='update reference outputs') 685758Shsul@eecs.umich.eduadd_option('-D', '--build-dir', default='', metavar='DIR', 695758Shsul@eecs.umich.edu help='build directory location') 705771Shsul@eecs.umich.eduadd_option('-n', "--no-exec", default=False, action='store_true', 715758Shsul@eecs.umich.edu help="don't actually invoke scons, just echo SCons command line") 725771Shsul@eecs.umich.edu 735758Shsul@eecs.umich.edu(options, tests) = optparser.parse_args() 745758Shsul@eecs.umich.edu 755771Shsul@eecs.umich.edu 765758Shsul@eecs.umich.edu# split a comma-separated list, but return an empty list if given the 775758Shsul@eecs.umich.edu# empty string 782SN/Adef split_if_nonempty(s): 792SN/A if not s: 802SN/A return [] 812SN/A return s.split(',') 822378SN/A 832378SN/A# split list options on ',' to get Python lists 842378SN/Abuilds = split_if_nonempty(options.builds) 852378SN/Atest_variants = split_if_nonempty(options.test_variants) 862680Sktlim@umich.educompile_variants = split_if_nonempty(options.compile_variants) 872SN/A 882SN/Aoptions.build_dir = os.path.join(options.build_dir, 'build') 892SN/A 902SN/A# Call os.system() and raise exception if return status is non-zero 915183Ssaidi@eecs.umich.edudef system(cmd): 925183Ssaidi@eecs.umich.edu try: 932680Sktlim@umich.edu retcode = call(cmd, shell=True) 945713Shsul@eecs.umich.edu if retcode < 0: 95180SN/A print >>sys.stderr, "Child was terminated by signal", -retcode 963971Sgblack@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 973971Sgblack@eecs.umich.edu sys.exit(1) 983971Sgblack@eecs.umich.edu elif retcode > 0: 993971Sgblack@eecs.umich.edu print >>sys.stderr, "Child returned", retcode 1003971Sgblack@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 101180SN/A sys.exit(1) 1025713Shsul@eecs.umich.edu except OSError, e: 1032SN/A print >>sys.stderr, "Execution failed:", e 1042SN/A print >>sys.stderr, "When attemping to execute: %s" % cmd 1052SN/A sys.exit(1) 1062SN/A 1072SN/Atargets = [] 1082680Sktlim@umich.edu 1092SN/A# start with compile-only targets, if any 1102680Sktlim@umich.eduif compile_variants: 1112SN/A targets += ['%s/%s/m5.%s' % (options.build_dir, build, variant) 1125543Ssaidi@eecs.umich.edu for variant in compile_variants 1132SN/A for build in builds] 1142SN/A 1152SN/A# By default run the 'quick' tests 1162SN/Aif not tests: 1172SN/A tests = ['quick'] 1185543Ssaidi@eecs.umich.edu 1192SN/A# set up test targets for scons 1205543Ssaidi@eecs.umich.eduif 'all' in tests: 1215543Ssaidi@eecs.umich.edu targets += ['%s/%s/tests/%s' % (options.build_dir, build, variant) 1225543Ssaidi@eecs.umich.edu for build in builds 1232SN/A for variant in test_variants] 1245154Sgblack@eecs.umich.eduelse: 1255154Sgblack@eecs.umich.edu # Ugly! Since we don't have any quick SPARC_FS tests remove the 1265154Sgblack@eecs.umich.edu # SPARC_FS target If we ever get a quick SPARC_FS test, this code 1272SN/A # should be removed 1282SN/A if 'quick' in tests and 'SPARC_FS' in builds: 1292SN/A builds.remove('SPARC_FS') 130360SN/A targets += ['%s/%s/tests/%s/%s' % (options.build_dir, build, variant, test) 1311408SN/A for build in builds 1321408SN/A for variant in test_variants 133360SN/A for test in tests] 1341514SN/A 1351514SN/Adef cpu_count(): 1361514SN/A if 'bsd' in sys.platform or sys.platform == 'darwin': 1371514SN/A try: 1385543Ssaidi@eecs.umich.edu return int(os.popen('sysctl -n hw.ncpu').read()) 1392SN/A except ValueError: 1405999Snate@binkert.org pass 1412SN/A else: 1422SN/A try: 1432SN/A return os.sysconf('SC_NPROCESSORS_ONLN') 1442SN/A except (ValueError, OSError, AttributeError): 1455154Sgblack@eecs.umich.edu pass 1462SN/A 1471395SN/A raise NotImplementedError('cannot determine number of cpus') 1481395SN/A 1492SN/Ascons_opts = options.scons_opts 1502SN/Aif options.jobs != 1: 1512378SN/A if options.jobs == 0: 1522401SN/A options.jobs = cpu_count() 1532378SN/A scons_opts += ' -j %d' % options.jobs 1542378SN/Aif options.keep_going: 1552378SN/A scons_opts += ' -k' 1562SN/Aif options.update_ref: 1574997Sgblack@eecs.umich.edu scons_opts += ' --update-ref' 1584997Sgblack@eecs.umich.edu 1594997Sgblack@eecs.umich.educmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets)) 1604997Sgblack@eecs.umich.eduif options.no_exec: 1615282Srstrong@cs.ucsd.edu print cmd 1625282Srstrong@cs.ucsd.eduelse: 1635282Srstrong@cs.ucsd.edu system(cmd) 1645282Srstrong@cs.ucsd.edu sys.exit(0) 1655282Srstrong@cs.ucsd.edu