From: Emil Velikov Date: Fri, 13 Jun 2025 16:16:09 +0000 (+0100) Subject: testsuite: introduce and use EXEC_TOOL() macro X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d59268554b0a7ea68dfc5bf17289b9bdef7d2843;p=thirdparty%2Fkmod.git testsuite: introduce and use EXEC_TOOL() macro Swap the currect EXEC_DEPMOD and EXEC_MODPROBE with a slightly more generic macro - EXEC_TOOL based off them. Update all in-tree instances of test_spawn_prog() to use it. This will make follow-up work (removing the noreturn/exit) a bit easier and more consistent. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/371 Signed-off-by: Lucas De Marchi --- diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c index 060a5fb0..9ac20d11 100644 --- a/testsuite/test-depmod.c +++ b/testsuite/test-depmod.c @@ -13,16 +13,12 @@ #include "testsuite.h" -#define EXEC_DEPMOD(...) \ - test_spawn_prog(TOOLS_DIR "/depmod", \ - (const char *[]){ TOOLS_DIR "/depmod", ##__VA_ARGS__, NULL }) - #define MODULES_UNAME "4.4.4" #define MODULES_ORDER_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-order-compressed" #define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_modules_order_for_compressed(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_modules_order_for_compressed, @@ -46,7 +42,7 @@ DEFINE_TEST(depmod_modules_order_for_compressed, MODULES_OUTDIR_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_modules_outdir(void) { - EXEC_DEPMOD("--outdir", "/outdir/"); + EXEC_TOOL(depmod, "--outdir", "/outdir/"); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_modules_outdir, @@ -70,7 +66,7 @@ DEFINE_TEST(depmod_modules_outdir, SEARCH_ORDER_SIMPLE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_search_order_simple(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_simple, @@ -92,12 +88,12 @@ DEFINE_TEST(depmod_search_order_simple, #define MODULES_ANOTHER_MODDIR_ROOTFS TESTSUITE_ROOTFS "test-depmod/another-moddir" static noreturn int depmod_another_moddir(void) { - EXEC_DEPMOD("-m", ANOTHER_MODDIR); + EXEC_TOOL(depmod, "-m", ANOTHER_MODDIR); exit(EXIT_FAILURE); } static noreturn int depmod_another_moddir_relative(void) { - EXEC_DEPMOD("-m", RELATIVE_MODDIR); + EXEC_TOOL(depmod, "-m", RELATIVE_MODDIR); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_another_moddir, @@ -133,7 +129,7 @@ DEFINE_TEST(depmod_another_moddir_relative, SEARCH_ORDER_SAME_PREFIX_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_search_order_same_prefix(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_same_prefix, @@ -153,7 +149,7 @@ DEFINE_TEST(depmod_search_order_same_prefix, #define DETECT_LOOP_ROOTFS TESTSUITE_ROOTFS "test-depmod/detect-loop" static noreturn int depmod_detect_loop(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_detect_loop, @@ -173,7 +169,7 @@ DEFINE_TEST(depmod_detect_loop, SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_search_order_external_first(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_external_first, @@ -196,7 +192,7 @@ DEFINE_TEST(depmod_search_order_external_first, SEARCH_ORDER_EXTERNAL_LAST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_search_order_external_last(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_external_last, @@ -218,7 +214,7 @@ DEFINE_TEST(depmod_search_order_external_last, SEARCH_ORDER_OVERRIDE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_search_order_override(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_override, @@ -239,7 +235,7 @@ DEFINE_TEST(depmod_search_order_override, #define CHECK_WEAKDEP_LIB_MODULES CHECK_WEAKDEP_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME static noreturn int depmod_check_weakdep(void) { - EXEC_DEPMOD(); + EXEC_TOOL(depmod); exit(EXIT_FAILURE); } DEFINE_TEST(depmod_check_weakdep, diff --git a/testsuite/test-modinfo.c b/testsuite/test-modinfo.c index d91cde16..9bb9a485 100644 --- a/testsuite/test-modinfo.c +++ b/testsuite/test-modinfo.c @@ -12,17 +12,12 @@ #include "testsuite.h" -static const char *progname = TOOLS_DIR "/modinfo"; - -#define DEFINE_MODINFO_TEST(_field, _flavor, ...) \ - static noreturn int test_modinfo_##_field(void) \ - { \ - const char *const args[] = { \ - progname, "-F", #_field, __VA_ARGS__, NULL, \ - }; \ - test_spawn_prog(progname, args); \ - exit(EXIT_FAILURE); \ - } \ +#define DEFINE_MODINFO_TEST(_field, _flavor, ...) \ + static noreturn int test_modinfo_##_field(void) \ + { \ + EXEC_TOOL(modinfo, "-F", #_field, __VA_ARGS__); \ + exit(EXIT_FAILURE); \ + } \ DEFINE_TEST(test_modinfo_##_field, \ .description = "check " #_field " output of modinfo for different architectures", \ .config = { \ @@ -60,12 +55,7 @@ DEFINE_MODINFO_SIGN_TEST(sig_hashalgo); #if 0 static noreturn int test_modinfo_signature(void) { - const char *const args[] = { - progname, - NULL, - }; - - test_spawn_prog(progname, args); + EXEC_TOOL(modinfo); exit(EXIT_FAILURE); } DEFINE_TEST(test_modinfo_signature, @@ -80,15 +70,7 @@ DEFINE_TEST(test_modinfo_signature, static noreturn int test_modinfo_external(void) { - const char *const args[] = { - // clang-format off - progname, - "-F", "filename", - "mod-simple", - NULL, - // clang-format on - }; - test_spawn_prog(progname, args); + EXEC_TOOL(modinfo, "-F", "filename", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(test_modinfo_external, @@ -103,14 +85,7 @@ DEFINE_TEST(test_modinfo_external, static noreturn int test_modinfo_builtin(void) { - const char *const args[] = { - // clang-format off - progname, - "intel_uncore", - NULL, - // clang-format on - }; - test_spawn_prog(progname, args); + EXEC_TOOL(modinfo, "intel_uncore"); exit(EXIT_FAILURE); } DEFINE_TEST(test_modinfo_builtin, diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c index 951dd65c..5d7764a8 100644 --- a/testsuite/test-modprobe.c +++ b/testsuite/test-modprobe.c @@ -13,13 +13,9 @@ #include "testsuite.h" -#define EXEC_MODPROBE(...) \ - test_spawn_prog(TOOLS_DIR "/modprobe", \ - (const char *[]){ TOOLS_DIR "/modprobe", ##__VA_ARGS__, NULL }) - static noreturn int modprobe_show_depends(void) { - EXEC_MODPROBE("--show-depends", "mod-loop-a"); + EXEC_TOOL(modprobe, "--show-depends", "mod-loop-a"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_show_depends, @@ -34,7 +30,7 @@ DEFINE_TEST(modprobe_show_depends, static noreturn int modprobe_show_depends2(void) { - EXEC_MODPROBE("--show-depends", "mod-simple"); + EXEC_TOOL(modprobe, "--show-depends", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_show_depends2, @@ -57,7 +53,7 @@ DEFINE_TEST_WITH_FUNC(modprobe_show_depends_no_load, modprobe_show_depends2, static noreturn int modprobe_show_alias_to_none(void) { - EXEC_MODPROBE("--show-depends", "--ignore-install", "mod-simple"); + EXEC_TOOL(modprobe, "--show-depends", "--ignore-install", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_show_alias_to_none, @@ -74,7 +70,7 @@ DEFINE_TEST(modprobe_show_alias_to_none, static noreturn int modprobe_show_exports(void) { - EXEC_MODPROBE("--show-exports", "/mod-loop-a.ko"); + EXEC_TOOL(modprobe, "--show-exports", "/mod-loop-a.ko"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_show_exports, @@ -89,7 +85,7 @@ DEFINE_TEST(modprobe_show_exports, static noreturn int modprobe_show_exports_module(void) { - EXEC_MODPROBE("--show-exports", "mod-loop-b"); + EXEC_TOOL(modprobe, "--show-exports", "mod-loop-b"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_show_exports_module, @@ -105,7 +101,7 @@ DEFINE_TEST(modprobe_show_exports_module, static noreturn int modprobe_builtin(void) { - EXEC_MODPROBE("unix"); + EXEC_TOOL(modprobe, "unix"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_builtin, .description = "check if modprobe return 0 for builtin", @@ -116,7 +112,7 @@ DEFINE_TEST(modprobe_builtin, .description = "check if modprobe return 0 for bui static noreturn int modprobe_builtin_lookup_only(void) { - EXEC_MODPROBE("-R", "unix"); + EXEC_TOOL(modprobe, "-R", "unix"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_builtin_lookup_only, @@ -131,7 +127,7 @@ DEFINE_TEST(modprobe_builtin_lookup_only, static noreturn int modprobe_softdep_loop(void) { - EXEC_MODPROBE("mod-loop-b"); + EXEC_TOOL(modprobe, "mod-loop-b"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_softdep_loop, @@ -146,7 +142,7 @@ DEFINE_TEST(modprobe_softdep_loop, static noreturn int modprobe_weakdep_loop(void) { - EXEC_MODPROBE("mod-loop-b"); + EXEC_TOOL(modprobe, "mod-loop-b"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_weakdep_loop, @@ -162,7 +158,7 @@ DEFINE_TEST(modprobe_weakdep_loop, static noreturn int modprobe_install_cmd_loop(void) { - EXEC_MODPROBE("mod-loop-a"); + EXEC_TOOL(modprobe, "mod-loop-a"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_install_cmd_loop, @@ -181,7 +177,7 @@ DEFINE_TEST(modprobe_install_cmd_loop, static noreturn int modprobe_param_kcmdline_show_deps(void) { - EXEC_MODPROBE("--show-depends", "mod-simple"); + EXEC_TOOL(modprobe, "--show-depends", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_param_kcmdline_show_deps, @@ -196,7 +192,7 @@ DEFINE_TEST(modprobe_param_kcmdline_show_deps, static noreturn int modprobe_param_kcmdline(void) { - EXEC_MODPROBE("-c"); + EXEC_TOOL(modprobe, "-c"); exit(EXIT_FAILURE); } DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline2, modprobe_param_kcmdline, @@ -283,7 +279,7 @@ DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline9, modprobe_param_kcmdline, static noreturn int modprobe_force(void) { - EXEC_MODPROBE("--force", "mod-simple"); + EXEC_TOOL(modprobe, "--force", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_force, @@ -298,7 +294,7 @@ DEFINE_TEST(modprobe_force, static noreturn int modprobe_force_modversion(void) { - EXEC_MODPROBE("--force-modversion", "mod-simple"); + EXEC_TOOL(modprobe, "--force-modversion", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_force_modversion, @@ -313,7 +309,7 @@ DEFINE_TEST(modprobe_force_modversion, static noreturn int modprobe_force_vermagic(void) { - EXEC_MODPROBE("--force-vermagic", "mod-simple"); + EXEC_TOOL(modprobe, "--force-vermagic", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_force_vermagic, @@ -328,7 +324,7 @@ DEFINE_TEST(modprobe_force_vermagic, static noreturn int modprobe_oldkernel(void) { - EXEC_MODPROBE("mod-simple"); + EXEC_TOOL(modprobe, "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_oldkernel, @@ -343,7 +339,7 @@ DEFINE_TEST(modprobe_oldkernel, static noreturn int modprobe_oldkernel_force(void) { - EXEC_MODPROBE("--force", "mod-simple"); + EXEC_TOOL(modprobe, "--force", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_oldkernel_force, @@ -358,7 +354,7 @@ DEFINE_TEST(modprobe_oldkernel_force, static noreturn int modprobe_oldkernel_force_modversion(void) { - EXEC_MODPROBE("--force-modversion", "mod-simple"); + EXEC_TOOL(modprobe, "--force-modversion", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_oldkernel_force_modversion, @@ -373,7 +369,7 @@ DEFINE_TEST(modprobe_oldkernel_force_modversion, static noreturn int modprobe_oldkernel_force_vermagic(void) { - EXEC_MODPROBE("--force-vermagic", "mod-simple"); + EXEC_TOOL(modprobe, "--force-vermagic", "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_oldkernel_force_vermagic, @@ -388,7 +384,7 @@ DEFINE_TEST(modprobe_oldkernel_force_vermagic, static noreturn int modprobe_external(void) { - EXEC_MODPROBE("mod-simple"); + EXEC_TOOL(modprobe, "mod-simple"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_external, @@ -403,7 +399,7 @@ DEFINE_TEST(modprobe_external, static noreturn int modprobe_module_from_abspath(void) { - EXEC_MODPROBE("/home/foo/mod-simple.ko"); + EXEC_TOOL(modprobe, "/home/foo/mod-simple.ko"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_module_from_abspath, @@ -423,7 +419,7 @@ static noreturn int modprobe_module_from_relpath(void) exit(EXIT_FAILURE); } - EXEC_MODPROBE("./mod-simple.ko"); + EXEC_TOOL(modprobe, "./mod-simple.ko"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_module_from_relpath, diff --git a/testsuite/test-weakdep.c b/testsuite/test-weakdep.c index 49b1a7b3..c7c034d5 100644 --- a/testsuite/test-weakdep.c +++ b/testsuite/test-weakdep.c @@ -14,10 +14,6 @@ #include "testsuite.h" -#define EXEC_MODPROBE(...) \ - test_spawn_prog(TOOLS_DIR "/modprobe", \ - (const char *[]){ TOOLS_DIR "/modprobe", ##__VA_ARGS__, NULL }) - static int test_weakdep(void) { static const char *const mod_name[] = { @@ -85,7 +81,7 @@ DEFINE_TEST(test_weakdep, static noreturn int modprobe_config(void) { - EXEC_MODPROBE("-c"); + EXEC_TOOL(modprobe, "-c"); exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_config, diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index e2f44240..9b7a5620 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -108,6 +108,10 @@ const struct test *test_find(const struct test *start, const struct test *stop, int test_spawn_prog(const char *prog, const char *const args[]); int test_run(const struct test *t); +#define EXEC_TOOL(tool, ...) \ + test_spawn_prog(TOOLS_DIR "/" #tool, \ + (const char *[]){ TOOLS_DIR "/" #tool, ##__VA_ARGS__, NULL }) + #define TS_EXPORT __attribute__((visibility("default"))) #define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ##__VA_ARGS__)