28
28
from .get_tools import get_make_tool , \
29
29
get_cmake_tool , \
30
30
get_cxx_tool , \
31
- get_c_tool
31
+ get_c_tool , \
32
+ get_valgrind_tool
32
33
from .settings import DEFAULT_CMAKE_GENERATORS
33
34
34
35
class UnitTestTool (object ):
@@ -59,7 +60,8 @@ def create_makefiles(self,
59
60
path_to_src = None ,
60
61
generator = None ,
61
62
coverage_output_type = None ,
62
- debug = False ):
63
+ debug = False ,
64
+ valgrind = False ):
63
65
"""
64
66
Create Makefiles and prepare targets with CMake.
65
67
@@ -94,6 +96,17 @@ def create_makefiles(self,
94
96
if coverage_output_type :
95
97
args .append ("-DCOVERAGE:STRING=%s" % coverage_output_type )
96
98
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
+
97
110
if path_to_src is not None :
98
111
args .append (path_to_src )
99
112
@@ -118,7 +131,7 @@ def build_tests(self):
118
131
"Building unit tests failed." ,
119
132
"Unit tests built successfully." )
120
133
121
- def run_tests (self , filter_regex = None ):
134
+ def run_tests (self , filter_regex = None , valgrind = False ):
122
135
"""
123
136
Run unit tests.
124
137
@@ -127,11 +140,16 @@ def run_tests(self, filter_regex=None):
127
140
"""
128
141
129
142
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" )
133
148
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" )
135
153
136
154
if logging .getLogger ().getEffectiveLevel () == logging .DEBUG :
137
155
args .append ("VERBOSE=1" )
0 commit comments