Skip to content

improve readability in the freeErrorPropagation test #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
22 changes: 12 additions & 10 deletions test/pools/disjoint_pool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023 Intel Corporation
// 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

Expand All @@ -22,17 +22,19 @@ using umf_test::test;
using namespace umf_test;

TEST_F(test, freeErrorPropagation) {
static umf_result_t freeReturn = UMF_RESULT_SUCCESS;
static umf_result_t expectedResult = UMF_RESULT_SUCCESS;
struct memory_provider : public umf_test::provider_base_t {
umf_result_t alloc(size_t size, size_t, void **ptr) noexcept {
*ptr = malloc(size);
return UMF_RESULT_SUCCESS;
}

umf_result_t free(void *ptr, [[maybe_unused]] size_t size) noexcept {
if (freeReturn == UMF_RESULT_SUCCESS) {
// do the actual free only when we expect the success
if (expectedResult == UMF_RESULT_SUCCESS) {
::free(ptr);
}
return freeReturn;
return expectedResult;
}
};
umf_memory_provider_ops_t provider_ops =
Expand All @@ -57,15 +59,15 @@ TEST_F(test, freeErrorPropagation) {
static constexpr size_t size = 1024;
void *ptr = umfPoolMalloc(pool, size);

freeReturn = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
// this umfPoolFree() will not free the memory
auto freeRet = umfPoolFree(pool, ptr);
EXPECT_EQ(freeRet, freeReturn);
expectedResult = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
umf_result_t testResult = umfPoolFree(pool, ptr);
EXPECT_EQ(testResult, expectedResult);
expectedResult = UMF_RESULT_SUCCESS;

freeReturn = UMF_RESULT_SUCCESS;
// free the memory to avoid memory leak
freeRet = umfPoolFree(pool, ptr);
EXPECT_EQ(freeRet, freeReturn);
testResult = umfPoolFree(pool, ptr);
EXPECT_EQ(testResult, expectedResult);
}

TEST_F(test, sharedLimits) {
Expand Down