regress revision 3099
1360SN/A#! /usr/bin/env python
210850SGiacomo.Gabrielli@arm.com# Copyright (c) 2005-2006 The Regents of The University of Michigan
310796Sbrandon.potter@amd.com# All rights reserved.
410027SChris.Adeniyi-Jones@arm.com#
510027SChris.Adeniyi-Jones@arm.com# Redistribution and use in source and binary forms, with or without
610027SChris.Adeniyi-Jones@arm.com# modification, are permitted provided that the following conditions are
710027SChris.Adeniyi-Jones@arm.com# met: redistributions of source code must retain the above copyright
810027SChris.Adeniyi-Jones@arm.com# notice, this list of conditions and the following disclaimer;
910027SChris.Adeniyi-Jones@arm.com# redistributions in binary form must reproduce the above copyright
1010027SChris.Adeniyi-Jones@arm.com# notice, this list of conditions and the following disclaimer in the
1110027SChris.Adeniyi-Jones@arm.com# documentation and/or other materials provided with the distribution;
1210027SChris.Adeniyi-Jones@arm.com# neither the name of the copyright holders nor the names of its
1310027SChris.Adeniyi-Jones@arm.com# contributors may be used to endorse or promote products derived from
1410027SChris.Adeniyi-Jones@arm.com# this software without specific prior written permission.
151458SN/A#
16360SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17360SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18360SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19360SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20360SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21360SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22360SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23360SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24360SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25360SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26360SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27360SN/A#
28360SN/A# Authors: Steve Reinhardt
29360SN/A
30360SN/Aimport sys
31360SN/Aimport os
32360SN/Aimport optparse
33360SN/Aimport datetime
34360SN/A
35360SN/Aprogname = os.path.basename(sys.argv[0])
36360SN/A
37360SN/Aoptparser = optparse.OptionParser()
38360SN/Aoptparser.add_option('-v', '--verbose', dest='verbose', action='store_true',
39360SN/A                     default=False,
402665Ssaidi@eecs.umich.edu                     help='echo commands before executing')
412665Ssaidi@eecs.umich.eduoptparser.add_option('--builds', dest='builds',
422665Ssaidi@eecs.umich.edu                     default='ALPHA_SE,ALPHA_FS,MIPS_SE,SPARC_SE',
43360SN/A                     help='comma-separated list of build targets to test  '
44360SN/A                     " (default: '%default')" )
451354SN/Aoptparser.add_option('--variants', dest='variants',
461354SN/A                     default='opt',
47360SN/A                     help='comma-separated list of build variants to test '
4812018Sandreas.sandberg@arm.com                     " (default: '%default')" )
4912018Sandreas.sandberg@arm.comoptparser.add_option('--scons-opts', dest='scons_opts', default='',
5012018Sandreas.sandberg@arm.com                     help='scons options', metavar='OPTS')
5112018Sandreas.sandberg@arm.com
5212018Sandreas.sandberg@arm.com(options, tests) = optparser.parse_args()
5312018Sandreas.sandberg@arm.com
5412018Sandreas.sandberg@arm.com
552064SN/A# split list options on ',' to get Python lists
5612018Sandreas.sandberg@arm.combuilds = options.builds.split(',')
5712018Sandreas.sandberg@arm.comvariants = options.variants.split(',')
5812018Sandreas.sandberg@arm.com
5912018Sandreas.sandberg@arm.com# Call os.system() and raise exception if return status is non-zero
6012018Sandreas.sandberg@arm.comdef system(cmd):
6112018Sandreas.sandberg@arm.com    if options.verbose:
6211799Sbrandon.potter@amd.com        print cmd
6312018Sandreas.sandberg@arm.com    status = os.system(cmd)
6412018Sandreas.sandberg@arm.com    if status != 0:
6512018Sandreas.sandberg@arm.com        upper = (status & 0xff00) >> 8
6612018Sandreas.sandberg@arm.com        lower = (status & 0xff)
6712018Sandreas.sandberg@arm.com        raise OSError, "shell command '%s' failed, status %d:%d" \
6812018Sandreas.sandberg@arm.com              % (cmd, upper, lower)
6911799Sbrandon.potter@amd.com
70360SN/A# Quote string s so it can be passed as a shell arg
71360SN/Adef shellquote(s):
72360SN/A    if ' ' in s:
73360SN/A        s = "'%s'" % s
74360SN/A    return s
75360SN/A
761809SN/Atry:
7711800Sbrandon.potter@amd.com    if not tests:
7811392Sbrandon.potter@amd.com        print "No tests specified."
791809SN/A        sys.exit(1)
8011392Sbrandon.potter@amd.com
8111383Sbrandon.potter@amd.com    if 'all' in tests:
823113Sgblack@eecs.umich.edu	targets = ['build/%s/tests/%s' % (build, variant)
8311799Sbrandon.potter@amd.com		   for build in builds
8411759Sbrandon.potter@amd.com		   for variant in variants]
8511812Sbaz21@cam.ac.uk    else:
8611812Sbaz21@cam.ac.uk	targets = ['build/%s/tests/%s/%s' % (build, variant, test)
8711799Sbrandon.potter@amd.com		   for build in builds
888229Snate@binkert.org		   for variant in variants
898229Snate@binkert.org		   for test in tests]
9011594Santhony.gutierrez@amd.com
917075Snate@binkert.org    system('scons %s %s' % (options.scons_opts, ' '.join(targets)))
928229Snate@binkert.org
9311856Sbrandon.potter@amd.com    sys.exit(0)
947075Snate@binkert.org
95360SN/Aexcept OSError, exc:
9611886Sbrandon.potter@amd.com    print "%s: " % progname, exc
9711800Sbrandon.potter@amd.com    sys.exit(1)
9811392Sbrandon.potter@amd.com