All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Factor out common build rules and helpers in tools/tests
@ 2026-02-23 10:14 Edwin Török
  2026-02-23 10:14 ` [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk Edwin Török
                   ` (7 more replies)
  0 siblings, 8 replies; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel
  Cc: Edwin Török, Anthony PERARD, Jan Beulich, Andrew Cooper,
	Roger Pau Monné, Stewart Hildebrand

There are a lot of duplicate rules and code in tools/tests.
To simplify writing new tests move common build rules into a
`tools/tests/Rules.mk`, and helper macros/functions into `common/{tests,guests}.{c,h}`.

This also ensures that CFLAGS are applied consistently across all tests (e.g. one test failed
to build now due to an unused variable error).

Guest creation also needs to test for the presence of PV, HVM HAP or HVM shadow support
in Xen and create a guest accordingly. This can be shared.

After these changes the per-test Makefile only contains entries specific
to the test (its name, dependencies, etc.) and avoids having to
copy&paste boilerplate code.

`tools/tests/x86_emulator` remains unchanged, because the Makefile
contains a lot of conditional build logic specific to that test.

An upcoming patch series will introduce new tests using the simplified
Makefile and shared helpers.

For convenience this is also available at:
https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...private%2Fedvint%2Fmigration-tests2?from_project_id=2336572
https://gitlab.com/xen-project/people/edwintorok/xen/-/pipelines/2342318716

Edwin Török (7):
  tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  tools/tests/vpci/main.c: drop unused variables
  tools/tests/*/Makefile: factor out build rules
  tools/tests: factor out common helpers
  tools/tests/common: ensure error messages have a newline
  tools/tests/tsx: move guest creation to common area
  tools/tests: print more debug info

 tools/tests/Rules.mk                          | 60 +++++++++++++
 tools/tests/common/guests.c                   | 89 +++++++++++++++++++
 tools/tests/common/guests.h                   | 11 +++
 tools/tests/common/tests.c                    | 15 ++++
 tools/tests/common/tests.h                    | 18 ++++
 tools/tests/cpu-policy/Makefile               | 41 ++-------
 tools/tests/cpu-policy/test-cpu-policy.c      |  7 +-
 tools/tests/domid/Makefile                    | 37 ++------
 tools/tests/domid/test-domid.c                | 11 +--
 tools/tests/mem-claim/Makefile                | 31 +------
 tools/tests/mem-claim/test-mem-claim.c        |  9 +-
 tools/tests/paging-mempool/Makefile           | 31 +------
 .../paging-mempool/test-paging-mempool.c      |  9 +-
 tools/tests/pdx/Makefile                      | 37 +-------
 tools/tests/pdx/test-pdx.c                    |  3 +-
 tools/tests/rangeset/Makefile                 | 36 +-------
 tools/tests/rangeset/test-rangeset.c          |  3 +-
 tools/tests/resource/Makefile                 | 35 +-------
 tools/tests/resource/test-resource.c          |  9 +-
 tools/tests/tsx/Makefile                      | 35 +-------
 tools/tests/tsx/test-tsx.c                    | 88 +++---------------
 tools/tests/vpci/.gitignore                   |  1 +
 tools/tests/vpci/Makefile                     | 36 ++------
 tools/tests/vpci/main.c                       |  6 +-
 tools/tests/xenstore/Makefile                 | 37 +-------
 tools/tests/xenstore/test-xenstore.c          |  4 +-
 26 files changed, 261 insertions(+), 438 deletions(-)
 create mode 100644 tools/tests/Rules.mk
 create mode 100644 tools/tests/common/guests.c
 create mode 100644 tools/tests/common/guests.h
 create mode 100644 tools/tests/common/tests.c
 create mode 100644 tools/tests/common/tests.h
 create mode 100644 tools/tests/vpci/.gitignore

-- 
2.47.3



^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-23 16:37   ` Jan Beulich
  2026-02-23 10:14 ` [PATCH 2/7] tools/tests/vpci/main.c: drop unused variables Edwin Török
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel
  Cc: Edwin Török, Anthony PERARD, Jan Beulich, Andrew Cooper,
	Roger Pau Monné, Stewart Hildebrand

Introduce a new tools/tests/Rules.mk that must be included *last* in a
Makefile, after TARGETS is defined.
This reduces the boilerplate that must be copy pasted when new tests are
written.

Renamed TESTS to TARGETS in tools/tests/domid/Makefile
Extend DEPS_RM, so that most tests don't need custom clean rules,
except in tools/tests/domid which needs to remove a directory too.

Make the run rules consistent: do not attempt to run the tests if HOSTCC != CC.

The common rules use the rule forms which allow multiple TARGETS.

tools/tests/x86_emulator/Makefile is unchanged, since this has a lot of
conditional rules that are very different from the other tests.

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/Rules.mk                | 48 +++++++++++++++++++++++++++++
 tools/tests/cpu-policy/Makefile     | 26 +---------------
 tools/tests/domid/Makefile          | 28 ++---------------
 tools/tests/mem-claim/Makefile      | 23 ++------------
 tools/tests/paging-mempool/Makefile | 23 ++------------
 tools/tests/pdx/Makefile            | 33 ++------------------
 tools/tests/rangeset/Makefile       | 27 ++--------------
 tools/tests/resource/Makefile       | 27 ++--------------
 tools/tests/tsx/Makefile            | 26 ++--------------
 tools/tests/vpci/Makefile           | 30 +++---------------
 tools/tests/xenstore/Makefile       | 29 ++---------------
 11 files changed, 72 insertions(+), 248 deletions(-)
 create mode 100644 tools/tests/Rules.mk

diff --git a/tools/tests/Rules.mk b/tools/tests/Rules.mk
new file mode 100644
index 0000000000..f7ef76bf4f
--- /dev/null
+++ b/tools/tests/Rules.mk
@@ -0,0 +1,48 @@
+# Usage: include this last in your Makefile.
+#
+# For example:
+#
+# XEN_ROOT = $(CURDIR)/../../..
+# include $(XEN_ROOT)/tools/Rules.mk
+#
+# TARGETS := ...
+# ...
+# include $(XEN_ROOT)/tools/tests/Rules.mk
+
+ifndef XEN_ROOT
+$(error XEN_ROOT is not defined)
+endif
+
+.PHONY: all
+all: $(TARGETS)
+.DEFAULT_GOAL: all
+
+.PHONY: run
+run: $(TARGETS)
+ifeq ($(CC),$(HOSTCC))
+	set -e;             \
+	for test in $? ; do \
+		./$$test ;  \
+	done
+else
+	$(warning HOSTCC != CC, will not run test)
+endif
+
+.PHONY: clean
+clean::
+	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
+
+.PHONY: distclean
+distclean: clean
+	$(RM) -- *~
+
+.PHONY: install
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
+	$(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests)
+
+.PHONY: uninstall
+uninstall:
+	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
+
+-include $(DEPS_INCLUDE)
diff --git a/tools/tests/cpu-policy/Makefile b/tools/tests/cpu-policy/Makefile
index 24f87e2eca..700e325215 100644
--- a/tools/tests/cpu-policy/Makefile
+++ b/tools/tests/cpu-policy/Makefile
@@ -12,30 +12,6 @@ else
 $(warning Test harness not built, use newer compiler than "$(CC)" (version $(shell $(CC) -dumpversion)))
 endif
 
-.PHONY: all
-all: $(TARGETS)
-
-.PHONY: run
-run: $(TARGETS)
-	./$<
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests)
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
-
 CFLAGS += -D__XEN_TOOLS__
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(APPEND_CFLAGS)
@@ -49,4 +25,4 @@ vpath %.c ../../../xen/lib/x86
 test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o
 	$(CC) $^ -o $@ $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/domid/Makefile b/tools/tests/domid/Makefile
index 753129029e..92f11777f2 100644
--- a/tools/tests/domid/Makefile
+++ b/tools/tests/domid/Makefile
@@ -7,7 +7,7 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TESTS := test-domid
+TARGETS += test-domid
 
 define list-c-headers
 $(shell sed -n \
@@ -36,30 +36,8 @@ vpath $(1) $(2)
 $(call emit-harness-deps,$(1),$(call list-c-headers,$(2)$(1)))
 endef
 
-.PHONY: all
-all: $(TESTS)
-
-.PHONY: run
-run: $(TESTS)
-	set -e; $(foreach t,$(TESTS),./$(t);)
-
-.PHONY: clean
-clean:
+clean::
 	$(RM) -r generated
-	$(RM) -- *.o $(TESTS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) test-domid $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/test-domid
 
 CFLAGS += -D__XEN_TOOLS__
 # find-next-bit.c
@@ -85,4 +63,4 @@ $(eval $(call vpath-with-harness-deps,domid.c,$(XEN_ROOT)/xen/common/))
 test-domid: domid.o find-next-bit.o test-domid.o
 	$(CC) $^ -o $@ $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/mem-claim/Makefile b/tools/tests/mem-claim/Makefile
index 76ba3e3c8b..6790e48417 100644
--- a/tools/tests/mem-claim/Makefile
+++ b/tools/tests/mem-claim/Makefile
@@ -2,26 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-mem-claim
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -35,4 +16,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-mem-claim.o
 	$(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/paging-mempool/Makefile b/tools/tests/paging-mempool/Makefile
index a1e12584ce..9ebeb24ab6 100644
--- a/tools/tests/paging-mempool/Makefile
+++ b/tools/tests/paging-mempool/Makefile
@@ -2,26 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-paging-mempool
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -35,4 +16,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-paging-mempool.o
 	$(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/pdx/Makefile b/tools/tests/pdx/Makefile
index 3c431d7c78..a5129a8282 100644
--- a/tools/tests/pdx/Makefile
+++ b/tools/tests/pdx/Makefile
@@ -3,36 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 TARGETS := test-pdx-mask test-pdx-offset
 
-.PHONY: all
-all: $(TARGETS)
-
-.PHONY: run
-run: $(TARGETS)
-ifeq ($(CC),$(HOSTCC))
-	set -e;             \
-	for test in $? ; do \
-		./$$test ;  \
-	done
-else
-	$(warning HOSTCC != CC, will not run test)
-endif
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGETS) $(DEPS_RM) pdx.h
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(patsubst %,$(DESTDIR)$(LIBEXEC)/tests/%,$(TARGETS))
+DEPS_RM += pdx.h
 
 pdx.h: $(XEN_ROOT)/xen/include/xen/pdx.h
 	sed -e '/^#[[:space:]]*include/d' <$< >$@
@@ -47,4 +18,4 @@ 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)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/rangeset/Makefile b/tools/tests/rangeset/Makefile
index e3bfce471c..c76746ce7a 100644
--- a/tools/tests/rangeset/Makefile
+++ b/tools/tests/rangeset/Makefile
@@ -2,30 +2,9 @@ XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-rangeset
+TARGETS := $(TARGET)
 
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: run
-run: $(TARGET)
-	./$<
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGET) $(DEPS_RM) list.h rangeset.h rangeset.c
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGET))
+DEPS_RM += list.h rangeset.h rangeset.c
 
 list.h: $(XEN_ROOT)/xen/include/xen/list.h
 rangeset.h: $(XEN_ROOT)/xen/include/xen/rangeset.h
@@ -47,4 +26,4 @@ test-rangeset.o rangeset.o: list.h rangeset.h
 test-rangeset: rangeset.o test-rangeset.o
 	$(CC) $^ -o $@ $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/resource/Makefile b/tools/tests/resource/Makefile
index 09d678fffe..764e34f3fa 100644
--- a/tools/tests/resource/Makefile
+++ b/tools/tests/resource/Makefile
@@ -2,30 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-resource
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: run
-run: $(TARGET)
-	./$(TARGET)
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -43,4 +20,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-resource.o
 	$(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/tsx/Makefile b/tools/tests/tsx/Makefile
index 0bb7e70103..817a63b085 100644
--- a/tools/tests/tsx/Makefile
+++ b/tools/tests/tsx/Makefile
@@ -2,29 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test-tsx
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGET) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
-
-.PHONY: uninstall
-uninstall:
+TARGETS := $(TARGET)
 
 CFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl -I$(XEN_ROOT)/tools/libs/guest
 CFLAGS += $(CFLAGS_xeninclude)
@@ -41,4 +19,4 @@ LDFLAGS += $(APPEND_LDFLAGS)
 $(TARGET): test-tsx.o
 	$(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/vpci/Makefile b/tools/tests/vpci/Makefile
index 97359ff67f..597303e31d 100644
--- a/tools/tests/vpci/Makefile
+++ b/tools/tests/vpci/Makefile
@@ -2,36 +2,12 @@ XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 TARGET := test_vpci
-
-.PHONY: all
-all: $(TARGET)
-
-.PHONY: run
-run: $(TARGET)
-ifeq ($(CC),$(HOSTCC))
-	./$(TARGET)
-else
-	$(warning HOSTCC != CC, will not run test)
-endif
+TARGETS := $(TARGET)
 
 $(TARGET): vpci.c vpci.h list.h main.c emul.h
 	$(CC) $(CFLAGS_xeninclude) -g -o $@ vpci.c main.c
 
-.PHONY: clean
-clean:
-	rm -rf $(TARGET) *.o *~ vpci.h vpci.c list.h
-
-.PHONY: distclean
-distclean: clean
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+DEPS_RM += vpci.h vpci.c list.h
 
 vpci.c: $(XEN_ROOT)/xen/drivers/vpci/vpci.c
 	# Remove includes and add the test harness header
@@ -41,3 +17,5 @@ list.h: $(XEN_ROOT)/xen/include/xen/list.h
 vpci.h: $(XEN_ROOT)/xen/include/xen/vpci.h
 list.h vpci.h:
 	sed -e '/#include/d' <$< >$@
+
+include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/xenstore/Makefile b/tools/tests/xenstore/Makefile
index 2ee4a1327e..56cfe07f25 100644
--- a/tools/tests/xenstore/Makefile
+++ b/tools/tests/xenstore/Makefile
@@ -1,31 +1,8 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TARGETS-y := test-xenstore
-TARGETS := $(TARGETS-y)
-
-.PHONY: all
-all: build
-
-.PHONY: build
-build: $(TARGETS)
-
-.PHONY: clean
-clean:
-	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-	$(RM) -- *~
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests)
-
-.PHONY: uninstall
-uninstall:
-	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
+TARGET := test-xenstore
+TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_libxenstore)
 CFLAGS += $(APPEND_CFLAGS)
@@ -41,4 +18,4 @@ endif
 test-xenstore: test-xenstore.o
 	$(CC) -o $@ $< $(LDFLAGS)
 
--include $(DEPS_INCLUDE)
+include $(XEN_ROOT)/tools/tests/Rules.mk
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 2/7] tools/tests/vpci/main.c: drop unused variables
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
  2026-02-23 10:14 ` [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-24 14:44   ` Roger Pau Monné
  2026-02-23 10:14 ` [PATCH 3/7] tools/tests/*/Makefile: factor out build rules Edwin Török
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel
  Cc: Edwin Török, Roger Pau Monné, Stewart Hildebrand,
	Anthony PERARD

