On 2017-09-21 15:21, [ext] Andreas J. Reichel wrote: > From: Andreas Reichel <[email protected]> > > Per default, tests are now always compiled. > > To run tests, with the main Makefile, issue > * 'make check'. > > The Makefile in `tools/tests` is changed so that: > * `make all` and `make build-tests`: builds the tests > * `make run-tests`: runs the tests > > Mention missing dependency in docs/COMPILE.md for cmocka > > Fix out-off-tree build for tests. > > Signed-off-by: Andreas Reichel <[email protected]> > --- > Makefile.am | 16 +++++++++++++- > docs/COMPILE.md | 11 ++++++++-- > tools/tests/Makefile | 61 > ++++++++++++++++++++++++++++++++-------------------- > 3 files changed, 62 insertions(+), 26 deletions(-) > > diff --git a/Makefile.am b/Makefile.am > index c6ebec4..f17b8d0 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -87,6 +87,8 @@ install-exec-hook: > $(LN_S) -f bg_setenv$(EXEEXT) \ > $(DESTDIR)$(bindir)/bg_printenv$(EXEEXT) > > +SRCDIR = $(realpath $(top_srcdir)) > +BUILDDIR = $(realpath $(top_builddir)) > # > # EFI compilation > # > @@ -190,6 +192,18 @@ bg_printenvdir = $(top_srcdir) > bg_printenv: $(bg_setenv) > $(LN_S) -f bg_setenv bg_printenv > > -all-local: bg_printenv > +all-local: bg_printenv build_tests > + > +build_tests: > + make -C $(top_srcdir)/tools/tests build-tests \ > + BUILDDIR=$(BUILDDIR) SRCDIR=$(SRCDIR)
Indention makes reading this hard -> 2 tabs. > + > +.PHONY: check > +check: > + make -C $(top_srcdir)/tools/tests run-tests \ > + BUILDDIR=$(BUILDDIR) > + > +clean-local: > + make -C $(top_srcdir)/tools/tests clean BUILDDIR=$(BUILDDIR) > > CLEANFILES += bg_printenv > diff --git a/docs/COMPILE.md b/docs/COMPILE.md > index 51c2008..0927fd1 100644 > --- a/docs/COMPILE.md > +++ b/docs/COMPILE.md > @@ -5,13 +5,13 @@ > ### Arch Linux ### > > ``` > -pacman -S gnu-efi-libs pciutils > +pacman -S gnu-efi-libs pciutils cmocka > ``` > > ### Debian 8 ### > > ``` > -apt-get install gnu-efi libpci-dev > +apt-get install gnu-efi libpci-dev libcmocka-dev > ``` > > ## Compilation ## > @@ -28,6 +28,13 @@ autoreconf -fi > make > ``` > > +This will also automatically compile internal tests for the environment API. > + > +To run the tests, call > +``` > +make check > +``` > + > To cross-compile, the environment variables must be set accordingly, i.e. > `CXX=<compiler-to-use>`. The following example shows how to specify needed > paths for an out-of-tree build, where cross-compilation environment variables > diff --git a/tools/tests/Makefile b/tools/tests/Makefile > index d52deaa..8e77cd9 100644 > --- a/tools/tests/Makefile > +++ b/tools/tests/Makefile > @@ -19,11 +19,15 @@ OBJCOPY ?= $(CROSS_COMPILE)objcopy > > INCLUDE ?= /usr/include > > +BUILDDIR ?= . > +SRCDIR ?= . > + > CFLAGS = \ > - -I$(PROJECTDIR) \ > - -I$(PROJECTDIR)/.. \ > - -I$(PROJECTDIR)/../../include \ > - -I$(PROJECTDIR)/../../swupdate-adapter \ > + -I$(BUILDDIR) \ > + -I$(SRCDIR) \ > + -I$(SRCDIR)/tools \ > + -I$(SRCDIR)/include \ > + -I$(SRCDIR)/swupdate-adapter \ > -std=gnu99 \ > -g > > @@ -38,11 +42,9 @@ endif > CFLAGS += \ > -fshort-wchar > > -LIBS = -L../.. \ > - -L../../swupdate-adapter \ > - -lcmocka \ > - -lebgenv \ > - -lz > +LIBS = -lcmocka \ > + $(BUILDDIR)/libebgenv.a \ > + -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 > @@ -70,7 +72,7 @@ MOCKOBJS_SYMBOLS_ebgpart-test_partitions = > ped_device_probe_all ped_device_get_n > TEST_TARGETS = test_partitions.target test_environment.target test_api.target > > define WEAKEN_SYMBOL = > - objcopy --weaken-symbol $(1) $(2) > + objcopy --weaken-symbol $(1) $(BUILDDIR)/$(2) > > endef > > @@ -78,28 +80,41 @@ define WEAKEN_SYMBOLS = > $(foreach symbol,$(MOCKOBJS_SYMBOLS_$(1)-$(2)),$(call > WEAKEN_SYMBOL,$(symbol),$(1).o)) > endef > > -define TEST_TARGET_TEMPLATE = > +define TEST_TARGET_COMPILE_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=) > + $(CC) $$(addprefix $(BUILDDIR)/, $$(OBJS_$(1:.target=):O=o)) -o > $(BUILDDIR)/$(1:.target=) $(LIBS) > +endef > + > +define TEST_TARGET_RUN_TEMPLATE = > +$(1:.target=.run): $(BUILDDIR)/$(1:.target=) > + $(BUILDDIR)/$(1:.target=) > endef > > -.PHONY: clean all $(TEST_TARGETS) > +.PHONY: clean all $(TEST_TARGETS) build-tests run-tests > + > +all: build-tests > > -all: $(TEST_TARGETS) > +build-tests: $(TEST_TARGETS) > > -$(foreach test,$(TEST_TARGETS),$(eval $(call TEST_TARGET_TEMPLATE,$(test)))) > +$(foreach test,$(TEST_TARGETS),$(eval $(call > TEST_TARGET_COMPILE_TEMPLATE,$(test)))) > + > +run-tests: $(TEST_TARGETS:.target=.run) > + > +$(foreach test,$(TEST_TARGETS),$(eval $(call > TEST_TARGET_RUN_TEMPLATE,$(test)))) > > # Search for source files in current and parent directory > -%.O: %.c > - $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o) > +%.O: $(SRCDIR)/tools/tests/%.c > + $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(BUILDDIR)/$(@:O=o) > + > +%.O: $(SRCDIR)/tools/%.c > + $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(BUILDDIR)/$(@:O=o) > > -%.O: ../%.c > - $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o) > +%.O: $(SRCDIR)/swupdate-adapter/%.c > + $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(BUILDDIR)/$(@:O=o) > > -%.O: ../../swupdate-adapter/%.c > - $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(@:O=o) > +%.O: $(SRCDIR)/env/%.c > + $(CC) $(CFLAGS) $(DEFINES) -c $< -o $(BUILDDIR)/$(@:O=o) > > clean: > - @rm -rf *.o $(TEST_TARGETS:.target=) > + rm -f $(BUILDDIR)/*.o $(addprefix $(BUILDDIR)/, > $(TEST_TARGETS:.target=)) > But this dumps all the output into the top-level folder, both for in-tree and out-of-tree. Ugly. It also rebuilds the tests each time you run make or make check. Even more ugly. The latter has been the case before, but now it affects the whole build. Do you see a some ways to address both issues? Otherwise, we should probably stick with the current situation (non-integrated test builds) until the build system of the tests has been reworked. Jan -- Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/f6ecb294-5ec1-1652-0ca9-7a36477bfac1%40siemens.com. For more options, visit https://groups.google.com/d/optout.
