Skip to content

Commit 8b7cada

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

File tree

4 files changed

+76
-53
lines changed

4 files changed

+76
-53
lines changed

test/c_api/disjoint_pool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "pool_disjoint.h"
88
#include "provider_null.h"
99
#include "test_helpers.h"
10+
#include "test_ut_asserts.h"
1011

1112
void test_disjoint_pool_default_params(void) {
1213
umf_memory_provider_handle_t provider = nullProviderCreate();

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 "test_ut_asserts.h"
1516

1617
umf_memory_pool_handle_t
1718
createDisjointPool(umf_memory_provider_handle_t provider) {

test/c_api/test_ut_asserts.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
*
3+
* Copyright (C) 2023-2024 Intel Corporation
4+
*
5+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
*
8+
*/
9+
10+
/*
11+
The project uses GTEST framework for testing, which is not supported in C. Therefore, there have been introduced customised asserts for C API test. These asserts should not be used in other purposes than for testing C files
12+
*/
13+
14+
#ifndef UMF_TEST_UT_ASSERTS_H
15+
#define UMF_TEST_UT_ASSERTS_H 1
16+
17+
#include <stdarg.h>
18+
#include <stdio.h>
19+
#include <stdlib.h>
20+
21+
static inline void UT_FATAL(const char *format, ...) {
22+
va_list args_list;
23+
va_start(args_list, format);
24+
vfprintf(stderr, format, args_list);
25+
va_end(args_list);
26+
27+
fprintf(stderr, "\n");
28+
29+
abort();
30+
}
31+
32+
static inline void UT_OUT(const char *format, ...) {
33+
va_list args_list;
34+
va_start(args_list, format);
35+
vfprintf(stdout, format, args_list);
36+
va_end(args_list);
37+
38+
fprintf(stdout, "\n");
39+
}
40+
41+
// Assert a condition is true at runtime
42+
#define UT_ASSERT(cnd) \
43+
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
44+
__LINE__, __func__, #cnd), \
45+
0)))
46+
47+
// Assertion with extra info printed if assertion fails at runtime
48+
#define UT_ASSERTinfo(cnd, info) \
49+
((void)((cnd) || \
50+
(UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \
51+
__LINE__, __func__, #cnd, #info, info), \
52+
0)))
53+
54+
// Assert two integer values are equal at runtime
55+
#define UT_ASSERTeq(lhs, rhs) \
56+
((void)(((lhs) == (rhs)) || \
57+
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \
58+
"(0x%llx)", \
59+
__FILE__, __LINE__, __func__, #lhs, \
60+
(unsigned long long)(lhs), #rhs, \
61+
(unsigned long long)(rhs)), \
62+
0)))
63+
64+
// Assert two integer values are not equal at runtime
65+
#define UT_ASSERTne(lhs, rhs) \
66+
((void)(((lhs) != (rhs)) || \
67+
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \
68+
"(0x%llx)", \
69+
__FILE__, __LINE__, __func__, #lhs, \
70+
(unsigned long long)(lhs), #rhs, \
71+
(unsigned long long)(rhs)), \
72+
0)))
73+
74+
#endif /* UMF_TEST_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)