They may become build failures.

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/vpci/main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/tests/vpci/main.c b/tools/tests/vpci/main.c
index 2ef8d4e03f..3753417e86 100644
--- a/tools/tests/vpci/main.c
+++ b/tools/tests/vpci/main.c
@@ -189,8 +189,6 @@ main(int argc, char **argv)
     uint32_t r24 = 0;
     uint8_t r28, r30;
     struct mask_data r32;
-    unsigned int i;
-    int rc;
 
     INIT_LIST_HEAD(&vpci.handlers);
     spin_lock_init(&vpci.lock);
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 3/7] tools/tests/*/Makefile: factor out build rules
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
  2026-02-23 10:14 ` [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk Edwin Török
  2026-02-23 10:14 ` [PATCH 2/7] tools/tests/vpci/main.c: drop unused variables Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-24 11:15   ` Jan Beulich
  2026-02-23 10:14 ` [PATCH 4/7] tools/tests: factor out common helpers Edwin Török
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel
  Cc: Edwin Török, Anthony PERARD, Jan Beulich, Andrew Cooper,
	Roger Pau Monné, Stewart Hildebrand

Also makes CFLAGS consistent across all tests, e.g. test_vpci would now
fail to build with an unused variable error if it hadn't been fixed in a
previous commit.

Introduce a symlink test_vpci.c -> main.c, since this is the only test
using a different .c file name from the main executable
(could also rename the file instead).

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/Rules.mk                |  9 +++++++++
 tools/tests/cpu-policy/Makefile     | 15 ++++-----------
 tools/tests/domid/Makefile          | 11 +++--------
 tools/tests/mem-claim/Makefile      |  8 --------
 tools/tests/paging-mempool/Makefile |  8 --------
 tools/tests/pdx/Makefile            |  4 ----
 tools/tests/rangeset/Makefile       |  9 +--------
 tools/tests/resource/Makefile       |  8 --------
 tools/tests/tsx/Makefile            |  8 --------
 tools/tests/vpci/.gitignore         |  1 +
 tools/tests/vpci/Makefile           | 10 +++++++---
 tools/tests/xenstore/Makefile       |  8 +-------
 12 files changed, 26 insertions(+), 73 deletions(-)
 create mode 100644 tools/tests/vpci/.gitignore

diff --git a/tools/tests/Rules.mk b/tools/tests/Rules.mk
index f7ef76bf4f..2de9e94546 100644
--- a/tools/tests/Rules.mk
+++ b/tools/tests/Rules.mk
@@ -45,4 +45,13 @@ install: all
 uninstall:
 	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
 
+CFLAGS += -D__XEN_TOOLS__
+CFLAGS += $(CFLAGS_xeninclude)
+
+%.o: Makefile
+
+$(TARGET): $(TARGET).o
+	$(CC) $^ -o $@ $(LDFLAGS) $(APPEND_LDFLAGS)
+
 -include $(DEPS_INCLUDE)
+
diff --git a/tools/tests/cpu-policy/Makefile b/tools/tests/cpu-policy/Makefile
index 700e325215..4ab3baf1fb 100644
--- a/tools/tests/cpu-policy/Makefile
+++ b/tools/tests/cpu-policy/Makefile
@@ -3,26 +3,19 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 TARGETS :=
 
+TARGET := test-cpu-policy
+
 # For brevity, these tests make extensive use of designated initialisers in
 # anonymous unions, but GCCs older than 4.6 can't cope.  Ignore the test in
 # this case.
 ifneq ($(gcc)$(call cc-ver,$(CC),lt,0x040600),yy)
-TARGETS += test-cpu-policy
+TARGETS += $(TARGET)
 else
 $(warning Test harness not built, use newer compiler than "$(CC)" (version $(shell $(CC) -dumpversion)))
 endif
 
-CFLAGS += -D__XEN_TOOLS__
-CFLAGS += $(CFLAGS_xeninclude)
-CFLAGS += $(APPEND_CFLAGS)
-
-LDFLAGS += $(APPEND_LDFLAGS)
-
 vpath %.c ../../../xen/lib/x86
 
-%.o: Makefile
-
-test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o
-	$(CC) $^ -o $@ $(LDFLAGS)
+$(TARGET): msr.o cpuid.o policy.o
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/domid/Makefile b/tools/tests/domid/Makefile
index 92f11777f2..89e4333bfb 100644
--- a/tools/tests/domid/Makefile
+++ b/tools/tests/domid/Makefile
@@ -7,7 +7,8 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TARGETS += test-domid
+TARGET := test-domid
+TARGETS += $(TARGET)
 
 define list-c-headers
 $(shell sed -n \
@@ -39,7 +40,6 @@ endef
 clean::
 	$(RM) -r generated
 
-CFLAGS += -D__XEN_TOOLS__
 # find-next-bit.c
 CFLAGS += '-DEXPORT_SYMBOL(x)=' \
           -Dfind_first_bit \
@@ -47,12 +47,8 @@ CFLAGS += '-DEXPORT_SYMBOL(x)=' \
           -Dfind_next_bit \
           -Dfind_next_bit_le \
           -Dfind_next_zero_bit_le
-CFLAGS += $(APPEND_CFLAGS)
-CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += -I./generated/
 
-LDFLAGS += $(APPEND_LDFLAGS)
-
 vpath find-next-bit.c $(XEN_ROOT)/xen/lib/
 
 # Point to the hypervisor code and generate test harness dependencies
@@ -60,7 +56,6 @@ vpath find-next-bit.c $(XEN_ROOT)/xen/lib/
 # within a mocked environment.
 $(eval $(call vpath-with-harness-deps,domid.c,$(XEN_ROOT)/xen/common/))
 
-test-domid: domid.o find-next-bit.o test-domid.o
-	$(CC) $^ -o $@ $(LDFLAGS)
+$(TARGET): domid.o find-next-bit.o
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/mem-claim/Makefile b/tools/tests/mem-claim/Makefile
index 6790e48417..eeae1eb5d2 100644
--- a/tools/tests/mem-claim/Makefile
+++ b/tools/tests/mem-claim/Makefile
@@ -4,16 +4,8 @@ include $(XEN_ROOT)/tools/Rules.mk
 TARGET := test-mem-claim
 TARGETS := $(TARGET)
 
-CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
-CFLAGS += $(APPEND_CFLAGS)
 
 LDFLAGS += $(LDLIBS_libxenctrl)
-LDFLAGS += $(APPEND_LDFLAGS)
-
-%.o: Makefile
-
-$(TARGET): test-mem-claim.o
-	$(CC) -o $@ $< $(LDFLAGS)
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/paging-mempool/Makefile b/tools/tests/paging-mempool/Makefile
index 9ebeb24ab6..ad4b7fc65f 100644
--- a/tools/tests/paging-mempool/Makefile
+++ b/tools/tests/paging-mempool/Makefile
@@ -4,16 +4,8 @@ include $(XEN_ROOT)/tools/Rules.mk
 TARGET := test-paging-mempool
 TARGETS := $(TARGET)
 
-CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
-CFLAGS += $(APPEND_CFLAGS)
 
 LDFLAGS += $(LDLIBS_libxenctrl)
-LDFLAGS += $(APPEND_LDFLAGS)
-
-%.o: Makefile
-
-$(TARGET): test-paging-mempool.o
-	$(CC) -o $@ $< $(LDFLAGS)
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/pdx/Makefile b/tools/tests/pdx/Makefile
index a5129a8282..bc19a217a5 100644
--- a/tools/tests/pdx/Makefile
+++ b/tools/tests/pdx/Makefile
@@ -8,10 +8,6 @@ DEPS_RM += pdx.h
 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
 
diff --git a/tools/tests/rangeset/Makefile b/tools/tests/rangeset/Makefile
index c76746ce7a..843b2129a9 100644
--- a/tools/tests/rangeset/Makefile
+++ b/tools/tests/rangeset/Makefile
@@ -15,15 +15,8 @@ rangeset.c: $(XEN_ROOT)/xen/common/rangeset.c
 	# Remove includes and add the test harness header
 	sed -e '/#include/d' -e '1s/^/#include "harness.h"/' <$< >$@
 
-CFLAGS += -D__XEN_TOOLS__
-CFLAGS += $(APPEND_CFLAGS)
-CFLAGS += $(CFLAGS_xeninclude)
-
-LDFLAGS += $(APPEND_LDFLAGS)
-
 test-rangeset.o rangeset.o: list.h rangeset.h
 
-test-rangeset: rangeset.o test-rangeset.o
-	$(CC) $^ -o $@ $(LDFLAGS)
+$(TARGET): rangeset.o
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/resource/Makefile b/tools/tests/resource/Makefile
index 764e34f3fa..11ce782b29 100644
--- a/tools/tests/resource/Makefile
+++ b/tools/tests/resource/Makefile
@@ -4,20 +4,12 @@ include $(XEN_ROOT)/tools/Rules.mk
 TARGET := test-resource
 TARGETS := $(TARGET)
 
-CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
 CFLAGS += $(CFLAGS_libxenforeginmemory)
 CFLAGS += $(CFLAGS_libxengnttab)
-CFLAGS += $(APPEND_CFLAGS)
 
 LDFLAGS += $(LDLIBS_libxenctrl)
 LDFLAGS += $(LDLIBS_libxenforeignmemory)
 LDFLAGS += $(LDLIBS_libxengnttab)
-LDFLAGS += $(APPEND_LDFLAGS)
-
-%.o: Makefile
-
-$(TARGET): test-resource.o
-	$(CC) -o $@ $< $(LDFLAGS)
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/tsx/Makefile b/tools/tests/tsx/Makefile
index 817a63b085..54852b0327 100644
--- a/tools/tests/tsx/Makefile
+++ b/tools/tests/tsx/Makefile
@@ -5,18 +5,10 @@ TARGET := test-tsx
 TARGETS := $(TARGET)
 
 CFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl -I$(XEN_ROOT)/tools/libs/guest
-CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
 CFLAGS += $(CFLAGS_libxenguest)
-CFLAGS += $(APPEND_CFLAGS)
 
 LDFLAGS += $(LDLIBS_libxenctrl)
 LDFLAGS += $(LDLIBS_libxenguest)
-LDFLAGS += $(APPEND_LDFLAGS)
-
-%.o: Makefile
-
-$(TARGET): test-tsx.o
-	$(CC) -o $@ $< $(LDFLAGS)
 
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/vpci/.gitignore b/tools/tests/vpci/.gitignore
new file mode 100644
index 0000000000..8be877b29a
--- /dev/null
+++ b/tools/tests/vpci/.gitignore
@@ -0,0 +1 @@
+test_vpci.c
diff --git a/tools/tests/vpci/Makefile b/tools/tests/vpci/Makefile
index 597303e31d..41ff867cdd 100644
--- a/tools/tests/vpci/Makefile
+++ b/tools/tests/vpci/Makefile
@@ -4,10 +4,14 @@ include $(XEN_ROOT)/tools/Rules.mk
 TARGET := test_vpci
 TARGETS := $(TARGET)
 
-$(TARGET): vpci.c vpci.h list.h main.c emul.h
-	$(CC) $(CFLAGS_xeninclude) -g -o $@ vpci.c main.c
+$(TARGET).c: main.c
+	ln -sf $< $@
 
-DEPS_RM += vpci.h vpci.c list.h
+vpci.o: vpci.h
+$(TARGET).o: vpci.h emul.h list.h
+$(TARGET): vpci.o
+
+DEPS_RM += vpci.h vpci.c list.h $(TARGET).c
 
 vpci.c: $(XEN_ROOT)/xen/drivers/vpci/vpci.c
 	# Remove includes and add the test harness header
diff --git a/tools/tests/xenstore/Makefile b/tools/tests/xenstore/Makefile
index 56cfe07f25..e1a0c086a9 100644
--- a/tools/tests/xenstore/Makefile
+++ b/tools/tests/xenstore/Makefile
@@ -5,17 +5,11 @@ TARGET := test-xenstore
 TARGETS := $(TARGET)
 
 CFLAGS += $(CFLAGS_libxenstore)
-CFLAGS += $(APPEND_CFLAGS)
 
 LDFLAGS += $(LDLIBS_libxenstore)
-LDFLAGS += $(APPEND_LDFLAGS)
+
 ifeq ($(CONFIG_Linux),y)
 LDFLAGS += -Wl,--as-needed -lc -lrt
 endif
 
-%.o: Makefile
-
-test-xenstore: test-xenstore.o
-	$(CC) -o $@ $< $(LDFLAGS)
-
 include $(XEN_ROOT)/tools/tests/Rules.mk
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 4/7] tools/tests: factor out common helpers
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
                   ` (2 preceding siblings ...)
  2026-02-23 10:14 ` [PATCH 3/7] tools/tests/*/Makefile: factor out build rules Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-24 11:27   ` Jan Beulich
  2026-02-23 10:14 ` [PATCH 5/7] tools/tests/common: ensure error messages have a newline Edwin Török
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel
  Cc: Edwin Török, Anthony PERARD, Jan Beulich, Andrew Cooper,
	Roger Pau Monné, Stewart Hildebrand

