From patchwork Thu Jun 29 23:23:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6EBCEB64D9 for ; Thu, 29 Jun 2023 23:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbjF2XYX (ORCPT ); Thu, 29 Jun 2023 19:24:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjF2XYW (ORCPT ); Thu, 29 Jun 2023 19:24:22 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4784A1FC2; Thu, 29 Jun 2023 16:24:21 -0700 (PDT) X-QQ-mid: bizesmtp89t1688081051teyogk65 Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:24:10 +0800 (CST) X-QQ-SSF: 00200000000000D0W000000A0000000 X-QQ-FEAT: rZJGTgY0+YOVTQ2kNXjsPZ3MGX+TVmKJcovJh/8yjg+hV2a7oyT97pXC4kLUt mj9kJr6hG0y/CgiAEGGVEQ4x8Y9AeFZstxg5XaUwLeMy80LNWwim6uWDIJUnX6Ztr7ukka1 amq3OMPGiPSMhwkSmJDwXL23FHx8t+SuFEbAuNwNV/of0y9mJKUzwS4DwkqsQUzuEoEjk1f uXXZVY5h8yw/DOBh76j+UqmQ25T3BY41/ByGpxOCochUrt0fUUqYmZJdMXliAYePfLoBrZj JOzjvwk+WeruPWku6rWBrYp8v5IEsP3ixD6wEetyP/yUR1iezjb2ttPlzHVx1ai6IHfodGv 21qh12wA/PRoTW43Af1PqTnR3fswnj8HWQdDzi5ThJF3q0lgJYnhgkuDaVYYQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 12172486614225476365 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 01/15] selftests/nolibc: stat_fault: silence NULL argument warning with glibc Date: Fri, 30 Jun 2023 07:23:58 +0800 Message-Id: <64938ffca05019a13e2cbcdc5beaa12625947572.1688078604.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Use another invalid address (void *)1 instead of NULL to silence this compile warning with glibc: $ make libc-test CC libc-test nolibc-test.c: In function ‘run_syscall’: nolibc-test.c:622:49: warning: null argument where non-null required (argument 1) [-Wnonnull] 622 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; | ^~~~ nolibc-test.c:304:79: note: in definition of macro ‘EXPECT_SYSER2’ 304 | do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) | ^~~~ nolibc-test.c:622:33: note: in expansion of macro ‘EXPECT_SYSER’ 622 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index b178bfa29ad9..a2eacd6436d0 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -734,7 +734,7 @@ int run_syscall(int min, int max) CASE_TEST(select_stdout); EXPECT_SYSNE(1, ({ fd_set fds; FD_ZERO(&fds); FD_SET(1, &fds); select(2, NULL, &fds, NULL, NULL); }), -1); break; CASE_TEST(select_fault); EXPECT_SYSER(1, select(1, (void *)1, NULL, NULL, 0), -1, EFAULT); break; CASE_TEST(stat_blah); EXPECT_SYSER(1, stat("/proc/self/blah", &stat_buf), -1, ENOENT); break; - CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; + CASE_TEST(stat_fault); EXPECT_SYSER(1, stat((void *)1, &stat_buf), -1, EFAULT); break; CASE_TEST(stat_timestamps); EXPECT_SYSZR(1, test_stat_timestamps()); break; CASE_TEST(symlink_root); EXPECT_SYSER(1, symlink("/", "/"), -1, EEXIST); break; CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); break; From patchwork Thu Jun 29 23:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92CA7EB64D9 for ; Thu, 29 Jun 2023 23:26:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbjF2X0K (ORCPT ); Thu, 29 Jun 2023 19:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231953AbjF2X0F (ORCPT ); Thu, 29 Jun 2023 19:26:05 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A66FD1FE4; Thu, 29 Jun 2023 16:26:03 -0700 (PDT) X-QQ-mid: bizesmtp91t1688081154tyi55hnf Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:25:52 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 6aXALTFZqPuZikFTnD0XtTrqnijJVdsBQ+fxB4J0aSCn27CFnCwO6LrrmluGc rpV/PikWplX1NtR6o5wbyCcv6WlYJCsSsHhUrWWybJrEciGHc9kgBfM70mFeFNYeglnMGaR 8kBS1WA6Q4/vvjTcUxQL//bO5Mn1EJTJzocmcqmGvmgq8MovuFny2kYrND2di0t/ae2si6k 109qlRNSTq5XbQJp2wTmaL7ZX5Rjgx+UyLcnaw17iJFrYU343Cyv7rqi6hV2Y2LZVOQSE7e eCT6Z5+JLR3XMhW7o4gCnAQAkgPr6qWY9aNtjTcvynXUgcu82JGWCvCw6lg1FETscw+rksp 6s6sRAan4j8fts6W6DRZYa0tWkZ42qJoAMsqUqJ/6sX6qmg4pm+krnciMniTQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 12284148764811659706 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 02/15] selftests/nolibc: gettid: restore for glibc and musl Date: Fri, 30 Jun 2023 07:25:14 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org As the gettid manpage [1] shows, glibc 2.30 has gettid support, so, let's enable the test for glibc >= 2.30. gettid works on musl too. [1]: https://man7.org/linux/man-pages/man2/gettid.2.html Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index a2eacd6436d0..785b1f4cbdc5 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -659,6 +659,7 @@ int run_syscall(int min, int max) int tmp; int ret = 0; void *p1, *p2; + int has_gettid = 1; /* indicates whether or not /proc is mounted */ proc = stat("/proc", &stat_buf) == 0; @@ -666,6 +667,11 @@ int run_syscall(int min, int max) /* this will be used to skip certain tests that can't be run unprivileged */ euid0 = geteuid() == 0; + /* from 2.30, glibc provides gettid() */ +#if defined(__GLIBC_MINOR__) && defined(__GLIBC__) + has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30); +#endif + for (test = min; test >= 0 && test <= max; test++) { int llen = 0; /* line length */ @@ -675,9 +681,7 @@ int run_syscall(int min, int max) switch (test + __LINE__ + 1) { CASE_TEST(getpid); EXPECT_SYSNE(1, getpid(), -1); break; CASE_TEST(getppid); EXPECT_SYSNE(1, getppid(), -1); break; -#ifdef NOLIBC - CASE_TEST(gettid); EXPECT_SYSNE(1, gettid(), -1); break; -#endif + CASE_TEST(gettid); EXPECT_SYSNE(has_gettid, gettid(), -1); break; CASE_TEST(getpgid_self); EXPECT_SYSNE(1, getpgid(0), -1); break; CASE_TEST(getpgid_bad); EXPECT_SYSER(1, getpgid(-1), -1, ESRCH); break; CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break; From patchwork Thu Jun 29 23:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A574EB64D9 for ; Thu, 29 Jun 2023 23:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjF2X2r (ORCPT ); Thu, 29 Jun 2023 19:28:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbjF2X2q (ORCPT ); Thu, 29 Jun 2023 19:28:46 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6667B1BC6; Thu, 29 Jun 2023 16:28:44 -0700 (PDT) X-QQ-mid: bizesmtp86t1688081315tjycq55u Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:28:34 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: RdkzUaxjIrfJY7jV7wFs1hXtoA3+Vv/lYMh4H2WNVuZBKAbd/xdTOxNXXKRtf jfuQ9QcCSu7QafjYL4xSTkK7jMt6OMdjr6isvrN3T2xAnU55eSqrebklnG681L/OmxI9bh/ VyTSb+V4G+WjUArncjMNhBb/stR9LJchLeOBeyLSC0JEbc40UBzcXTLFX7Fr0ZWMNyn5SK3 NeZXrnuqo7LLuDye+A7DzfLLeJbA37uc6Z7epdjB6GXts2/MgXM6eBl64d6n255EmoJoh+z Kv7dwv1d/SXpMqzqoxjuM+Oi7eY1LhE7373eSEKL9vh9IrCkyig/aa5RtSxLBDDHRGH/ril WlXDy6MFmIcm5IB0udI8ohjTkENOgGhI8PnpiL6OVYE5k10j5zom3w4LooGb3GtR/WSrbZi X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15633995598629543478 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v2 04/15] selftests/nolibc: fix up int_fast16/32_t test cases for musl Date: Fri, 30 Jun 2023 07:28:15 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org musl limits the fast signed int in 32bit, but glibc and nolibc don't, to let such test cases work on musl, let's provide the type based SINT_MAX_OF_TYPE(type) and SINT_MIN_OF_TYPE(type). Suggested-by: Thomas Weißschuh Link: https://lore.kernel.org/lkml/bc635c4f-67fe-4e86-bfdf-bcb4879b928d@t-8ch.de/ Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 29c21880a198..96d170cc9b47 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -41,6 +41,10 @@ #endif #endif +/* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */ +#define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2))) +#define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1) + /* will be used by nolibc by getenv() */ char **environ; @@ -819,11 +823,11 @@ int run_stdlib(int min, int max) CASE_TEST(limit_int_fast8_max); EXPECT_EQ(1, INT_FAST8_MAX, (int_fast8_t) 0x7f); break; CASE_TEST(limit_int_fast8_min); EXPECT_EQ(1, INT_FAST8_MIN, (int_fast8_t) 0x80); break; CASE_TEST(limit_uint_fast8_max); EXPECT_EQ(1, UINT_FAST8_MAX, (uint_fast8_t) 0xff); break; - CASE_TEST(limit_int_fast16_min); EXPECT_EQ(1, INT_FAST16_MIN, (int_fast16_t) INTPTR_MIN); break; - CASE_TEST(limit_int_fast16_max); EXPECT_EQ(1, INT_FAST16_MAX, (int_fast16_t) INTPTR_MAX); break; + CASE_TEST(limit_int_fast16_min); EXPECT_EQ(1, INT_FAST16_MIN, (int_fast16_t) SINT_MIN_OF_TYPE(int_fast16_t)); break; + CASE_TEST(limit_int_fast16_max); EXPECT_EQ(1, INT_FAST16_MAX, (int_fast16_t) SINT_MAX_OF_TYPE(int_fast16_t)); break; CASE_TEST(limit_uint_fast16_max); EXPECT_EQ(1, UINT_FAST16_MAX, (uint_fast16_t) UINTPTR_MAX); break; - CASE_TEST(limit_int_fast32_min); EXPECT_EQ(1, INT_FAST32_MIN, (int_fast32_t) INTPTR_MIN); break; - CASE_TEST(limit_int_fast32_max); EXPECT_EQ(1, INT_FAST32_MAX, (int_fast32_t) INTPTR_MAX); break; + CASE_TEST(limit_int_fast32_min); EXPECT_EQ(1, INT_FAST32_MIN, (int_fast32_t) SINT_MIN_OF_TYPE(int_fast32_t)); break; + CASE_TEST(limit_int_fast32_max); EXPECT_EQ(1, INT_FAST32_MAX, (int_fast32_t) SINT_MAX_OF_TYPE(int_fast32_t)); break; CASE_TEST(limit_uint_fast32_max); EXPECT_EQ(1, UINT_FAST32_MAX, (uint_fast32_t) UINTPTR_MAX); break; CASE_TEST(limit_int_fast64_min); EXPECT_EQ(1, INT_FAST64_MIN, (int_fast64_t) INT64_MIN); break; CASE_TEST(limit_int_fast64_max); EXPECT_EQ(1, INT_FAST64_MAX, (int_fast64_t) INT64_MAX); break; From patchwork Thu Jun 29 23:29:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 697837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FF79EB64D9 for ; Thu, 29 Jun 2023 23:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbjF2Xan (ORCPT ); Thu, 29 Jun 2023 19:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjF2Xam (ORCPT ); Thu, 29 Jun 2023 19:30:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694EC1FE7; Thu, 29 Jun 2023 16:30:40 -0700 (PDT) X-QQ-mid: bizesmtp77t1688081430tg4lkoyb Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:30:29 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: CR3LFp2JE4k2yCeR62ZuAGYUgkT1yq1gp7tSCx6PjhF/mNkyHruYzL79SeB7z CxTzPB7K2xFoUA/Ttaf/5FeV6L2uZdCkhc6XFd+y19TuqfuZXiEi8MxdsIwOmgQRqo4pRJU K9nE+AfOZFt1gnTXokRNuOjIyGH60R8MmM8qcVuceDH066+FiI3ebXS5ucV6i39M2LmgDgX jrMaXXzbKZXF1L/CX6tToO/a7QqbP3ZC94AEgLSNMjGkx1IUrGdvDHYo0t+4/y0ZadUrf9Q vKbj105VV3iJAVITKR8OC3793oJJQd58PXOK0m5ZJPs8AqexcipJTcZV9r6PDKW2fFm5tY3 UAyjZgTMxfiyqXCHysiWctOPNpjl1iIdiX5pdzoth3fQjGgjLzGMXhonNol+Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8005163360113825460 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 05/15] selftests/nolibc: fix up kernel parameters support Date: Fri, 30 Jun 2023 07:29:38 +0800 Message-Id: <582776208a75df19d09b8eaafcb6fdad7219abc8.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org kernel parameters allow pass two types of strings, one type is like 'noapic', another type is like 'panic=5', the first type is passed as arguments of the init program, the second type is passed as environment variables of the init program. when users pass kernel parameters like this: noapic NOLIBC_TEST=syscall our nolibc-test program will use the test setting from argv[1] and ignore the one from NOLIBC_TEST environment variable, and at last, it will print the following line and ignore the whole test setting. Ignoring unknown test name 'noapic' reversing the parsing order does solve the above issue: test = getenv("NOLIBC_TEST"); if (test) test = argv[1]; but it still doesn't work with such kernel parameters (without NOLIBC_TEST environment variable): noapic FOO=bar To support all of the potential kernel parameters, let's verify the test setting from both of argv[1] and NOLIBC_TEST environment variable. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 33 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 96d170cc9b47..223c00e83abf 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1063,6 +1063,35 @@ static const struct test test_names[] = { { 0 } }; +int is_setting_valid(char *test) +{ + int idx, len, test_len, valid = 0; + char delimiter; + + if (!test) + return valid; + + test_len = strlen(test); + + for (idx = 0; test_names[idx].name; idx++) { + len = strlen(test_names[idx].name); + if (test_len < len) + continue; + + if (strncmp(test, test_names[idx].name, len) != 0) + continue; + + delimiter = test[len]; + if (delimiter != ':' && delimiter != ',' && delimiter != '\0') + continue; + + valid = 1; + break; + } + + return valid; +} + int main(int argc, char **argv, char **envp) { int min = 0; @@ -1088,10 +1117,10 @@ int main(int argc, char **argv, char **envp) * syscall:5-15[:.*],stdlib:8-10 */ test = argv[1]; - if (!test) + if (!is_setting_valid(test)) test = getenv("NOLIBC_TEST"); - if (test) { + if (is_setting_valid(test)) { char *comma, *colon, *dash, *value; do { From patchwork Thu Jun 29 23:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 697836 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14F76EB64DD for ; Thu, 29 Jun 2023 23:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbjF2XgL (ORCPT ); Thu, 29 Jun 2023 19:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjF2XgK (ORCPT ); Thu, 29 Jun 2023 19:36:10 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D3A51713; Thu, 29 Jun 2023 16:36:08 -0700 (PDT) X-QQ-mid: bizesmtp64t1688081757tnqk2bme Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:35:56 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 3M0okmaRx3jzXUNZYCjF22Yt5q5NFwMgmhuWKlNMBfQ9f40ThEIsT/5lI1O4U WTU+lHNIjWl6hrnW7p4jSjiM7agpdRFqQPOYCLhDNV+lu8Gw8Ix+6NWlvPgvzPOA03J22Hs xnOaKbUZegQkWE2vf+3+hpyASl6yde1FbI7BjKOd3RWr64jv3jC7X/FKkiY+gbl0I2iV2vp abwjKmGuqvzJszYtKQcASRVuIKUcNRXdwsuK3jMwUIECfGliZDnizInZnNeglxZ0Hh15PpQ 9Zdle0TebbOIE/kaNpct8qijh366/xn6vycmfsA8M9NqWBuOsRh5KNxHkAp2Lfpk/7q+4HP 20AiePlmwg77191+LbqegPp1akzdiPRWn4wvBFR5rBZWkLxit/0Xzf4+I2sfQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10916663048857480056 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 06/15] selftests/nolibc: stat_timestamps: remove procfs dependency Date: Fri, 30 Jun 2023 07:31:33 +0800 Message-Id: <6fae777966cf710321a8d8369a9194e00b72ecf6.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org '/proc/self/' is a good path which doesn't have stale time info but it is only available for CONFIG_PROC_FS=y. For CONFIG_PROC_FS=n, Let's try '/init' for initramfs and '/' for the others. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 223c00e83abf..1d2be52d44a5 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -582,7 +582,7 @@ static int test_stat_timestamps(void) if (sizeof(st.st_atim.tv_sec) != sizeof(st.st_atime)) return 1; - if (stat("/proc/self/", &st)) + if (stat("/proc/self/", &st) && stat("/init", &st) && stat("/", &st)) return 1; if (st.st_atim.tv_sec != st.st_atime || st.st_atim.tv_nsec > 1000000000) From patchwork Thu Jun 29 23:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D59AAEB64D9 for ; Thu, 29 Jun 2023 23:45:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232190AbjF2XpP (ORCPT ); Thu, 29 Jun 2023 19:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbjF2Xo6 (ORCPT ); Thu, 29 Jun 2023 19:44:58 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 068843A9E; Thu, 29 Jun 2023 16:44:31 -0700 (PDT) X-QQ-mid: bizesmtp71t1688082237td2r7nrs Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:43:57 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 9fp+MOMfZT3B2+27Lz2FTtpHEdP5j3lylTTpTlkY+1W9tYtMODtQHajOyUa+u KjzLT8Qc3eQVG5pPIeHgQ5dEURdQ2cV62nDeE9XHkM2MvowgrDTcEq1J+MR+p2lBpjqDlHc tmi8mq8yEz4+BD0xkYc1YeDmRD++G0w1cUIY9KI046I1CS8lX0PcziIAYWisMdC9QHlVUwM hR+oTfgO3MsLZfc3/7PNuAUYridqhYq4hM/1uuCK1ba9SyEP7nnM6tmkOtQ0vVt/NgPqU3U 3FHxEbPs/Dv4lcsYnMSZJ+xCqVW1y3+NJe4pF1nK122Bh9r3H7TYDjwy/7O9s3fM9xmypyg I3b3Aw9jgd9IHLy+5b7dY2iJnlWWr+OA/fedR4Ss3GD+2BOQy3BrmSl9H/qoA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15543981623249164707 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 07/15] selftests/nolibc: link_cross: use /proc/self/cmdline Date: Fri, 30 Jun 2023 07:37:00 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org For CONFIG_NET=n, there would be no /proc/self/net, so, use /proc/self/cmdline instead. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 1d2be52d44a5..0bb222eaafca 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -724,7 +724,7 @@ int run_syscall(int min, int max) CASE_TEST(link_root1); EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break; CASE_TEST(link_blah); EXPECT_SYSER(1, link("/proc/self/blah", "/blah"), -1, ENOENT); break; CASE_TEST(link_dir); EXPECT_SYSER(euid0, link("/", "/blah"), -1, EPERM); break; - CASE_TEST(link_cross); EXPECT_SYSER(proc, link("/proc/self/net", "/blah"), -1, EXDEV); break; + CASE_TEST(link_cross); EXPECT_SYSER(proc, link("/proc/self/cmdline", "/blah"), -1, EXDEV); break; CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; From patchwork Thu Jun 29 23:45:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 697835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCC7AEB64D9 for ; Thu, 29 Jun 2023 23:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbjF2Xrl (ORCPT ); Thu, 29 Jun 2023 19:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjF2Xri (ORCPT ); Thu, 29 Jun 2023 19:47:38 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 947382D50; Thu, 29 Jun 2023 16:47:36 -0700 (PDT) X-QQ-mid: bizesmtp69t1688082446tioisu3e Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:47:25 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: GUznYiACrGRXU/PHOEhZV4uIpp/gsrUe2qnOFpSTSF4MU1t9SCpp/PEXkGLnU X5sOQhdKVk9smFzAGQFaDLeDEwaVOpwCjMZ/QvMIpG5KF3300XxhHvoQpm6rFYpTpMhdbWa gielDawdT0Lm8wppHPUNs30pHHLYDJozuaT+A5bC2vX6H5DIQHD2GRfibL9k1GlUy1sL7iw U2L0h/dLPqID9hcbsmNDXA/PNc+YmKx8l6rpH7i7qkRkeUeLDZtU5S8PXbXWE5Vuf2jW2WT IQtTG3PqUOW8AttwjOR41SezOEo15azPYbN7wfChYvXhPFoUf362D8B7WwnbHY3pS1qAFbX T2mZ380MafeGj9Wbhzx8/WUCYI8pfecB1ICzTqF3SXKkLsgfhQ= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1361039155256738211 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 08/15] tools/nolibc: add rmdir() support Date: Fri, 30 Jun 2023 07:45:00 +0800 Message-Id: <7a2cde610506ca288742b4e52833572c4341ac20.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org a reverse operation of mkdir() is meaningful, add rmdir() here. required by nolibc-test to remove /proc while CONFIG_PROC_FS is not enabled. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index b6c33c40c037..7b052958e2ae 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -610,6 +610,28 @@ int mkdir(const char *path, mode_t mode) return __sysret(sys_mkdir(path, mode)); } +/* + * int rmdir(const char *path); + */ + +static __attribute__((unused)) +int sys_rmdir(const char *path) +{ +#ifdef __NR_rmdir + return my_syscall1(__NR_rmdir, path); +#elif defined(__NR_unlinkat) + return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); +#else + return -ENOSYS; +#endif +} + +static __attribute__((unused)) +int rmdir(const char *path) +{ + return __sysret(sys_rmdir(path)); +} + /* * int mknod(const char *path, mode_t mode, dev_t dev); From patchwork Thu Jun 29 23:48:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F5AEEB64D9 for ; Thu, 29 Jun 2023 23:48:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229614AbjF2Xsw (ORCPT ); Thu, 29 Jun 2023 19:48:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjF2Xsv (ORCPT ); Thu, 29 Jun 2023 19:48:51 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8B952D55; Thu, 29 Jun 2023 16:48:49 -0700 (PDT) X-QQ-mid: bizesmtp73t1688082520tj99e1ey Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:48:39 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: rZJGTgY0+YPV5/jLlL1r2TTowp9VzAJ/QuZsdkm5XOB79yntw54lelBhGFGBW +iDCR+bq5zuGY1Fb5AOm9nx/s2lzObBrLIU6hKpbs2UAer50DRPUX5SXgyRxGcGoeAj4hLE ZeKdJH9pzNzvsarmvs3DCR53UszQvhXaLbg4dp20rANnIT0/3bXQEFJYUINdfEY5uYn18gq u9ksw5IB8zjOinFLQFFb9AuiAFpF2HoQxoPVaS2/Uhz2MaX8tb6sbRf1nDxkcWLFqUrwA20 msOXABk2XcYTB7yww0XiP5gppsd/tXgth9vLou2iZhqKqV42WH1UKjxu82NVmaDS51d5vO3 StbtwR6MAldUGm6M3EglvM8DTmqRzi64SQ+8y8VHJ3FStWMmcAADDmXyBZjzQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1596370371220799989 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 09/15] selftests/nolibc: add a new rmdir() test case Date: Fri, 30 Jun 2023 07:48:29 +0800 Message-Id: <652efe216f732c88bd275b597924c4d106741c6b.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org A new rmdir_blah test case is added to remove a non-existing /blah, which expects failure with ENOENT errno. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 0bb222eaafca..2725d3dbfaf0 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -738,6 +738,7 @@ int run_syscall(int min, int max) CASE_TEST(poll_fault); EXPECT_SYSER(1, poll((void *)1, 1, 0), -1, EFAULT); break; CASE_TEST(prctl); EXPECT_SYSER(1, prctl(PR_SET_NAME, (unsigned long)NULL, 0, 0, 0), -1, EFAULT); break; CASE_TEST(read_badf); EXPECT_SYSER(1, read(-1, &tmp, 1), -1, EBADF); break; + CASE_TEST(rmdir_blah); EXPECT_SYSER(1, rmdir("/blah"), -1, ENOENT); break; CASE_TEST(sched_yield); EXPECT_SYSZR(1, sched_yield()); break; CASE_TEST(select_null); EXPECT_SYSZR(1, ({ struct timeval tv = { 0 }; select(0, NULL, NULL, NULL, &tv); })); break; CASE_TEST(select_stdout); EXPECT_SYSNE(1, ({ fd_set fds; FD_ZERO(&fds); FD_SET(1, &fds); select(2, NULL, &fds, NULL, NULL); }), -1); break; From patchwork Thu Jun 29 23:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 697834 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A72EB64DD for ; Thu, 29 Jun 2023 23:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231557AbjF2XvU (ORCPT ); Thu, 29 Jun 2023 19:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbjF2XvT (ORCPT ); Thu, 29 Jun 2023 19:51:19 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B3592D56; Thu, 29 Jun 2023 16:51:10 -0700 (PDT) X-QQ-mid: bizesmtp83t1688082660twu7a8ef Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:50:58 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: D2GZf6M6C/i23X3okTEDyY7sY3qClIpPp5F6NuS/AEEIAEVpfzZOlfZdTUae/ 8CfRQul6j18UQzkvZt4EsG5DY7/jNUNQinzpFR6x/BTidUBNAu9H2aVgrxP7o2Q7pS7SCfg w5kxfiqw3cg2/Olv9TybUurx+SRkjOzWzeDs/NRYj3Q5/ToQPoACfSxqmES7ywPwYJabr2g 0g6EM//dSBgtZRsUVY5Bc4/1Vw1kaRxeEiQ7/prMFw7/U1s7lOJqskt9aYv3ariLgg5Q8t/ KW9cw0ditY8PZiICS5z9ENmLuWC56RUovXsksri2oZLW9rd07Bvtrx0qYtrw3KdX2junOQT +7T0Y8lW34Z+6nDzkXxM9rGwCchPB4d3xzAqiL5qMR17heqzC0iW53NX0FHnQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18297835509952804073 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 10/15] selftests/nolibc: fix up failures when CONFIG_PROC_FS=n Date: Fri, 30 Jun 2023 07:49:42 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org For CONFIG_PROC_FS=n, the /proc is not mountable, but the /proc directory has been created in the prepare() stage whenever /proc is there or not. so, the checking of /proc in the run_syscall() stage will be always true and at last it will fail all of the procfs dependent test cases, which deviates from the 'cond' check design of the EXPECT_xx macros, without procfs, these test cases should be skipped instead of failed. To solve this issue, one method is checking /proc/self instead of /proc, another method is removing the /proc directory completely for CONFIG_PROC_FS=n, we apply the second method to avoid misleading the users. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 2725d3dbfaf0..c0f5302ada5d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1047,8 +1047,11 @@ int prepare(void) /* try to mount /proc if not mounted. Silently fail otherwise */ if (stat("/proc/.", &stat_buf) == 0 || mkdir("/proc", 0755) == 0) { - if (stat("/proc/self", &stat_buf) != 0) - mount("/proc", "/proc", "proc", 0, 0); + if (stat("/proc/self", &stat_buf) != 0) { + /* If not mountable, remove /proc completely to avoid misuse */ + if (mount("none", "/proc", "proc", 0, 0) != 0) + rmdir("/proc"); + } } return 0; From patchwork Thu Jun 29 23:52:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6839EB64D9 for ; Thu, 29 Jun 2023 23:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231587AbjF2Xxo (ORCPT ); Thu, 29 Jun 2023 19:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbjF2Xxo (ORCPT ); Thu, 29 Jun 2023 19:53:44 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85236C3; Thu, 29 Jun 2023 16:53:42 -0700 (PDT) X-QQ-mid: bizesmtp62t1688082813tkl23r8i Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:53:32 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: SdugMSrl+IPAzXWq+rfJBOyleIPNwAJP1BnWuXjvrOgozUJpjkblZ040nbM0V 4nYGY8mJHgC1InPwQxd66pwy39Ncw2l3U1VAq3Exy6G8vo5XDg/2ht6XP8d2wYbESG8lrA6 uSJqxqrWSrWxsAY9JcffJxCcyO/dpYdQlb2N693wOs2t5z86w3JMJ8vj+nz0kd9q//1DQ8J hb5IppBq9Qot4Koo5KkS9x/7oaCb7FcZSgJWBZgfggO/5UtJe4z7N1DEwSHWJRlQH3Pnp66 xuXtRV+1rRqBOREkItMdGFJck4pnjXpgCWm16Kf4OnQKi4lWcuXEFWuZCnvYnlrKCI2nEwz rOVbx8w+ne0rx0ByPHIAwpoVVvs5XdhaNvbMK5Phj+Itt1nE1g1sv9pbnY75g== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11952200826971950609 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 11/15] selftests/nolibc: prepare /tmp for tmpfs or ramfs Date: Fri, 30 Jun 2023 07:52:03 +0800 Message-Id: <9dc032064dde254a03e2111da1e58344deca6522.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Let's create a /tmp directory and mount tmpfs there, if tmpfs is not mountable, use ramfs as tmpfs. tmpfs will be used instead of procfs for some tests. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index c0f5302ada5d..8e3e2792f5e3 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1054,6 +1054,10 @@ int prepare(void) } } + /* try to mount /tmp if not mounted, if not mountable, use ramfs as tmpfs */ + if (stat("/tmp/.", &stat_buf) == 0 || mkdir("/tmp", 0755) == 0) + mount("none", "/tmp", "tmpfs", 0, 0); + return 0; } From patchwork Thu Jun 29 23:54:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 697833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65BA8EB64D9 for ; Thu, 29 Jun 2023 23:59:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230189AbjF2X7h (ORCPT ); Thu, 29 Jun 2023 19:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjF2X7h (ORCPT ); Thu, 29 Jun 2023 19:59:37 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C9482972; Thu, 29 Jun 2023 16:59:34 -0700 (PDT) X-QQ-mid: bizesmtp86t1688083165t6ieamo4 Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:59:24 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: i75H2eCteEhF1p4iQc3BY/8OPWOM3oRV+m1q8nMuW55lIXGl3BcbML5es10ms jUJ47FoEB9w1RrMiQT5qOoUDc73bYdvwB9sPxtmeszNifC+0YMKarlKsKsVlF09ESf6D0pE j0CkAw8/zC9q/WERC2PIYa2YBnc+l9ualw7CIwHzQ6BqgC1ol46rzAJamJJAUOCL+u6ksZr SxkovQ7MYlGasGHmhyCHvCw9O0rfuDylF/FehTVIFRHmU5HgP2pvT1XxfNuktS9M4bOGj48 qK/4a/evfIeN8GrXBPtYXm1HYuPUS+ZUrpNmjbMAdxXF7T8GX1E2J7N1Umee4jfYVUUla6a FgYc2Ny0mVYD33BQNKsS0am2tDuk58hX+iozREosjyq6NS97Mw= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10255374307051264272 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 12/15] selftests/nolibc: add common get_tmpfile() Date: Fri, 30 Jun 2023 07:54:35 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org allow create and get a temporary file from tmpfs. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8e3e2792f5e3..1002e0267515 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -54,6 +54,23 @@ struct test { int (*func)(int min, int max); /* handler */ }; +static const char *get_tmpfile(const char *tmpfile) +{ + struct stat stat_buf; + int fd; + + if (stat(tmpfile, &stat_buf) == 0) + return tmpfile; + + fd = open(tmpfile, O_CREAT, 0600); + if (fd != -1) { + close(fd); + return tmpfile; + } + + return NULL; +} + #ifndef _NOLIBC_STDLIB_H char *itoa(int i) { From patchwork Fri Jun 30 00:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3992EB64D9 for ; Fri, 30 Jun 2023 00:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230284AbjF3AA4 (ORCPT ); Thu, 29 Jun 2023 20:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjF3AAz (ORCPT ); Thu, 29 Jun 2023 20:00:55 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B0252972; Thu, 29 Jun 2023 17:00:53 -0700 (PDT) X-QQ-mid: bizesmtp70t1688083243tc6q58s1 Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 08:00:43 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: CR3LFp2JE4kswbijyT8FSHr/m5Ro1TRCzo0a8RfheEUvcf/BVZGX2KLlH6E/+ ShX8DywmRJ9ILMpomwp/MCmci/hDinkPesyIEF8m1z95RH4xr+UNw7Yg9ulHwl3Jt/BEuwK wY3rSTi9866Fog1s2TtL6YySRzzpuWzkghoVs58pDr48HYz2G6BLHsnKSvBnuCK3bNxBdn5 ljA/Au8aGriHhAlDjLeRl6iTzcX0CoK1GI0ozDFMjE4Q9SztOGzJOUw96JOZtXYGlaITQxc bkb+eW2apV54E40wx7aRPpITa7SqGh7wpSvibt119O/MtmCGbqN99YMlET+fYnYEA1R1AQI cSxavE7nLz/r3EOrqvur7xG9QFph5o5xFoNwERFkEopWHVlaymMKulc5hiamQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 14245471600300813277 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 13/15] selftests/nolibc: rename chroot_exe to chroot_tmpfile Date: Fri, 30 Jun 2023 08:00:28 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org For CONFIG_PROC_FS=n, let's use tmpfs and create a tmp file for chroot_exe test. Since chroot_exe is mainly testing the not directory case (ENOTDIR), so, rename it to chroot_tmpfile may be better. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 1002e0267515..2e9eaa7efa6e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -682,6 +682,8 @@ int run_syscall(int min, int max) int ret = 0; void *p1, *p2; int has_gettid = 1; + const char *tmpfile = get_tmpfile("/tmp/dummy"); + int has_tmpfile = tmpfile != NULL; /* indicates whether or not /proc is mounted */ proc = stat("/proc", &stat_buf) == 0; @@ -720,7 +722,7 @@ int run_syscall(int min, int max) CASE_TEST(chown_self); EXPECT_SYSER(proc, chown("/proc/self", 0, 0), -1, EPERM); break; CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; - CASE_TEST(chroot_exe); EXPECT_SYSER(proc, chroot("/proc/self/exe"), -1, ENOTDIR); break; + CASE_TEST(chroot_tmpfile); EXPECT_SYSER(has_tmpfile, chroot(tmpfile), -1, ENOTDIR); break; CASE_TEST(close_m1); EXPECT_SYSER(1, close(-1), -1, EBADF); break; CASE_TEST(close_dup); EXPECT_SYSZR(1, close(dup(0))); break; CASE_TEST(dup_0); tmp = dup(0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; From patchwork Fri Jun 30 00:01:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 697832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EF04EB64D9 for ; Fri, 30 Jun 2023 00:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbjF3AC3 (ORCPT ); Thu, 29 Jun 2023 20:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231953AbjF3ACX (ORCPT ); Thu, 29 Jun 2023 20:02:23 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D5B83588; Thu, 29 Jun 2023 17:02:21 -0700 (PDT) X-QQ-mid: bizesmtp73t1688083331t4dhfelf Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 08:02:10 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: eSZ1CZgv+JACTc0WzG4h74YvHe3gYF2XyV6HOEkcVE0utw0p/IA1Z5qToF1SM 3RioGCvD1BnB7phTtW7YUGkLu/mO4OLtLuJtK9lcbL1Wjv1fHbWItWGhIUokSs7aA1G6RmO iWqNAcsY1vABTHLrGflhEGYSlrXuqFUmkROxHdV5zxKFqyPNRDFlkIUjEa7cBj+/1kubjDh Vkc21XSo9YgqVB8wJwRykJpc1f4bpDrmIaIHkVbIa70aTwJSs82UHnS1IsSS49VrDbQc8Ew MkRPNOwLf+bR2SIpfKT+20lSlA6kQZOH3fsiMHvsH8voRT3tPqDCWobmkXTcRfS2KqpsWQc F9+jJROZtG5A/m81h/Tk7Sjl2cCnoGIRIf0+BDU6yZSIX1DdiwNkTwMaTctAw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5863286306713928212 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 14/15] selftests/nolibc: add chmod_tmpfile test Date: Fri, 30 Jun 2023 08:01:46 +0800 Message-Id: <02a08c64cd16ea03101e271527c5573453e9195f.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org allow test chmod with tmpfs even when procfs is not there. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 2e9eaa7efa6e..0ca7d011765a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -719,6 +719,7 @@ int run_syscall(int min, int max) CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break; CASE_TEST(chmod_net); EXPECT_SYSZR(proc, chmod("/proc/self/net", 0555)); break; CASE_TEST(chmod_self); EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); break; + CASE_TEST(chmod_tmpfile); EXPECT_SYSZR(has_tmpfile, chmod(tmpfile, 0555)); break; CASE_TEST(chown_self); EXPECT_SYSER(proc, chown("/proc/self", 0, 0), -1, EPERM); break; CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; From patchwork Fri Jun 30 00:03:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C324EB64D9 for ; Fri, 30 Jun 2023 00:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbjF3AGS (ORCPT ); Thu, 29 Jun 2023 20:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbjF3AGR (ORCPT ); Thu, 29 Jun 2023 20:06:17 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 724C3199B; Thu, 29 Jun 2023 17:06:15 -0700 (PDT) X-QQ-mid: bizesmtp71t1688083565twklsj26 Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 08:06:04 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: RFp2QSjOiS7beTcSYXt1iawYE5VBFE+qfrFikOGIrZGU78FGQ//+XBNHlkTeb TF9bjq4tqANTGj/eXrmZuqrAjBtKHg7Qp+Y5VIjCUePqDup95utpa2bac+We01QQ5iHPhta /zN6i6ZKv9IPOPTajq6hPE+XEVU+Lc/QRz7szyfrDSQ+kksByTKk20N1o8F2uxrCJJgmE8O 5hVrAJvv3KqNUx9SLoQ8ngwmbNGFK5DTN0cZ+Pps0q5ox1rTJREprqRx/RBPItazmUbDH6I DiikY/83T+T6cmW/kAnmW8Lt1Q+wE8q+79BlUAdoStWwD1jLD+RDCQ49SpArKwT3WIn1hz4 1yCFJtTzqJcQzfMvymdKAYqjfJxUixP6hjv/1KgL7SqVmysltewh2BBbP4TtbvBUY+HKAA3 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 527216731131771503 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v2 15/15] selftests/nolibc: vfprintf: remove MEMFD_CREATE dependency Date: Fri, 30 Jun 2023 08:03:14 +0800 Message-Id: <2438cf7e4ecb2444a79f838437c149dd7d5bdde6.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.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 Link: https://lore.kernel.org/lkml/9ad51430-b7c0-47dc-80af-20c86539498d@t-8ch.de Signed-off-by: Zhangjin Wu --- 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 0ca7d011765a..0847813d756c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -888,10 +888,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+");