diff mbox series

[v1,17/17] selftests/nolibc: vfprintf: support tmpfs and hugetlbfs

Message ID 52c056a4d319070d2f36b59a8ef0b739ee84fdbc.1687344643.git.falcon@tinylab.org (mailing list archive)
State New
Headers show
Series selftests/nolibc: allow run with minimal kernel config | expand

Commit Message

Zhangjin Wu June 21, 2023, 1:21 p.m. UTC
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 mbox series

Patch

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;