Share fail/verify macros, and the handling or nr_failures.
The tests will no longer have a `main` function, but instead have a
`test_main`. This ensures that `nr_failures` is handled consistently.

This'll make it easier to write new tests that are consistent with the
existing ones, without having to copy/paste.

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/Rules.mk                           |  3 +++
 tools/tests/common/tests.c                     | 15 +++++++++++++++
 tools/tests/common/tests.h                     | 18 ++++++++++++++++++
 tools/tests/cpu-policy/test-cpu-policy.c       |  7 +------
 tools/tests/domid/test-domid.c                 | 11 ++---------
 tools/tests/mem-claim/test-mem-claim.c         |  9 ++-------
 .../tests/paging-mempool/test-paging-mempool.c |  9 ++-------
 tools/tests/pdx/test-pdx.c                     |  3 ++-
 tools/tests/rangeset/test-rangeset.c           |  3 ++-
 tools/tests/resource/test-resource.c           |  9 ++-------
 tools/tests/tsx/test-tsx.c                     | 10 ++--------
 tools/tests/vpci/main.c                        |  4 ++--
 tools/tests/xenstore/test-xenstore.c           |  4 +++-
 13 files changed, 56 insertions(+), 49 deletions(-)
 create mode 100644 tools/tests/common/tests.c
 create mode 100644 tools/tests/common/tests.h

diff --git a/tools/tests/Rules.mk b/tools/tests/Rules.mk
index 2de9e94546..9e03e1e0b8 100644
--- a/tools/tests/Rules.mk
+++ b/tools/tests/Rules.mk
@@ -47,11 +47,14 @@ uninstall:
 
 CFLAGS += -D__XEN_TOOLS__
 CFLAGS += $(CFLAGS_xeninclude)
+CFLAGS += -I../common/
 
 %.o: Makefile
 
 $(TARGET): $(TARGET).o
 	$(CC) $^ -o $@ $(LDFLAGS) $(APPEND_LDFLAGS)
 
+$(TARGETS): $(XEN_ROOT)/tools/tests/common/tests.o
+
 -include $(DEPS_INCLUDE)
 
diff --git a/tools/tests/common/tests.c b/tools/tests/common/tests.c
new file mode 100644
index 0000000000..43d9ea5442
--- /dev/null
+++ b/tools/tests/common/tests.c
@@ -0,0 +1,15 @@
+#include "tests.h"
+
+unsigned int nr_failures;
+
+int main(int argc, char *argv[argc+1])
+{
+    int rc = test_main(argc, argv);
+
+    if ( nr_failures )
+        printf("Done: %u failures\n", nr_failures);
+    else
+        printf("Done: all ok\n");
+
+    return rc ? rc : !!nr_failures;
+}
diff --git a/tools/tests/common/tests.h b/tools/tests/common/tests.h
new file mode 100644
index 0000000000..f0df616e3e
--- /dev/null
+++ b/tools/tests/common/tests.h
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <sysexits.h>
+
+extern unsigned int nr_failures;
+
+#define fail(fmt, ...)                          \
+({                                              \
+    nr_failures++;                              \
+    (void)printf(fmt, ##__VA_ARGS__);           \
+})
+
+#define verify(exp, fmt, args...) \
+while (!(exp)) { \
+    printf(fmt, ## args); \
+    exit(EX_SOFTWARE); \
+}
+
+extern int test_main(int argc, char *argv[argc+1]);
diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index 301df2c002..67a36c80d5 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -650,7 +650,7 @@ static void test_is_compatible_failure(void)
     }
 }
 
-int main(int argc, char **argv)
+int test_main(int argc, char **argv)
 {
     printf("CPU Policy unit tests\n");
 
@@ -667,10 +667,5 @@ int main(int argc, char **argv)
     test_is_compatible_success();
     test_is_compatible_failure();
 
-    if ( nr_failures )
-        printf("Done: %u failures\n", nr_failures);
-    else
-        printf("Done: all ok\n");
-
     return !!nr_failures;
 }
diff --git a/tools/tests/domid/test-domid.c b/tools/tests/domid/test-domid.c
index 5915c4699a..de39bae8b0 100644
--- a/tools/tests/domid/test-domid.c
+++ b/tools/tests/domid/test-domid.c
@@ -5,20 +5,13 @@
  * Copyright 2025 Ford Motor Company
  */
 
-#include <sysexits.h>
-
+#include "tests.h"
 #include "harness.h"
 
-#define verify(exp, fmt, args...) \
-while (!(exp)) { \
-    printf(fmt, ## args); \
-    exit(EX_SOFTWARE); \
-}
-
 /*
  * Fail on the first error, since tests are dependent on each other.
  */
-int main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     domid_t expected, allocated;
 
diff --git a/tools/tests/mem-claim/test-mem-claim.c b/tools/tests/mem-claim/test-mem-claim.c
index ad038e45d1..1f3c70aace 100644
--- a/tools/tests/mem-claim/test-mem-claim.c
+++ b/tools/tests/mem-claim/test-mem-claim.c
@@ -11,12 +11,7 @@
 #include <xengnttab.h>
 #include <xen-tools/common-macros.h>
 
-static unsigned int nr_failures;
-#define fail(fmt, ...)                          \
-({                                              \
-    nr_failures++;                              \
-    (void)printf(fmt, ##__VA_ARGS__);           \
-})
+#include "tests.h"
 
 #define MB_PAGES(x) (MB(x) / XC_PAGE_SIZE)
 
@@ -158,7 +153,7 @@ static void run_tests(void)
                     physinfo.outstanding_pages);
 }
 
-int main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     int rc;
 
