|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 4/7] tools/tests: factor out common helpers
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |