Skip to content

Commit 465e263

Browse files
committed
improve readability in the freeErrorPropagation test
1 parent 7be09f0 commit 465e263

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

test/pools/disjoint_pool.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2023 Intel Corporation
1+
// Copyright (C) 2023-2024 Intel Corporation
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

@@ -22,17 +22,19 @@ using umf_test::test;
2222
using namespace umf_test;
2323

2424
TEST_F(test, freeErrorPropagation) {
25-
static umf_result_t freeReturn = UMF_RESULT_SUCCESS;
25+
static umf_result_t expectedResult = UMF_RESULT_SUCCESS;
2626
struct memory_provider : public umf_test::provider_base_t {
2727
umf_result_t alloc(size_t size, size_t, void **ptr) noexcept {
2828
*ptr = malloc(size);
2929
return UMF_RESULT_SUCCESS;
3030
}
31+
3132
umf_result_t free(void *ptr, [[maybe_unused]] size_t size) noexcept {
32-
if (freeReturn == UMF_RESULT_SUCCESS) {
33+
// do the actual free only when we expect the success
34+
if (expectedResult == UMF_RESULT_SUCCESS) {
3335
::free(ptr);
3436
}
35-
return freeReturn;
37+
return expectedResult;
3638
}
3739
};
3840
umf_memory_provider_ops_t provider_ops =
@@ -57,15 +59,14 @@ TEST_F(test, freeErrorPropagation) {
5759
static constexpr size_t size = 1024;
5860
void *ptr = umfPoolMalloc(pool, size);
5961

60-
freeReturn = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
6162
// this umfPoolFree() will not free the memory
62-
auto freeRet = umfPoolFree(pool, ptr);
63-
EXPECT_EQ(freeRet, freeReturn);
64-
65-
freeReturn = UMF_RESULT_SUCCESS;
63+
expectedResult = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
64+
umf_result_t testResult = umfPoolFree(pool, ptr);
65+
EXPECT_EQ(testResult, expectedResult);
66+
expectedResult = UMF_RESULT_SUCCESS;
6667
// free the memory to avoid memory leak
67-
freeRet = umfPoolFree(pool, ptr);
68-
EXPECT_EQ(freeRet, freeReturn);
68+
testResult = umfPoolFree(pool, ptr);
69+
EXPECT_EQ(testResult, expectedResult);
6970
}
7071

7172
TEST_F(test, sharedLimits) {

0 commit comments

Comments
 (0)