Skip to content

Commit b377875

Browse files
UT_ASSERTs moved to test/c_api
1 parent 11e94da commit b377875

File tree

4 files changed

+64
-53
lines changed

4 files changed

+64
-53
lines changed

test/c_api/disjoint_pool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "provider_null.h"
99
#include "test_helpers.h"
1010

11+
#include "ut_asserts.h"
12+
1113
void test_disjoint_pool_default_params(void) {
1214
umf_memory_provider_handle_t provider = nullProviderCreate();
1315
umf_result_t retp;

test/c_api/multi_pool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <umf/providers/provider_os_memory.h>
1313

1414
#include "test_helpers.h"
15+
#include "ut_asserts.h"
1516

1617
umf_memory_pool_handle_t
1718
createDisjointPool(umf_memory_provider_handle_t provider) {

test/c_api/ut_asserts.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef UMF_UT_ASSERTS_H
2+
#define UMF_UT_ASSERTS_H 1
3+
4+
#include <stdarg.h>
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
8+
static inline void UT_FATAL(const char *format, ...) {
9+
va_list args_list;
10+
va_start(args_list, format);
11+
vfprintf(stderr, format, args_list);
12+
va_end(args_list);
13+
14+
fprintf(stderr, "\n");
15+
16+
abort();
17+
}
18+
19+
static inline void UT_OUT(const char *format, ...) {
20+
va_list args_list;
21+
va_start(args_list, format);
22+
vfprintf(stdout, format, args_list);
23+
va_end(args_list);
24+
25+
fprintf(stdout, "\n");
26+
}
27+
28+
// Assert a condition is true at runtime
29+
#define UT_ASSERT(cnd) \
30+
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
31+
__LINE__, __func__, #cnd), \
32+
0)))
33+
34+
// Assertion with extra info printed if assertion fails at runtime
35+
#define UT_ASSERTinfo(cnd, info) \
36+
((void)((cnd) || \
37+
(UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \
38+
__LINE__, __func__, #cnd, #info, info), \
39+
0)))
40+
41+
// Assert two integer values are equal at runtime
42+
#define UT_ASSERTeq(lhs, rhs) \
43+
((void)(((lhs) == (rhs)) || \
44+
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \
45+
"(0x%llx)", \
46+
__FILE__, __LINE__, __func__, #lhs, \
47+
(unsigned long long)(lhs), #rhs, \
48+
(unsigned long long)(rhs)), \
49+
0)))
50+
51+
// Assert two integer values are not equal at runtime
52+
#define UT_ASSERTne(lhs, rhs) \
53+
((void)(((lhs) != (rhs)) || \
54+
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \
55+
"(0x%llx)", \
56+
__FILE__, __LINE__, __func__, #lhs, \
57+
(unsigned long long)(lhs), #rhs, \
58+
(unsigned long long)(rhs)), \
59+
0)))
60+
61+
#endif /* UMF_UT_ASSERTS_H */

test/common/test_helpers.h

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,6 @@ extern "C" {
2222
// Needed for CI
2323
#define TEST_SKIP_ERROR_CODE 125
2424

25-
static inline void UT_FATAL(const char *format, ...) {
26-
va_list args_list;
27-
va_start(args_list, format);
28-
vfprintf(stderr, format, args_list);
29-
va_end(args_list);
30-
31-
fprintf(stderr, "\n");
32-
33-
abort();
34-
}
35-
36-
static inline void UT_OUT(const char *format, ...) {
37-
va_list args_list;
38-
va_start(args_list, format);
39-
vfprintf(stdout, format, args_list);
40-
va_end(args_list);
41-
42-
fprintf(stdout, "\n");
43-
}
44-
45-
// Assert a condition is true at runtime
46-
#define UT_ASSERT(cnd) \
47-
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
48-
__LINE__, __func__, #cnd), \
49-
0)))
50-
51-
// Assertion with extra info printed if assertion fails at runtime
52-
#define UT_ASSERTinfo(cnd, info) \
53-
((void)((cnd) || \
54-
(UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \
55-
__LINE__, __func__, #cnd, #info, info), \
56-
0)))
57-
58-
// Assert two integer values are equal at runtime
59-
#define UT_ASSERTeq(lhs, rhs) \
60-
((void)(((lhs) == (rhs)) || \
61-
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \
62-
"(0x%llx)", \
63-
__FILE__, __LINE__, __func__, #lhs, \
64-
(unsigned long long)(lhs), #rhs, \
65-
(unsigned long long)(rhs)), \
66-
0)))
67-
68-
// Assert two integer values are not equal at runtime
69-
#define UT_ASSERTne(lhs, rhs) \
70-
((void)(((lhs) != (rhs)) || \
71-
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \
72-
"(0x%llx)", \
73-
__FILE__, __LINE__, __func__, #lhs, \
74-
(unsigned long long)(lhs), #rhs, \
75-
(unsigned long long)(rhs)), \
76-
0)))
77-
7825
#ifndef ALIGN_UP
7926
#define ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1))
8027
#endif

0 commit comments

Comments
 (0)