When CONFIG_TMPFS not enabled, kernel will use the ramfs based tmpfs instead, but memfd_create doesn't work with such tmpfs, for this type of tmpfs, let's use it instead of memfd_create.
At the same time, let's support hugetlbfs too if there is one.
Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/testing/selftests/nolibc/nolibc-test.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 85fa64746cde..bff72365a158 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -796,6 +796,14 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char if (fd == -1) fd = memfd_create("vfprintf", 0);
+ /* memfd_create not work with ramfs based tmpfs, try tmpfs and hugetlbfs in order instead */ + if (fd == -1) { + if (tmpfs) + fd = open("/tmp/vfprintf", O_CREAT | O_TRUNC | O_RDWR); + else if (hugetlbfs) + fd = open("/hugetlb/vfprintf", O_CREAT | O_TRUNC | O_RDWR); + } + if (fd == -1) { pad_spc(llen, 64, "[FAIL]\n"); return 1;