lkl: link tests against common private library

This effectively reverts commit 3c97822a40 ("lkl: add tests build
barrier"), replacing the tests .WAIT barrier with a common-object
prerequisite to keep parallel builds working.

Prerequisites are preferable to explicit .WAIT barriers, as they better
allow for build concurrency and also avoid install target breakage
described in the previous commit.

One minor drawback is that some of the test binaries don't use any
cla.o symbols, but get linked nevertheless. E.g. Before:
   text    data     bss     dec     hex filename
7878818 4851995  885880 13616693	 cfc635 tools/lkl/tests/boot

After:
   text	   data	    bss	    dec	    hex	filename
7880494	4852094	 885856	13618444	 cfcd0c	tools/lkl/tests/boot

I don't see it as a problem, but if it is then we could split up the
prerequisites.

Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
David Disseldorp
2025-09-03 16:37:29 +10:00
parent 6784e53c14
commit 6d360d164e
3 changed files with 17 additions and 21 deletions

View File

@@ -52,15 +52,9 @@ export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra \
include Targets include Targets
# Expand targets to output location and suffix but preserve special TARGETS := $(progs-y:%=$(OUTPUT)%$(EXESUF))
# targets (e.g. .WAIT) TARGETS := $(tests-y:%=$(OUTPUT)%$(EXESUF))
# $1 - targets TARGETS += $(libs-y:%=$(OUTPUT)%$(SOSUF))
# $2 - suffix
expand-targets = $(foreach t,$(1),$(if $(filter .%,$(t)),$(t),$(OUTPUT)$(t)$(2)))
TARGETS := $(call expand-targets,$(progs-y),$(EXESUF))
TARGETS += $(call expand-targets,$(tests-y),$(EXESUF))
TARGETS += $(call expand-targets,$(libs-y),$(SOSUF))
all: $(TARGETS) all: $(TARGETS)
# this workaround is for FreeBSD # this workaround is for FreeBSD
@@ -103,6 +97,9 @@ $(OUTPUT)liblkl.a: $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o
$(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a $(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y) $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)
# tests use a common private lib
$(tests-y:%=$(OUTPUT)%$(EXESUF)): $(tests-priv-y:%=$(OUTPUT)%-in.o)
# rule to build objects # rule to build objects
$(OUTPUT)%-in.o: $(OUTPUT)lib/lkl.o FORCE $(OUTPUT)%-in.o: $(OUTPUT)lib/lkl.o FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*)
@@ -182,7 +179,7 @@ libraries_install: $(libs-y:%=$(OUTPUT)%$(SOSUF)) $(OUTPUT)liblkl.a
install -d $(DESTDIR)$(LIBDIR) ; \ install -d $(DESTDIR)$(LIBDIR) ; \
install -m 644 $^ $(DESTDIR)$(LIBDIR) install -m 644 $^ $(DESTDIR)$(LIBDIR)
programs_install: $(call expand-targets,$(progs-y),$(EXESUF)) programs_install: $(progs-y:%=$(OUTPUT)%$(EXESUF))
$(call QUIET_INSTALL, programs) \ $(call QUIET_INSTALL, programs) \
install -d $(DESTDIR)$(BINDIR) ; \ install -d $(DESTDIR)$(BINDIR) ; \
install -m 755 $^ $(DESTDIR)$(BINDIR) install -m 755 $^ $(DESTDIR)$(BINDIR)
@@ -198,4 +195,3 @@ FORCE: ;
.PHONY: headers_install libraries_install programs_install install .PHONY: headers_install libraries_install programs_install install
.NOTPARALLEL : lib/lkl.o .NOTPARALLEL : lib/lkl.o
.SECONDARY: .SECONDARY:
.WAIT:

View File

@@ -27,11 +27,10 @@ LDLIBS_cptofs-y := -larchive
LDLIBS_cptofs-$(LKL_HOST_CONFIG_NEEDS_LARGP) += -largp LDLIBS_cptofs-$(LKL_HOST_CONFIG_NEEDS_LARGP) += -largp
# tools/build/Makefile.build does not support parallel builds when # tools/build/Makefile.build does not support parallel builds when
# objects are shared between build objects so keep the test that uses # objects are shared between build objects so use tests-common-in.o
# the most common object first and insert a build barrier to avoid # as a tests build prerequisite which gets linked into each binary.
# rebuilding common objects tests-priv-y := tests/tests-common
tests-y := tests/disk tests-y := tests/disk
tests-y += .WAIT
tests-y += tests/boot tests-y += tests/boot
tests-y += tests/disk-vfio-pci tests-y += tests/disk-vfio-pci
tests-y += tests/net-test tests-y += tests/net-test

View File

@@ -1,6 +1,7 @@
boot-y += boot.o test.o tests-common-y += cla.o test.o
disk-y += disk.o cla.o test.o boot-y += boot.o
disk-vfio-pci-y += disk-vfio-pci.o cla.o test.o disk-y += disk.o
net-test-y += net-test.o cla.o test.o disk-vfio-pci-y += disk-vfio-pci.o
config-y += config.o test.o net-test-y += net-test.o
test-dlmopen-y += test-dlmopen.o test.o config-y += config.o
test-dlmopen-y += test-dlmopen.o