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/
.sconsign.dblite
*.patch
tests/*-lib

View File

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

6
TODO
View File

@ -61,13 +61,7 @@ Future work:
the library? Perhaps create a mirror group?
- 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
- Simple testing library?
- Stop tests on failure
- Test callbacks
- Preferences:

View File

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

View File

@ -1,8 +1,9 @@
#!/usr/bin/python
Import("env", "CONFIG_DEBUG", "CONFIG_VERSION")
Import("env", "test_env")
version = str(CONFIG_VERSION)
if CONFIG_DEBUG == True:
version = str(env.Version)
if env.Debug == True:
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
Import("use_package")
Import("env")
use_package("gstreamer-1.0")
use_package("taglib")
env.UsePackage("gstreamer-1.0")
env.UsePackage("taglib")
res = Glob("*.cpp")
Return("res")

View File

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