Skip to content

Commit 95b0889

Browse files
committed
Add tests for HOST ALL memspace
1 parent 7577355 commit 95b0889

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

test/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function(add_umf_test)
5050
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "umf")
5151

5252
if(WIN32)
53-
set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT_MODIFICATION
53+
set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT_MODIFICATION
5454
"PATH=path_list_append:../bin/$<CONFIG>")
5555
endif()
5656

@@ -61,7 +61,7 @@ endfunction()
6161

6262
add_subdirectory(common)
6363

64-
add_umf_test(NAME base
64+
add_umf_test(NAME base
6565
SRCS base.cpp)
6666
add_umf_test(NAME memoryPool
6767
SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp)
@@ -129,6 +129,9 @@ if(UMF_BUILD_OS_MEMORY_PROVIDER AND LINUX) # OS-specific functions are implement
129129
add_umf_test(NAME provider_os_memory_config
130130
SRCS provider_os_memory_config.cpp
131131
LIBS umf_utils ${LIBNUMA_LIBRARIES})
132+
add_umf_test(NAME memspace_host_all
133+
SRCS memspace_host_all.cpp
134+
LIBS ${LIBNUMA_LIBRARIES})
132135
endif()
133136

134137
if(UMF_BUILD_SHARED_LIBRARY)

test/memspace_host_all.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#include "base.hpp"
6+
#include "test_helpers.h"
7+
8+
#include <umf/memspace.h>
9+
10+
using umf_test::test;
11+
12+
#define SIZE_4K (4096)
13+
14+
struct predefinedMemspaceTest : test {
15+
16+
void SetUp() override {
17+
::test::SetUp();
18+
19+
hMemspace = umfMemspaceHostAllGet();
20+
UT_ASSERTne(hMemspace, nullptr);
21+
}
22+
23+
umf_memspace_handle_t hMemspace;
24+
};
25+
26+
struct predefinedMemspaceProviderTest : predefinedMemspaceTest {
27+
28+
void SetUp() override {
29+
::predefinedMemspaceTest::SetUp();
30+
31+
enum umf_result_t ret =
32+
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &provider);
33+
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
34+
UT_ASSERTne(provider, nullptr);
35+
}
36+
37+
void TearDown() override {
38+
::predefinedMemspaceTest::TearDown();
39+
40+
umfMemoryProviderDestroy(provider);
41+
}
42+
43+
umf_memory_provider_handle_t provider = nullptr;
44+
};
45+
46+
TEST_F(test, memspaceGet) {
47+
umf_memspace_handle_t hMemspace = umfMemspaceHostAllGet();
48+
UT_ASSERTne(hMemspace, nullptr);
49+
}
50+
51+
TEST_F(predefinedMemspaceProviderTest, allocFree) {
52+
void *ptr = nullptr;
53+
size_t size = SIZE_4K;
54+
size_t alignment = 0;
55+
56+
enum umf_result_t ret =
57+
umfMemoryProviderAlloc(provider, size, alignment, &ptr);
58+
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
59+
UT_ASSERTne(ptr, nullptr);
60+
61+
memset(ptr, 0xFF, size);
62+
63+
ret = umfMemoryProviderFree(provider, ptr, size);
64+
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
65+
}

0 commit comments

Comments
 (0)