diff --git a/tools/tests/paging-mempool/test-paging-mempool.c b/tools/tests/paging-mempool/test-paging-mempool.c
index 1ebc13455a..27fd109031 100644
--- a/tools/tests/paging-mempool/test-paging-mempool.c
+++ b/tools/tests/paging-mempool/test-paging-mempool.c
@@ -10,12 +10,7 @@
 #include <xengnttab.h>
 #include <xen-tools/common-macros.h>
 
-static unsigned int nr_failures;
-#define fail(fmt, ...)                          \
-({                                              \
-    nr_failures++;                              \
-    (void)printf(fmt, ##__VA_ARGS__);           \
-})
+#include "tests.h"
 
 static xc_interface *xch;
 static uint32_t domid;
@@ -136,7 +131,7 @@ static void run_tests(void)
                     64 << 20, size_bytes);
 }
 
-int main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     int rc;
 
diff --git a/tools/tests/pdx/test-pdx.c b/tools/tests/pdx/test-pdx.c
index eefd54c768..d2d143ec76 100644
--- a/tools/tests/pdx/test-pdx.c
+++ b/tools/tests/pdx/test-pdx.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2025 Cloud Software Group
  */
 
+#include "tests.h"
 #include "harness.h"
 
 #include "../../xen/common/pdx.c"
@@ -29,7 +30,7 @@ static void print_ranges(const struct range *r)
     }
 }
 
