From: Lucas De Marchi Date: Fri, 25 May 2012 03:30:37 +0000 (-0300) Subject: testsuite: create initstate file upon fake init_module() X-Git-Tag: v9~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a2949cdf32cf6193992e3362c161ee1df978d2a;p=thirdparty%2Fkmod.git testsuite: create initstate file upon fake init_module() --- diff --git a/TODO b/TODO index 71f2a47e..221172da 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ Features: ========= * testsuite: - - when fake init_module() succeeds, create an entry in /sys/module - when fake delete_module() succeeds, remove its entry from /sys/module - add test for dependency loop _with install commands_ relying on module already been loaded in order to succeed. E.g.: alsa install rules on diff --git a/testsuite/init_module.c b/testsuite/init_module.c index 8a963cce..a76ca2db 100644 --- a/testsuite/init_module.c +++ b/testsuite/init_module.c @@ -35,6 +35,7 @@ /* FIXME: hack, change name so we don't clash */ #undef ERR +#include "mkdir.h" #include "testsuite.h" #include "stripped-module.h" @@ -102,6 +103,55 @@ 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; + + assert(fn); + assert(line); + + f = fopen(fn, "we"); + if (!f) + return -errno; + + errno = 0; + if (fputs(line, f) < 0) { + r = -errno; + goto finish; + } + + fflush(f); + + if (ferror(f)) { + if (errno != 0) + r = -errno; + else + r = -EIO; + } else + r = 0; + +finish: + fclose(f); + return r; +} + +static int create_sysfs_files(const char *modname) +{ + char buf[PATH_MAX]; + const char *sysfsmod = "/sys/module/"; + int len = strlen(sysfsmod); + + memcpy(buf, sysfsmod, len); + strcpy(buf + len, modname); + len += strlen(modname); + + mkdir_p(buf, 0755); + + strcpy(buf + len, "/initstate"); + return write_one_line_file(buf, "live\n", strlen("live\n")); +} + static struct mod *find_module(struct mod *_modules, const char *modname) { struct mod *mod; @@ -134,8 +184,6 @@ static void init_retcodes(void) TS_EXPORT long init_module(void *mem, unsigned long len, const char *args); /* - * FIXME: change /sys/module/ to fake-insert a module - * * Default behavior is to exit successfully. If this is not the intended * behavior, set TESTSUITE_INIT_MODULE_RETCODES env var. */ @@ -167,8 +215,10 @@ long init_module(void *mem, unsigned long len, const char *args) modname = (char *)buf + offsetof(struct module, name); mod = find_module(modules, modname); - if (mod == NULL) + if (mod == NULL) { + create_sysfs_files(modname); return 0; + } errno = mod->errcode; return mod->ret;