test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MatrixRunner.py
Go to the documentation of this file.
1 
2 import os, sys, time
3 import random
4 
5 from Configuration.PyReleaseValidation.WorkFlow import WorkFlow
6 from Configuration.PyReleaseValidation.WorkFlowRunner import WorkFlowRunner
7 
8 # ================================================================================
9 
11 
12  def __init__(self, wfIn=None, nThrMax=4):
13 
14  self.workFlows = wfIn
15 
16  self.threadList = []
17  self.maxThreads = nThrMax
18 
19  #the directories in which it happened
20  self.runDirs={}
21 
22  def activeThreads(self):
23 
24  nActive = 0
25  for t in self.threadList:
26  if t.isAlive() : nActive += 1
27 
28  return nActive
29 
30 
31  def runTests(self, opt):
32 
33  testList=opt.testList
34  dryRun=opt.dryRun
35  cafVeto=opt.cafVeto
36 
37  startDir = os.getcwd()
38 
39  report=''
40  noRun=(self.maxThreads==0)
41  if noRun:
42  print 'Not running the wf, only creating cfgs and logs'
43  print 'resetting to default number of threads'
44  self.maxThreads=4
45 
46  print 'Running in %s thread(s)' % self.maxThreads
47 
48 
49  for wf in self.workFlows:
50 
51  if testList and float(wf.numId) not in [float(x) for x in testList]: continue
52 
53  item = wf.nameId
54  if os.path.islink(item) : continue # ignore symlinks
55 
56  # make sure we don't run more than the allowed number of threads:
57  while self.activeThreads() >= self.maxThreads:
58  time.sleep(10)
59  continue
60 
61  print '\nPreparing to run %s %s' % (wf.numId, item)
62 
63  current = WorkFlowRunner(wf,noRun,dryRun,cafVeto, opt.dasOptions, opt.jobReports)
64  self.threadList.append(current)
65  current.start()
66  if not dryRun:
67  time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec
68 
69  # wait until all threads are finished
70  while self.activeThreads() > 0:
71  time.sleep(0.5)
72 
73 
74  #wrap up !
75  totpassed=[]
76  totfailed=[]
77  def count(collect,result):
78  #pad with zeros
79  for i in range(len(collect),len(result)):
80  collect.append(0)
81  for i,c in enumerate(result):
82  collect[i]+=c
83 
84  for pingle in self.threadList:
85  pingle.join()
86  try:
87  count(totpassed,pingle.npass)
88  count(totfailed,pingle.nfail)
89  report+=pingle.report
90  self.runDirs[pingle.wf.numId]=pingle.wfDir
91  except Exception, e:
92  msg = "ERROR retrieving info from thread: " + str(e)
93  report += msg
94 
95  report+=' '.join(map(str,totpassed))+' tests passed, '+' '.join(map(str,totfailed))+' failed\n'
96  print report
97 
98  runall_report_name='runall-report-step123-.log'
99  runall_report=open(runall_report_name,'w')
100  runall_report.write(report)
101  runall_report.close()
102  os.chdir(startDir)
103 
104  anyFail=sum(totfailed)
105 
106  return anyFail
107 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
list object
Definition: dbtoconf.py:77