regress revision 8120
15081Sgblack@eecs.umich.edu#! /usr/bin/env python 25081Sgblack@eecs.umich.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan 35081Sgblack@eecs.umich.edu# All rights reserved. 45081Sgblack@eecs.umich.edu# 55081Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 65081Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 75081Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 85081Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 95081Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 105081Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 115081Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 125081Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 135081Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 145081Sgblack@eecs.umich.edu# this software without specific prior written permission. 155081Sgblack@eecs.umich.edu# 165081Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175081Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185081Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195081Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205081Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215081Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225081Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235081Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245081Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255081Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265081Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275081Sgblack@eecs.umich.edu# 285081Sgblack@eecs.umich.edu# Authors: Steve Reinhardt 295081Sgblack@eecs.umich.edu 305081Sgblack@eecs.umich.eduimport sys 315081Sgblack@eecs.umich.eduimport os 325081Sgblack@eecs.umich.eduimport optparse 335081Sgblack@eecs.umich.eduimport datetime 345081Sgblack@eecs.umich.edufrom subprocess import call 355081Sgblack@eecs.umich.edu 365081Sgblack@eecs.umich.eduprogname = os.path.basename(sys.argv[0]) 375081Sgblack@eecs.umich.edu 385081Sgblack@eecs.umich.eduoptparser = optparse.OptionParser() 395081Sgblack@eecs.umich.eduadd_option = optparser.add_option 405081Sgblack@eecs.umich.eduadd_option('-v', '--verbose', dest='verbose', action='store_true', 415081Sgblack@eecs.umich.edu default=False, 425081Sgblack@eecs.umich.edu help='echo commands before executing') 435081Sgblack@eecs.umich.eduadd_option('--builds', dest='builds', 445081Sgblack@eecs.umich.edu default='ALPHA_SE,ALPHA_SE_MOESI_hammer,' \ 455081Sgblack@eecs.umich.edu 'ALPHA_SE_MESI_CMP_directory,' \ 465081Sgblack@eecs.umich.edu 'ALPHA_SE_MOESI_CMP_directory,' \ 475081Sgblack@eecs.umich.edu 'ALPHA_SE_MOESI_CMP_token,' \ 485081Sgblack@eecs.umich.edu 'ALPHA_FS,MIPS_SE,POWER_SE,SPARC_SE,SPARC_FS,X86_SE,ARM_SE,ARM_FS', 495081Sgblack@eecs.umich.edu help="comma-separated build targets to test (default: '%default')") 505081Sgblack@eecs.umich.eduadd_option('--variants', dest='variants', default='fast', 515081Sgblack@eecs.umich.edu help="comma-separated build variants to test (default: '%default')") 525081Sgblack@eecs.umich.eduadd_option('--scons-opts', dest='scons_opts', default='', metavar='OPTS', 535081Sgblack@eecs.umich.edu help='scons options') 545081Sgblack@eecs.umich.eduadd_option('-j', '--jobs', type='int', default=1, 555081Sgblack@eecs.umich.edu help='number of parallel jobs to use') 565081Sgblack@eecs.umich.eduadd_option('-k', '--keep-going', action='store_true', 576584Sgblack@eecs.umich.edu help='keep going after errors') 586584Sgblack@eecs.umich.eduadd_option('-D', '--build-dir', default='', 596584Sgblack@eecs.umich.edu help='build directory location') 606584Sgblack@eecs.umich.eduadd_option('-n', "--no-exec", default=False, action='store_true', 616584Sgblack@eecs.umich.edu help="don't actually invoke scons, just echo SCons command line") 626584Sgblack@eecs.umich.edu 636584Sgblack@eecs.umich.edu(options, tests) = optparser.parse_args() 646584Sgblack@eecs.umich.edu 656584Sgblack@eecs.umich.edu 666584Sgblack@eecs.umich.edu# split list options on ',' to get Python lists 676584Sgblack@eecs.umich.edubuilds = options.builds.split(',') 686584Sgblack@eecs.umich.eduvariants = options.variants.split(',') 696584Sgblack@eecs.umich.edu 706584Sgblack@eecs.umich.eduoptions.build_dir = os.path.join(options.build_dir, 'build') 716584Sgblack@eecs.umich.edu 726584Sgblack@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero 736584Sgblack@eecs.umich.edudef system(cmd): 746584Sgblack@eecs.umich.edu try: 756584Sgblack@eecs.umich.edu retcode = call(cmd, shell=True) 766584Sgblack@eecs.umich.edu if retcode < 0: 776584Sgblack@eecs.umich.edu print >>sys.stderr, "Child was terminated by signal", -retcode 786584Sgblack@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 796584Sgblack@eecs.umich.edu sys.exit(1) 806584Sgblack@eecs.umich.edu elif retcode > 0: 816584Sgblack@eecs.umich.edu print >>sys.stderr, "Child returned", retcode 826584Sgblack@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 836584Sgblack@eecs.umich.edu sys.exit(1) 846584Sgblack@eecs.umich.edu except OSError, e: 856584Sgblack@eecs.umich.edu print >>sys.stderr, "Execution failed:", e 866584Sgblack@eecs.umich.edu print >>sys.stderr, "When attemping to execute: %s" % cmd 876584Sgblack@eecs.umich.edu sys.exit(1) 886584Sgblack@eecs.umich.edu 896584Sgblack@eecs.umich.edu# Quote string s so it can be passed as a shell arg 906584Sgblack@eecs.umich.edudef shellquote(s): 916584Sgblack@eecs.umich.edu if ' ' in s: 926584Sgblack@eecs.umich.edu s = "'%s'" % s 936584Sgblack@eecs.umich.edu return s 946584Sgblack@eecs.umich.edu 956584Sgblack@eecs.umich.eduif not tests: 966584Sgblack@eecs.umich.edu print "No tests specified, just building binaries." 976584Sgblack@eecs.umich.edu targets = ['%s/%s/m5.%s' % (options.build_dir, build, variant) 986584Sgblack@eecs.umich.edu for build in builds 996584Sgblack@eecs.umich.edu for variant in variants] 1006584Sgblack@eecs.umich.eduelif 'all' in tests: 1016584Sgblack@eecs.umich.edu targets = ['%s/%s/tests/%s' % (options.build_dir, build, variant) 1026584Sgblack@eecs.umich.edu for build in builds 1036584Sgblack@eecs.umich.edu for variant in variants] 1046584Sgblack@eecs.umich.eduelse: 1056584Sgblack@eecs.umich.edu # Ugly! Since we don't have any quick SPARC_FS tests remove the SPARC_FS target 1066584Sgblack@eecs.umich.edu # If we ever get a quick SPARC_FS test, this code should be removed 1076584Sgblack@eecs.umich.edu if 'quick' in tests and 'SPARC_FS' in builds: 1086584Sgblack@eecs.umich.edu builds.remove('SPARC_FS') 1096584Sgblack@eecs.umich.edu targets = ['%s/%s/tests/%s/%s' % (options.build_dir, build, variant, test) 1106584Sgblack@eecs.umich.edu for build in builds 1116584Sgblack@eecs.umich.edu for variant in variants 1126584Sgblack@eecs.umich.edu for test in tests] 1136584Sgblack@eecs.umich.edu 1146584Sgblack@eecs.umich.edudef cpu_count(): 1156584Sgblack@eecs.umich.edu if 'bsd' in sys.platform or sys.platform == 'darwin': 1166584Sgblack@eecs.umich.edu try: 1176584Sgblack@eecs.umich.edu return int(os.popen('sysctl -n hw.ncpu').read()) 1186584Sgblack@eecs.umich.edu except ValueError: 1196584Sgblack@eecs.umich.edu pass 1206584Sgblack@eecs.umich.edu else: 1216584Sgblack@eecs.umich.edu try: 1226584Sgblack@eecs.umich.edu return os.sysconf('SC_NPROCESSORS_ONLN') 1236584Sgblack@eecs.umich.edu except (ValueError, OSError, AttributeError): 1246584Sgblack@eecs.umich.edu pass 1256584Sgblack@eecs.umich.edu 1265081Sgblack@eecs.umich.edu raise NotImplementedError('cannot determine number of cpus') 127 128scons_opts = options.scons_opts 129if options.jobs != 1: 130 if options.jobs == 0: 131 options.jobs = cpu_count() 132 scons_opts += ' -j %d' % options.jobs 133if options.keep_going: 134 scons_opts += ' -k' 135 136cmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets)) 137if options.no_exec: 138 print cmd 139else: 140 system(cmd) 141 sys.exit(0) 142