3
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
4
5
5
#ifndef _WIN32
6
+ #include " test_helpers_linux.h"
6
7
#include < fcntl.h>
7
8
#include < sys/stat.h>
8
9
#include < sys/types.h>
11
12
#include " base.hpp"
12
13
13
14
#include " cpp_helpers.hpp"
15
+ #include " test_helpers.h"
14
16
15
17
#include < umf/memory_provider.h>
16
18
#include < umf/providers/provider_devdax_memory.h>
@@ -137,10 +139,6 @@ static void test_alloc_failure(umf_memory_provider_handle_t provider,
137
139
// TESTS
138
140
139
141
// 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.
144
142
TEST_F (test, test_if_mapped_with_MAP_SYNC) {
145
143
umf_memory_provider_handle_t hProvider = nullptr ;
146
144
umf_result_t umf_result;
@@ -167,56 +165,16 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
167
165
umf_result = umfMemoryProviderAlloc (hProvider, size, 0 , (void **)&buf);
168
166
ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
169
167
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
- }
189
168
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);
212
170
213
171
umf_result = umfMemoryProviderFree (hProvider, buf, size);
214
172
ASSERT_EQ (umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
215
173
216
174
umfMemoryProviderDestroy (hProvider);
217
175
218
176
// fail test if the "sf" flag was not found
219
- ASSERT_NE (sf_flag, nullptr );
177
+ ASSERT_EQ (flag_found, true );
220
178
}
221
179
222
180
// positive tests using test_alloc_free_success
0 commit comments