[libc-commits] [libc] [libc] Add Linux mman extension remap_file_pages. (PR #110307)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Oct 3 11:31:32 PDT 2024


================
@@ -0,0 +1,88 @@
+//===-- Unittests for remap_file_pages ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/errno/libc_errno.h"
+#include "src/sys/mman/mmap.h"
+#include "src/sys/mman/munmap.h"
+#include "src/sys/mman/remap_file_pages.h"
+#include "src/unistd/sysconf.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+#include <fcntl.h>
+
+#include <sys/mman.h>
+
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+
+TEST(LlvmLibcRemapFilePagesTest, NoError) {
+  size_t page_size = sysconf(_SC_PAGE_SIZE);
+  ASSERT_GT(page_size, size_t(0));
+
+  // Create a file-backed mapping
+  int fd = open("/dev/zero", O_RDWR);
----------------
michaelrj-google wrote:

If you're opening a file in a test you should use a file in the same directory as the test, similar to what's done in [`access_test`](https://github.com/llvm/llvm-project/blob/main/libc/test/src/unistd/access_test.cpp#L26-L27)

also small nit: this should use `LIBC_NAMESPACE::open`.

https://github.com/llvm/llvm-project/pull/110307


More information about the libc-commits mailing list