Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/c_api/disjoint_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pool_disjoint.h"
#include "provider_null.h"
#include "test_helpers.h"
#include "test_ut_asserts.h"

void test_disjoint_pool_default_params(void) {
umf_memory_provider_handle_t provider = nullProviderCreate();
Expand Down
1 change: 1 addition & 0 deletions test/c_api/multi_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <umf/providers/provider_os_memory.h>

#include "test_helpers.h"
#include "test_ut_asserts.h"

umf_memory_pool_handle_t
createDisjointPool(umf_memory_provider_handle_t provider) {
Expand Down
75 changes: 75 additions & 0 deletions test/c_api/test_ut_asserts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
*
* Copyright (C) 2023-2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/

/*
The project uses GTEST framework for testing, which is not supported in C
These asserts should NOT be used in other purposes than for testing C API
*/

#ifndef UMF_TEST_UT_ASSERTS_H
#define UMF_TEST_UT_ASSERTS_H 1

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

static inline void UT_FATAL(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
vfprintf(stderr, format, args_list);
va_end(args_list);

fprintf(stderr, "\n");

abort();
}

static inline void UT_OUT(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
vfprintf(stdout, format, args_list);
va_end(args_list);

fprintf(stdout, "\n");
}

// Assert a condition is true at runtime
#define UT_ASSERT(cnd) \
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
__LINE__, __func__, #cnd), \
0)))

// Assertion with extra info printed if assertion fails at runtime
#define UT_ASSERTinfo(cnd, info) \
((void)((cnd) || \
(UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \
__LINE__, __func__, #cnd, #info, info), \
0)))

// Assert two integer values are equal at runtime
#define UT_ASSERTeq(lhs, rhs) \
((void)(((lhs) == (rhs)) || \
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \
"(0x%llx)", \
__FILE__, __LINE__, __func__, #lhs, \
(unsigned long long)(lhs), #rhs, \
(unsigned long long)(rhs)), \
0)))

// Assert two integer values are not equal at runtime
#define UT_ASSERTne(lhs, rhs) \
((void)(((lhs) != (rhs)) || \
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \
"(0x%llx)", \
__FILE__, __LINE__, __func__, #lhs, \
(unsigned long long)(lhs), #rhs, \
(unsigned long long)(rhs)), \
0)))

#endif /* UMF_TEST_UT_ASSERTS_H */
53 changes: 0 additions & 53 deletions test/common/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,6 @@ extern "C" {
// Needed for CI
#define TEST_SKIP_ERROR_CODE 125

static inline void UT_FATAL(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
vfprintf(stderr, format, args_list);
va_end(args_list);

fprintf(stderr, "\n");

abort();
}

static inline void UT_OUT(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
vfprintf(stdout, format, args_list);
va_end(args_list);

fprintf(stdout, "\n");
}

// Assert a condition is true at runtime
#define UT_ASSERT(cnd) \
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
__LINE__, __func__, #cnd), \
0)))

// Assertion with extra info printed if assertion fails at runtime
#define UT_ASSERTinfo(cnd, info) \
((void)((cnd) || \
(UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \
__LINE__, __func__, #cnd, #info, info), \
0)))

// Assert two integer values are equal at runtime
#define UT_ASSERTeq(lhs, rhs) \
((void)(((lhs) == (rhs)) || \
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \
"(0x%llx)", \
__FILE__, __LINE__, __func__, #lhs, \
(unsigned long long)(lhs), #rhs, \
(unsigned long long)(rhs)), \
0)))

// Assert two integer values are not equal at runtime
#define UT_ASSERTne(lhs, rhs) \
((void)(((lhs) != (rhs)) || \
(UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \
"(0x%llx)", \
__FILE__, __LINE__, __func__, #lhs, \
(unsigned long long)(lhs), #rhs, \
(unsigned long long)(rhs)), \
0)))

#ifndef ALIGN_UP
#define ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1))
#endif
Expand Down
Loading