File indexing completed on 2024-12-01 23:40:06
0001
0002
0003 import os
0004 import time
0005 import sys
0006 from threading import Thread
0007
0008 class testit(Thread):
0009 def __init__(self,command):
0010 Thread.__init__(self)
0011 self.command=command
0012 self.status=-1
0013 self.report=''
0014 self.nfail=0
0015 self.npass=0
0016 def run(self):
0017 commandbase=''
0018 for word in self.command.split(' ')[1:]:
0019 commandbase+='%s_'%word
0020 logfile='%s.log' %commandbase[:-1]
0021 logfile = logfile.replace('/','_')
0022
0023 startime='date %s' %time.asctime()
0024 executable='%s > %s 2>&1' %(self.command,logfile)
0025
0026 exitcode=os.system(executable)
0027 endtime='date %s' %time.asctime()
0028 tottime='%s-%s'%(endtime,startime)
0029
0030 if exitcode!=0:
0031 log='%s : FAILED - time: %s s - exit: %s\n' %(self.command,tottime,exitcode)
0032 self.report+='%s\n'%log
0033 self.nfail=1
0034 self.npass=0
0035 else:
0036 log='%s : PASSED - time: %s s - exit: %s\n' %(self.command,tottime,exitcode)
0037 self.report+='%s\n'%log
0038 self.nfail=0
0039 self.npass=1
0040
0041 def main(argv) :
0042
0043 import getopt
0044
0045 try:
0046 opts, args = getopt.getopt(argv, "", ["nproc=","dohighstat",'hlt','inFile=','intbld'])
0047 except getopt.GetoptError as e:
0048 print("unknown option", str(e))
0049 sys.exit(2)
0050
0051
0052 np=1
0053 doHighStat=0
0054 hlt = False
0055 inFile = None
0056 intBld = False
0057 for opt, arg in opts :
0058 if opt == "--inFile" :
0059 inFile=arg
0060 if opt == "--nproc" :
0061 np=arg
0062 if opt == "--dohighstat" :
0063 doHighStat=1
0064 if opt in ('--hlt',):
0065 hlt = True
0066 if opt in ('--intbld',):
0067 intBld = True
0068
0069 if hlt:
0070 print("\nWARNING: option --hlt is deprecated as this is now default.\n")
0071
0072 if inFile:
0073 commands_standard_file=open(inFile,'r')
0074 lines_standard=commands_standard_file.readlines()
0075 commands_standard_file.close()
0076 lines=lines_standard
0077 else:
0078 commands_standard_file=open('cmsDriver_standard_hlt.txt','r')
0079 lines_standard=commands_standard_file.readlines()
0080 commands_standard_file.close()
0081 lines=lines_standard
0082
0083 if doHighStat==1:
0084 commands_highstat_file=open('cmsDriver_highstats_hlt.txt','r')
0085 lines_highstat=commands_highstat_file.readlines()
0086 commands_highstat_file.close()
0087
0088 lines=lines+lines_highstat
0089
0090
0091
0092 forIB = [
0093 'SingleMuPt10', 'SinglePiPt1', 'SingleElectronPt10', 'SingleGammaPt10',
0094 'MinBias', 'QCD_Pt_80_120', 'ZEE', 'BJets_Pt_50_120','TTbar',
0095
0096 'SinglePiE50HCAL', 'H130GGgluonfusion', 'QQH120Inv', 'bJpsiX',
0097 'JpsiMM', 'BsMM', 'UpsMM', 'CJets_Pt_50_120'
0098 ]
0099
0100 commands=[]
0101 for line in lines:
0102 if ( line[0]!='#' and
0103 line.replace(' ','')!='\n' ):
0104 linecomponents=line.split('@@@')
0105 if intBld and linecomponents[0].strip() not in forIB: continue
0106 command=linecomponents[1][:-1]
0107 commands.append(command)
0108 print('Will do: '+command)
0109
0110
0111 nfail=0
0112 npass=0
0113 report=''
0114
0115 clist = []
0116 cdone = []
0117 i=0
0118 print('Running in %s thread(s)' %np)
0119
0120 for command in commands:
0121 print('Preparing to run %s' %command)
0122 current = testit(command)
0123 clist.append(current)
0124 cdone.append(0)
0125 current.start()
0126
0127 i=int(np)
0128 while (int(i) >= int(np)):
0129 i=0
0130 time.sleep(10)
0131 alen=len(cdone)
0132 for j in range(0,alen):
0133 mystat=cdone[j]
0134 pingle=clist[j]
0135 isA=pingle.is_alive()
0136 if ( isA ): i+=1
0137 if ( not isA and mystat==0 ):
0138 nfail+=pingle.nfail
0139 npass+=pingle.npass
0140 report+=pingle.report
0141 cdone[j]=1
0142 print(pingle.report)
0143
0144
0145 alen=len(cdone)
0146 for j in range(0,alen):
0147 pingle=clist[j]
0148 mystat=cdone[j]
0149 if ( mystat == 0 ):
0150 pingle.join()
0151 nfail+=pingle.nfail
0152 npass+=pingle.npass
0153 report+=pingle.report
0154 print(pingle.report)
0155
0156 report+='\n %s tests passed, %s failed \n' %(npass,nfail)
0157 print(report)
0158
0159 runall_report_name='runall-report.log'
0160 runall_report=open(runall_report_name,'w')
0161 runall_report.write(report)
0162 runall_report.close()
0163
0164 if hlt:
0165 print("\nWARNING: option --hlt is deprecated as this is now default.\n")
0166
0167 if __name__ == '__main__' :
0168 main(sys.argv[1:])