]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: Add assert_return
authorLucas De Marchi <lucas.demarchi@intel.com>
Fri, 6 Jun 2014 05:19:01 +0000 (02:19 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Fri, 6 Jun 2014 05:19:28 +0000 (02:19 -0300)
Add assert_return to use in testcases instead of assert. The issues
with assert are:
1) It's disabled when NDEBUG is defined
2) Even if it's well supported by testsuite (the parent will
   report the child died) it can't output any meaningful
   error message

testsuite/testsuite.h

index f2a75e5dd44266b19935861ca044c5ebff5f8733..47b72fd46955e17497c7fdf81950154024a713b9 100644 (file)
@@ -119,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 = { \