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
4
@@ -22,17 +22,19 @@ using umf_test::test;
22
22
using namespace umf_test ;
23
23
24
24
TEST_F (test, freeErrorPropagation) {
25
- static umf_result_t freeReturn = UMF_RESULT_SUCCESS;
25
+ static umf_result_t expectedResult = UMF_RESULT_SUCCESS;
26
26
struct memory_provider : public umf_test ::provider_base_t {
27
27
umf_result_t alloc (size_t size, size_t , void **ptr) noexcept {
28
28
*ptr = malloc (size);
29
29
return UMF_RESULT_SUCCESS;
30
30
}
31
+
31
32
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) {
33
35
::free (ptr);
34
36
}
35
- return freeReturn ;
37
+ return expectedResult ;
36
38
}
37
39
};
38
40
umf_memory_provider_ops_t provider_ops =
@@ -57,15 +59,15 @@ TEST_F(test, freeErrorPropagation) {
57
59
static constexpr size_t size = 1024 ;
58
60
void *ptr = umfPoolMalloc (pool, size);
59
61
60
- freeReturn = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
61
62
// this umfPoolFree() will not free the memory
62
- auto freeRet = umfPoolFree (pool, ptr);
63
- EXPECT_EQ (freeRet, freeReturn);
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;
64
67
65
- freeReturn = UMF_RESULT_SUCCESS;
66
68
// free the memory to avoid memory leak
67
- freeRet = umfPoolFree (pool, ptr);
68
- EXPECT_EQ (freeRet, freeReturn );
69
+ testResult = umfPoolFree (pool, ptr);
70
+ EXPECT_EQ (testResult, expectedResult );
69
71
}
70
72
71
73
TEST_F (test, sharedLimits) {
0 commit comments