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
18 changes: 18 additions & 0 deletions test/common/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,25 @@ typedef struct pool_base_t {
umf_result_t get_last_allocation_error() noexcept {
return UMF_RESULT_SUCCESS;
}
umf_result_t get_name(const char **name) noexcept {
if (name) {
*name = "pool_base";
}
return UMF_RESULT_SUCCESS;
}
} pool_base_t;

struct malloc_pool : public pool_base_t {
void *malloc(size_t size) noexcept { return ::malloc(size); }

void *calloc(size_t num, size_t size) noexcept {
return ::calloc(num, size);
}

void *realloc(void *ptr, size_t size) noexcept {
return ::realloc(ptr, size);
}

void *aligned_malloc(size_t size, size_t alignment) noexcept {
#ifdef _WIN32
(void)size; // unused
Expand All @@ -143,6 +152,7 @@ struct malloc_pool : public pool_base_t {
return ::aligned_alloc(alignment, size);
#endif
}

umf_result_t malloc_usable_size(const void *ptr, size_t *size) noexcept {
if (size) {
#ifdef _WIN32
Expand All @@ -155,10 +165,18 @@ struct malloc_pool : public pool_base_t {
}
return UMF_RESULT_SUCCESS;
}

umf_result_t free(void *ptr) noexcept {
::free(ptr);
return UMF_RESULT_SUCCESS;
}

umf_result_t get_name(const char **name) noexcept {
if (name) {
*name = "malloc_pool";
}
return UMF_RESULT_SUCCESS;
}
};

umf_memory_pool_ops_t MALLOC_POOL_OPS =
Expand Down
6 changes: 6 additions & 0 deletions test/pools/pool_base_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ struct base_alloc_pool : public umf_test::pool_base_t {
umf_result_t get_last_allocation_error() {
return umf_test::getPoolLastStatusRef<base_alloc_pool>();
}
umf_result_t get_name(const char **name) noexcept {
if (name) {
*name = "base_alloc_pool";
}
return UMF_RESULT_SUCCESS;
}
};

umf_memory_pool_ops_t BA_POOL_OPS =
Expand Down
17 changes: 9 additions & 8 deletions test/utils/cpp_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ using provider_unique_handle_t =
#define UMF_ASSIGN_OP(ops, type, func, default_return) \
ops.func = [](void *obj, auto... args) { \
try { \
if (!obj) { \
return type().func(args...); \
} \
return reinterpret_cast<type *>(obj)->func(args...); \
} catch (...) { \
return default_return; \
Expand All @@ -43,6 +46,9 @@ using provider_unique_handle_t =
#define UMF_ASSIGN_OP_NORETURN(ops, type, func) \
ops.func = [](void *obj, auto... args) { \
try { \
if (!obj) { \
return type().func(args...); \
} \
return reinterpret_cast<type *>(obj)->func(args...); \
} catch (...) { \
} \
Expand Down Expand Up @@ -76,15 +82,10 @@ template <typename T> umf_memory_pool_ops_t poolOpsBase() {
UMF_ASSIGN_OP(ops, T, calloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, aligned_malloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, realloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, malloc_usable_size, UMF_RESULT_SUCCESS);
UMF_ASSIGN_OP(ops, T, free, UMF_RESULT_SUCCESS);
UMF_ASSIGN_OP(ops, T, get_name, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, malloc_usable_size, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, free, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, get_last_allocation_error, UMF_RESULT_ERROR_UNKNOWN);
ops.get_name = [](void *, const char **name) {
if (name) {
*name = "test_pool";
}
return UMF_RESULT_SUCCESS;
};
return ops;
}

Expand Down
Loading