Skip to content

Commit a0fb36a

Browse files
authored
Merge pull request #748 from ldorau/Add_test_if_FSDAX_is_mapped_with_the_MAP_SYNC_flag
Add test if FSDAX is mapped with the MAP_SYNC flag
2 parents 3150f2e + 64de550 commit a0fb36a

File tree

8 files changed

+236
-117
lines changed

8 files changed

+236
-117
lines changed

.github/workflows/dax.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#
2+
# This workflow builds and tests the DEVDAX memory provider
3+
# and the file memory provider with FSDAX.
4+
# It requires:
5+
# - a DAX device (e.g. /dev/dax0.0) and
6+
# - a FSDAX device (e.g. /dev/pmem1)
7+
# configured and mounted in the OS.
8+
#
9+
# The DAX device should be specified using the
10+
# UMF_TESTS_DEVDAX_PATH and UMF_TESTS_DEVDAX_SIZE environment variables.
11+
#
12+
# The FSDAX device should be mounted in the OS (e.g. /mnt/pmem1)
13+
# and the UMF_TESTS_FSDAX_PATH environment variable
14+
# should contain a path to a file o this FSDAX device.
15+
#
16+
17+
name: Dax
18+
19+
on: [workflow_call]
20+
21+
permissions:
22+
contents: read
23+
24+
env:
25+
DEVDAX_NAMESPACE : "0.0"
26+
FSDAX_NAMESPACE : "1.0"
27+
FSDAX_PMEM: "pmem1"
28+
UMF_TESTS_FSDAX_PATH: "/mnt/pmem1/file"
29+
BUILD_DIR : "${{github.workspace}}/build"
30+
INSTL_DIR : "${{github.workspace}}/../install-dir"
31+
32+
jobs:
33+
dax:
34+
name: Build
35+
# run only on upstream; forks may not have a DAX device
36+
if: github.repository == 'oneapi-src/unified-memory-framework'
37+
strategy:
38+
matrix:
39+
build_type: [Debug, Release]
40+
shared_library: ['ON', 'OFF']
41+
42+
runs-on: ["DSS-DEVDAX", "DSS-Ubuntu"]
43+
steps:
44+
- name: Check configuration of the DEVDAX
45+
run: |
46+
echo DEVDAX_NAMESPACE="${{env.DEVDAX_NAMESPACE}}"
47+
ndctl list --namespace=namespace${{env.DEVDAX_NAMESPACE}} --device-dax
48+
ls -al /dev/dax${{env.DEVDAX_NAMESPACE}}
49+
echo UMF_TESTS_DEVDAX_PATH="/dev/dax${{env.DEVDAX_NAMESPACE}}"
50+
echo UMF_TESTS_DEVDAX_SIZE="$(ndctl list --namespace=namespace${{env.DEVDAX_NAMESPACE}} | grep size | cut -d':' -f2 | cut -d',' -f1)"
51+
52+
- name: Check configuration of the FSDAX
53+
run: |
54+
echo FSDAX_NAMESPACE="${{env.FSDAX_NAMESPACE}}"
55+
echo UMF_TESTS_FSDAX_PATH="${{env.UMF_TESTS_FSDAX_PATH}}"
56+
ndctl list --namespace=namespace${{env.FSDAX_NAMESPACE}}
57+
ls -al /dev/${{env.FSDAX_PMEM}} /mnt/${{env.FSDAX_PMEM}}
58+
mount | grep -e "/dev/${{env.FSDAX_PMEM}}"
59+
touch ${{env.UMF_TESTS_FSDAX_PATH}}
60+
rm -f ${{env.UMF_TESTS_FSDAX_PATH}}
61+
62+
- name: Checkout
63+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Configure build
68+
run: >
69+
cmake
70+
-B ${{env.BUILD_DIR}}
71+
-DCMAKE_INSTALL_PREFIX="${{env.INSTL_DIR}}"
72+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
73+
-DCMAKE_C_COMPILER=gcc
74+
-DCMAKE_CXX_COMPILER=g++
75+
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
76+
-DUMF_BUILD_BENCHMARKS=OFF
77+
-DUMF_BUILD_TESTS=ON
78+
-DUMF_BUILD_GPU_TESTS=OFF
79+
-DUMF_BUILD_GPU_EXAMPLES=OFF
80+
-DUMF_FORMAT_CODE_STYLE=OFF
81+
-DUMF_DEVELOPER_MODE=ON
82+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
83+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
84+
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
85+
-DUMF_TESTS_FAIL_ON_SKIP=ON
86+
87+
- name: Build UMF
88+
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $(nproc)
89+
90+
- name: Run the DEVDAX tests
91+
working-directory: ${{env.BUILD_DIR}}
92+
run: >
93+
UMF_TESTS_DEVDAX_PATH="/dev/dax${{env.DEVDAX_NAMESPACE}}"
94+
UMF_TESTS_DEVDAX_SIZE="$(ndctl list --namespace=namespace${{env.DEVDAX_NAMESPACE}} | grep size | cut -d':' -f2 | cut -d',' -f1)"
95+
ctest -C ${{matrix.build_type}} -R devdax -V
96+
97+
- name: Run the FSDAX tests
98+
working-directory: ${{env.BUILD_DIR}}
99+
run: >
100+
UMF_TESTS_FSDAX_PATH=${{env.UMF_TESTS_FSDAX_PATH}}
101+
ctest -C ${{matrix.build_type}} -R umf-provider_file_memory -V

