/[escript]/trunk/site_scons/site_init.py
ViewVC logotype

Contents of /trunk/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5609 - (show annotations)
Wed May 6 23:57:42 2015 UTC (4 years, 1 month ago) by sshaw
File MIME type: text/x-python
File size: 9142 byte(s)
making itest do the summary of failures the same as utest
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2015 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2015 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import sys, os, time, py_compile, re, subprocess
25 from SCons.Defaults import Chmod, Copy
26 from grouptest import *
27 from extractdebbuild import *
28
29 def findLibWithHeader(env, libs, header, paths, lang='c++'):
30 from SCons.Script.SConscript import Configure
31 inc_path=''
32 lib_path=''
33 # 'paths' may be a prefix, so look for lib and include subdirectories
34 if type(paths)==str:
35 # find the header file first
36 for i in 'include','include64','include32','inc':
37 inc=os.path.join(paths, i)
38 if os.path.isfile(os.path.join(inc, header)):
39 inc_path=inc
40 break
41 if inc_path=='':
42 raise RuntimeError('%s not found under %s'%(header,paths))
43
44 # now try to find a lib directory
45 for l in 'lib','lib64','lib32':
46 lp=os.path.join(paths, l)
47 if os.path.isdir(lp):
48 lib_path=lp
49 break
50 if lib_path=='':
51 raise RuntimeError('No lib directory found under %s'%paths)
52 else:
53 if os.path.isfile(os.path.join(paths[0], header)):
54 inc_path=paths[0]
55 else:
56 raise RuntimeError('%s not found under %s'%(header,paths[0]))
57 if os.path.isdir(paths[1]):
58 lib_path=paths[1]
59 else:
60 raise RuntimeError('%s is not a valid path.'%paths[1])
61
62 # now try the library
63 conf=Configure(env.Clone())
64 conf.env.AppendUnique(CPPPATH = [inc_path])
65 conf.env.AppendUnique(LIBPATH = [lib_path])
66 if type(libs)==str: libs=[libs]
67 if len(libs)==0: libs=['']
68 # we can't check for each library by itself since they may depend on each
69 # other, so we add all libraries to the link line and check only for one
70 conf.env.AppendUnique(LIBS = libs)
71 if not conf.CheckLibWithHeader(libs[0], header, lang):
72 conf.Finish()
73 raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
74
75 conf.Finish()
76 return inc_path, lib_path
77
78 def detectModule(env, module):
79 from tempfile import TemporaryFile
80 p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
81 if p != 0:
82 env[module] = False
83 return False
84 env[module] = True
85 return True
86
87 def write_buildvars(env):
88 buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
89 for k,v in sorted(env['buildvars'].items()):
90 buildvars.write("%s=%s\n"%(k,v))
91 buildvars.close()
92
93 def write_launcher(env):
94 reps={'%n':'${ESCRIPT_NUM_NODES}', '%p':'${ESCRIPT_NUM_PROCS}',
95 '%N':'${TOTPROC}', '%t':'${ESCRIPT_NUM_THREADS}', '%f':'${HOSTFILE}',
96 '%h':'${HOSTLIST}', '%e':'${EXPORT_ENV}', '%b':'${EXEC_CMD}'}
97 pre=env['prelaunch']
98 cmd=env['launcher']
99 post=env['postlaunch']
100 # %b should be present in launcher at least
101 if not '%b' in cmd:
102 raise RuntimeError('option "launcher" must contain %b!')
103
104 for k, v in reps.iteritems():
105 pre = pre.replace(k, v)
106 cmd = cmd.replace(k, v)
107 post = post.replace(k, v)
108 try:
109 launchscript = os.path.join(env['bininstall'], 'run-escript')
110 launcher=open(launchscript, 'w')
111 for line in open('run-escript.in','r').readlines():
112 launcher.write(line.replace('@@PRELAUNCH', pre).replace('@@LAUNCH', cmd).replace('@@POSTLAUNCH', post))
113 launcher.close()
114 env.Execute(Chmod(launchscript, 0o755))
115 except IOError:
116 env['warnings'].append("Error attempting to write launcher script.")
117
118 def generateTestScripts(env, TestGroups):
119 try:
120 utest=open('utest.sh','w')
121 utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
122 for tests in TestGroups:
123 utest.write(tests.makeString())
124 utest.write(tests.makeFooter())
125 utest.close()
126 env.Execute(Chmod('utest.sh', 0o755))
127 print("Generated utest.sh.")
128 # This version contains only python tests - I want this to be usable
129 # from a binary only install if you have the test files
130 utest=open('itest.sh','w')
131 utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
132 for tests in TestGroups:
133 if tests.exec_cmd=='$PYTHONRUNNER ':
134 utest.write(tests.makeString())
135 utest.write(tests.makeFooter())
136 utest.close()
137 env.Execute(Chmod('itest.sh', 0o755))
138 print("Generated itest.sh.")
139 except IOError:
140 env['warnings'].append("Error attempting to write unit test script(s).")
141
142 # delete scripts upon cleanup
143 env.Clean('target_init', 'utest.sh')
144 env.Clean('target_init', 'itest.sh')
145
146 # Code to build .pyc from .py
147 def build_py(target, source, env):
148 try:
149 py_compile.compile(str(source[0]), str(target[0]), doraise=True)
150 return 0
151 except py_compile.PyCompileError, e:
152 print e
153 return 1
154
155
156 # Code to run unit_test executables
157 def runUnitTest(target, source, env):
158 time_start = time.time()
159 app = str(source[0].abspath)
160 pn, sn= os.path.split(app)
161 if not os.name== "nt":
162 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
163 else:
164 if env['usempi']:
165 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
166 "FINLEY_TEST_DATA,PATH %s"\
167 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
168 else:
169 app = "cd "+ pn +" & "+sn
170 print "Executing test: " + app
171 if not env.Execute(app):
172 open(str(target[0]),'w').write("PASSED\n")
173 else:
174 return 1
175 print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
176 return None
177
178 def binpath(env, name=None):
179 if not name:
180 return env['bininstall']
181 return os.path.join(env['bininstall'], name)
182
183 def runPyUnitTest(target, source, env):
184 time_start = time.time()
185 app = str(source[0].abspath)
186 pn, sn= os.path.split(app)
187 if os.name=="nt":
188 if env['usempi']:
189 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
190 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
191 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
192 else:
193 app = "cd "+ pn +" & "+sys.executable + " " + sn
194 else:
195 skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
196 failfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".failed"
197 try:
198 os.unlink(skipfile)
199 except Exception as e:
200 pass
201 app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
202 "../tools/testrunner.py")+" -skipfile="+skipfile+" "+"-failfile="+failfile+" "+"-exit "+sn
203 print "Executing test: ",app
204 if env.Execute(app) == 0:
205 open(str(target[0]),'w').write("PASSED\n")
206 else:
207 return 1
208 print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
209 return None
210
211 def runPyExample(target, source, env):
212 time_start = time.time()
213 app = str(source[0].abspath)
214 pn, sn= os.path.split(app)
215 if os.name=="nt":
216 if env['usempi']:
217 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
218 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
219 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
220 else:
221 app = "cd "+ pn +" & "+sys.executable + " " + sn
222 else:
223
224 app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
225 print "Executing test: ",app
226 if env.Execute(app) == 0:
227 open(str(target[0]),'w').write("PASSED\n")
228 else:
229 return 1
230 print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
231 return None
232
233 def eps2pdf(target, source, env):
234 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
235 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
236 return 1
237 return None
238
239 def effectiveName(inname):
240 m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
241 if m.match(inname):
242 return "savanna"
243 return inname

  ViewVC Help
Powered by ViewVC 1.1.26