[PATCH 3/7] tests: Convert to automake

13 views
Skip to first unread message

Jan Kiszka

unread,
Sep 24, 2017, 4:20:16 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Jan Kiszka <jan.k...@siemens.com>

Properly integrate our unit tests into automake. This allows to invoke
them via "make check", generating nice reports as well.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.gitignore | 11 ++++-
Makefile.am | 3 ++
configure.ac | 2 +-
tools/tests/Makefile | 105 ------------------------------------------------
tools/tests/Makefile.am | 62 ++++++++++++++++++++++++++++
5 files changed, 75 insertions(+), 108 deletions(-)
delete mode 100644 tools/tests/Makefile
create mode 100644 tools/tests/Makefile.am

diff --git a/.gitignore b/.gitignore
index 2559674..cad1f4a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,13 @@
bg_printenv
bg_setenv

+# Test results
+tools/tests/test_partitions
+tools/tests/test_environment
+tools/tests/test_api
+tools/tests/*.log
+tools/tests/*.trs
+
# Debug files
*.dSYM/
*.su
@@ -69,5 +76,5 @@ Makefile.in
/missing
/stamp-h1
/Makefile
-
-tools/.*
+/tools/tests/Makefile
+.deps/
diff --git a/Makefile.am b/Makefile.am
index c6ebec4..a03d3ea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -193,3 +193,6 @@ bg_printenv: $(bg_setenv)
all-local: bg_printenv

CLEANFILES += bg_printenv
+
+# Tests depend on libraries being built - start with "."
+SUBDIRS = . tools/tests
diff --git a/configure.ac b/configure.ac
index 80dd365..bf4430d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -137,6 +137,7 @@ AC_TYPE_UINT8_T
# ------------------------------------------------------------------------------
AC_CONFIG_FILES([
Makefile
+ tools/tests/Makefile
])

AC_OUTPUT
@@ -154,4 +155,3 @@ AC_MSG_RESULT([
efi libs: ${GNUEFI_LIBS}
efi lds: ${GNUEFI_LDS_DIR}
])
-
diff --git a/tools/tests/Makefile b/tools/tests/Makefile
deleted file mode 100644
index 5a4bfd8..0000000
--- a/tools/tests/Makefile
+++ /dev/null
@@ -1,105 +0,0 @@
-#
-# EFI Boot Guard
-#
-# Copyright (c) Siemens AG, 2017
-#
-# Authors:
-# Andreas Reichel <andreas.r...@siemens.com>
-#
-# This work is licensed under the terms of the GNU GPL, version 2. See
-# the COPYING file in the top-level directory.
-#
-
-PROJECTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
-
-CC ?= $(CROSS_COMPILE)gcc
-LD ?= $(CROSS_COMPILE)ld
-AR ?= $(CROSS_COMPILE)ar
-OBJCOPY ?= $(CROSS_COMPILE)objcopy
-
-INCLUDE ?= /usr/include
-
-CFLAGS = \
- -I$(PROJECTDIR) \
- -I$(PROJECTDIR)/.. \
- -I$(PROJECTDIR)/../../include \
- -I$(PROJECTDIR)/../../swupdate-adapter \
- -std=gnu99 \
- -g
-
-DEFINES = \
- -DHAVE_ENDIAN_H \
- -D_GNU_SOURCE
-
-ifneq ($(DEBUG),)
-DEFINES += -DDEBUG
-endif
-
-CFLAGS += \
- -fshort-wchar
-
-LIBS = -L../.. \
- -L../../swupdate-adapter \
- -lcmocka \
- -lebgenv \
- -lz
-
-# Test recipes shall run everytime independent of already built files.
-# A simple way to achieve this is to depend on files that don't exist
-# by changing their extension with Makefile's string functions.
-# All capital O's get replaced by lower-case o's within the target
-# dependency recipes.
-# All targets' '.target' extensions get removed within the target recipes.
-#
-OBJS_test_partitions = test_partitions.O bg_utils.O ebgpart.O
-OBJS_test_environment = test_environment.O bg_utils.O ebgpart.O
-OBJS_test_api = test_api.O bg_utils.O ebgenv.O
-
-MOCKOBJS_test_partitions = bg_utils ebgpart
-MOCKOBJS_test_environment = bg_utils
-MOCKOBJS_test_api = bg_utils
-
-# Define symbols to be stripped dependent on target and object file name
-# MOCKOBJS_SYMBOLS_objectname-targetname = symbolname1 symbolname2 ...
-
-MOCKOBJS_SYMBOLS_bg_utils-test_partitions = probe_config_file
-MOCKOBJS_SYMBOLS_bg_utils-test_environment = oldenvs configparts fopen fclose fread fwrite feof
-MOCKOBJS_SYMBOLS_bg_utils-test_api = bgenv_init bgenv_write bgenv_close bgenv_get_latest bgenv_get_by_index bgenv_get_oldest
-MOCKOBJS_SYMBOLS_ebgpart-test_partitions = ped_device_probe_all ped_device_get_next ped_disk_next_partition
-
-TEST_TARGETS = test_partitions.target test_environment.target test_api.target
-
-define WEAKEN_SYMBOL =
- objcopy --weaken-symbol $(1) $(2)
-
-endef
-
-define WEAKEN_SYMBOLS =
-$(foreach symbol,$(MOCKOBJS_SYMBOLS_$(1)-$(2)),$(call WEAKEN_SYMBOL,$(symbol),$(1).o))
-endef
-
-define TEST_TARGET_TEMPLATE =
-$(1): $$(OBJS_$(1:.target=))
- $(foreach mockobj,$(MOCKOBJS_$(1:.target=)),$(call WEAKEN_SYMBOLS,$(mockobj),$(1:.target=)))
- $(CC) $$(OBJS_$(1:.target=):O=o) -o $(1:.target=) $(LIBS)
- ./$(1:.target=)
-endef
-
-.PHONY: clean all $(TEST_TARGETS)
-
-all: $(TEST_TARGETS)
-
-$(foreach test,$(TEST_TARGETS),$(eval $(call TEST_TARGET_TEMPLATE,$(test))))
-
-# Search for source files in current and parent directory
-%.O: %.c
- $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o)
-
-%.O: ../%.c
- $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o)
-
-%.O: ../../swupdate-adapter/%.c
- $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o)
-
-clean:
- @rm -rf *.o $(TEST_TARGETS:.target=)
diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am
new file mode 100644
index 0000000..548d085
--- /dev/null
+++ b/tools/tests/Makefile.am
@@ -0,0 +1,62 @@
+#
+# EFI Boot Guard
+#
+# Copyright (c) Siemens AG, 2017
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+OBJCOPY ?= objcopy
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/include \
+ -I$(top_srcdir)/swupdate-adapter \
+ -I$(top_srcdir)/tools
+
+AM_CFLAGS = \
+ -Wno-unused-parameter \
+ -Wmissing-prototypes \
+ -fshort-wchar \
+ -DHAVE_ENDIAN_H \
+ -D_GNU_SOURCE \
+ -g
+
+CLEANFILES =
+
+test_partitions_LDADD = \
+ libebgenv-test_partitions.a \
+ -lcmocka
+
+libebgenv-test_partitions.a: $(top_builddir)/libebgenv.a
+ $(AM_V_GEN) $(OBJCOPY) -W probe_config_file -W ped_device_probe_all \
+ -W ped_device_get_next -W ped_disk_next_partition $< $@
+
+CLEANFILES += libebgenv-test_partitions.a
+
+test_environment_LDADD = \
+ libebgenv-test_environment.a \
+ -lcmocka
+
+libebgenv-test_environment.a: $(top_builddir)/libebgenv.a
+ $(AM_V_GEN) $(OBJCOPY) -W oldenvs -W configparts -W fopen -W fclose \
+ -W fread -W fwrite -W feof $< $@
+
+CLEANFILES += libebgenv-test_environment.a
+
+test_api_LDADD = \
+ libebgenv-test_api.a \
+ -lcmocka
+
+libebgenv-test_api.a: $(top_builddir)/libebgenv.a
+ $(AM_V_GEN) $(OBJCOPY) -W bgenv_init -W bgenv_write -W bgenv_close \
+ -W bgenv_get_latest -W bgenv_get_by_index -W bgenv_get_oldest $< $@
+
+CLEANFILES += libebgenv-test_api.a
+
+check_PROGRAMS = test_partitions test_environment test_api
+
+TESTS = $(check_PROGRAMS)
--
2.12.3

Jan Kiszka

unread,
Sep 24, 2017, 4:20:16 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Jan Kiszka <jan.k...@siemens.com>

Catch missing outputs when building in-tree as well as the backup of
config.h.in that autoreconf creates.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.gitignore | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index e4d18f1..2559674 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,10 @@
# EFI
*.efi

+# Executables
+bg_printenv
+bg_setenv
+
# Debug files
*.dSYM/
*.su
@@ -42,6 +46,7 @@ Makefile.in
/py-compile
/test-driver
/ylwrap
+.dirstamp

# http://www.gnu.org/software/autoconf

@@ -53,7 +58,7 @@ Makefile.in
/compile
/config.guess
/config.h
-/config.h.in
+/config.h.in*
/config.log
/config.status
/config.sub
--
2.12.3

Jan Kiszka

unread,
Sep 24, 2017, 4:20:16 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Jan Kiszka <jan.k...@siemens.com>

gnu-efi upstream as well as distros install the linker scripts into the
lib folder. Thus, there is no reason to configure those two directories
separately.

Remove GNUEFI_LDS_DIR and make sure that GNUEFI_LIB_DIR is set to the
right default, using based on "$CC -print-multi-os-directory". Fix the
reporting at the end of configure as well.

This finally fixes the detection of the gnu-efi location on SUSE.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
Makefile.am | 2 +-
configure.ac | 22 ++++++----------------
docs/COMPILE.md | 1 -
3 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index a03d3ea..911971f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -138,7 +138,7 @@ efi_cflags += \
endif

efi_ldflags = \
- -T $(GNUEFI_LDS_DIR)/elf_$(ARCH)_efi.lds \
+ -T $(GNUEFI_LIB_DIR)/elf_$(ARCH)_efi.lds \
-shared \
-Bsymbolic \
-nostdlib \
diff --git a/configure.ac b/configure.ac
index bf4430d..6b8d50d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,26 +63,17 @@ AC_ARG_WITH([gnuefi-include-dir],
AC_SUBST(GNUEFI_INC_DIR)
AC_DEFINE_UNQUOTED(GNUEFI_INC_DIR, ["$GNUEFI_INC_DIR"], [The include directory for gnuefi])

+efiroot=$(echo $(cd $GNUEFI_SYS_DIR/usr/lib/$($CC -print-multi-os-directory); pwd))
+
AC_ARG_WITH([gnuefi-lib-dir],
AS_HELP_STRING([--with-gnuefi-lib-dir=DIRECTORY],
- [specify the lib directory of gnuefi, defaults to "$GNUEFI_SYS_DIR/usr/lib"]),
+ [specify the lib directory of gnuefi, defaults to "$efiroot"]),
[GNUEFI_LIB_DIR="$withval"],
- [GNUEFI_LIB_DIR="$GNUEFI_SYS_DIR/usr/lib"])
+ [GNUEFI_LIB_DIR="$efiroot"])

AC_SUBST(GNUEFI_LIB_DIR)
AC_DEFINE_UNQUOTED(GNUEFI_LIB_DIR, ["$GNUEFI_LIB_DIR"], [The lib directory for gnuefi])

-efiroot=$(echo $(cd ${GNUEFI_LIB_DIR}/$($CC -print-multi-os-directory); pwd))
-
-AC_ARG_WITH([gnuefi-lds-dir],
- AS_HELP_STRING([--with-gnuefi-lds-dir=DIRECTORY],
- [specify the lds directory of gnuefi, defaults to "$GNUEFI_LIB_DIR/$($CC -print-multi-os-directory)"]),
- [GNUEFI_LDS_DIR="$withval"],
- [GNUEFI_LDS_DIR="$efiroot"])
-
-AC_SUBST(GNUEFI_LDS_DIR)
-AC_DEFINE_UNQUOTED(GNUEFI_LDS_DIR, ["$GNUEFI_LDS_DIR"], [The lds directory for gnuefi])
-
dnl Define ARCH_<NAME> conditionals
SET_ARCH(I586, i586*)
SET_ARCH(I686, i686*)
@@ -148,10 +139,9 @@ AC_MSG_RESULT([
machine type: $MACHINE_TYPE_NAME

prefix: ${prefix}
- exec_prefix: ${exec_prefix}
+ exec_prefix: ${exec_prefix}
libexecdir: ${libexecdir}
libdir: ${libdir}

- efi libs: ${GNUEFI_LIBS}
- efi lds: ${GNUEFI_LDS_DIR}
+ efi libs: ${GNUEFI_LIB_DIR}
])
diff --git a/docs/COMPILE.md b/docs/COMPILE.md
index 51c2008..0429d81 100644
--- a/docs/COMPILE.md
+++ b/docs/COMPILE.md
@@ -40,7 +40,6 @@ autoreconf -fi ..
../configure --host=i586 --build=x86_64-unknown-linux-gnu \
--with-gnuefi-sys-dir=<sys-root-dir> \
--with-gnuefi-include-dir=<sys-root-dir>/usr/include/efi \
- --with-gnuefi-lds-dir=<sys-root-dir>/usr/lib \
--with-gnuefi-lib-dir=<sys-root-dir>/usr/lib
make
```
--
2.12.3

Jan Kiszka

unread,
Sep 24, 2017, 4:20:16 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
This took longer than expected, but now we have a clean build of the
unit tests. With the integration into automake, I gave up on the request
to build the tests unconditionally and rather follow automake standards
(tests are built on "make check").

To ensure that no regression slips in, run the tests in Travis CI. You
can follow our status now at https://travis-ci.org/siemens/efibootguard.

Finally, this revealed a number of smaller issues, some fixes are
included. Not yet addressed are the -Wunused-result, -Wformat= and
-Wformat-security findings of the Travis run under Ubuntu. Andreas,
maybe you can have a look. We probably want to enable those warning for
ourselves as well.

So, please review carefully, specifically the automake conversion. Then,
Andreas, please rebase you remaining patches on top.

Jan

Jan Kiszka (7):
gitignore: Update
tests: Remove unused mount_partition stub
tests: Convert to automake
Rework gnu-efi path configuration
Allow i386 cross build
ci: Enable Travis CI
tests: Fix 32-bit targets by mocking fopen64

.gitignore | 18 +++++--
.travis.yml | 35 ++++++++++++++
Makefile.am | 7 ++-
README.md | 7 ++-
configure.ac | 24 +++-------
docs/COMPILE.md | 1 -
tools/tests/Makefile | 105 -----------------------------------------
tools/tests/Makefile.am | 62 ++++++++++++++++++++++++
tools/tests/test_environment.c | 10 ++--
9 files changed, 135 insertions(+), 134 deletions(-)
create mode 100644 .travis.yml
delete mode 100644 tools/tests/Makefile
create mode 100644 tools/tests/Makefile.am

--
2.12.3

Jan Kiszka

unread,
Sep 24, 2017, 4:20:17 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Jan Kiszka <jan.k...@siemens.com>

Build both x86_64 and i386 variant and run the tests.

As trusty, the default Ubuntu version of Travis, contains a too old
libcmocka, pull it from xenial.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.travis.yml | 35 +++++++++++++++++++++++++++++++++++
README.md | 7 ++++++-
2 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..df4a0db
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,35 @@
+#
+# EFI Boot Guard
+#
+# Copyright (c) Siemens AG, 2017
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+language: c
+
+compiler:
+ - gcc
+
+sudo: required
+
+install:
+ - sudo apt-get install gcc-multilib gnu-efi libpci-dev libz-dev:i386
+ - sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu xenial universe'
+ - sudo apt-get update -qq
+ - sudo apt-get install --no-install-recommends --target-release xenial libcmocka-dev
+
+script:
+ - autoreconf -fi
+ - mkdir build-x86_64 && cd build-x86_64
+ - ../configure
+ - make check
+ # Switch to 32-bit (libcmocka-dev can only be installed in one variant)
+ - sudo apt-get install --no-install-recommends --target-release xenial libcmocka-dev:i386
+ - mkdir ../build-i586 && cd ../build-i586
+ - ../configure --with-gnuefi-lib-dir=/usr/lib32 CFLAGS=-m32 host_alias=i586-linux
+ - make check
diff --git a/README.md b/README.md
index d29151f..8c859a8 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,12 @@ Archive:
For sending patches, please refer to the mailing list and `CONTRIBUTING.md` in
the source tree.

+Continuous integration:
+* [Travis CI](https://travis-ci.org/siemens/efibootguard)
+* Status:
+ * ![](https://travis-ci.org/siemens/efibootguard.svg?branch=master) on master
+ * ![](https://travis-ci.org/siemens/efibootguard.svg?branch=next) on next
+
## Watchdog support ##

The following watchdog drivers are implemented:
@@ -43,4 +49,3 @@ See `Installation And Usage` for further information.
* [Compilation Instructions](docs/COMPILE.md)
* [Installation And Usage](docs/USAGE.md)
* [Future Work](docs/TODO.md)
-
--
2.12.3

Jan Kiszka

unread,
Sep 24, 2017, 4:20:17 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Jan Kiszka <jan.k...@siemens.com>

If large files are enabled, fopen will translate to fopen64.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
tools/tests/Makefile.am | 4 ++--
tools/tests/test_environment.c | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am
index 548d085..c99ba60 100644
--- a/tools/tests/Makefile.am
+++ b/tools/tests/Makefile.am
@@ -42,8 +42,8 @@ test_environment_LDADD = \
-lcmocka

libebgenv-test_environment.a: $(top_builddir)/libebgenv.a
- $(AM_V_GEN) $(OBJCOPY) -W oldenvs -W configparts -W fopen -W fclose \
- -W fread -W fwrite -W feof $< $@
+ $(AM_V_GEN) $(OBJCOPY) -W oldenvs -W configparts -W fopen -W fopen64 \
+ -W fclose -W fread -W fwrite -W feof $< $@

CLEANFILES += libebgenv-test_environment.a

diff --git a/tools/tests/test_environment.c b/tools/tests/test_environment.c
index 423eed0..caecd72 100644
--- a/tools/tests/test_environment.c
+++ b/tools/tests/test_environment.c
@@ -40,6 +40,11 @@ FILE *fopen(const char *filename, const char *mode)
return NULL;
}

+FILE *fopen64(const char *filename, const char *mode)
+{
+ return fopen(filename, mode);
+}
+
int fclose(FILE *handle)
{
return mock_type(int);
--
2.12.3

Jan Kiszka

unread,
Sep 24, 2017, 4:20:17 PM9/24/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Jan Kiszka <jan.k...@siemens.com>

Make sure to pass the CFLAGS to gcc when retrieving libgcc files - it
may contain an arch override.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 911971f..426a17f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -177,7 +177,7 @@ $(top_builddir)/drivers/watchdog/%.o: $(top_srcdir)/drivers/watchdog/%.S

$(efi_solib): $(efi_objects)
$(AM_V_CCLD)$(LD) $(efi_ldflags) $(efi_objects) \
- -o $@ -lefi -lgnuefi $(shell $(CC) -print-libgcc-file-name); \
+ -o $@ -lefi -lgnuefi $(shell $(CC) $(CFLAGS) -print-libgcc-file-name); \
nm -D -u $@ | grep ' U ' && exit 1 || :

$(efi_loadername): $(efi_solib)
--
2.12.3

Reply all
Reply to author
Forward
0 new messages