regress revision 9850
112027Sjungma@eit.uni-kl.de#! /usr/bin/env python
212027Sjungma@eit.uni-kl.de# Copyright (c) 2005-2007 The Regents of The University of Michigan
312027Sjungma@eit.uni-kl.de# All rights reserved.
412027Sjungma@eit.uni-kl.de#
512027Sjungma@eit.uni-kl.de# Redistribution and use in source and binary forms, with or without
612027Sjungma@eit.uni-kl.de# modification, are permitted provided that the following conditions are
712027Sjungma@eit.uni-kl.de# met: redistributions of source code must retain the above copyright
812027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer;
912027Sjungma@eit.uni-kl.de# redistributions in binary form must reproduce the above copyright
1012027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer in the
1112027Sjungma@eit.uni-kl.de# documentation and/or other materials provided with the distribution;
1212027Sjungma@eit.uni-kl.de# neither the name of the copyright holders nor the names of its
1312027Sjungma@eit.uni-kl.de# contributors may be used to endorse or promote products derived from
1412027Sjungma@eit.uni-kl.de# this software without specific prior written permission.
1512027Sjungma@eit.uni-kl.de#
1612027Sjungma@eit.uni-kl.de# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712027Sjungma@eit.uni-kl.de# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812027Sjungma@eit.uni-kl.de# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912027Sjungma@eit.uni-kl.de# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012027Sjungma@eit.uni-kl.de# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112027Sjungma@eit.uni-kl.de# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212027Sjungma@eit.uni-kl.de# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312027Sjungma@eit.uni-kl.de# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412027Sjungma@eit.uni-kl.de# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512027Sjungma@eit.uni-kl.de# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612027Sjungma@eit.uni-kl.de# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712027Sjungma@eit.uni-kl.de#
2812027Sjungma@eit.uni-kl.de# Authors: Steve Reinhardt
2912027Sjungma@eit.uni-kl.de
3012027Sjungma@eit.uni-kl.deimport sys
3112027Sjungma@eit.uni-kl.deimport os
3212027Sjungma@eit.uni-kl.deimport optparse
3312027Sjungma@eit.uni-kl.deimport datetime
3412027Sjungma@eit.uni-kl.defrom subprocess import call
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.deprogname = os.path.basename(sys.argv[0])
3712027Sjungma@eit.uni-kl.de
3812027Sjungma@eit.uni-kl.deoptparser = optparse.OptionParser()
3912027Sjungma@eit.uni-kl.deadd_option = optparser.add_option
4012027Sjungma@eit.uni-kl.deadd_option('-v', '--verbose', action='store_true', default=False,
4112027Sjungma@eit.uni-kl.de           help='echo commands before executing')
4212027Sjungma@eit.uni-kl.deadd_option('--builds',
4312027Sjungma@eit.uni-kl.de           default='ALPHA,ALPHA_MOESI_hammer,' \
4412027Sjungma@eit.uni-kl.de           'ALPHA_MESI_CMP_directory,'  \
4512027Sjungma@eit.uni-kl.de           'ALPHA_MOESI_CMP_directory,' \
4612027Sjungma@eit.uni-kl.de           'ALPHA_MOESI_CMP_token,' \
4712027Sjungma@eit.uni-kl.de           'MIPS,' \
4812027Sjungma@eit.uni-kl.de           'NULL,' \
4912027Sjungma@eit.uni-kl.de           'POWER,' \
5012027Sjungma@eit.uni-kl.de           'SPARC,' \
5112027Sjungma@eit.uni-kl.de           'X86,X86_MESI_CMP_directory,' \
5212027Sjungma@eit.uni-kl.de           'ARM',
5312027Sjungma@eit.uni-kl.de           help="comma-separated build targets to test (default: '%default')")
5412027Sjungma@eit.uni-kl.deadd_option('--modes',
5512027Sjungma@eit.uni-kl.de           default='se,fs',
5612027Sjungma@eit.uni-kl.de           help="comma-separated modes to test (default: '%default')")
5712027Sjungma@eit.uni-kl.deadd_option('--test-variants', default='opt',
5812027Sjungma@eit.uni-kl.de           help="comma-separated build variants to test (default: '%default')"\
5912027Sjungma@eit.uni-kl.de           ", set to '' for none")
6012027Sjungma@eit.uni-kl.deadd_option('--compile-variants', default='debug,fast',
6112027Sjungma@eit.uni-kl.de           help="comma-separated build variants to compile only (not test) " \
6212027Sjungma@eit.uni-kl.de           "(default: '%default'), set to '' for none", metavar='VARIANTS')
6312027Sjungma@eit.uni-kl.deadd_option('--scons-opts', default='', metavar='OPTS',
6412027Sjungma@eit.uni-kl.de           help='scons options')
6512027Sjungma@eit.uni-kl.deadd_option('-j', '--jobs', type='int', default=1, metavar='N',
6612027Sjungma@eit.uni-kl.de           help='number of parallel jobs to use (0 to use all cores)')
6712027Sjungma@eit.uni-kl.deadd_option('-k', '--keep-going', action='store_true',
6812027Sjungma@eit.uni-kl.de           help='keep going after errors')
6912027Sjungma@eit.uni-kl.deadd_option('--update-ref', action='store_true',
7012027Sjungma@eit.uni-kl.de           help='update reference outputs')
7112027Sjungma@eit.uni-kl.deadd_option('-D', '--build-dir', default='', metavar='DIR',
7212027Sjungma@eit.uni-kl.de           help='build directory location')
7312027Sjungma@eit.uni-kl.deadd_option('-n', "--no-exec", default=False, action='store_true',
7412027Sjungma@eit.uni-kl.de           help="don't actually invoke scons, just echo SCons command line")
7512027Sjungma@eit.uni-kl.de
7612027Sjungma@eit.uni-kl.de(options, tests) = optparser.parse_args()
7712027Sjungma@eit.uni-kl.de
7812027Sjungma@eit.uni-kl.de
7912027Sjungma@eit.uni-kl.de# split a comma-separated list, but return an empty list if given the
8012027Sjungma@eit.uni-kl.de# empty string
8112027Sjungma@eit.uni-kl.dedef split_if_nonempty(s):
8212027Sjungma@eit.uni-kl.de    if not s:
8312027Sjungma@eit.uni-kl.de        return []
8412027Sjungma@eit.uni-kl.de    return s.split(',')
8512027Sjungma@eit.uni-kl.de
8612027Sjungma@eit.uni-kl.de# split list options on ',' to get Python lists
8712027Sjungma@eit.uni-kl.debuilds = split_if_nonempty(options.builds)
8812027Sjungma@eit.uni-kl.demodes = split_if_nonempty(options.modes)
8912027Sjungma@eit.uni-kl.detest_variants = split_if_nonempty(options.test_variants)
9012027Sjungma@eit.uni-kl.decompile_variants = split_if_nonempty(options.compile_variants)
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.deoptions.build_dir = os.path.join(options.build_dir, 'build')
9312027Sjungma@eit.uni-kl.de
9412027Sjungma@eit.uni-kl.de# Call os.system() and raise exception if return status is non-zero
9512027Sjungma@eit.uni-kl.dedef system(cmd):
9612027Sjungma@eit.uni-kl.de    try:
9712027Sjungma@eit.uni-kl.de        retcode = call(cmd, shell=True)
9812027Sjungma@eit.uni-kl.de        if retcode < 0:
9912027Sjungma@eit.uni-kl.de            print >>sys.stderr, "Child was terminated by signal", -retcode
10012027Sjungma@eit.uni-kl.de            print >>sys.stderr, "When attemping to execute: %s" % cmd
10112027Sjungma@eit.uni-kl.de            sys.exit(1)
10212027Sjungma@eit.uni-kl.de        elif retcode > 0:
10312027Sjungma@eit.uni-kl.de            print >>sys.stderr, "Child returned", retcode
10412027Sjungma@eit.uni-kl.de            print >>sys.stderr, "When attemping to execute: %s" % cmd
10512027Sjungma@eit.uni-kl.de            sys.exit(1)
10612027Sjungma@eit.uni-kl.de    except OSError, e:
10712027Sjungma@eit.uni-kl.de        print >>sys.stderr, "Execution failed:", e
10812027Sjungma@eit.uni-kl.de        print >>sys.stderr, "When attemping to execute: %s" % cmd
10912027Sjungma@eit.uni-kl.de        sys.exit(1)
11012027Sjungma@eit.uni-kl.de
11112027Sjungma@eit.uni-kl.detargets = []
11212027Sjungma@eit.uni-kl.de
11312027Sjungma@eit.uni-kl.de# start with compile-only targets, if any
11412027Sjungma@eit.uni-kl.deif compile_variants:
11512027Sjungma@eit.uni-kl.de    targets += ['%s/%s/gem5.%s' % (options.build_dir, build, variant)
11612027Sjungma@eit.uni-kl.de                for variant in compile_variants
11712027Sjungma@eit.uni-kl.de                for build in builds]
11812027Sjungma@eit.uni-kl.de
11912027Sjungma@eit.uni-kl.de# By default run the 'quick' tests, all expands to quick and long
12012027Sjungma@eit.uni-kl.deif not tests:
12112027Sjungma@eit.uni-kl.de    tests = ['quick']
12212027Sjungma@eit.uni-kl.deelif 'all' in tests:
12312027Sjungma@eit.uni-kl.de    tests = ['quick', 'long']
12412027Sjungma@eit.uni-kl.de
12512027Sjungma@eit.uni-kl.de# set up test targets for scons, since we don't have any quick SPARC
12612027Sjungma@eit.uni-kl.de# full-system tests exclude it
12712027Sjungma@eit.uni-kl.detargets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test,
12812027Sjungma@eit.uni-kl.de                                      mode)
12912027Sjungma@eit.uni-kl.de            for build in builds
13012027Sjungma@eit.uni-kl.de            for variant in test_variants
13112027Sjungma@eit.uni-kl.de            for test in tests
13212027Sjungma@eit.uni-kl.de            for mode in modes
13312027Sjungma@eit.uni-kl.de            if not (build == 'SPARC' and test == 'quick' and mode == 'fs')]
13412027Sjungma@eit.uni-kl.de
13512027Sjungma@eit.uni-kl.dedef cpu_count():
13612027Sjungma@eit.uni-kl.de    if 'bsd' in sys.platform or sys.platform == 'darwin':
13712027Sjungma@eit.uni-kl.de        try:
13812027Sjungma@eit.uni-kl.de            return int(os.popen('sysctl -n hw.ncpu').read())
13912027Sjungma@eit.uni-kl.de        except ValueError:
14012027Sjungma@eit.uni-kl.de            pass
14112027Sjungma@eit.uni-kl.de    else:
14212027Sjungma@eit.uni-kl.de        try:
14312027Sjungma@eit.uni-kl.de            return os.sysconf('SC_NPROCESSORS_ONLN')
14412027Sjungma@eit.uni-kl.de        except (ValueError, OSError, AttributeError):
14512027Sjungma@eit.uni-kl.de            pass
14612027Sjungma@eit.uni-kl.de
14712027Sjungma@eit.uni-kl.de    raise NotImplementedError('cannot determine number of cpus')
14812027Sjungma@eit.uni-kl.de
14912027Sjungma@eit.uni-kl.descons_opts = options.scons_opts
15012027Sjungma@eit.uni-kl.deif options.jobs != 1:
15112027Sjungma@eit.uni-kl.de    if options.jobs == 0:
15212027Sjungma@eit.uni-kl.de        options.jobs = cpu_count()
15312027Sjungma@eit.uni-kl.de    scons_opts += ' -j %d' % options.jobs
15412027Sjungma@eit.uni-kl.deif options.keep_going:
15512027Sjungma@eit.uni-kl.de    scons_opts += ' -k'
15612027Sjungma@eit.uni-kl.deif options.update_ref:
15712027Sjungma@eit.uni-kl.de    scons_opts += ' --update-ref'
15812027Sjungma@eit.uni-kl.de
15912027Sjungma@eit.uni-kl.de# We generally compile gem5.fast only to make sure it compiles OK;
16012027Sjungma@eit.uni-kl.de# it's not very useful to run as a regression test since assertions
16112027Sjungma@eit.uni-kl.de# are disabled.  Thus there's not much point spending time on
16212027Sjungma@eit.uni-kl.de# link-time optimization.
16312027Sjungma@eit.uni-kl.descons_opts += ' --no-lto'
16412027Sjungma@eit.uni-kl.de
16512027Sjungma@eit.uni-kl.decmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets))
16612027Sjungma@eit.uni-kl.deif options.no_exec:
16712027Sjungma@eit.uni-kl.de    print cmd
16812027Sjungma@eit.uni-kl.deelse:
16912027Sjungma@eit.uni-kl.de    system(cmd)
17012027Sjungma@eit.uni-kl.de    sys.exit(0)
17112027Sjungma@eit.uni-kl.de