2013-07-05 09:40:11 -04:00
|
|
|
#!/usr/bin/python
|
2014-03-03 12:09:51 -05:00
|
|
|
|
2014-05-14 17:48:43 -04:00
|
|
|
import sys, os
|
|
|
|
Import("test_env")
|
2014-06-14 10:50:18 -04:00
|
|
|
|
|
|
|
test_env.UsePackage("glib-2.0")
|
|
|
|
test_env.DEBUG = True
|
|
|
|
|
|
|
|
if test_env.Coverage == True:
|
|
|
|
test_env.Append( CCFLAGS = [ "--coverage" ] )
|
|
|
|
test_env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] )
|
2014-04-13 18:39:56 -04:00
|
|
|
check_depends = True
|
|
|
|
|
|
|
|
for arg in sys.argv:
|
2014-06-14 10:50:18 -04:00
|
|
|
if arg.find("tests/core") == 0 and len(arg) > 11:
|
2014-05-20 17:22:49 -04:00
|
|
|
check_depends = False
|
2014-04-13 18:39:56 -04:00
|
|
|
break
|
2014-06-14 20:43:20 -04:00
|
|
|
if arg.find("tests/lib") == 0 and len(arg) > 10:
|
|
|
|
check_depends = False
|
|
|
|
break
|
2014-03-03 12:09:51 -05:00
|
|
|
|
2014-11-01 14:45:31 -04:00
|
|
|
valgrind = ""
|
|
|
|
if test_env.Valgrind == True:
|
|
|
|
valgrind = "valgrind -q --leak-check=full --error-exitcode=42"
|
2014-06-14 10:50:18 -04:00
|
|
|
gcov = "gcov -r tests/%s/*.gcda"
|
2014-11-01 14:39:30 -04:00
|
|
|
res = []
|
|
|
|
|
|
|
|
|
|
|
|
def all_tests_enabled(dir):
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
arg = os.path.normpath(arg)
|
|
|
|
name = os.path.basename(arg)
|
|
|
|
if (arg.find("tests") == 0) and (name == "tests"):
|
|
|
|
return True
|
|
|
|
if (arg.find("tests/%s" % dir) == 0) and (name == dir):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def add_test(test, dir):
|
|
|
|
global res
|
|
|
|
if (all_tests_enabled(dir) == True) and (len(res) > 0):
|
|
|
|
Depends(test, res[-1])
|
|
|
|
res += [ test ]
|
|
|
|
|
|
|
|
def get_test_obj(name, dir):
|
|
|
|
src = "../../%s/%s.cpp" % (dir, name)
|
|
|
|
if os.path.exists(src):
|
|
|
|
return test_env.Object("%s.cpp-%s" % (name, dir), src)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def generic_test(name, dir, objs, extra):
|
2014-11-01 14:45:31 -04:00
|
|
|
global valgrind
|
|
|
|
|
2014-11-01 14:39:30 -04:00
|
|
|
obj = get_test_obj(name, dir)
|
|
|
|
if obj != None:
|
|
|
|
objs += [ obj ]
|
|
|
|
test_objs = extra + objs
|
|
|
|
else:
|
|
|
|
test_objs = extra
|
|
|
|
|
|
|
|
exe = test_env.Program(name, [ "%s.cpp" % name ] + test_objs)
|
2014-11-01 14:45:31 -04:00
|
|
|
test = Command("%s.fake" % name, [], "%s tests/%s/%s" % (valgrind, dir, name));
|
2014-11-01 14:39:30 -04:00
|
|
|
Alias("tests/%s/%s" % (dir, name), test)
|
|
|
|
Depends(test, exe)
|
|
|
|
add_test(test, dir)
|
|
|
|
return objs
|
|
|
|
|
2014-05-06 08:36:11 -04:00
|
|
|
|
2014-05-14 17:48:43 -04:00
|
|
|
|
2014-06-14 10:50:18 -04:00
|
|
|
class TestList:
|
|
|
|
def __init__(self, subdir, tests):
|
|
|
|
self.subdir = subdir
|
|
|
|
self.tests = tests
|
2014-03-02 12:00:41 -05:00
|
|
|
|
2014-06-14 10:50:18 -04:00
|
|
|
f = open(".gitignore", "w")
|
|
|
|
for t in tests:
|
|
|
|
f.write(t.Name + "\n")
|
|
|
|
f.close()
|
2014-05-20 17:22:49 -04:00
|
|
|
|
2014-06-14 10:50:18 -04:00
|
|
|
def prepare(self):
|
|
|
|
res = []
|
|
|
|
for t in self.tests:
|
|
|
|
res += [ t.prepare(self.subdir) ]
|
2014-05-20 17:22:49 -04:00
|
|
|
|
2014-06-14 10:50:18 -04:00
|
|
|
if test_env.Coverage == True:
|
|
|
|
res += [ Command("%s.gcov" % self.subdir, [], gcov % self.subdir) ]
|
|
|
|
Depends(res[len(res) - 1], res[len(res) - 2])
|
|
|
|
AlwaysBuild(res[len(res) - 1])
|
|
|
|
return res
|
|
|
|
|
|
|
|
Export("OTest", "TestList")
|
2014-11-01 14:39:30 -04:00
|
|
|
Export("get_test_obj", "generic_test")
|
2014-03-02 14:44:24 -05:00
|
|
|
|
2014-06-14 10:50:18 -04:00
|
|
|
|
|
|
|
core = SConscript("core/Sconscript")
|
2014-06-14 20:43:20 -04:00
|
|
|
lib = SConscript("lib/Sconscript")
|
2014-06-14 10:50:18 -04:00
|
|
|
|
2014-11-01 14:39:30 -04:00
|
|
|
#res = [ core, lib ]
|
2014-06-14 10:50:18 -04:00
|
|
|
if test_env.CppCheck == True:
|
|
|
|
res += [ Command("cpp.check", [], "cppcheck -q --error-exitcode=42 .") ]
|
|
|
|
Depends(res[len(res) - 1], res[len(res) - 2])
|
|
|
|
|
|
|
|
Return("res")
|