|
1 |
| -// Copyright (C) 2023 Intel Corporation |
| 1 | +// Copyright (C) 2023-2024 Intel Corporation |
2 | 2 | // Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
|
3 | 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
4 |
| -// This file contains tests for UMF pool API |
| 4 | +// This file contains helpers for tests for UMF pool API |
5 | 5 |
|
6 | 6 | #ifndef UMF_TEST_HELPERS_H
|
7 | 7 | #define UMF_TEST_HELPERS_H 1
|
8 | 8 |
|
| 9 | +#include <stdarg.h> |
| 10 | +#include <stdio.h> |
9 | 11 | #include <umf/base.h>
|
10 | 12 | #include <umf/memory_pool.h>
|
11 | 13 | #include <umf/memory_provider_ops.h>
|
|
14 | 16 | extern "C" {
|
15 | 17 | #endif
|
16 | 18 |
|
| 19 | +static inline void UT_FATAL(const char *format, ...) { |
| 20 | + va_list args_list; |
| 21 | + va_start(args_list, format); |
| 22 | + vfprintf(stderr, format, args_list); |
| 23 | + va_end(args_list); |
| 24 | + |
| 25 | + fprintf(stderr, "\n"); |
| 26 | + |
| 27 | + abort(); |
| 28 | +} |
| 29 | + |
| 30 | +static inline void UT_OUT(const char *format, ...) { |
| 31 | + va_list args_list; |
| 32 | + va_start(args_list, format); |
| 33 | + vfprintf(stdout, format, args_list); |
| 34 | + va_end(args_list); |
| 35 | + |
| 36 | + fprintf(stdout, "\n"); |
| 37 | +} |
| 38 | + |
| 39 | +// Assert a condition is true at runtime |
| 40 | +#define UT_ASSERT(cnd) \ |
| 41 | + ((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \ |
| 42 | + __LINE__, __func__, #cnd), \ |
| 43 | + 0))) |
| 44 | + |
| 45 | +// Assertion with extra info printed if assertion fails at runtime |
| 46 | +#define UT_ASSERTinfo(cnd, info) \ |
| 47 | + ((void)((cnd) || \ |
| 48 | + (UT_FATAL("%s:%d %s - assertion failure: %s (%s = %s)", __FILE__, \ |
| 49 | + __LINE__, __func__, #cnd, #info, info), \ |
| 50 | + 0))) |
| 51 | + |
| 52 | +// Assert two integer values are equal at runtime |
| 53 | +#define UT_ASSERTeq(lhs, rhs) \ |
| 54 | + ((void)(((lhs) == (rhs)) || \ |
| 55 | + (UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) == %s " \ |
| 56 | + "(0x%llx)", \ |
| 57 | + __FILE__, __LINE__, __func__, #lhs, \ |
| 58 | + (unsigned long long)(lhs), #rhs, \ |
| 59 | + (unsigned long long)(rhs)), \ |
| 60 | + 0))) |
| 61 | + |
| 62 | +// Assert two integer values are not equal at runtime |
| 63 | +#define UT_ASSERTne(lhs, rhs) \ |
| 64 | + ((void)(((lhs) != (rhs)) || \ |
| 65 | + (UT_FATAL("%s:%d %s - assertion failure: %s (0x%llx) != %s " \ |
| 66 | + "(0x%llx)", \ |
| 67 | + __FILE__, __LINE__, __func__, #lhs, \ |
| 68 | + (unsigned long long)(lhs), #rhs, \ |
| 69 | + (unsigned long long)(rhs)), \ |
| 70 | + 0))) |
| 71 | + |
17 | 72 | int bufferIsFilledWithChar(void *ptr, size_t size, char c);
|
18 | 73 |
|
19 | 74 | int buffersHaveSameContent(void *first, void *second, size_t size);
|
|
0 commit comments