CMS 3D CMS Logo

runall.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import os
00004 import time
00005 import sys
00006 from threading import Thread
00007 
00008 class testit(Thread):
00009     def __init__(self,command):
00010         Thread.__init__(self)
00011         self.command=command
00012         self.status=-1
00013         self.report=''
00014         self.nfail=0
00015         self.npass=0
00016     def run(self):
00017         commandbase=''
00018         for word in self.command.split(' ')[1:]:
00019             commandbase+='%s_'%word
00020         logfile='%s.log' %commandbase[:-1]
00021         logfile = logfile.replace('/','_') # otherwise the path in the args to --cusotmize make trouble
00022         
00023         startime='date %s' %time.asctime()
00024         executable='%s > %s 2>&1' %(self.command,logfile)
00025     
00026         exitcode=os.system(executable)
00027         endtime='date %s' %time.asctime()
00028         tottime='%s-%s'%(endtime,startime)
00029     
00030         if exitcode!=0:
00031             log='%s : FAILED - time: %s s - exit: %s\n' %(self.command,tottime,exitcode)
00032             self.report+='%s\n'%log
00033             self.nfail=1
00034             self.npass=0
00035         else:
00036             log='%s : PASSED - time: %s s - exit: %s\n' %(self.command,tottime,exitcode)
00037             self.report+='%s\n'%log
00038             self.nfail=0
00039             self.npass=1
00040                 
00041 def main(argv) :
00042 
00043     import getopt
00044     
00045     try:
00046         opts, args = getopt.getopt(argv, "", ["nproc=","dohighstat",'hlt','inFile=','intbld'])
00047     except getopt.GetoptError, e:
00048         print "unknown option", str(e)
00049         sys.exit(2)
00050         
00051 # check command line parameter
00052     np=1
00053     doHighStat=0
00054     hlt = False
00055     inFile = None
00056     intBld = False
00057     for opt, arg in opts :
00058         if opt == "--inFile" :
00059             inFile=arg
00060         if opt == "--nproc" :
00061             np=arg
00062         if opt == "--dohighstat" :
00063             doHighStat=1
00064         if opt in ('--hlt',): # note: trailing comma needed for single arg to indicate tuple
00065             hlt = True
00066         if opt in ('--intbld',): # note: trailing comma needed for single arg to indicate tuple
00067             intBld = True
00068 
00069     if hlt:
00070         print "\nWARNING: option --hlt is deprecated as this is now default.\n"
00071 
00072     if inFile:
00073         commands_standard_file=open(inFile,'r')
00074         lines_standard=commands_standard_file.readlines()
00075         commands_standard_file.close()
00076         lines=lines_standard
00077     else:
00078         commands_standard_file=open('cmsDriver_standard_hlt.txt','r')
00079         lines_standard=commands_standard_file.readlines()
00080         commands_standard_file.close()
00081         lines=lines_standard
00082 
00083         if doHighStat==1:
00084             commands_highstat_file=open('cmsDriver_highstats_hlt.txt','r')
00085             lines_highstat=commands_highstat_file.readlines()
00086             commands_highstat_file.close()
00087 
00088             lines=lines+lines_highstat
00089    
00090 
00091     # for the integration builds, check only these samples:
00092     forIB = [ # from the standard_hlt:
00093              'SingleMuPt10', 'SinglePiPt1', 'SingleElectronPt10', 'SingleGammaPt10',
00094              'MinBias', 'QCD_Pt_80_120', 'ZEE', 'BJets_Pt_50_120','TTbar',
00095              # from the highstats_hlt
00096              'SinglePiE50HCAL', 'H130GGgluonfusion', 'QQH120Inv', 'bJpsiX', 
00097              'JpsiMM', 'BsMM', 'UpsMM', 'CJets_Pt_50_120'
00098              ]
00099     
00100     commands=[]
00101     for line in lines:
00102         if ( line[0]!='#' and
00103            line.replace(' ','')!='\n' ):
00104                linecomponents=line.split('@@@')
00105                if intBld and linecomponents[0].strip() not in forIB: continue
00106                command=linecomponents[1][:-1]
00107                commands.append(command)
00108                print 'Will do: '+command
00109         
00110 
00111     nfail=0
00112     npass=0
00113     report=''
00114 
00115     clist = []
00116     cdone = []
00117     i=0
00118     print 'Running in %s thread(s)' %np
00119 
00120     for command in commands:
00121         print 'Preparing to run %s' %command 
00122         current = testit(command)
00123         clist.append(current)
00124         cdone.append(0)
00125         current.start()
00126 
00127         i=int(np)
00128         while (int(i) >= int(np)): 
00129             i=0
00130             time.sleep(10)
00131             alen=len(cdone)
00132             for j in range(0,alen):
00133                 mystat=cdone[j]
00134                 pingle=clist[j]
00135                 isA=pingle.isAlive()
00136                 if ( isA ): i+=1
00137                 if ( not isA and mystat==0 ): 
00138                     nfail+=pingle.nfail
00139                     npass+=pingle.npass
00140                     report+=pingle.report
00141                     cdone[j]=1
00142                     print pingle.report
00143 #            print 'Number of running threads: %s' % i        
00144 
00145     alen=len(cdone)
00146     for j in range(0,alen):
00147         pingle=clist[j]
00148         mystat=cdone[j]
00149         if ( mystat == 0 ):  
00150             pingle.join()
00151             nfail+=pingle.nfail
00152             npass+=pingle.npass
00153             report+=pingle.report
00154             print pingle.report
00155         
00156     report+='\n %s tests passed, %s failed \n' %(npass,nfail)
00157     print report
00158     
00159     runall_report_name='runall-report.log'
00160     runall_report=open(runall_report_name,'w')
00161     runall_report.write(report)
00162     runall_report.close()
00163     
00164     if hlt:
00165         print "\nWARNING: option --hlt is deprecated as this is now default.\n"
00166 
00167 if __name__ == '__main__' :
00168     main(sys.argv[1:])

Generated on Tue Jun 9 17:26:58 2009 for CMSSW by  doxygen 1.5.4