regress revision 4130
14120Sgblack@eecs.umich.edu#! /usr/bin/env python
24120Sgblack@eecs.umich.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan
37087Snate@binkert.org# All rights reserved.
47087Snate@binkert.org#
57087Snate@binkert.org# Redistribution and use in source and binary forms, with or without
67087Snate@binkert.org# modification, are permitted provided that the following conditions are
77087Snate@binkert.org# met: redistributions of source code must retain the above copyright
87087Snate@binkert.org# notice, this list of conditions and the following disclaimer;
97087Snate@binkert.org# redistributions in binary form must reproduce the above copyright
107087Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
117087Snate@binkert.org# documentation and/or other materials provided with the distribution;
127087Snate@binkert.org# neither the name of the copyright holders nor the names of its
137087Snate@binkert.org# contributors may be used to endorse or promote products derived from
147087Snate@binkert.org# this software without specific prior written permission.
154120Sgblack@eecs.umich.edu#
164120Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174120Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184120Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194120Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204120Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214120Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224120Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234120Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244120Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254120Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264120Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274120Sgblack@eecs.umich.edu#
284120Sgblack@eecs.umich.edu# Authors: Steve Reinhardt
294120Sgblack@eecs.umich.edu
304120Sgblack@eecs.umich.eduimport sys
314120Sgblack@eecs.umich.eduimport os
324120Sgblack@eecs.umich.eduimport optparse
334120Sgblack@eecs.umich.eduimport datetime
344120Sgblack@eecs.umich.edu
354120Sgblack@eecs.umich.eduprogname = os.path.basename(sys.argv[0])
364120Sgblack@eecs.umich.edu
374120Sgblack@eecs.umich.eduoptparser = optparse.OptionParser()
384120Sgblack@eecs.umich.eduoptparser.add_option('-v', '--verbose', dest='verbose', action='store_true',
394120Sgblack@eecs.umich.edu                     default=False,
404120Sgblack@eecs.umich.edu                     help='echo commands before executing')
414120Sgblack@eecs.umich.eduoptparser.add_option('--builds', dest='builds',
424120Sgblack@eecs.umich.edu                     default='ALPHA_SE,ALPHA_FS,MIPS_SE,SPARC_SE,SPARC_FS',
434202Sbinkertn@umich.edu                     help='comma-separated list of build targets to test  '
445069Sgblack@eecs.umich.edu                     " (default: '%default')" )
454202Sbinkertn@umich.eduoptparser.add_option('--variants', dest='variants',
465659Sgblack@eecs.umich.edu                     default='fast',
479022Sgblack@eecs.umich.edu                     help='comma-separated list of build variants to test '
489023Sgblack@eecs.umich.edu                     " (default: '%default')" )
494601Sgblack@eecs.umich.eduoptparser.add_option('--scons-opts', dest='scons_opts', default='',
505124Sgblack@eecs.umich.edu                     help='scons options', metavar='OPTS')
517966Sgblack@eecs.umich.eduoptparser.add_option('-j', '--jobs', type='int', default=1,
525083Sgblack@eecs.umich.edu                     help='number of parallel jobs to use')
534679Sgblack@eecs.umich.edu
546515Sgblack@eecs.umich.edu(options, tests) = optparser.parse_args()
555083Sgblack@eecs.umich.edu
564679Sgblack@eecs.umich.edu
574679Sgblack@eecs.umich.edu# split list options on ',' to get Python lists
588745Sgblack@eecs.umich.edubuilds = options.builds.split(',')
596313Sgblack@eecs.umich.eduvariants = options.variants.split(',')
608771Sgblack@eecs.umich.edu
618771Sgblack@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero
628771Sgblack@eecs.umich.edudef system(cmd):
638771Sgblack@eecs.umich.edu    if options.verbose:
646365Sgblack@eecs.umich.edu        print cmd
655124Sgblack@eecs.umich.edu    status = os.system(cmd)
668752Sgblack@eecs.umich.edu    if status != 0:
678771Sgblack@eecs.umich.edu        upper = (status & 0xff00) >> 8
684202Sbinkertn@umich.edu        lower = (status & 0xff)
698771Sgblack@eecs.umich.edu        raise OSError, "shell command '%s' failed, status %d:%d" \
708771Sgblack@eecs.umich.edu              % (cmd, upper, lower)
714997Sgblack@eecs.umich.edu
727624Sgblack@eecs.umich.edu# Quote string s so it can be passed as a shell arg
735135Sgblack@eecs.umich.edudef shellquote(s):
748753Sgblack@eecs.umich.edu    if ' ' in s:
754997Sgblack@eecs.umich.edu        s = "'%s'" % s
768745Sgblack@eecs.umich.edu    return s
776365Sgblack@eecs.umich.edu
788771Sgblack@eecs.umich.edutry:
798740Sgblack@eecs.umich.edu    if not tests:
806365Sgblack@eecs.umich.edu        print "No tests specified, just building binaries."
818740Sgblack@eecs.umich.edu        targets = ['build/%s/m5.%s' % (build, variant)
828745Sgblack@eecs.umich.edu		   for build in builds
838752Sgblack@eecs.umich.edu		   for variant in variants]
848752Sgblack@eecs.umich.edu    elif 'all' in tests:
859023Sgblack@eecs.umich.edu	targets = ['build/%s/tests/%s' % (build, variant)
868335Snate@binkert.org		   for build in builds
874120Sgblack@eecs.umich.edu		   for variant in variants]
885069Sgblack@eecs.umich.edu    else:
895081Sgblack@eecs.umich.edu	targets = ['build/%s/tests/%s/%s' % (build, variant, test)
905081Sgblack@eecs.umich.edu		   for build in builds
915081Sgblack@eecs.umich.edu		   for variant in variants
925081Sgblack@eecs.umich.edu		   for test in tests]
935081Sgblack@eecs.umich.edu
945081Sgblack@eecs.umich.edu    scons_opts = options.scons_opts
955081Sgblack@eecs.umich.edu    if options.jobs != 1:
965081Sgblack@eecs.umich.edu        scons_opts += ' -j %d' % options.jobs
975081Sgblack@eecs.umich.edu
985081Sgblack@eecs.umich.edu    system('scons %s %s' % (scons_opts, ' '.join(targets)))
995081Sgblack@eecs.umich.edu
1005081Sgblack@eecs.umich.edu    sys.exit(0)
1015081Sgblack@eecs.umich.edu
1025081Sgblack@eecs.umich.eduexcept OSError, exc:
1035081Sgblack@eecs.umich.edu    print "%s: " % progname, exc
1045081Sgblack@eecs.umich.edu    sys.exit(1)
1055081Sgblack@eecs.umich.edu