1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

Follow up with the PR #31819

This commit is contained in:
Unique-Usman 2024-03-19 18:20:29 +05:30 committed by Luca Boccassi
parent c3a55dc469
commit c0cd99eee6
3 changed files with 67 additions and 35 deletions

View File

@ -383,4 +383,17 @@ assert_cc(sizeof(dummy_t) == 0);
((long)(_current_ - _entries_) < (long)(ELEMENTSOF(_entries_) - 1)) && ({ entry = *_current_; true; }); \
_current_++)
#define DECIMAL_STR_FMT(x) _Generic((x), \
char: "%c", \
bool: "%d", \
unsigned char: "%d", \
short: "%hd", \
unsigned short: "%hu", \
int: "%d", \
unsigned: "%u", \
long: "%ld", \
unsigned long: "%lu", \
long long: "%lld", \
unsigned long long: "%llu")
#include "log.h"

View File

@ -203,39 +203,58 @@ static inline int run_test_table(void) {
#define ASSERT_OK(expr) \
({ \
int _result = (expr); \
typeof(expr) _result = (expr); \
if (_result < 0) { \
log_error_errno("Assertion failed: %s (result: %d, error: %m)", #expr, _result); \
log_error_errno(_result, "%s:%i: Assertion failed: %s: %m", \
PROJECT_FILE, __LINE__, #expr); \
abort(); \
} \
})
/* DECIMAL_STR_FMT() uses _Generic which cannot be used in string concatenation so we have to format the
* input into strings first and then format those into the final assertion message. */
#define ASSERT_EQ(expr1, expr2) \
({ \
int _expr1 = (expr1); \
int _expr2 = (expr2); \
typeof(expr1) _expr1 = (expr1); \
typeof(expr2) _expr2 = (expr2); \
if (_expr1 != _expr2) { \
log_error("Assertion failed: expected %s == %s, but %d != %d", #expr1, #expr2, _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_GE(expr1, expr2) \
({ \
int _expr1 = (expr1); \
int _expr2 = (expr2); \
typeof(expr1) _expr1 = (expr1); \
typeof(expr2) _expr2 = (expr2); \
if (_expr1 < _expr2) { \
log_error("Assertion failed: expected %s >= %s, but %d < %d", #expr1, #expr2, _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_LE(expr1, expr2) \
({ \
int _expr1 = (expr1); \
int _expr2 = (expr2); \
typeof(expr1) _expr1 = (expr1); \
typeof(expr2) _expr2 = (expr2); \
if (_expr1 > _expr2) { \
log_error("Assertion failed: expected %s <= %s, but %d > %d", #expr1, #expr2, _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(); \
} \
})

View File

@ -188,13 +188,13 @@ _unused_ static void test_compress_stream(const char *compression,
log_debug("/* create source from %s */", srcfile);
assert_se((src = open(srcfile, O_RDONLY|O_CLOEXEC)) >= 0);
ASSERT_OK((src = open(srcfile, O_RDONLY|O_CLOEXEC)));
log_debug("/* test compression */");
assert_se((dst = mkostemp_safe(pattern)) >= 0);
assert_se(compress(src, dst, -1, &uncompressed_size) >= 0);
ASSERT_OK(compress(src, dst, -1, &uncompressed_size));
if (cat) {
assert_se(asprintf(&cmd, "%s %s | diff %s -", cat, pattern, srcfile) > 0);