Skip to content

Commit 310b993

Browse files
Merge pull request #837 from EuphoricThinking/assertspr12
UT_ASSERTs moved to test/c_api
2 parents 77ef32a + 82b7184 commit 310b993

File tree

4 files changed

+77
-53
lines changed

4 files changed

+77
-53
lines changed

test/c_api/disjoint_pool.c

+1
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

+1
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

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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
12+
These asserts should NOT be used in other purposes than for testing C API
13+
*/
14+
15+
#ifndef UMF_TEST_UT_ASSERTS_H
16+
#define UMF_TEST_UT_ASSERTS_H 1
17+
18+
#include <stdarg.h>
19+
#include <stdio.h>
20+
#include <stdlib.h>
21+
22+
static inline void UT_FATAL(const char *format, ...) {
23+
va_list args_list;
24+
va_start(args_list, format);
25+
vfprintf(stderr, format, args_list);
26+
va_end(args_list);
27+
28+
fprintf(stderr, "\n");
29+
30+
abort();
31+
}
32+
33+
static inline void UT_OUT(const char *format, ...) {
34+
va_list args_list;
35+
va_start(args_list, format);
36+
vfprintf(stdout, format, args_list);
37+
va_end(args_list);
38+
39+
fprintf(stdout, "\n");
40+
}
41+
42+
// Assert a condition is true at runtime
43+
#define UT_ASSERT(cnd) \
44+
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
45+
__LINE__, __func__, #cnd), \
46+
0)))
47+
48+
// Assertion with extra info printed if assertion fails at runtime
49+
#define UT_ASSERTinfo(cnd, info) \
50+
((void)((cnd) || \
51+
(UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \
52+
__LINE__, __func__, #cnd, #info, info), \
53+
0)))
54+
55+
// Assert two integer values are equal at runtime
56+
#define UT_ASSERTeq(lhs, rhs) \
57+
((void)(((lhs) == (rhs)) || \
58+
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \
59+
"(0x%llx)", \
60+
__FILE__, __LINE__, __func__, #lhs, \
61+
(unsigned long long)(lhs), #rhs, \
62+
(unsigned long long)(rhs)), \
63+
0)))
64+
65+
// Assert two integer values are not equal at runtime
66+
#define UT_ASSERTne(lhs, rhs) \
67+
((void)(((lhs) != (rhs)) || \
68+
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \
69+
"(0x%llx)", \
70+
__FILE__, __LINE__, __func__, #lhs, \
71+
(unsigned long long)(lhs), #rhs, \
72+
(unsigned long long)(rhs)), \
73+
0)))
74+
75+
#endif /* UMF_TEST_UT_ASSERTS_H */

test/common/test_helpers.h

-53
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)