From 53f0c2a6aafc3c784dfd84d2c956f174debb7f3b Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 20 May 2014 17:22:49 -0400 Subject: [PATCH] testing: Add gcov and cppcheck tests It doesn't hurt to run even more tests on the code! Signed-off-by: Anna Schumaker --- .gitignore | 3 +++ Sconstruct | 15 ++++++++++++--- TODO | 5 +++++ tests/Sconscript | 19 +++++++++++++++---- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 469f6001..ab606dd9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ bin/ .sconsign.dblite *.patch tests/*-lib +*.gcov +*.gcda +*.gcno diff --git a/Sconstruct b/Sconstruct index b00961af..e9d657e9 100644 --- a/Sconstruct +++ b/Sconstruct @@ -5,6 +5,8 @@ import os CONFIG_VERSION = 6.1 CONFIG_DEBUG = True CONFIG_TEST_VALGRIND = False +CONFIG_TEST_COVERAGE = False +CONFIG_TEST_CPPCHECK = False # Set up default environment @@ -16,21 +18,25 @@ class OEnvironment(Environment): Debug = False Version = 0 Valgrind = False + Coverage = False + CppCheck = False - def __init__(self): - Environment.__init__(self, CCFLAGS = CONFIG_CCFLAGS) + def __init__(self, CCFLAGS = CONFIG_CCFLAGS): + Environment.__init__(self, CCFLAGS = 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 + self.Coverage = CONFIG_TEST_COVERAGE + self.CppCheck = CONFIG_TEST_CPPCHECK def UsePackage(self, name): self.ParseConfig("pkg-config --cflags --libs %s" % name) env = OEnvironment() -test_env = OEnvironment() +test_env = OEnvironment( CONFIG_CCFLAGS + [ "-DCONFIG_TEST" ] ) Export("env", "test_env") @@ -39,6 +45,9 @@ lib = SConscript("lib/Sconscript") gui = SConscript("gui/Sconscript") tests = SConscript("tests/Sconscript") +Clean(tests, Glob("*.gcov")) +Clean(tests, Glob("tests/*.gcda")) +Clean(tests, Glob("tests/*.gcno")) ocarina = env.Program("bin/ocarina", lib + gui) diff --git a/TODO b/TODO index c0b3ddec..98219f24 100644 --- a/TODO +++ b/TODO @@ -89,3 +89,8 @@ Future work: - Functions to tag individual files - Functions to read multiple tags from a single text file when CONFIG_TEST == true + - Doxygen support for documentation? + - Jenkins + - Run tests + - Show gcov graph + - Run cppcheck diff --git a/tests/Sconscript b/tests/Sconscript index c6cf7c42..690fdb65 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -24,13 +24,14 @@ tests = [ env = test_env env.UsePackage("glib-2.0") +if env.Coverage == True: + env.Append( CCFLAGS = [ "--coverage" ] ) + env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] ) check_depends = True for arg in sys.argv: - if arg.find("tests") == 0: - env.Append( CCFLAGS = [ "-DCONFIG_TEST" ] ) - if len(arg) > 5: - check_depends = False + if arg.find("tests") == 0 and len(arg) > 5: + check_depends = False break def expand_files(extra_files): @@ -80,6 +81,16 @@ for src, lib, extra, pkgs in tests: ignore.write(name + "\n") ignore.close(); +if env.Coverage == True: + cov = Command("ocarina.gcov", [], "gcov -r tests/*.gcda") + Depends(cov, res[len(res) - 1]) + res += [ cov ] + +if env.CppCheck == True: + check = Command("cpp.check", [], "cppcheck -q .") + Depends(check, res[len(res) - 1]) + res += [ check ] + Return("res") ##scripts = [ "library", "deck", "audio", "gui" ]