|
15 | 15 |
|
16 | 16 | #include "base.hpp"
|
17 | 17 | #include "test_helpers.h"
|
| 18 | +#include "utils_common.h" |
18 | 19 |
|
19 | 20 | using umf_test::test;
|
20 | 21 |
|
21 |
| -TEST_F(test, proxyLibBasic) { |
| 22 | +#define SIZE_64 64 |
| 23 | +#define ALIGN_1024 1024 |
22 | 24 |
|
23 |
| - ::free(::malloc(64)); |
| 25 | +TEST_F(test, proxyLib_basic) { |
| 26 | + |
| 27 | + ::free(::malloc(SIZE_64)); |
24 | 28 |
|
25 | 29 | // a check to verify we are running the proxy library
|
26 | 30 | void *ptr = (void *)0x01;
|
| 31 | + |
27 | 32 | #ifdef _WIN32
|
28 | 33 | size_t size = _msize(ptr);
|
29 | 34 | #elif __APPLE__
|
30 | 35 | size_t size = ::malloc_size(ptr);
|
31 | 36 | #else
|
32 | 37 | size_t size = ::malloc_usable_size(ptr);
|
33 | 38 | #endif
|
| 39 | + |
34 | 40 | ASSERT_EQ(size, 0xDEADBEEF);
|
35 | 41 | }
|
| 42 | + |
| 43 | +TEST_F(test, proxyLib_realloc_size0) { |
| 44 | + // realloc(ptr, 0) == free (ptr) |
| 45 | + // realloc(ptr, 0) returns NULL |
| 46 | + ASSERT_EQ(::realloc(::malloc(SIZE_64), 0), nullptr); |
| 47 | +} |
| 48 | + |
| 49 | +TEST_F(test, proxyLib_malloc_usable_size) { |
| 50 | + |
| 51 | + void *ptr = ::malloc(SIZE_64); |
| 52 | + |
| 53 | +#ifdef _WIN32 |
| 54 | + size_t size = _msize(ptr); |
| 55 | +#elif __APPLE__ |
| 56 | + size_t size = ::malloc_size(ptr); |
| 57 | +#else |
| 58 | + size_t size = ::malloc_usable_size(ptr); |
| 59 | +#endif |
| 60 | + |
| 61 | + ASSERT_EQ((int)(size == 0 || size >= SIZE_64), 1); |
| 62 | + |
| 63 | + ::free(ptr); |
| 64 | +} |
| 65 | + |
| 66 | +TEST_F(test, proxyLib_aligned_alloc) { |
| 67 | +#ifdef _WIN32 |
| 68 | + void *ptr = _aligned_malloc(SIZE_64, ALIGN_1024); |
| 69 | +#else |
| 70 | + void *ptr = ::aligned_alloc(ALIGN_1024, SIZE_64); |
| 71 | +#endif |
| 72 | + |
| 73 | + ASSERT_EQ((int)(IS_ALIGNED((uintptr_t)ptr, ALIGN_1024)), 1); |
| 74 | + |
| 75 | +#ifdef _WIN32 |
| 76 | + _aligned_free(ptr); |
| 77 | +#else |
| 78 | + ::free(ptr); |
| 79 | +#endif |
| 80 | +} |
0 commit comments