Go to the documentation of this file.00001
00002 import os, sys, time
00003 import random
00004
00005 from Configuration.PyReleaseValidation.WorkFlow import WorkFlow
00006 from Configuration.PyReleaseValidation.WorkFlowRunner import WorkFlowRunner
00007
00008
00009
00010 class MatrixRunner(object):
00011
00012 def __init__(self, wfIn=None, nThrMax=4):
00013
00014 self.workFlows = wfIn
00015
00016 self.threadList = []
00017 self.maxThreads = int(nThrMax)
00018
00019
00020 def activeThreads(self):
00021
00022 nActive = 0
00023 for t in self.threadList:
00024 if t.isAlive() : nActive += 1
00025
00026 return nActive
00027
00028
00029 def runTests(self, testList=None):
00030
00031 startDir = os.getcwd()
00032
00033 report=''
00034 if self.maxThreads == 0:
00035 print 'resetting to default number of threads'
00036 self.maxThreads=4
00037
00038 print 'Running in %s thread(s)' % self.maxThreads
00039
00040
00041 for wf in self.workFlows:
00042
00043 if testList and float(wf.numId) not in [float(x) for x in testList]: continue
00044
00045 item = wf.nameId
00046 if os.path.islink(item) : continue
00047
00048
00049 while self.activeThreads() >= self.maxThreads:
00050 time.sleep(10)
00051 continue
00052
00053 print '\nPreparing to run %s %s' % (wf.numId, item)
00054
00055
00056
00057
00058 current = WorkFlowRunner(wf)
00059 self.threadList.append(current)
00060 current.start()
00061 time.sleep(random.randint(1,5))
00062
00063
00064 while self.activeThreads() > 0:
00065 time.sleep(5)
00066
00067
00068 nfail1 = 0
00069 nfail2 = 0
00070 nfail3 = 0
00071 nfail4 = 0
00072 npass = 0
00073 npass1 = 0
00074 npass2 = 0
00075 npass3 = 0
00076 npass4 = 0
00077 for pingle in self.threadList:
00078 pingle.join()
00079 try:
00080 nfail1 += pingle.nfail[0]
00081 nfail2 += pingle.nfail[1]
00082 nfail3 += pingle.nfail[2]
00083 nfail4 += pingle.nfail[3]
00084 npass1 += pingle.npass[0]
00085 npass2 += pingle.npass[1]
00086 npass3 += pingle.npass[2]
00087 npass4 += pingle.npass[3]
00088 npass += npass1+npass2+npass3+npass4
00089 report += pingle.report
00090
00091 except Exception, e:
00092 msg = "ERROR retrieving info from thread: " + str(e)
00093 nfail1 += 1
00094 nfail2 += 1
00095 nfail3 += 1
00096 nfail4 += 1
00097 report += msg
00098 print msg
00099
00100 report+='\n %s %s %s %s tests passed, %s %s %s %s failed\n' %(npass1, npass2, npass3, npass4, nfail1, nfail2, nfail3, nfail4)
00101 print report
00102
00103 runall_report_name='runall-report-step123-.log'
00104 runall_report=open(runall_report_name,'w')
00105 runall_report.write(report)
00106 runall_report.close()
00107
00108 os.chdir(startDir)
00109
00110 return
00111