All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhangjin Wu <falcon@tinylab.org>
To: thomas@t-8ch.de, w@1wt.eu
Cc: arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v3 14/14] selftests/nolibc: vfprintf: remove MEMFD_CREATE dependency
Date: Fri, 30 Jun 2023 23:00:35 +0800	[thread overview]
Message-ID: <10d0316283b1467a9604d2b170f83e0a50483b48.1688134400.git.falcon@tinylab.org> (raw)
In-Reply-To: <cover.1688134399.git.falcon@tinylab.org>

The vfprintf test case require to open a temporary file to write, the
old memfd_create() method is perfect but has strong dependency on
MEMFD_CREATE and also TMPFS or HUGETLBFS (see fs/Kconfig):

    config MEMFD_CREATE
	def_bool TMPFS || HUGETLBFS

And from v6.2, MFD_NOEXEC_SEAL must be passed for the non-executable
memfd, otherwise, The kernel warning will be output to the test result
like this:

        Running test 'vfprintf'
        0 emptymemfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 'init'
         "" = ""                                                  [OK]

To avoid such warning and also to remove the MEMFD_CREATE dependency,
let's open a file from tmpfs directly.

The /tmp directory is used to detect the existing of tmpfs, if not
there, skip instead of fail.

And further, for pid == 1, the initramfs is loaded as ramfs, which can
be used as tmpfs, so, it is able to further remove TMPFS dependency too.

Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/9ad51430-b7c0-47dc-80af-20c86539498d@t-8ch.de
Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index be2a18cd5bd5..714252518595 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -868,10 +868,10 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char
 	FILE *memfile;
 	va_list args;
 
-	fd = memfd_create("vfprintf", 0);
+	fd = open("/tmp", O_TMPFILE | O_EXCL | O_RDWR, 0600);
 	if (fd == -1) {
-		pad_spc(llen, 64, "[FAIL]\n");
-		return 1;
+		pad_spc(llen, 64, "[SKIPPED]\n");
+		return 0;
 	}
 
 	memfile = fdopen(fd, "w+");
-- 
2.25.1


      parent reply	other threads:[~2023-06-30 15:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30 14:41 [PATCH v3 00/14] selftests/nolibc: allow run with minimal kernel config Zhangjin Wu
2023-06-30 14:42 ` [PATCH v3 01/14] selftests/nolibc: stat_fault: silence NULL argument warning with glibc Zhangjin Wu
2023-06-30 14:43 ` [PATCH v3 02/14] selftests/nolibc: gettid: restore for glibc and musl Zhangjin Wu
2023-06-30 14:44 ` [PATCH v3 03/14] selftests/nolibc: add _LARGEFILE64_SOURCE for musl Zhangjin Wu
2023-06-30 15:23   ` Arnd Bergmann
2023-06-30 18:01     ` Zhangjin Wu
2023-06-30 18:45       ` Arnd Bergmann
2023-06-30 14:46 ` [PATCH v3 04/14] selftests/nolibc: fix up int_fast16/32_t test cases " Zhangjin Wu
2023-06-30 14:47 ` [PATCH v3 05/14] selftests/nolibc: fix up kernel parameters support Zhangjin Wu
2023-06-30 14:48 ` [PATCH v3 06/14] selftests/nolibc: stat_timestamps: remove procfs dependency Zhangjin Wu
2023-06-30 14:50 ` [PATCH v3 07/14] selftests/nolibc: chroot_exe: " Zhangjin Wu
2023-06-30 14:52 ` [PATCH v3 08/14] selftests/nolibc: link_cross: use /proc/self/cmdline Zhangjin Wu
2023-06-30 14:54 ` [PATCH v3 09/14] tools/nolibc: add rmdir() support Zhangjin Wu
2023-06-30 14:55 ` [PATCH v3 10/14] selftests/nolibc: add a new rmdir() test case Zhangjin Wu
2023-06-30 14:56 ` [PATCH v3 11/14] selftests/nolibc: fix up failures when CONFIG_PROC_FS=n Zhangjin Wu
2023-06-30 14:58 ` [PATCH v3 12/14] selftests/nolibc: prepare /tmp for tmpfs or ramfs Zhangjin Wu
2023-06-30 14:59 ` [PATCH v3 13/14] selftests/nolibc: add chmod_tmpdir test Zhangjin Wu
2023-06-30 15:00 ` Zhangjin Wu [this message]

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=10d0316283b1467a9604d2b170f83e0a50483b48.1688134400.git.falcon@tinylab.org \
    --to=falcon@tinylab.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=thomas@t-8ch.de \
    --cc=w@1wt.eu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.