2828from .get_tools import get_make_tool , \
2929 get_cmake_tool , \
3030 get_cxx_tool , \
31- get_c_tool
31+ get_c_tool , \
32+ get_valgrind_tool
3233from .settings import DEFAULT_CMAKE_GENERATORS
3334
3435class UnitTestTool (object ):
@@ -59,7 +60,8 @@ def create_makefiles(self,
5960 path_to_src = None ,
6061 generator = None ,
6162 coverage_output_type = None ,
62- debug = False ):
63+ debug = False ,
64+ valgrind = False ):
6365 """
6466 Create Makefiles and prepare targets with CMake.
6567
@@ -94,6 +96,17 @@ def create_makefiles(self,
9496 if coverage_output_type :
9597 args .append ("-DCOVERAGE:STRING=%s" % coverage_output_type )
9698
99+ if valgrind :
100+ valgrind = get_valgrind_tool ()
101+ if valgrind is None :
102+ logging .error (
103+ "No Valgrind found in Path. Install all the required tools.\n " )
104+ sys .exit (1 )
105+ args .append ("-DVALGRIND=1" )
106+ args .append ("-DMEMORYCHECK_COMMAND_OPTIONS=\" --track-origins=yes\" \" --leak-check=full\" \" --show-reachable=yes\" \" --error-exitcode=1\" " )
107+ else :
108+ args .append ("-DVALGRIND=0" )
109+
97110 if path_to_src is not None :
98111 args .append (path_to_src )
99112
@@ -118,7 +131,7 @@ def build_tests(self):
118131 "Building unit tests failed." ,
119132 "Unit tests built successfully." )
120133
121- def run_tests (self , filter_regex = None ):
134+ def run_tests (self , filter_regex = None , valgrind = False ):
122135 """
123136 Run unit tests.
124137
@@ -127,11 +140,16 @@ def run_tests(self, filter_regex=None):
127140 """
128141
129142 args = [self .make_program , "test" ]
130-
131- if filter_regex :
132- args .append ("ARGS=-R %s -V -D ExperimentalTest" % filter_regex )
143+ if valgrind :
144+ if filter_regex :
145+ args .append ("ARGS=-R %s -V -D ExperimentalMemCheck" % filter_regex )
146+ else :
147+ args .append ("ARGS=-V -D ExperimentalMemCheck" )
133148 else :
134- args .append ("ARGS=-V -D ExperimentalTest" )
149+ if filter_regex :
150+ args .append ("ARGS=-R %s -V -D ExperimentalTest" % filter_regex )
151+ else :
152+ args .append ("ARGS=-V -D ExperimentalTest" )
135153
136154 if logging .getLogger ().getEffectiveLevel () == logging .DEBUG :
137155 args .append ("VERBOSE=1" )
0 commit comments