]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: mass convert with clang-format
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 11 Sep 2024 16:30:32 +0000 (17:30 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 24 Sep 2024 14:59:20 +0000 (09:59 -0500)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/118
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
20 files changed:
testsuite/delete_module.c
testsuite/init_module.c
testsuite/path.c
testsuite/stripped-module.h
testsuite/test-array.c
testsuite/test-blacklist.c
testsuite/test-depmod.c
testsuite/test-hash.c
testsuite/test-init.c
testsuite/test-initstate.c
testsuite/test-list.c
testsuite/test-modinfo.c
testsuite/test-modprobe.c
testsuite/test-scratchbuf.c
testsuite/test-strbuf.c
testsuite/test-testsuite.c
testsuite/test-util.c
testsuite/testsuite.c
testsuite/testsuite.h
testsuite/uname.c

index 8df93a162add37c214965eb9be1df3c19d859aff..25bfc1dc091559dd6c81f1680c62ed69c95a9536 100644 (file)
@@ -63,7 +63,7 @@ static void parse_retcodes(struct mod **_modules, const char *s)
                if (end == p || *end != ':')
                        break;
 
-               ret = (int) l;
+               ret = (int)l;
                p = end + 1;
 
                l = strtol(p, &end, 0);
@@ -72,7 +72,7 @@ static void parse_retcodes(struct mod **_modules, const char *s)
                else if (*end != '\0')
                        break;
 
-               errcode = (int) l;
+               errcode = (int)l;
 
                mod = malloc(sizeof(*mod) + modnamelen + 1);
                if (mod == NULL)
@@ -111,15 +111,14 @@ static void init_retcodes(void)
        s = getenv(S_TC_DELETE_MODULE_RETCODES);
        if (s == NULL) {
                ERR("TRAP delete_module(): missing export %s?\n",
-                                               S_TC_DELETE_MODULE_RETCODES);
+                   S_TC_DELETE_MODULE_RETCODES);
        }
 
        parse_retcodes(&modules, s);
 
        for (mod = modules; mod != NULL; mod = mod->next) {
                LOG("Added module to test delete_module:\n");
-               LOG("\tname=%s ret=%d errcode=%d\n",
-                   mod->name, mod->ret, mod->errcode);
+               LOG("\tname=%s ret=%d errcode=%d\n", mod->name, mod->ret, mod->errcode);
        }
 }
 
index b6ac1c2d1b4f266f367987f72e6cb7a2044fbff3..d1857b823b0c895bccb1201fd39566b08538aa54 100644 (file)
@@ -78,7 +78,7 @@ static void parse_retcodes(struct mod **_modules, const char *s)
                l = strtol(p, &end, 0);
                if (end == p || *end != ':')
                        break;
-               ret = (int) l;
+               ret = (int)l;
                p = end + 1;
 
                l = strtol(p, &end, 0);
@@ -87,7 +87,7 @@ static void parse_retcodes(struct mod **_modules, const char *s)
                else if (*end != '\0')
                        break;
 
-               errcode = (int) l;
+               errcode = (int)l;
 
                mod = malloc(sizeof(*mod) + modnamelen + 1);
                if (mod == NULL)
@@ -104,35 +104,35 @@ static void parse_retcodes(struct mod **_modules, const char *s)
 
 static int write_one_line_file(const char *fn, const char *line, int len)
 {
-        FILE *f;
-        int r;
+       FILE *f;
+       int r;
 
-        assert(fn);
-        assert(line);
+       assert(fn);
+       assert(line);
 
-        f = fopen(fn, "we");
-        if (!f)
-                return -errno;
+       f = fopen(fn, "we");
+       if (!f)
+               return -errno;
 
-        errno = 0;
-        if (fputs(line, f) < 0) {
-                r = -errno;
-                goto finish;
-        }
+       errno = 0;
+       if (fputs(line, f) < 0) {
+               r = -errno;
+               goto finish;
+       }
 
-        fflush(f);
+       fflush(f);
 
-        if (ferror(f)) {
-                if (errno != 0)
-                        r = -errno;
-                else
-                        r = -EIO;
-        } else
-                r = 0;
+       if (ferror(f)) {
+               if (errno != 0)
+                       r = -errno;
+               else
+                       r = -EIO;
+       } else
+               r = 0;
 
 finish:
-        fclose(f);
-        return r;
+       fclose(f);
+       return r;
 }
 
 static int create_sysfs_files(const char *modname)
@@ -174,7 +174,7 @@ static void init_retcodes(void)
        s = getenv(S_TC_INIT_MODULE_RETCODES);
        if (s == NULL) {
                fprintf(stderr, "TRAP init_module(): missing export %s?\n",
-                                               S_TC_INIT_MODULE_RETCODES);
+                       S_TC_INIT_MODULE_RETCODES);
        }
 
        ctx = kmod_new(NULL, NULL);
@@ -193,8 +193,7 @@ static inline bool module_is_inkernel(const char *modname)
 
        state = kmod_module_get_initstate(mod);
 
-       if (state == KMOD_MODULE_LIVE ||
-                       state == KMOD_MODULE_BUILTIN)
+       if (state == KMOD_MODULE_LIVE || state == KMOD_MODULE_BUILTIN)
                ret = true;
        else
                ret = false;
@@ -238,8 +237,7 @@ long init_module(void *mem, unsigned long len, const char *args)
        if (elf == NULL)
                return 0;
 
-       err = kmod_elf_get_section(elf, ".gnu.linkonce.this_module", &buf,
-                                                               &bufsize);
+       err = kmod_elf_get_section(elf, ".gnu.linkonce.this_module", &buf, &bufsize);
        kmod_elf_unref(elf);
 
        /* We couldn't parse the ELF file. Just exit as if it was successful */
@@ -288,7 +286,6 @@ static int check_kernel_version(int major, int minor)
        return false;
 }
 
-
 TS_EXPORT int finit_module(const int fd, const char *args, const int flags);
 
 int finit_module(const int fd, const char *args, const int flags)
