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
2018-11-16 15:25:28 +01:00
Import ( ' env core_lib app_lib vault_lib guimodule 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
2018-11-16 15:25:28 +01:00
elif id . startswith ( ' vault ' ) :
return vault_lib # tests in 'vault*' subdirs only linked against vault layer
elif id . startswith ( ' stage ' ) :
return guimodule + core_lib # tests in 'stage*' are additionally linked against the GTK GUI module
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
2025-06-07 23:59:57 +02:00
@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
2018-11-16 15:25:28 +01:00
if dir . startswith ( ' stage ' ) :
2018-11-16 22:38:29 +01:00
# additional libs used from GUI tests
2015-12-25 03:06:33 +01:00
env . mergeConf ( [ ' sigc++-2.0 ' ] )
2013-01-07 02:15:05 +01:00
# pick up all test classes and link them shared
testlib = [ ]
testClasses = list ( scanSubtree ( dir , [ ' *.cpp ' ] ) )
if testClasses :
2014-10-17 21:15:59 +02:00
testlib = sharedTestLibs [ dir ] = env . SharedLibrary ( ' test- ' + dir , testClasses , addLibs = linkContext ( dir ) ) # note: linking dependencies according to application layers
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
2025-06-07 23:59:57 +02:00
# any test-class on startup, even if no code dependency is visible for the linker
2014-09-30 04:40:24 +02:00
envSuite = env . Clone ( )
2015-08-14 23:39:07 +02:00
envSuite . Append ( LINKFLAGS = ' -Wl,--no-as-needed ' )
2014-09-30 04:40:24 +02:00
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 ( )
2023-01-05 13:42:57 +01:00
testrunner = envSuite . Program ( " test-suite " , [ " testrunner.cpp " ] + list ( testLibs ) + list ( 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
2023-01-05 13:42:57 +01:00
vgsuppression = envSuite . Program ( ' vgsuppression ' , [ ' tool/vgsuppression.c ' ] + list ( testLibs ) + list ( core_lib ) ) ## for suppressing false valgrind alarms
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 ' )
2025-04-24 23:39:58 +02:00
propagateSetting ( testEnv , ' HOME ' )
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 )
2015-08-14 23:39:07 +02:00
Depends ( runTests , vgsuppression )
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
#
2025-11-15 19:08:23 +01:00
env . Alias ( ' testcode ' , testsuite + vgsuppression )
2012-01-09 02:56:29 +01:00
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 ' ] )