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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: dmukhin@xxxxxxxx
  • Date: Thu, 12 Feb 2026 18:49:49 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 205.220.161.53) 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=D+K4AlEnp22qTNZLqCdKEdqhzmvY/R2xKikFORG7B4I=; b=EckWBDaOzH6xxGzFtvnOeGmnwDI60KnMXHVAayFaYcuydNG0POgTuqvoKAR2PNbY5+VnamM+OQkulMtEfFweaTN3uvSQErecBsWwTiyPDNMDe2GR6vYo/VQIkLXMCqriR8sAhH70I7LHqxXap8jp/00i8rYGxKXpzgCAtIwKL2ZtbFLqr9ZTYf3KO4hIHvyjyl5XZftl4AiiZBuFMOqjv8nktpoVT08NVn/irRi4kcX7//M7scYyL8tAM+CVrMtbUURzBdmC8fMjFw4jjx9VDTihjwsDYwZqKXGgH17Lvq+JeOpLqevSXT1F1NObaJ+m342LXAWkZsRE6e9lcy4CRA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eBSew6fgw5NjfL4W+q28Ftnwbma1Ss/K17Ot7XvWmOM1iGKOExcl7vVmlkDf8P/rvKh36s4FVPf1TG6IFnnBMhI6QgPIbAJqqHfvNzQ95KWL25QwTYzI+TignZmbQGtC+KHRdivezMkSVjO1NELIw5etiDOtJ3JsdbdD7hWKLhMOEccSq4+yAzBg9lzvUIEkHnvUUHCJkLuS+iH9PYLwNxlKT5IBpJir6b329zVXTEWMN2B1LiVb7H2SZm0Td6MgBcENcnRD9qIQLpJLVm+nTqlULjxKLMTHOJXeVowe5ieKcIx6BffnQhc+QQlUXkiOMZo9i0shRD900SCUiv33SQ==
  • 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> 

Introduce common fragment for unit tests to minimize some code
duplication.

Use the new make fragment to generate test harness code for the domain
ID allocator unit test.

Introduce CFLAGS dedicated for find-next-bit.c only to avoid contaminating
global CFLAGS.

Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
Changes since v2:
- honor LDFLAGS
---
 tools/tests/Rules.mk       | 93 +++++++++++++++++++++++++++++++++++++
 tools/tests/domid/Makefile | 95 ++------------------------------------
 2 files changed, 98 insertions(+), 90 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 000000000000..8c4881e35da1
--- /dev/null
+++ b/tools/tests/Rules.mk
@@ -0,0 +1,93 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Common unit test fragment.
+#
+
+include $(XEN_ROOT)/tools/Rules.mk
+
+define list-c-headers
+$(shell sed -n \
+    's/^[ \t]*# *include[ \t]*[<"]\([^">]*\)[">].*/\1/p' $(1) 2>/dev/null)
+endef
+
+# Generate mock environment by replicating header file hierarchy;
+# each mock header file will point to a harness header.
+#
+# $1 Hypervisor header.
+# $2 Test harness header.
+define emit-harness-nested-rule
+$(1): $(2)
+       set -e; \
+       mkdir -p $$(@D); \
+       [ -e $$@ ] || ln -s $(2) $$@
+
+endef
+
+# Helper function to emit mock hypervisor code dependencies.
+#
+# $1 Hypervisor filename.
+# $2 Harness filename.
+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)))
+$(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 $$^)
+
+endef
+
+# Emit dependencies for mock hypervisor code.
+#
+# $1 Hypervisor filename.
+# $2 Hypervisor source path.
+define vpath-with-harness-deps
+vpath $(1) $(2)
+$(call emit-harness-deps,$(addprefix $(2),$(1)),\
+                         $(CURDIR)/harness.h)
+endef
+
+.PHONY: all
+all: $(TESTS)
+
+.PHONY: run
+run: $(TESTS)
+ifeq ($(CC),$(HOSTCC))
+       set -e; $(foreach t,$(TESTS),./$(t);)
+else
+       $(warning HOSTCC != CC, will not run test)
+endif
+
+.PHONY: clean
+clean:
+       $(RM) -r generated
+       $(RM) -- *.o $(TESTS) $(DEPS_RM)
+
+.PHONY: distclean
+distclean: clean
+       $(RM) -- *~
+
+.PHONY: install
+install: all
+       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
+       set -e; $(foreach t,$(TESTS),$(INSTALL_PROG) $t 
$(DESTDIR)$(LIBEXEC)/tests;)
+
+.PHONY: uninstall
+uninstall:
+       set -e; $(foreach t,$(TESTS),$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$t;)
+
+CFLAGS += -D__XEN_TOOLS__
+
+# Honor mock hypervisor headers over tools/include/xen
+CFLAGS += -I$(CURDIR)/generated/
+CFLAGS += $(CFLAGS_xeninclude)
+CFLAGS += $(APPEND_CFLAGS)
+
+LDFLAGS += $(APPEND_LDFLAGS)
+
+ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
+-include $(DEPS_INCLUDE)
+endif
diff --git a/tools/tests/domid/Makefile b/tools/tests/domid/Makefile
index 74cadab25b2e..b6ba0c4e14ee 100644
--- a/tools/tests/domid/Makefile
+++ b/tools/tests/domid/Makefile
@@ -4,101 +4,20 @@
 #
 # Copyright 2025 Ford Motor Company
 
