source: branches/testScripts/nightlyBuild.py @ 626

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

Added NBosCommand (nightly build operating system command).
This is an attempt to run commands and exe's in a subprocess, so if they
crash they don't bring down the script

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.4 KB
Line 
1#! /usr/bin/env python
2
3import os
4import sys
5import smtplib
6import re 
7
8import NBuserConfig
9import NBprojectConfig
10import NBlogMessages
11import NBemail
12import NBosCommand
13
14# TODO:
15#   -After "svn co" then get all 3rd party packages.
16#   -Get some information about the platform and put this in email failure message.
17#   -Implement Kipp's vpath (delete vpath instead of 'make distclean').
18#   Break this file up into multiple files so it is manageable.
19#   Don't do build if 'svn update' doesn't change anything and prior test was OK.
20#     (no need to re-run if nothing has changed since prior run)
21#   Build both trunk and latest stable
22#   Build both optimized and debug (or have a set of config-site scripts to test?)
23#   Check the testing of the success criteria of each projects "make test"
24#   Implement "cbc -miplib" test for successful run.  JohnF sent JP the criteria
25#     to test on in an email dated 10/12/2007 12:01pm
26
27
28
29#------------------------------------------------------------------------
30# Function to Check Return Code from unitTest
31#------------------------------------------------------------------------
32def didTestFail( result, project, buildStep ) :
33  retVal = 0
34
35  # If the return code is not 0, then failure
36  if result['returnCode'] != 0 :
37    retVal = 1
38
39  # Many tests write a "Success" message.
40  # For test that do this, check for the success message
41  if NBprojectConfig.ALL_TESTS_COMPLETED_SUCCESSFULLY_CMDS.has_key(project) : 
42    if buildStep in NBprojectConfig.ALL_TESTS_COMPLETED_SUCCESSFULLY_CMDS[project] :
43      # Is the success message contained in the output?
44      if result['stderr'].rfind("All tests completed successfully") == -1 and \
45         result['stdout'].rfind("All tests completed successfully") == -1 :
46        # Success message not found, assume test failed
47        retVal = 1
48
49  #---------------------------------------------------------------------
50  # Some (project,buildStep) pairs require further checking
51  # to determine if they were successful
52  #---------------------------------------------------------------------
53  # Clp's "./clp -unitTest dirNetlib=_NETLIBDIR_ -netlib"
54  if project=='Clp' and buildStep==NBprojectConfig.UNITTEST_CMD['Clp'] :
55    # Check that last netlib test case ran by looking for message of form
56    # '../../Data/Netlib/woodw took 0.47 seconds using algorithm either'
57    reexp = r"(.|\n)*(\\|/)Data(\\|/)Netlib(\\|/)woodw took (\d*\.\d*) seconds using algorithm either(.|\n)*"
58    msgTail = result['stdout'][-200:]
59    if not re.compile(reexp).match(msgTail,1) :
60      # message not found, assume test failed
61      retVal = 1
62     
63  # Cbc's "make test"
64  elif project=='Cbc' and buildStep=='make test' :
65    # Check that last the last few lines are of the form
66    # 'cbc_clp solved 2 out of 2 and took XX.XX seconds.'
67    reexp=r"(.|\n)*cbc_clp solved 2 out of 2 and took (\d*\.\d*) seconds."
68    msgTail = result['stdout'][-300:]
69    if not re.compile(reexp).match(msgTail,1) :
70      # message not found, assume test failed
71      retVal = 1
72
73  # Cbc's "./cbc -unitTest dirNetlib=_MIPLIB3DIR_ -miplib"
74  elif project=='Cbc' and buildStep==NBprojectConfig.UNITTEST_CMD['Cbc'] :
75    if result['returnCode']>=0 and result['returnCode']<=2 :
76      # return code is between 0 and 2.
77      # Return code between 1 and 44 is the number of test cases that
78      # ended because maxnodes limit reached.  John Forrest says if this
79      # is less than 3, the OK.
80      retVal=0
81    else :
82      retVal=1
83
84  return retVal
85
86#------------------------------------------------------------------------
87# Function for executing svn commands
88#------------------------------------------------------------------------
89def issueSvnCmd(svnCmd,dir,project) :
90  retVal='OK'
91  os.chdir(dir)
92  NBlogMessages.writeMessage('  '+svnCmd)
93  result = NBosCommand.run(svnCmd)
94  if result['returnCode'] != 0 :
95    NBemail.sendCmdMsgs(project,result,svnCmd)
96    retVal='Error'
97  return retVal
98
99#------------------------------------------------------------------------
100#  Main Program Starts Here 
101#------------------------------------------------------------------------
102
103#------------------------------------------------------------------------
104#  If needed create the top level directory
105#------------------------------------------------------------------------
106if not os.path.isdir(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR) :
107  os.makedirs(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR)
108os.chdir(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR)
109
110#------------------------------------------------------------------------
111#  Get the data directories if they don't already exist
112#------------------------------------------------------------------------
113dataBaseDir=os.path.join(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR,'Data')
114if not os.path.isdir(dataBaseDir) :
115  os.makedirs(dataBaseDir)
116dataDirs=['Netlib','miplib3']
117for d in dataDirs :
118  dataDir=os.path.join(dataBaseDir,d)
119  if not os.path.isdir(dataDir) :
120    svnCmd=os.path.join(NBuserConfig.SVNPATH_PREFIX,'svn') + ' checkout https://projects.coin-or.org/svn/Data/releases/1.0.0/'+d+' '+d
121    if issueSvnCmd(svnCmd,dataBaseDir,'Data')!='OK' :
122      sys.exit(1)
123    result=NBosCommand.run('find '+d+' -name \*.gz -print | xargs gzip -d')
124netlibDir=os.path.join(dataBaseDir,'Netlib')
125miplib3Dir=os.path.join(dataBaseDir,'miplib3')
126
127#------------------------------------------------------------------------
128# Loop once for each project
129#------------------------------------------------------------------------
130for p in NBuserConfig.PROJECTS:
131  NBlogMessages.writeMessage( p )
132
133  #---------------------------------------------------------------------
134  # svn checkout or update the project
135  #---------------------------------------------------------------------
136  projectBaseDir=os.path.join(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR,p)
137  projectCheckOutDir=os.path.join(projectBaseDir,'trunk')
138  if not os.path.isdir(projectBaseDir) :
139    os.makedirs(projectBaseDir)
140  if not os.path.isdir(projectCheckOutDir) :
141    svnCmd=os.path.join(NBuserConfig.SVNPATH_PREFIX,'svn') + ' checkout https://projects.coin-or.org/svn/'+p+'/trunk trunk'
142    if issueSvnCmd(svnCmd,projectBaseDir,p)!='OK' :
143      continue
144  else :
145    svnCmd=os.path.join(NBuserConfig.SVNPATH_PREFIX,'svn') + ' update'
146    if issueSvnCmd(svnCmd,projectCheckOutDir,p)!='OK' :
147      continue
148
149  #---------------------------------------------------------------------
150  # Should probably run make 'distclean' to do a build from scrath
151  # or delete the VPATH directory when there is one
152  #---------------------------------------------------------------------
153
154
155  #---------------------------------------------------------------------
156  # Run configure part of buid
157  #---------------------------------------------------------------------
158  os.chdir(projectCheckOutDir)
159  configCmd = os.path.join('.','configure -C')
160  NBlogMessages.writeMessage('  '+configCmd)
161  result=NBosCommand.run(configCmd)
162 
163  # Check if configure worked
164  if result['returnCode'] != 0 :
165    error_msg = result
166    # Add contents of log file to message
167    logFileName = 'config.log'
168    if os.path.isfile(logFileName) :
169      logFilePtr = open(logFileName,'r')
170      error_msg['config.log']  = "config.log contains: \n" 
171      error_msg['config.log'] += logFilePtr.read()
172      logFilePtr.close()
173    NBemail.sendCmdMsgs(p,error_msg,configCmd)
174    continue
175
176  #---------------------------------------------------------------------
177  # Run make part of build
178  #---------------------------------------------------------------------
179  NBlogMessages.writeMessage( '  make' )
180  result=NBosCommand.run('make')
181 
182  # Check if make worked
183  if result['returnCode'] != 0 :
184    NBemail.sendCmdMsgs(p,result,'make')
185    continue
186
187  #---------------------------------------------------------------------
188  # Run 'make test' part of build
189  #---------------------------------------------------------------------
190  NBlogMessages.writeMessage( '  make test' )
191  result=NBosCommand.run('make test')
192 
193  # Check if 'make test' worked
194  if didTestFail(result,p,"make test") :
195    NBemail.sendCmdMsgs(p,result,"make test")
196    continue
197
198  #---------------------------------------------------------------------
199  # Run unitTest if available and different from 'make test'
200  #---------------------------------------------------------------------
201  if NBprojectConfig.UNITTEST_CMD.has_key(p) :
202    unitTestPath = os.path.join(projectCheckOutDir,NBprojectConfig.UNITTEST_DIR[p])
203    os.chdir(unitTestPath)
204
205    unitTestCmdTemplate=NBprojectConfig.UNITTEST_CMD[p]
206    unitTestCmd=unitTestCmdTemplate.replace('_NETLIBDIR_',netlibDir)
207    unitTestCmd=unitTestCmd.replace('_MIPLIB3DIR_',miplib3Dir)
208
209    NBlogMessages.writeMessage( '  '+unitTestCmd )
210    result=NBosCommand.run(unitTestCmd)
211 
212    if didTestFail(result,p,unitTestCmdTemplate) :
213      NBemail.sendCmdMsgs(p,result,unitTestCmd)
214      continue
215
216  # For testing purposes only do first successful project
217  #break
218
219
220NBlogMessages.writeMessage( "nightlyBuild.py Finished" )
221
222sys.exit(0)
223
224
225# START KIPP
226#----------------------------------------------------------------------
227# CONFIG FILE PATH:
228#   path to the config file for the build
229#   done. If the directory does not exist, it will be created.
230#   this should have all of the user specific data
231#   it should have values for
232#   NIGHTLY_BUILD_ROOT
233#   NBuserConfig.SMTP_SERVER_NAME
234#   NBuserConfig.SMTP_SERVER_PORT
235#   NBuserConfig.SMTP_SSL_SERVER
236#   NBuserConfig.SMTP_USER_NAME
237#   NBuserConfig.SMTP_PASSWORD_FILENAME = '/home/jp/bin/smtpPwFile'
238#   NBuserConfig.SENDER_EMAIL_ADDR='jpfasano _AT_ verizon _DOT_ net'
239#   NBuserConfig.MY_EMAIL_ADDR='jpfasano _AT_ us _DOT_ ibm _DOT_ com'
240#   
241#----------------------------------------------------------------------
242
243CONFIG_FILE_PATH = '/Users/kmartin/Documents/files/configDir/'
244CONFIG_FILENAME = 'config.txt'
245
246
247# Get configFile data
248
249configFile = os.path.join(os.path.dirname( CONFIG_FILE_PATH),
250                                 os.path.basename(CONFIG_FILENAME ))
251if os.path.isfile(  configFile) :
252  pwFilePtr = open(configFile ,'r')
253  d = pwFilePtr.readlines()
254  # do pwFilePtr.read() to get a string object
255  # we have a list object
256  print d[0]
257  print d[1]
258  # make a dictionary
259  config_dic = {}
260
261  #smtppass  = pwFilePtr.read().strip()
262  pwFilePtr.close()
263else :
264  #NBlogMessages.writeMessage( "Failure reading pwFileName=" + CONFIG_FILENAME )
265  #print cmdMsgs
266  sys.exit( 1)
267sys.exit( 0)
268
269
270
271# START KIPP
272#----------------------------------------------------------------------
273#   path to the config file for the build
274#   get the user dependent variables
275# CONFIG FILE PATH:
276#   it should have values for
277#   NIGHTLY_BUILD_ROOT
278#   NBuserConfig.SMTP_SERVER_NAME
279#   NBuserConfig.SMTP_SERVER_PORT
280#   NBuserConfig.SMTP_SSL_SERVER
281#   NBuserConfig.SMTP_USER_NAME
282#   NBuserConfig.SMTP_PASSWORD_FILENAME
283#   NBuserConfig.SENDER_EMAIL_ADDR
284#   NBuserConfig.MY_EMAIL_ADDR
285#   
286#----------------------------------------------------------------------
287
288CONFIG_FILE_PATH = '/Users/kmartin/Documents/files/configDir/'
289CONFIG_FILENAME = 'config.txt'
290
291
292# Get configFile data
293
294configFile = os.path.join(os.path.dirname( CONFIG_FILE_PATH),
295                                 os.path.basename(CONFIG_FILENAME ))
296if os.path.isfile(  configFile) :
297  pwFilePtr = open(configFile ,'r')
298  d = pwFilePtr.readlines()
299  # do pwFilePtr.read() to get a string object
300  # we have a list object
301  print d[0]
302  print d[1]
303  # make a dictionary
304  config_dic = {}
305
306  #smtppass  = pwFilePtr.read().strip()
307  pwFilePtr.close()
308else :
309  #NBlogMessages.writeMessage( "Failure reading pwFileName=" + CONFIG_FILENAME )
310  #print cmdMsgs
311  sys.exit( 1)
312sys.exit( 0)
313
314# END KIPP
Note: See TracBrowser for help on using the repository browser.