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 <earl_c...@yahoo.com>
---
 .github/workflows/main.yaml            |  3 ++-
 Makefile.am                            |  5 ++++-
 configure.ac                           |  6 ++++++
 tools/tests/Makefile.am                |  2 ++
 tools/tests/test_ebgenv_api_internal.c | 24 +++++++++++++++---------
 5 files changed, 29 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..f59ce31 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,7 @@
 # Copyright (C) 2013 Karel Zak <k...@redhat.com>
 #
 
-ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
+ACLOCAL_AMFLAGS = -I m4 --install ${ACLOCAL_FLAGS}
 AM_MAKEFLAGS = --no-print-directory
 
 efibootguarddir = $(libdir)/efibootguard
@@ -362,6 +362,9 @@ clean-local-completion-pycache:
        rm -rf $(top_builddir)/completion/bg_printenv/__pycache__
        rm -rf $(top_builddir)/completion/bg_setenv/__pycache__
 
+.PHONY:        check-valgrind-local
+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 de7ef3e..20fcf32 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,6 +237,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
 
-- 
2.39.1

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to efibootguard-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20240214040657.461300-1-earl_chew%40yahoo.com.

Reply via email to