Skip to content

Commit 8bc5e05

Browse files
authored
Merge pull request #1383 from bstaletic/valgrind
[READY] Run valgrind in CI
2 parents 9a6b86e + 4a8260a commit 8bc5e05

8 files changed

Lines changed: 423 additions & 13 deletions

File tree

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
YCM_BENCHMARK: true
2121
COVERAGE: false
2222
'C++ linting':
23-
YCM_PYTHON_VERSION: '3.6.3'
23+
YCM_PYTHON_VERSION: '3.8.0'
2424
YCM_CLANG_TIDY: true
2525
COVERAGE: false
2626
maxParallel: 6

azure/lint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pyenv global ${YCM_PYTHON_VERSION}
1313
python_version=$(python -c 'import sys; print( "{}.{}.{}".format( *sys.version_info[:3] ) )')
1414
echo "Checking python version (actual ${python_version} vs expected ${YCM_PYTHON_VERSION})"
1515
test ${python_version} == ${YCM_PYTHON_VERSION}
16-
17-
python build.py --clang-completer --clang-tidy --no-regex
16+
YCM_TESTRUN=1 python build.py --clang-completer --clang-tidy --valgrind
17+
python run_tests.py --valgrind --skip-build --no-flake8
1818

1919
set +e

azure/linux/install_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if [ "${YCM_CLANG_TIDY}" ]; then
2020
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
2121
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main"
2222
sudo apt-get update
23-
sudo apt-get install -y clang-tidy-8
23+
sudo apt-get install -y clang-tidy-8 valgrind
2424
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-8 100
2525
fi
2626

build.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ def ParseArguments():
430430
parser.add_argument( '--no-regex',
431431
action = 'store_true',
432432
help = "Don't build the regex module" )
433+
parser.add_argument( '--valgrind',
434+
action = 'store_true',
435+
help = 'For developers: '
436+
'Run core tests inside valgrind.' )
433437
parser.add_argument( '--clang-tidy',
434438
action = 'store_true',
435439
help = 'For developers: Run clang-tidy static analysis '
@@ -543,13 +547,26 @@ def RunYcmdTests( args, build_dir ):
543547
tests_cmd = [ p.join( tests_dir, 'ycm_core_tests' ) ]
544548
if args.core_tests != '*':
545549
tests_cmd.append( '--gtest_filter={}'.format( args.core_tests ) )
546-
CheckCall( tests_cmd,
547-
env = new_env,
548-
quiet = args.quiet,
549-
status_message = 'Running ycmd tests' )
550-
551-
552-
def RunYcmdBenchmarks( build_dir ):
550+
if not args.valgrind:
551+
CheckCall( tests_cmd,
552+
env = new_env,
553+
quiet = args.quiet,
554+
status_message = 'Running ycmd tests' )
555+
else:
556+
new_env[ 'PYTHONMALLOC' ] = 'malloc'
557+
cmd = [ 'valgrind',
558+
'--gen-suppressions=all',
559+
'--error-exitcode=1',
560+
'--leak-check=full',
561+
'--show-leak-kinds=all',
562+
'--show-reachable=no',
563+
'--suppressions=' + p.join( DIR_OF_THIS_SCRIPT,
564+
'valgrind.suppressions' ),
565+
p.join( tests_dir, 'ycm_core_tests' ) ]
566+
CheckCall( cmd, env = new_env )
567+
568+
569+
def RunYcmdBenchmarks( args, build_dir ):
553570
benchmarks_dir = p.join( build_dir, 'ycm', 'benchmarks' )
554571
new_env = os.environ.copy()
555572

@@ -636,7 +653,7 @@ def BuildYcmdLib( cmake, cmake_common_args, script_args ):
636653
if script_args.core_tests:
637654
RunYcmdTests( script_args, build_dir )
638655
if 'YCM_BENCHMARK' in os.environ:
639-
RunYcmdBenchmarks( build_dir )
656+
RunYcmdBenchmarks( script_args, build_dir )
640657
finally:
641658
os.chdir( DIR_OF_THIS_SCRIPT )
642659

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ xfail_strict = true
55
log_level = debug
66
log_date_format = "%Y-%m-%d %H:%M:%S"
77
log_format = "%(asctime)s - %(levelname)s - %(message)s"
8+
markers = valgrind_skip

run_tests.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
216250
def 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

311348
if __name__ == "__main__":

0 commit comments

Comments
 (0)