regress revision 3077
11897Sstever@eecs.umich.edu#! /usr/bin/env python 23077Sstever@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 341897Sstever@eecs.umich.edu 351897Sstever@eecs.umich.edu# 361897Sstever@eecs.umich.edu# Regression invocation: 371897Sstever@eecs.umich.edu# 381897Sstever@eecs.umich.edu# regress \ 391897Sstever@eecs.umich.edu# --workdir poolfs \ 401897Sstever@eecs.umich.edu# --scons-opts 'BATCH=yes USE_MYSQL=no -j 30 -Q' \ 411897Sstever@eecs.umich.edu# --recurse 423077Sstever@eecs.umich.edu 433099Sstever@eecs.umich.eduprogname = os.path.basename(sys.argv[0]) 443099Sstever@eecs.umich.edu 451897Sstever@eecs.umich.eduoptparser = optparse.OptionParser() 461897Sstever@eecs.umich.eduoptparser.add_option('-v', '--verbose', dest='verbose', action='store_true', 473099Sstever@eecs.umich.edu default=False, 483099Sstever@eecs.umich.edu help='echo commands before executing') 491897Sstever@eecs.umich.eduoptparser.add_option('--scratch', dest='scratch', action='store_true', 503099Sstever@eecs.umich.edu default=False, 511897Sstever@eecs.umich.edu help='rebuld from scratch') 521897Sstever@eecs.umich.eduoptparser.add_option('--builds', dest='builds', 531897Sstever@eecs.umich.edu default='ALPHA_SE,ALPHA_FS,MIPS_SE,SPARC_SE', 541897Sstever@eecs.umich.edu help='comma-separated list of builds to test') 551897Sstever@eecs.umich.eduoptparser.add_option('--variants', dest='variants', 561897Sstever@eecs.umich.edu default='opt', 571897Sstever@eecs.umich.edu help='comma-separated list of build variants to test') 581897Sstever@eecs.umich.eduoptparser.add_option('--workdir', dest='workdir', 591897Sstever@eecs.umich.edu help='directory for checked-out source trees') 601897Sstever@eecs.umich.eduoptparser.add_option('--scons-opts', dest='scons_opts', default='', 611897Sstever@eecs.umich.edu help='scons options') 621897Sstever@eecs.umich.eduoptparser.add_option('--no-pull', dest='pull', action='store_false', 631897Sstever@eecs.umich.edu default=True, 641897Sstever@eecs.umich.edu help="don't pull changes from repository") 651897Sstever@eecs.umich.eduoptparser.add_option('--recurse', dest='recurse', action='store_true', 661897Sstever@eecs.umich.edu default=False, 671897Sstever@eecs.umich.edu help='call recursively to get summary up front') 681897Sstever@eecs.umich.edu 691897Sstever@eecs.umich.edu(options, tests) = optparser.parse_args() 701897Sstever@eecs.umich.edu 711897Sstever@eecs.umich.edu 721897Sstever@eecs.umich.edu# split list options on ',' to get Python lists 731897Sstever@eecs.umich.edubuilds = options.builds.split(',') 741897Sstever@eecs.umich.eduvariants = options.variants.split(',') 751897Sstever@eecs.umich.edu 761897Sstever@eecs.umich.edu# Repositories to clone/update 771897Sstever@eecs.umich.edurepos = ['m5'] 781897Sstever@eecs.umich.edu 791897Sstever@eecs.umich.edu# Call os.system() and raise exception if return status is non-zero 801897Sstever@eecs.umich.edudef system(cmd): 813077Sstever@eecs.umich.edu if options.verbose: 823077Sstever@eecs.umich.edu print cmd 833077Sstever@eecs.umich.edu status = os.system(cmd) 843077Sstever@eecs.umich.edu if status != 0: 853077Sstever@eecs.umich.edu upper = (status & 0xff00) >> 8 863077Sstever@eecs.umich.edu lower = (status & 0xff) 873077Sstever@eecs.umich.edu raise OSError, "shell command '%s' failed, status %d:%d" \ 883077Sstever@eecs.umich.edu % (cmd, upper, lower) 893077Sstever@eecs.umich.edu 901897Sstever@eecs.umich.edu# Quote string s so it can be passed as a shell arg 911897Sstever@eecs.umich.edudef shellquote(s): 921897Sstever@eecs.umich.edu if ' ' in s: 931897Sstever@eecs.umich.edu s = "'%s'" % s 941897Sstever@eecs.umich.edu return s 951897Sstever@eecs.umich.edu 961897Sstever@eecs.umich.edu# The '--recurse' option invokes scons once to perform any necessary 971897Sstever@eecs.umich.edu# rebuilds/test runs with the (possibly verbose) output placed in a 98# log file, then (if the buld was successful) returns scons to print a 99# summary of the results. 100if options.recurse: 101 sys.argv.remove('--recurse') # avoid infinite recursion... 102 timestr = datetime.datetime.now().isoformat('-')[:19] 103 logfile = '%s-%s' % (progname, timestr) 104 # quote args for shell 105 qargs = [shellquote(a) for a in sys.argv] 106 # always run the sub-job in verbose mode 107 qargs.append('-v') 108 cmd = '%s > %s 2>&1' % (' '.join(qargs), logfile) 109 try: 110 system(cmd) 111 except OSError, exc: 112 print "Error: recursive invocation failed, aborting." 113 print exc 114 print "=======================" 115 os.system('cat %s' % logfile) 116 sys.exit(1) 117 # recursive call succeeded... re-run to generate summary 118 # don't *re*-build from scratch now 119 options.scratch = False 120 # no need to re-pull since the recursive call shoudl have done that 121 options.pull = False 122 print "Recursive invocation successful, see %s for output." % logfile 123 124try: 125 if options.workdir: 126 if options.verbose: 127 print 'cd', options.workdir 128 os.chdir(options.workdir) 129 130 if options.scratch: 131 for dir in repos: 132 system('rm -rf %s' % dir) 133 system('bk clone /bk/%s' % dir) 134 elif options.pull: 135 for dir in repos: 136 system('cd %s; bk pull' % dir) 137 138 if not tests: 139 print "No tests specified." 140 sys.exit(1) 141 142 if options.verbose: 143 print 'cd m5' 144 os.chdir('m5') 145 146 if 'all' in tests: 147 targets = ['build/%s/tests/%s' % (build, variant) 148 for build in builds 149 for variant in variants] 150 else: 151 targets = ['build/%s/tests/%s/%s' % (build, variant, test) 152 for build in builds 153 for variant in variants 154 for test in tests] 155 156 system('scons %s %s' % (options.scons_opts, ' '.join(targets))) 157 158 sys.exit(0) 159 160except OSError, exc: 161 print "%s: " % progname, exc 162 sys.exit(1) 163