Add valgrind support to testing

To help find memory leaks!

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-05-14 17:48:43 -04:00
parent bcfa735dd7
commit 7aa5f22777
7 changed files with 53 additions and 41 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ share/ocarina/#*
bin/ bin/
.sconsign.dblite .sconsign.dblite
*.patch *.patch
tests/*-lib

View File

@ -4,6 +4,7 @@ import os
# Configuration variables # Configuration variables
CONFIG_VERSION = 6.1 CONFIG_VERSION = 6.1
CONFIG_DEBUG = True CONFIG_DEBUG = True
CONFIG_TEST_VALGRIND = False
# Set up default environment # Set up default environment
@ -11,28 +12,36 @@ CONFIG_CCFLAGS = [ "-O2" ]
if CONFIG_DEBUG == True: if CONFIG_DEBUG == True:
CONFIG_CCFLAGS = [ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ] CONFIG_CCFLAGS = [ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ]
env = Environment( CCFLAGS = CONFIG_CCFLAGS ) class OEnvironment(Environment):
env.Append(CPPPATH = os.path.abspath("include")) Debug = False
env.Append(CXXCOMSTR = "C++ $TARGET") Version = 0
env.Append(LINKCOMSTR = "Linking $TARGET") Valgrind = False
def __init__(self):
Environment.__init__(self, CCFLAGS = CONFIG_CCFLAGS)
self.Append(CPPPATH = os.path.abspath("include"))
self.Append(CXXCOMSTR = "C++ $TARGET")
self.Append(LINKCOMSTR = "Linking $TARGET")
self.Debug = CONFIG_DEBUG
self.Version = CONFIG_VERSION
self.Valgrind = CONFIG_TEST_VALGRIND
def use_package(name): def UsePackage(self, name):
env.ParseConfig("pkg-config --cflags --libs %s" % name) self.ParseConfig("pkg-config --cflags --libs %s" % name)
Export("env", "use_package", "CONFIG_DEBUG", "CONFIG_VERSION") env = OEnvironment()
test_env = OEnvironment()
Export("env", "test_env")
include = SConscript("include/Sconscript") include = SConscript("include/Sconscript")
lib = SConscript("lib/Sconscript") lib = SConscript("lib/Sconscript")
Export("lib") gui = SConscript("gui/Sconscript")
tests = SConscript("tests/Sconscript") tests = SConscript("tests/Sconscript")
gui = SConscript("gui/Sconscript")
ocarina = env.Program("bin/ocarina", lib + gui) ocarina = env.Program("bin/ocarina", lib + gui, LIBS="y")
Default(ocarina) Default(ocarina)
Clean(ocarina, "bin/") Clean(ocarina, "bin/")

6
TODO
View File

@ -61,13 +61,7 @@ Future work:
the library? Perhaps create a mirror group? the library? Perhaps create a mirror group?
- Extra testing ideas: - Extra testing ideas:
- Run tests through valgrind to help find memory leaks
- Some way to enable / disable tests during development
- Run tests based on dependencies
- Fix tests that will only work on my computer
- Double check that all inputs and outputs are tested - Double check that all inputs and outputs are tested
- Simple testing library?
- Stop tests on failure
- Test callbacks - Test callbacks
- Preferences: - Preferences:

View File

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
Import("use_package") Import("env")
use_package("gtkmm-3.0") env.UsePackage("gtkmm-3.0")
res = Glob("*.cpp") res = Glob("*.cpp")
Return("res") Return("res")

View File

@ -1,8 +1,9 @@
#!/usr/bin/python #!/usr/bin/python
Import("env", "CONFIG_DEBUG", "CONFIG_VERSION") Import("env", "test_env")
version = str(CONFIG_VERSION) version = str(env.Version)
if CONFIG_DEBUG == True: if env.Debug == True:
version += "-debug" version += "-debug"
env.Append( CCFLAGS = [ "-DCONFIG_VERSION='\"%s\"'" % version ] ) for e in (env, test_env):
e.Append( CCFLAGS = [ "-DCONFIG_VERSION='\"%s\"'" % version ] )

View File

@ -1,8 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
Import("use_package") Import("env")
use_package("gstreamer-1.0") env.UsePackage("gstreamer-1.0")
use_package("taglib") env.UsePackage("taglib")
res = Glob("*.cpp") res = Glob("*.cpp")
Return("res") Return("res")

View File

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
import sys import sys, os
Import("env") Import("test_env")
tests = [ tests = [
### ###
@ -9,18 +9,19 @@ tests = [
# (source.cpp, use collected lib_files?, [ other files ]) # (source.cpp, use collected lib_files?, [ other files ])
# #
("version.cpp", False, []), ("version.cpp", False, [], [ "glib-2.0" ]),
("file.cpp", True, []), ("file.cpp", True, [], []),
("database.cpp", True, []), ("database.cpp", True, [], []),
("index.cpp", True, []), ("index.cpp", True, [], []),
("filter.cpp", True, []), ("filter.cpp", True, [], []),
("idle.cpp", False, [ "idle.cpp" ]), ("idle.cpp", False, [ "idle.cpp" ], []),
("tags.cpp", True, []), ("tags.cpp", True, [], [ "taglib" ]),
("queue.cpp", True, [ "callback.cpp" ]), ("queue.cpp", True, [ "callback.cpp" ], []),
] ]
env = test_env
env.UsePackage("glib-2.0")
check_depends = True check_depends = True
for arg in sys.argv: for arg in sys.argv:
@ -33,15 +34,18 @@ for arg in sys.argv:
def expand_files(extra_files): def expand_files(extra_files):
res = [] res = []
for f in extra_files: for f in extra_files:
res += [ "../lib/%s" % f ] res += [ env.Object("%s-lib" % f, "../lib/%s" % f) ]
return res return res
def make_program(src, name, extra_files): def make_program(src, name, extra_files):
return env.Program("%s" % name, [ src ] + expand_files(extra_files)) return env.Program("%s" % name, [ src ] + expand_files(extra_files))
def make_test(src, name): def make_test(src, name):
test = Command("%s.out" % name, [], cmd = "./tests/%s | tee ./tests/%s.out" % (name, name)
"set -o pipefail; ./tests/%s | tee ./tests/%s.out" % (name, name)) if env.Valgrind == True:
cmd = "valgrind -q --leak-check=full --error-exitcode=42 %s" % cmd
test = Command("%s.out" % name, [], "set -o pipefail; %s" % cmd)
Alias("tests/%s" % name, test) Alias("tests/%s" % name, test)
AlwaysBuild(test) AlwaysBuild(test)
return test return test
@ -56,13 +60,16 @@ res = []
lib_files = [] lib_files = []
ignore = open(".gitignore", 'w') ignore = open(".gitignore", 'w')
for src, lib, extra in tests: for src, lib, extra, pkgs in tests:
name = "%s" % src.rsplit(".")[0] name = "%s" % src.rsplit(".")[0]
if lib == True: if lib == True:
lib_files += [ src ] lib_files += [ src ]
extra = lib_files + extra extra = lib_files + extra
for p in pkgs:
env.UsePackage(p)
test = prepare_test(name, src, extra) test = prepare_test(name, src, extra)
if (check_depends == True) and (len(res) > 0): if (check_depends == True) and (len(res) > 0):
Depends(test, res[len(res) - 1]) Depends(test, res[len(res) - 1])