CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
runall.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import os
4 import time
5 import sys
6 from threading import Thread
7 
8 class testit(Thread):
9  def __init__(self,command):
10  Thread.__init__(self)
11  self.command=command
12  self.status=-1
13  self.report=''
14  self.nfail=0
15  self.npass=0
16  def run(self):
17  commandbase=''
18  for word in self.command.split(' ')[1:]:
19  commandbase+='%s_'%word
20  logfile='%s.log' %commandbase[:-1]
21  logfile = logfile.replace('/','_') # otherwise the path in the args to --cusotmize make trouble
22 
23  startime='date %s' %time.asctime()
24  executable='%s > %s 2>&1' %(self.command,logfile)
25 
26  exitcode=os.system(executable)
27  endtime='date %s' %time.asctime()
28  tottime='%s-%s'%(endtime,startime)
29 
30  if exitcode!=0:
31  log='%s : FAILED - time: %s s - exit: %s\n' %(self.command,tottime,exitcode)
32  self.report+='%s\n'%log
33  self.nfail=1
34  self.npass=0
35  else:
36  log='%s : PASSED - time: %s s - exit: %s\n' %(self.command,tottime,exitcode)
37  self.report+='%s\n'%log
38  self.nfail=0
39  self.npass=1
40 
41 def main(argv) :
42 
43  import getopt
44 
45  try:
46  opts, args = getopt.getopt(argv, "", ["nproc=","dohighstat",'hlt','inFile=','intbld'])
47  except getopt.GetoptError, e:
48  print "unknown option", str(e)
49  sys.exit(2)
50 
51 # check command line parameter
52  np=1
53  doHighStat=0
54  hlt = False
55  inFile = None
56  intBld = False
57  for opt, arg in opts :
58  if opt == "--inFile" :
59  inFile=arg
60  if opt == "--nproc" :
61  np=arg
62  if opt == "--dohighstat" :
63  doHighStat=1
64  if opt in ('--hlt',): # note: trailing comma needed for single arg to indicate tuple
65  hlt = True
66  if opt in ('--intbld',): # note: trailing comma needed for single arg to indicate tuple
67  intBld = True
68 
69  if hlt:
70  print "\nWARNING: option --hlt is deprecated as this is now default.\n"
71 
72  if inFile:
73  commands_standard_file=open(inFile,'r')
74  lines_standard=commands_standard_file.readlines()
75  commands_standard_file.close()
76  lines=lines_standard
77  else:
78  commands_standard_file=open('cmsDriver_standard_hlt.txt','r')
79  lines_standard=commands_standard_file.readlines()
80  commands_standard_file.close()
81  lines=lines_standard
82 
83  if doHighStat==1:
84  commands_highstat_file=open('cmsDriver_highstats_hlt.txt','r')
85  lines_highstat=commands_highstat_file.readlines()
86  commands_highstat_file.close()
87 
88  lines=lines+lines_highstat
89 
90 
91  # for the integration builds, check only these samples:
92  forIB = [ # from the standard_hlt:
93  'SingleMuPt10', 'SinglePiPt1', 'SingleElectronPt10', 'SingleGammaPt10',
94  'MinBias', 'QCD_Pt_80_120', 'ZEE', 'BJets_Pt_50_120','TTbar',
95  # from the highstats_hlt
96  'SinglePiE50HCAL', 'H130GGgluonfusion', 'QQH120Inv', 'bJpsiX',
97  'JpsiMM', 'BsMM', 'UpsMM', 'CJets_Pt_50_120'
98  ]
99 
100  commands=[]
101  for line in lines:
102  if ( line[0]!='#' and
103  line.replace(' ','')!='\n' ):
104  linecomponents=line.split('@@@')
105  if intBld and linecomponents[0].strip() not in forIB: continue
106  command=linecomponents[1][:-1]
107  commands.append(command)
108  print 'Will do: '+command
109 
110 
111  nfail=0
112  npass=0
113  report=''
114 
115  clist = []
116  cdone = []
117  i=0
118  print 'Running in %s thread(s)' %np
119 
120  for command in commands:
121  print 'Preparing to run %s' %command
122  current = testit(command)
123  clist.append(current)
124  cdone.append(0)
125  current.start()
126 
127  i=int(np)
128  while (int(i) >= int(np)):
129  i=0
130  time.sleep(10)
131  alen=len(cdone)
132  for j in range(0,alen):
133  mystat=cdone[j]
134  pingle=clist[j]
135  isA=pingle.isAlive()
136  if ( isA ): i+=1
137  if ( not isA and mystat==0 ):
138  nfail+=pingle.nfail
139  npass+=pingle.npass
140  report+=pingle.report
141  cdone[j]=1
142  print pingle.report
143 # print 'Number of running threads: %s' % i
144 
145  alen=len(cdone)
146  for j in range(0,alen):
147  pingle=clist[j]
148  mystat=cdone[j]
149  if ( mystat == 0 ):
150  pingle.join()
151  nfail+=pingle.nfail
152  npass+=pingle.npass
153  report+=pingle.report
154  print pingle.report
155 
156  report+='\n %s tests passed, %s failed \n' %(npass,nfail)
157  print report
158 
159  runall_report_name='runall-report.log'
160  runall_report=open(runall_report_name,'w')
161  runall_report.write(report)
162  runall_report.close()
163 
164  if hlt:
165  print "\nWARNING: option --hlt is deprecated as this is now default.\n"
166 
167 if __name__ == '__main__' :
168  main(sys.argv[1:])
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
def __init__
Definition: runall.py:9
def main
Definition: runall.py:41