regress revision 3725
111731Sjason@lowepower.com#! /usr/bin/env python
211731Sjason@lowepower.com# Copyright (c) 2005-2006 The Regents of The University of Michigan
312137Sar4jc@virginia.edu# All rights reserved.
412137Sar4jc@virginia.edu#
512137Sar4jc@virginia.edu# Redistribution and use in source and binary forms, with or without
612137Sar4jc@virginia.edu# modification, are permitted provided that the following conditions are
712137Sar4jc@virginia.edu# met: redistributions of source code must retain the above copyright
812137Sar4jc@virginia.edu# notice, this list of conditions and the following disclaimer;
912137Sar4jc@virginia.edu# redistributions in binary form must reproduce the above copyright
1012137Sar4jc@virginia.edu# notice, this list of conditions and the following disclaimer in the
1112137Sar4jc@virginia.edu# documentation and/or other materials provided with the distribution;
1212137Sar4jc@virginia.edu# neither the name of the copyright holders nor the names of its
1312137Sar4jc@virginia.edu# contributors may be used to endorse or promote products derived from
1412137Sar4jc@virginia.edu# this software without specific prior written permission.
1512137Sar4jc@virginia.edu#
1612137Sar4jc@virginia.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712137Sar4jc@virginia.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812137Sar4jc@virginia.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912137Sar4jc@virginia.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012137Sar4jc@virginia.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112137Sar4jc@virginia.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212137Sar4jc@virginia.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312137Sar4jc@virginia.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412137Sar4jc@virginia.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512137Sar4jc@virginia.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612137Sar4jc@virginia.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712137Sar4jc@virginia.edu#
2812137Sar4jc@virginia.edu# Authors: Steve Reinhardt
2912137Sar4jc@virginia.edu
3012137Sar4jc@virginia.eduimport sys
3112137Sar4jc@virginia.eduimport os
3212137Sar4jc@virginia.eduimport optparse
3312137Sar4jc@virginia.eduimport datetime
3412137Sar4jc@virginia.edu
3512137Sar4jc@virginia.eduprogname = os.path.basename(sys.argv[0])
3612137Sar4jc@virginia.edu
3712137Sar4jc@virginia.eduoptparser = optparse.OptionParser()
3812137Sar4jc@virginia.eduoptparser.add_option('-v', '--verbose', dest='verbose', action='store_true',
3912137Sar4jc@virginia.edu                     default=False,
4012137Sar4jc@virginia.edu                     help='echo commands before executing')
4112137Sar4jc@virginia.eduoptparser.add_option('--builds', dest='builds',
4212137Sar4jc@virginia.edu                     default='ALPHA_SE,ALPHA_FS,MIPS_SE,SPARC_SE',
4312137Sar4jc@virginia.edu                     help='comma-separated list of build targets to test  '
4412137Sar4jc@virginia.edu                     " (default: '%default')" )
4512137Sar4jc@virginia.eduoptparser.add_option('--variants', dest='variants',
4612137Sar4jc@virginia.edu                     default='opt',
4712137Sar4jc@virginia.edu                     help='comma-separated list of build variants to test '
4812137Sar4jc@virginia.edu                     " (default: '%default')" )
4912137Sar4jc@virginia.eduoptparser.add_option('--scons-opts', dest='scons_opts', default='',
5012137Sar4jc@virginia.edu                     help='scons options', metavar='OPTS')
5112137Sar4jc@virginia.eduoptparser.add_option('-j', '--jobs', type='int', default=1,
5212137Sar4jc@virginia.edu                     help='number of parallel jobs to use')
5312137Sar4jc@virginia.edu
5412137Sar4jc@virginia.edu(options, tests) = optparser.parse_args()
5512137Sar4jc@virginia.edu
5612137Sar4jc@virginia.edu
5712137Sar4jc@virginia.edu# split list options on ',' to get Python lists
5812137Sar4jc@virginia.edubuilds = options.builds.split(',')
5912137Sar4jc@virginia.eduvariants = options.variants.split(',')
6012137Sar4jc@virginia.edu
6112137Sar4jc@virginia.edu# Call os.system() and raise exception if return status is non-zero
6212137Sar4jc@virginia.edudef system(cmd):
6312137Sar4jc@virginia.edu    if options.verbose:
6412137Sar4jc@virginia.edu        print cmd
6512137Sar4jc@virginia.edu    status = os.system(cmd)
6612137Sar4jc@virginia.edu    if status != 0:
6712137Sar4jc@virginia.edu        upper = (status & 0xff00) >> 8
6812137Sar4jc@virginia.edu        lower = (status & 0xff)
6912137Sar4jc@virginia.edu        raise OSError, "shell command '%s' failed, status %d:%d" \
7012137Sar4jc@virginia.edu              % (cmd, upper, lower)
7112137Sar4jc@virginia.edu
7212137Sar4jc@virginia.edu# Quote string s so it can be passed as a shell arg
7312137Sar4jc@virginia.edudef shellquote(s):
7412137Sar4jc@virginia.edu    if ' ' in s:
7512137Sar4jc@virginia.edu        s = "'%s'" % s
7612137Sar4jc@virginia.edu    return s
7712137Sar4jc@virginia.edu
7812137Sar4jc@virginia.edutry:
7912137Sar4jc@virginia.edu    if not tests:
8012137Sar4jc@virginia.edu        print "No tests specified."
8112137Sar4jc@virginia.edu        sys.exit(1)
8212137Sar4jc@virginia.edu
8312137Sar4jc@virginia.edu    if 'all' in tests:
8412137Sar4jc@virginia.edu	targets = ['build/%s/tests/%s' % (build, variant)
8512137Sar4jc@virginia.edu		   for build in builds
8612137Sar4jc@virginia.edu		   for variant in variants]
8712137Sar4jc@virginia.edu    else:
8812137Sar4jc@virginia.edu	targets = ['build/%s/tests/%s/%s' % (build, variant, test)
8912137Sar4jc@virginia.edu		   for build in builds
9012137Sar4jc@virginia.edu		   for variant in variants
9112137Sar4jc@virginia.edu		   for test in tests]
9212137Sar4jc@virginia.edu
9312137Sar4jc@virginia.edu    scons_opts = options.scons_opts
9412137Sar4jc@virginia.edu    if options.jobs != 1:
9512137Sar4jc@virginia.edu        scons_opts += ' -j %d' % options.jobs
9612137Sar4jc@virginia.edu
9712137Sar4jc@virginia.edu    system('scons %s %s' % (scons_opts, ' '.join(targets)))
9812137Sar4jc@virginia.edu
9912137Sar4jc@virginia.edu    sys.exit(0)
10012137Sar4jc@virginia.edu
10112137Sar4jc@virginia.eduexcept OSError, exc:
10212137Sar4jc@virginia.edu    print "%s: " % progname, exc
10312137Sar4jc@virginia.edu    sys.exit(1)
10412137Sar4jc@virginia.edu