From: Anthony PERARD <anthony@xenproject.org>
To: dmkhn@proton.me
Cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com,
anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org,
michal.orzel@amd.com, roger.pau@citrix.com,
sstabellini@kernel.org, dmukhin@ford.com,
Julien Grall <jgrall@amazon.com>
Subject: Re: [PATCH v16 3/4] tools/tests: introduce unit tests for domain ID allocator
Date: Mon, 25 Aug 2025 15:47:39 +0200 [thread overview]
Message-ID: <aKxpe7OJ8B7Qif5c@l14> (raw)
In-Reply-To: <20250812223024.2364749-4-dmukhin@ford.com>
On Tue, Aug 12, 2025 at 10:30:50PM +0000, dmkhn@proton.me wrote:
> diff --git a/tools/tests/domid/.gitignore b/tools/tests/domid/.gitignore
> new file mode 100644
> index 000000000000..0e02715159c2
> --- /dev/null
> +++ b/tools/tests/domid/.gitignore
> @@ -0,0 +1,3 @@
> +*.o
"*.o" is already in the .gitignore at the root of the project. I don't
think it's useful here.
> +generated
> +test-domid
> diff --git a/tools/tests/domid/Makefile b/tools/tests/domid/Makefile
> new file mode 100644
> index 000000000000..0a124a8bfc76
> --- /dev/null
> +++ b/tools/tests/domid/Makefile
> @@ -0,0 +1,84 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# Unit tests for domain ID allocator.
> +#
> +# Copyright 2025 Ford Motor Company
> +
> +XEN_ROOT=$(CURDIR)/../../..
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +TESTS := test-domid
> +
> +strip-list = $(sort $(strip $(foreach x,$(1),$(strip $(x)))))
What's that macro for? Also, what's a "list"?
> +define list-c-headers
> +$(shell sed -n -r \
Could you use "-E" instead of "-r"? (-r might not work on FreeBSD)
> + 's/^[ \t]*# *include[ \t]*[<"]([^">]+)[">].*/\1/p' $(1) 2>/dev/null)
> +endef
> +
> +define emit-harness-nested-rule
> +$(1): $(CURDIR)/harness.h
> + mkdir -p $$(dir $$@)
You can use $(@D) instead of $(dir $@). The only difference is a /
not present at the end.
> + ln -sf $$^ $$@
This should use $<, I don't think the command is going to work if
there's multiple prerequisite.
> +endef
> +
> +define emit-harness-rules
> +ifneq ($(strip $(3)),)
How many time do you need to call $(strip) ?
Also, I think I would prefer to have $(if $(strip $(3)), [the rest])
rather than actually evaluating code and generating code that we already
know is isn't going to be executed.
> +$(foreach h,$(3),$(call emit-harness-nested-rule,$(CURDIR)/generated/$(h)))
> +vpath $(1) $(2)
> +$(1:.c=.o): $(addprefix $(CURDIR)/generated/,$(3))
> +endif
> +endef
This macro fails if there's more than one "#include" in "domid.c".
And if there's no "#include" in "domid.c", then Make doesn't know how to
make "domid.o" for "test-domid".
> +
> +define vpath-with-harness-deps
> +$(call emit-harness-rules,$(1),$(2),\
> + $(call strip-list,$(call list-c-headers,$(2)$(1))))
> +endef
> +
> +.PHONY: all
> +all: $(TESTS)
> +
> +.PHONY: run
> +run: $(TESTS)
> + $(foreach t,$(TESTS),./$(t);)
This recipe doesn't work as expected. You need `set -e` or only the last
tests count.
> +
> +.PHONY: clean
> +clean:
> + $(RM) -rf $(CURDIR)/generated
$(RM) already contain the '-f' option, no need to add it a second time.
Also, we expected Make to run all commands in recipe from $(CURDIR), so
adding $(CURDIR) is unnecessary, could potentially be an issue.
> + $(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
> +CFLAGS += '-DEXPORT_SYMBOL(x)=' \
> + -Dfind_first_bit \
> + -Dfind_first_zero_bit \
> + -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/
> +# Ubuntu {16,18}.04 need single eval at the call site.
I'd rather see a comment about what's the macro is about rather that a
comment some Linux distribution. Our target is GNU Make 3.80, without
regards to a particular distribution. (Also I don't think it's useful to
point out that `eval` is needed for older version of Make, at least in
our project.)
> +$(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)
> diff --git a/tools/tests/domid/test-domid.c b/tools/tests/domid/test-domid.c
> new file mode 100644
> index 000000000000..51a88a6a9550
> --- /dev/null
> +++ b/tools/tests/domid/test-domid.c
> @@ -0,0 +1,93 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Unit tests for domain ID allocator.
> + *
> + * Copyright 2025 Ford Motor Company
> + */
> +
> +#include "harness.h"
> +
> +#define verify(exp, fmt, args...) do { \
> + if ( !(exp) ) \
> + printf(fmt, ## args); \
> + assert(exp); \
Relying on assert() for the test isn't wise. It's useful for developing
and debugging because it calls abort(), but they can easily be get rid of,
by simply building with -DNDEBUG. Could you maybe replace it with exit()
since you already check the condition?
Thanks,
--
Anthony PERARD
next prev parent reply other threads:[~2025-08-25 13:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 22:30 [PATCH v16 0/4] xen/domain: domain ID allocation dmkhn
2025-08-12 22:30 ` [PATCH v16 1/4] xen/domain: unify " dmkhn
2025-08-14 7:11 ` Jan Beulich
2025-08-19 23:58 ` dmkhn
2025-08-21 7:16 ` Jan Beulich
2025-08-21 10:29 ` Alejandro Vallejo
2025-08-26 9:52 ` dmkhn
2025-08-26 9:53 ` dmkhn
2025-08-26 9:53 ` dmkhn
2025-08-20 21:33 ` Julien Grall
2025-08-26 9:51 ` dmkhn
2025-08-29 23:32 ` dmukhin
2025-08-12 22:30 ` [PATCH v16 2/4] tools/include: move xc_bitops.h to xen-tools/bitops.h dmkhn
2025-08-25 9:30 ` Anthony PERARD
2025-08-26 9:28 ` dmkhn
2025-08-12 22:30 ` [PATCH v16 3/4] tools/tests: introduce unit tests for domain ID allocator dmkhn
2025-08-25 13:47 ` Anthony PERARD [this message]
2025-08-26 9:48 ` dmkhn
2025-08-12 22:30 ` [PATCH v16 4/4] xen/domain: update create_dom0() messages dmkhn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aKxpe7OJ8B7Qif5c@l14 \
--to=anthony@xenproject.org \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=dmkhn@proton.me \
--cc=dmukhin@ford.com \
--cc=jbeulich@suse.com \
--cc=jgrall@amazon.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.