113540Sandrea.mondelli@ucf.edu#! /usr/bin/env python2.7
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
408319Ssteve.reinhardt@amd.comadd_option('-v', '--verbose', action='store_true', default=False,
417047Snate@binkert.org           help='echo commands before executing')
428319Ssteve.reinhardt@amd.comadd_option('--builds',
4311706Sandreas.hansson@arm.com           default='ALPHA,' \
448811Sandreas.hansson@arm.com           'MIPS,' \
459850Sandreas.hansson@arm.com           'NULL,' \
4611706Sandreas.hansson@arm.com           'NULL_MOESI_hammer,' \
4711706Sandreas.hansson@arm.com           'NULL_MESI_Two_Level,'  \
4811706Sandreas.hansson@arm.com           'NULL_MOESI_CMP_directory,' \
4911706Sandreas.hansson@arm.com           'NULL_MOESI_CMP_token,' \
508811Sandreas.hansson@arm.com           'POWER,' \
518811Sandreas.hansson@arm.com           'SPARC,' \
5210007Snilay@cs.wisc.edu           'X86,X86_MESI_Two_Level,' \
5311308Santhony.gutierrez@amd.com           'ARM,' \
5411730Sar4jc@virginia.edu           'RISCV,' \
5511308Santhony.gutierrez@amd.com           'HSAIL_X86',
567047Snate@binkert.org           help="comma-separated build targets to test (default: '%default')")
578811Sandreas.hansson@arm.comadd_option('--modes',
588811Sandreas.hansson@arm.com           default='se,fs',
598811Sandreas.hansson@arm.com           help="comma-separated modes to test (default: '%default')")
608319Ssteve.reinhardt@amd.comadd_option('--test-variants', default='opt',
618319Ssteve.reinhardt@amd.com           help="comma-separated build variants to test (default: '%default')"\
628319Ssteve.reinhardt@amd.com           ", set to '' for none")
638319Ssteve.reinhardt@amd.comadd_option('--compile-variants', default='debug,fast',
648319Ssteve.reinhardt@amd.com           help="comma-separated build variants to compile only (not test) " \
658319Ssteve.reinhardt@amd.com           "(default: '%default'), set to '' for none", metavar='VARIANTS')
668319Ssteve.reinhardt@amd.comadd_option('--scons-opts', default='', metavar='OPTS',
677047Snate@binkert.org           help='scons options')
688319Ssteve.reinhardt@amd.comadd_option('-j', '--jobs', type='int', default=1, metavar='N',
698319Ssteve.reinhardt@amd.com           help='number of parallel jobs to use (0 to use all cores)')
707047Snate@binkert.orgadd_option('-k', '--keep-going', action='store_true',
717047Snate@binkert.org           help='keep going after errors')
728319Ssteve.reinhardt@amd.comadd_option('--update-ref', action='store_true',
738319Ssteve.reinhardt@amd.com           help='update reference outputs')
748319Ssteve.reinhardt@amd.comadd_option('-D', '--build-dir', default='', metavar='DIR',
757047Snate@binkert.org           help='build directory location')
767047Snate@binkert.orgadd_option('-n', "--no-exec", default=False, action='store_true',
777047Snate@binkert.org           help="don't actually invoke scons, just echo SCons command line")
781897Sstever@eecs.umich.edu
791897Sstever@eecs.umich.edu(options, tests) = optparser.parse_args()
801897Sstever@eecs.umich.edu
811897Sstever@eecs.umich.edu
828319Ssteve.reinhardt@amd.com# split a comma-separated list, but return an empty list if given the
838319Ssteve.reinhardt@amd.com# empty string
848319Ssteve.reinhardt@amd.comdef split_if_nonempty(s):
858319Ssteve.reinhardt@amd.com    if not s:
868319Ssteve.reinhardt@amd.com        return []
878319Ssteve.reinhardt@amd.com    return s.split(',')
888319Ssteve.reinhardt@amd.com
891897Sstever@eecs.umich.edu# split list options on ',' to get Python lists
908319Ssteve.reinhardt@amd.combuilds = split_if_nonempty(options.builds)
918811Sandreas.hansson@arm.commodes = split_if_nonempty(options.modes)
928319Ssteve.reinhardt@amd.comtest_variants = split_if_nonempty(options.test_variants)
938319Ssteve.reinhardt@amd.comcompile_variants = split_if_nonempty(options.compile_variants)
941897Sstever@eecs.umich.edu
957047Snate@binkert.orgoptions.build_dir = os.path.join(options.build_dir, 'build')
967047Snate@binkert.org
971897Sstever@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero
981897Sstever@eecs.umich.edudef system(cmd):
994961Ssaidi@eecs.umich.edu    try:
1004961Ssaidi@eecs.umich.edu        retcode = call(cmd, shell=True)
1014961Ssaidi@eecs.umich.edu        if retcode < 0:
1024961Ssaidi@eecs.umich.edu            print >>sys.stderr, "Child was terminated by signal", -retcode
1034961Ssaidi@eecs.umich.edu            print >>sys.stderr, "When attemping to execute: %s" % cmd
1044961Ssaidi@eecs.umich.edu            sys.exit(1)
1054961Ssaidi@eecs.umich.edu        elif retcode > 0:
1064961Ssaidi@eecs.umich.edu            print >>sys.stderr, "Child returned", retcode
1074961Ssaidi@eecs.umich.edu            print >>sys.stderr, "When attemping to execute: %s" % cmd
1084961Ssaidi@eecs.umich.edu            sys.exit(1)
1094961Ssaidi@eecs.umich.edu    except OSError, e:
1104961Ssaidi@eecs.umich.edu        print >>sys.stderr, "Execution failed:", e
1114961Ssaidi@eecs.umich.edu        print >>sys.stderr, "When attemping to execute: %s" % cmd
1124961Ssaidi@eecs.umich.edu        sys.exit(1)
1131897Sstever@eecs.umich.edu
1148319Ssteve.reinhardt@amd.comtargets = []
1151897Sstever@eecs.umich.edu
1168319Ssteve.reinhardt@amd.com# start with compile-only targets, if any
1178319Ssteve.reinhardt@amd.comif compile_variants:
1188816Sgblack@eecs.umich.edu    targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant)
1198319Ssteve.reinhardt@amd.com                for variant in compile_variants
1208319Ssteve.reinhardt@amd.com                for build in builds]
1218319Ssteve.reinhardt@amd.com
1228811Sandreas.hansson@arm.com# By default run the 'quick' tests, all expands to quick and long
1234961Ssaidi@eecs.umich.eduif not tests:
1248319Ssteve.reinhardt@amd.com    tests = ['quick']
1258811Sandreas.hansson@arm.comelif 'all' in tests:
1268814Sgblack@eecs.umich.edu    tests = ['quick', 'long']
1278319Ssteve.reinhardt@amd.com
1288811Sandreas.hansson@arm.com# set up test targets for scons, since we don't have any quick SPARC
1298811Sandreas.hansson@arm.com# full-system tests exclude it
1308811Sandreas.hansson@arm.comtargets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test,
1318811Sandreas.hansson@arm.com                                      mode)
1328811Sandreas.hansson@arm.com            for build in builds
1338811Sandreas.hansson@arm.com            for variant in test_variants
1348811Sandreas.hansson@arm.com            for test in tests
1358811Sandreas.hansson@arm.com            for mode in modes
1368811Sandreas.hansson@arm.com            if not (build == 'SPARC' and test == 'quick' and mode == 'fs')]
1371897Sstever@eecs.umich.edu
1387047Snate@binkert.orgdef cpu_count():
1397047Snate@binkert.org    if 'bsd' in sys.platform or sys.platform == 'darwin':
1407047Snate@binkert.org        try:
1417047Snate@binkert.org            return int(os.popen('sysctl -n hw.ncpu').read())
1427047Snate@binkert.org        except ValueError:
1437047Snate@binkert.org            pass
1447047Snate@binkert.org    else:
1457047Snate@binkert.org        try:
1467047Snate@binkert.org            return os.sysconf('SC_NPROCESSORS_ONLN')
1477047Snate@binkert.org        except (ValueError, OSError, AttributeError):
1487047Snate@binkert.org            pass
1497047Snate@binkert.org
1507047Snate@binkert.org    raise NotImplementedError('cannot determine number of cpus')
1517047Snate@binkert.org
1524961Ssaidi@eecs.umich.eduscons_opts = options.scons_opts
1534961Ssaidi@eecs.umich.eduif options.jobs != 1:
1547047Snate@binkert.org    if options.jobs == 0:
1557047Snate@binkert.org        options.jobs = cpu_count()
1564961Ssaidi@eecs.umich.edu    scons_opts += ' -j %d' % options.jobs
1575247Sstever@gmail.comif options.keep_going:
1585247Sstever@gmail.com    scons_opts += ' -k'
1598319Ssteve.reinhardt@amd.comif options.update_ref:
1608319Ssteve.reinhardt@amd.com    scons_opts += ' --update-ref'
1613725Sstever@eecs.umich.edu
1629843Ssteve.reinhardt@amd.com# We generally compile gem5.fast only to make sure it compiles OK;
1639843Ssteve.reinhardt@amd.com# it's not very useful to run as a regression test since assertions
1649843Ssteve.reinhardt@amd.com# are disabled.  Thus there's not much point spending time on
1659843Ssteve.reinhardt@amd.com# link-time optimization.
1669843Ssteve.reinhardt@amd.comscons_opts += ' --no-lto'
1679843Ssteve.reinhardt@amd.com
1688120Sgblack@eecs.umich.educmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets))
1697047Snate@binkert.orgif options.no_exec:
1707047Snate@binkert.org    print cmd
1717047Snate@binkert.orgelse:
1727047Snate@binkert.org    system(cmd)
1737047Snate@binkert.org    sys.exit(0)
174