if (end == p || *end != ':')
break;
- ret = (int) l;
+ ret = (int)l;
p = end + 1;
l = strtol(p, &end, 0);
else if (*end != '\0')
break;
- errcode = (int) l;
+ errcode = (int)l;
mod = malloc(sizeof(*mod) + modnamelen + 1);
if (mod == NULL)
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);
}
}
l = strtol(p, &end, 0);
if (end == p || *end != ':')
break;
- ret = (int) l;
+ ret = (int)l;
p = end + 1;
l = strtol(p, &end, 0);
else if (*end != '\0')
break;
- errcode = (int) l;
+ errcode = (int)l;
mod = malloc(sizeof(*mod) + modnamelen + 1);
if (mod == NULL)
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)
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);
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;
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 */
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)
#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();
}
* 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();
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])
}
/* 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
#endif
#if HAVE_DECL___XSTAT
-WRAP_VERSTAT(__x,);
-WRAP_VERSTAT(__x,64);
+WRAP_VERSTAT(__x, );
+WRAP_VERSTAT(__x, 64);
#endif
#pragma once
-enum module_state
-{
+enum module_state {
MODULE_STATE_LIVE,
MODULE_STATE_COMING,
MODULE_STATE_GOING,
#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
-struct module
-{
+struct module {
enum module_state state;
/* Member of list of modules */
};
/* 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
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)
{
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)
{
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;
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)
{
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)
{
array_append(&array, c2);
array_append(&array, c3);
-
array_pop(&array);
assert_return(array.count == 2, EXIT_FAILURE);
return 0;
}
-DEFINE_TEST(test_array_pop,
- .description = "test array pop");
+DEFINE_TEST(test_array_pop, .description = "test array pop");
TESTSUITE_MAIN();
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;
});
#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";
});
#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";
},
});
-
#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";
},
});
-#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";
.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";
},
});
-#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";
});
#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";
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)
{
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)
{
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)
{
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)
{
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);
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)
{
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);
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)
{
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)
{
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)
{
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();
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)
{
#include "testsuite.h"
-
static noreturn int test_initstate_from_lookup(const struct test *t)
{
struct kmod_ctx *ctx;
},
.need_spawn = true);
-
-
-
TESTSUITE_MAIN();
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)
{
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)
{
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++;
}
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;
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);
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;
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++;
}
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;
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;
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/", \
/* 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
const char *progname = TOOLS_DIR "/modprobe";
const char *const args[] = {
progname,
- "--show-depends", "mod-loop-a",
+ "--show-depends",
+ "mod-loop-a",
NULL,
};
const char *progname = TOOLS_DIR "/modprobe";
const char *const args[] = {
progname,
- "--show-depends", "mod-simple",
+ "--show-depends",
+ "mod-simple",
NULL,
};
.regex = true,
});
-
static noreturn int modprobe_builtin(const struct test *t)
{
const char *progname = TOOLS_DIR "/modprobe";
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,
};
const char *progname = TOOLS_DIR "/modprobe";
const char *const args[] = {
progname,
- "--show-depends", "mod-simple",
+ "--show-depends",
+ "mod-simple",
NULL,
};
.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,
};
const char *progname = TOOLS_DIR "/modprobe";
const char *const args[] = {
progname,
- "--force", "mod-simple",
+ "--force",
+ "mod-simple",
NULL,
};
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)
{
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();
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);
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)
{
}
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);
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);
return 0;
}
DEFINE_TEST(test_strbuf_pushchars,
- .description = "test strbuf_{pushchars, popchar, popchars}");
-
+ .description = "test strbuf_{pushchars, popchar, popchars}");
TESTSUITE_MAIN();
#include "testsuite.h"
-
#define TEST_UNAME "4.0.20-kmod"
static noreturn int testsuite_uname(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)
{
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)
{
}, *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
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));
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)
{
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();
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;
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)
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);
}
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];
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;
{
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;
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");
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);
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);
}
}
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;
}
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;
}
/* 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;
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);
}
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;
}
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);
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;
}
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++;
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;
* 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;
* 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;
* 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;
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;
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++;
} else if (cmp < 0) {
i1++;
i2++;
- } else {
+ } else {
err = false;
ERR("module %s is loaded but should not be\n", a2[i2]);
i2++;
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;
}
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
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;
}
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;
}
}
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); \
+ }
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;
}