]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: introduce TS_ASSERT reimplementing assert_return
authorEmil Velikov <emil.l.velikov@gmail.com>
Fri, 3 Jul 2026 10:20:42 +0000 (11:20 +0100)
committerLucas De Marchi <ldemarchi@kernel.org>
Thu, 16 Jul 2026 02:19:53 +0000 (23:19 -0300)
The existing macro has a few shortcomings:
 - lowercase, non-prefixed so it can be confused with assert(3), which
   has varying behaviour depending on -DNDEBUG
 - the return value is constant across the project

Introduce TS_ASSERT which is modelled after KUNIT_ASSERT, addressing the
above and tweaking the output format.

Existing instances of assert_return will be updated with a follow-up
commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/375
Signed-off-by: Lucas De Marchi <ldemarchi@kernel.org>
testsuite/testsuite.h

index c86e793b55e0b34573d52be666556dcc4be8aa57..06de9a914c42ddce09c8e97b2949c64baeeaa865 100644 (file)
@@ -119,12 +119,14 @@ 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)                                                  \
+#define assert_return(expr, r) TS_ASSERT(expr)
+
+#define TS_ASSERT(expr)                                                         \
        do {                                                                    \
                if ((!(expr))) {                                                \
-                       ERR("Failed assertion: " #expr " %s:%d %s\n", __FILE__, \
-                           __LINE__, __PRETTY_FUNCTION__);                     \
-                       return (r);                                             \
+                       ERR("ASSERTION FAILED at %s:%d\n", __FILE__, __LINE__); \
+                       ERR("\t" #expr "\n");                                   \
+                       return EXIT_FAILURE;                                    \
                }                                                               \
        } while (false)