]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: remove remaining exit/noreturn instances
authorEmil Velikov <emil.l.velikov@gmail.com>
Fri, 13 Jun 2025 16:37:25 +0000 (17:37 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Mon, 16 Jun 2025 12:37:42 +0000 (07:37 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/371
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
testsuite/test-blacklist.c
testsuite/test-dependencies.c
testsuite/test-init.c
testsuite/test-initstate.c
testsuite/test-loaded.c
testsuite/test-multi-softdep.c
testsuite/test-new-module.c
testsuite/test-remove.c
testsuite/test-testsuite.c
testsuite/test-weakdep.c

index 883e0e9d7a634bee8bf9e733e203828318dd8535..83e4e266a1967f9da7740d2bb475edd12938e2aa 100644 (file)
@@ -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);
index 4d853b796c4c2171522ff456a04323f432a2758f..24b241824f2bb0e4efd44347311d25d724c91f17 100644 (file)
@@ -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",
index a1523dbe087e4300d3927bbdfbb2f908e0c31136..fb4cdce41a2782c9a94b54b501a167297e4c7a8d 100644 (file)
@@ -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",
index 115c7779d5cd9c3c04f03153eed19ea1d7581fcc..0d46ac022bfdf823a001036c2cebb979840748ea 100644 (file)
@@ -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 =
index b8375cf4b7866249a907ddfdc311de7807f8734c..fdfb280e4e8df2be8b326272ec31218be3bafce6 100644 (file)
@@ -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");
index e53a65b9aedb53005a52fce94d385a526a430607..74226a4adefb575b9af5f7a45a3fd6c3a1c54486 100644 (file)
@@ -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;
index 238908d417d2b872795e7b5979287bdd3296651d..c4968b2f8ebadd1602f6e338651c9b2bc9000d3a 100644 (file)
@@ -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;
index ed5cc31e0ef019ed83ba936bc8efe07758e7fd45..f4f6975697e7777a8255134abb844dcdca50bf66 100644 (file)
@@ -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",
index 647dc1e4df0897ae494a00647b8cd9a3d7a8fae2..43c946f9d827d35e093fe67ea930e7e5e7c57ca0 100644 (file)
 #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 = {
index 26a9624b35c31ab1e31dfd4c7e42bc7f5eea7a7a..a98df8e0154067171850754cdc873c9a38a5da87 100644 (file)
@@ -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) {