]> git.ipfire.org Git - thirdparty/kmod.git/blobdiff - testsuite/testsuite.h
testsuite: Add assert_return
[thirdparty/kmod.git] / testsuite / testsuite.h
index 1f8eb6ea1e4a50019300350be6d2902f5075783b..47b72fd46955e17497c7fdf81950154024a713b9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012  ProFUSION embedded systems
+ * Copyright (C) 2012-2013  ProFUSION embedded systems
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,8 @@
 #include <stdbool.h>
 #include <stdarg.h>
 
+#include "macro.h"
+
 struct test;
 typedef int (*testfunc)(const struct test *t);
 
@@ -81,9 +83,20 @@ struct test {
        const char *name;
        const char *description;
        struct {
-               const char *stdout;
-               const char *stderr;
+               /* File with correct stdout */
+               const char *out;
+               /* File with correct stderr */
+               const char *err;
+
+               /*
+                * Vector with pair of files
+                * key = correct file
+                * val = file to check
+                */
+               const struct keyval *files;
        } output;
+       /* comma-separated list of loaded modules at the end of the test */
+       const char *modules_loaded;
        testfunc func;
        const char *config[_TC_LAST];
        const char *path;
@@ -106,6 +119,16 @@ int test_run(const struct test *t);
 #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,                 \
+                           __FILE__, __LINE__, __PRETTY_FUNCTION__);   \
+                       return (r);                                     \
+               }                                                       \
+       } while (false)
+
+
 /* Test definitions */
 #define DEFINE_TEST(_name, ...) \
        const struct test s##_name = { \
@@ -143,4 +166,10 @@ int test_run(const struct test *t);
                exit(EXIT_SUCCESS);                             \
        }                                                       \
 
-#define __noreturn __attribute__((noreturn))
+#ifdef noreturn
+# define __noreturn noreturn
+#elif __STDC_VERSION__ >= 201112L
+# define __noreturn _Noreturn
+#else
+# define __noreturn __attribute__((noreturn))
+#endif