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