.github/workflows/devdax.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/pr_push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
uses: ./.github/workflows/basic.yml
8989
DevDax:
9090
needs: [FastBuild]
91-
uses: ./.github/workflows/devdax.yml
91+
uses: ./.github/workflows/dax.yml
9292
Sanitizers:
9393
needs: [FastBuild]
9494
uses: ./.github/workflows/sanitizers.yml

test/common/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ set(COMMON_SOURCES
99
provider_null.c
1010
provider_trace.c)
1111

12+
if(LINUX)
13+
set(COMMON_SOURCES ${COMMON_SOURCES} test_helpers_linux.c)
14+
endif(LINUX)
15+
1216
add_umf_library(
1317
NAME umf_test_common
1418
TYPE STATIC

test/common/test_helpers_linux.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
// This file contains tests for UMF pool API
5+
6+
#include <fcntl.h>
7+
#include <stdbool.h>
8+
#include <string.h>
9+
#include <sys/stat.h>
10+
#include <sys/types.h>
11+
#include <unistd.h>
12+
13+
#include "test_helpers_linux.h"
14+
15+
// Check if the file given by the 'path' argument was mapped with the MAP_SYNC flag:
16+
// 1) Open and read the /proc/self/smaps file.
17+
// 2) Look for the section of the 'path' file.
18+
// 3) Check if the VmFlags of the 'path' file contains the "sf" flag
19+
// marking that the file was mapped with the MAP_SYNC flag.
20+
bool is_mapped_with_MAP_SYNC(char *path, char *buf, size_t size_buf) {
21+
memset(buf, 0, size_buf);
22+
23+
int fd = open("/proc/self/smaps", O_RDONLY);
24+
if (fd == -1) {
25+
return false;
26+
}
27+
28+
// number of bytes read from the file
29+
ssize_t nbytes = 1;
30+
// string starting from the path of the smaps
31+
char *smaps = NULL;
32+
33+
// Read the "/proc/self/smaps" file
34+
// until the path of the smaps is found
35+
// or EOF is reached.
36+
while (nbytes > 0 && smaps == NULL) {
37+
memset(buf, 0, nbytes); // erase previous data
38+
nbytes = read(fd, buf, size_buf);
39+
// look for the path of the smaps
40+
smaps = strstr(buf, path);
41+
}
42+
43+
// String starting from the "sf" flag
44+
// marking that memory was mapped with the MAP_SYNC flag.
45+
char *sf_flag = NULL;
46+
47+
if (smaps) {
48+
// look for the "VmFlags:" string
49+
char *VmFlags = strstr(smaps, "VmFlags:");
50+
if (VmFlags) {
51+
// look for the EOL
52+
char *eol = strstr(VmFlags, "\n");
53+
if (eol) {
54+
// End the VmFlags string at EOL.
55+
*eol = 0;
56+
// Now the VmFlags string contains only one line with all VmFlags.
57+
58+
// Look for the "sf" flag in VmFlags
59+
// marking that memory was mapped
60+
// with the MAP_SYNC flag.
61+
sf_flag = strstr(VmFlags, "sf");
62+
}
63+
}
64+
}
65+
66+
return (sf_flag != NULL);
67+
}

test/common/test_helpers_linux.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// This file contains helpers for tests for UMF pool API
5+
6+
#ifndef UMF_TEST_HELPERS_LINUX_H
7+
#define UMF_TEST_HELPERS_LINUX_H 1
8+
9+
#include <stddef.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
bool is_mapped_with_MAP_SYNC(char *path, char *buf, size_t size_buf);
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
21+
#endif /* UMF_TEST_HELPERS_LINUX_H */

test/provider_devdax_memory.cpp

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#ifndef _WIN32
6+
#include "test_helpers_linux.h"
67
#include <fcntl.h>
78
#include <sys/stat.h>
89
#include <sys/types.h>
@@ -11,6 +12,7 @@
1112
#include "base.hpp"
1213

1314
#include "cpp_helpers.hpp"
15+
#include "test_helpers.h"
1416

1517
#include <umf/memory_provider.h>
1618
#include <umf/providers/provider_devdax_memory.h>
@@ -137,10 +139,6 @@ static void test_alloc_failure(umf_memory_provider_handle_t provider,
137139
// TESTS
138140

139141
// Test checking if devdax was mapped with the MAP_SYNC flag:
140-
// 1) Open and read the /proc/self/smaps file.
141-
// 2) Look for the section of the devdax (the /dev/daxX.Y path).
142-
// 3) Check if the VmFlags of the /dev/daxX.Y contains the "sf" flag
143-
// marking that the devdax was mapped with the MAP_SYNC flag.
144142
TEST_F(test, test_if_mapped_with_MAP_SYNC) {
145143
umf_memory_provider_handle_t hProvider = nullptr;
146144
umf_result_t umf_result;
@@ -167,56 +165,16 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
167165
umf_result = umfMemoryProviderAlloc(hProvider, size, 0, (void **)&buf);
168166
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
169167
ASSERT_NE(buf, nullptr);
170-
memset(buf, 0, size);
171-
172-
int fd = open("/proc/self/smaps", O_RDONLY);
173-
ASSERT_NE(fd, -1);
174-
175-
// number of bytes read from the file
176-
ssize_t nbytes = 1;
177-
// string starting from the path of the devdax
178-
char *devdax = nullptr;
179-
180-
// Read the "/proc/self/smaps" file
181-
// until the path of the devdax is found
182-
// or EOF is reached.
183-
while (nbytes > 0 && devdax == nullptr) {
184-
memset(buf, 0, nbytes); // erase previous data
185-
nbytes = read(fd, buf, size);
186-
// look for the path of the devdax
187-
devdax = strstr(buf, path);
188-
}
189168

190-
// String starting from the "sf" flag
191-
// marking that memory was mapped with the MAP_SYNC flag.
192-
char *sf_flag = nullptr;
193-
194-
if (devdax) {
195-
// look for the "VmFlags:" string
196-
char *VmFlags = strstr(devdax, "VmFlags:");
197-
if (VmFlags) {
198-
// look for the EOL
199-
char *eol = strstr(VmFlags, "\n");
200-
if (eol) {
201-
// End the VmFlags string at EOL.
202-
*eol = 0;
203-
// Now the VmFlags string contains only one line with all VmFlags.
204-
205-
// Look for the "sf" flag in VmFlags
206-
// marking that memory was mapped
207-
// with the MAP_SYNC flag.
208-
sf_flag = strstr(VmFlags, "sf");
209-
}
210-
}
211-
}
169+
bool flag_found = is_mapped_with_MAP_SYNC(path, buf, size);
212170

213171
umf_result = umfMemoryProviderFree(hProvider, buf, size);
214172
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
215173

216174
umfMemoryProviderDestroy(hProvider);
217175

218176
// fail test if the "sf" flag was not found
219-
ASSERT_NE(sf_flag, nullptr);
177+
ASSERT_EQ(flag_found, true);
220178
}
221179

222180
// positive tests using test_alloc_free_success

0 commit comments

Comments
 (0)