-int main(int argc, char **argv)
+int main(int argc, char *argv[argc+1])
 {
     static const struct {
         struct range ranges[MAX_RANGES];
diff --git a/tools/tests/rangeset/test-rangeset.c b/tools/tests/rangeset/test-rangeset.c
index c14a908b4f..3f8ac95097 100644
--- a/tools/tests/rangeset/test-rangeset.c
+++ b/tools/tests/rangeset/test-rangeset.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2025 Cloud Software Group
  */
 
+#include "tests.h"
 #include "harness.h"
 
 struct range {
@@ -140,7 +141,7 @@ static void print_both(struct rangeset *r, const struct range *expected,
         printf("[%ld, %ld]\n", expected[i].start, expected[i].end);
 }
 
-int main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     struct rangeset *r = rangeset_new(NULL, NULL, 0);
     unsigned int i;
diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/test-resource.c
index a7f2d04643..4155b62507 100644
--- a/tools/tests/resource/test-resource.c
+++ b/tools/tests/resource/test-resource.c
@@ -9,12 +9,7 @@
 #include <xengnttab.h>
 #include <xen-tools/common-macros.h>
 
-static unsigned int nr_failures;
-#define fail(fmt, ...)                          \
-({                                              \
-    nr_failures++;                              \
-    (void)printf(fmt, ##__VA_ARGS__);           \
-})
+#include "tests.h"
 
 static xc_interface *xch;
 static xenforeignmemory_handle *fh;
@@ -255,7 +250,7 @@ static void test_domain_configurations(void)
     }
 }
 
-int main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     int rc;
 
diff --git a/tools/tests/tsx/test-tsx.c b/tools/tests/tsx/test-tsx.c
index 5af04953f3..ab099e9038 100644
--- a/tools/tests/tsx/test-tsx.c
+++ b/tools/tests/tsx/test-tsx.c
@@ -30,6 +30,7 @@
 #include <xenguest.h>
 #include <xen-tools/common-macros.h>
 
+#include "tests.h"
 #include "xg_private.h"
 
 enum {
@@ -44,13 +45,6 @@ enum {
 #define MSR_TSX_CTRL                        0x00000122
 #define MSR_MCU_OPT_CTRL                    0x00000123
 
-static unsigned int nr_failures;
-#define fail(fmt, ...)                          \
-({                                              \
-    nr_failures++;                              \
-    (void)printf(fmt, ##__VA_ARGS__);           \
-})
-
 static xc_interface *xch;
 
 /*
@@ -540,7 +534,7 @@ static void test_tsx(void)
     test_guests();
 }
 
-int main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     printf("TSX tests\n");
 
diff --git a/tools/tests/vpci/main.c b/tools/tests/vpci/main.c
index 3753417e86..0e4f24aace 100644
--- a/tools/tests/vpci/main.c
+++ b/tools/tests/vpci/main.c
@@ -16,6 +16,7 @@
  * License along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "tests.h"
 #include "emul.h"
 
 /* Single vcpu (current), and single domain with a single PCI device. */
@@ -175,8 +176,7 @@ void multiwrite4_check(unsigned int reg)
     multiread4_check(reg, val);
 }
 
-int
-main(int argc, char **argv)
+int test_main(int argc, char *argv[argc+1])
 {
     /* Index storage by offset. */
     uint32_t r0 = 0xdeadbeef;
diff --git a/tools/tests/xenstore/test-xenstore.c b/tools/tests/xenstore/test-xenstore.c
index 7a9bd9afb3..470cbeed30 100644
--- a/tools/tests/xenstore/test-xenstore.c
+++ b/tools/tests/xenstore/test-xenstore.c
@@ -33,6 +33,8 @@
 
 #include <xen-tools/common-macros.h>
 
+#include "tests.h"
+
 #define TEST_PATH "xenstore-test"
 #define WRITE_BUFFERS_N    10
 #define WRITE_BUFFERS_SIZE 4000
@@ -445,7 +447,7 @@ static void cleanup(void)
     }
 }
 
-int main(int argc, char *argv[])
+int test_main(int argc, char *argv[argc+1])
 {
     int opt, t, iters = 1, ret = 0, randtime = 0;
     char *test = NULL;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 5/7] tools/tests/common: ensure error messages have a newline
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
                   ` (3 preceding siblings ...)
  2026-02-23 10:14 ` [PATCH 4/7] tools/tests: factor out common helpers Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-24 11:36   ` Jan Beulich
  2026-02-23 10:14 ` [PATCH 6/7] tools/tests/tsx: move guest creation to common area Edwin Török
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel; +Cc: Edwin Török, Anthony PERARD

Otherwise messages from the next test will end up on the same line as an
error message from a previous test.
(calling `fail` is not fatal).

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/common/tests.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/tests/common/tests.h b/tools/tests/common/tests.h
index f0df616e3e..add847a46a 100644
--- a/tools/tests/common/tests.h
+++ b/tools/tests/common/tests.h
@@ -6,12 +6,12 @@ extern unsigned int nr_failures;
 #define fail(fmt, ...)                          \
 ({                                              \
     nr_failures++;                              \
-    (void)printf(fmt, ##__VA_ARGS__);           \
+    (void)printf(fmt"\n", ##__VA_ARGS__);           \
 })
 
 #define verify(exp, fmt, args...) \
 while (!(exp)) { \
-    printf(fmt, ## args); \
+    printf(fmt"\n", ## args); \
     exit(EX_SOFTWARE); \
 }
 
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 6/7] tools/tests/tsx: move guest creation to common area
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
                   ` (4 preceding siblings ...)
  2026-02-23 10:14 ` [PATCH 5/7] tools/tests/common: ensure error messages have a newline Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-24 11:49   ` Jan Beulich
  2026-02-23 10:14 ` [PATCH 7/7] tools/tests: print more debug info Edwin Török
  2026-02-23 10:42 ` [PATCH 0/7] Factor out common build rules and helpers in tools/tests Jan Beulich
  7 siblings, 1 reply; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel; +Cc: Edwin Török, Anthony PERARD

So that other tests can reuse the creation of HVM/PV tests.

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/common/guests.c | 87 +++++++++++++++++++++++++++++++++++++
 tools/tests/common/guests.h | 11 +++++
 tools/tests/tsx/Makefile    |  2 +
 tools/tests/tsx/test-tsx.c  | 78 ++++-----------------------------
 4 files changed, 108 insertions(+), 70 deletions(-)
 create mode 100644 tools/tests/common/guests.c
 create mode 100644 tools/tests/common/guests.h

diff --git a/tools/tests/common/guests.c b/tools/tests/common/guests.c
new file mode 100644
index 0000000000..bb33bfd8c0
--- /dev/null
+++ b/tools/tests/common/guests.c
@@ -0,0 +1,87 @@
+#define _GNU_SOURCE
+#include "guests.h"
+#include "tests.h"
+
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+
+xc_interface *xch;
+xc_physinfo_t physinfo;
+bool xen_has_pv = true, xen_has_hvm = true;
+
+void test_guest_init(void)
+{
+    int rc;
+    xch = xc_interface_open(NULL, NULL, 0);
+
+    if ( !xch )
+        err(1, "xc_interface_open");
+
+    rc = xc_physinfo(xch, &physinfo);
+    if ( rc )
+        err(1, "Failed to obtain physinfo");
+
+    xen_has_hvm = physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm;
+    xen_has_pv = physinfo.capabilities & XEN_SYSCTL_PHYSCAP_pv;
+}
+
+void test_guest(struct xen_domctl_createdomain *c)
+{
+    uint32_t domid = 0;
+    int rc;
+
+    if (!xch)
+        return fail("test_guest_init() not called");
+
+    rc = xc_domain_create(xch, &domid, c);
+    if ( rc )
+        return fail("  Domain create failure: %d - %s\n",
+                    errno, strerror(errno));
+
+    printf("  Created d%u\n", domid);
+
+    test_guest_domid(domid);
+
+    rc = xc_domain_destroy(xch, domid);
+    if ( rc )
+        fail("  Failed to destroy domain: %d - %s\n",
+             errno, strerror(errno));
+}
+
+void test_guests(void)
+{
+    if ( xen_has_pv )
+    {
+        struct xen_domctl_createdomain c = {
+            .max_vcpus = 1,
+            .max_grant_frames = 1,
+            .grant_opts = XEN_DOMCTL_GRANT_version(1),
+        };
+
+        printf("Testing PV guest\n");
+        test_guest(&c);
+    }
+
+    if ( xen_has_hvm )
+    {
+        struct xen_domctl_createdomain c = {
+            .flags = XEN_DOMCTL_CDF_hvm,
+            .max_vcpus = 1,
+            .max_grant_frames = 1,
+            .grant_opts = XEN_DOMCTL_GRANT_version(1),
+            .arch = {
+                .emulation_flags = XEN_X86_EMU_LAPIC,
+            },
+        };
+
+        if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap )
+            c.flags |= XEN_DOMCTL_CDF_hap;
+        else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) )
+            return fail("  HVM available, but neither HAP nor Shadow\n");
+
+        printf("Testing HVM guest\n");
+        test_guest(&c);
+    }
+}
+
diff --git a/tools/tests/common/guests.h b/tools/tests/common/guests.h
new file mode 100644
index 0000000000..8cd6fc1b68
--- /dev/null
+++ b/tools/tests/common/guests.h
@@ -0,0 +1,11 @@
+#include <xenctrl.h>
+#include <xen/domctl.h>
+
+extern void test_guest_domid(domid_t domid);
+extern xc_interface *xch;
+extern xc_physinfo_t physinfo;
+extern bool xen_has_pv, xen_has_hvm;
+
+void test_guest_init(void);
+void test_guest(struct xen_domctl_createdomain *c);
+void test_guests(void);
diff --git a/tools/tests/tsx/Makefile b/tools/tests/tsx/Makefile
index 54852b0327..3ccb6dcb9f 100644
--- a/tools/tests/tsx/Makefile
+++ b/tools/tests/tsx/Makefile
@@ -11,4 +11,6 @@ CFLAGS += $(CFLAGS_libxenguest)
 LDFLAGS += $(LDLIBS_libxenctrl)
 LDFLAGS += $(LDLIBS_libxenguest)
 
+$(TARGET): ../common/guests.o
+
 include $(XEN_ROOT)/tools/tests/Rules.mk
diff --git a/tools/tests/tsx/test-tsx.c b/tools/tests/tsx/test-tsx.c
index ab099e9038..b80a812a74 100644
--- a/tools/tests/tsx/test-tsx.c
+++ b/tools/tests/tsx/test-tsx.c
@@ -31,6 +31,7 @@
 #include <xen-tools/common-macros.h>
 
 #include "tests.h"
+#include "guests.h"
 #include "xg_private.h"
 
 enum {
@@ -45,7 +46,6 @@ enum {
 #define MSR_TSX_CTRL                        0x00000122
 #define MSR_MCU_OPT_CTRL                    0x00000123
 
-static xc_interface *xch;
 
 /*
  * Policies, arranged as an array for easy collection of all of them.  We
@@ -60,10 +60,6 @@ static struct xc_cpu_policy policies[6];
 #define pv_default   policies[XEN_SYSCTL_cpu_policy_pv_default]
 #define hvm_default  policies[XEN_SYSCTL_cpu_policy_hvm_default]
 
-static bool xen_has_pv = true, xen_has_hvm = true;
-
-static xc_physinfo_t physinfo;
-
 static enum rtm_behaviour {
     RTM_UD,
     RTM_OK,
@@ -354,24 +350,16 @@ static void test_def_max_policies(void)
     }
 }
 
-static void test_guest(struct xen_domctl_createdomain *c)
+void test_guest_domid(domid_t domid)
 {
-    uint32_t domid = 0;
     int rc;
 
-    rc = xc_domain_create(xch, &domid, c);
-    if ( rc )
-        return fail("  Domain create failure: %d - %s\n",
-                    errno, strerror(errno));
-
-    printf("  Created d%u\n", domid);
-
     rc = xc_cpu_policy_get_domain(xch, domid, &guest_policy);
     if ( rc )
     {
         fail("  Failed to obtain domain policy: %d - %s\n",
              errno, strerror(errno));
-        goto out;
+        return;
     }
 
     dump_tsx_details(&guest_policy.policy, "Cur:");
@@ -408,7 +396,7 @@ static void test_guest(struct xen_domctl_createdomain *c)
         {
             fail("  Failed to set domain policy: %d - %s\n",
                  errno, strerror(errno));
-            goto out;
+            return;
         }
 
         /* Re-get the new policy. */
@@ -417,7 +405,7 @@ static void test_guest(struct xen_domctl_createdomain *c)
         {
             fail("  Failed to obtain domain policy: %d - %s\n",
                  errno, strerror(errno));
-            goto out;
+            return;
         }
 
         dump_tsx_details(&guest_policy.policy, "Cur:");
@@ -426,58 +414,17 @@ static void test_guest(struct xen_domctl_createdomain *c)
         {
             fail("  Expected CPUID.7[0].b 0x%08x differs from actual 0x%08x\n",
                  _7b0, guest_policy.policy.feat.raw[0].b);
-            goto out;
+            return;
         }
 
         if ( guest_policy.policy.feat.raw[0].d != _7d0 )
         {
             fail("  Expected CPUID.7[0].d 0x%08x differs from actual 0x%08x\n",
                  _7d0, guest_policy.policy.feat.raw[0].d);
-            goto out;
+            return;
         }
     }
 
- out:
-    rc = xc_domain_destroy(xch, domid);
-    if ( rc )
-        fail("  Failed to destroy domain: %d - %s\n",
-             errno, strerror(errno));
-}
-
-static void test_guests(void)
-{
-    if ( xen_has_pv )
-    {
-        struct xen_domctl_createdomain c = {
-            .max_vcpus = 1,
-            .max_grant_frames = 1,
-            .grant_opts = XEN_DOMCTL_GRANT_version(1),
-        };
-
-        printf("Testing PV guest\n");
-        test_guest(&c);
-    }
-
-    if ( xen_has_hvm )
-    {
-        struct xen_domctl_createdomain c = {
-            .flags = XEN_DOMCTL_CDF_hvm,
-            .max_vcpus = 1,
-            .max_grant_frames = 1,
-            .grant_opts = XEN_DOMCTL_GRANT_version(1),
-            .arch = {
-                .emulation_flags = XEN_X86_EMU_LAPIC,
-            },
-        };
-
-        if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap )
-            c.flags |= XEN_DOMCTL_CDF_hap;
-        else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) )
-            return fail("  HVM available, but neither HAP nor Shadow\n");
-
-        printf("Testing HVM guest\n");
-        test_guest(&c);
-    }
 }
 
 /* Obtain some general data, then run the tests. */
@@ -521,11 +468,6 @@ static void test_tsx(void)
 
     dump_tsx_details(&host.policy, "Host:");
 
-    rc = xc_physinfo(xch, &physinfo);
-    if ( rc )
-        return fail("Failed to obtain physinfo: %d - %s\n",
-                    errno, strerror(errno));
-
     printf("  Got %u CPUs\n", physinfo.max_cpu_id + 1);
 
     test_tsx_msrs();
@@ -538,11 +480,7 @@ int test_main(int argc, char *argv[argc+1])
 {
     printf("TSX tests\n");
 
-    xch = xc_interface_open(NULL, NULL, 0);
-
-    if ( !xch )
-        err(1, "xc_interface_open");
-
+    test_guest_init();
     test_tsx();
 
     return !!nr_failures;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 7/7] tools/tests: print more debug info
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
                   ` (5 preceding siblings ...)
  2026-02-23 10:14 ` [PATCH 6/7] tools/tests/tsx: move guest creation to common area Edwin Török
@ 2026-02-23 10:14 ` Edwin Török
  2026-02-23 10:42 ` [PATCH 0/7] Factor out common build rules and helpers in tools/tests Jan Beulich
  7 siblings, 0 replies; 21+ messages in thread
From: Edwin Török @ 2026-02-23 10:14 UTC (permalink / raw)
  To: xen-devel; +Cc: Edwin Török, Anthony PERARD

Enable xentoollog at XTL_DEBUG level.

Signed-off-by: Edwin Török <edwin.torok@citrix.com>
---
 tools/tests/common/guests.c | 4 +++-
 tools/tests/tsx/Makefile    | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/tests/common/guests.c b/tools/tests/common/guests.c
index bb33bfd8c0..a46ff2f68d 100644
--- a/tools/tests/common/guests.c
+++ b/tools/tests/common/guests.c
@@ -9,11 +9,13 @@
 xc_interface *xch;
 xc_physinfo_t physinfo;
 bool xen_has_pv = true, xen_has_hvm = true;
+xentoollog_logger *logger;
 
 void test_guest_init(void)
 {
     int rc;
-    xch = xc_interface_open(NULL, NULL, 0);
+    logger = (xentoollog_logger*)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0);
+    xch = xc_interface_open(logger, NULL, 0);
 
     if ( !xch )
         err(1, "xc_interface_open");
diff --git a/tools/tests/tsx/Makefile b/tools/tests/tsx/Makefile
index 3ccb6dcb9f..cbcae6d090 100644
--- a/tools/tests/tsx/Makefile
+++ b/tools/tests/tsx/Makefile
@@ -10,6 +10,7 @@ CFLAGS += $(CFLAGS_libxenguest)
 
 LDFLAGS += $(LDLIBS_libxenctrl)
 LDFLAGS += $(LDLIBS_libxenguest)
+LDFLAGS += $(LDLIBS_libxentoollog)
 
 $(TARGET): ../common/guests.o
 
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] Factor out common build rules and helpers in tools/tests
  2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
                   ` (6 preceding siblings ...)
  2026-02-23 10:14 ` [PATCH 7/7] tools/tests: print more debug info Edwin Török
@ 2026-02-23 10:42 ` Jan Beulich
  2026-02-27 18:00   ` Edwin Torok
  7 siblings, 1 reply; 21+ messages in thread
From: Jan Beulich @ 2026-02-23 10:42 UTC (permalink / raw)
  To: Edwin Török
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monné,
	Stewart Hildebrand, xen-devel, Denis Mukhin

On 23.02.2026 11:14, Edwin Török wrote:
> There are a lot of duplicate rules and code in tools/tests.
> To simplify writing new tests move common build rules into a
> `tools/tests/Rules.mk`, and helper macros/functions into `common/{tests,guests}.{c,h}`.
> 
> This also ensures that CFLAGS are applied consistently across all tests (e.g. one test failed
> to build now due to an unused variable error).
> 
> Guest creation also needs to test for the presence of PV, HVM HAP or HVM shadow support
> in Xen and create a guest accordingly. This can be shared.
> 
> After these changes the per-test Makefile only contains entries specific
> to the test (its name, dependencies, etc.) and avoids having to
> copy&paste boilerplate code.
> 
> `tools/tests/x86_emulator` remains unchanged, because the Makefile
> contains a lot of conditional build logic specific to that test.
> 
> An upcoming patch series will introduce new tests using the simplified
> Makefile and shared helpers.
> 
> For convenience this is also available at:
> https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...private%2Fedvint%2Fmigration-tests2?from_project_id=2336572
> https://gitlab.com/xen-project/people/edwintorok/xen/-/pipelines/2342318716
> 
> Edwin Török (7):
>   tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
>   tools/tests/vpci/main.c: drop unused variables
>   tools/tests/*/Makefile: factor out build rules
>   tools/tests: factor out common helpers
>   tools/tests/common: ensure error messages have a newline
>   tools/tests/tsx: move guest creation to common area
>   tools/tests: print more debug info

Just fyi that there is also
https://lists.xen.org/archives/html/xen-devel/2026-02/msg00751.html.
Can the two of you maybe work together to have a single resulting approach?

Jan

>  tools/tests/Rules.mk                          | 60 +++++++++++++
>  tools/tests/common/guests.c                   | 89 +++++++++++++++++++
>  tools/tests/common/guests.h                   | 11 +++
>  tools/tests/common/tests.c                    | 15 ++++
>  tools/tests/common/tests.h                    | 18 ++++
>  tools/tests/cpu-policy/Makefile               | 41 ++-------
>  tools/tests/cpu-policy/test-cpu-policy.c      |  7 +-
>  tools/tests/domid/Makefile                    | 37 ++------
>  tools/tests/domid/test-domid.c                | 11 +--
>  tools/tests/mem-claim/Makefile                | 31 +------
>  tools/tests/mem-claim/test-mem-claim.c        |  9 +-
>  tools/tests/paging-mempool/Makefile           | 31 +------
>  .../paging-mempool/test-paging-mempool.c      |  9 +-
>  tools/tests/pdx/Makefile                      | 37 +-------
>  tools/tests/pdx/test-pdx.c                    |  3 +-
>  tools/tests/rangeset/Makefile                 | 36 +-------
>  tools/tests/rangeset/test-rangeset.c          |  3 +-
>  tools/tests/resource/Makefile                 | 35 +-------
>  tools/tests/resource/test-resource.c          |  9 +-
>  tools/tests/tsx/Makefile                      | 35 +-------
>  tools/tests/tsx/test-tsx.c                    | 88 +++---------------
>  tools/tests/vpci/.gitignore                   |  1 +
>  tools/tests/vpci/Makefile                     | 36 ++------
>  tools/tests/vpci/main.c                       |  6 +-
>  tools/tests/xenstore/Makefile                 | 37 +-------
>  tools/tests/xenstore/test-xenstore.c          |  4 +-
>  26 files changed, 261 insertions(+), 438 deletions(-)
>  create mode 100644 tools/tests/Rules.mk
>  create mode 100644 tools/tests/common/guests.c
>  create mode 100644 tools/tests/common/guests.h
>  create mode 100644 tools/tests/common/tests.c
>  create mode 100644 tools/tests/common/tests.h
>  create mode 100644 tools/tests/vpci/.gitignore
> 



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  2026-02-23 10:14 ` [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk Edwin Török
@ 2026-02-23 16:37   ` Jan Beulich
  2026-02-24  9:38     ` Edwin Torok
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Beulich @ 2026-02-23 16:37 UTC (permalink / raw)
  To: Edwin Török
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monné,
	Stewart Hildebrand, xen-devel

On 23.02.2026 11:14, Edwin Török wrote:
> Introduce a new tools/tests/Rules.mk that must be included *last* in a
> Makefile, after TARGETS is defined.

Requiring inclusion after TARGETS is defined is certainly okay. Requiring it to
be included absolutely last is imo going too far. There surely are going to be
cases where something wants overriding or adding to.

> --- /dev/null
> +++ b/tools/tests/Rules.mk
> @@ -0,0 +1,48 @@
> +# Usage: include this last in your Makefile.
> +#
> +# For example:
> +#
> +# XEN_ROOT = $(CURDIR)/../../..
> +# include $(XEN_ROOT)/tools/Rules.mk
> +#
> +# TARGETS := ...
> +# ...
> +# include $(XEN_ROOT)/tools/tests/Rules.mk
> +
> +ifndef XEN_ROOT
> +$(error XEN_ROOT is not defined)
> +endif
> +
> +.PHONY: all
> +all: $(TARGETS)
> +.DEFAULT_GOAL: all

Make 3.80, which ./README still says we support, doesn't look to know this.

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  2026-02-23 16:37   ` Jan Beulich
@ 2026-02-24  9:38     ` Edwin Torok
  2026-02-24  9:42       ` Jan Beulich
  0 siblings, 1 reply; 21+ messages in thread
From: Edwin Torok @ 2026-02-24  9:38 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monne,
	Stewart Hildebrand, xen-devel@lists.xenproject.org

[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]



On 23 Feb 2026, at 16:37, Jan Beulich <jbeulich@suse.com> wrote:

On 23.02.2026 11:14, Edwin Török wrote:
Introduce a new tools/tests/Rules.mk that must be included *last* in a
Makefile, after TARGETS is defined.

Requiring inclusion after TARGETS is defined is certainly okay. Requiring it to
be included absolutely last is imo going too far. There surely are going to be
cases where something wants overriding or adding to.


I’ll change this so that the Makefile defines XEN_ROOT, CFLAGS, LDFLAGS, TARGETS, and then includes the file.


--- /dev/null
+++ b/tools/tests/Rules.mk
@@ -0,0 +1,48 @@
+# Usage: include this last in your Makefile.
+#
+# For example:
+#
+# XEN_ROOT = $(CURDIR)/../../..
+# include $(XEN_ROOT)/tools/Rules.mk
+#
+# TARGETS := ...
+# ...
+# include $(XEN_ROOT)/tools/tests/Rules.mk
+
+ifndef XEN_ROOT
+$(error XEN_ROOT is not defined)
+endif
+
+.PHONY: all
+all: $(TARGETS)
+.DEFAULT_GOAL: all

Make 3.80, which ./README still says we support, doesn't look to know this.

Do you know which (Linux) distribution and version would have Make 3.80 so I can test my changes there?
I tried looking at https://repology.org/project/make/versions, but the only OS that has make 3.80 is AIX, and I don’t have access to that.

Thanks,
—Edwin

[-- Attachment #2: Type: text/html, Size: 2178 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  2026-02-24  9:38     ` Edwin Torok
@ 2026-02-24  9:42       ` Jan Beulich
  2026-02-24 10:01         ` Edwin Torok
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Beulich @ 2026-02-24  9:42 UTC (permalink / raw)
  To: Edwin Torok
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monne,
	Stewart Hildebrand, xen-devel@lists.xenproject.org

First, since this looks to be recurring: Please don't send HTML mails.

On 24.02.2026 10:38, Edwin Torok wrote:
> On 23 Feb 2026, at 16:37, Jan Beulich <jbeulich@suse.com> wrote:
> On 23.02.2026 11:14, Edwin Török wrote:
> Introduce a new tools/tests/Rules.mk that must be included *last* in a
> Makefile, after TARGETS is defined.
> 
> Requiring inclusion after TARGETS is defined is certainly okay. Requiring it to
> be included absolutely last is imo going too far. There surely are going to be
> cases where something wants overriding or adding to.
> 
> 
> I’ll change this so that the Makefile defines XEN_ROOT, CFLAGS, LDFLAGS, TARGETS, and then includes the file.
> 
> 
> --- /dev/null
> +++ b/tools/tests/Rules.mk
> @@ -0,0 +1,48 @@
> +# Usage: include this last in your Makefile.
> +#
> +# For example:
> +#
> +# XEN_ROOT = $(CURDIR)/../../..
> +# include $(XEN_ROOT)/tools/Rules.mk
> +#
> +# TARGETS := ...
> +# ...
> +# include $(XEN_ROOT)/tools/tests/Rules.mk
> +
> +ifndef XEN_ROOT
> +$(error XEN_ROOT is not defined)
> +endif
> +
> +.PHONY: all
> +all: $(TARGETS)
> +.DEFAULT_GOAL: all
> 
> Make 3.80, which ./README still says we support, doesn't look to know this.
> 
> Do you know which (Linux) distribution and version would have Make 3.80 so I can test my changes there?

Not without a lot of digging. Perhaps we simply want to bump the minimum version,
to "sync up" with what we did for binutils, gcc, and clang?

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  2026-02-24  9:42       ` Jan Beulich
@ 2026-02-24 10:01         ` Edwin Torok
  2026-02-24 10:30           ` Jan Beulich
  0 siblings, 1 reply; 21+ messages in thread
From: Edwin Torok @ 2026-02-24 10:01 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monne,
	Stewart Hildebrand, xen-devel@lists.xenproject.org



> On 24 Feb 2026, at 09:42, Jan Beulich <jbeulich@suse.com> wrote:
> 
> First, since this looks to be recurring: Please don't send HTML mails.

Thanks, didn’t notice my mail client was doing that, changed the settings now.

> 
> On 24.02.2026 10:38, Edwin Torok wrote:
>> On 23 Feb 2026, at 16:37, Jan Beulich <jbeulich@suse.com> wrote:
>> On 23.02.2026 11:14, Edwin Török wrote:
>> Introduce a new tools/tests/Rules.mk that must be included *last* in a
>> Makefile, after TARGETS is defined.
>> 
>> Requiring inclusion after TARGETS is defined is certainly okay. Requiring it to
>> be included absolutely last is imo going too far. There surely are going to be
>> cases where something wants overriding or adding to.
>> 
>> 
>> I’ll change this so that the Makefile defines XEN_ROOT, CFLAGS, LDFLAGS, TARGETS, and then includes the file.
>> 
>> 
>> --- /dev/null
>> +++ b/tools/tests/Rules.mk
>> @@ -0,0 +1,48 @@
>> +# Usage: include this last in your Makefile.
>> +#
>> +# For example:
>> +#
>> +# XEN_ROOT = $(CURDIR)/../../..
>> +# include $(XEN_ROOT)/tools/Rules.mk
>> +#
>> +# TARGETS := ...
>> +# ...
>> +# include $(XEN_ROOT)/tools/tests/Rules.mk
>> +
>> +ifndef XEN_ROOT
>> +$(error XEN_ROOT is not defined)
>> +endif
>> +
>> +.PHONY: all
>> +all: $(TARGETS)
>> +.DEFAULT_GOAL: all
>> 
>> Make 3.80, which ./README still says we support, doesn't look to know this.
>> 
>> Do you know which (Linux) distribution and version would have Make 3.80 so I can test my changes there?
> 
> Not without a lot of digging. Perhaps we simply want to bump the minimum version,
> to "sync up" with what we did for binutils, gcc, and clang?

Minimum binutils is 2.25, which excludes CentOS6. CentOS7 has 2.27 and make 3.82.
The only other OS that I see that’d have make 3.81 and binutils >= 2.25 would be Ubuntu 14.04, which is EoL.

So we could update to Make 3.82?

If we exclude CentOS7 (which is EoL), then the next minimum make that I see would be 4.2.1. Would that be too big of a jump?

Best regards,
—Edwin

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
  2026-02-24 10:01         ` Edwin Torok
@ 2026-02-24 10:30           ` Jan Beulich
  0 siblings, 0 replies; 21+ messages in thread
From: Jan Beulich @ 2026-02-24 10:30 UTC (permalink / raw)
  To: Edwin Torok
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monne,
	Stewart Hildebrand, xen-devel@lists.xenproject.org

On 24.02.2026 11:01, Edwin Torok wrote:
> 
> 
>> On 24 Feb 2026, at 09:42, Jan Beulich <jbeulich@suse.com> wrote:
>>
>> First, since this looks to be recurring: Please don't send HTML mails.
> 
> Thanks, didn’t notice my mail client was doing that, changed the settings now.
> 
>>
>> On 24.02.2026 10:38, Edwin Torok wrote:
>>> On 23 Feb 2026, at 16:37, Jan Beulich <jbeulich@suse.com> wrote:
>>> On 23.02.2026 11:14, Edwin Török wrote:
>>> Introduce a new tools/tests/Rules.mk that must be included *last* in a
>>> Makefile, after TARGETS is defined.
>>>
>>> Requiring inclusion after TARGETS is defined is certainly okay. Requiring it to
>>> be included absolutely last is imo going too far. There surely are going to be
>>> cases where something wants overriding or adding to.
>>>
>>>
>>> I’ll change this so that the Makefile defines XEN_ROOT, CFLAGS, LDFLAGS, TARGETS, and then includes the file.
>>>
>>>
>>> --- /dev/null
>>> +++ b/tools/tests/Rules.mk
>>> @@ -0,0 +1,48 @@
>>> +# Usage: include this last in your Makefile.
>>> +#
>>> +# For example:
>>> +#
>>> +# XEN_ROOT = $(CURDIR)/../../..
>>> +# include $(XEN_ROOT)/tools/Rules.mk
>>> +#
>>> +# TARGETS := ...
>>> +# ...
>>> +# include $(XEN_ROOT)/tools/tests/Rules.mk
>>> +
>>> +ifndef XEN_ROOT
>>> +$(error XEN_ROOT is not defined)
>>> +endif
>>> +
>>> +.PHONY: all
>>> +all: $(TARGETS)
>>> +.DEFAULT_GOAL: all
>>>
>>> Make 3.80, which ./README still says we support, doesn't look to know this.
>>>
>>> Do you know which (Linux) distribution and version would have Make 3.80 so I can test my changes there?
>>
>> Not without a lot of digging. Perhaps we simply want to bump the minimum version,
>> to "sync up" with what we did for binutils, gcc, and clang?
> 
> Minimum binutils is 2.25, which excludes CentOS6. CentOS7 has 2.27 and make 3.82.
> The only other OS that I see that’d have make 3.81 and binutils >= 2.25 would be Ubuntu 14.04, which is EoL.
> 
> So we could update to Make 3.82?
> 
> If we exclude CentOS7 (which is EoL), then the next minimum make that I see would be 4.2.1. Would that be too big of a jump?

I would take gcc and binutils (both dating back to 2015) as reference, which would
make it either 4.0 or 4.1 which we may want to pick. (Which doesn't exclude 3.82
as an option, of course.)

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/7] tools/tests/*/Makefile: factor out build rules
  2026-02-23 10:14 ` [PATCH 3/7] tools/tests/*/Makefile: factor out build rules Edwin Török
@ 2026-02-24 11:15   ` Jan Beulich
  0 siblings, 0 replies; 21+ messages in thread
From: Jan Beulich @ 2026-02-24 11:15 UTC (permalink / raw)
  To: Edwin Török
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monné,
	Stewart Hildebrand, xen-devel

On 23.02.2026 11:14, Edwin Török wrote:
> Also makes CFLAGS consistent across all tests, e.g. test_vpci would now
> fail to build with an unused variable error if it hadn't been fixed in a
> previous commit.

I can't quite derive why that would happen.

> --- a/tools/tests/Rules.mk
> +++ b/tools/tests/Rules.mk
> @@ -45,4 +45,13 @@ install: all
>  uninstall:
>  	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC)/tests/,$(TARGETS))
>  
> +CFLAGS += -D__XEN_TOOLS__
> +CFLAGS += $(CFLAGS_xeninclude)
> +
> +%.o: Makefile
> +
> +$(TARGET): $(TARGET).o
> +	$(CC) $^ -o $@ $(LDFLAGS) $(APPEND_LDFLAGS)

In the earlier patch you require TARGETS to be surfaced. Why would we limit
things to a single target here then? Imo we want to settle on every subdir
having a single target, or the abstraction allowing for multiple.

>  -include $(DEPS_INCLUDE)
> +

Nit: Stray change?

> --- a/tools/tests/cpu-policy/Makefile
> +++ b/tools/tests/cpu-policy/Makefile
> @@ -3,26 +3,19 @@ include $(XEN_ROOT)/tools/Rules.mk
>  
>  TARGETS :=
>  
> +TARGET := test-cpu-policy
> +
>  # For brevity, these tests make extensive use of designated initialisers in
>  # anonymous unions, but GCCs older than 4.6 can't cope.  Ignore the test in
>  # this case.
>  ifneq ($(gcc)$(call cc-ver,$(CC),lt,0x040600),yy)
> -TARGETS += test-cpu-policy
> +TARGETS += $(TARGET)
>  else
>  $(warning Test harness not built, use newer compiler than "$(CC)" (version $(shell $(CC) -dumpversion)))
>  endif
>  
> -CFLAGS += -D__XEN_TOOLS__
> -CFLAGS += $(CFLAGS_xeninclude)
> -CFLAGS += $(APPEND_CFLAGS)
> -
> -LDFLAGS += $(APPEND_LDFLAGS)

You use $(APPEND_LDFLAGS) in the new rule (without adding to LDFLAGS), but where
did $(APPEND_CFLAGS) go?

> --- /dev/null
> +++ b/tools/tests/vpci/.gitignore
> @@ -0,0 +1 @@
> +test_vpci.c
> diff --git a/tools/tests/vpci/Makefile b/tools/tests/vpci/Makefile
> index 597303e31d..41ff867cdd 100644
> --- a/tools/tests/vpci/Makefile
> +++ b/tools/tests/vpci/Makefile
> @@ -4,10 +4,14 @@ include $(XEN_ROOT)/tools/Rules.mk
>  TARGET := test_vpci
>  TARGETS := $(TARGET)
>  
> -$(TARGET): vpci.c vpci.h list.h main.c emul.h
> -	$(CC) $(CFLAGS_xeninclude) -g -o $@ vpci.c main.c
> +$(TARGET).c: main.c
> +	ln -sf $< $@

Can we perhaps try to avoid further symlinking, unless absolutely necessary?
Here it looks to be easy to rename main.c into test_vpci.c (yet better would
be test-vcpi.c).

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 4/7] tools/tests: factor out common helpers
  2026-02-23 10:14 ` [PATCH 4/7] tools/tests: factor out common helpers Edwin Török
@ 2026-02-24 11:27   ` Jan Beulich
  0 siblings, 0 replies; 21+ messages in thread
From: Jan Beulich @ 2026-02-24 11:27 UTC (permalink / raw)
  To: Edwin Török
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monné,
	Stewart Hildebrand, xen-devel

On 23.02.2026 11:14, Edwin Török wrote:
> --- a/tools/tests/Rules.mk
> +++ b/tools/tests/Rules.mk
> @@ -47,11 +47,14 @@ uninstall:
>  
>  CFLAGS += -D__XEN_TOOLS__
>  CFLAGS += $(CFLAGS_xeninclude)
> +CFLAGS += -I../common/
>  
>  %.o: Makefile
>  
>  $(TARGET): $(TARGET).o
>  	$(CC) $^ -o $@ $(LDFLAGS) $(APPEND_LDFLAGS)
>  
> +$(TARGETS): $(XEN_ROOT)/tools/tests/common/tests.o
> +
>  -include $(DEPS_INCLUDE)
>  
> diff --git a/tools/tests/common/tests.c b/tools/tests/common/tests.c
> new file mode 100644
> index 0000000000..43d9ea5442
> --- /dev/null
> +++ b/tools/tests/common/tests.c
> @@ -0,0 +1,15 @@
> +#include "tests.h"
> +
> +unsigned int nr_failures;
> +
> +int main(int argc, char *argv[argc+1])

Nit (style): Blanks around + please.

> +{
> +    int rc = test_main(argc, argv);
> +
> +    if ( nr_failures )
> +        printf("Done: %u failures\n", nr_failures);
> +    else
> +        printf("Done: all ok\n");
> +
> +    return rc ? rc : !!nr_failures;

Nit: No need for the middle operand; we use that extension extensively.

> --- /dev/null
> +++ b/tools/tests/common/tests.h
> @@ -0,0 +1,18 @@
> +#include <stdio.h>
> +#include <sysexits.h>
> +
> +extern unsigned int nr_failures;
> +
> +#define fail(fmt, ...)                          \
> +({                                              \
> +    nr_failures++;                              \
> +    (void)printf(fmt, ##__VA_ARGS__);           \
> +})
> +
> +#define verify(exp, fmt, args...) \
> +while (!(exp)) { \
> +    printf(fmt, ## args); \
> +    exit(EX_SOFTWARE); \
> +}

For both macros, please be consistent in how you want to deal with the variable
number of arguments.

For the latter macro, like the former it wants to be coded such that a semicolon
and the use site is necessary (and doesn't end up as a stray one).

> --- a/tools/tests/cpu-policy/test-cpu-policy.c
> +++ b/tools/tests/cpu-policy/test-cpu-policy.c
> @@ -650,7 +650,7 @@ static void test_is_compatible_failure(void)
>      }
>  }
>  
> -int main(int argc, char **argv)
> +int test_main(int argc, char **argv)

Elsewhere you switch to argv[argc + 1] - why not here?

> --- a/tools/tests/pdx/test-pdx.c
> +++ b/tools/tests/pdx/test-pdx.c
> @@ -5,6 +5,7 @@
>   * Copyright (C) 2025 Cloud Software Group
>   */
>  
> +#include "tests.h"
>  #include "harness.h"
>  
>  #include "../../xen/common/pdx.c"
> @@ -29,7 +30,7 @@ static void print_ranges(const struct range *r)
>      }
>  }
>  
> -int main(int argc, char **argv)
> +int main(int argc, char *argv[argc+1])
>  {
>      static const struct {
>          struct range ranges[MAX_RANGES];

No renaming to test_main() here?

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 5/7] tools/tests/common: ensure error messages have a newline
  2026-02-23 10:14 ` [PATCH 5/7] tools/tests/common: ensure error messages have a newline Edwin Török
@ 2026-02-24 11:36   ` Jan Beulich
  0 siblings, 0 replies; 21+ messages in thread
From: Jan Beulich @ 2026-02-24 11:36 UTC (permalink / raw)
  To: Edwin Török; +Cc: Anthony PERARD, xen-devel

On 23.02.2026 11:14, Edwin Török wrote:
> Otherwise messages from the next test will end up on the same line as an
> error message from a previous test.
> (calling `fail` is not fatal).

Will they? Glancing quickly over the uses of fail(), I see most if not all
of them using a newline. Same for verify(). Imo either all use sites have
newlines, or all use sites lose them in favor of adding them centrally ...

> --- a/tools/tests/common/tests.h
> +++ b/tools/tests/common/tests.h
> @@ -6,12 +6,12 @@ extern unsigned int nr_failures;
>  #define fail(fmt, ...)                          \
>  ({                                              \
>      nr_failures++;                              \
> -    (void)printf(fmt, ##__VA_ARGS__);           \
> +    (void)printf(fmt"\n", ##__VA_ARGS__);           \
>  })
>  
>  #define verify(exp, fmt, args...) \
>  while (!(exp)) { \
> -    printf(fmt, ## args); \
> +    printf(fmt"\n", ## args); \
>      exit(EX_SOFTWARE); \
>  }

... here.

As a style nit - please have a blank between fmt and the string literal.

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 6/7] tools/tests/tsx: move guest creation to common area
  2026-02-23 10:14 ` [PATCH 6/7] tools/tests/tsx: move guest creation to common area Edwin Török
@ 2026-02-24 11:49   ` Jan Beulich
  0 siblings, 0 replies; 21+ messages in thread
From: Jan Beulich @ 2026-02-24 11:49 UTC (permalink / raw)
  To: Edwin Török; +Cc: Anthony PERARD, xen-devel

On 23.02.2026 11:14, Edwin Török wrote:
> --- /dev/null
> +++ b/tools/tests/common/guests.c

Everything in the file uses singular, si I'd suggest to use singular also for
the file name.

> @@ -0,0 +1,87 @@
> +#define _GNU_SOURCE
> +#include "guests.h"
> +#include "tests.h"
> +
> +#include <err.h>
> +#include <errno.h>
> +#include <string.h>
> +
> +xc_interface *xch;
> +xc_physinfo_t physinfo;
> +bool xen_has_pv = true, xen_has_hvm = true;

static for at least some of these?

> +void test_guest_init(void)
> +{
> +    int rc;
> +    xch = xc_interface_open(NULL, NULL, 0);
> +
> +    if ( !xch )
> +        err(1, "xc_interface_open");
> +
> +    rc = xc_physinfo(xch, &physinfo);
> +    if ( rc )
> +        err(1, "Failed to obtain physinfo");
> +
> +    xen_has_hvm = physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm;
> +    xen_has_pv = physinfo.capabilities & XEN_SYSCTL_PHYSCAP_pv;
> +}
> +
> +void test_guest(struct xen_domctl_createdomain *c)

static?

> +{
> +    uint32_t domid = 0;
> +    int rc;
> +
> +    if (!xch)

Everything else uses Xen style, so this wants to, too.

> +        return fail("test_guest_init() not called");
> +
> +    rc = xc_domain_create(xch, &domid, c);
> +    if ( rc )
> +        return fail("  Domain create failure: %d - %s\n",
> +                    errno, strerror(errno));
> +
> +    printf("  Created d%u\n", domid);
> +
> +    test_guest_domid(domid);

This might better be passed as a function pointer, so harnesses can have
multiple functions dealing with different aspects of the testing.

> +    rc = xc_domain_destroy(xch, domid);
> +    if ( rc )
> +        fail("  Failed to destroy domain: %d - %s\n",
> +             errno, strerror(errno));
> +}
> +
> +void test_guests(void)
> +{
> +    if ( xen_has_pv )
> +    {
> +        struct xen_domctl_createdomain c = {
> +            .max_vcpus = 1,
> +            .max_grant_frames = 1,
> +            .grant_opts = XEN_DOMCTL_GRANT_version(1),
> +        };
> +
> +        printf("Testing PV guest\n");

To easily distinguish things in the output of a harness creating multiple
guests, some disambuating string may want passing in.

> +        test_guest(&c);
> +    }
> +
> +    if ( xen_has_hvm )
> +    {
> +        struct xen_domctl_createdomain c = {
> +            .flags = XEN_DOMCTL_CDF_hvm,
> +            .max_vcpus = 1,
> +            .max_grant_frames = 1,
> +            .grant_opts = XEN_DOMCTL_GRANT_version(1),
> +            .arch = {
> +                .emulation_flags = XEN_X86_EMU_LAPIC,
> +            },
> +        };

For starters this may work, but longer term we may need ways to specify certain
propertied of the to be created guest(s).

> --- /dev/null
> +++ b/tools/tests/common/guests.h
> @@ -0,0 +1,11 @@
> +#include <xenctrl.h>
> +#include <xen/domctl.h>
> +
> +extern void test_guest_domid(domid_t domid);

Nit: If this was to stay, no need for "extern", just like ...

> +extern xc_interface *xch;
> +extern xc_physinfo_t physinfo;
> +extern bool xen_has_pv, xen_has_hvm;
> +
> +void test_guest_init(void);
> +void test_guest(struct xen_domctl_createdomain *c);
> +void test_guests(void);

... you have none here.

> --- a/tools/tests/tsx/Makefile
> +++ b/tools/tests/tsx/Makefile
> @@ -11,4 +11,6 @@ CFLAGS += $(CFLAGS_libxenguest)
>  LDFLAGS += $(LDLIBS_libxenctrl)
>  LDFLAGS += $(LDLIBS_libxenguest)
>  
> +$(TARGET): ../common/guests.o

Does this work properly with parallel builds, once more than one test would
use it?

> --- a/tools/tests/tsx/test-tsx.c
> +++ b/tools/tests/tsx/test-tsx.c
> @@ -31,6 +31,7 @@
>  #include <xen-tools/common-macros.h>
>  
>  #include "tests.h"
> +#include "guests.h"

Isn't this ../common/guests.h ? Plus perhaps common stuff could go straight
in the parent directory anyway?

Jan


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/7] tools/tests/vpci/main.c: drop unused variables
  2026-02-23 10:14 ` [PATCH 2/7] tools/tests/vpci/main.c: drop unused variables Edwin Török
@ 2026-02-24 14:44   ` Roger Pau Monné
  0 siblings, 0 replies; 21+ messages in thread
From: Roger Pau Monné @ 2026-02-24 14:44 UTC (permalink / raw)
  To: Edwin Török; +Cc: xen-devel, Stewart Hildebrand, Anthony PERARD

On Mon, Feb 23, 2026 at 10:14:06AM +0000, Edwin Török wrote:
> They may become build failures.
> 
> Signed-off-by: Edwin Török <edwin.torok@citrix.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] Factor out common build rules and helpers in tools/tests
  2026-02-23 10:42 ` [PATCH 0/7] Factor out common build rules and helpers in tools/tests Jan Beulich
@ 2026-02-27 18:00   ` Edwin Torok
  2026-03-31 20:12     ` Edwin Torok
  0 siblings, 1 reply; 21+ messages in thread
From: Edwin Torok @ 2026-02-27 18:00 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monne,
	Stewart Hildebrand, xen-devel@lists.xenproject.org, Denis Mukhin


> On 23 Feb 2026, at 10:42, Jan Beulich <jbeulich@suse.com> wrote:
> 
> On 23.02.2026 11:14, Edwin Török wrote:
>> There are a lot of duplicate rules and code in tools/tests.
>> To simplify writing new tests move common build rules into a
>> `tools/tests/Rules.mk`, and helper macros/functions into `common/{tests,guests}.{c,h}`.
>> 
>> This also ensures that CFLAGS are applied consistently across all tests (e.g. one test failed
>> to build now due to an unused variable error).
>> 
>> Guest creation also needs to test for the presence of PV, HVM HAP or HVM shadow support
>> in Xen and create a guest accordingly. This can be shared.
>> 
>> After these changes the per-test Makefile only contains entries specific
>> to the test (its name, dependencies, etc.) and avoids having to
>> copy&paste boilerplate code.
>> 
>> `tools/tests/x86_emulator` remains unchanged, because the Makefile
>> contains a lot of conditional build logic specific to that test.
>> 
>> An upcoming patch series will introduce new tests using the simplified
>> Makefile and shared helpers.
>> 
>> For convenience this is also available at:
>> https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...private%2Fedvint%2Fmigration-tests2?from_project_id=2336572
>> https://gitlab.com/xen-project/people/edwintorok/xen/-/pipelines/2342318716
>> 
>> Edwin Török (7):
>>  tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk
>>  tools/tests/vpci/main.c: drop unused variables
>>  tools/tests/*/Makefile: factor out build rules
>>  tools/tests: factor out common helpers
>>  tools/tests/common: ensure error messages have a newline
>>  tools/tests/tsx: move guest creation to common area
>>  tools/tests: print more debug info
> 
> Just fyi that there is also
> https://lists.xen.org/archives/html/xen-devel/2026-02/msg00751.html.
> Can the two of you maybe work together to have a single resulting approach?
> 
> Jan

There is definitely a lot in common between the two series, and I’m talking with Denis.
The Makefile cleanups that both of us have done can probably go in first as part of a shared series,
I’ll try to setup a combined branch to see how that’d look like.

Best regards,
—Edwin

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/7] Factor out common build rules and helpers in tools/tests
  2026-02-27 18:00   ` Edwin Torok
@ 2026-03-31 20:12     ` Edwin Torok
  0 siblings, 0 replies; 21+ messages in thread
From: Edwin Torok @ 2026-03-31 20:12 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Anthony PERARD, Andrew Cooper, Roger Pau Monne,
	Stewart Hildebrand, xen-devel@lists.xenproject.org, Denis Mukhin,
	Marcus Granado



> On 27 Feb 2026, at 18:00, Edwin Torok <edwin.torok@citrix.com> wrote:
> 
> 
>> On 23 Feb 2026, at 10:42, Jan Beulich <jbeulich@suse.com> wrote:
>> 
>> On 23.02.2026 11:14, Edwin Török wrote:
>>> There are a lot of duplicate rules and code in tools/tests.
>>> To simplify writing new tests move common build rules into a
>>> `tools/tests/Rules.mk`, and helper macros/functions into `common/{tests,guests}.{c,h}`.
>>> 
>>> ….
>> 
>> Just fyi that there is also
>> https://lists.xen.org/archives/html/xen-devel/2026-02/msg00751.html.
>> Can the two of you maybe work together to have a single resulting approach?
>> 
>> Jan
> 
> There is definitely a lot in common between the two series, and I’m talking with Denis.
> The Makefile cleanups that both of us have done can probably go in first as part of a shared series,
> I’ll try to setup a combined branch to see how that’d look like.
> 


I have a combined branch here:
https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...private%2Fedvint%2Fmigration-tests5?from_project_id=2336572

TODO:
* rebase the vPCI Makefile patch on top of this 
* there is review feedback for the previous series on the list

Today is my last actual working day at Citrix, and likely next week onward this email address will stop working too.
I intended to finish my pending patch series, unfortunately I ran out of time (I managed to get the ~70+ XAPI+Xen branches down to ~18, but cycling through each series took more time than available).
I hope that someone else (e.g. from XenServer) will be able to pick up where I left off and complete these.

I intended to send out the rest of the branches I have as patches, but git send-email or the internal SMTP server stopped working.

Here are some git repositories instead:
* this series: https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...private%2Fedvint%2Fmigration-tests5?from_project_id=2336572

* the migration foreign copy optimizations as a Proof of Concept (~2.5x faster localhost migrations). Don’t use these as is, should be done properly by introducing a separate foreign copy operation, instead of piggy-backing on top of grant-copy as I’ve done here (piggy-backing was useful for measuring the performance optimisation potential, since a lot of the glue code between hypervisor and user space was already there): https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...private%2Fedvint%2Ftests2?from_project_id=2336572

* combined XenServer patch queue + PMU stacktrace (flame graph) + migration foreign copy optimizations https://gitlab.com/xen-project/people/edwintorok/xen/-/compare/staging...guilt%2Fpatches?from_project_id=2336572
* foreign copy Proof of Concept for the kernel (this is a kernel tree in a Xen git repo):  https://gitlab.com/xen-project/people/edwintorok/xen/-/commit/ea13155dce8f2f1cfd1a2c54a3f8158be8beed62

I’m not leaving the Xen ecosystem entirely, in my new role I’ll be working on the Unikraft and MirageOS subprojects, instead of the XAPI subproject of Xen
(it’ll likely mean a lot less interaction with the hypervisor itself)

Thank you all for all your patience and advice when reviewing patches!


Best regards,
—Edwin

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2026-03-31 20:12 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 10:14 [PATCH 0/7] Factor out common build rules and helpers in tools/tests Edwin Török
2026-02-23 10:14 ` [PATCH 1/7] tools/tests/*/Makefile: factor out common PHONY rules into Rules.mk Edwin Török
2026-02-23 16:37   ` Jan Beulich
2026-02-24  9:38     ` Edwin Torok
2026-02-24  9:42       ` Jan Beulich
2026-02-24 10:01         ` Edwin Torok
2026-02-24 10:30           ` Jan Beulich
2026-02-23 10:14 ` [PATCH 2/7] tools/tests/vpci/main.c: drop unused variables Edwin Török
2026-02-24 14:44   ` Roger Pau Monné
2026-02-23 10:14 ` [PATCH 3/7] tools/tests/*/Makefile: factor out build rules Edwin Török
2026-02-24 11:15   ` Jan Beulich
2026-02-23 10:14 ` [PATCH 4/7] tools/tests: factor out common helpers Edwin Török
2026-02-24 11:27   ` Jan Beulich
2026-02-23 10:14 ` [PATCH 5/7] tools/tests/common: ensure error messages have a newline Edwin Török
2026-02-24 11:36   ` Jan Beulich
2026-02-23 10:14 ` [PATCH 6/7] tools/tests/tsx: move guest creation to common area Edwin Török
2026-02-24 11:49   ` Jan Beulich
2026-02-23 10:14 ` [PATCH 7/7] tools/tests: print more debug info Edwin Török
2026-02-23 10:42 ` [PATCH 0/7] Factor out common build rules and helpers in tools/tests Jan Beulich
2026-02-27 18:00   ` Edwin Torok
2026-03-31 20:12     ` Edwin Torok

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.