summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-19 16:28:15 +0200
committerGitHub <noreply@github.com>2024-09-19 16:28:15 +0200
commita3c2a9ee5dda01fd1ed0dc23c02258b2592ce6ef (patch)
tree1f62f3ae67cb0a5505b1f6337fb92c8241d0a962 /src/shared
parentMerge pull request #34481 from yuwata/has-tpm2 (diff)
parenttest-process-util: Ignore EINVAL from setresuid() and setresgid() (diff)
downloadsystemd-a3c2a9ee5dda01fd1ed0dc23c02258b2592ce6ef.tar.xz
systemd-a3c2a9ee5dda01fd1ed0dc23c02258b2592ce6ef.zip
Merge pull request #34486 from DaanDeMeyer/test-process-util
test-process-util: Migrate to new assertion macros
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/tests.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/shared/tests.h b/src/shared/tests.h
index 0c1b8cfa78..33180e7b37 100644
--- a/src/shared/tests.h
+++ b/src/shared/tests.h
@@ -281,6 +281,44 @@ static inline int run_test_table(void) {
} \
})
+#define ASSERT_OK_ZERO_ERRNO(expr) \
+ ({ \
+ typeof(expr) _result = (expr); \
+ if (_result < 0) { \
+ log_error_errno(errno, "%s:%i: Assertion failed: expected \"%s\" to succeed but got the following error: %m", \
+ PROJECT_FILE, __LINE__, #expr); \
+ abort(); \
+ } \
+ if (_result != 0) { \
+ char _sexpr[DECIMAL_STR_MAX(typeof(expr))]; \
+ xsprintf(_sexpr, DECIMAL_STR_FMT(_result), _result); \
+ log_error("%s:%i: Assertion failed: expected \"%s\" to be zero, but it is %s.", \
+ PROJECT_FILE, __LINE__, #expr, _sexpr); \
+ abort(); \
+ } \
+ })
+
+#define ASSERT_OK_EQ_ERRNO(expr1, expr2) \
+ ({ \
+ typeof(expr1) _expr1 = (expr1); \
+ typeof(expr2) _expr2 = (expr2); \
+ if (_expr1 < 0) { \
+ log_error_errno(errno, "%s:%i: Assertion failed: expected \"%s\" to succeed but got the following error: %m", \
+ PROJECT_FILE, __LINE__, #expr1); \
+ abort(); \
+ } \
+ if (_expr1 != _expr2) { \
+ char _sexpr1[DECIMAL_STR_MAX(typeof(expr1))]; \
+ char _sexpr2[DECIMAL_STR_MAX(typeof(expr2))]; \
+ xsprintf(_sexpr1, DECIMAL_STR_FMT(_expr1), _expr1); \
+ xsprintf(_sexpr2, DECIMAL_STR_FMT(_expr2), _expr2); \
+ log_error("%s:%i: Assertion failed: expected \"%s == %s\", but %s != %s", \
+ PROJECT_FILE, __LINE__, #expr1, #expr2, _sexpr1, _sexpr2); \
+ abort(); \
+ } \
+ })
+
+
#define ASSERT_FAIL(expr) \
({ \
typeof(expr) _result = (expr); \