2007-08-13 09:55:32 +02:00
|
|
|
# -*- python -*-
|
|
|
|
|
##
|
|
|
|
|
## SConscript - SCons buildscript for the Testsuite (called by SConstruct)
|
|
|
|
|
##
|
|
|
|
|
|
2008-10-23 04:53:50 +02:00
|
|
|
import os
|
2007-09-20 03:46:14 +02:00
|
|
|
from os import path
|
2010-04-16 02:17:15 +02:00
|
|
|
from glob import glob
|
|
|
|
|
|
2007-08-18 04:28:14 +02:00
|
|
|
from Buildhelper import srcSubtree
|
2008-09-07 23:43:06 +02:00
|
|
|
from Buildhelper import scanSubtree
|
2007-08-18 04:28:14 +02:00
|
|
|
from Buildhelper import globRootdirs
|
2009-01-12 12:48:14 +01:00
|
|
|
from Buildhelper import createPlugins
|
2007-08-13 09:55:32 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
Import('env core_lib app_lib backend_lib tools config')
|
2008-05-20 13:04:22 +02:00
|
|
|
env = env.Clone()
|
2011-12-02 21:34:29 +01:00
|
|
|
env.Append(CPPPATH='include') # additional headers for tests
|
|
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
# test classes of subcomponents linked in shared objects
|
|
|
|
|
sharedTestLibs = {}
|
2011-12-02 21:34:29 +01:00
|
|
|
|
2007-08-17 11:06:49 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
|
|
|
|
|
def linkContext(id):
|
|
|
|
|
if id.startswith('lib'):
|
|
|
|
|
return app_lib # tests in 'lib*' subdirs only linked against application framework
|
|
|
|
|
elif id.startswith('back'):
|
|
|
|
|
return backend_lib # tests in 'back*' subdirs only linked against backend layer
|
2007-09-20 03:46:14 +02:00
|
|
|
else:
|
2013-01-07 02:15:05 +01:00
|
|
|
return core_lib # all other tests linked against complete application core
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exeTestName(srcName):
|
|
|
|
|
name = path.basename(path.splitext(srcName)[0])
|
|
|
|
|
if not name.startswith('test-'):
|
|
|
|
|
name = 'test-'+name
|
|
|
|
|
return name
|
2007-08-18 04:28:14 +02:00
|
|
|
|
2007-08-17 11:06:49 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
def testCases(env,dir):
|
|
|
|
|
""" visit a source subtree and declare all testcases.
|
|
|
|
|
Test classes will be linked into shared libraries,
|
|
|
|
|
while plain-C tests end up as standalone test-XXX.
|
|
|
|
|
@note: using the tree root as additional includepath
|
|
|
|
|
@note: linking scope chosen based on the name-prefix
|
2008-09-07 23:43:06 +02:00
|
|
|
"""
|
2011-12-02 21:34:29 +01:00
|
|
|
env = env.Clone()
|
2013-01-07 02:15:05 +01:00
|
|
|
env.Append(CPPPATH=dir) # add subdir to Includepath
|
|
|
|
|
|
|
|
|
|
# pick up all test classes and link them shared
|
|
|
|
|
testlib = []
|
|
|
|
|
testClasses = list(scanSubtree(dir,['*.cpp']))
|
|
|
|
|
if testClasses:
|
2013-11-02 23:59:13 +01:00
|
|
|
testlib = sharedTestLibs[dir] = env.SharedLibrary('test-'+dir, testClasses, addLibs=core_lib) ### TICKET #938 : should be: addLibs=linkContext(dir))
|
2013-01-07 02:15:05 +01:00
|
|
|
|
|
|
|
|
# pick up standalone plain-C tests
|
|
|
|
|
standaloneTests = list(scanSubtree(dir,['test-*.c']))
|
|
|
|
|
simpletests = [env.Program(exeTestName(p), [p]+linkContext(dir)) for p in standaloneTests]
|
|
|
|
|
|
|
|
|
|
return testlib + simpletests
|
2008-09-07 23:43:06 +02:00
|
|
|
|
|
|
|
|
|
2009-01-12 12:48:14 +01:00
|
|
|
|
|
|
|
|
|
2014-09-30 04:40:24 +02:00
|
|
|
# Specific linker treatment for the testsuite:
|
|
|
|
|
# force explicit linking against all dependencies to ensure auto-registration of
|
|
|
|
|
# any test-class on startup, even if no code dependency is visible to the linker
|
|
|
|
|
envSuite = env.Clone()
|
|
|
|
|
envSuite.Append(LINKFLAGS='-Wl,--no-as-needed')
|
|
|
|
|
|
|
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
# have to treat some subdirs separately.
|
|
|
|
|
specialDirs = ['plugin','tool','include']
|
|
|
|
|
testSrcDirs = globRootdirs('*')
|
2007-08-17 11:06:49 +02:00
|
|
|
|
2007-09-20 03:46:14 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
testcases = [testCases(env, dir) for dir in testSrcDirs if not dir in specialDirs]
|
|
|
|
|
testLibs = sharedTestLibs.values()
|
2014-09-30 04:40:24 +02:00
|
|
|
testrunner = envSuite.Program("test-suite", ["testrunner.cpp"]+testLibs+core_lib)
|
2007-09-20 03:46:14 +02:00
|
|
|
|
2007-08-18 04:28:14 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
testsuite = ( testcases
|
|
|
|
|
+ testrunner
|
2013-11-02 23:59:13 +01:00
|
|
|
+ createPlugins(env, 'plugin', addLibs=core_lib)
|
2013-01-07 02:15:05 +01:00
|
|
|
+ env.File(glob('*.tests')) # depend explicitly on the test definition files for test.sh
|
2012-01-09 02:56:29 +01:00
|
|
|
+ config
|
|
|
|
|
)
|
|
|
|
|
Export('testsuite')
|
2010-04-16 02:17:15 +02:00
|
|
|
|
2007-08-17 11:06:49 +02:00
|
|
|
|
2007-08-13 09:55:32 +02:00
|
|
|
|
|
|
|
|
|
2009-01-17 14:27:35 +01:00
|
|
|
# for creating a Valgrind-Suppression file
|
2013-01-07 02:15:05 +01:00
|
|
|
vgsuppr = env.Program('vgsuppression',['tool/vgsuppression.c']+core_lib) ## for suppressing false valgrind alarms
|
2012-01-09 02:56:29 +01:00
|
|
|
tools += [vgsuppr]
|
|
|
|
|
Depends(testsuite,vgsuppr)
|
2007-08-17 11:06:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# actually run the Testsuite
|
|
|
|
|
#
|
|
|
|
|
# - the product of running the Testsuite is the ",testlog"
|
2012-01-09 02:56:29 +01:00
|
|
|
# - it depends on all artifacts defined as "testsuite" above
|
2010-04-16 02:17:15 +02:00
|
|
|
# - including the tests/*.tests (suite definition files)
|
2013-01-07 02:15:05 +01:00
|
|
|
# - if not set via options switch, the environment variables TESTMODE,
|
2010-04-16 02:17:15 +02:00
|
|
|
# TESTSUITES and VALGRINDFLAGS are explicitly propagated to test.sh
|
2007-08-17 11:06:49 +02:00
|
|
|
#
|
2007-08-31 20:32:26 +02:00
|
|
|
testEnv = env.Clone()
|
2008-12-26 23:31:00 +01:00
|
|
|
|
|
|
|
|
valgrind = os.environ.get('VALGRINDFLAGS', '') # unset if not defined
|
|
|
|
|
if not valgrind and not env['VALGRIND']:
|
|
|
|
|
valgrind = 'DISABLE'
|
|
|
|
|
|
|
|
|
|
testEnv.Append(ENV = { 'VALGRINDFLAGS' : valgrind
|
2010-04-16 02:17:15 +02:00
|
|
|
, 'LUMIERA_CONFIG_PATH' : './'
|
2013-01-07 02:15:05 +01:00
|
|
|
, 'TEST_CONF' : env.File("test.conf").abspath
|
2008-12-26 23:31:00 +01:00
|
|
|
})
|
2010-04-16 02:17:15 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
def propagateSetting(env, key):
|
|
|
|
|
setting = key in env and env[key] or os.environ.get(key)
|
|
|
|
|
if setting:
|
|
|
|
|
env['ENV'][key] = setting
|
2010-02-15 03:25:01 +01:00
|
|
|
|
2010-04-16 02:17:15 +02:00
|
|
|
|
2013-01-07 02:15:05 +01:00
|
|
|
propagateSetting(testEnv, 'TESTSUITES')
|
|
|
|
|
propagateSetting(testEnv, 'TESTMODE')
|
|
|
|
|
propagateSetting(testEnv, 'LUMIERA_PLUGIN_PATH')
|
2010-02-15 03:25:01 +01:00
|
|
|
|
2011-01-30 15:27:21 +01:00
|
|
|
testDir = env.Dir('#$TARGDIR')
|
2007-09-02 23:57:40 +02:00
|
|
|
runTest = env.File("test.sh").abspath
|
2007-08-31 20:32:26 +02:00
|
|
|
|
2012-01-09 02:56:29 +01:00
|
|
|
runTests = testEnv.Command('#$TARGDIR/,testlog', testsuite, runTest, chdir=testDir)
|
2007-08-18 06:13:39 +02:00
|
|
|
|
2007-08-18 04:28:14 +02:00
|
|
|
|
2007-08-17 11:06:49 +02:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# define Phony targets
|
|
|
|
|
# - 'scons testcode' triggers building of the Testsuite
|
|
|
|
|
# - 'scons check' triggers building and running
|
|
|
|
|
#
|
2012-01-09 02:56:29 +01:00
|
|
|
env.Alias('testcode', testsuite )
|
|
|
|
|
env.Alias('check', runTests )
|
2007-08-17 11:06:49 +02:00
|
|
|
|
2008-10-23 04:53:50 +02:00
|
|
|
# allow tempfiles of test.sh to be cleaned
|
2010-04-16 02:17:15 +02:00
|
|
|
env.Clean ('check', [',testlog',',testlog.pre',',expect_stdout',',stdout',',stderr',',testtmp','.libs'])
|