From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [RFC PATCH 2/3] memfd_create03: make use of new .request_hugepages
Date: Thu, 28 Apr 2022 21:29:48 +0800 [thread overview]
Message-ID: <20220428132949.11719-2-liwang@redhat.com> (raw)
In-Reply-To: <20220428132949.11719-1-liwang@redhat.com>
To get rid of some failures like:
memfd_create03.c:179: TINFO: --TESTING PAGE SIZE OF CREATED FILE--
memfd_create03.c:184: TINFO: memfd_create() succeeded
memfd_create03.c:47: TBROK: mmap((nil),1048576,2,2,3,0) failed: ENOMEM (12)
Signed-off-by: Li Wang <liwang@redhat.com>
---
.../syscalls/memfd_create/memfd_create03.c | 77 ++-----------------
1 file changed, 7 insertions(+), 70 deletions(-)
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create03.c b/testcases/kernel/syscalls/memfd_create/memfd_create03.c
index 036182f0a..400a56854 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create03.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create03.c
@@ -32,14 +32,6 @@
#include <stdio.h>
#include <errno.h>
-#define TOTAL_HP_PATH "/proc/sys/vm/nr_hugepages"
-#define MEMINFO_PATH "/proc/meminfo"
-#define FREE_HP "HugePages_Free:\t%ld"
-#define DEFAULT_HPS "Hugepagesize:\t%ld kB"
-
-static int hugepages_allocated;
-static long og_total_pages;
-
static void *check_huge_mmapable(int fd, unsigned long size)
{
void *mem;
@@ -88,7 +80,7 @@ static void test_def_pagesize(int fd)
long hps;
void *mem;
- SAFE_FILE_LINES_SCANF(MEMINFO_PATH, DEFAULT_HPS, &hps);
+ hps = SAFE_READ_MEMINFO("Hugepagesize:");
hps = hps << 10;
unmap_size = hps / 4;
mem = check_huge_mmapable(fd, hps);
@@ -128,8 +120,8 @@ static void test_max_hugepages(int fd)
void *mem;
void *new_mem;
- SAFE_FILE_LINES_SCANF(MEMINFO_PATH, FREE_HP, &free_pages);
- SAFE_FILE_LINES_SCANF(MEMINFO_PATH, DEFAULT_HPS, &hps);
+ free_pages = SAFE_READ_MEMINFO("HugePages_Free:");
+ hps = SAFE_READ_MEMINFO("Hugepagesize:");
hps = hps << 10;
mem = check_huge_mmapable(fd, free_pages * hps);
@@ -188,68 +180,13 @@ static void memfd_huge_controller(unsigned int n)
SAFE_CLOSE(fd);
}
-static void setup(void)
-{
- char buf[8];
- int fd;
- long free_pages;
- long total_pages;
-
- if (access(MEMINFO_PATH, F_OK) ||
- access("/sys/kernel/mm/hugepages", F_OK) ||
- access(TOTAL_HP_PATH, F_OK))
- tst_brk(TCONF, "Huge page is not supported");
-
- SAFE_FILE_LINES_SCANF(MEMINFO_PATH, FREE_HP, &free_pages);
- if (free_pages > 0)
- return;
-
- SAFE_FILE_LINES_SCANF(TOTAL_HP_PATH, "%ld", &og_total_pages);
- sprintf(buf, "%ld", og_total_pages + 1);
-
- fd = SAFE_OPEN(TOTAL_HP_PATH, O_RDWR | O_TRUNC);
-
- if (write(fd, buf, strlen(buf)) == -1)
- tst_brk(TCONF | TERRNO,
- "write() fail: Hugepage allocation failed");
-
- SAFE_CLOSE(fd);
-
- SAFE_FILE_LINES_SCANF(TOTAL_HP_PATH, "%ld", &total_pages);
- if (total_pages != (og_total_pages + 1))
- tst_brk(TCONF, "Hugepage allocation failed");
-
- hugepages_allocated = 1;
-}
-
-static void cleanup(void)
-{
- char buf[8];
- int fd;
- long total_pages;
-
- if (hugepages_allocated == 0)
- return;
-
- sprintf(buf, "%ld", og_total_pages);
-
- fd = SAFE_OPEN(TOTAL_HP_PATH, O_RDWR | O_TRUNC);
-
- if (write(fd, buf, strlen(buf)) == -1)
- tst_brk(TCONF | TERRNO, "Clean-up failed: write() failed");
-
- SAFE_CLOSE(fd);
-
- SAFE_FILE_LINES_SCANF(TOTAL_HP_PATH, "%ld", &total_pages);
- if (og_total_pages != total_pages)
- tst_brk(TCONF, "Clean-up failed");
-}
-
static struct tst_test test = {
- .setup = setup,
.test = memfd_huge_controller,
.tcnt = ARRAY_SIZE(tcases),
.needs_root = 1,
.min_kver = "4.14",
- .cleanup = cleanup,
+ .request_hugepages = (struct tst_hugepage []){
+ {1, TST_ENFORCED},
+ {}
+ },
};
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-04-28 13:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 13:29 [LTP] [RFC PATCH 1/3] lib: extend .request_hugepages to guarantee enough pages Li Wang
2022-04-28 13:29 ` Li Wang [this message]
2022-04-28 13:29 ` [LTP] [RFC PATCH 3/3] hugetlb: make use of new .request_hugepages Li Wang
2022-06-01 12:08 ` [LTP] [RFC PATCH 1/3] lib: extend .request_hugepages to guarantee enough pages Cyril Hrubis
2022-06-02 4:24 ` Li Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220428132949.11719-2-liwang@redhat.com \
--to=liwang@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox