From: Emil Velikov Date: Fri, 13 Jun 2025 16:37:25 +0000 (+0100) Subject: testsuite: remove remaining exit/noreturn instances X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d0d80ac0b6a82114f689213b82b32d9d51cfcb6;p=thirdparty%2Fkmod.git testsuite: remove remaining exit/noreturn instances Purge the remaining exit/noreturn instances, which means we now get a consistent return path on all tests and across both success and failure paths. 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-blacklist.c b/testsuite/test-blacklist.c index 883e0e9d..83e4e266 100644 --- a/testsuite/test-blacklist.c +++ b/testsuite/test-blacklist.c @@ -34,7 +34,7 @@ static int blacklist_1(void) ctx = kmod_new(NULL, NULL); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; for (size_t i = 0; i < ARRAY_SIZE(names); i++) { err = kmod_module_new_from_name(ctx, names[i], &mod); diff --git a/testsuite/test-dependencies.c b/testsuite/test-dependencies.c index 4d853b79..24b24182 100644 --- a/testsuite/test-dependencies.c +++ b/testsuite/test-dependencies.c @@ -18,7 +18,7 @@ #define TEST_UNAME "4.0.20-kmod" -static noreturn int test_dependencies(void) +static int test_dependencies(void) { struct kmod_ctx *ctx; struct kmod_module *mod = NULL; @@ -29,12 +29,12 @@ static noreturn int test_dependencies(void) ctx = kmod_new(NULL, NULL); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_name(ctx, "mod-foo", &mod); if (err < 0 || mod == NULL) { kmod_unref(ctx); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } list = kmod_module_get_dependencies(mod); @@ -57,13 +57,13 @@ static noreturn int test_dependencies(void) /* fooa, foob, fooc */ if (len != 3 || !fooa || !foob || !fooc) - exit(EXIT_FAILURE); + return EXIT_FAILURE; kmod_module_unref_list(list); kmod_module_unref(mod); kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST(test_dependencies, .description = "test if kmod_module_get_dependencies works", diff --git a/testsuite/test-init.c b/testsuite/test-init.c index a1523dbe..fb4cdce4 100644 --- a/testsuite/test-init.c +++ b/testsuite/test-init.c @@ -17,7 +17,7 @@ #include "testsuite.h" -static noreturn int test_load_resources(void) +static int test_load_resources(void) { struct kmod_ctx *ctx; const char *null_config = NULL; @@ -25,19 +25,19 @@ static noreturn int test_load_resources(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; kmod_set_log_priority(ctx, 7); err = kmod_load_resources(ctx); if (err != 0) { ERR("could not load libkmod resources: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST_WITH_FUNC( test_load_resource1, test_load_resources, @@ -58,22 +58,22 @@ DEFINE_TEST_WITH_FUNC( [TC_UNAME_R] = "5.6.0", }); -static noreturn int test_initlib(void) +static int test_initlib(void) { struct kmod_ctx *ctx; const char *null_config = NULL; ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST(test_initlib, .description = "test if libkmod's init function work"); -static noreturn int test_insert(void) +static int test_insert(void) { struct kmod_ctx *ctx; struct kmod_module *mod; @@ -82,23 +82,23 @@ static noreturn int test_insert(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_path(ctx, "/mod-simple.ko", &mod); if (err != 0) { ERR("could not create module from path: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } err = kmod_module_insert_module(mod, 0, NULL); if (err != 0) { ERR("could not insert module: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_module_unref(mod); kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST(test_insert, .description = "test if libkmod's insert_module returns ok", @@ -108,7 +108,7 @@ DEFINE_TEST(test_insert, }, .modules_loaded = "mod_simple"); -static noreturn int test_remove(void) +static int test_remove(void) { struct kmod_ctx *ctx; struct kmod_module *mod_simple, *mod_bla; @@ -117,37 +117,37 @@ static noreturn int test_remove(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_name(ctx, "mod-simple", &mod_simple); if (err != 0) { ERR("could not create module from name: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } err = kmod_module_new_from_name(ctx, "bla", &mod_bla); if (err != 0) { ERR("could not create module from name: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } err = kmod_module_remove_module(mod_simple, 0); if (err != 0) { ERR("could not remove module: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } err = kmod_module_remove_module(mod_bla, 0); if (err != -ENOENT) { ERR("wrong return code for failure test: %d\n", err); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_module_unref(mod_bla); kmod_module_unref(mod_simple); kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST( test_remove, .description = "test if libkmod's remove_module returns ok", diff --git a/testsuite/test-initstate.c b/testsuite/test-initstate.c index 115c7779..0d46ac02 100644 --- a/testsuite/test-initstate.c +++ b/testsuite/test-initstate.c @@ -18,7 +18,7 @@ #include "testsuite.h" -static noreturn int test_initstate_from_lookup(void) +static int test_initstate_from_lookup(void) { struct kmod_ctx *ctx; struct kmod_list *list = NULL; @@ -28,17 +28,17 @@ static noreturn int test_initstate_from_lookup(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_lookup(ctx, "fake-builtin", &list); if (err < 0) { ERR("could not create module from lookup: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (!list) { ERR("could not create module from lookup: module not found: fake-builtin\n"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } mod = kmod_module_get_module(list); @@ -47,14 +47,14 @@ static noreturn int test_initstate_from_lookup(void) if (r != KMOD_MODULE_BUILTIN) { ERR("module should have builtin state but is: %s\n", kmod_module_initstate_str(r)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_module_unref(mod); kmod_module_unref_list(list); kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST( test_initstate_from_lookup, @@ -65,7 +65,7 @@ DEFINE_TEST( [TC_UNAME_R] = "4.4.4", }); -static noreturn int test_initstate_from_name(void) +static int test_initstate_from_name(void) { struct kmod_ctx *ctx; struct kmod_module *mod = NULL; @@ -74,30 +74,30 @@ static noreturn int test_initstate_from_name(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_name(ctx, "fake-builtin", &mod); if (err != 0) { ERR("could not create module from lookup: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (!mod) { ERR("could not create module from lookup: module not found: fake-builtin\n"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } r = kmod_module_get_initstate(mod); if (r != KMOD_MODULE_BUILTIN) { ERR("module should have builtin state but is: %s\n", kmod_module_initstate_str(r)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_module_unref(mod); kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST(test_initstate_from_name, .description = diff --git a/testsuite/test-loaded.c b/testsuite/test-loaded.c index b8375cf4..fdfb280e 100644 --- a/testsuite/test-loaded.c +++ b/testsuite/test-loaded.c @@ -23,13 +23,13 @@ static int loaded_1(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_loaded(ctx, &list); if (err < 0) { fprintf(stderr, "%s\n", strerror(-err)); kmod_unref(ctx); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } printf("Module Size Used by\n"); diff --git a/testsuite/test-multi-softdep.c b/testsuite/test-multi-softdep.c index e53a65b9..74226a4a 100644 --- a/testsuite/test-multi-softdep.c +++ b/testsuite/test-multi-softdep.c @@ -79,7 +79,7 @@ static int multi_softdep(void) ctx = kmod_new(NULL, NULL); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; for (mod_index = 0; mod_index < ARRAY_SIZE(test_modules); mod_index++) { modname = test_modules[mod_index].modname; diff --git a/testsuite/test-new-module.c b/testsuite/test-new-module.c index 238908d4..c4968b2f 100644 --- a/testsuite/test-new-module.c +++ b/testsuite/test-new-module.c @@ -32,12 +32,12 @@ static int from_name(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; for (size_t i = 0; i < ARRAY_SIZE(modnames); i++) { err = kmod_module_new_from_name(ctx, modnames[i], &mod); if (err < 0) - exit(EXIT_FAILURE); + return EXIT_FAILURE; printf("modname: %s\n", kmod_module_get_name(mod)); kmod_module_unref(mod); @@ -66,14 +66,14 @@ static int from_alias(void) ctx = kmod_new(NULL, NULL); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; for (size_t i = 0; i < ARRAY_SIZE(modnames); i++) { struct kmod_list *l, *list = NULL; err = kmod_module_new_from_lookup(ctx, modnames[i], &list); if (err < 0) - exit(EXIT_FAILURE); + return EXIT_FAILURE; kmod_list_foreach(l, list) { struct kmod_module *m; diff --git a/testsuite/test-remove.c b/testsuite/test-remove.c index ed5cc31e..f4f69756 100644 --- a/testsuite/test-remove.c +++ b/testsuite/test-remove.c @@ -17,7 +17,7 @@ #include "testsuite.h" -static noreturn int test_remove(void) +static int test_remove(void) { struct kmod_ctx *ctx; struct kmod_module *mod; @@ -27,34 +27,34 @@ static noreturn int test_remove(void) ctx = kmod_new(NULL, &null_config); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; err = kmod_module_new_from_path(ctx, "/mod-simple.ko", &mod); if (err != 0) { ERR("could not create module from path: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } err = kmod_module_insert_module(mod, 0, NULL); if (err != 0) { ERR("could not insert module: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } err = kmod_module_remove_module(mod, 0); if (err != 0) { ERR("could not remove module: %s\n", strerror(-err)); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (stat("/sys/module/mod_simple", &st) == 0 && S_ISDIR(st.st_mode)) { ERR("could not remove module directory.\n"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_module_unref(mod); kmod_unref(ctx); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST(test_remove, .description = "test if libkmod's delete_module removes module directory", diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c index 647dc1e4..43c946f9 100644 --- a/testsuite/test-testsuite.c +++ b/testsuite/test-testsuite.c @@ -21,22 +21,22 @@ #include "testsuite.h" #define TEST_UNAME "4.0.20-kmod" -static noreturn int testsuite_uname(void) +static int testsuite_uname(void) { struct utsname u; int err = uname(&u); if (err < 0) - exit(EXIT_FAILURE); + return EXIT_FAILURE; if (!streq(u.release, TEST_UNAME)) { const char *ldpreload = getenv("LD_PRELOAD"); ERR("u.release=%s should be %s\n", u.release, TEST_UNAME); ERR("LD_PRELOAD=%s\n", ldpreload); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } DEFINE_TEST(testsuite_uname, .description = "test if trap to uname() works", .config = { diff --git a/testsuite/test-weakdep.c b/testsuite/test-weakdep.c index 26a9624b..a98df8e0 100644 --- a/testsuite/test-weakdep.c +++ b/testsuite/test-weakdep.c @@ -25,7 +25,7 @@ static int test_weakdep(void) ctx = kmod_new(NULL, NULL); if (ctx == NULL) - exit(EXIT_FAILURE); + return EXIT_FAILURE; for (size_t i = 0; i < ARRAY_SIZE(mod_name); i++) { struct kmod_list *list = NULL; @@ -38,7 +38,7 @@ static int test_weakdep(void) if (list == NULL || err < 0) { fprintf(stderr, "module %s not found in directory %s\n", mod_name[i], ctx ? kmod_get_dirname(ctx) : "(missing)"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } mod = kmod_module_get_module(list); @@ -47,7 +47,7 @@ static int test_weakdep(void) if (err) { fprintf(stderr, "weak dependencies can not be read for %s (%d)\n", mod_name[i], err); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } kmod_list_foreach(itr, mod_list) {