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>
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.
144142TEST_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