Skip to content

Commit

Permalink
Support check-valgrind
Browse files Browse the repository at this point in the history
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 <[email protected]>
[Jan: drop redundant .PHONY rule]
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
earlchew authored and jan-kiszka committed Feb 14, 2024
1 parent dfc393f commit 0b2e1e6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Copyright (C) 2013 Karel Zak <[email protected]>
#

ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
ACLOCAL_AMFLAGS = -I m4 --install ${ACLOCAL_FLAGS}
AM_MAKEFLAGS = --no-print-directory

efibootguarddir = $(libdir)/efibootguard
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tools/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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@
24 changes: 15 additions & 9 deletions tools/tests/test_ebgenv_api_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down

0 comments on commit 0b2e1e6

Please sign in to comment.