2012-02-01 23:35:01 +00:00
|
|
|
from buildutils import *
|
|
|
|
|
import subprocess
|
|
|
|
|
|
2012-03-05 20:45:20 +00:00
|
|
|
Import('env','build','install')
|
2012-02-01 23:35:01 +00:00
|
|
|
localenv = env.Clone()
|
|
|
|
|
|
2012-02-13 17:24:34 +00:00
|
|
|
localenv.Append(CPPPATH=['#ext/gtest/include', '#include'],
|
2012-02-01 23:35:01 +00:00
|
|
|
LIBPATH='#build/lib',
|
|
|
|
|
LIBS=['gtest'] + localenv['cantera_libs'])
|
|
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
localenv['ENV']['PYTHONPATH'] = Dir('#interfaces/python').abspath
|
|
|
|
|
localenv['ENV']['CANTERA_DATA'] = Dir('#data/inputs').abspath
|
|
|
|
|
|
2012-03-07 00:52:00 +00:00
|
|
|
# Needed for Intel runtime libraries when compiling with ICC
|
|
|
|
|
if 'LD_LIBRARY_PATH' in os.environ:
|
|
|
|
|
localenv['ENV']['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
|
|
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
def testRunner(target, source, env):
|
|
|
|
|
"""SCons Action to run a compiled test program"""
|
2012-02-01 23:35:01 +00:00
|
|
|
program = source[0]
|
2012-02-27 18:12:42 +00:00
|
|
|
code = subprocess.call([program.abspath], env=env['ENV'])
|
|
|
|
|
if not code:
|
|
|
|
|
open(target[0].path, 'w').write(time.asctime()+'\n')
|
|
|
|
|
return code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def addTestProgram(subdir, progName):
|
|
|
|
|
"""
|
|
|
|
|
Compile a test program and create a targets for running
|
|
|
|
|
and resetting the test.
|
|
|
|
|
"""
|
2012-02-01 23:35:01 +00:00
|
|
|
program = localenv.Program(pjoin(subdir, progName),
|
|
|
|
|
pjoin(subdir, '%s.cpp' % progName))
|
|
|
|
|
passedFile = File(pjoin(str(program[0].dir), '%s.passed' % program[0].name))
|
2012-02-27 18:12:42 +00:00
|
|
|
run_program = localenv.Command(passedFile, program, testRunner)
|
2012-02-01 23:35:01 +00:00
|
|
|
Alias('newtest', run_program)
|
|
|
|
|
if os.path.exists(passedFile.abspath):
|
|
|
|
|
Alias('newtest-reset', localenv.Command('reset-%s%s' % (subdir, progName),
|
|
|
|
|
[], [Delete(passedFile.abspath)]))
|
|
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
|
2012-02-27 18:13:53 +00:00
|
|
|
def addTestScript(subdir, script, interpreter, dependencies):
|
2012-02-27 18:12:42 +00:00
|
|
|
"""
|
|
|
|
|
Create targets for running and resetting a test script.
|
|
|
|
|
"""
|
2012-03-13 17:32:10 +00:00
|
|
|
def scriptRunner(target, source, env):
|
|
|
|
|
"""Scons Action to run a test script using the specified interpreter"""
|
|
|
|
|
workDir = Dir('#test/work').abspath
|
|
|
|
|
if not os.path.isdir(workDir):
|
|
|
|
|
os.mkdir(workDir)
|
|
|
|
|
code = subprocess.call([interpreter, source[0].abspath],
|
|
|
|
|
env=env['ENV'],
|
|
|
|
|
cwd=workDir)
|
|
|
|
|
if not code:
|
|
|
|
|
open(target[0].path, 'w').write(time.asctime()+'\n')
|
|
|
|
|
return code
|
|
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
testenv = localenv.Clone()
|
|
|
|
|
passedFile = File(pjoin(subdir, '%s.passed' % (script)))
|
|
|
|
|
run_program = testenv.Command(passedFile, pjoin(subdir, script), scriptRunner)
|
2012-02-27 18:13:53 +00:00
|
|
|
for dep in dependencies:
|
2012-03-09 22:59:04 +00:00
|
|
|
if isinstance(dep, str):
|
|
|
|
|
dep = File(pjoin(subdir, dep))
|
|
|
|
|
testenv.Depends(run_program, dep)
|
2012-02-27 18:12:42 +00:00
|
|
|
Alias('newtest', run_program)
|
|
|
|
|
if os.path.exists(passedFile.abspath):
|
|
|
|
|
Alias('newtest-reset', testenv.Command('reset-%s%s' % (subdir, script),
|
|
|
|
|
[], [Delete(passedFile.abspath)]))
|
|
|
|
|
|
2012-03-13 17:32:10 +00:00
|
|
|
|
|
|
|
|
def addMatlabTest(script, dependencies=None):
|
|
|
|
|
def matlabRunner(target, source, env):
|
|
|
|
|
workDir = Dir('#test/work').abspath
|
|
|
|
|
if not os.path.isdir(workDir):
|
|
|
|
|
os.mkdir(workDir)
|
|
|
|
|
outfile = pjoin(workDir, 'matlab-results.txt')
|
|
|
|
|
runCommand = "%s('%s'); exit" % (source[0].name[:-2], outfile)
|
|
|
|
|
if os.name == 'nt':
|
|
|
|
|
matlabOptions = ['-nojvm','-nosplash','-wait']
|
|
|
|
|
else:
|
|
|
|
|
matlabOptions = ['-nojvm','-nodisplay']
|
|
|
|
|
os.remove(outfile)
|
|
|
|
|
code = subprocess.call([pjoin(env['matlab_path'], 'bin', 'matlab')] +
|
|
|
|
|
matlabOptions + ['-r', runCommand],
|
|
|
|
|
env=env['ENV'], cwd=Dir('#test/matlab').abspath)
|
|
|
|
|
results = open(outfile).read()
|
|
|
|
|
print '-------- Matlab test results --------'
|
|
|
|
|
print results
|
|
|
|
|
print '------ end Matlab test results ------'
|
|
|
|
|
if 'FAILED' in results:
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
open(target[0].path, 'w').write(time.asctime()+'\n')
|
|
|
|
|
|
|
|
|
|
testenv = localenv.Clone()
|
|
|
|
|
passedFile = File(pjoin('matlab', '%s.passed' % (script)))
|
|
|
|
|
|
|
|
|
|
run_program = testenv.Command(passedFile, pjoin('matlab', script), matlabRunner)
|
|
|
|
|
|
|
|
|
|
dependencies = (dependencies or []) + localenv['matlab_extension']
|
|
|
|
|
for dep in dependencies:
|
|
|
|
|
if isinstance(dep, str):
|
|
|
|
|
dep = File(pjoin('matlab', dep))
|
|
|
|
|
testenv.Depends(run_program, dep)
|
|
|
|
|
|
|
|
|
|
Alias('newtest', run_program)
|
|
|
|
|
if os.path.exists(passedFile.abspath):
|
|
|
|
|
Alias('newtest-reset', testenv.Command('reset-%s%s' % ('matlab', script),
|
|
|
|
|
[], [Delete(passedFile.abspath)]))
|
|
|
|
|
|
|
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
# Instantiate tests
|
|
|
|
|
addTestProgram('thermo', 'nasapoly')
|
2012-03-13 17:32:10 +00:00
|
|
|
|
|
|
|
|
if localenv['python_package'] == 'full':
|
|
|
|
|
addTestScript('python', 'runTests.py',
|
|
|
|
|
interpreter=sys.executable,
|
|
|
|
|
dependencies=['testSolution.py', localenv['python_module']])
|
|
|
|
|
|
|
|
|
|
if localenv['matlab_toolbox'] == 'y':
|
|
|
|
|
addMatlabTest('runCanteraTests.m',
|
|
|
|
|
dependencies=mglob(localenv, 'matlab', 'm'))
|