CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
addOnTests.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import os
4 import time
5 import sys
6 import re
7 import random
8 from threading import Thread
9 
10 scriptPath = os.path.dirname( os.path.abspath(sys.argv[0]) )
11 if scriptPath not in sys.path:
12  sys.path.append(scriptPath)
13 
14 
15 class testit(Thread):
16  def __init__(self,dirName, commandList):
17  Thread.__init__(self)
18  self.dirName = dirName
19  self.commandList = commandList
20  self.status=-1
21  self.report=''
22  self.nfail=[]
23  self.npass=[]
24 
25  return
26 
27  def run(self):
28 
29  startime='date %s' %time.asctime()
30  exitCodes = []
31 
32  for command in self.commandList:
33 
34  if not os.path.exists(self.dirName):
35  os.makedirs(self.dirName)
36 
37  commandbase = command.replace(' ','_').replace('/','_')
38  logfile='%s.log' % commandbase[:150].replace("'",'').replace('"','').replace('../','')
39 
40  executable = 'cd '+self.dirName+'; '+command+' > '+logfile+' 2>&1'
41 
42  ret = os.system(executable)
43  exitCodes.append( ret )
44 
45  endtime='date %s' %time.asctime()
46  tottime='%s-%s'%(endtime,startime)
47 
48  for i in range(len(self.commandList)):
49  command = self.commandList[i]
50  exitcode = exitCodes[i]
51  if exitcode != 0:
52  log='%s : FAILED - time: %s s - exit: %s\n' %(command,tottime,exitcode)
53  self.report+='%s\n'%log
54  self.nfail.append(1)
55  self.npass.append(0)
56  else:
57  log='%s : PASSED - time: %s s - exit: %s\n' %(command,tottime,exitcode)
58  self.report+='%s\n'%log
59  self.nfail.append(0)
60  self.npass.append(1)
61 
62  return
63 
65 
66  def __init__(self, nThrMax=4):
67 
68  self.threadList = []
69  self.maxThreads = nThrMax
70  self.prepare()
71 
72  return
73 
74  def activeThreads(self):
75 
76  nActive = 0
77  for t in self.threadList:
78  if t.isAlive() : nActive += 1
79 
80  return nActive
81 
82  def prepare(self):
83 
84  self.devPath = os.environ['LOCALRT'] + '/src/'
85  self.relPath = self.devPath
86  if os.environ.has_key('CMSSW_RELEASE_BASE') and (os.environ['CMSSW_RELEASE_BASE'] != ""): self.relPath = os.environ['CMSSW_RELEASE_BASE'] + '/src/'
87 
88  lines = { 'read312RV' : ['cmsRun '+self.file2Path('Utilities/ReleaseScripts/scripts/read312RV_cfg.py')],
89  'fastsim1' : ['cmsRun '+self.file2Path('FastSimulation/Configuration/test/IntegrationTestFake_cfg.py')],
90  'fastsim2' : ['cmsRun '+self.file2Path('FastSimulation/Configuration/test/IntegrationTest_cfg.py')],
91  #'fastsim3' : ['cmsRun '+self.file2Path('FastSimulation/Configuration/test/ExampleWithHLT_1E31_cfg.py')],
92  'fastsim4' : ['cmsRun '+self.file2Path('FastSimulation/Configuration/test/IntegrationTestWithHLT_cfg.py')],
93  'pat1' : ['cmsRun '+self.file2Path('PhysicsTools/PatAlgos/test/IntegrationTest_cfg.py')],
94  }
95 
96  hltTests = {
97  'hlt_mc_Fake' : ['cmsDriver.py TTbar_Tauola_8TeV_cfi -s GEN,SIM,DIGI,L1,DIGI2RAW --mc --scenario=pp -n 10 --conditions auto:run1_mc_Fake --relval 9000,50 --datatier "GEN-SIM-RAW" --eventcontent RAWSIM --customise=HLTrigger/Configuration/CustomConfigs.L1T --fileout file:RelVal_Raw_Fake_MC.root',
98  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnMc_HLT_Fake.py'),
99  'cmsDriver.py RelVal -s HLT:Fake,RAW2DIGI,L1Reco,RECO --mc --scenario=pp -n 10 --conditions auto:run1_mc_Fake --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --processName=HLTRECO --filein file:RelVal_Raw_Fake_MC.root --fileout file:RelVal_Raw_Fake_MC_HLT_RECO.root'],
100  'hlt_mc_FULL' : ['cmsDriver.py TTbar_Tauola_13TeV_cfi -s GEN,SIM,DIGI,L1,DIGI2RAW --mc --scenario=pp -n 10 --conditions auto:run2_mc_FULL --relval 9000,50 --datatier "GEN-SIM-RAW" --eventcontent RAWSIM --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_FULL_MC.root',
101  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnMc_HLT_FULL.py'),
102  'cmsDriver.py RelVal -s HLT:FULL,RAW2DIGI,L1Reco,RECO --mc --scenario=pp -n 10 --conditions auto:run2_mc_FULL --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_FULL_MC.root --fileout file:RelVal_Raw_FULL_MC_HLT_RECO.root'],
103  'hlt_mc_GRun' : ['cmsDriver.py TTbar_Tauola_13TeV_cfi -s GEN,SIM,DIGI,L1,DIGI2RAW --mc --scenario=pp -n 10 --conditions auto:run2_mc_GRun --relval 9000,50 --datatier "GEN-SIM-RAW" --eventcontent RAWSIM --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_GRun_MC.root',
104  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnMc_HLT_GRun.py'),
105  'cmsDriver.py RelVal -s HLT:GRun,RAW2DIGI,L1Reco,RECO --mc --scenario=pp -n 10 --conditions auto:run2_mc_GRun --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_GRun_MC.root --fileout file:RelVal_Raw_GRun_MC_HLT_RECO.root'],
106  'hlt_mc_HIon' : ['cmsDriver.py TTbar_Tauola_13TeV_cfi -s GEN,SIM,DIGI,L1,DIGI2RAW --mc --scenario=HeavyIons -n 10 --conditions auto:run2_mc_HIon --relval 9000,50 --datatier "GEN-SIM-RAW" --eventcontent RAWSIM --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_HIon_MC.root',
107  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnMc_HLT_HIon.py'),
108  'cmsDriver.py RelVal -s HLT:HIon,RAW2DIGI,L1Reco,RECO --mc --scenario=HeavyIons -n 10 --conditions auto:run2_mc_HIon --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_HIon_MC.root --fileout file:RelVal_Raw_HIon_MC_HLT_RECO.root'],
109  'hlt_mc_PIon' : ['cmsDriver.py TTbar_Tauola_13TeV_cfi -s GEN,SIM,DIGI,L1,DIGI2RAW --mc --scenario=pp -n 10 --conditions auto:run2_mc_PIon --relval 9000,50 --datatier "GEN-SIM-RAW" --eventcontent RAWSIM --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_PIon_MC.root',
110  'cmsRun ' + self.file2Path('HLTrigger/Configuration/test/OnMc_HLT_PIon.py'),
111  'cmsDriver.py RelVal -s HLT:PIon,RAW2DIGI,L1Reco,RECO --mc --scenario=pp -n 10 --conditions auto:run2_mc_PIon --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_PIon_MC.root --fileout file:RelVal_Raw_PIon_MC_HLT_RECO.root'],
112  'hlt_data_Fake' : ['cmsDriver.py RelVal -s L1REPACK:GT1 --data --scenario=pp -n 10 --conditions auto:run1_hlt_Fake --relval 9000,50 --datatier "RAW" --eventcontent RAW --customise=HLTrigger/Configuration/CustomConfigs.L1T --fileout file:RelVal_Raw_Fake_DATA.root --filein /store/data/Run2012A/MuEG/RAW/v1/000/191/718/14932935-E289-E111-830C-5404A6388697.root',
113  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnData_HLT_Fake.py'),
114  'cmsDriver.py RelVal -s HLT:Fake,RAW2DIGI,L1Reco,RECO --data --scenario=pp -n 10 --conditions auto:run1_data_Fake --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --processName=HLTRECO --filein file:RelVal_Raw_Fake_DATA.root --fileout file:RelVal_Raw_Fake_DATA_HLT_RECO.root'],
115  'hlt_data_FULL' : ['cmsDriver.py RelVal -s L1REPACK:GCTGT --data --scenario=pp -n 10 --conditions auto:run2_hlt_FULL --relval 9000,50 --datatier "RAW" --eventcontent RAW --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_FULL_DATA.root --filein /store/data/Run2012A/MuEG/RAW/v1/000/191/718/14932935-E289-E111-830C-5404A6388697.root',
116  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnData_HLT_FULL.py'),
117  'cmsDriver.py RelVal -s HLT:FULL,RAW2DIGI,L1Reco,RECO --data --scenario=pp -n 10 --conditions auto:run2_data_FULL --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_FULL_DATA.root --fileout file:RelVal_Raw_FULL_DATA_HLT_RECO.root'],
118  'hlt_data_GRun' : ['cmsDriver.py RelVal -s L1REPACK:GCTGT --data --scenario=pp -n 10 --conditions auto:run2_hlt_GRun --relval 9000,50 --datatier "RAW" --eventcontent RAW --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_GRun_DATA.root --filein /store/data/Run2012A/MuEG/RAW/v1/000/191/718/14932935-E289-E111-830C-5404A6388697.root',
119  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnData_HLT_GRun.py'),
120  'cmsDriver.py RelVal -s HLT:GRun,RAW2DIGI,L1Reco,RECO --data --scenario=pp -n 10 --conditions auto:run2_data_GRun --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_GRun_DATA.root --fileout file:RelVal_Raw_GRun_DATA_HLT_RECO.root'],
121  'hlt_data_HIon' : ['cmsDriver.py RelVal -s L1REPACK:GCTGT --data --scenario=HeavyIons -n 10 --conditions auto:run2_hlt_HIon --relval 9000,50 --datatier "RAW" --eventcontent RAW --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --fileout file:RelVal_Raw_HIon_DATA.root --filein /store/hidata/HIRun2011/HIHighPt/RAW/v1/000/182/838/F20AAF66-F71C-E111-9704-BCAEC532971D.root',
122  'cmsRun '+self.file2Path('HLTrigger/Configuration/test/OnData_HLT_HIon.py'),
123  'cmsDriver.py RelVal -s HLT:HIon,RAW2DIGI,L1Reco,RECO --data --scenario=HeavyIons -n 10 --conditions auto:run2_data_HIon --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_HIon_DATA.root --fileout file:RelVal_Raw_HIon_DATA_HLT_RECO.root'],
124  'hlt_data_PIon' : ['cmsDriver.py RelVal -s L1REPACK:GCTGT --data --scenario=pp -n 10 --conditions auto:run2_hlt_PIon --relval 9000,50 --datatier "RAW" --customise=HLTrigger/Configuration/CustomConfigs.L1T --customise SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --eventcontent RAW --fileout file:RelVal_Raw_PIon_DATA.root --filein /store/data/Run2012A/MuEG/RAW/v1/000/191/718/14932935-E289-E111-830C-5404A6388697.root',
125  'cmsRun ' + self.file2Path('HLTrigger/Configuration/test/OnData_HLT_PIon.py'),
126  'cmsDriver.py RelVal -s HLT:PIon,RAW2DIGI,L1Reco,RECO --data --scenario=pp -n 10 --conditions auto:run2_data_PIon --relval 9000,50 --datatier "RAW-HLT-RECO" --eventcontent FEVTDEBUGHLT --customise=HLTrigger/Configuration/CustomConfigs.L1THLT --customise=SLHCUpgradeSimulations/Configuration/postLS1Customs.customisePostLS1 --magField 38T_PostLS1 --processName=HLTRECO --filein file:RelVal_Raw_PIon_DATA.root --fileout file:RelVal_Raw_PIon_DATA_HLT_RECO.root'],
127  }
128 
129  self.commands={}
130  for dirName, command in lines.items():
131  self.commands[dirName] = command
132 
133  for dirName, commandList in hltTests.items():
134  self.commands[dirName] = commandList
135  return
136 
137  def dumpTest(self):
138  print ",".join(self.commands.keys())
139  return
140 
141  def file2Path(self,rFile):
142 
143  fullPath = self.relPath + rFile
144  if os.path.exists(self.devPath + rFile): fullPath = self.devPath + rFile
145  return fullPath
146 
147  def runTests(self, testList = None):
148 
149  actDir = os.getcwd()
150 
151  if not os.path.exists('addOnTests'):
152  os.makedirs('addOnTests')
153  os.chdir('addOnTests')
154 
155  nfail=0
156  npass=0
157  report=''
158 
159  print 'Running in %s thread(s)' % self.maxThreads
160 
161  for dirName, command in self.commands.items():
162 
163  if testList and not dirName in testList:
164  del self.commands[dirName]
165  continue
166 
167  # make sure we don't run more than the allowed number of threads:
168  while self.activeThreads() >= self.maxThreads:
169  time.sleep(10)
170  continue
171 
172  print 'Preparing to run %s' % str(command)
173  current = testit(dirName, command)
174  self.threadList.append(current)
175  current.start()
176  time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec
177 
178  # wait until all threads are finished
179  while self.activeThreads() > 0:
180  time.sleep(5)
181 
182  # all threads are done now, check status ...
183  for pingle in self.threadList:
184  pingle.join()
185  for f in pingle.nfail: nfail += f
186  for p in pingle.npass: npass += p
187  report += pingle.report
188  print pingle.report
189  sys.stdout.flush()
190 
191  reportSumm = '\n %s tests passed, %s failed \n' %(npass,nfail)
192  print reportSumm
193 
194  runall_report_name='runall-report.log'
195  runall_report=open(runall_report_name,'w')
196  runall_report.write(report+reportSumm)
197  runall_report.close()
198 
199  # get the logs to the logs dir:
200  print '==> in :', os.getcwd()
201  print ' going to copy log files to logs dir ...'
202  if not os.path.exists('logs'):
203  os.makedirs('logs')
204  for dirName in self.commands:
205  cmd = "for L in `ls "+dirName+"/*.log`; do cp $L logs/cmsDriver-`dirname $L`_`basename $L` ; done"
206  print "going to ",cmd
207  os.system(cmd)
208 
209  import pickle
210  pickle.dump(self.commands, open('logs/addOnTests.pkl', 'w') )
211 
212  os.chdir(actDir)
213 
214  return
215 
216  def upload(self, tgtDir):
217 
218  print "in ", os.getcwd()
219 
220  if not os.path.exists(tgtDir):
221  os.makedirs(tgtDir)
222 
223  cmd = 'tar cf - addOnTests.log addOnTests/logs | (cd '+tgtDir+' ; tar xf - ) '
224  try:
225  print 'executing: ',cmd
226  ret = os.system(cmd)
227  if ret != 0:
228  print "ERROR uploading logs:", ret, cmd
229  except Exception, e:
230  print "EXCEPTION while uploading addOnTest-logs : ", str(e)
231 
232  return
233 
234 
235 def main(argv) :
236 
237  import getopt
238 
239  try:
240  opts, args = getopt.getopt(argv, "dj:t:", ["nproc=", 'uploadDir=', 'tests=','noRun','dump'])
241  except getopt.GetoptError, e:
242  print "unknown option", str(e)
243  sys.exit(2)
244 
245  np = 4
246  uploadDir = None
247  runTests = True
248  testList = None
249  dump = False
250  for opt, arg in opts :
251  if opt in ('-j', "--nproc" ):
252  np=int(arg)
253  if opt in ("--uploadDir", ):
254  uploadDir = arg
255  if opt in ('--noRun', ):
256  runTests = False
257  if opt in ('-d','--dump', ):
258  dump = True
259  if opt in ('-t','--tests', ):
260  testList = arg.split(",")
261 
262  tester = StandardTester(np)
263  if dump:
264  tester.dumpTest()
265  else:
266  if runTests:
267  tester.runTests(testList)
268  if uploadDir:
269  tester.upload(uploadDir)
270  return
271 
272 if __name__ == '__main__' :
273  main(sys.argv[1:])
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
list object
Definition: dbtoconf.py:77
Definition: main.py:1