CMS 3D CMS Logo

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