source: branches/testScripts/NBcbcRunTimes.py @ 820

Last change on this file since 820 was 820, checked in by jpfasano, 12 years ago

modified the way the build directory name is generated.
The way it had been done was causing the code which removes the NBallTestsPassed file to work incorrectly.
Added the writing of the config parms to the config log

  • Property svn:executable set to *
File size: 5.9 KB
Line 
1import re
2import os
3import sys
4import platform
5import MySQLdb
6
7import NBsvnCommand
8import NBlogMessages
9
10def getTestCaseRunTimes(cbcStdout):
11  retVal = {}
12  # Look for pattern
13  #   processing mps file: p0201 (31 out of 44)
14  # cbc_clp 13.75 = 13.75 ; okay - took 17.83 seconds.
15  r1=r'(cbc_clp (.+) = (.+) ; okay - took (\d*\.\d*) seconds.)'
16 
17  r2=r'(.+ processing mps file: (.+) \((\d*) out of (\d*)\))'
18  r='('+r1+'|'+r2+')'
19  reResult=re.findall(r,cbcStdout)
20
21  for i in range(len(reResult)):
22    if reResult[i][0].find("  processing mps file:") : continue
23    # reResult[i] contains "  processing mps file:"
24    if reResult[i][8] != '44' : continue
25    tcName=reResult[i][6]
26    tcRuntime=reResult[i+1][4]
27    retVal[tcName]=tcRuntime
28   
29  return retVal
30
31def getCbcStdout(cbcStdoutFileName):
32  retVal='file not read'
33  if os.path.isfile(cbcStdoutFileName) :
34    cbcStdoutFilePtr = open(cbcStdoutFileName,'r')
35    retVal = cbcStdoutFilePtr.read()
36    cbcStdoutFilePtr.close()
37  return retVal
38#===========================================================================
39def getConfigOptions(buildDir):
40  retVal=''
41  configFile = os.path.join(buildDir,'NBstdout-config')
42  if os.path.isfile(configFile) :
43    configFilePtr = open(configFile,'r')
44    retVal=configFilePtr.readline()
45    configFilePtr.close()
46  else :
47    NBlogMessages.writeMessage( "Failure reading " + configFile )
48    sys.exit(1)
49  return retVal
50#===========================================================================
51def updateMachineTables(db) : 
52  cursor = db.cursor()
53 
54  # Get Info about machine and put into database
55  machineHw=platform.machine()
56  machineOS=platform.system()
57  machineName=platform.node()
58  svnRevNum = NBsvnCommand.svnRevision('.')
59
60  # Does this machine already exist in database?
61  x=cursor.execute("""SELECT machineId from machine WHERE hostName='%s' and machineOS='%s' and machineHardware='%s'"""%
62                 (machineName,machineOS,machineHw) )
63  row = cursor.fetchone()
64  if row!=None :
65    retVal=row[0]
66    cursor.close()
67    return retVal
68 
69  x=cursor.execute("Insert INTO machine (hostName,machineOS,machineHardware) VALUES (%s,%s,%s)",
70                 (machineName,machineOS,machineHw) ) 
71  retVal = db.insert_id()
72  cursor.close()
73
74  return retVal
75#==================================================================================
76
77def updateBuildTables(db,svnSrcDir,buildDir) : 
78  cursor = db.cursor()
79 
80  # Get Info about build and put into database
81  os.chdir(svnSrcDir) 
82  svnRevNum = NBsvnCommand.svnRevision('.')
83  svnUrl = NBsvnCommand.svnUrl('.')
84  execFilename=os.path.join(buildDir,"Cbc","src","cbc")
85  execModTimeEpoch=os.path.getmtime(execFilename)
86  execModTime=str(datetime.datetime.fromtimestamp(execModTimeEpoch))
87  configOptions=getConfigOptions(buildDir)
88  print configOptions
89
90  # Does this build already exist in database?
91  x=cursor.execute("""SELECT buildId from build WHERE svnRevision='%s' and svnUrl='%s' and executableTimeStamp='%s' and configOptions='%s'"""%
92                 (str(svnRevNum),svnUrl,execModTime,configOptions) )
93  row = cursor.fetchone()
94  if row!=None :
95    retVal=row[0]
96    cursor.close()
97    return retVal
98 
99  x=cursor.execute("Insert INTO build (svnRevision,svnUrl,executableTimeStamp,configOptions) VALUES (%s,%s,%s,%s)",
100                 (str(svnRevNum),svnUrl,execModTime,configOptions) ) 
101  retVal = db.insert_id()
102
103  # Insert build attributes in database
104  externalsRevisionNum = {}
105  NBsvnCommand.svnRevisions('.',externalsRevisionNum)
106  x=cursor.execute("Insert INTO buildAttr"+
107                   "(buildId,buildAttrName,buildAttrValue) VALUES (%s,'svnExternals',%s)",
108                 (str(retVal),str(externalsRevisionNum)) )
109
110  #TODO: add configuration parms and gcc version (perhaps compiler name too)
111  cursor.close()
112  return retVal
113
114
115
116#==================================================================================
117 
118
119def updateDb(dbPwDir,svnSrcDir,buildDir,cbcStdout) :
120
121  # Get access info: host, userid, pw
122  dbAccessInfoFile = os.path.join(dbPwDir,'dbAccessInfo.txt')
123  if os.path.isfile(dbAccessInfoFile) :
124    dbAccessInfoFilePtr = open(dbAccessInfoFile,'r')
125    for dbAccessInfoRecord in dbAccessInfoFilePtr.readlines():
126      dbAccessInfo=dbAccessInfoRecord.split(":")
127      if len(dbAccessInfo)!=4 : continue
128      if dbAccessInfo[0].strip()=="DbAccessInfo" : break
129    if dbAccessInfo[0].strip()!="DbAccessInfo" :
130      NBlogMessages.writeMessage("Expected record not found in "+dbAccessInfoFile )
131      sys.exit(1)
132    dbAccessInfoFilePtr.close() 
133    dbServer=dbAccessInfo[1].strip()
134    dbUserid=dbAccessInfo[2].strip()
135    dbPw=dbAccessInfo[3].strip()
136  else :
137    NBlogMessages.writeMessage( "Failure reading " + dbAccessInfoFile )
138    sys.exit(1)
139
140  # Open date base connection
141  db = MySQLdb.connect(host=dbServer,user=dbUserid,passwd=dbPw,db='coin')
142
143 
144  # Get Info about machine and put into database
145  machineId=updateMachineTables(db)
146
147  # Get Info about build and put into database
148  buildId=updateBuildTables(db,svnSrcDir,buildDir)
149
150  x=getTestCaseRunTimes(cbcStdout)
151  cursor = db.cursor() 
152  for t in x:
153    # execute SQL statement
154    cursor.execute("INSERT INTO cbcUnitTest (mpsName,time,buildId,machineId) VALUES (%s,%s,%s,%s)",
155                  (t, x[t],str(buildId),str(machineId)))
156
157##  cursor.execute("SELECT mpsName, time from cbcUnitTest")
158##  while (1):
159##    row=cursor.fetchone()
160##    if row==None: break
161##    print "%s %s" % (row[0],row[1])
162##  print "Number of rows returned: %d" % cursor.rowcount
163
164  cursor.close()
165  db.commit()
166  db.close()
167
168
169x=getCbcStdout('/home/jp/COIN/Cbc/trunkNoThirdParty/Cbc/src/NBstdout-.-cbcunitTestdirMiplib--home-jp-COIN-Data-miplib3miplib')
170updateDb("/home/jp/testScripts","/home/jp/COIN/Cbc/trunk","/home/jp/COIN/Cbc/trunkNoThirdParty",x)
171
172# http://pleac.sourceforge.net/pleac_python/datesandtimes.html
173
Note: See TracBrowser for help on using the repository browser.