Skip to content

Commit db96b76

Browse files
committed
- Add test file creation
- Remove errno resetting
1 parent 6cdfe53 commit db96b76

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libc/test/src/sys/mman/linux/remap_file_pages_test.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/errno/libc_errno.h"
10+
#include "src/fcntl/open.h"
1011
#include "src/sys/mman/mmap.h"
1112
#include "src/sys/mman/munmap.h"
1213
#include "src/sys/mman/remap_file_pages.h"
14+
#include "src/unistd/close.h"
1315
#include "src/unistd/sysconf.h"
1416
#include "test/UnitTest/ErrnoSetterMatcher.h"
1517
#include "test/UnitTest/Test.h"
16-
#include <fcntl.h>
1718

1819
#include <sys/mman.h>
20+
#include <sys/stat.h> // For S_IRWXU
1921

2022
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
2123
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
@@ -25,7 +27,9 @@ TEST(LlvmLibcRemapFilePagesTest, NoError) {
2527
ASSERT_GT(page_size, size_t(0));
2628

2729
// Create a file-backed mapping
28-
int fd = open("/dev/zero", O_RDWR);
30+
constexpr const char *file_name = "noerror.remap_file_pages";
31+
auto test_file = libc_make_test_file_path(file_name);
32+
int fd = LIBC_NAMESPACE::open(test_file, O_RDWR | O_CREAT, S_IRWXU);
2933
ASSERT_GT(fd, 0);
3034

3135
// First, allocate some memory using mmap
@@ -36,9 +40,6 @@ TEST(LlvmLibcRemapFilePagesTest, NoError) {
3640
ASSERT_ERRNO_SUCCESS();
3741
EXPECT_NE(addr, MAP_FAILED);
3842

39-
// Reset error number for the new function
40-
LIBC_NAMESPACE::libc_errno = 0;
41-
4243
// Now try to remap the pages
4344
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(addr, page_size, 0, 1, 0),
4445
Succeeds());
@@ -48,14 +49,17 @@ TEST(LlvmLibcRemapFilePagesTest, NoError) {
4849

4950
// Clean up
5051
EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, alloc_size), Succeeds());
52+
EXPECT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
5153
}
5254

5355
TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) {
5456
size_t page_size = sysconf(_SC_PAGE_SIZE);
5557
ASSERT_GT(page_size, size_t(0));
5658

5759
// Create a file-backed mapping
58-
int fd = open("/dev/zero", O_RDWR);
60+
constexpr const char *file_name = "error.remap";
61+
auto test_file = libc_make_test_file_path(file_name);
62+
int fd = LIBC_NAMESPACE::open(test_file, O_RDWR | O_CREAT, S_IRWXU);
5963
ASSERT_GT(fd, 0);
6064

6165
// First, allocate some memory using mmap
@@ -73,6 +77,7 @@ TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) {
7377

7478
// Clean up
7579
EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, page_size), Succeeds());
80+
EXPECT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
7681
}
7782

7883
TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidAddress) {

0 commit comments

Comments
 (0)