Skip to content

Commit

Permalink
testsuite: mass convert with clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
  • Loading branch information
evelikov authored and lucasdemarchi committed Sep 24, 2024
1 parent 1d0117f commit 4c760f7
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 400 deletions.
9 changes: 4 additions & 5 deletions testsuite/delete_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down
63 changes: 31 additions & 32 deletions testsuite/init_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down
168 changes: 83 additions & 85 deletions testsuite/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand All @@ -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
8 changes: 3 additions & 5 deletions testsuite/stripped-module.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

enum module_state
{
enum module_state {
MODULE_STATE_LIVE,
MODULE_STATE_COMING,
MODULE_STATE_GOING,
Expand All @@ -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 */
Expand All @@ -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
Loading

0 comments on commit 4c760f7

Please sign in to comment.