[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 5/5] tests: use unit test fragment in PDX test


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: dmukhin@xxxxxxxx
  • Date: Thu, 12 Feb 2026 18:49:52 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 148.163.138.245) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=ford.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ford.com; dkim=pass (signature was verified) header.d=saarlouis.ford.com; dkim=pass (signature was verified) header.d=ford.com; arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QZz0RdBUzIq+6LfiYUuswSgwU3nj3aTiG/f1W9D2zWY=; b=IkJ6r8my6UU/wbC7R8xGx1XcACiXalRa1QqyuHVB3EtH23McVEt/RJoQdWyjduRaWX5Firb/mXoioc4glWMcDjHCJZdqIB05who7lSZkFQCgUDUce/AjCFjV7I3X00g3UwcRZUdTEXc4Dr5gzfBKfsQOIHbgGWi4lkx2AY6LalFDro8w6uMyh3ZDFmV/QjenCKSEMz74zF9L1BxQHhJIOMSsYlLpg9BiDOHsSnnpixWrqYHslAD7UONETFAJoqN1KXoG/WfK6BAQSsqpRcVi25JER0a5A60/rYKpvzutZ3w/QQdCT1TAtxLB6W7XwOUw6O0ZIz5Lt+KXKTrGU7mAMw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SpNlHX0tSmBCNBBAZjoVGLv0ocJ7D8OV+dApWfL2268/KbLKkrZi2G11AE4xyWummU2SABeY/59rFJJ6g+QCZz92rLKspYSqIddXogHxOq0k6E8QY8F2kj0lYH+1ZN/qCUE0OEQ8zXvFTSPmmepzWXIQINbBV8juiWzwkeCSjrZ0AtERsfW0FMoRHaWy5nQ95sUdVePyKVJkCcxaz4hwKRfV4Vkbjg+veHdTGcWmvkueVW5wTTGOTRJoP+k5lDL4PZPpxuf48vQXDraV22AQxa7T8WNWC7hMaSM+GrRPYHuPDQkb8E18xSrEcxD/fwhTnyiP88XEcjiaMbwStj4KRQ==
  • Cc: andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, julien@xxxxxxx, michal.orzel@xxxxxxx, roger.pau@xxxxxxxxxx, sstabellini@xxxxxxxxxx, dmukhin@xxxxxxxx
  • Delivery-date: Fri, 13 Feb 2026 02:50:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Pser-m365-app: SER-APP

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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.