@@ -149,6 +149,9 @@ def ParseArguments():
149149 parser .add_argument ( '--quiet' , action = 'store_true' ,
150150 help = 'Quiet installation mode. Just print overall '
151151 'progress and errors' )
152+ parser .add_argument ( '--valgrind' ,
153+ action = 'store_true' ,
154+ help = 'Run tests inside valgrind.' )
152155
153156 parsed_args , pytests_args = parser .parse_known_args ()
154157
@@ -213,6 +216,37 @@ def BuildYcmdLibs( args ):
213216 subprocess .check_call ( build_cmd )
214217
215218
219+ def PytestValgrind ( parsed_args , extra_pytests_args ):
220+ pytests_args = [ '-v' ]
221+ if extra_pytests_args :
222+ pytests_args .extend ( extra_pytests_args )
223+ else :
224+ pytests_args += glob .glob (
225+ p .join ( DIR_OF_THIS_SCRIPT , 'ycmd' , 'tests' , 'bindings' , '*_test.py' ) )
226+ pytests_args += glob .glob (
227+ p .join ( DIR_OF_THIS_SCRIPT , 'ycmd' , 'tests' , 'clang' , '*_test.py' ) )
228+ pytests_args += glob .glob (
229+ p .join ( DIR_OF_THIS_SCRIPT , 'ycmd' , 'tests' , '*_test.py' ) )
230+ # Avoids needing all completers for a valgrind run
231+ pytests_args += [ '-m' , 'not valgrind_skip' ]
232+
233+ new_env = os .environ .copy ()
234+ new_env [ 'PYTHONMALLOC' ] = 'malloc'
235+ new_env [ 'LD_LIBRARY_PATH' ] = LIBCLANG_DIR
236+ cmd = [ 'valgrind' ,
237+ '--gen-suppressions=all' ,
238+ '--error-exitcode=1' ,
239+ '--leak-check=full' ,
240+ '--show-leak-kinds=all' ,
241+ '--show-reachable=no' ,
242+ '--suppressions=' + p .join ( DIR_OF_THIS_SCRIPT ,
243+ 'valgrind.suppressions' ) ]
244+ subprocess .check_call ( cmd +
245+ [ sys .executable , '-m' , 'pytest' ] +
246+ pytests_args ,
247+ env = new_env )
248+
249+
216250def PytestTests ( parsed_args , extra_pytests_args ):
217251 pytests_args = [ '-v' ]
218252
@@ -305,7 +339,10 @@ def Main():
305339 if not parsed_args .no_flake8 :
306340 RunFlake8 ()
307341 BuildYcmdLibs ( parsed_args )
308- PytestTests ( parsed_args , pytests_args )
342+ if parsed_args .valgrind :
343+ PytestValgrind ( parsed_args , pytests_args )
344+ else :
345+ PytestTests ( parsed_args , pytests_args )
309346
310347
311348if __name__ == "__main__" :
0 commit comments