regress revision 9843
16019SN/A#! /usr/bin/env python
26019SN/A# Copyright (c) 2005-2007 The Regents of The University of Michigan
37134Sgblack@eecs.umich.edu# All rights reserved.
47134Sgblack@eecs.umich.edu#
57134Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
67134Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
77134Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
87134Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
97134Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
107134Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
117134Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
127134Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
137134Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
147134Sgblack@eecs.umich.edu# this software without specific prior written permission.
156019SN/A#
166019SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176019SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186019SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196019SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206019SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216019SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226019SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236019SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246019SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256019SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266019SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276019SN/A#
286019SN/A# Authors: Steve Reinhardt
296019SN/A
306019SN/Aimport sys
316019SN/Aimport os
326019SN/Aimport optparse
336019SN/Aimport datetime
346019SN/Afrom subprocess import call
356019SN/A
366019SN/Aprogname = os.path.basename(sys.argv[0])
376019SN/A
386019SN/Aoptparser = optparse.OptionParser()
396019SN/Aadd_option = optparser.add_option
406019SN/Aadd_option('-v', '--verbose', action='store_true', default=False,
416019SN/A           help='echo commands before executing')
426308SN/Aadd_option('--builds',
436308SN/A           default='ALPHA,ALPHA_MOESI_hammer,' \
446309SN/A           'ALPHA_MESI_CMP_directory,'  \
456309SN/A           'ALPHA_MOESI_CMP_directory,' \
466309SN/A           'ALPHA_MOESI_CMP_token,' \
476309SN/A           'MIPS,' \
486309SN/A           'POWER,' \
497134Sgblack@eecs.umich.edu           'SPARC,' \
507296Sgblack@eecs.umich.edu           'X86,X86_MESI_CMP_directory,' \
516309SN/A           'ARM',
526309SN/A           help="comma-separated build targets to test (default: '%default')")
537296Sgblack@eecs.umich.eduadd_option('--modes',
548139SMatt.Horsnell@arm.com           default='se,fs',
556309SN/A           help="comma-separated modes to test (default: '%default')")
566309SN/Aadd_option('--test-variants', default='opt',
576309SN/A           help="comma-separated build variants to test (default: '%default')"\
587342Sgblack@eecs.umich.edu           ", set to '' for none")
597174Sgblack@eecs.umich.eduadd_option('--compile-variants', default='debug,fast',
607639Sgblack@eecs.umich.edu           help="comma-separated build variants to compile only (not test) " \
617639Sgblack@eecs.umich.edu           "(default: '%default'), set to '' for none", metavar='VARIANTS')
627644Sali.saidi@arm.comadd_option('--scons-opts', default='', metavar='OPTS',
638139SMatt.Horsnell@arm.com           help='scons options')
647639Sgblack@eecs.umich.eduadd_option('-j', '--jobs', type='int', default=1, metavar='N',
657639Sgblack@eecs.umich.edu           help='number of parallel jobs to use (0 to use all cores)')
667639Sgblack@eecs.umich.eduadd_option('-k', '--keep-going', action='store_true',
677639Sgblack@eecs.umich.edu           help='keep going after errors')
687639Sgblack@eecs.umich.eduadd_option('--update-ref', action='store_true',
697639Sgblack@eecs.umich.edu           help='update reference outputs')
707639Sgblack@eecs.umich.eduadd_option('-D', '--build-dir', default='', metavar='DIR',
717644Sali.saidi@arm.com           help='build directory location')
728139SMatt.Horsnell@arm.comadd_option('-n', "--no-exec", default=False, action='store_true',
737639Sgblack@eecs.umich.edu           help="don't actually invoke scons, just echo SCons command line")
747639Sgblack@eecs.umich.edu
757639Sgblack@eecs.umich.edu(options, tests) = optparser.parse_args()
767639Sgblack@eecs.umich.edu
777639Sgblack@eecs.umich.edu
787639Sgblack@eecs.umich.edu# split a comma-separated list, but return an empty list if given the
797639Sgblack@eecs.umich.edu# empty string
807639Sgblack@eecs.umich.edudef split_if_nonempty(s):
817639Sgblack@eecs.umich.edu    if not s:
827644Sali.saidi@arm.com        return []
838139SMatt.Horsnell@arm.com    return s.split(',')
847639Sgblack@eecs.umich.edu
857639Sgblack@eecs.umich.edu# split list options on ',' to get Python lists
867639Sgblack@eecs.umich.edubuilds = split_if_nonempty(options.builds)
877639Sgblack@eecs.umich.edumodes = split_if_nonempty(options.modes)
887174Sgblack@eecs.umich.edutest_variants = split_if_nonempty(options.test_variants)
896754SN/Acompile_variants = split_if_nonempty(options.compile_variants)
907296Sgblack@eecs.umich.edu
917400SAli.Saidi@ARM.comoptions.build_dir = os.path.join(options.build_dir, 'build')
927134Sgblack@eecs.umich.edu
937400SAli.Saidi@ARM.com# Call os.system() and raise exception if return status is non-zero
947134Sgblack@eecs.umich.edudef system(cmd):
957134Sgblack@eecs.umich.edu    try:
967797Sgblack@eecs.umich.edu        retcode = call(cmd, shell=True)
977858SMatt.Horsnell@arm.com        if retcode < 0:
987858SMatt.Horsnell@arm.com            print >>sys.stderr, "Child was terminated by signal", -retcode
996754SN/A            print >>sys.stderr, "When attemping to execute: %s" % cmd
1006754SN/A            sys.exit(1)
1016754SN/A        elif retcode > 0:
1026754SN/A            print >>sys.stderr, "Child returned", retcode
1036754SN/A            print >>sys.stderr, "When attemping to execute: %s" % cmd
1048139SMatt.Horsnell@arm.com            sys.exit(1)
1057422Sgblack@eecs.umich.edu    except OSError, e:
1067648SAli.Saidi@ARM.com        print >>sys.stderr, "Execution failed:", e
1076754SN/A        print >>sys.stderr, "When attemping to execute: %s" % cmd
1088139SMatt.Horsnell@arm.com        sys.exit(1)
1096309SN/A
1106309SN/Atargets = []
1117296Sgblack@eecs.umich.edu
1127303Sgblack@eecs.umich.edu# start with compile-only targets, if any
1138139SMatt.Horsnell@arm.comif compile_variants:
1146309SN/A    targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant)
1156309SN/A                for variant in compile_variants
1166309SN/A                for build in builds]
1177296Sgblack@eecs.umich.edu
1187174Sgblack@eecs.umich.edu# By default run the 'quick' tests, all expands to quick and long
1197174Sgblack@eecs.umich.eduif not tests:
1207296Sgblack@eecs.umich.edu    tests = ['quick']
1217303Sgblack@eecs.umich.eduelif 'all' in tests:
1227644Sali.saidi@arm.com    tests = ['quick', 'long']
1238139SMatt.Horsnell@arm.com
1247174Sgblack@eecs.umich.edu# set up test targets for scons, since we don't have any quick SPARC
1257174Sgblack@eecs.umich.edu# full-system tests exclude it
1267174Sgblack@eecs.umich.edutargets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test,
1277639Sgblack@eecs.umich.edu                                      mode)
1287639Sgblack@eecs.umich.edu            for build in builds
1297639Sgblack@eecs.umich.edu            for variant in test_variants
1307639Sgblack@eecs.umich.edu            for test in tests
1317639Sgblack@eecs.umich.edu            for mode in modes
1327644Sali.saidi@arm.com            if not (build == 'SPARC' and test == 'quick' and mode == 'fs')]
1338139SMatt.Horsnell@arm.com
1347639Sgblack@eecs.umich.edudef cpu_count():
1357639Sgblack@eecs.umich.edu    if 'bsd' in sys.platform or sys.platform == 'darwin':
1367639Sgblack@eecs.umich.edu        try:
1377639Sgblack@eecs.umich.edu            return int(os.popen('sysctl -n hw.ncpu').read())
1387639Sgblack@eecs.umich.edu        except ValueError:
1397639Sgblack@eecs.umich.edu            pass
1407639Sgblack@eecs.umich.edu    else:
1417639Sgblack@eecs.umich.edu        try:
1427639Sgblack@eecs.umich.edu            return os.sysconf('SC_NPROCESSORS_ONLN')
1437639Sgblack@eecs.umich.edu        except (ValueError, OSError, AttributeError):
1447644Sali.saidi@arm.com            pass
1458139SMatt.Horsnell@arm.com
1467639Sgblack@eecs.umich.edu    raise NotImplementedError('cannot determine number of cpus')
1477639Sgblack@eecs.umich.edu
1487639Sgblack@eecs.umich.eduscons_opts = options.scons_opts
1497639Sgblack@eecs.umich.eduif options.jobs != 1:
1507639Sgblack@eecs.umich.edu    if options.jobs == 0:
1517174Sgblack@eecs.umich.edu        options.jobs = cpu_count()
1527174Sgblack@eecs.umich.edu    scons_opts += ' -j %d' % options.jobs
1537639Sgblack@eecs.umich.eduif options.keep_going:
1547639Sgblack@eecs.umich.edu    scons_opts += ' -k'
1557639Sgblack@eecs.umich.eduif options.update_ref:
1567639Sgblack@eecs.umich.edu    scons_opts += ' --update-ref'
1577174Sgblack@eecs.umich.edu
1587174Sgblack@eecs.umich.edu# We generally compile gem5.fast only to make sure it compiles OK;
1597174Sgblack@eecs.umich.edu# it's not very useful to run as a regression test since assertions
1607174Sgblack@eecs.umich.edu# are disabled.  Thus there's not much point spending time on
1617174Sgblack@eecs.umich.edu# link-time optimization.
1627174Sgblack@eecs.umich.eduscons_opts += ' --no-lto'
1637174Sgblack@eecs.umich.edu
1647174Sgblack@eecs.umich.educmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets))
1657174Sgblack@eecs.umich.eduif options.no_exec:
1667174Sgblack@eecs.umich.edu    print cmd
1677174Sgblack@eecs.umich.eduelse:
1686309SN/A    system(cmd)
1696308SN/A    sys.exit(0)
1707639Sgblack@eecs.umich.edu