From 0b2e1e6df23d700330b4482e968fb7c9f7980fba Mon Sep 17 00:00:00 2001 From: Earl Chew Date: Wed, 14 Feb 2024 05:06:57 +0100 Subject: [PATCH] Support check-valgrind Use AX_VALGRIND_CHECK in configure.ac to enable support for check-valgrind target that uses valgrind when running unit tests. Signed-off-by: Earl Chew [Jan: drop redundant .PHONY rule] Signed-off-by: Jan Kiszka --- .github/workflows/main.yaml | 3 ++- Makefile.am | 4 +++- configure.ac | 6 ++++++ tools/tests/Makefile.am | 2 ++ tools/tests/test_ebgenv_api_internal.c | 24 +++++++++++++++--------- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2cce035..5c589d8 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -44,7 +44,7 @@ jobs: sudo apt-get update sudo apt-get install --no-install-recommends \ autoconf-archive gcc-multilib gnu-efi libpci-dev check \ - bats libarchive-zip-perl + bats libarchive-zip-perl valgrind - name: Install i386 dependencies if: ${{ matrix.target == 'i386' }} run: | @@ -124,6 +124,7 @@ jobs: pushd build >/dev/null ../configure make check -j $(nproc) + make check-valgrind -j $(nproc) sudo make install time bats --tap ../tests popd >/dev/null diff --git a/Makefile.am b/Makefile.am index 3b05e7c..6ad18e7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,7 +15,7 @@ # Copyright (C) 2013 Karel Zak # -ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} +ACLOCAL_AMFLAGS = -I m4 --install ${ACLOCAL_FLAGS} AM_MAKEFLAGS = --no-print-directory efibootguarddir = $(libdir)/efibootguard @@ -362,6 +362,8 @@ clean-local-completion-pycache: rm -rf $(top_builddir)/completion/bg_printenv/__pycache__ rm -rf $(top_builddir)/completion/bg_setenv/__pycache__ +check-valgrind-local: $(GEN_VERSION_H) + # Tests depend on libraries being built - start with "." SUBDIRS = . tools/tests diff --git a/configure.ac b/configure.ac index 4ae45f3..c8d2162 100644 --- a/configure.ac +++ b/configure.ac @@ -231,6 +231,12 @@ AS_IF([test "x$enable_completion" != "xno"], ]) AM_CONDITIONAL([COMPLETION], [test "x$enable_completion" != "xno"]) +AX_VALGRIND_DFLT(memcheck, on) +AX_VALGRIND_DFLT(helgrind, off) +AX_VALGRIND_DFLT(drd, off) +AX_VALGRIND_DFLT(sgcheck, off) +AX_VALGRIND_CHECK + # ------------------------------------------------------------------------------ AC_CONFIG_FILES([ Makefile diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am index 58fd26f..97d4367 100644 --- a/tools/tests/Makefile.am +++ b/tools/tests/Makefile.am @@ -108,3 +108,5 @@ test_fat_SOURCES = test_fat.c $(SRC_TEST_COMMON) test_fat_LDADD = $(FAT_TESTLIB) $(LIBCHECK_LIBS) TESTS = $(check_PROGRAMS) + +@VALGRIND_CHECK_RULES@ diff --git a/tools/tests/test_ebgenv_api_internal.c b/tools/tests/test_ebgenv_api_internal.c index 6a3d816..08d690d 100644 --- a/tools/tests/test_ebgenv_api_internal.c +++ b/tools/tests/test_ebgenv_api_internal.c @@ -165,12 +165,14 @@ END_TEST START_TEST(ebgenv_api_internal_bgenv_write) { + bool err = true; + bool res; BGENV *dummy_env; dummy_env = calloc(1, sizeof(BGENV)); if (!dummy_env) { - goto bgew_error; + goto finally; } RESET_FAKE(write_env); @@ -194,25 +196,29 @@ START_TEST(ebgenv_api_internal_bgenv_write) */ dummy_env->desc = calloc(1, sizeof(CONFIG_PART)); if (!dummy_env->desc) { - goto bgew_error; + goto finally; } dummy_env->data = calloc(1, sizeof(BG_ENVDATA)); if (!dummy_env->data) { - goto bgew_error; + goto finally; } res = bgenv_write(dummy_env); ck_assert(write_env_fake.call_count == 1); ck_assert(res == true); - return; + err = false; + +finally: + if (dummy_env) { + free(dummy_env->data); + free(dummy_env->desc); + free(dummy_env); + } -bgew_error: - free(dummy_env->data); - free(dummy_env->desc); - free(dummy_env); - exit(errno); + if (err) + ck_abort(); } END_TEST