Skip to content

Commit cce29c1

Browse files
committed
add tests for backward compatility
1 parent e5d3861 commit cce29c1

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

test/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,20 @@ if(LINUX
625625
"LD_LIBRARY_PATH=path_list_append:${CMAKE_BINARY_DIR}/lib")
626626
endif()
627627

628+
if(LINUX
629+
AND UMF_BUILD_SHARED_LIBRARY
630+
AND NOT UMF_DISABLE_HWLOC)
631+
add_umf_test(
632+
NAME multiple_symbols
633+
SRCS test_multiple_symbols.c
634+
LIBS dl)
635+
# append LD_LIBRARY_PATH to the libumf
636+
set_property(
637+
TEST umf-multiple_symbols
638+
PROPERTY ENVIRONMENT_MODIFICATION
639+
"LD_LIBRARY_PATH=path_list_append:${CMAKE_BINARY_DIR}/lib")
640+
endif()
641+
628642
# Tests of examples as standalone projects. TODO: enable this for Windows (maybe
629643
# replace test_examples.sh with CMake script?)
630644
if(LINUX

test/test_multiple_symbols.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (C) 2024-2025 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include <assert.h>
9+
#include <dlfcn.h>
10+
#include <stddef.h>
11+
#include <stdint.h>
12+
#include <stdio.h>
13+
14+
#include <umf/memory_provider_ops.h>
15+
16+
typedef void *(*umfGetPtr_t)(void);
17+
18+
// UMF so handle
19+
static void *h_umf;
20+
21+
static void load_symbol(void *handle, const char *name, void **dest) {
22+
void *symbol = dlsym(handle, name);
23+
if (symbol == NULL) {
24+
fprintf(stderr, "umf_load: symbol %s NOT found\n", name);
25+
*dest = NULL;
26+
return;
27+
}
28+
29+
fprintf(stderr, "umf_load: symbol found: %s\n", name);
30+
31+
*dest = symbol;
32+
}
33+
34+
static int umf_load() {
35+
umfGetPtr_t umfFileMemoryProviderOps;
36+
umfGetPtr_t umfFileMemoryProviderOps_0_11;
37+
umfGetPtr_t umfDevDaxMemoryProviderOps;
38+
umfGetPtr_t umfDevDaxMemoryProviderOps_0_11;
39+
40+
char *umf_lib_name = "libumf.so";
41+
h_umf = dlopen(umf_lib_name, RTLD_LAZY);
42+
if (h_umf == NULL) {
43+
fprintf(stderr, "umf_load: UMF library not found (%s)\n", umf_lib_name);
44+
return -1;
45+
}
46+
47+
load_symbol(h_umf, "umfFileMemoryProviderOps",
48+
(void **)&umfFileMemoryProviderOps);
49+
if (umfFileMemoryProviderOps == NULL) {
50+
goto err_dlclose;
51+
} else {
52+
umf_memory_provider_ops_t *ops = umfFileMemoryProviderOps();
53+
if (ops == NULL) {
54+
fprintf(stderr, "umfFileMemoryProviderOps: NULL ops\n");
55+
goto err_dlclose;
56+
}
57+
58+
// default version of umfFileMemoryProviderOps should return ops_0_10
59+
if (ops->version != UMF_MAKE_VERSION(0, 10)) {
60+
fprintf(stderr, "umfFileMemoryProviderOps: bad ops version\n");
61+
goto err_dlclose;
62+
}
63+
}
64+
65+
load_symbol(h_umf, "umfFileMemoryProviderOps_0_11",
66+
(void **)&umfFileMemoryProviderOps_0_11);
67+
if (umfFileMemoryProviderOps_0_11 == NULL) {
68+
goto err_dlclose;
69+
} else {
70+
umf_memory_provider_ops_0_11_t *ops = umfFileMemoryProviderOps_0_11();
71+
if (ops == NULL) {
72+
fprintf(stderr, "umfFileMemoryProviderOps_0_11: NULL ops\n");
73+
goto err_dlclose;
74+
}
75+
76+
if (ops->version != UMF_MAKE_VERSION(0, 11)) {
77+
fprintf(stderr, "umfFileMemoryProviderOps_0_11: bad ops version\n");
78+
goto err_dlclose;
79+
}
80+
}
81+
82+
load_symbol(h_umf, "umfDevDaxMemoryProviderOps",
83+
(void **)&umfDevDaxMemoryProviderOps);
84+
if (umfDevDaxMemoryProviderOps == NULL) {
85+
goto err_dlclose;
86+
} else {
87+
umf_memory_provider_ops_t *ops = umfDevDaxMemoryProviderOps();
88+
if (ops == NULL) {
89+
fprintf(stderr, "umfDevDaxMemoryProviderOps: NULL ops\n");
90+
goto err_dlclose;
91+
}
92+
93+
// default version of umfDevDaxMemoryProviderOps should return ops_0_10
94+
if (ops->version != UMF_MAKE_VERSION(0, 10)) {
95+
fprintf(stderr, "umfDevDaxMemoryProviderOps: bad ops version\n");
96+
goto err_dlclose;
97+
}
98+
}
99+
100+
load_symbol(h_umf, "umfDevDaxMemoryProviderOps_0_11",
101+
(void **)&umfDevDaxMemoryProviderOps_0_11);
102+
if (umfDevDaxMemoryProviderOps_0_11 == NULL) {
103+
goto err_dlclose;
104+
} else {
105+
umf_memory_provider_ops_0_11_t *ops = umfDevDaxMemoryProviderOps_0_11();
106+
if (ops == NULL) {
107+
fprintf(stderr, "umfDevDaxMemoryProviderOps_0_11: NULL ops\n");
108+
goto err_dlclose;
109+
}
110+
111+
if (ops->version != UMF_MAKE_VERSION(0, 11)) {
112+
fprintf(stderr,
113+
"umfDevDaxMemoryProviderOps_0_11: bad ops version\n");
114+
goto err_dlclose;
115+
}
116+
}
117+
118+
return 0;
119+
120+
err_dlclose:
121+
dlclose(h_umf);
122+
123+
return -1;
124+
}
125+
126+
static void umf_unload() {
127+
fprintf(stderr, "umf_unload: closing umf library ...\n");
128+
dlclose(h_umf);
129+
fprintf(stderr, "umf_unload: umf library closed\n");
130+
}
131+
132+
int main(void) {
133+
134+
if (umf_load()) {
135+
return -1;
136+
}
137+
138+
umf_unload();
139+
return 0;
140+
}

0 commit comments

Comments
 (0)