Add a regression test

This commit is contained in:
Chen Chengjun 2025-06-27 07:42:07 +00:00 committed by Jianfeng Jiang
parent fe24c2d8ae
commit f274af17de
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// SPDX-License-Identifier: MPL-2.0
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include "../test.h"
#define PAGE_SIZE 4096
FN_TEST(mmap_beyond_the_file)
{
const char *filename = "mmap_test_file";
int fd = TEST_SUCC(open(filename, O_CREAT | O_RDWR, 0600));
TEST_SUCC(ftruncate(fd, 2 * PAGE_SIZE));
char *addr = CHECK_WITH(mmap(NULL, 4 * PAGE_SIZE,
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0),
_ret != MAP_FAILED);
TEST_RES(addr[1 * PAGE_SIZE], _ret == 0);
// The following operation (if uncommented) would cause a segmentation fault.
// TEST_RES(addr[3 * PAGE_SIZE], _ret == 0);
TEST_SUCC(munmap(addr, 4 * PAGE_SIZE));
TEST_SUCC(close(fd));
TEST_SUCC(unlink(filename));
}
END_TEST()

View File

@ -29,6 +29,7 @@ itimer/setitimer
itimer/timer_create
mmap/mmap_and_fork
mmap/mmap_and_mremap
mmap/mmap_beyond_the_file
mmap/mmap_shared_filebacked
mmap/mmap_readahead
mmap/mmap_vmrss