2012-02-01 23:35:01 +00:00
|
|
|
from buildutils import *
|
|
|
|
|
import subprocess
|
2014-02-06 22:59:10 +00:00
|
|
|
from xml.etree import ElementTree
|
2012-02-01 23:35:01 +00:00
|
|
|
|
2012-03-05 20:45:20 +00:00
|
|
|
Import('env','build','install')
|
2012-02-01 23:35:01 +00:00
|
|
|
localenv = env.Clone()
|
|
|
|
|
|
2012-08-10 21:03:06 +00:00
|
|
|
localenv.Prepend(CPPPATH=['#ext/gtest/include', '#include'],
|
|
|
|
|
LIBPATH='#build/lib')
|
2012-11-14 21:07:03 +00:00
|
|
|
localenv.Append(LIBS=['gtest'] + localenv['cantera_libs'],
|
|
|
|
|
CCFLAGS=env['warning_flags'])
|
2012-02-01 23:35:01 +00:00
|
|
|
|
2012-08-02 15:47:45 +00:00
|
|
|
localenv['ENV']['CANTERA_DATA'] = Dir('#build/data').abspath
|
2012-02-27 18:12:42 +00:00
|
|
|
|
2013-01-11 22:56:40 +00:00
|
|
|
PASSED_FILES = {}
|
|
|
|
|
|
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
|
|
|
|
2014-01-30 00:47:37 +00:00
|
|
|
def addTestProgram(subdir, progName, env_vars={}):
|
2012-02-27 18:12:42 +00:00
|
|
|
"""
|
|
|
|
|
Compile a test program and create a targets for running
|
|
|
|
|
and resetting the test.
|
|
|
|
|
"""
|
2014-02-06 22:59:10 +00:00
|
|
|
def gtestRunner(target, source, env):
|
|
|
|
|
"""SCons Action to run a compiled gtest program"""
|
|
|
|
|
program = source[0]
|
|
|
|
|
passedFile = target[0]
|
|
|
|
|
testResults.tests.pop(passedFile.name, None)
|
|
|
|
|
workDir = Dir('#test/work').abspath
|
|
|
|
|
resultsFile = pjoin(workDir, 'gtest-%s.xml' % progName)
|
|
|
|
|
if os.path.exists(resultsFile):
|
|
|
|
|
os.remove(resultsFile)
|
|
|
|
|
|
|
|
|
|
if not os.path.isdir(workDir):
|
|
|
|
|
os.mkdir(workDir)
|
|
|
|
|
code = subprocess.call([program.abspath, '--gtest_output=xml:'+resultsFile],
|
|
|
|
|
env=env['ENV'], cwd=workDir)
|
|
|
|
|
|
|
|
|
|
if not code:
|
|
|
|
|
# Test was successful
|
|
|
|
|
open(passedFile.path, 'w').write(time.asctime()+'\n')
|
2014-03-05 03:25:19 +00:00
|
|
|
|
|
|
|
|
if os.path.exists(resultsFile):
|
|
|
|
|
# Determine individual test status
|
|
|
|
|
results = ElementTree.parse(resultsFile)
|
|
|
|
|
for test in results.findall('.//testcase'):
|
|
|
|
|
testName = ': '.join((progName, test.get('name')))
|
|
|
|
|
if test.findall('failure'):
|
|
|
|
|
testResults.failed[testName] = 1
|
|
|
|
|
else:
|
|
|
|
|
testResults.passed[testName] = 1
|
2014-02-06 22:59:10 +00:00
|
|
|
else:
|
2014-03-05 03:25:19 +00:00
|
|
|
# Total failure of the test program - unable to determine status
|
|
|
|
|
# of individual tests
|
2014-02-06 22:59:10 +00:00
|
|
|
testResults.failed[passedFile.name] = program
|
|
|
|
|
|
2014-01-30 00:47:37 +00:00
|
|
|
testenv = localenv.Clone()
|
|
|
|
|
testenv['ENV'].update(env_vars)
|
|
|
|
|
program = testenv.Program(pjoin(subdir, progName),
|
|
|
|
|
mglob(testenv, subdir, 'cpp'))
|
2012-02-01 23:35:01 +00:00
|
|
|
passedFile = File(pjoin(str(program[0].dir), '%s.passed' % program[0].name))
|
2013-01-11 22:56:40 +00:00
|
|
|
PASSED_FILES[progName] = str(passedFile)
|
2012-05-31 14:58:07 +00:00
|
|
|
testResults.tests[passedFile.name] = program
|
2014-02-06 22:59:10 +00:00
|
|
|
run_program = testenv.Command(passedFile, program, gtestRunner)
|
2012-04-12 15:28:33 +00:00
|
|
|
Alias('test', run_program)
|
|
|
|
|
Alias('test-%s' % progName, run_program)
|
|
|
|
|
env['testNames'].append(progName)
|
2012-02-01 23:35:01 +00:00
|
|
|
if os.path.exists(passedFile.abspath):
|
2014-01-30 00:47:37 +00:00
|
|
|
Alias('test-reset', testenv.Command('reset-%s%s' % (subdir, progName),
|
|
|
|
|
[], [Delete(passedFile.abspath)]))
|
2012-02-01 23:35:01 +00:00
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
|
2014-01-09 23:12:32 +00:00
|
|
|
def addPythonTest(testname, subdir, script, interpreter, outfile,
|
|
|
|
|
args='', dependencies=(), env_vars={}, optional=False):
|
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
|
2012-05-31 14:58:07 +00:00
|
|
|
passedFile = target[0]
|
2014-01-11 00:20:21 +00:00
|
|
|
testResults.tests.pop(passedFile.name, None)
|
2012-03-13 17:32:10 +00:00
|
|
|
if not os.path.isdir(workDir):
|
|
|
|
|
os.mkdir(workDir)
|
2014-01-09 23:12:32 +00:00
|
|
|
if os.path.exists(outfile):
|
|
|
|
|
os.remove(outfile)
|
2012-05-31 14:58:07 +00:00
|
|
|
|
2012-09-06 19:58:32 +00:00
|
|
|
environ = dict(env['ENV'])
|
|
|
|
|
for k,v in env_vars.iteritems():
|
|
|
|
|
print k,v
|
|
|
|
|
environ[k] = v
|
2013-12-18 17:45:30 +00:00
|
|
|
code = subprocess.call([env.subst(interpreter), source[0].abspath] + args.split(),
|
2014-03-24 04:03:35 +00:00
|
|
|
env=environ)
|
2012-03-13 17:32:10 +00:00
|
|
|
if not code:
|
2012-05-31 14:58:07 +00:00
|
|
|
# Test was successful
|
2012-03-13 17:32:10 +00:00
|
|
|
open(target[0].path, 'w').write(time.asctime()+'\n')
|
2014-03-17 02:05:17 +00:00
|
|
|
|
2014-04-08 16:27:01 +00:00
|
|
|
failures = 0
|
2014-03-17 02:05:17 +00:00
|
|
|
if os.path.exists(outfile):
|
|
|
|
|
# Determine individual test status
|
|
|
|
|
for line in open(outfile):
|
|
|
|
|
status, name = line.strip().split(': ', 1)
|
|
|
|
|
if status == 'PASS':
|
|
|
|
|
testResults.passed[':'.join((testname,name))] = 1
|
|
|
|
|
elif status in ('FAIL', 'ERROR'):
|
|
|
|
|
testResults.failed[':'.join((testname,name))] = 1
|
2014-04-08 16:27:01 +00:00
|
|
|
failures += 1
|
|
|
|
|
|
|
|
|
|
if code and failures == 0:
|
|
|
|
|
# Failure, but unable to determine status of individual tests
|
2014-01-30 00:47:58 +00:00
|
|
|
testResults.failed[testname] = True
|
2012-05-31 14:58:07 +00:00
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
testenv = localenv.Clone()
|
2012-09-06 19:58:32 +00:00
|
|
|
passedFile = File(pjoin(subdir, '%s.passed' % testname))
|
2013-01-11 22:56:40 +00:00
|
|
|
PASSED_FILES[testname] = str(passedFile)
|
2014-02-20 03:01:05 +00:00
|
|
|
|
|
|
|
|
run_program = testenv.Command(passedFile, pjoin('#test', 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)
|
2013-12-18 17:45:30 +00:00
|
|
|
if not optional:
|
|
|
|
|
Alias('test', run_program)
|
2014-01-11 00:20:21 +00:00
|
|
|
testResults.tests[passedFile.name] = True
|
2012-02-27 18:12:42 +00:00
|
|
|
if os.path.exists(passedFile.abspath):
|
2012-09-06 19:58:32 +00:00
|
|
|
Alias('test-reset', testenv.Command('reset-%s%s' % (subdir, testname),
|
2012-04-12 15:28:33 +00:00
|
|
|
[], [Delete(passedFile.abspath)]))
|
|
|
|
|
|
|
|
|
|
return run_program
|
2012-02-27 18:12:42 +00:00
|
|
|
|
2012-03-13 17:32:10 +00:00
|
|
|
|
2013-12-09 01:36:03 +00:00
|
|
|
def addMatlabTest(script, testName, dependencies=None, env_vars=()):
|
2012-03-13 17:32:10 +00:00
|
|
|
def matlabRunner(target, source, env):
|
2012-05-31 14:58:07 +00:00
|
|
|
passedFile = target[0]
|
|
|
|
|
del testResults.tests[passedFile.name]
|
2012-03-13 17:32:10 +00:00
|
|
|
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']
|
2012-03-15 22:48:59 +00:00
|
|
|
if os.path.exists(outfile):
|
|
|
|
|
os.remove(outfile)
|
2012-03-23 22:16:28 +00:00
|
|
|
|
|
|
|
|
environ = dict(os.environ)
|
|
|
|
|
environ.update(env['ENV'])
|
2013-12-09 01:36:03 +00:00
|
|
|
environ.update(env_vars)
|
2012-03-13 17:32:10 +00:00
|
|
|
code = subprocess.call([pjoin(env['matlab_path'], 'bin', 'matlab')] +
|
|
|
|
|
matlabOptions + ['-r', runCommand],
|
2012-03-23 22:16:28 +00:00
|
|
|
env=environ, cwd=Dir('#test/matlab').abspath)
|
2012-03-13 17:32:10 +00:00
|
|
|
results = open(outfile).read()
|
|
|
|
|
print '-------- Matlab test results --------'
|
|
|
|
|
print results
|
|
|
|
|
print '------ end Matlab test results ------'
|
|
|
|
|
if 'FAILED' in results:
|
2012-05-31 14:58:07 +00:00
|
|
|
testResults.failed[passedFile.name] = True
|
2012-03-13 17:32:10 +00:00
|
|
|
else:
|
2012-05-31 14:58:07 +00:00
|
|
|
testResults.passed[passedFile.name] = True
|
2012-03-13 17:32:10 +00:00
|
|
|
open(target[0].path, 'w').write(time.asctime()+'\n')
|
|
|
|
|
|
|
|
|
|
testenv = localenv.Clone()
|
|
|
|
|
passedFile = File(pjoin('matlab', '%s.passed' % (script)))
|
2013-01-11 22:56:40 +00:00
|
|
|
PASSED_FILES[testName] = str(passedFile)
|
2012-05-31 14:58:07 +00:00
|
|
|
testResults.tests[passedFile.name] = True
|
2012-03-13 17:32:10 +00:00
|
|
|
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)
|
|
|
|
|
|
2012-04-12 15:28:33 +00:00
|
|
|
Alias('test', run_program)
|
2012-03-13 17:32:10 +00:00
|
|
|
if os.path.exists(passedFile.abspath):
|
2012-04-12 15:28:33 +00:00
|
|
|
Alias('test-reset', testenv.Command('reset-%s%s' % ('matlab', script),
|
|
|
|
|
[], [Delete(passedFile.abspath)]))
|
2012-03-13 17:32:10 +00:00
|
|
|
|
2012-04-12 15:28:33 +00:00
|
|
|
return run_program
|
2012-03-13 17:32:10 +00:00
|
|
|
|
2014-01-30 00:47:37 +00:00
|
|
|
if localenv['python_package'] in ('full', 'minimal'):
|
2014-03-17 02:05:09 +00:00
|
|
|
python_env_vars = {'PYTHONPATH': localenv['pythonpath_build2'],
|
2014-01-30 00:47:37 +00:00
|
|
|
'PYTHON_CMD': localenv.subst('$python_cmd')}
|
|
|
|
|
elif localenv['python3_package'] == 'y':
|
2014-03-17 02:05:09 +00:00
|
|
|
python_env_vars = {'PYTHONPATH': localenv['pythonpath_build3'],
|
2014-01-30 00:47:37 +00:00
|
|
|
'PYTHON_CMD': localenv.subst('$python3_cmd')}
|
|
|
|
|
else:
|
|
|
|
|
python_env_vars = {} # Tests calling ck2cti or ctml_writer will fail
|
|
|
|
|
|
|
|
|
|
|
2012-02-27 18:12:42 +00:00
|
|
|
# Instantiate tests
|
2014-01-30 00:47:37 +00:00
|
|
|
addTestProgram('thermo', 'thermo', env_vars=python_env_vars)
|
2012-05-07 18:20:11 +00:00
|
|
|
addTestProgram('kinetics', 'kinetics')
|
2012-03-13 17:32:10 +00:00
|
|
|
|
2013-12-18 17:45:30 +00:00
|
|
|
python_subtests = ['']
|
|
|
|
|
test_root = '#interfaces/cython/cantera/test'
|
|
|
|
|
for f in mglob(localenv, test_root, '^test_*.py'):
|
|
|
|
|
python_subtests.append(f.name[5:-3])
|
|
|
|
|
|
2013-12-18 17:45:35 +00:00
|
|
|
def make_python_tests(version):
|
2013-12-18 17:45:30 +00:00
|
|
|
# Create test aliases for individual test modules (e.g. test-cython2-thermo;
|
|
|
|
|
# not run as part of the main suite) and a single test runner with all the
|
|
|
|
|
# tests (test-cython2) for the main suite.
|
|
|
|
|
for subset in python_subtests:
|
2013-12-18 17:45:35 +00:00
|
|
|
name = 'cython%i-' %version + subset if subset else 'cython%i' % version
|
2014-01-09 23:12:32 +00:00
|
|
|
pyTest = addPythonTest(
|
2013-12-18 17:45:35 +00:00
|
|
|
name, 'python', 'runCythonTests.py',
|
|
|
|
|
args=subset,
|
2013-12-20 19:21:41 +00:00
|
|
|
interpreter='$python_cmd' if version == 2 else '$python3_cmd',
|
2014-01-09 23:12:32 +00:00
|
|
|
outfile=File('#test/work/python%d-results.txt' % version).abspath,
|
2013-12-18 17:45:35 +00:00
|
|
|
dependencies=(localenv['python%i_module' % version] +
|
|
|
|
|
localenv['python%i_extension' % version] +
|
|
|
|
|
mglob(localenv, test_root, 'py')),
|
2014-03-17 02:05:09 +00:00
|
|
|
env_vars={'PYTHONPATH': localenv['pythonpath_build%s' % version]},
|
2013-12-18 17:45:35 +00:00
|
|
|
optional=bool(subset))
|
2013-12-18 17:45:30 +00:00
|
|
|
localenv.Alias('test-' + name, pyTest)
|
|
|
|
|
env['testNames'].append(name)
|
2012-09-06 19:58:32 +00:00
|
|
|
|
2013-12-18 17:45:35 +00:00
|
|
|
if localenv['python_package'] == 'full':
|
|
|
|
|
make_python_tests(2)
|
|
|
|
|
|
2012-09-06 19:58:32 +00:00
|
|
|
if localenv['python3_package'] == 'y':
|
2013-12-18 17:45:35 +00:00
|
|
|
make_python_tests(3)
|
2012-09-06 19:58:32 +00:00
|
|
|
|
2012-03-13 17:32:10 +00:00
|
|
|
if localenv['matlab_toolbox'] == 'y':
|
2013-01-11 22:56:40 +00:00
|
|
|
matlabTest = addMatlabTest('runCanteraTests.m', 'matlab',
|
2013-12-09 01:36:03 +00:00
|
|
|
dependencies=mglob(localenv, 'matlab', 'm'),
|
2014-01-30 00:47:37 +00:00
|
|
|
env_vars=python_env_vars)
|
2012-04-12 21:35:32 +00:00
|
|
|
localenv.Alias('test-matlab', matlabTest)
|
2012-04-12 15:28:33 +00:00
|
|
|
env['testNames'].append('matlab')
|
2013-01-11 22:56:40 +00:00
|
|
|
|
|
|
|
|
# Force explicitly-named tests to run even if SCons thinks they're up to date
|
|
|
|
|
for command in COMMAND_LINE_TARGETS:
|
|
|
|
|
if command.startswith('test-'):
|
|
|
|
|
name = command[5:]
|
|
|
|
|
if name in PASSED_FILES and os.path.exists(PASSED_FILES[name]):
|
|
|
|
|
os.remove(PASSED_FILES[name])
|