mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
zdtm: Add memfd hugetlb test
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
This commit is contained in:
parent
ffa2688969
commit
d22e472cf2
4 changed files with 50 additions and 6 deletions
|
|
@ -248,6 +248,7 @@ TST_NOFILE := \
|
|||
memfd00 \
|
||||
memfd01 \
|
||||
memfd02 \
|
||||
memfd02-hugetlb \
|
||||
memfd03 \
|
||||
shmemfd \
|
||||
shmemfd-priv \
|
||||
|
|
@ -618,6 +619,7 @@ socket-tcp6-closing: CFLAGS += -D ZDTM_IPV6
|
|||
socket-tcp6-unconn: CFLAGS += -D ZDTM_IPV6
|
||||
socket-tcp4v6-last-ack: CFLAGS += -D ZDTM_TCP_LAST_ACK -D ZDTM_IPV4V6
|
||||
socket-tcp4v6-closing: CFLAGS += -D ZDTM_IPV4V6
|
||||
memfd02-hugetlb: CFLAGS += -D ZDTM_HUGETLB
|
||||
|
||||
sockets00-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
|
||||
sockets01-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
|
||||
|
|
|
|||
1
test/zdtm/static/memfd02-hugetlb.c
Symbolic link
1
test/zdtm/static/memfd02-hugetlb.c
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
memfd02.c
|
||||
1
test/zdtm/static/memfd02-hugetlb.desc
Normal file
1
test/zdtm/static/memfd02-hugetlb.desc
Normal file
|
|
@ -0,0 +1 @@
|
|||
{'feature': 'memfd_hugetlb'}
|
||||
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
#ifndef MFD_HUGETLB
|
||||
#define MFD_HUGETLB 4
|
||||
#endif
|
||||
|
||||
const char *test_doc = "memfd mmap";
|
||||
const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>";
|
||||
|
||||
|
|
@ -29,14 +33,24 @@ static int _memfd_create(const char *name, unsigned int flags)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef ZDTM_HUGETLB
|
||||
#define LEN (2 * (1 << 20)) /* 2MB */
|
||||
#else
|
||||
#define LEN 6
|
||||
int fd;
|
||||
#endif
|
||||
|
||||
int fd, flag = 0;
|
||||
void *addr_shared, *addr_private;
|
||||
char buf[LEN];
|
||||
dev_t dev1, dev2;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
fd = _memfd_create("somename", MFD_CLOEXEC);
|
||||
#ifdef ZDTM_HUGETLB
|
||||
flag = MFD_HUGETLB;
|
||||
#endif
|
||||
|
||||
fd = _memfd_create("somename", MFD_CLOEXEC | flag);
|
||||
if (fd < 0)
|
||||
err(1, "Can't call memfd_create");
|
||||
|
||||
|
|
@ -47,16 +61,32 @@ int main(int argc, char *argv[])
|
|||
if (addr_shared == MAP_FAILED)
|
||||
err(1, "Can't mmap");
|
||||
|
||||
dev1 = get_mapping_dev(addr_shared);
|
||||
if (dev1 == (dev_t)-1) {
|
||||
fail("Can't get mapping dev");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef ZDTM_HUGETLB
|
||||
strcpy(addr_shared, "write1");
|
||||
#else
|
||||
write(fd, "write1", LEN);
|
||||
#endif
|
||||
|
||||
addr_private = mmap(NULL, LEN, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
if (addr_private == MAP_FAILED)
|
||||
err(1, "Can't mmap");
|
||||
|
||||
dev2 = get_mapping_dev(addr_private);
|
||||
if (dev2 == (dev_t)-1) {
|
||||
fail("Can't get mapping dev");
|
||||
return 1;
|
||||
}
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
if (memcmp(addr_shared, "write1", LEN)) {
|
||||
if (strncmp(addr_shared, "write1", LEN)) {
|
||||
fail("content mismatch (shared)");
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -68,23 +98,33 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp(buf, "write2", LEN)) {
|
||||
if (strncmp(buf, "write2", LEN)) {
|
||||
fail("content mismatch (shared)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp(addr_private, "write2", LEN)) {
|
||||
if (strncmp(addr_private, "write2", LEN)) {
|
||||
fail("content mismatch (private)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
strcpy(addr_private, "write3");
|
||||
|
||||
if (memcmp(addr_shared, "write2", LEN)) {
|
||||
if (strncmp(addr_shared, "write2", LEN)) {
|
||||
fail("content mismatch (shared)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dev1 != get_mapping_dev(addr_shared)) {
|
||||
fail("Mapping dev mismatch");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dev2 != get_mapping_dev(addr_private)) {
|
||||
fail("Mapping dev mismatch");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pass();
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue