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

From: Zhangjin Wu
Date: Wed Jun 21 2023 - 09:20:29 EST


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@xxxxxxxxxxx>
---
tools/testing/selftests/nolibc/nolibc-test.c | 11 +++++++++++
1 file changed, 11 insertions(+)

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>"
--
2.25.1