regress revision 8811:be4990a2c764
111977Sjason@lowepower.com#! /usr/bin/env python
211977Sjason@lowepower.com# Copyright (c) 2005-2007 The Regents of The University of Michigan
311977Sjason@lowepower.com# All rights reserved.
411977Sjason@lowepower.com#
511977Sjason@lowepower.com# Redistribution and use in source and binary forms, with or without
611977Sjason@lowepower.com# modification, are permitted provided that the following conditions are
711977Sjason@lowepower.com# met: redistributions of source code must retain the above copyright
811977Sjason@lowepower.com# notice, this list of conditions and the following disclaimer;
911977Sjason@lowepower.com# redistributions in binary form must reproduce the above copyright
1011977Sjason@lowepower.com# notice, this list of conditions and the following disclaimer in the
1111977Sjason@lowepower.com# documentation and/or other materials provided with the distribution;
1211977Sjason@lowepower.com# neither the name of the copyright holders nor the names of its
1311977Sjason@lowepower.com# contributors may be used to endorse or promote products derived from
1411977Sjason@lowepower.com# this software without specific prior written permission.
1511977Sjason@lowepower.com#
1611977Sjason@lowepower.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711977Sjason@lowepower.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811977Sjason@lowepower.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911977Sjason@lowepower.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011977Sjason@lowepower.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111977Sjason@lowepower.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211977Sjason@lowepower.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311977Sjason@lowepower.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411977Sjason@lowepower.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511977Sjason@lowepower.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611977Sjason@lowepower.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711977Sjason@lowepower.com#
2811977Sjason@lowepower.com# Authors: Steve Reinhardt
2911977Sjason@lowepower.com
3011977Sjason@lowepower.comimport sys
3111977Sjason@lowepower.comimport os
3211977Sjason@lowepower.comimport optparse
3311977Sjason@lowepower.comimport datetime
3411977Sjason@lowepower.comfrom subprocess import call
3511977Sjason@lowepower.com
3611977Sjason@lowepower.comprogname = os.path.basename(sys.argv[0])
3711977Sjason@lowepower.com
3811977Sjason@lowepower.comoptparser = optparse.OptionParser()
3911977Sjason@lowepower.comadd_option = optparser.add_option
4011977Sjason@lowepower.comadd_option('-v', '--verbose', action='store_true', default=False,
4111977Sjason@lowepower.com           help='echo commands before executing')
4211977Sjason@lowepower.comadd_option('--builds',
4311977Sjason@lowepower.com           default='ALPHA,ALPHA_MOESI_hammer,' \
4411977Sjason@lowepower.com           'ALPHA_MESI_CMP_directory,'  \
4511977Sjason@lowepower.com           'ALPHA_MOESI_CMP_directory,' \
4611977Sjason@lowepower.com           'ALPHA_MOESI_CMP_token,' \
4711977Sjason@lowepower.com           'MIPS,' \
4811977Sjason@lowepower.com           'POWER,' \
4911977Sjason@lowepower.com           'SPARC,' \
5011977Sjason@lowepower.com           'X86,' \
5111977Sjason@lowepower.com           'ARM',
5211977Sjason@lowepower.com           help="comma-separated build targets to test (default: '%default')")
5311977Sjason@lowepower.comadd_option('--modes',
5411977Sjason@lowepower.com           default='se,fs',
5511977Sjason@lowepower.com           help="comma-separated modes to test (default: '%default')")
5611977Sjason@lowepower.comadd_option('--test-variants', default='opt',
5711977Sjason@lowepower.com           help="comma-separated build variants to test (default: '%default')"\
5811977Sjason@lowepower.com           ", set to '' for none")
5911977Sjason@lowepower.comadd_option('--compile-variants', default='debug,fast',
6011977Sjason@lowepower.com           help="comma-separated build variants to compile only (not test) " \
6112367Sjason@lowepower.com           "(default: '%default'), set to '' for none", metavar='VARIANTS')
6212367Sjason@lowepower.comadd_option('--scons-opts', default='', metavar='OPTS',
6312367Sjason@lowepower.com           help='scons options')
6412367Sjason@lowepower.comadd_option('-j', '--jobs', type='int', default=1, metavar='N',
6511977Sjason@lowepower.com           help='number of parallel jobs to use (0 to use all cores)')
6611977Sjason@lowepower.comadd_option('-k', '--keep-going', action='store_true',
6711977Sjason@lowepower.com           help='keep going after errors')
6811977Sjason@lowepower.comadd_option('--update-ref', action='store_true',
6911977Sjason@lowepower.com           help='update reference outputs')
7011977Sjason@lowepower.comadd_option('-D', '--build-dir', default='', metavar='DIR',
7111977Sjason@lowepower.com           help='build directory location')
7211977Sjason@lowepower.comadd_option('-n', "--no-exec", default=False, action='store_true',
7311977Sjason@lowepower.com           help="don't actually invoke scons, just echo SCons command line")
7411977Sjason@lowepower.com
7511977Sjason@lowepower.com(options, tests) = optparser.parse_args()
7611977Sjason@lowepower.com
7711977Sjason@lowepower.com
7811977Sjason@lowepower.com# split a comma-separated list, but return an empty list if given the
7911977Sjason@lowepower.com# empty string
8011977Sjason@lowepower.comdef split_if_nonempty(s):
8111977Sjason@lowepower.com    if not s:
8211977Sjason@lowepower.com        return []
8311977Sjason@lowepower.com    return s.split(',')
8411977Sjason@lowepower.com
8511977Sjason@lowepower.com# split list options on ',' to get Python lists
8611977Sjason@lowepower.combuilds = split_if_nonempty(options.builds)
8711977Sjason@lowepower.commodes = split_if_nonempty(options.modes)
8811977Sjason@lowepower.comtest_variants = split_if_nonempty(options.test_variants)
8911977Sjason@lowepower.comcompile_variants = split_if_nonempty(options.compile_variants)
9011977Sjason@lowepower.com
9114148Sandreas.sandberg@arm.comoptions.build_dir = os.path.join(options.build_dir, 'build')
9214148Sandreas.sandberg@arm.com
9314148Sandreas.sandberg@arm.com# Call os.system() and raise exception if return status is non-zero
9414148Sandreas.sandberg@arm.comdef system(cmd):
9514148Sandreas.sandberg@arm.com    try:
9611977Sjason@lowepower.com        retcode = call(cmd, shell=True)
9711977Sjason@lowepower.com        if retcode < 0:
9811977Sjason@lowepower.com            print >>sys.stderr, "Child was terminated by signal", -retcode
9911977Sjason@lowepower.com            print >>sys.stderr, "When attemping to execute: %s" % cmd
100            sys.exit(1)
101        elif retcode > 0:
102            print >>sys.stderr, "Child returned", retcode
103            print >>sys.stderr, "When attemping to execute: %s" % cmd
104            sys.exit(1)
105    except OSError, e:
106        print >>sys.stderr, "Execution failed:", e
107        print >>sys.stderr, "When attemping to execute: %s" % cmd
108        sys.exit(1)
109
110targets = []
111
112# start with compile-only targets, if any
113if compile_variants:
114    targets += ['%s/%s/m5.%s' % (options.build_dir, build, variant)
115                for variant in compile_variants
116                for build in builds]
117
118# By default run the 'quick' tests, all expands to quick and long
119if not tests:
120    tests = ['quick']
121elif 'all' in tests:
122    tests = ['quick,long']
123
124# set up test targets for scons, since we don't have any quick SPARC
125# full-system tests exclude it
126targets += ['%s/%s/tests/%s/%s/%s' % (options.build_dir, build, variant, test,
127                                      mode)
128            for build in builds
129            for variant in test_variants
130            for test in tests
131            for mode in modes
132            if not (build == 'SPARC' and test == 'quick' and mode == 'fs')]
133
134def cpu_count():
135    if 'bsd' in sys.platform or sys.platform == 'darwin':
136        try:
137            return int(os.popen('sysctl -n hw.ncpu').read())
138        except ValueError:
139            pass
140    else:
141        try:
142            return os.sysconf('SC_NPROCESSORS_ONLN')
143        except (ValueError, OSError, AttributeError):
144            pass
145
146    raise NotImplementedError('cannot determine number of cpus')
147
148scons_opts = options.scons_opts
149if options.jobs != 1:
150    if options.jobs == 0:
151        options.jobs = cpu_count()
152    scons_opts += ' -j %d' % options.jobs
153if options.keep_going:
154    scons_opts += ' -k'
155if options.update_ref:
156    scons_opts += ' --update-ref'
157
158cmd = 'scons --ignore-style %s %s' % (scons_opts, ' '.join(targets))
159if options.no_exec:
160    print cmd
161else:
162    system(cmd)
163    sys.exit(0)
164