Skip to content

Commit 0da8a2d

Browse files
committed
Add test if FSDAX is mapped with the MAP_SYNC flag
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent fe80d68 commit 0da8a2d

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

.github/workflows/dax.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ permissions:
2222

2323
env:
2424
UMF_TESTS_DEVDAX_NAMESPACE : "0.0"
25+
UMF_TESTS_FSDAX_NAMESPACE : "1.0"
26+
UMF_TESTS_FSDAX_PATH: "/mnt/pmem1/file"
2527
BUILD_DIR : "${{github.workspace}}/build"
2628
INSTL_DIR : "${{github.workspace}}/../install-dir"
2729

@@ -39,11 +41,21 @@ jobs:
3941
steps:
4042
- name: Check if the devdax exists, print out UMF_TESTS_DEVDAX_PATH and UMF_TESTS_DEVDAX_SIZE
4143
run: |
42-
ndctl list -N --device-dax
44+
echo UMF_TESTS_DEVDAX_NAMESPACE="${UMF_TESTS_DEVDAX_NAMESPACE}"
45+
ndctl list --namespace=namespace${UMF_TESTS_DEVDAX_NAMESPACE} --device-dax
4346
ls -al /dev/dax${UMF_TESTS_DEVDAX_NAMESPACE}
4447
echo UMF_TESTS_DEVDAX_PATH="/dev/dax${UMF_TESTS_DEVDAX_NAMESPACE}"
4548
echo UMF_TESTS_DEVDAX_SIZE="$(ndctl list --namespace=namespace${UMF_TESTS_DEVDAX_NAMESPACE} | grep size | cut -d':' -f2 | cut -d',' -f1)"
4649
50+
- name: Check if the FSDAX exists
51+
run: |
52+
echo UMF_TESTS_FSDAX_NAMESPACE="${UMF_TESTS_FSDAX_NAMESPACE}"
53+
echo UMF_TESTS_FSDAX_PATH="${UMF_TESTS_FSDAX_PATH}"
54+
ndctl list --namespace=namespace${UMF_TESTS_FSDAX_NAMESPACE}
55+
ls -al /dev/$(echo $UMF_TESTS_FSDAX_PATH | cut -d'/' -f3)
56+
ls -al /mnt/$(echo $UMF_TESTS_FSDAX_PATH | cut -d'/' -f3)
57+
mount | grep -e "/dev/$(echo $UMF_TESTS_FSDAX_PATH | cut -d'/' -f3)"
58+
4759
- name: Checkout
4860
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4961
with:
@@ -78,3 +90,7 @@ jobs:
7890
UMF_TESTS_DEVDAX_PATH="/dev/dax${UMF_TESTS_DEVDAX_NAMESPACE}"
7991
UMF_TESTS_DEVDAX_SIZE="$(ndctl list --namespace=namespace${UMF_TESTS_DEVDAX_NAMESPACE} | grep size | cut -d':' -f2 | cut -d',' -f1)"
8092
ctest -C ${{matrix.build_type}} -R devdax -V
93+
94+
- name: Run only tests of the file memory provider with FSDAX
95+
working-directory: ${{env.BUILD_DIR}}
96+
run: ctest -C ${{matrix.build_type}} -R umf-provider_file_memory -V

test/provider_file_memory.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5+
#include <fcntl.h>
6+
#include <sys/stat.h>
7+
#include <sys/types.h>
8+
59
#include "base.hpp"
610

711
#include "cpp_helpers.hpp"
@@ -121,6 +125,85 @@ static void test_alloc_failure(umf_memory_provider_handle_t provider,
121125

122126
// TESTS
123127

128+
// Test checking if FSDAX was mapped with the MAP_SYNC flag:
129+
// 1) Open and read the /proc/self/smaps file.
130+
// 2) Look for the section of the FSDAX file (for example /mnt/pmem1/file path).
131+
// 3) Check if the VmFlags of the /mnt/pmem1/file contains the "sf" flag
132+
// marking that the FSDAX file was mapped with the MAP_SYNC flag.
133+
TEST_F(test, test_if_mapped_with_MAP_SYNC) {
134+
umf_memory_provider_handle_t hProvider = nullptr;
135+
umf_result_t umf_result;
136+
137+
char *path = getenv("UMF_TESTS_FSDAX_PATH");
138+
if (path == nullptr || path[0] == 0) {
139+
GTEST_SKIP() << "Test skipped, UMF_TESTS_FSDAX_PATH is not set";
140+
}
141+
142+
auto params = umfFileMemoryProviderParamsDefault(path);
143+
params.visibility = UMF_MEM_MAP_SYNC;
144+
145+
umf_result = umfMemoryProviderCreate(umfFileMemoryProviderOps(), &params,
146+
&hProvider);
147+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
148+
ASSERT_NE(hProvider, nullptr);
149+
150+
char *buf;
151+
size_t size = 2 * 1024 * 1024; // 2MB
152+
umf_result = umfMemoryProviderAlloc(hProvider, size, 0, (void **)&buf);
153+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
154+
ASSERT_NE(buf, nullptr);
155+
memset(buf, 0, size);
156+
157+
int fd = open("/proc/self/smaps", O_RDONLY);
158+
ASSERT_NE(fd, -1);
159+
160+
// number of bytes read from the file
161+
ssize_t nbytes = 1;
162+
// string starting from the path of the fsdax
163+
char *fsdax = nullptr;
164+
165+
// Read the "/proc/self/smaps" file
166+
// until the path of the fsdax is found
167+
// or EOF is reached.
168+
while (nbytes > 0 && fsdax == nullptr) {
169+
memset(buf, 0, nbytes); // erase previous data
170+
nbytes = read(fd, buf, size);
171+
// look for the path of the fsdax
172+
fsdax = strstr(buf, path);
173+
}
174+
175+
// String starting from the "sf" flag
176+
// marking that memory was mapped with the MAP_SYNC flag.
177+
char *sf_flag = nullptr;
178+
179+
if (fsdax) {
180+
// look for the "VmFlags:" string
181+
char *VmFlags = strstr(fsdax, "VmFlags:");
182+
if (VmFlags) {
183+
// look for the EOL
184+
char *eol = strstr(VmFlags, "\n");
185+
if (eol) {
186+
// End the VmFlags string at EOL.
187+
*eol = 0;
188+
// Now the VmFlags string contains only one line with all VmFlags.
189+
190+
// Look for the "sf" flag in VmFlags
191+
// marking that memory was mapped
192+
// with the MAP_SYNC flag.
193+
sf_flag = strstr(VmFlags, "sf");
194+
}
195+
}
196+
}
197+
198+
umf_result = umfMemoryProviderFree(hProvider, buf, size);
199+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
200+
201+
umfMemoryProviderDestroy(hProvider);
202+
203+
// fail test if the "sf" flag was not found
204+
ASSERT_NE(sf_flag, nullptr);
205+
}
206+
124207
// positive tests using test_alloc_free_success
125208

126209
umf_file_memory_provider_params_t get_file_params_shared(char *path) {

0 commit comments

Comments
 (0)