diff --git a/test/c_api/disjoint_pool.c b/test/c_api/disjoint_pool.c index f63b283558..13cd65ab05 100644 --- a/test/c_api/disjoint_pool.c +++ b/test/c_api/disjoint_pool.c @@ -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(); diff --git a/test/c_api/multi_pool.c b/test/c_api/multi_pool.c index 9d4ee5d4c1..9b5f73e774 100644 --- a/test/c_api/multi_pool.c +++ b/test/c_api/multi_pool.c @@ -12,6 +12,7 @@ #include #include "test_helpers.h" +#include "test_ut_asserts.h" umf_memory_pool_handle_t createDisjointPool(umf_memory_provider_handle_t provider) { diff --git a/test/c_api/test_ut_asserts.h b/test/c_api/test_ut_asserts.h new file mode 100644 index 0000000000..834d39bda8 --- /dev/null +++ b/test/c_api/test_ut_asserts.h @@ -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 +#include +#include + +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 */ diff --git a/test/common/test_helpers.h b/test/common/test_helpers.h index df4c3c2357..4a581bc4d3 100644 --- a/test/common/test_helpers.h +++ b/test/common/test_helpers.h @@ -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