Skip to content

Commit d6c5327

Browse files
committed
Add a test for not aligned fixed memory buffer
Add a test for not aligned fixed memory buffer: - coarseTest_basic_non_aligned_fixed_memory Signed-off-by: Lukasz Dorau <[email protected]>
1 parent a406dde commit d6c5327

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/coarse_lib.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -1349,3 +1349,48 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseTest_alignment_fixed_memory) {
13491349

13501350
coarse_delete(ch);
13511351
}
1352+
1353+
TEST_P(CoarseWithMemoryStrategyTest,
1354+
coarseTest_basic_non_aligned_fixed_memory) {
1355+
// preallocate some memory and initialize the vector with zeros
1356+
const size_t buff_size = 20 * MB + coarse_params.page_size;
1357+
std::vector<char> buffer(buff_size, 0);
1358+
1359+
void *buf_aligned = (void *)ALIGN_UP_SAFE((uintptr_t)buffer.data(),
1360+
coarse_params.page_size);
1361+
ASSERT_NE(buf_aligned, nullptr);
1362+
1363+
void *buf_non_aligned = (void *)((uintptr_t)buf_aligned + 64);
1364+
size_t buf_non_aligned_size =
1365+
buff_size - ((uintptr_t)buf_non_aligned - (uintptr_t)buffer.data());
1366+
buf_non_aligned_size =
1367+
ALIGN_DOWN(buf_non_aligned_size, coarse_params.page_size);
1368+
1369+
coarse_params.cb.alloc = NULL;
1370+
coarse_params.cb.free = NULL;
1371+
1372+
umf_result = coarse_new(&coarse_params, &coarse_handle);
1373+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
1374+
ASSERT_NE(coarse_handle, nullptr);
1375+
1376+
coarse_t *ch = coarse_handle;
1377+
char *ptr = nullptr;
1378+
1379+
umf_result =
1380+
coarse_add_memory_fixed(ch, buf_non_aligned, buf_non_aligned_size);
1381+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
1382+
1383+
ASSERT_EQ(coarse_get_stats(ch).used_size, 0 * MB);
1384+
ASSERT_EQ(coarse_get_stats(ch).alloc_size, buf_non_aligned_size);
1385+
ASSERT_EQ(coarse_get_stats(ch).num_all_blocks, 1);
1386+
1387+
umf_result = coarse_alloc(ch, buf_non_aligned_size, 0, (void **)&ptr);
1388+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY);
1389+
ASSERT_EQ(ptr, nullptr);
1390+
1391+
ASSERT_EQ(coarse_get_stats(ch).used_size, 0 * MB);
1392+
ASSERT_EQ(coarse_get_stats(ch).alloc_size, buf_non_aligned_size);
1393+
ASSERT_EQ(coarse_get_stats(ch).num_all_blocks, 1);
1394+
1395+
coarse_delete(ch);
1396+
}

0 commit comments

Comments
 (0)