-XEN_ROOT=$(CURDIR)/../../..
-include $(XEN_ROOT)/tools/Rules.mk
-
 TESTS := test-domid
 
-define list-c-headers
-$(shell sed -n \
-    's/^[ \t]*# *include[ \t]*[<"]\([^">]*\)[">].*/\1/p' $(1) 2>/dev/null)
-endef
-
-# Generate mock environment by replicating header file hierarchy;
-# each mock header file will point to a harness header.
-#
-# $1 Hypervisor header.
-# $2 Test harness header.
-define emit-harness-nested-rule
-$(1): $(2)
-       set -e; \
-       mkdir -p $$(@D); \
-       [ -e $$@ ] || ln -s $(2) $$@
-
-endef
-
-# Helper function to emit mock hypervisor code dependencies.
-#
-# $1 Hypervisor filename.
-# $2 Harness filename.
-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)))
-$(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 $$^)
-
-endef
-
-# Emit dependencies for mock hypervisor code.
-#
-# $1 Hypervisor filename.
-# $2 Hypervisor source path.
-define vpath-with-harness-deps
-vpath $(1) $(2)
-$(call emit-harness-deps,$(addprefix $(2),$(1)),\
-                         $(CURDIR)/harness.h)
-endef
-
-.PHONY: all
-all: $(TESTS)
-
-.PHONY: run
-run: $(TESTS)
-ifeq ($(CC),$(HOSTCC))
-       set -e; $(foreach t,$(TESTS),./$(t);)
-else
-       $(warning HOSTCC != CC, will not run test)
-endif
-
-.PHONY: clean
-clean:
-       $(RM) -r generated
-       $(RM) -- *.o $(TESTS) $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-       $(RM) -- *~
-
-.PHONY: install
-install: all
-       $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-       set -e; $(foreach t,$(TESTS),$(INSTALL_PROG) $t 
$(DESTDIR)$(LIBEXEC)/tests;)
-
-.PHONY: uninstall
-uninstall:
-       set -e; $(foreach t,$(TESTS),$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$t;)
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/tests/Rules.mk
 
 # find-next-bit.c
-CFLAGS += '-DEXPORT_SYMBOL(x)=' \
+CFLAGS-find-next-bit.c += '-DEXPORT_SYMBOL(x)=' \
           -Dfind_first_bit \
           -Dfind_first_zero_bit \
           -Dfind_next_bit \
           -Dfind_next_bit_le \
           -Dfind_next_zero_bit_le
 
-CFLAGS += -D__XEN_TOOLS__
-
-# Honor mock hypervisor headers over tools/include/xen
-CFLAGS += -I$(CURDIR)/generated/
-CFLAGS += $(CFLAGS_xeninclude)
-CFLAGS += $(APPEND_CFLAGS)
-
-LDFLAGS += $(APPEND_LDFLAGS)
+find-next-bit.o: CFLAGS += $(CFLAGS-find-next-bit.c)
 
 vpath find-next-bit.c $(XEN_ROOT)/xen/lib/
 
@@ -108,8 +27,4 @@ vpath find-next-bit.c $(XEN_ROOT)/xen/lib/
 $(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)
-
-ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
--include $(DEPS_INCLUDE)
-endif
+       $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
-- 
2.52.0




 


Rackspace

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