regress revision 7047
11897Sstever@eecs.umich.edu#! /usr/bin/env python
24130Ssaidi@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
344961Ssaidi@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()
397047Snate@binkert.orgadd_option = optparser.add_option
407047Snate@binkert.orgadd_option('-v', '--verbose', dest='verbose', action='store_true',
417047Snate@binkert.org           default=False,
427047Snate@binkert.org           help='echo commands before executing')
437047Snate@binkert.orgadd_option('--builds', dest='builds',
447047Snate@binkert.org           default='ALPHA_SE,ALPHA_SE_MOESI_hammer,' \
457047Snate@binkert.org           'ALPHA_SE_MESI_CMP_directory,'  \
467047Snate@binkert.org           'ALPHA_SE_MOESI_CMP_directory,' \
477047Snate@binkert.org           'ALPHA_SE_MOESI_CMP_token,' \
487047Snate@binkert.org           'ALPHA_FS,MIPS_SE,POWER_SE,SPARC_SE,SPARC_FS,X86_SE,ARM_SE',
497047Snate@binkert.org           help="comma-separated build targets to test (default: '%default')")
507047Snate@binkert.orgadd_option('--variants', dest='variants', default='fast',
517047Snate@binkert.org           help="comma-separated build variants to test (default: '%default')")
527047Snate@binkert.orgadd_option('--scons-opts', dest='scons_opts', default='', metavar='OPTS',
537047Snate@binkert.org           help='scons options')
547047Snate@binkert.orgadd_option('-j', '--jobs', type='int', default=1,
557047Snate@binkert.org           help='number of parallel jobs to use')
567047Snate@binkert.orgadd_option('-k', '--keep-going', action='store_true',
577047Snate@binkert.org           help='keep going after errors')
587047Snate@binkert.orgadd_option('-D', '--build-dir', default='',
597047Snate@binkert.org           help='build directory location')
607047Snate@binkert.orgadd_option('-n', "--no-exec", default=False, action='store_true',
617047Snate@binkert.org           help="don't actually invoke scons, just echo SCons command line")
621897Sstever@eecs.umich.edu
631897Sstever@eecs.umich.edu(options, tests) = optparser.parse_args()
641897Sstever@eecs.umich.edu
651897Sstever@eecs.umich.edu
661897Sstever@eecs.umich.edu# split list options on ',' to get Python lists
671897Sstever@eecs.umich.edubuilds = options.builds.split(',')
681897Sstever@eecs.umich.eduvariants = options.variants.split(',')
691897Sstever@eecs.umich.edu
707047Snate@binkert.orgoptions.build_dir = os.path.join(options.build_dir, 'build')
717047Snate@binkert.org
721897Sstever@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero
731897Sstever@eecs.umich.edudef system(cmd):
744961Ssaidi@eecs.umich.edu    try:
754961Ssaidi@eecs.umich.edu        retcode = call(cmd, shell=True)
764961Ssaidi@eecs.umich.edu        if retcode < 0:
774961Ssaidi@eecs.umich.edu            print >>sys.stderr, "Child was terminated by signal", -retcode
784961Ssaidi@eecs.umich.edu            print >>sys.stderr, "When attemping to execute: %s" % cmd
794961Ssaidi@eecs.umich.edu            sys.exit(1)
804961Ssaidi@eecs.umich.edu        elif retcode > 0:
814961Ssaidi@eecs.umich.edu            print >>sys.stderr, "Child returned", retcode
824961Ssaidi@eecs.umich.edu            print >>sys.stderr, "When attemping to execute: %s" % cmd
834961Ssaidi@eecs.umich.edu            sys.exit(1)
844961Ssaidi@eecs.umich.edu    except OSError, e:
854961Ssaidi@eecs.umich.edu        print >>sys.stderr, "Execution failed:", e
864961Ssaidi@eecs.umich.edu        print >>sys.stderr, "When attemping to execute: %s" % cmd
874961Ssaidi@eecs.umich.edu        sys.exit(1)
881897Sstever@eecs.umich.edu
891897Sstever@eecs.umich.edu# Quote string s so it can be passed as a shell arg
901897Sstever@eecs.umich.edudef shellquote(s):
911897Sstever@eecs.umich.edu    if ' ' in s:
921897Sstever@eecs.umich.edu        s = "'%s'" % s
931897Sstever@eecs.umich.edu    return s
941897Sstever@eecs.umich.edu
954961Ssaidi@eecs.umich.eduif not tests:
964961Ssaidi@eecs.umich.edu    print "No tests specified, just building binaries."
977047Snate@binkert.org    targets = ['%s/%s/m5.%s' % (options.build_dir, build, variant)
984961Ssaidi@eecs.umich.edu               for build in builds
994961Ssaidi@eecs.umich.edu               for variant in variants]
1004961Ssaidi@eecs.umich.eduelif 'all' in tests:
1017047Snate@binkert.org    targets = ['%s/%s/tests/%s' % (options.build_dir, build, variant)
1024961Ssaidi@eecs.umich.edu               for build in builds
1034961Ssaidi@eecs.umich.edu               for variant in variants]
1044961Ssaidi@eecs.umich.eduelse:
1054961Ssaidi@eecs.umich.edu    # Ugly! Since we don't have any quick SPARC_FS tests remove the SPARC_FS target
1064961Ssaidi@eecs.umich.edu    # If we ever get a quick SPARC_FS test, this code should be removed
1074961Ssaidi@eecs.umich.edu    if 'quick' in tests and 'SPARC_FS' in builds:
1084961Ssaidi@eecs.umich.edu        builds.remove('SPARC_FS')
1097047Snate@binkert.org    targets = ['%s/%s/tests/%s/%s' % (options.build_dir, build, variant, test)
1104961Ssaidi@eecs.umich.edu               for build in builds
1114961Ssaidi@eecs.umich.edu               for variant in variants
1124961Ssaidi@eecs.umich.edu               for test in tests]
1131897Sstever@eecs.umich.edu
1147047Snate@binkert.orgdef cpu_count():
1157047Snate@binkert.org    if 'bsd' in sys.platform or sys.platform == 'darwin':
1167047Snate@binkert.org        try:
1177047Snate@binkert.org            return int(os.popen('sysctl -n hw.ncpu').read())
1187047Snate@binkert.org        except ValueError:
1197047Snate@binkert.org            pass
1207047Snate@binkert.org    else:
1217047Snate@binkert.org        try:
1227047Snate@binkert.org            return os.sysconf('SC_NPROCESSORS_ONLN')
1237047Snate@binkert.org        except (ValueError, OSError, AttributeError):
1247047Snate@binkert.org            pass
1257047Snate@binkert.org
1267047Snate@binkert.org    raise NotImplementedError('cannot determine number of cpus')
1277047Snate@binkert.org
1284961Ssaidi@eecs.umich.eduscons_opts = options.scons_opts
1294961Ssaidi@eecs.umich.eduif options.jobs != 1:
1307047Snate@binkert.org    if options.jobs == 0:
1317047Snate@binkert.org        options.jobs = cpu_count()
1324961Ssaidi@eecs.umich.edu    scons_opts += ' -j %d' % options.jobs
1335247Sstever@gmail.comif options.keep_going:
1345247Sstever@gmail.com    scons_opts += ' -k'
1353725Sstever@eecs.umich.edu
1367047Snate@binkert.orgcmd = 'scons IGNORE_STYLE=True %s %s' % (scons_opts, ' '.join(targets))
1377047Snate@binkert.orgif options.no_exec:
1387047Snate@binkert.org    print cmd
1397047Snate@binkert.orgelse:
1407047Snate@binkert.org    system(cmd)
1417047Snate@binkert.org    sys.exit(0)
142