Fix p_test_fail()'s va_list abuse.
p_test_fail() was passing a va_list to two separate functions with the expectation that no reset would occur. Refactor p_test_fail()'s callers to instead format two strings and pass them to p_test_fail(). Add a missing parameter to an assert_u64_eq() call, which the compiler warned about after the assertion macro refactoring.
This commit is contained in:
parent
9480a23005
commit
e3f27cfced
@ -1,13 +1,19 @@
|
|||||||
|
#define ASSERT_BUFSIZE 256
|
||||||
|
|
||||||
#define assert_cmp(t, a, b, cmp, neg_cmp, pri, fmt...) do { \
|
#define assert_cmp(t, a, b, cmp, neg_cmp, pri, fmt...) do { \
|
||||||
t a_ = (a); \
|
t a_ = (a); \
|
||||||
t b_ = (b); \
|
t b_ = (b); \
|
||||||
if (!(a_ cmp b_)) { \
|
if (!(a_ cmp b_)) { \
|
||||||
p_test_fail( \
|
char prefix[ASSERT_BUFSIZE]; \
|
||||||
|
char message[ASSERT_BUFSIZE]; \
|
||||||
|
malloc_snprintf(prefix, sizeof(prefix), \
|
||||||
"%s:%s:%d: Failed assertion: " \
|
"%s:%s:%d: Failed assertion: " \
|
||||||
"(%s) "#cmp" (%s) --> " \
|
"(%s) "#cmp" (%s) --> " \
|
||||||
"%"pri" "#neg_cmp" %"pri": ", \
|
"%"pri" "#neg_cmp" %"pri": ", \
|
||||||
__func__, __FILE__, __LINE__, \
|
__func__, __FILE__, __LINE__, \
|
||||||
#a, #b, a_, b_, fmt); \
|
#a, #b, a_, b_); \
|
||||||
|
malloc_snprintf(message, sizeof(message), fmt); \
|
||||||
|
p_test_fail(prefix, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -208,24 +214,32 @@
|
|||||||
bool a_ = (a); \
|
bool a_ = (a); \
|
||||||
bool b_ = (b); \
|
bool b_ = (b); \
|
||||||
if (!(a_ == b_)) { \
|
if (!(a_ == b_)) { \
|
||||||
p_test_fail( \
|
char prefix[ASSERT_BUFSIZE]; \
|
||||||
|
char message[ASSERT_BUFSIZE]; \
|
||||||
|
malloc_snprintf(prefix, sizeof(prefix), \
|
||||||
"%s:%s:%d: Failed assertion: " \
|
"%s:%s:%d: Failed assertion: " \
|
||||||
"(%s) == (%s) --> %s != %s: ", \
|
"(%s) == (%s) --> %s != %s: ", \
|
||||||
__func__, __FILE__, __LINE__, \
|
__func__, __FILE__, __LINE__, \
|
||||||
#a, #b, a_ ? "true" : "false", \
|
#a, #b, a_ ? "true" : "false", \
|
||||||
b_ ? "true" : "false", fmt); \
|
b_ ? "true" : "false"); \
|
||||||
|
malloc_snprintf(message, sizeof(message), fmt); \
|
||||||
|
p_test_fail(prefix, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define assert_b_ne(a, b, fmt...) do { \
|
#define assert_b_ne(a, b, fmt...) do { \
|
||||||
bool a_ = (a); \
|
bool a_ = (a); \
|
||||||
bool b_ = (b); \
|
bool b_ = (b); \
|
||||||
if (!(a_ != b_)) { \
|
if (!(a_ != b_)) { \
|
||||||
p_test_fail( \
|
char prefix[ASSERT_BUFSIZE]; \
|
||||||
|
char message[ASSERT_BUFSIZE]; \
|
||||||
|
malloc_snprintf(prefix, sizeof(prefix), \
|
||||||
"%s:%s:%d: Failed assertion: " \
|
"%s:%s:%d: Failed assertion: " \
|
||||||
"(%s) != (%s) --> %s == %s: ", \
|
"(%s) != (%s) --> %s == %s: ", \
|
||||||
__func__, __FILE__, __LINE__, \
|
__func__, __FILE__, __LINE__, \
|
||||||
#a, #b, a_ ? "true" : "false", \
|
#a, #b, a_ ? "true" : "false", \
|
||||||
b_ ? "true" : "false", fmt); \
|
b_ ? "true" : "false"); \
|
||||||
|
malloc_snprintf(message, sizeof(message), fmt); \
|
||||||
|
p_test_fail(prefix, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define assert_true(a, fmt...) assert_b_eq(a, true, fmt)
|
#define assert_true(a, fmt...) assert_b_eq(a, true, fmt)
|
||||||
@ -233,26 +247,39 @@
|
|||||||
|
|
||||||
#define assert_str_eq(a, b, fmt...) do { \
|
#define assert_str_eq(a, b, fmt...) do { \
|
||||||
if (strcmp((a), (b))) { \
|
if (strcmp((a), (b))) { \
|
||||||
p_test_fail( \
|
char prefix[ASSERT_BUFSIZE]; \
|
||||||
|
char message[ASSERT_BUFSIZE]; \
|
||||||
|
malloc_snprintf(prefix, sizeof(prefix), \
|
||||||
"%s:%s:%d: Failed assertion: " \
|
"%s:%s:%d: Failed assertion: " \
|
||||||
"(%s) same as (%s) --> " \
|
"(%s) same as (%s) --> " \
|
||||||
"\"%s\" differs from \"%s\": ", \
|
"\"%s\" differs from \"%s\": ", \
|
||||||
__func__, __FILE__, __LINE__, #a, #b, a, b, fmt); \
|
__func__, __FILE__, __LINE__, #a, #b, a, b); \
|
||||||
|
malloc_snprintf(message, sizeof(message), fmt); \
|
||||||
|
p_test_fail(prefix, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define assert_str_ne(a, b, fmt...) do { \
|
#define assert_str_ne(a, b, fmt...) do { \
|
||||||
if (!strcmp((a), (b))) { \
|
if (!strcmp((a), (b))) { \
|
||||||
p_test_fail( \
|
char prefix[ASSERT_BUFSIZE]; \
|
||||||
|
char message[ASSERT_BUFSIZE]; \
|
||||||
|
malloc_snprintf(prefix, sizeof(prefix), \
|
||||||
"%s:%s:%d: Failed assertion: " \
|
"%s:%s:%d: Failed assertion: " \
|
||||||
"(%s) differs from (%s) --> " \
|
"(%s) differs from (%s) --> " \
|
||||||
"\"%s\" same as \"%s\": ", \
|
"\"%s\" same as \"%s\": ", \
|
||||||
__func__, __FILE__, __LINE__, #a, #b, a, b, fmt); \
|
__func__, __FILE__, __LINE__, #a, #b, a, b); \
|
||||||
|
malloc_snprintf(message, sizeof(message), fmt); \
|
||||||
|
p_test_fail(prefix, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define assert_not_reached(fmt...) do { \
|
#define assert_not_reached(fmt...) do { \
|
||||||
p_test_fail("%s:%s:%d: Unreachable code reached: ", \
|
char prefix[ASSERT_BUFSIZE]; \
|
||||||
__func__, __FILE__, __LINE__, fmt); \
|
char message[ASSERT_BUFSIZE]; \
|
||||||
|
malloc_snprintf(prefix, sizeof(prefix), \
|
||||||
|
"%s:%s:%d: Unreachable code reached: ", \
|
||||||
|
__func__, __FILE__, __LINE__); \
|
||||||
|
malloc_snprintf(message, sizeof(message), fmt); \
|
||||||
|
p_test_fail(prefix, message); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -299,4 +326,4 @@ void test_fail(const char *format, ...) JEMALLOC_ATTR(format(printf, 1, 2));
|
|||||||
test_status_t p_test(test_t* t, ...);
|
test_status_t p_test(test_t* t, ...);
|
||||||
void p_test_init(const char *name);
|
void p_test_init(const char *name);
|
||||||
void p_test_fini(void);
|
void p_test_fini(void);
|
||||||
void p_test_fail(const char *format, ...);
|
void p_test_fail(const char *prefix, const char *message);
|
||||||
|
@ -86,15 +86,9 @@ p_test(test_t* t, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
p_test_fail(const char *format, ...)
|
p_test_fail(const char *prefix, const char *message)
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message);
|
||||||
malloc_vcprintf(NULL, NULL, format, ap);
|
|
||||||
format = va_arg(ap, const char *);
|
|
||||||
malloc_vcprintf(NULL, NULL, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
malloc_printf("\n");
|
|
||||||
test_status = test_status_fail;
|
test_status = test_status_fail;
|
||||||
}
|
}
|
||||||
|
@ -1576,7 +1576,7 @@ TEST_BEGIN(test_by_array_64)
|
|||||||
for (i = 0; i < BLOCK_SIZE64; i++) {
|
for (i = 0; i < BLOCK_SIZE64; i++) {
|
||||||
if (i < COUNT_1) {
|
if (i < COUNT_1) {
|
||||||
assert_u64_eq(array64[i], init_by_array_64_expected[i],
|
assert_u64_eq(array64[i], init_by_array_64_expected[i],
|
||||||
"Output mismatch for i=%d");
|
"Output mismatch for i=%d", i);
|
||||||
}
|
}
|
||||||
r = gen_rand64(ctx);
|
r = gen_rand64(ctx);
|
||||||
assert_u64_eq(r, array64[i],
|
assert_u64_eq(r, array64[i],
|
||||||
|
Loading…
Reference in New Issue
Block a user