regress revision 4130
11897Sstever@eecs.umich.edu#! /usr/bin/env python
24130Ssaidi@eecs.umich.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan
31897Sstever@eecs.umich.edu# All rights reserved.
41897Sstever@eecs.umich.edu#
51897Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
61897Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are
71897Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright
81897Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
91897Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
101897Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
111897Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution;
121897Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its
131897Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
141897Sstever@eecs.umich.edu# this software without specific prior written permission.
151897Sstever@eecs.umich.edu#
161897Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171897Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181897Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191897Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201897Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211897Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221897Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231897Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241897Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251897Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261897Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271897Sstever@eecs.umich.edu#
281897Sstever@eecs.umich.edu# Authors: Steve Reinhardt
291897Sstever@eecs.umich.edu
301897Sstever@eecs.umich.eduimport sys
311897Sstever@eecs.umich.eduimport os
321897Sstever@eecs.umich.eduimport optparse
331897Sstever@eecs.umich.eduimport datetime
344961Ssaidi@eecs.umich.edu
351897Sstever@eecs.umich.eduprogname = os.path.basename(sys.argv[0])
361897Sstever@eecs.umich.edu
371897Sstever@eecs.umich.eduoptparser = optparse.OptionParser()
381897Sstever@eecs.umich.eduoptparser.add_option('-v', '--verbose', dest='verbose', action='store_true',
397047Snate@binkert.org                     default=False,
408319Ssteve.reinhardt@amd.com                     help='echo commands before executing')
417047Snate@binkert.orgoptparser.add_option('--builds', dest='builds',
428319Ssteve.reinhardt@amd.com                     default='ALPHA_SE,ALPHA_FS,MIPS_SE,SPARC_SE,SPARC_FS',
438811Sandreas.hansson@arm.com                     help='comma-separated list of build targets to test  '
4410007Snilay@cs.wisc.edu                     " (default: '%default')" )
458811Sandreas.hansson@arm.comoptparser.add_option('--variants', dest='variants',
468811Sandreas.hansson@arm.com                     default='fast',
478811Sandreas.hansson@arm.com                     help='comma-separated list of build variants to test '
489850Sandreas.hansson@arm.com                     " (default: '%default')" )
498811Sandreas.hansson@arm.comoptparser.add_option('--scons-opts', dest='scons_opts', default='',
508811Sandreas.hansson@arm.com                     help='scons options', metavar='OPTS')
5110007Snilay@cs.wisc.eduoptparser.add_option('-j', '--jobs', type='int', default=1,
528811Sandreas.hansson@arm.com                     help='number of parallel jobs to use')
537047Snate@binkert.org
548811Sandreas.hansson@arm.com(options, tests) = optparser.parse_args()
558811Sandreas.hansson@arm.com
568811Sandreas.hansson@arm.com
578319Ssteve.reinhardt@amd.com# split list options on ',' to get Python lists
588319Ssteve.reinhardt@amd.combuilds = options.builds.split(',')
598319Ssteve.reinhardt@amd.comvariants = options.variants.split(',')
608319Ssteve.reinhardt@amd.com
618319Ssteve.reinhardt@amd.com# Call os.system() and raise exception if return status is non-zero
628319Ssteve.reinhardt@amd.comdef system(cmd):
638319Ssteve.reinhardt@amd.com    if options.verbose:
647047Snate@binkert.org        print cmd
658319Ssteve.reinhardt@amd.com    status = os.system(cmd)
668319Ssteve.reinhardt@amd.com    if status != 0:
677047Snate@binkert.org        upper = (status & 0xff00) >> 8
687047Snate@binkert.org        lower = (status & 0xff)
698319Ssteve.reinhardt@amd.com        raise OSError, "shell command '%s' failed, status %d:%d" \
708319Ssteve.reinhardt@amd.com              % (cmd, upper, lower)
718319Ssteve.reinhardt@amd.com
727047Snate@binkert.org# Quote string s so it can be passed as a shell arg
737047Snate@binkert.orgdef shellquote(s):
747047Snate@binkert.org    if ' ' in s:
751897Sstever@eecs.umich.edu        s = "'%s'" % s
761897Sstever@eecs.umich.edu    return s
771897Sstever@eecs.umich.edu
781897Sstever@eecs.umich.edutry:
798319Ssteve.reinhardt@amd.com    if not tests:
808319Ssteve.reinhardt@amd.com        print "No tests specified, just building binaries."
818319Ssteve.reinhardt@amd.com        targets = ['build/%s/m5.%s' % (build, variant)
828319Ssteve.reinhardt@amd.com		   for build in builds
838319Ssteve.reinhardt@amd.com		   for variant in variants]
848319Ssteve.reinhardt@amd.com    elif 'all' in tests:
858319Ssteve.reinhardt@amd.com	targets = ['build/%s/tests/%s' % (build, variant)
861897Sstever@eecs.umich.edu		   for build in builds
878319Ssteve.reinhardt@amd.com		   for variant in variants]
888811Sandreas.hansson@arm.com    else:
898319Ssteve.reinhardt@amd.com	targets = ['build/%s/tests/%s/%s' % (build, variant, test)
908319Ssteve.reinhardt@amd.com		   for build in builds
911897Sstever@eecs.umich.edu		   for variant in variants
927047Snate@binkert.org		   for test in tests]
937047Snate@binkert.org
941897Sstever@eecs.umich.edu    scons_opts = options.scons_opts
951897Sstever@eecs.umich.edu    if options.jobs != 1:
964961Ssaidi@eecs.umich.edu        scons_opts += ' -j %d' % options.jobs
974961Ssaidi@eecs.umich.edu
984961Ssaidi@eecs.umich.edu    system('scons %s %s' % (scons_opts, ' '.join(targets)))
994961Ssaidi@eecs.umich.edu
1004961Ssaidi@eecs.umich.edu    sys.exit(0)
1014961Ssaidi@eecs.umich.edu
1024961Ssaidi@eecs.umich.eduexcept OSError, exc:
1034961Ssaidi@eecs.umich.edu    print "%s: " % progname, exc
1044961Ssaidi@eecs.umich.edu    sys.exit(1)
1054961Ssaidi@eecs.umich.edu