regress revision 3725
11897Sstever@eecs.umich.edu#! /usr/bin/env python
24130Ssaidi@eecs.umich.edu# Copyright (c) 2005-2006 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',
438811Sandreas.hansson@arm.com                     help='comma-separated list of build targets to test  '
448811Sandreas.hansson@arm.com                     " (default: '%default')" )
458811Sandreas.hansson@arm.comoptparser.add_option('--variants', dest='variants',
468811Sandreas.hansson@arm.com                     default='opt',
478811Sandreas.hansson@arm.com                     help='comma-separated list of build variants to test '
488811Sandreas.hansson@arm.com                     " (default: '%default')" )
498811Sandreas.hansson@arm.comoptparser.add_option('--scons-opts', dest='scons_opts', default='',
508969Snilay@cs.wisc.edu                     help='scons options', metavar='OPTS')
518811Sandreas.hansson@arm.comoptparser.add_option('-j', '--jobs', type='int', default=1,
527047Snate@binkert.org                     help='number of parallel jobs to use')
538811Sandreas.hansson@arm.com
548811Sandreas.hansson@arm.com(options, tests) = optparser.parse_args()
558811Sandreas.hansson@arm.com
568319Ssteve.reinhardt@amd.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):
637047Snate@binkert.org    if options.verbose:
648319Ssteve.reinhardt@amd.com        print cmd
658319Ssteve.reinhardt@amd.com    status = os.system(cmd)
667047Snate@binkert.org    if status != 0:
677047Snate@binkert.org        upper = (status & 0xff00) >> 8
688319Ssteve.reinhardt@amd.com        lower = (status & 0xff)
698319Ssteve.reinhardt@amd.com        raise OSError, "shell command '%s' failed, status %d:%d" \
708319Ssteve.reinhardt@amd.com              % (cmd, upper, lower)
717047Snate@binkert.org
727047Snate@binkert.org# Quote string s so it can be passed as a shell arg
737047Snate@binkert.orgdef shellquote(s):
741897Sstever@eecs.umich.edu    if ' ' in s:
751897Sstever@eecs.umich.edu        s = "'%s'" % s
761897Sstever@eecs.umich.edu    return s
771897Sstever@eecs.umich.edu
788319Ssteve.reinhardt@amd.comtry:
798319Ssteve.reinhardt@amd.com    if not tests:
808319Ssteve.reinhardt@amd.com        print "No tests specified."
818319Ssteve.reinhardt@amd.com        sys.exit(1)
828319Ssteve.reinhardt@amd.com
838319Ssteve.reinhardt@amd.com    if 'all' in tests:
848319Ssteve.reinhardt@amd.com	targets = ['build/%s/tests/%s' % (build, variant)
851897Sstever@eecs.umich.edu		   for build in builds
868319Ssteve.reinhardt@amd.com		   for variant in variants]
878811Sandreas.hansson@arm.com    else:
888319Ssteve.reinhardt@amd.com	targets = ['build/%s/tests/%s/%s' % (build, variant, test)
898319Ssteve.reinhardt@amd.com		   for build in builds
901897Sstever@eecs.umich.edu		   for variant in variants
917047Snate@binkert.org		   for test in tests]
927047Snate@binkert.org
931897Sstever@eecs.umich.edu    scons_opts = options.scons_opts
941897Sstever@eecs.umich.edu    if options.jobs != 1:
954961Ssaidi@eecs.umich.edu        scons_opts += ' -j %d' % options.jobs
964961Ssaidi@eecs.umich.edu
974961Ssaidi@eecs.umich.edu    system('scons %s %s' % (scons_opts, ' '.join(targets)))
984961Ssaidi@eecs.umich.edu
994961Ssaidi@eecs.umich.edu    sys.exit(0)
1004961Ssaidi@eecs.umich.edu
1014961Ssaidi@eecs.umich.eduexcept OSError, exc:
1024961Ssaidi@eecs.umich.edu    print "%s: " % progname, exc
1034961Ssaidi@eecs.umich.edu    sys.exit(1)
1044961Ssaidi@eecs.umich.edu