From: Emil Velikov Date: Fri, 3 Jul 2026 10:20:42 +0000 (+0100) Subject: testsuite: introduce TS_ASSERT reimplementing assert_return X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8280fab2bc1b32214a349e6bd5faf7049b154d70;p=thirdparty%2Fkmod.git testsuite: introduce TS_ASSERT reimplementing assert_return 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 Link: https://github.com/kmod-project/kmod/pull/375 Signed-off-by: Lucas De Marchi --- diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index c86e793..06de9a9 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -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)