diff mbox series

[v1,16/17] selftests/nolibc: vfprintf: skip if neither tmpfs nor hugetlbfs

Message ID 55a01001987f2795a982755ed2ca8e27efe49249.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:18 p.m. UTC
As fs/Kconfig shows, MEMFD_CREATE depends on TMPFS or HUGETLBFS:

    config MEMFD_CREATE
    	def_bool TMPFS || HUGETLBFS

Let's skip vfprintf test if they are not there.

The /tmp and /hugetlb directories have been created to mount tmpfs and
hugetlbfs respectively, if they are not enabled in kernel configuration,
neither /tmp nor /hugetlb will be created.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 8b1ce9911c5c..85fa64746cde 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -769,11 +769,22 @@  int run_stdlib(int min, int max)
 
 static int expect_vfprintf(int llen, size_t c, const char *expected, const char *fmt, ...)
 {
+	struct stat stat_buf;
 	int ret, fd, w, r;
+	int tmpfs = 0, hugetlbfs = 0;
 	char buf[100];
 	FILE *memfile;
 	va_list args;
 
+	/* memfd_create depends on tmpfs or hugetlbfs */
+	tmpfs = stat("/tmp/.", &stat_buf) == 0;
+	hugetlbfs = stat("/hugetlb/.", &stat_buf) == 0;
+
+	if (!tmpfs && !hugetlbfs) {
+		pad_spc(llen, 64, "[SKIPPED]\n");
+		return 0;
+	}
+
 	/* silence warning for kernel >= v6.2:
 	 *
 	 *   "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=<pid>"