@@ -355,7 +352,8 @@ TS_EXPORT long int syscall(long int __sysno, ...)
 #endif
                        nextlib_syscall = dlsym(nextlib, "syscall");
                        if (nextlib_syscall == NULL) {
-                               fprintf(stderr, "FIXME FIXME FIXME: could not load syscall symbol: %s\n",
+                               fprintf(stderr,
+                                       "FIXME FIXME FIXME: could not load syscall symbol: %s\n",
                                        dlerror());
                                abort();
                        }
@@ -370,7 +368,8 @@ TS_EXPORT long int syscall(long int __sysno, ...)
         * this may fail if a library or process is trying to call syscall()
         * directly, for example to implement gettid().
         */
-       fprintf(stderr, "FIXME FIXME FIXME: could not wrap call to syscall(%ld), this should not happen\n",
+       fprintf(stderr,
+               "FIXME FIXME FIXME: could not wrap call to syscall(%ld), this should not happen\n",
                __sysno);
 
        abort();
index 9b1f97a945cd326f4c086f7f3bf3f5ca03116697..aba9cf8840e4b3ff5da87323778e4aa2b5da4673 100644 (file)
@@ -32,8 +32,8 @@ static size_t rootpathlen;
 
 static inline bool need_trap(const char *path)
 {
-       return path != NULL && path[0] == '/'
-               && !strnstartswith(path, rootpath, rootpathlen);
+       return path != NULL && path[0] == '/' &&
+              !strnstartswith(path, rootpath, rootpathlen);
 }
 
 static const char *trap_path(const char *path, char buf[PATH_MAX * 2])
@@ -91,105 +91,103 @@ static void *get_libc_func(const char *f)
 }
 
 /* wrapper template for a function with one "const char* path" argument */
-#define WRAP_1ARG(rettype, failret, name) \
-TS_EXPORT rettype name(const char *path) \
-{ \
-       const char *p;                          \
-       char buf[PATH_MAX * 2];                 \
-       static rettype (*_fn)(const char*);     \
-                                               \
-       if (!get_rootpath(__func__))            \
-               return failret;                 \
-       _fn = get_libc_func(#name);             \
-       p = trap_path(path, buf);               \
-       if (p == NULL)                          \
-               return failret;                 \
-       return (*_fn)(p);                       \
-}
+#define WRAP_1ARG(rettype, failret, name)            \
+       TS_EXPORT rettype name(const char *path)     \
+       {                                            \
+               const char *p;                       \
+               char buf[PATH_MAX * 2];              \
+               static rettype (*_fn)(const char *); \
+                                                     \
+               if (!get_rootpath(__func__))         \
+                       return failret;              \
+               _fn = get_libc_func(#name);          \
+               p = trap_path(path, buf);            \
+               if (p == NULL)                       \
+                       return failret;              \
+               return (*_fn)(p);                    \
+       }
 
 /* wrapper template for a function with "const char* path" and another argument */
-#define WRAP_2ARGS(rettype, failret, name, arg2t)      \
-TS_EXPORT rettype name(const char *path, arg2t arg2)   \
-{ \
-       const char *p;                                  \
-       char buf[PATH_MAX * 2];                         \
-       static rettype (*_fn)(const char*, arg2t arg2); \
-                                                       \
-       if (!get_rootpath(__func__))                    \
-               return failret;                         \
-       _fn = get_libc_func(#name);                     \
-       p = trap_path(path, buf);                       \
-       if (p == NULL)                                  \
-               return failret;                         \
-       return (*_fn)(p, arg2);                         \
-}
+#define WRAP_2ARGS(rettype, failret, name, arg2t)                \
+       TS_EXPORT rettype name(const char *path, arg2t arg2)     \
+       {                                                        \
+               const char *p;                                   \
+               char buf[PATH_MAX * 2];                          \
+               static rettype (*_fn)(const char *, arg2t arg2); \
+                                                                 \
+               if (!get_rootpath(__func__))                     \
+                       return failret;                          \
+               _fn = get_libc_func(#name);                      \
+               p = trap_path(path, buf);                        \
+               if (p == NULL)                                   \
+                       return failret;                          \
+               return (*_fn)(p, arg2);                          \
+       }
 
 /* wrapper template for open family */
-#define WRAP_OPEN(suffix)                                      \
-TS_EXPORT int open ## suffix (const char *path, int flags, ...)        \
-{ \
-       const char *p;                                          \
-       char buf[PATH_MAX * 2];                                 \
-       static int (*_fn)(const char *path, int flags, ...);    \
-                                                               \
-       if (!get_rootpath(__func__))                            \
-               return -1;                                      \
-       _fn = get_libc_func("open" #suffix);                    \
-       p = trap_path(path, buf);                               \
-       if (p == NULL)                                          \
-               return -1;                                      \
-                                                               \
-       if (flags & O_CREAT) {                                  \
-               mode_t mode;                                    \
-               va_list ap;                                     \
-                                                               \
-               va_start(ap, flags);                            \
-               mode = va_arg(ap, mode_t);                      \
-               va_end(ap);                                     \
-               return _fn(p, flags, mode);                     \
-       }                                                       \
-                                                               \
-       return _fn(p, flags);                                   \
-}
+#define WRAP_OPEN(suffix)                                            \
+       TS_EXPORT int open##suffix(const char *path, int flags, ...) \
+       {                                                            \
+               const char *p;                                       \
+               char buf[PATH_MAX * 2];                              \
+               static int (*_fn)(const char *path, int flags, ...); \
+                                                                     \
+               if (!get_rootpath(__func__))                         \
+                       return -1;                                   \
+               _fn = get_libc_func("open" #suffix);                 \
+               p = trap_path(path, buf);                            \
+               if (p == NULL)                                       \
+                       return -1;                                   \
+                                                                     \
+               if (flags & O_CREAT) {                               \
+                       mode_t mode;                                 \
+                       va_list ap;                                  \
+                                                                     \
+                       va_start(ap, flags);                         \
+                       mode = va_arg(ap, mode_t);                   \
+                       va_end(ap);                                  \
+                       return _fn(p, flags, mode);                  \
+               }                                                    \
+                                                                     \
+               return _fn(p, flags);                                \
+       }
 
-#define WRAP_VERSTAT(prefix, suffix)                       \
-TS_EXPORT int prefix ## stat ## suffix (int ver,           \
-                             const char *path,             \
-                             struct stat ## suffix *st)    \
-{ \
-       const char *p;                                      \
-       char buf[PATH_MAX * 2];                             \
-       static int (*_fn)(int ver, const char *path,        \
-                         struct stat ## suffix *);         \
-       _fn = get_libc_func(#prefix "stat" #suffix);        \
-                                                           \
-       if (!get_rootpath(__func__))                        \
-               return -1;                                  \
-       p = trap_path(path, buf);                           \
-       if (p == NULL)                                      \
-               return -1;                                  \
-                                                           \
-       return _fn(ver, p, st);                             \
-}
+#define WRAP_VERSTAT(prefix, suffix)                                                 \
+       TS_EXPORT int prefix##stat##suffix(int ver, const char *path,                \
+                                          struct stat##suffix *st)                  \
+       {                                                                            \
+               const char *p;                                                       \
+               char buf[PATH_MAX * 2];                                              \
+               static int (*_fn)(int ver, const char *path, struct stat##suffix *); \
+               _fn = get_libc_func(#prefix "stat" #suffix);                         \
+                                                                                     \
+               if (!get_rootpath(__func__))                                         \
+                       return -1;                                                   \
+               p = trap_path(path, buf);                                            \
+               if (p == NULL)                                                       \
+                       return -1;                                                   \
+                                                                                     \
+               return _fn(ver, p, st);                                              \
+       }
 
-WRAP_1ARG(DIR*, NULL, opendir);
+WRAP_1ARG(DIR *, NULL, opendir);
 WRAP_1ARG(int, -1, chdir);
 
-WRAP_2ARGS(FILE*, NULL, fopen, const char*);
+WRAP_2ARGS(FILE *, NULL, fopen, const char *);
 WRAP_2ARGS(int, -1, mkdir, mode_t);
-WRAP_2ARGS(int, -1, stat, struct stat*);
+WRAP_2ARGS(int, -1, stat, struct stat *);
 
 WRAP_OPEN();
 
 #ifdef HAVE_FOPEN64
-WRAP_2ARGS(FILE*, NULL, fopen64, const char*);
+WRAP_2ARGS(FILE *, NULL, fopen64, const char *);
 #endif
 #ifdef HAVE_STAT64
-WRAP_2ARGS(int, -1, stat64, struct stat64*);
+WRAP_2ARGS(int, -1, stat64, struct stat64 *);
 #endif
 
 #ifdef HAVE___STAT64_TIME64
-extern int __stat64_time64 (const char *file, void *buf);
+extern int __stat64_time64(const char *file, void *buf);
 WRAP_2ARGS(int, -1, __stat64_time64, void *);
 #endif
 
@@ -198,6 +196,6 @@ WRAP_OPEN(64);
 #endif
 
 #if HAVE_DECL___XSTAT
-WRAP_VERSTAT(__x,);
-WRAP_VERSTAT(__x,64);
+WRAP_VERSTAT(__x, );
+WRAP_VERSTAT(__x, 64);
 #endif
index 83986b2c44b373fdda71d76f93d8ae407352ac2f..aeb24de449d2f0e105295563b9633a7f75efc09b 100644 (file)
@@ -1,7 +1,6 @@
 #pragma once
 
-enum module_state
-{
+enum module_state {
        MODULE_STATE_LIVE,
        MODULE_STATE_COMING,
        MODULE_STATE_GOING,
@@ -13,8 +12,7 @@ struct list_head {
 
 #define MODULE_NAME_LEN (64 - sizeof(unsigned long))
 
-struct module
-{
+struct module {
        enum module_state state;
 
        /* Member of list of modules */
@@ -25,5 +23,5 @@ struct module
 };
 
 /*                                padding */
-#define MODULE_NAME_OFFSET_64 4 + 4           + 2 * 8
+#define MODULE_NAME_OFFSET_64 4 + 4 + 2 * 8
 #define MODULE_NAME_OFFSET_32 4 + 2 * 4
index 838dcec9c70bab6adb615fbf8fc083cba492cd10..913826407c24d6e1938eebf3dade56c7bdf4df40 100644 (file)
@@ -27,9 +27,7 @@ static int test_array_append1(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_array_append1,
-               .description = "test simple array append");
-
+DEFINE_TEST(test_array_append1, .description = "test simple array append");
 
 static int test_array_append2(const struct test *t)
 {
@@ -50,8 +48,7 @@ static int test_array_append2(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_array_append2,
-               .description = "test array append over step");
+DEFINE_TEST(test_array_append2, .description = "test array append over step");
 
 static int test_array_append_unique(const struct test *t)
 {
@@ -75,10 +72,10 @@ static int test_array_append_unique(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_array_append_unique,
-               .description = "test array append unique");
+DEFINE_TEST(test_array_append_unique, .description = "test array append unique");
 
-static int strptrcmp(const void *pa, const void *pb) {
+static int strptrcmp(const void *pa, const void *pb)
+{
        const char *a = *(const char **)pa;
        const char *b = *(const char **)pb;
 
@@ -111,8 +108,7 @@ static int test_array_sort(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_array_sort,
-               .description = "test array sort");
+DEFINE_TEST(test_array_sort, .description = "test array sort");
 
 static int test_array_remove_at(const struct test *t)
 {
@@ -155,8 +151,7 @@ static int test_array_remove_at(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_array_remove_at,
-               .description = "test array remove at");
+DEFINE_TEST(test_array_remove_at, .description = "test array remove at");
 
 static int test_array_pop(const struct test *t)
 {
@@ -170,7 +165,6 @@ static int test_array_pop(const struct test *t)
        array_append(&array, c2);
        array_append(&array, c3);
 
-
        array_pop(&array);
 
        assert_return(array.count == 2, EXIT_FAILURE);
@@ -191,7 +185,6 @@ static int test_array_pop(const struct test *t)
        return 0;
 }
 
-DEFINE_TEST(test_array_pop,
-               .description = "test array pop");
+DEFINE_TEST(test_array_pop, .description = "test array pop");
 
 TESTSUITE_MAIN();
index 3fb6d3b1b9096cb1f2755c9b4139cbbde68174d4..4c741d3c93abe284cf54edd7de592b05f85afd44 100644 (file)
@@ -38,15 +38,14 @@ static int blacklist_1(const struct test *t)
        if (ctx == NULL)
                exit(EXIT_FAILURE);
 
-       for(name = names; *name; name++) {
+       for (name = names; *name; name++) {
                err = kmod_module_new_from_name(ctx, *name, &mod);
                if (err < 0)
                        goto fail_lookup;
                list = kmod_list_append(list, mod);
        }
 
-       err = kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, list,
-                                                               &filtered);
+       err = kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, list, &filtered);
        if (err < 0) {
                ERR("Could not filter: %s\n", strerror(-err));
                goto fail;
index 36729673aaf2c10e26ab52550558ded252e9af67..569a5e3adeae4fd5a142229a34095545eae3d4d0 100644 (file)
@@ -43,8 +43,10 @@ DEFINE_TEST(depmod_modules_order_for_compressed,
        });
 
 #define MODULES_OUTDIR_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-outdir"
-#define MODULES_OUTDIR_LIB_MODULES_OUTPUT MODULES_OUTDIR_ROOTFS "/outdir" MODULE_DIRECTORY "/" MODULES_UNAME
-#define MODULES_OUTDIR_LIB_MODULES_INPUT MODULES_OUTDIR_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
+#define MODULES_OUTDIR_LIB_MODULES_OUTPUT \
+       MODULES_OUTDIR_ROOTFS "/outdir" MODULE_DIRECTORY "/" MODULES_UNAME
+#define MODULES_OUTDIR_LIB_MODULES_INPUT \
+       MODULES_OUTDIR_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
 static noreturn int depmod_modules_outdir(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
@@ -77,7 +79,8 @@ DEFINE_TEST(depmod_modules_outdir,
        });
 
 #define SEARCH_ORDER_SIMPLE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-simple"
-#define SEARCH_ORDER_SIMPLE_LIB_MODULES SEARCH_ORDER_SIMPLE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
+#define SEARCH_ORDER_SIMPLE_LIB_MODULES \
+       SEARCH_ORDER_SIMPLE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
 static noreturn int depmod_search_order_simple(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
@@ -103,10 +106,10 @@ DEFINE_TEST(depmod_search_order_simple,
                },
        });
 
-
 #define ANOTHER_MODDIR "/foobar"
 #define MODULES_ANOTHER_MODDIR_ROOTFS TESTSUITE_ROOTFS "test-depmod/another-moddir"
-#define MODULES_ANOTHER_MODDIR_LIB_MODULES MODULES_ANOTHER_MODDIR_ROOTFS ANOTHER_MODDIR "/" MODULES_UNAME
+#define MODULES_ANOTHER_MODDIR_LIB_MODULES \
+       MODULES_ANOTHER_MODDIR_ROOTFS ANOTHER_MODDIR "/" MODULES_UNAME
 static noreturn int depmod_another_moddir(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
@@ -134,8 +137,10 @@ DEFINE_TEST(depmod_another_moddir,
                },
        });
 
-#define SEARCH_ORDER_SAME_PREFIX_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-same-prefix"
-#define SEARCH_ORDER_SAME_PREFIX_LIB_MODULES SEARCH_ORDER_SAME_PREFIX_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
+#define SEARCH_ORDER_SAME_PREFIX_ROOTFS \
+       TESTSUITE_ROOTFS "test-depmod/search-order-same-prefix"
+#define SEARCH_ORDER_SAME_PREFIX_LIB_MODULES \
+       SEARCH_ORDER_SAME_PREFIX_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
 static noreturn int depmod_search_order_same_prefix(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
@@ -184,8 +189,10 @@ DEFINE_TEST(depmod_detect_loop,
                .err = DETECT_LOOP_ROOTFS "/correct.txt",
        });
 
-#define SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-external-first"
-#define SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
+#define SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS \
+       TESTSUITE_ROOTFS "test-depmod/search-order-external-first"
+#define SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES \
+       SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
 static noreturn int depmod_search_order_external_first(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
@@ -211,8 +218,10 @@ DEFINE_TEST(depmod_search_order_external_first,
                },
        });
 
-#define SEARCH_ORDER_EXTERNAL_LAST_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-external-last"
-#define SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES SEARCH_ORDER_EXTERNAL_LAST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
+#define SEARCH_ORDER_EXTERNAL_LAST_ROOTFS \
+       TESTSUITE_ROOTFS "test-depmod/search-order-external-last"
+#define SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES \
+       SEARCH_ORDER_EXTERNAL_LAST_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
 static noreturn int depmod_search_order_external_last(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
@@ -239,7 +248,8 @@ DEFINE_TEST(depmod_search_order_external_last,
        });
 
 #define SEARCH_ORDER_OVERRIDE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-override"
-#define SEARCH_ORDER_OVERRIDE_LIB_MODULES SEARCH_ORDER_OVERRIDE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
+#define SEARCH_ORDER_OVERRIDE_LIB_MODULES \
+       SEARCH_ORDER_OVERRIDE_ROOTFS MODULE_DIRECTORY "/" MODULES_UNAME
 static noreturn int depmod_search_order_override(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/depmod";
index 193210230c781446cda36276057ae505cb29c027..cfe5a8e4bc3e8c4f334d83346790bc03f3fe100d 100644 (file)
@@ -29,9 +29,7 @@ static int test_hash_new(const struct test *t)
        hash_free(h);
        return 0;
 }
-DEFINE_TEST(test_hash_new,
-               .description = "test hash_new");
-
+DEFINE_TEST(test_hash_new, .description = "test hash_new");
 
 static int test_hash_get_count(const struct test *t)
 {
@@ -48,9 +46,7 @@ static int test_hash_get_count(const struct test *t)
        hash_free(h);
        return 0;
 }
-DEFINE_TEST(test_hash_get_count,
-               .description = "test hash_add / hash_get_count");
-
+DEFINE_TEST(test_hash_get_count, .description = "test hash_add / hash_get_count");
 
 static int test_hash_replace(const struct test *t)
 {
@@ -78,9 +74,7 @@ static int test_hash_replace(const struct test *t)
        hash_free(h);
        return 0;
 }
-DEFINE_TEST(test_hash_replace,
-               .description = "test hash_add replacing existing value");
-
+DEFINE_TEST(test_hash_replace, .description = "test hash_add replacing existing value");
 
 static int test_hash_replace_failing(const struct test *t)
 {
@@ -110,8 +104,7 @@ static int test_hash_replace_failing(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_hash_replace_failing,
-               .description = "test hash_add_unique failing to replace existing value");
-
+           .description = "test hash_add_unique failing to replace existing value");
 
 static int test_hash_iter(const struct test *t)
 {
@@ -129,8 +122,7 @@ static int test_hash_iter(const struct test *t)
        hash_add(h, k3, v3);
        hash_add(h2, k3, v3);
 
-       for (hash_iter_init(h, &iter);
-            hash_iter_next(&iter, &k, (const void **) &v);) {
+       for (hash_iter_init(h, &iter); hash_iter_next(&iter, &k, (const void **)&v);) {
                v2 = hash_find(h2, k);
                assert_return(v2 != NULL, EXIT_FAILURE);
                hash_del(h2, k);
@@ -143,9 +135,7 @@ static int test_hash_iter(const struct test *t)
        hash_free(h2);
        return 0;
 }
-DEFINE_TEST(test_hash_iter,
-               .description = "test hash_iter");
-
+DEFINE_TEST(test_hash_iter, .description = "test hash_iter");
 
 static int test_hash_iter_after_del(const struct test *t)
 {
@@ -165,8 +155,7 @@ static int test_hash_iter_after_del(const struct test *t)
 
        hash_del(h, k1);
 
-       for (hash_iter_init(h, &iter);
-            hash_iter_next(&iter, &k, (const void **) &v);) {
+       for (hash_iter_init(h, &iter); hash_iter_next(&iter, &k, (const void **)&v);) {
                v2 = hash_find(h2, k);
                assert_return(v2 != NULL, EXIT_FAILURE);
                hash_del(h2, k);
@@ -180,8 +169,7 @@ static int test_hash_iter_after_del(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_hash_iter_after_del,
-               .description = "test hash_iter, after deleting element");
-
+           .description = "test hash_iter, after deleting element");
 
 static int test_hash_free(const struct test *t)
 {
@@ -206,8 +194,7 @@ static int test_hash_free(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_hash_free,
-               .description = "test hash_free calling free function for all values");
-
+           .description = "test hash_free calling free function for all values");
 
 static int test_hash_add_unique(const struct test *t)
 {
@@ -232,8 +219,7 @@ static int test_hash_add_unique(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_hash_add_unique,
-               .description = "test hash_add_unique with different key orders")
-
+           .description = "test hash_add_unique with different key orders")
 
 static int test_hash_massive_add_del(const struct test *t)
 {
@@ -265,6 +251,6 @@ static int test_hash_massive_add_del(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_hash_massive_add_del,
-               .description = "test multiple adds followed by multiple dels")
+           .description = "test multiple adds followed by multiple dels")
 
 TESTSUITE_MAIN();
index 11fd8b8b468b8754f2c5b8b3c7a7a9b693092cb8..2c825dfb5bb2e5fd7f35c3fd3787927553ee43f4 100644 (file)
@@ -68,8 +68,7 @@ static noreturn int test_initlib(const struct test *t)
 
        exit(EXIT_SUCCESS);
 }
-DEFINE_TEST(test_initlib,
-               .description = "test if libkmod's init function work");
+DEFINE_TEST(test_initlib, .description = "test if libkmod's init function work");
 
 static noreturn int test_insert(const struct test *t)
 {
index 455dbee91141e64877d1472f63eb6ba179037c44..f29aced1b16b4ba80c2d684c15e33a9da750e379 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "testsuite.h"
 
-
 static noreturn int test_initstate_from_lookup(const struct test *t)
 {
        struct kmod_ctx *ctx;
@@ -108,7 +107,4 @@ DEFINE_TEST(test_initstate_from_name,
        },
        .need_spawn = true);
 
-
-
-
 TESTSUITE_MAIN();
index 143379bea330f631e492fc5c815f779d803d1522..0fcbc805ec383e250e84aa2b67e98d8117107324 100644 (file)
@@ -45,9 +45,7 @@ static int test_list_last(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_list_last,
-           .description = "test for the last element of a list");
-
+DEFINE_TEST(test_list_last, .description = "test for the last element of a list");
 
 static int test_list_prev(const struct test *t)
 {
@@ -76,9 +74,7 @@ static int test_list_prev(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_list_prev,
-           .description = "test list prev");
-
+DEFINE_TEST(test_list_prev, .description = "test list prev");
 
 static int test_list_remove_n_latest(const struct test *t)
 {
@@ -95,7 +91,7 @@ static int test_list_remove_n_latest(const struct test *t)
        assert_return(len(list) == N - M, EXIT_FAILURE);
 
        i = 0;
-       kmod_list_foreach (l, list) {
+       kmod_list_foreach(l, list) {
                assert_return(l->data == v[i], EXIT_FAILURE);
                i++;
        }
@@ -107,7 +103,6 @@ static int test_list_remove_n_latest(const struct test *t)
 DEFINE_TEST(test_list_remove_n_latest,
            .description = "test list function to remove n latest elements");
 
-
 static int test_list_remove_data(const struct test *t)
 {
        struct kmod_list *list = NULL, *l;
@@ -122,7 +117,7 @@ static int test_list_remove_data(const struct test *t)
        list = kmod_list_remove_data(list, removed);
        assert_return(len(list) == N - 1, EXIT_FAILURE);
 
-       kmod_list_foreach (l, list)
+       kmod_list_foreach(l, list)
                assert_return(l->data != removed, EXIT_FAILURE);
 
        kmod_list_remove_all(list);
@@ -132,7 +127,6 @@ static int test_list_remove_data(const struct test *t)
 DEFINE_TEST(test_list_remove_data,
            .description = "test list function to remove element by data");
 
-
 static int test_list_append_list(const struct test *t)
 {
        struct kmod_list *a = NULL, *b = NULL, *c, *l;
@@ -158,7 +152,7 @@ static int test_list_append_list(const struct test *t)
        assert_return(len(c) == N, EXIT_FAILURE);
 
        i = 0;
-       kmod_list_foreach (l, c) {
+       kmod_list_foreach(l, c) {
                assert_return(l->data == v[i], EXIT_FAILURE);
                i++;
        }
@@ -170,7 +164,6 @@ static int test_list_append_list(const struct test *t)
 DEFINE_TEST(test_list_append_list,
            .description = "test list function to append another list");
 
-
 static int test_list_insert_before(const struct test *t)
 {
        struct kmod_list *list = NULL, *l;
@@ -206,7 +199,6 @@ static int test_list_insert_before(const struct test *t)
 DEFINE_TEST(test_list_insert_before,
            .description = "test list function to insert before element");
 
-
 static int test_list_insert_after(const struct test *t)
 {
        struct kmod_list *list = NULL, *l;
index 4d41dc9d137ffb6d89293c86fd27bc099f9db6a8..a8e8e552333363afa7c7f332cdbed5e2566da85a 100644 (file)
 
 static const char *progname = TOOLS_DIR "/modinfo";
 
-#define DEFINE_MODINFO_TEST(_field, _flavor, ...) \
-static noreturn int test_modinfo_##_field(const struct test *t) \
-{ \
-       const char *const args[] = { \
-               progname, "-F", #_field ,\
-               __VA_ARGS__ , \
-               NULL, \
-       }; \
-       test_spawn_prog(progname, args); \
-       exit(EXIT_FAILURE); \
-} \
-DEFINE_TEST(test_modinfo_##_field, \
+#define DEFINE_MODINFO_TEST(_field, _flavor, ...)                       \
+       static noreturn int test_modinfo_##_field(const struct test *t) \
+       {                                                               \
+               const char *const args[] = {                            \
+                       progname, "-F", #_field, __VA_ARGS__, NULL,     \
+               };                                                      \
+               test_spawn_prog(progname, args);                        \
+               exit(EXIT_FAILURE);                                     \
+       }                                                               \
+       DEFINE_TEST(test_modinfo_##_field, \
        .description = "check " #_field " output of modinfo for different architectures", \
        .config = { \
                [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/", \
@@ -37,20 +35,15 @@ DEFINE_TEST(test_modinfo_##_field, \
 
 /* TODO: add cross-compiled modules to the test */
 #define DEFINE_MODINFO_GENERIC_TEST(_field) \
-       DEFINE_MODINFO_TEST(_field, , \
-                           "/mod-simple.ko")
+       DEFINE_MODINFO_TEST(_field, , "/mod-simple.ko")
 
 #ifdef ENABLE_OPENSSL
-#define DEFINE_MODINFO_SIGN_TEST(_field) \
-       DEFINE_MODINFO_TEST(_field, -openssl, \
-                           "/mod-simple-sha1.ko", \
-                           "/mod-simple-sha256.ko",    \
-                           "/mod-simple-pkcs7.ko")
+#define DEFINE_MODINFO_SIGN_TEST(_field)                             \
+       DEFINE_MODINFO_TEST(_field, -openssl, "/mod-simple-sha1.ko", \
+                           "/mod-simple-sha256.ko", "/mod-simple-pkcs7.ko")
 #else
-#define DEFINE_MODINFO_SIGN_TEST(_field) \
-       DEFINE_MODINFO_TEST(_field, , \
-                           "/mod-simple-sha1.ko", \
-                           "/mod-simple-sha256.ko",    \
+#define DEFINE_MODINFO_SIGN_TEST(_field)                                              \
+       DEFINE_MODINFO_TEST(_field, , "/mod-simple-sha1.ko", "/mod-simple-sha256.ko", \
                            "/mod-simple-pkcs7.ko")
 #endif
 
index 414c8cd8653b21335e1a1ae6cf32d4241fcd3fae..cbdd9c753f0902a9b4369131ba3c7247292ef713 100644 (file)
@@ -18,7 +18,8 @@ static noreturn int modprobe_show_depends(const struct test *t)
        const char *progname = TOOLS_DIR "/modprobe";
        const char *const args[] = {
                progname,
-               "--show-depends", "mod-loop-a",
+               "--show-depends",
+               "mod-loop-a",
                NULL,
        };
 
@@ -40,7 +41,8 @@ static noreturn int modprobe_show_depends2(const struct test *t)
        const char *progname = TOOLS_DIR "/modprobe";
        const char *const args[] = {
                progname,
-               "--show-depends", "mod-simple",
+               "--show-depends",
+               "mod-simple",
                NULL,
        };
 
@@ -109,7 +111,6 @@ DEFINE_TEST(modprobe_show_exports,
                .regex = true,
        });
 
-
 static noreturn int modprobe_builtin(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/modprobe";
@@ -122,19 +123,19 @@ static noreturn int modprobe_builtin(const struct test *t)
        test_spawn_prog(progname, args);
        exit(EXIT_FAILURE);
 }
-DEFINE_TEST(modprobe_builtin,
-       .description = "check if modprobe return 0 for builtin",
-       .config = {
-               [TC_UNAME_R] = "4.4.4",
-               [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
-       });
+DEFINE_TEST(modprobe_builtin, .description = "check if modprobe return 0 for builtin",
+           .config = {
+                   [TC_UNAME_R] = "4.4.4",
+                   [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
+           });
 
 static noreturn int modprobe_builtin_lookup_only(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/modprobe";
        const char *const args[] = {
                progname,
-               "-R", "unix",
+               "-R",
+               "unix",
                NULL,
        };
 
@@ -227,7 +228,8 @@ static noreturn int modprobe_param_kcmdline_show_deps(const struct test *t)
        const char *progname = TOOLS_DIR "/modprobe";
        const char *const args[] = {
                progname,
-               "--show-depends", "mod-simple",
+               "--show-depends",
+               "mod-simple",
                NULL,
        };
 
@@ -342,13 +344,13 @@ DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline8, modprobe_param_kcmdline,
        .modules_loaded = "",
        );
 
-
 static noreturn int modprobe_force(const struct test *t)
 {
        const char *progname = TOOLS_DIR "/modprobe";
        const char *const args[] = {
                progname,
-               "--force", "mod-simple",
+               "--force",
+               "mod-simple",
                NULL,
        };
 
@@ -392,7 +394,8 @@ static noreturn int modprobe_oldkernel_force(const struct test *t)
        const char *progname = TOOLS_DIR "/modprobe";
        const char *const args[] = {
                progname,
-               "--force", "mod-simple",
+               "--force",
+               "mod-simple",
                NULL,
        };
 
index 69ad645599753d4fe7f553f99bcade499111ddb7..b5fdd7f4041c346b946ebc44bd9daabcf5733514 100644 (file)
@@ -34,8 +34,7 @@ static int test_scratchbuf_onlystack(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_scratchbuf_onlystack,
-               .description = "test scratchbuf for buffer on stack only");
-
+           .description = "test scratchbuf for buffer on stack only");
 
 static int test_scratchbuf_heap(const struct test *t)
 {
@@ -72,6 +71,6 @@ static int test_scratchbuf_heap(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_scratchbuf_heap,
-               .description = "test scratchbuf for buffer on that grows to heap");
+           .description = "test scratchbuf for buffer on that grows to heap");
 
 TESTSUITE_MAIN();
index 278ac6d03bed05d117a7d922fd3df38dff7e10fc..d4644ca08eeb8bb68cbaa655dad236a38aab30e4 100644 (file)
@@ -29,7 +29,7 @@ static int test_strbuf_pushchar(const struct test *t)
        for (c = TEXT; *c != '\0'; c++)
                strbuf_pushchar(&buf, *c);
 
-       result1 = (char *) strbuf_str(&buf);
+       result1 = (char *)strbuf_str(&buf);
        assert_return(result1 == buf.bytes, EXIT_FAILURE);
        assert_return(streq(result1, TEXT), EXIT_FAILURE);
        result1 = strdup(result1);
@@ -42,8 +42,7 @@ static int test_strbuf_pushchar(const struct test *t)
 
        return 0;
 }
-DEFINE_TEST(test_strbuf_pushchar,
-               .description = "test strbuf_{pushchar, str, steal}");
+DEFINE_TEST(test_strbuf_pushchar, .description = "test strbuf_{pushchar, str, steal}");
 
 static int test_strbuf_pushchars(const struct test *t)
 {
@@ -62,7 +61,7 @@ static int test_strbuf_pushchars(const struct test *t)
        }
 
        strbuf_popchar(&buf);
-       result1 = (char *) strbuf_str(&buf);
+       result1 = (char *)strbuf_str(&buf);
        assert_return(result1 == buf.bytes, EXIT_FAILURE);
        assert_return(streq(result1, TEXT), EXIT_FAILURE);
 
@@ -71,8 +70,7 @@ static int test_strbuf_pushchars(const struct test *t)
        assert_return(!streq(TEXT, result2), EXIT_FAILURE);
        assert_return(strncmp(TEXT, result2, strlen(TEXT) - lastwordlen) == 0,
                      EXIT_FAILURE);
-       assert_return(result2[strlen(TEXT) - lastwordlen] == '\0',
-                     EXIT_FAILURE);
+       assert_return(result2[strlen(TEXT) - lastwordlen] == '\0', EXIT_FAILURE);
 
        free(str);
        free(result2);
@@ -80,7 +78,6 @@ static int test_strbuf_pushchars(const struct test *t)
        return 0;
 }
 DEFINE_TEST(test_strbuf_pushchars,
-               .description = "test strbuf_{pushchars, popchar, popchars}");
-
+           .description = "test strbuf_{pushchars, popchar, popchars}");
 
 TESTSUITE_MAIN();
index dcfcf7c77956c78118b3e52ca08df17d5d4d4609..3b84aaa709456190bc6d7d34f8a6b86a4360c4c5 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "testsuite.h"
 
-
 #define TEST_UNAME "4.0.20-kmod"
 static noreturn int testsuite_uname(const struct test *t)
 {
index fde8e52532820ab736683bea47d580fad87866db..2425ff9f015b8d53ab5626090364e4009d1fc42f 100644 (file)
@@ -101,8 +101,7 @@ static int test_strchr_replace(const struct test *t)
 
        return EXIT_SUCCESS;
 }
-DEFINE_TEST(test_strchr_replace,
-       .description = "check implementation of strchr_replace()")
+DEFINE_TEST(test_strchr_replace, .description = "check implementation of strchr_replace()")
 
 static int test_underscores(const struct test *t)
 {
@@ -127,8 +126,7 @@ static int test_underscores(const struct test *t)
 
        return EXIT_SUCCESS;
 }
-DEFINE_TEST(test_underscores,
-       .description = "check implementation of underscores()")
+DEFINE_TEST(test_underscores, .description = "check implementation of underscores()")
 
 static int test_path_ends_with_kmod_ext(const struct test *t)
 {
@@ -154,15 +152,15 @@ static int test_path_ends_with_kmod_ext(const struct test *t)
        }, *iter;
 
        for (iter = &teststr[0]; iter->val != NULL; iter++) {
-               assert_return(path_ends_with_kmod_ext(iter->val,
-                                                     strlen(iter->val)) == iter->res,
+               assert_return(path_ends_with_kmod_ext(iter->val, strlen(iter->val)) ==
+                                     iter->res,
                              EXIT_FAILURE);
        }
 
        return EXIT_SUCCESS;
 }
 DEFINE_TEST(test_path_ends_with_kmod_ext,
-       .description = "check implementation of path_ends_with_kmod_ext()")
+           .description = "check implementation of path_ends_with_kmod_ext()")
 
 #define TEST_WRITE_STR_SAFE_FILE "/write-str-safe"
 #define TEST_WRITE_STR_SAFE_PATH TESTSUITE_ROOTFS "test-util2/" TEST_WRITE_STR_SAFE_FILE
@@ -171,7 +169,7 @@ static int test_write_str_safe(const struct test *t)
        const char *s = "test";
        int fd;
 
-       fd = open(TEST_WRITE_STR_SAFE_FILE ".txt", O_CREAT|O_TRUNC|O_WRONLY, 0644);
+       fd = open(TEST_WRITE_STR_SAFE_FILE ".txt", O_CREAT | O_TRUNC | O_WRONLY, 0644);
        assert_return(fd >= 0, EXIT_FAILURE);
 
        write_str_safe(fd, s, strlen(s));
@@ -208,8 +206,7 @@ static int test_addu64_overflow(const struct test *t)
        return EXIT_SUCCESS;
 }
 DEFINE_TEST(test_addu64_overflow,
-       .description = "check implementation of addu4_overflow()")
-
+           .description = "check implementation of addu4_overflow()")
 
 static int test_backoff_time(const struct test *t)
 {
@@ -247,7 +244,6 @@ static int test_backoff_time(const struct test *t)
        return EXIT_SUCCESS;
 }
 DEFINE_TEST(test_backoff_time,
-       .description = "check implementation of get_backoff_delta_msec()")
-
+           .description = "check implementation of get_backoff_delta_msec()")
 
 TESTSUITE_MAIN();
index 22ee29c2022d837255e9422dfa3c129de180db97..6e9d2089d508521cd59cd284b7841bbce66be22d 100644 (file)
@@ -27,7 +27,7 @@
 
 static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m";
 static const char *ANSI_HIGHLIGHT_YELLOW_ON = "\x1B[1;33m";
-static const char *ANSI_HIGHLIGHT_RED_ON =  "\x1B[1;31m";
+static const char *ANSI_HIGHLIGHT_RED_ON = "\x1B[1;31m";
 static const char *ANSI_HIGHLIGHT_OFF = "\x1B[0m";
 
 static const char *progname;
@@ -45,10 +45,12 @@ static const struct {
        const char *key;
        const char *ldpreload;
 } env_config[_TC_LAST] = {
-       [TC_UNAME_R] = { S_TC_UNAME_R, OVERRIDE_LIBDIR  "uname.so" },
+       [TC_UNAME_R] = { S_TC_UNAME_R, OVERRIDE_LIBDIR "uname.so" },
        [TC_ROOTFS] = { S_TC_ROOTFS, OVERRIDE_LIBDIR "path.so" },
-       [TC_INIT_MODULE_RETCODES] = { S_TC_INIT_MODULE_RETCODES, OVERRIDE_LIBDIR "init_module.so" },
-       [TC_DELETE_MODULE_RETCODES] = { S_TC_DELETE_MODULE_RETCODES, OVERRIDE_LIBDIR "delete_module.so" },
+       [TC_INIT_MODULE_RETCODES] = { S_TC_INIT_MODULE_RETCODES,
+                                     OVERRIDE_LIBDIR "init_module.so" },
+       [TC_DELETE_MODULE_RETCODES] = { S_TC_DELETE_MODULE_RETCODES,
+                                       OVERRIDE_LIBDIR "delete_module.so" },
 };
 
 static void help(void)
@@ -58,10 +60,11 @@ static void help(void)
 
        printf("Usage:\n"
               "\t%s [options] <test>\n"
-              "Options:\n", basename(progname));
+              "Options:\n",
+              basename(progname));
 
-       for (itr = options, itr_short = options_short;
-                               itr->name != NULL; itr++, itr_short++)
+       for (itr = options, itr_short = options_short; itr->name != NULL;
+            itr++, itr_short++)
                printf("\t-%c, --%s\n", *itr_short, itr->name);
 }
 
@@ -74,8 +77,8 @@ static void test_list(const struct test *start, const struct test *stop)
                printf("\t%s, %s\n", t->name, t->description);
 }
 
-int test_init(const struct test *start, const struct test *stop,
-             int argc, char *const argv[])
+int test_init(const struct test *start, const struct test *stop, int argc,
+             char *const argv[])
 {
        progname = argv[0];
 
@@ -111,8 +114,8 @@ int test_init(const struct test *start, const struct test *stop,
        return optind;
 }
 
-const struct test *test_find(const struct test *start,
-                            const struct test *stop, const char *name)
+const struct test *test_find(const struct test *start, const struct test *stop,
+                            const char *name)
 {
        const struct test *t;
 
@@ -128,7 +131,7 @@ static int test_spawn_test(const struct test *t)
 {
        const char *const args[] = { progname, "-n", t->name, NULL };
 
-       execv(progname, (char *const *) args);
+       execv(progname, (char *const *)args);
 
        ERR("failed to spawn %s for %s: %m\n", progname, t->name);
        return EXIT_FAILURE;
@@ -144,7 +147,7 @@ static int test_run_spawned(const struct test *t)
 
 int test_spawn_prog(const char *prog, const char *const args[])
 {
-       execv(prog, (char *const *) args);
+       execv(prog, (char *const *)args);
 
        ERR("failed to spawn %s\n", prog);
        ERR("did you forget to build tools?\n");
@@ -195,8 +198,8 @@ static void test_export_environ(const struct test *t)
                setenv(env->key, env->val, 1);
 }
 
-static inline int test_run_child(const struct test *t, int fdout[2],
-                                               int fderr[2], int fdmonitor[2])
+static inline int test_run_child(const struct test *t, int fdout[2], int fderr[2],
+                                int fdmonitor[2])
 {
        /* kill child if parent dies */
        prctl(PR_SET_PDEATHSIG, SIGTERM);
@@ -239,7 +242,7 @@ static inline int test_run_child(const struct test *t, int fdout[2],
 
                if (stat_mstamp(&rootfsst) > stat_mstamp(&stampst)) {
                        ERR("rootfs %s is dirty, please run 'make rootfs' before running this test\n",
-                                                               rootfs);
+                           rootfs);
                        exit(EXIT_FAILURE);
                }
        }
@@ -284,8 +287,7 @@ static int fd_cmp_check_activity(struct fd_cmp *fd_cmp)
        if (stat(fd_cmp->path, &st) == 0 && st.st_size == 0)
                return 0;
 
-       ERR("Expecting output on %s, but test didn't produce any\n",
-           fd_cmp->name);
+       ERR("Expecting output on %s, but test didn't produce any\n", fd_cmp->name);
 
        return -1;
 }
@@ -309,8 +311,7 @@ static int fd_cmp_open_monitor(struct fd_cmp *fd_cmp, int fd, int fd_ep)
        return 0;
 }
 
-static int fd_cmp_open_std(struct fd_cmp *fd_cmp,
-                          const char *fn, int fd, int fd_ep)
+static int fd_cmp_open_std(struct fd_cmp *fd_cmp, const char *fn, int fd, int fd_ep)
 {
        struct epoll_event ep = {};
        int fd_match;
@@ -332,9 +333,8 @@ static int fd_cmp_open_std(struct fd_cmp *fd_cmp,
 }
 
 /* opens output file AND adds descriptor to epoll */
-static int fd_cmp_open(struct fd_cmp **fd_cmp_out,
-                      enum fd_cmp_type type, const char *fn, int fd,
-                      int fd_ep)
+static int fd_cmp_open(struct fd_cmp **fd_cmp_out, enum fd_cmp_type type, const char *fn,
+                      int fd, int fd_ep)
 {
        int err = 0;
        struct fd_cmp *fd_cmp;
@@ -407,9 +407,9 @@ static void fd_cmp_close(struct fd_cmp *fd_cmp)
 
 static bool fd_cmp_regex_one(const char *pattern, const char *s)
 {
-       _cleanup_(regfree) regex_t re = { };
+       _cleanup_(regfree) regex_t re = {};
 
-       return !regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) &&
+       return !regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) &&
               !regexec(&re, s, 0, NULL, 0);
 }
 
@@ -450,8 +450,10 @@ static bool fd_cmp_regex(struct fd_cmp *fd_cmp, const struct test *t)
                                 fd_cmp->head_match - done_match);
                if (!p_match) {
                        if (fd_cmp->head_match >= sizeof(fd_cmp->buf_match)) {
-                               ERR("Read %zu bytes without a match\n", sizeof(fd_cmp->buf_match));
-                               ERR("output: %.*s", (int)sizeof(fd_cmp->buf_match), fd_cmp->buf_match);
+                               ERR("Read %zu bytes without a match\n",
+                                   sizeof(fd_cmp->buf_match));
+                               ERR("output: %.*s", (int)sizeof(fd_cmp->buf_match),
+                                   fd_cmp->buf_match);
                                return false;
                        }
 
@@ -466,13 +468,15 @@ static bool fd_cmp_regex(struct fd_cmp *fd_cmp, const struct test *t)
                        p_match = memchr(fd_cmp->buf_match + done_match, '\n',
                                         fd_cmp->head_match - done_match);
                        if (!p_match) {
-                               ERR("could not find match line from fd %d\n", fd_cmp->fd_match);
+                               ERR("could not find match line from fd %d\n",
+                                   fd_cmp->fd_match);
                                return false;
                        }
                }
                *p_match = '\0';
 
-               if (!fd_cmp_regex_one(fd_cmp->buf_match + done_match, fd_cmp->buf + done)) {
+               if (!fd_cmp_regex_one(fd_cmp->buf_match + done_match,
+                                     fd_cmp->buf + done)) {
                        ERR("Output does not match pattern on %s:\n", fd_cmp->name);
                        ERR("pattern: %s\n", fd_cmp->buf_match + done_match);
                        ERR("output : %s\n", fd_cmp->buf + done);
@@ -545,9 +549,8 @@ static bool fd_cmp_exact(struct fd_cmp *fd_cmp, const struct test *t)
        return true;
 }
 
-static bool test_run_parent_check_outputs(const struct test *t,
-                                         int fdout, int fderr, int fdmonitor,
-                                         pid_t child)
+static bool test_run_parent_check_outputs(const struct test *t, int fdout, int fderr,
+                                         int fdmonitor, pid_t child)
 {
        int err, fd_ep;
        unsigned long long end_usec, start_usec;
@@ -563,16 +566,14 @@ static bool test_run_parent_check_outputs(const struct test *t,
        }
 
        if (t->output.out != NULL) {
-               err = fd_cmp_open(&fd_cmp_out,
-                                 FD_CMP_OUT, t->output.out, fdout, fd_ep);
+               err = fd_cmp_open(&fd_cmp_out, FD_CMP_OUT, t->output.out, fdout, fd_ep);
                if (err < 0)
                        goto out;
                n_fd++;
        }
 
        if (t->output.err != NULL) {
-               err = fd_cmp_open(&fd_cmp_err,
-                                 FD_CMP_ERR, t->output.err, fderr, fd_ep);
+               err = fd_cmp_open(&fd_cmp_err, FD_CMP_ERR, t->output.err, fderr, fd_ep);
                if (err < 0)
                        goto out;
                n_fd++;
@@ -604,7 +605,7 @@ static bool test_run_parent_check_outputs(const struct test *t,
                        goto out;
                }
 
-               for (i = 0;  i < fdcount; i++) {
+               for (i = 0; i < fdcount; i++) {
                        struct fd_cmp *fd_cmp = ev[i].data.ptr;
                        bool ret;
 
@@ -763,15 +764,13 @@ static int cmp_modnames(const void *m1, const void *m2)
  * Auxiliary function to store the module names in buf and return a list
  * of pointers to them.
  */
-static const char **read_modules(const char* modules,
-               char **buf, int *count)
+static const char **read_modules(const char *modules, char **buf, int *count)
 {
        const char **res;
        int len;
        int i;
        char *p;
 
-
        *buf = strdup(modules);
        if (!*buf) {
                *count = -1;
@@ -804,8 +803,7 @@ static const char **read_modules(const char* modules,
  * Store the expected module names in buf and return a list of pointers to
  * them.
  */
-static const char **read_expected_modules(const struct test *t,
-               char **buf, int *count)
+static const char **read_expected_modules(const struct test *t, char **buf, int *count)
 {
        if (t->modules_loaded[0] == '\0') {
                *count = 0;
@@ -819,8 +817,7 @@ static const char **read_expected_modules(const struct test *t,
  * Store the unexpected module names in buf and return a list of pointers to
  * them.
  */
-static const char **read_unexpected_modules(const struct test *t,
-               char **buf, int *count)
+static const char **read_unexpected_modules(const struct test *t, char **buf, int *count)
 {
        if (t->modules_not_loaded[0] == '\0') {
                *count = 0;
@@ -842,8 +839,8 @@ static char **read_loaded_modules(const struct test *t, char **buf, int *count)
        const char *rootfs = t->config[TC_ROOTFS] ? t->config[TC_ROOTFS] : "";
 
        /* Store the entries in /sys/module to res */
-       if (snprintf(dirname, sizeof(dirname), "%s/sys/module", rootfs)
-                       >= (int)sizeof(dirname)) {
+       if (snprintf(dirname, sizeof(dirname), "%s/sys/module", rootfs) >=
+           (int)sizeof(dirname)) {
                ERR("rootfs path too long: %s\n", rootfs);
                *buf = NULL;
                len = -1;
@@ -932,7 +929,7 @@ static int check_loaded_modules(const struct test *t)
                        err = false;
                        ERR("module %s not loaded\n", a1[i1]);
                        i1++;
-               } else  {
+               } else {
                        err = false;
                        ERR("module %s is loaded but should not be \n", a2[i2]);
                        i2++;
@@ -980,7 +977,7 @@ static int check_not_loaded_modules(const struct test *t)
                } else if (cmp < 0) {
                        i1++;
                        i2++;
-               } else  {
+               } else {
                        err = false;
                        ERR("module %s is loaded but should not be\n", a2[i2]);
                        i2++;
@@ -994,17 +991,16 @@ out_a1:
        return err;
 }
 
-static inline int test_run_parent(const struct test *t, int fdout[2],
-                               int fderr[2], int fdmonitor[2], pid_t child)
+static inline int test_run_parent(const struct test *t, int fdout[2], int fderr[2],
+                                 int fdmonitor[2], pid_t child)
 {
        pid_t pid;
        int err;
        bool matchout, match_modules;
 
        if (t->skip) {
-               LOG("%sSKIPPED%s: %s\n",
-                       ANSI_HIGHLIGHT_YELLOW_ON, ANSI_HIGHLIGHT_OFF,
-                       t->name);
+               LOG("%sSKIPPED%s: %s\n", ANSI_HIGHLIGHT_YELLOW_ON, ANSI_HIGHLIGHT_OFF,
+                   t->name);
                err = EXIT_SUCCESS;
                goto exit;
        }
@@ -1016,8 +1012,8 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
                close(fderr[1]);
        close(fdmonitor[1]);
 
-       matchout = test_run_parent_check_outputs(t, fdout[0], fderr[0],
-                                                       fdmonitor[0], child);
+       matchout =
+               test_run_parent_check_outputs(t, fdout[0], fderr[0], fdmonitor[0], child);
 
        /*
         * break pipe on the other end: either child already closed or we want
@@ -1040,14 +1036,14 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
 
        if (WIFEXITED(err)) {
                if (WEXITSTATUS(err) != 0)
-                       ERR("'%s' [%u] exited with return code %d\n",
-                                       t->name, pid, WEXITSTATUS(err));
+                       ERR("'%s' [%u] exited with return code %d\n", t->name, pid,
+                           WEXITSTATUS(err));
                else
-                       LOG("'%s' [%u] exited with return code %d\n",
-                                       t->name, pid, WEXITSTATUS(err));
+                       LOG("'%s' [%u] exited with return code %d\n", t->name, pid,
+                           WEXITSTATUS(err));
        } else if (WIFSIGNALED(err)) {
                ERR("'%s' [%u] terminated by signal %d (%s)\n", t->name, pid,
-                               WTERMSIG(err), strsignal(WTERMSIG(err)));
+                   WTERMSIG(err), strsignal(WTERMSIG(err)));
                err = t->expected_fail ? EXIT_SUCCESS : EXIT_FAILURE;
                goto exit;
        }
@@ -1064,44 +1060,38 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
        if (t->expected_fail == false) {
                if (err == 0) {
                        if (matchout && match_modules)
-                               LOG("%sPASSED%s: %s\n",
-                                       ANSI_HIGHLIGHT_GREEN_ON, ANSI_HIGHLIGHT_OFF,
-                                       t->name);
+                               LOG("%sPASSED%s: %s\n", ANSI_HIGHLIGHT_GREEN_ON,
+                                   ANSI_HIGHLIGHT_OFF, t->name);
                        else {
                                ERR("%sFAILED%s: exit ok but %s do not match: %s\n",
-                                       ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF,
-                                       matchout ? "loaded modules" : "outputs",
-                                       t->name);
+                                   ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF,
+                                   matchout ? "loaded modules" : "outputs", t->name);
                                err = EXIT_FAILURE;
                        }
                } else {
-                       ERR("%sFAILED%s: %s\n",
-                                       ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF,
-                                       t->name);
+                       ERR("%sFAILED%s: %s\n", ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF,
+                           t->name);
                }
        } else {
                if (err == 0) {
                        if (matchout) {
                                ERR("%sUNEXPECTED PASS%s: exit with 0: %s\n",
-                                       ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF,
-                                       t->name);
+                                   ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF, t->name);
                                err = EXIT_FAILURE;
                        } else {
                                ERR("%sUNEXPECTED PASS%s: exit with 0 and outputs do not match: %s\n",
-                                       ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF,
-                                       t->name);
+                                   ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF, t->name);
                                err = EXIT_FAILURE;
                        }
                } else {
                        if (matchout) {
-                               LOG("%sEXPECTED FAIL%s: %s\n",
-                                       ANSI_HIGHLIGHT_GREEN_ON, ANSI_HIGHLIGHT_OFF,
-                                       t->name);
+                               LOG("%sEXPECTED FAIL%s: %s\n", ANSI_HIGHLIGHT_GREEN_ON,
+                                   ANSI_HIGHLIGHT_OFF, t->name);
                                err = EXIT_SUCCESS;
                        } else {
                                LOG("%sEXPECTED FAIL%s: exit with %d but outputs do not match: %s\n",
-                                       ANSI_HIGHLIGHT_GREEN_ON, ANSI_HIGHLIGHT_OFF,
-                                       WEXITSTATUS(err), t->name);
+                                   ANSI_HIGHLIGHT_GREEN_ON, ANSI_HIGHLIGHT_OFF,
+                                   WEXITSTATUS(err), t->name);
                                err = EXIT_FAILURE;
                        }
                }
index dd4c673898a3abb7f9a244a1d8907252682f6e6d..59d29c132882283bb3daf47d8586f7bf621a4590 100644 (file)
@@ -103,71 +103,68 @@ struct test {
        bool print_outputs;
 } __attribute__((aligned(8)));
 
-
-int test_init(const struct test *start, const struct test *stop,
-             int argc, char *const argv[]);
+int test_init(const struct test *start, const struct test *stop, int argc,
+             char *const argv[]);
 const struct test *test_find(const struct test *start, const struct test *stop,
                             const char *name);
 int test_spawn_prog(const char *prog, const char *const args[]);
 int test_run(const struct test *t);
 
-#define TS_EXPORT __attribute__ ((visibility("default")))
+#define TS_EXPORT __attribute__((visibility("default")))
 
-#define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ## __VA_ARGS__)
-#define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__)
-#define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__)
-#define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__)
+#define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ##__VA_ARGS__)
+#define LOG(fmt, ...) _LOG("", fmt, ##__VA_ARGS__)
+#define WARN(fmt, ...) _LOG("WARN: ", fmt, ##__VA_ARGS__)
+#define ERR(fmt, ...) _LOG("ERR: ", fmt, ##__VA_ARGS__)
 
-#define assert_return(expr, r)                                         \
-       do {                                                            \
-               if ((!(expr))) {                                        \
-                       ERR("Failed assertion: " #expr " %s:%d %s\n",   \
-                           __FILE__, __LINE__, __PRETTY_FUNCTION__);   \
-                       return (r);                                     \
-               }                                                       \
+#define assert_return(expr, r)                                                  \
+       do {                                                                    \
+               if ((!(expr))) {                                                \
+                       ERR("Failed assertion: " #expr " %s:%d %s\n", __FILE__, \
+                           __LINE__, __PRETTY_FUNCTION__);                     \
+                       return (r);                                             \
+               }                                                               \
        } while (false)
 
-
 /* Test definitions */
-#define DEFINE_TEST_WITH_FUNC(_name, _func, ...) \
-       static const struct test UNIQ(s##_name) \
-       __attribute__((used, section("kmod_tests"), aligned(8))) = { \
-               .name = #_name, \
-               .func = _func, \
-               ## __VA_ARGS__ \
-       };
+#define DEFINE_TEST_WITH_FUNC(_name, _func, ...)                             \
+       static const struct test UNIQ(s##_name)                              \
+               __attribute__((used, section("kmod_tests"), aligned(8))) = { \
+                       .name = #_name, .func = _func, ##__VA_ARGS__         \
+               };
 
 #define DEFINE_TEST(_name, ...) DEFINE_TEST_WITH_FUNC(_name, _name, __VA_ARGS__)
 
-#define TESTSUITE_MAIN() \
-       extern struct test __start_kmod_tests[] __attribute__((weak, visibility("hidden")));    \
-       extern struct test __stop_kmod_tests[] __attribute__((weak, visibility("hidden")));     \
-       int main(int argc, char *argv[])                                                        \
-       {                                                                                       \
-               const struct test *t;                                                           \
-               int arg;                                                                        \
-                                                                                               \
-               arg = test_init(__start_kmod_tests, __stop_kmod_tests, argc, argv);             \
-               if (arg == 0)                                                                   \
-                       return 0;                                                               \
-               if (arg < 0)                                                                    \
-                       return EXIT_FAILURE;                                                    \
-                                                                                               \
-               if (arg < argc) {                                                               \
-                       t = test_find(__start_kmod_tests, __stop_kmod_tests, argv[arg]);        \
-                       if (t == NULL) {                                                        \
-                               fprintf(stderr, "could not find test %s\n", argv[arg]);         \
-                               exit(EXIT_FAILURE);                                             \
-                       }                                                                       \
-                                                                                               \
-                       return test_run(t);                                                     \
-               }                                                                               \
-                                                                                               \
-               for (t = __start_kmod_tests; t < __stop_kmod_tests; t++) {                      \
-                       if (test_run(t) != 0)                                                   \
-                               exit(EXIT_FAILURE);                                             \
-               }                                                                               \
-                                                                                               \
-               exit(EXIT_SUCCESS);                                                             \
-       }                                                                                       \
-
+#define TESTSUITE_MAIN()                                                                 \
+       extern struct test __start_kmod_tests[]                                          \
+               __attribute__((weak, visibility("hidden")));                             \
+       extern struct test __stop_kmod_tests[]                                           \
+               __attribute__((weak, visibility("hidden")));                             \
+       int main(int argc, char *argv[])                                                 \
+       {                                                                                \
+               const struct test *t;                                                    \
+               int arg;                                                                 \
+                                                                                         \
+               arg = test_init(__start_kmod_tests, __stop_kmod_tests, argc, argv);      \
+               if (arg == 0)                                                            \
+                       return 0;                                                        \
+               if (arg < 0)                                                             \
+                       return EXIT_FAILURE;                                             \
+                                                                                         \
+               if (arg < argc) {                                                        \
+                       t = test_find(__start_kmod_tests, __stop_kmod_tests, argv[arg]); \
+                       if (t == NULL) {                                                 \
+                               fprintf(stderr, "could not find test %s\n", argv[arg]);  \
+                               exit(EXIT_FAILURE);                                      \
+                       }                                                                \
+                                                                                         \
+                       return test_run(t);                                              \
+               }                                                                        \
+                                                                                         \
+               for (t = __start_kmod_tests; t < __stop_kmod_tests; t++) {               \
+                       if (test_run(t) != 0)                                            \
+                               exit(EXIT_FAILURE);                                      \
+               }                                                                        \
+                                                                                         \
+               exit(EXIT_SUCCESS);                                                      \
+       }
index a7bd962d7df4d41f9968706fd11fc77c1a4c4526..293c625d533147f90434c91ff8f11b13b09fe243 100644 (file)
@@ -43,16 +43,16 @@ TS_EXPORT int uname(struct utsname *u)
 
        release = getenv(S_TC_UNAME_R);
        if (release == NULL) {
-               fprintf(stderr, "TRAP uname(): missing export %s?\n",
-                                                       S_TC_UNAME_R);
+               fprintf(stderr, "TRAP uname(): missing export %s?\n", S_TC_UNAME_R);
                return 0;
        }
 
        sz = strlen(release) + 1;
        if (sz > sizeof(u->release)) {
-               fprintf(stderr, "uname(): sizeof release (%s) "
-                               "is greater than available space: %zu",
-                               release, sizeof(u->release));
+               fprintf(stderr,
+                       "uname(): sizeof release (%s) "
+                       "is greater than available space: %zu",
+                       release, sizeof(u->release));
                errno = -EFAULT;
                return -1;
        }