From af87874f9cb077217212e3d4e625b745cf35396f Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 14 Jan 2015 14:05:24 -0200 Subject: [PATCH] testsuite: fix retcodes parsing It was not saving _modules in modules and thus all check were falling in the fallback "consider a success if module is not in the list". Also the name check wasn't right: replace with streq(). The parsing could be better implemented, but this is left for later. --- testsuite/delete_module.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/testsuite/delete_module.c b/testsuite/delete_module.c index 39618fd..f3ae20b 100644 --- a/testsuite/delete_module.c +++ b/testsuite/delete_module.c @@ -30,6 +30,8 @@ #include #include +#include + #include "testsuite.h" struct mod { @@ -42,7 +44,7 @@ struct mod { static struct mod *modules; static bool need_init = true; -static void parse_retcodes(struct mod *_modules, const char *s) +static void parse_retcodes(struct mod **_modules, const char *s) { const char *p; @@ -61,7 +63,7 @@ static void parse_retcodes(struct mod *_modules, const char *s) if (modname == NULL || modname[0] == '\0') break; - modnamelen = strcspn(s, ":"); + modnamelen = strcspn(p, ":"); if (modname[modnamelen] != ':') break; @@ -72,6 +74,7 @@ static void parse_retcodes(struct mod *_modules, const char *s) l = strtol(p, &end, 0); if (end == p || *end != ':') break; + ret = (int) l; p = end + 1; @@ -91,8 +94,8 @@ static void parse_retcodes(struct mod *_modules, const char *s) mod->name[modnamelen] = '\0'; mod->ret = ret; mod->errcode = errcode; - mod->next = _modules; - _modules = mod; + mod->next = *_modules; + *_modules = mod; } } @@ -101,7 +104,7 @@ static struct mod *find_module(struct mod *_modules, const char *modname) struct mod *mod; for (mod = _modules; mod != NULL; mod = mod->next) { - if (strcmp(mod->name, modname)) + if (streq(mod->name, modname)) return mod; } @@ -111,6 +114,7 @@ static struct mod *find_module(struct mod *_modules, const char *modname) static void init_retcodes(void) { const char *s; + struct mod *mod; if (!need_init) return; @@ -118,11 +122,17 @@ static void init_retcodes(void) need_init = false; s = getenv(S_TC_DELETE_MODULE_RETCODES); if (s == NULL) { - fprintf(stderr, "TRAP delete_module(): missing export %s?\n", + ERR("TRAP delete_module(): missing export %s?\n", S_TC_DELETE_MODULE_RETCODES); } - parse_retcodes(modules, s); + 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); + } } TS_EXPORT long delete_module(const char *name, unsigned int flags);