regress revision 11308
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
302665Ssaidi@eecs.umich.eduimport sys
312SN/Aimport os
322SN/Aimport optparse
3310474Sandreas.hansson@arm.comimport datetime
342SN/Afrom subprocess import call
352SN/A
362SN/Aprogname = os.path.basename(sys.argv[0])
378229Snate@binkert.org
382984Sgblack@eecs.umich.eduoptparser = optparse.OptionParser()
392171SN/Aadd_option = optparser.add_option
408591Sgblack@eecs.umich.eduadd_option('-v', '--verbose', action='store_true', default=False,
41146SN/A           help='echo commands before executing')
42146SN/Aadd_option('--builds',
43146SN/A           default='ALPHA,ALPHA_MOESI_hammer,' \
442680Sktlim@umich.edu           'ALPHA_MESI_Two_Level,'  \
458232Snate@binkert.org           'ALPHA_MOESI_CMP_directory,' \
468738Sgblack@eecs.umich.edu           'ALPHA_MOESI_CMP_token,' \
472SN/A           'MIPS,' \
482SN/A           'NULL,' \
492SN/A           'POWER,' \
504088Sbinkertn@umich.edu           'SPARC,' \
515569Snate@binkert.org           'X86,X86_MESI_Two_Level,' \
523838Shsul@eecs.umich.edu           'ARM,' \
533838Shsul@eecs.umich.edu           'HSAIL_X86',
543838Shsul@eecs.umich.edu           help="comma-separated build targets to test (default: '%default')")
553838Shsul@eecs.umich.eduadd_option('--modes',
565569Snate@binkert.org           default='se,fs',
57860SN/A           help="comma-separated modes to test (default: '%default')")
583838Shsul@eecs.umich.eduadd_option('--test-variants', default='opt',
593838Shsul@eecs.umich.edu           help="comma-separated build variants to test (default: '%default')"\
60860SN/A           ", set to '' for none")
61860SN/Aadd_option('--compile-variants', default='debug,fast',
625569Snate@binkert.org           help="comma-separated build variants to compile only (not test) " \
631147SN/A           "(default: '%default'), set to '' for none", metavar='VARIANTS')
645034Smilesck@eecs.umich.eduadd_option('--scons-opts', default='', metavar='OPTS',
655358Sgblack@eecs.umich.edu           help='scons options')
663838Shsul@eecs.umich.eduadd_option('-j', '--jobs', type='int', default=1, metavar='N',
675004Sgblack@eecs.umich.edu           help='number of parallel jobs to use (0 to use all cores)')
688737Skoansin.tan@gmail.comadd_option('-k', '--keep-going', action='store_true',
694957Sacolyte@umich.edu           help='keep going after errors')
703838Shsul@eecs.umich.eduadd_option('--update-ref', action='store_true',
712SN/A           help='update reference outputs')
723838Shsul@eecs.umich.eduadd_option('-D', '--build-dir', default='', metavar='DIR',
733838Shsul@eecs.umich.edu           help='build directory location')
743838Shsul@eecs.umich.eduadd_option('-n', "--no-exec", default=False, action='store_true',
753838Shsul@eecs.umich.edu           help="don't actually invoke scons, just echo SCons command line")
763838Shsul@eecs.umich.edu
772SN/A(options, tests) = optparser.parse_args()
786022Sgblack@eecs.umich.edu
796022Sgblack@eecs.umich.edu
806022Sgblack@eecs.umich.edu# split a comma-separated list, but return an empty list if given the
816022Sgblack@eecs.umich.edu# empty string
826022Sgblack@eecs.umich.edudef split_if_nonempty(s):
836022Sgblack@eecs.umich.edu    if not s:
846022Sgblack@eecs.umich.edu        return []
856022Sgblack@eecs.umich.edu    return s.split(',')
866022Sgblack@eecs.umich.edu
876022Sgblack@eecs.umich.edu# split list options on ',' to get Python lists
886022Sgblack@eecs.umich.edubuilds = split_if_nonempty(options.builds)
896022Sgblack@eecs.umich.edumodes = split_if_nonempty(options.modes)
906022Sgblack@eecs.umich.edutest_variants = split_if_nonempty(options.test_variants)
916022Sgblack@eecs.umich.educompile_variants = split_if_nonempty(options.compile_variants)
926022Sgblack@eecs.umich.edu
936022Sgblack@eecs.umich.eduoptions.build_dir = os.path.join(options.build_dir, 'build')
946022Sgblack@eecs.umich.edu
956022Sgblack@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero
966022Sgblack@eecs.umich.edudef system(cmd):
976022Sgblack@eecs.umich.edu    try:
986022Sgblack@eecs.umich.edu        retcode = call(cmd, shell=True)
996022Sgblack@eecs.umich.edu        if retcode < 0:
1006022Sgblack@eecs.umich.edu            print >>sys.stderr, "Child was terminated by signal", -retcode
1016022Sgblack@eecs.umich.edu            print >>sys.stderr, "When attemping to execute: %s" % cmd
1026022Sgblack@eecs.umich.edu            sys.exit(1)
1036022Sgblack@eecs.umich.edu        elif retcode > 0:
1046022Sgblack@eecs.umich.edu            print >>sys.stderr, "Child returned", retcode
1056022Sgblack@eecs.umich.edu            print >>sys.stderr, "When attemping to execute: %s" % cmd
1066022Sgblack@eecs.umich.edu            sys.exit(1)
1076022Sgblack@eecs.umich.edu    except OSError, e:
1086022Sgblack@eecs.umich.edu        print >>sys.stderr, "Execution failed:", e
1096022Sgblack@eecs.umich.edu        print >>sys.stderr, "When attemping to execute: %s" % cmd
1106022Sgblack@eecs.umich.edu        sys.exit(1)
1116022Sgblack@eecs.umich.edu
1126022Sgblack@eecs.umich.edutargets = []
1136022Sgblack@eecs.umich.edu
1146022Sgblack@eecs.umich.edu# start with compile-only targets, if any
1156022Sgblack@eecs.umich.eduif compile_variants:
1166022Sgblack@eecs.umich.edu    targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant)
1176022Sgblack@eecs.umich.edu                for variant in compile_variants
1186022Sgblack@eecs.umich.edu                for build in builds]
1196022Sgblack@eecs.umich.edu
1206022Sgblack@eecs.umich.edu# By default run the 'quick' tests, all expands to quick and long
1216022Sgblack@eecs.umich.eduif not tests:
1226022Sgblack@eecs.umich.edu    tests = ['quick']
1236022Sgblack@eecs.umich.eduelif 'all' in tests:
1246022Sgblack@eecs.umich.edu    tests = ['quick', 'long']
1256022Sgblack@eecs.umich.edu
1266022Sgblack@eecs.umich.edu# set up test targets for scons, since we don't have any quick SPARC
1276022Sgblack@eecs.umich.edu# full-system tests exclude it
1286022Sgblack@eecs.umich.edutargets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test,
1296022Sgblack@eecs.umich.edu                                      mode)
1306022Sgblack@eecs.umich.edu            for build in builds
1316022Sgblack@eecs.umich.edu            for variant in test_variants
1326022Sgblack@eecs.umich.edu            for test in tests
1336022Sgblack@eecs.umich.edu            for mode in modes
1346022Sgblack@eecs.umich.edu            if not (build == 'SPARC' and test == 'quick' and mode == 'fs')]
1356022Sgblack@eecs.umich.edu
1366022Sgblack@eecs.umich.edudef cpu_count():
1376022Sgblack@eecs.umich.edu    if 'bsd' in sys.platform or sys.platform == 'darwin':
1386022Sgblack@eecs.umich.edu        try:
1396022Sgblack@eecs.umich.edu            return int(os.popen('sysctl -n hw.ncpu').read())
1406022Sgblack@eecs.umich.edu        except ValueError:
1416022Sgblack@eecs.umich.edu            pass
1426022Sgblack@eecs.umich.edu    else:
1436022Sgblack@eecs.umich.edu        try:
1446022Sgblack@eecs.umich.edu            return os.sysconf('SC_NPROCESSORS_ONLN')
1456022Sgblack@eecs.umich.edu        except (ValueError, OSError, AttributeError):
1466022Sgblack@eecs.umich.edu            pass
1476022Sgblack@eecs.umich.edu
1486022Sgblack@eecs.umich.edu    raise NotImplementedError('cannot determine number of cpus')
1496022Sgblack@eecs.umich.edu
1506022Sgblack@eecs.umich.eduscons_opts = options.scons_opts
1516022Sgblack@eecs.umich.eduif options.jobs != 1:
1526022Sgblack@eecs.umich.edu    if options.jobs == 0:
1536022Sgblack@eecs.umich.edu        options.jobs = cpu_count()
1546022Sgblack@eecs.umich.edu    scons_opts += ' -j %d' % options.jobs
1556022Sgblack@eecs.umich.eduif options.keep_going:
1566022Sgblack@eecs.umich.edu    scons_opts += ' -k'
1576022Sgblack@eecs.umich.eduif options.update_ref:
1586022Sgblack@eecs.umich.edu    scons_opts += ' --update-ref'
1596022Sgblack@eecs.umich.edu
1606022Sgblack@eecs.umich.edu# We generally compile gem5.fast only to make sure it compiles OK;
1616022Sgblack@eecs.umich.edu# it's not very useful to run as a regression test since assertions
1623838Shsul@eecs.umich.edu# are disabled.  Thus there's not much point spending time on
1635004Sgblack@eecs.umich.edu# link-time optimization.
1644967Sacolyte@umich.eduscons_opts += ' --no-lto'
1653838Shsul@eecs.umich.edu
1663838Shsul@eecs.umich.educmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets))
1675004Sgblack@eecs.umich.eduif options.no_exec:
1682SN/A    print cmd
1695004Sgblack@eecs.umich.eduelse:
1705004Sgblack@eecs.umich.edu    system(cmd)
1715004Sgblack@eecs.umich.edu    sys.exit(0)
1725004Sgblack@eecs.umich.edu