regress revision 3097:6d06427d2248
113961Sodanrc@yahoo.com.br#! /usr/bin/env python
213961Sodanrc@yahoo.com.br# Copyright (c) 2005-2006 The Regents of The University of Michigan
313961Sodanrc@yahoo.com.br# All rights reserved.
413961Sodanrc@yahoo.com.br#
513961Sodanrc@yahoo.com.br# Redistribution and use in source and binary forms, with or without
613961Sodanrc@yahoo.com.br# modification, are permitted provided that the following conditions are
713961Sodanrc@yahoo.com.br# met: redistributions of source code must retain the above copyright
813961Sodanrc@yahoo.com.br# notice, this list of conditions and the following disclaimer;
913961Sodanrc@yahoo.com.br# redistributions in binary form must reproduce the above copyright
1013961Sodanrc@yahoo.com.br# notice, this list of conditions and the following disclaimer in the
1113961Sodanrc@yahoo.com.br# documentation and/or other materials provided with the distribution;
1213961Sodanrc@yahoo.com.br# neither the name of the copyright holders nor the names of its
1313961Sodanrc@yahoo.com.br# contributors may be used to endorse or promote products derived from
1413961Sodanrc@yahoo.com.br# this software without specific prior written permission.
1513961Sodanrc@yahoo.com.br#
1613961Sodanrc@yahoo.com.br# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713961Sodanrc@yahoo.com.br# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813961Sodanrc@yahoo.com.br# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913961Sodanrc@yahoo.com.br# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013961Sodanrc@yahoo.com.br# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113961Sodanrc@yahoo.com.br# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213961Sodanrc@yahoo.com.br# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313961Sodanrc@yahoo.com.br# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413961Sodanrc@yahoo.com.br# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513961Sodanrc@yahoo.com.br# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613961Sodanrc@yahoo.com.br# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713961Sodanrc@yahoo.com.br#
2813961Sodanrc@yahoo.com.br# Authors: Steve Reinhardt
2913961Sodanrc@yahoo.com.br
3013961Sodanrc@yahoo.com.brimport sys
3113961Sodanrc@yahoo.com.brimport os
3213961Sodanrc@yahoo.com.brimport optparse
3313961Sodanrc@yahoo.com.brimport datetime
3413961Sodanrc@yahoo.com.br
3513961Sodanrc@yahoo.com.brprogname = os.path.basename(sys.argv[0])
3613961Sodanrc@yahoo.com.br
3713961Sodanrc@yahoo.com.broptparser = optparse.OptionParser()
3813961Sodanrc@yahoo.com.broptparser.add_option('-v', '--verbose', dest='verbose', action='store_true',
3913961Sodanrc@yahoo.com.br                     default=False,
4013961Sodanrc@yahoo.com.br                     help='echo commands before executing')
4113961Sodanrc@yahoo.com.broptparser.add_option('--builds', dest='builds',
4213961Sodanrc@yahoo.com.br                     default='ALPHA_SE,ALPHA_FS,MIPS_SE,SPARC_SE',
4313961Sodanrc@yahoo.com.br                     help='comma-separated list of builds to test')
4413961Sodanrc@yahoo.com.broptparser.add_option('--variants', dest='variants',
4513961Sodanrc@yahoo.com.br                     default='opt',
4613961Sodanrc@yahoo.com.br                     help='comma-separated list of build variants to test')
4713961Sodanrc@yahoo.com.broptparser.add_option('--scons-opts', dest='scons_opts', default='',
4813961Sodanrc@yahoo.com.br                     help='scons options')
4913961Sodanrc@yahoo.com.br
5013961Sodanrc@yahoo.com.br(options, tests) = optparser.parse_args()
5113961Sodanrc@yahoo.com.br
5213961Sodanrc@yahoo.com.br
5313961Sodanrc@yahoo.com.br# split list options on ',' to get Python lists
5413961Sodanrc@yahoo.com.brbuilds = options.builds.split(',')
5513961Sodanrc@yahoo.com.brvariants = options.variants.split(',')
5613961Sodanrc@yahoo.com.br
5713961Sodanrc@yahoo.com.br# Call os.system() and raise exception if return status is non-zero
5813961Sodanrc@yahoo.com.brdef system(cmd):
5913961Sodanrc@yahoo.com.br    if options.verbose:
6013961Sodanrc@yahoo.com.br        print cmd
6113961Sodanrc@yahoo.com.br    status = os.system(cmd)
6213961Sodanrc@yahoo.com.br    if status != 0:
6313961Sodanrc@yahoo.com.br        upper = (status & 0xff00) >> 8
6413961Sodanrc@yahoo.com.br        lower = (status & 0xff)
6513961Sodanrc@yahoo.com.br        raise OSError, "shell command '%s' failed, status %d:%d" \
6613961Sodanrc@yahoo.com.br              % (cmd, upper, lower)
6713961Sodanrc@yahoo.com.br
6813961Sodanrc@yahoo.com.br# Quote string s so it can be passed as a shell arg
6913961Sodanrc@yahoo.com.brdef shellquote(s):
7013961Sodanrc@yahoo.com.br    if ' ' in s:
7113961Sodanrc@yahoo.com.br        s = "'%s'" % s
7213961Sodanrc@yahoo.com.br    return s
7313961Sodanrc@yahoo.com.br
7413961Sodanrc@yahoo.com.brtry:
7513961Sodanrc@yahoo.com.br    if not tests:
7613961Sodanrc@yahoo.com.br        print "No tests specified."
7713961Sodanrc@yahoo.com.br        sys.exit(1)
7813961Sodanrc@yahoo.com.br
7913961Sodanrc@yahoo.com.br    if 'all' in tests:
8013961Sodanrc@yahoo.com.br	targets = ['build/%s/tests/%s' % (build, variant)
8113961Sodanrc@yahoo.com.br		   for build in builds
8213961Sodanrc@yahoo.com.br		   for variant in variants]
8313961Sodanrc@yahoo.com.br    else:
8413961Sodanrc@yahoo.com.br	targets = ['build/%s/tests/%s/%s' % (build, variant, test)
8513961Sodanrc@yahoo.com.br		   for build in builds
8613961Sodanrc@yahoo.com.br		   for variant in variants
8713961Sodanrc@yahoo.com.br		   for test in tests]
8813961Sodanrc@yahoo.com.br
8913961Sodanrc@yahoo.com.br    system('scons %s %s' % (options.scons_opts, ' '.join(targets)))
9013961Sodanrc@yahoo.com.br
9113961Sodanrc@yahoo.com.br    sys.exit(0)
9213961Sodanrc@yahoo.com.br
9313961Sodanrc@yahoo.com.brexcept OSError, exc:
9413961Sodanrc@yahoo.com.br    print "%s: " % progname, exc
9513961Sodanrc@yahoo.com.br    sys.exit(1)
9613961Sodanrc@yahoo.com.br