From d22e472cf21871de09ad49fed30a625c01499938 Mon Sep 17 00:00:00 2001 From: Bui Quang Minh Date: Tue, 26 Oct 2021 22:31:44 +0700 Subject: [PATCH] zdtm: Add memfd hugetlb test Signed-off-by: Bui Quang Minh --- test/zdtm/static/Makefile | 2 ++ test/zdtm/static/memfd02-hugetlb.c | 1 + test/zdtm/static/memfd02-hugetlb.desc | 1 + test/zdtm/static/memfd02.c | 52 +++++++++++++++++++++++---- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 120000 test/zdtm/static/memfd02-hugetlb.c create mode 100644 test/zdtm/static/memfd02-hugetlb.desc diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index 0e5f096fa..3b244e52d 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -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 diff --git a/test/zdtm/static/memfd02-hugetlb.c b/test/zdtm/static/memfd02-hugetlb.c new file mode 120000 index 000000000..db0820633 --- /dev/null +++ b/test/zdtm/static/memfd02-hugetlb.c @@ -0,0 +1 @@ +memfd02.c \ No newline at end of file diff --git a/test/zdtm/static/memfd02-hugetlb.desc b/test/zdtm/static/memfd02-hugetlb.desc new file mode 100644 index 000000000..f88ad828b --- /dev/null +++ b/test/zdtm/static/memfd02-hugetlb.desc @@ -0,0 +1 @@ +{'feature': 'memfd_hugetlb'} diff --git a/test/zdtm/static/memfd02.c b/test/zdtm/static/memfd02.c index 12e294921..8950e38e2 100644 --- a/test/zdtm/static/memfd02.c +++ b/test/zdtm/static/memfd02.c @@ -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 "; @@ -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;