|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v3 5/5] tests: use unit test fragment in PDX test
From: Denis Mukhin <dmukhin@xxxxxxxx>
Use the new make fragment to generate test harness code for the PDX unit
test.
Add ability to pass custom CFLAGS for mock code and object file suffix.
Move <xen/bitops.h> earlier in xen/common/pdx.c to ensure harness.h is
included before triggering the #ifndef MAX_PFN_RANGES check when building a
unit test.
Additionally, use real <xen/pdx.h> in harness.h instead of a locally copied
version.
Update .gitignore to exclude generated test build-time dependencies.
Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
Changes since v2:
- added lost -DCONFIG_PDX_OFFSET_COMPRESSION test
---
tools/tests/Rules.mk | 19 ++++++++----
tools/tests/pdx/.gitignore | 2 +-
tools/tests/pdx/Makefile | 59 +++++++++++---------------------------
tools/tests/pdx/harness.h | 2 +-
tools/tests/pdx/test-pdx.c | 2 --
xen/common/pdx.c | 3 +-
xen/include/xen/pdx.h | 2 ++
7 files changed, 36 insertions(+), 53 deletions(-)
diff --git a/tools/tests/Rules.mk b/tools/tests/Rules.mk
index e8a9e82320cf..dc16926f0591 100644
--- a/tools/tests/Rules.mk
+++ b/tools/tests/Rules.mk
@@ -16,11 +16,13 @@ prepare-harness:
# Generate mock environment by replicating header file hierarchy;
# each mock header file will point to a harness header.
#
+# NB: double-colon rule for mocking environment for multiple tests.
+#
# $1 Hypervisor header.
# $2 Test harness header.
define emit-harness-nested-rule
-$(1): prepare-harness $(2)
- set -e; \
+$(1):: prepare-harness $(2)
+ @set -e; \
mkdir -p $$(@D); \
[ -e $$@ ] || ln -s $(2) $$@
@@ -30,16 +32,19 @@ endef
#
# $1 Hypervisor filename.
# $2 Harness filename.
+# $3 Extra CFLAGS.
+# $4 Object file suffix.
define emit-harness-deps
$(eval c-file := $(abspath $(1)))
$(eval c-name := $(notdir $(c-file)))
$(eval c-headers := $(call list-c-headers,$(c-file)))
$(eval c-deps := $(addprefix $(CURDIR)/generated/,$(c-headers)))
+$(eval c-obj := $(if $(strip $(4)),-$(strip $(4)),))
$(foreach x,$(c-headers),$(call emit-harness-nested-rule,\
$(addprefix $(CURDIR)/generated/,$(x)),\
$(2)))
-$(c-name:%.c=%.o): $(c-file) $(c-deps)
- $(CC) $(CFLAGS) -o $$@ -c $$(firstword $$^)
+$(c-name:%.c=%$(c-obj).o): $(c-file) $(c-deps)
+ $(CC) $(3) $(CFLAGS) -o $$@ -c $$(firstword $$^)
endef
@@ -48,10 +53,14 @@ endef
# $1 Hypervisor filename.
# $2 Hypervisor source path.
# $3 Harness header filename (optional).
+# $4 Extra CFLAGS (optional).
+# $5 Object file suffix (optional).
define vpath-with-harness-deps
vpath $(1) $(2)
$(call emit-harness-deps,$(addprefix $(2),$(1)),\
- $(strip $(or $(3),$(CURDIR)/harness.h)))
+ $(strip $(or $(3),$(CURDIR)/harness.h)),\
+ $(4),\
+ $(5))
endef
.PHONY: all
diff --git a/tools/tests/pdx/.gitignore b/tools/tests/pdx/.gitignore
index 1202a531a7fd..1bf9c05985c4 100644
--- a/tools/tests/pdx/.gitignore
+++ b/tools/tests/pdx/.gitignore
@@ -1,3 +1,3 @@
-/pdx.h
+/generated
/test-pdx-mask
/test-pdx-offset
diff --git a/tools/tests/pdx/Makefile b/tools/tests/pdx/Makefile
index 3c431d7c7822..fa0bea8e1035 100644
--- a/tools/tests/pdx/Makefile
+++ b/tools/tests/pdx/Makefile
@@ -1,50 +1,23 @@
-XEN_ROOT=$(CURDIR)/../../..
-include $(XEN_ROOT)/tools/Rules.mk
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Unit tests for PDX (Page inDeX).
+#
-TARGETS := test-pdx-mask test-pdx-offset
+TESTS := test-pdx-mask test-pdx-offset
-.PHONY: all
-all: $(TARGETS)
+XEN_ROOT = $(CURDIR)/../../..
-.PHONY: run
-run: $(TARGETS)
-ifeq ($(CC),$(HOSTCC))
- set -e; \
- for test in $? ; do \
- ./$$test ; \
- done
-else
- $(warning HOSTCC != CC, will not run test)
-endif
+include $(XEN_ROOT)/tools/tests/Rules.mk
-.PHONY: clean
-clean:
- $(RM) -- *.o $(TARGETS) $(DEPS_RM) pdx.h
+CFLAGS += -I $(XEN_ROOT)/xen/include/
-.PHONY: distclean
-distclean: clean
- $(RM) -- *~
+$(eval $(call
vpath-with-harness-deps,pdx.c,$(XEN_ROOT)/xen/common/,,-DCONFIG_PDX_MASK_COMPRESSION,mask))
+test-pdx-mask.o: test-pdx.c
+ $(CC) -DCONFIG_PDX_MASK_COMPRESSION $(CFLAGS) -o $@ -c $^
-.PHONY: install
-install: all
- $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
- $(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests
+$(eval $(call
vpath-with-harness-deps,pdx.c,$(XEN_ROOT)/xen/common/,,-DCONFIG_PDX_OFFSET_COMPRESSION,offset))
+test-pdx-offset.o: test-pdx.c
+ $(CC) -DCONFIG_PDX_OFFSET_COMPRESSION $(CFLAGS) -o $@ -c $^
-.PHONY: uninstall
-uninstall:
- $(RM) -- $(patsubst %,$(DESTDIR)$(LIBEXEC)/tests/%,$(TARGETS))
-
-pdx.h: $(XEN_ROOT)/xen/include/xen/pdx.h
- sed -e '/^#[[:space:]]*include/d' <$< >$@
-
-CFLAGS += -D__XEN_TOOLS__
-CFLAGS += $(APPEND_CFLAGS)
-CFLAGS += $(CFLAGS_xeninclude)
-
-test-pdx-mask: CFLAGS += -DCONFIG_PDX_MASK_COMPRESSION
-test-pdx-offset: CFLAGS += -DCONFIG_PDX_OFFSET_COMPRESSION
-
-test-pdx-%: test-pdx.c pdx.h
- $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) -o $@ $< $(APPEND_CFLAGS)
-
--include $(DEPS_INCLUDE)
+test-pdx-%: test-pdx-%.o pdx-%.o
+ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
diff --git a/tools/tests/pdx/harness.h b/tools/tests/pdx/harness.h
index e49d6bcf92c2..4cdda931feb2 100644
--- a/tools/tests/pdx/harness.h
+++ b/tools/tests/pdx/harness.h
@@ -84,7 +84,7 @@ typedef uint64_t paddr_t;
qsort(elem, nr, size, cmp); \
})
-#include "pdx.h"
+#include <xen/pdx.h>
#endif
diff --git a/tools/tests/pdx/test-pdx.c b/tools/tests/pdx/test-pdx.c
index eefd54c76815..3633c231abaa 100644
--- a/tools/tests/pdx/test-pdx.c
+++ b/tools/tests/pdx/test-pdx.c
@@ -7,8 +7,6 @@
#include "harness.h"
-#include "../../xen/common/pdx.c"
-
struct range {
/* Ranges are defined as [start, end). */
unsigned long start, end;
diff --git a/xen/common/pdx.c b/xen/common/pdx.c
index 7e070ff962e8..068a2098b41b 100644
--- a/xen/common/pdx.c
+++ b/xen/common/pdx.c
@@ -15,11 +15,12 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
+#include <xen/bitops.h>
+
/* Trim content when built for the test harness. */
#ifdef __XEN__
#include <xen/init.h>
#include <xen/mm.h>
-#include <xen/bitops.h>
#include <xen/nospec.h>
#include <xen/param.h>
#include <xen/pfn.h>
diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h
index 856fc3e8a0e6..8b4a8701a25f 100644
--- a/xen/include/xen/pdx.h
+++ b/xen/include/xen/pdx.h
@@ -199,7 +199,9 @@ static inline paddr_t directmapoff_to_maddr_xlate(unsigned
long offset)
#elif defined(CONFIG_PDX_OFFSET_COMPRESSION) /* CONFIG_PDX_MASK_COMPRESSION */
+#ifdef __XEN__
#include <xen/page-size.h>
+#endif
#define CONFIG_PDX_NR_LOOKUP (1UL << CONFIG_PDX_OFFSET_TBL_ORDER)
#define PDX_TBL_MASK (CONFIG_PDX_NR_LOOKUP - 1)
--
2.52.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |