build: Use add_test_setup() to allow tests to be run under valgrind

This means we can specify the standard options for testing GLib under
valgrind consistently, so that developers can use `meson test
--setup=valgrind` to run them.

Port the existing valgrind CI to use them (this will not change its
functional behaviour).

Suggested by Marco Trevisan at
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2717#note_1478891.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2022-06-16 11:01:04 +01:00
parent 594a70bf5f
commit f5baecdb36
2 changed files with 25 additions and 2 deletions

View File

@ -225,8 +225,7 @@ valgrind:
# See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2710
- ulimit -Sn 1024
- bash -x ./.gitlab-ci/run-tests.sh
--wrap "valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes --leak-check=full --leak-resolution=high --num-callers=50 --show-leak-kinds=definite,possible --show-error-list=yes --suppressions=${CI_PROJECT_DIR}/tools/glib.supp"
--no-suite no-valgrind
--setup valgrind
--no-suite slow
# FIXME: Remove this when we have zero valgrind leaks.
# https://gitlab.gnome.org/GNOME/glib/issues/333

View File

@ -102,6 +102,30 @@ installed_tests_template_tap = files('tests/template-tap.test.in')
# Dont build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
build_tests = get_option('tests') and (meson.can_run_host_binaries() or installed_tests_enabled)
# Allow the tests to be easily run under valgrind using --setup=valgrind
valgrind = find_program('valgrind', required: false)
if valgrind.found()
suppression_file = files('tools' / 'glib.supp')
add_test_setup('valgrind',
exclude_suites: [ 'no-valgrind' ],
exe_wrapper: [
valgrind,
'--tool=memcheck',
'--error-exitcode=1',
'--track-origins=yes',
'--leak-check=full',
'--leak-resolution=high',
'--num-callers=50',
'--show-leak-kinds=definite,possible',
'--show-error-list=yes',
'--suppressions=@0@'.format(meson.project_source_root() /
'@0@'.format(suppression_file[0])),
],
timeout_multiplier: 10,
)
endif
add_project_arguments('-D_GNU_SOURCE', language: 'c')
if host_system == 'qnx'