]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: static const annotate the remaining test data
authorEmil Velikov <emil.l.velikov@gmail.com>
Fri, 13 Jun 2025 18:44:25 +0000 (19:44 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Mon, 16 Jun 2025 12:37:42 +0000 (07:37 -0500)
A while ago we annotated a bunch of of the tests although I missed some
during grepping. Update the final instances, taking the chance to move
the strdup instances into the test loop and failing the test should the
duplication fails.

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-hash.c
testsuite/test-list.c
testsuite/test-util.c

index 77241d473b0b8d696be6ab586936c5baa33bc4de..0f7baab96a76347c023f064fd3cb0ab87874a37c 100644 (file)
@@ -30,7 +30,7 @@ static int blacklist_1(void)
        int err;
        size_t len = 0;
 
-       const char *names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL };
+       static const char *const names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL};
        const char **name;
 
        ctx = kmod_new(NULL, NULL);
index e3d6d85efd1c630f9753d95298856a38b4034f79..810e7d2c8435428f20aa7bbbb41bf6663f5ed3cb 100644 (file)
@@ -229,8 +229,8 @@ DEFINE_TEST(test_hash_free,
 
 static int test_hash_add_unique(void)
 {
-       const char *k[] = { "k1", "k2", "k3", "k4", "k5" };
-       const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
+       static const char *const k[] = { "k1", "k2", "k3", "k4", "k5" };
+       static const char *const v[] = { "v1", "v2", "v3", "v4", "v5" };
        unsigned int i, j, N;
 
        N = ARRAY_SIZE(k);
index 19518a4d85357b888f27e405091459adc3367ab4..70f92545cf6a7611c5f3004405fd6c2e7485229b 100644 (file)
@@ -31,7 +31,7 @@ static int test_list_last(void)
 {
        struct kmod_list *list = NULL, *last;
        int i;
-       const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
+       static const char *const v[] = { "v1", "v2", "v3", "v4", "v5" };
        const int N = ARRAY_SIZE(v);
 
        for (i = 0; i < N; i++)
@@ -51,7 +51,7 @@ static int test_list_prev(void)
 {
        struct kmod_list *list = NULL, *l, *p;
        int i;
-       const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
+       static const char *const v[] = { "v1", "v2", "v3", "v4", "v5" };
        const int N = ARRAY_SIZE(v);
 
        l = kmod_list_prev(list, list);
@@ -80,7 +80,8 @@ static int test_list_remove_data(void)
 {
        struct kmod_list *list = NULL, *l;
        int i;
-       const char *v[] = { "v1", "v2", "v3", "v4", "v5" }, *removed;
+       static const char *const v[] = { "v1", "v2", "v3", "v4", "v5" };
+       const char *removed;
        const int N = ARRAY_SIZE(v);
 
        for (i = 0; i < N; i++)
@@ -104,7 +105,7 @@ static int test_list_append_list(void)
 {
        struct kmod_list *a = NULL, *b = NULL, *c, *l;
        int i;
-       const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
+       static const char *const v[] = { "v1", "v2", "v3", "v4", "v5" };
        const int N = ARRAY_SIZE(v), M = N / 2;
 
        for (i = 0; i < M; i++)
index 7f71ef2ab7d39029e594b35fdf48d0cd6b6242c6..aa47040045d60ec2ffb8cafaf9bd803837de5d02 100644 (file)
@@ -104,23 +104,25 @@ DEFINE_TEST(test_strchr_replace,
 
 static int test_underscores(void)
 {
-       struct teststr {
-               char *val;
+       static const struct teststr {
+               const char *val;
                const char *res;
        } teststr[] = {
-               { strdup("aa-bb-cc_"), "aa_bb_cc_" },
-               { strdup("-aa-bb-cc-"), "_aa_bb_cc_" },
-               { strdup("-aa[-bb-]cc-"), "_aa[-bb-]cc_" },
-               { strdup("-aa-[bb]-cc-"), "_aa_[bb]_cc_" },
-               { strdup("-aa-[b-b]-cc-"), "_aa_[b-b]_cc_" },
-               { strdup("-aa-b[-]b-cc"), "_aa_b[-]b_cc" },
-               { },
-       }, *iter;
+               // clang-format off
+               { "aa-bb-cc_", "aa_bb_cc_" },
+               { "-aa-bb-cc-", "_aa_bb_cc_" },
+               { "-aa[-bb-]cc-", "_aa[-bb-]cc_" },
+               { "-aa-[bb]-cc-", "_aa_[bb]_cc_" },
+               { "-aa-[b-b]-cc-", "_aa_[b-b]_cc_" },
+               { "-aa-b[-]b-cc", "_aa_b[-]b_cc" },
+               // clang-format on
+       };
 
-       for (iter = &teststr[0]; iter->val != NULL; iter++) {
-               _cleanup_free_ char *val = iter->val;
+       for (size_t i = 0; i < ARRAY_SIZE(teststr); i++) {
+               _cleanup_free_ char *val = strdup(teststr[i].val);
+               assert_return(val != NULL, EXIT_FAILURE);
                assert_return(!underscores(val), EXIT_FAILURE);
-               assert_return(streq(val, iter->res), EXIT_FAILURE);
+               assert_return(streq(val, teststr[i].res), EXIT_FAILURE);
        }
 
        return EXIT_SUCCESS;
@@ -129,7 +131,7 @@ DEFINE_TEST(test_underscores, .description = "check implementation of underscore
 
 static int test_path_ends_with_kmod_ext(void)
 {
-       struct teststr {
+       static const struct teststr {
                const char *val;
                bool res;
        } teststr[] = {