From patchwork Fri Jun 30 14:42:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698373 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 4A400EB64DA for ; Fri, 30 Jun 2023 14:43:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232389AbjF3On3 (ORCPT ); Fri, 30 Jun 2023 10:43:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232403AbjF3OnM (ORCPT ); Fri, 30 Jun 2023 10:43:12 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAC4A44A6; Fri, 30 Jun 2023 07:42:55 -0700 (PDT) X-QQ-mid: bizesmtp84t1688136166tze1g8ev Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:42:44 +0800 (CST) X-QQ-SSF: 00200000000000D0W000000A0000000 X-QQ-FEAT: LE7C6P2vL8SQwZOGdkG/lTjPsV7PgvW2oesEBVFY6dM9tcdRhIkifWsyjQUo/ Ol8lESzlCLkSb8/LwvbBjwFNtLbbQoGMX9ZQmju3B292dp0/jDMaguAs+Y61UyM+s9x9G5s N0iwPV5qFiX02Rkr+vXvSIPY71FnWXWa5lOsqqG4hpHlOs8qMyOQOL90FU8X3t5jYrvAYlz bn3uLQEBQMBlikvRAFvd7x9DHJ+JlXAPJCaR//7Me3iGbYtGupmfYIvm1fzdBvNPPi3hrYy pi1lMkdGVARJL1NfrB5JRU8XxG1kZaYWDn0FsMpGEPM4uHxINr9UjdSnGUn3/ZhVzRhWE5Q PFnfuhwkZTOLdYZeoC/zd3EneQFzWG/muXo5wyuSLavubcPeHwVA3ng4/XlhArBOMlAk93F X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2264253388160424813 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 01/14] selftests/nolibc: stat_fault: silence NULL argument warning with glibc Date: Fri, 30 Jun 2023 22:42:38 +0800 Message-Id: <8a0a69f8e88219ca83f7d1eecfaeceafe7551a34.1688134399.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; Reviewed-by: Thomas Weißschuh 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 f85f55921410..ffef0ff921bf 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -733,7 +733,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 Fri Jun 30 14:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698206 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 8FC92EB64D7 for ; Fri, 30 Jun 2023 14:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231854AbjF3OoX (ORCPT ); Fri, 30 Jun 2023 10:44:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232382AbjF3OoK (ORCPT ); Fri, 30 Jun 2023 10:44:10 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 163724223; Fri, 30 Jun 2023 07:44:02 -0700 (PDT) X-QQ-mid: bizesmtp62t1688136233td32r9qm Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:43:51 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPiH69hHrQvaiwgA2zlFoZJKtxC3fQVf7xOa2i8JFvEi+l7cutDAu NdSKTsbC9yjEhA6vmXFk52zYQc0pKbNiELQlyjNzuftlI2+C5S6KjlV6ZmpgxTNZYbbmwT3 XBAqH3DVlvcmqCIlVUIQ5tDSiIc5s7ZO4aw6x3P4BEFHP5IW5xWN3d5R8h6EhyakVqszTjH d8c4U4zRgluYH95UaAUrzK8gOV5JlyhGb75ONtswumgTLcvBBAIqAkIu6QFvtT1qjDkNOju +dz7qfMaSdRefLXOxX7PKtAZNQA4/zrDxOlVVDC/qI93jjoPyE8OBFOf6PRsrdlBK0gvPQf K1pD2PxV9e1EJdrEsOsdraPfpcPBiMHBJo7H6KsMY6+eQIZpiJGyL/KQ1VYkY3uPthpY+tq P65JLNq7VMo= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16227406883335655901 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 02/14] selftests/nolibc: gettid: restore for glibc and musl Date: Fri, 30 Jun 2023 22:43:49 +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 Reviewed-by: Thomas Weißschuh 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 ffef0ff921bf..be7614c897b4 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 Fri Jun 30 14:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698205 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 535E6EB64D7 for ; Fri, 30 Jun 2023 14:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbjF3OqX (ORCPT ); Fri, 30 Jun 2023 10:46:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232292AbjF3OqW (ORCPT ); Fri, 30 Jun 2023 10:46:22 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F27E4C; Fri, 30 Jun 2023 07:46:20 -0700 (PDT) X-QQ-mid: bizesmtp88t1688136371tgmgq7hg Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:46:10 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 0laiA9+vjACjfigCT6n4FbL5nW8/jNpLSvoQkIDyLgOgBYBSUrlxcH7cnsPU+ JNB/Hh2ZH4ZY4LYZnTxLLi6KnhREVwWhLMTzcfjzSbfu/xOKHtF+25gTAl3QJJFdUIh8Pt+ vgGudIqnS4erVtv75UKjIJu1sl5FHOsP8/K/tLTgxyYA1PquKa5zjkttPYZxhmpUEMMByET kMgN9iBOae9NC62iooXvUpOP8uy8WejN4EjGxWAjVTW26TXgoPIq6JferQDHtFDyGmMShy6 1yW5n7fJlFrgRIZRC7lwjPCb4R0tbndTVHmKpanNjhPmqES+8Vy6MgPGN1lAAwgwlzZeGLk rl7hbIsnFvABzmn5YLi9YhCvwi6xqOqe5cnSkShP1WeFyVF8nBhLgjZm54OYDHCa5npU7rn wZ0kYSsMQ5E= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4395302546129479556 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 04/14] selftests/nolibc: fix up int_fast16/32_t test cases for musl Date: Fri, 30 Jun 2023 22:46:07 +0800 Message-Id: <8b47bb0d7ff4c24d99e8e3c9e03f747664d3465a.1688134400.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 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/ Reviewed-by: Thomas Weißschuh 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 d9644244fc95..290b43c7dc72 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; @@ -818,11 +822,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 Fri Jun 30 14:47: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: 698372 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 91311EB64DC for ; Fri, 30 Jun 2023 14:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232292AbjF3Ora (ORCPT ); Fri, 30 Jun 2023 10:47:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232176AbjF3Ora (ORCPT ); Fri, 30 Jun 2023 10:47:30 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF05E4C; Fri, 30 Jun 2023 07:47:28 -0700 (PDT) X-QQ-mid: bizesmtp76t1688136438tbbkfb8i Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:47:17 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: rRzgT1OOeLqcsI4HZ6uwZGCFEkc3obYUh18KgobxkZnKI5QUXNZlM728bmyMP i/hnfFr8sHQm4/9yZ5VrwNKm6edfJopZXLJxrcEM9j9fyxLNkU2NlUfhvAy9poIx6ODEOWI h1eGfNYL8Yo5wUUll7cewmQyOFctAYqTTMIoJrUADsEnq7Xjw/3Ilcziwx3vkKhtyF3TJeN FofpwL4gpa622cnxx8dxsqXcWlTc8DW6XsOd7lBkw3yy8ClduzQBCxmQ/OXHlbY/Gy9iV1f gs3fZwRNN16EZA7xHBWRmSmxdkYbciqEy9QCuf1AVjV1NDzSXo/JYMIx0WAFy90evipBuL7 ODEaVw0VKlijmQn44j0fTHCenEmvyJf2U4j+6jnHpBBqtMtCkXpFTSiiN7bK1Xy5F/PDzQg +gW1dBxP53E= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16371103090428855131 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 05/14] selftests/nolibc: fix up kernel parameters support Date: Fri, 30 Jun 2023 22:47: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 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. Reviewed-by: Thomas Weißschuh 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 290b43c7dc72..94801961740a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1062,6 +1062,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; @@ -1087,10 +1116,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 Fri Jun 30 14:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698204 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 881C3EB64D7 for ; Fri, 30 Jun 2023 14:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232548AbjF3OtV (ORCPT ); Fri, 30 Jun 2023 10:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231633AbjF3OtU (ORCPT ); Fri, 30 Jun 2023 10:49:20 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901F1171E; Fri, 30 Jun 2023 07:49:17 -0700 (PDT) X-QQ-mid: bizesmtp79t1688136546tlj7qf2s Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:49:04 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 3M0okmaRx3g9FGi2GrgTbWso5GF6j8mNsD9EEsYEj3ftL3NfDx/gEJX7AasWI CPaZaB2hzz3UmKC905zXg3WZwZ/Pw8rlRzBujXkhDTXYkh+YbYwSztk4k6xvNeu9EMYDvqR pDfa64sh3NeBr7EAWIkZNcfeZrzAsJypzUp1XO4zgsmJe1AG68vgYEJP26yaLpVilzLQZ9Y oO1l2vlTBbypgl1CmH2nZDniqAuJ0zeA+IVhPQrdCwEginvotjXC+2BworCYimBtNJA3G5+ BcAHRBl+oWwFN04U4O8qGTPLocpyuS8ryGlfskhNRpPNKLYqrWH8iXGH+URyc2u9ZyYPtdN /GALQMhWZ5ODi9MtWkTD1/AFWcbPSvLRtXY5Uzf31pL9JmzUf8Cthm5LabQgXgFbZGcNDs/ X-QQ-GoodBg: 0 X-BIZMAIL-ID: 519475413023589342 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 06/14] selftests/nolibc: stat_timestamps: remove procfs dependency Date: Fri, 30 Jun 2023 22:48:22 +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 '/proc/self/' is a good path which doesn't have stale time info but it is only available for CONFIG_PROC_FS=y. When CONFIG_PROC_FS=n, use '/init' for initramfs and '/' for the others. Reviewed-by: Thomas Weißschuh 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 94801961740a..3e2e808e06c2 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 Fri Jun 30 14:50:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698371 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 8548DEB64D7 for ; Fri, 30 Jun 2023 14:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbjF3OvZ (ORCPT ); Fri, 30 Jun 2023 10:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231657AbjF3OvY (ORCPT ); Fri, 30 Jun 2023 10:51:24 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDF7199; Fri, 30 Jun 2023 07:51:20 -0700 (PDT) X-QQ-mid: bizesmtp75t1688136671tks53y7u Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:51:10 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPhtX0qqQD3e9uQe+zph/w5hvXojtfrw04MKncxuDc5m83pLdsrLg 1voBQJq/KkY5cjRgJe6tncXcvlA4E09cKSck78NCzB9n+Mzg0TGmgwg9ZCX3hNi63/BUbv3 s694W/9//VoR66wOD3HOqNdNHW0+QgIIfdywvw6Fjg+tnldOCOA4HDG2j3QgfErB1gnDOIK I2sB26OYEYTtlhDwXoYLrPpEZ2J9Znbg4zMPKjlkW7xgG8AcssfXtAb0J4JsHhye9/8O3Ji EULTdX+5eP+DhysMLoDuyzvPk38li457EyiNKrLfZaJhoHnPhpFH9dg/IUAYBIxITjUX4iU Zzew+gU3S97jWYdLfZqMvAno6R+MR1cdNB0V7OJX69VG+c1XLejGkeyxN3jQA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8120028281936275689 From: Zhangjin Wu 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 Subject: [PATCH v3 07/14] selftests/nolibc: chroot_exe: remove procfs dependency Date: Fri, 30 Jun 2023 22:50:10 +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 Use '/init' instead of '/proc/self/exe' for CONFIG_PROC_FS=n. If '/init' is not there, add ENOENT into the errno check list. 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 3e2e808e06c2..a7a4310dec3e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -702,7 +702,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_exe); EXPECT_SYSER2(1, chroot(proc ? "/proc/self/exe" : "/init"), -1, ENOTDIR, ENOENT); 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 14:52: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: 698203 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 7C4CFEB64D7 for ; Fri, 30 Jun 2023 14:53:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232674AbjF3Oxf (ORCPT ); Fri, 30 Jun 2023 10:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232701AbjF3Oxd (ORCPT ); Fri, 30 Jun 2023 10:53:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D77A61996; Fri, 30 Jun 2023 07:53:30 -0700 (PDT) X-QQ-mid: bizesmtp69t1688136801tyxc0y2f Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:53:18 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 5q30pvLz2ie3Y/Doqwtf5t34E8pidXRwnNfxRvp8bFvhcIXw71A6eq1w9Q9UM JXc2vs6oj9EfcQ4DmBQDD+8F3o7g/1ieNlGp43BUMCLL/6+ixRn8Q1BSzZ2NTn+3OBREJQa 7tY96c5Ks3ylL/BoEb3WKkkB2tT4uqYLgq5XHyS//7sKuUdIPO/8FUI7MJyv2/ypFVbPeKH 9oyDtoNSJW7oHNG96YQgiI+r0/4HM9VVKP1tQPKj1EdXrKHhLSP8Bwg0QGEGJLb/1pxnjbG QjOZJmGjeoe3wQuFVs6Za0deePAz9pUJl+1ogiiowfNf6MOMlMYT3SSlbr0+jAXjNRBsEeN 9/VaPz3SBZPas4uiZLh1yFH2q2uqfoohPTr7nFhNGWE3e6bJ4l3o921Nb8MFYuOyu/OdIoF X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15121841345925353120 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 08/14] selftests/nolibc: link_cross: use /proc/self/cmdline Date: Fri, 30 Jun 2023 22:52:14 +0800 Message-Id: <3131dc57acb38f0c6db068aff43bde28441a414c.1688134400.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 For CONFIG_NET=n, there would be no /proc/self/net, so, use /proc/self/cmdline instead. Reviewed-by: Thomas Weißschuh 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 a7a4310dec3e..8269f900db76 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -723,7 +723,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 Fri Jun 30 14:54:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698370 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 F350BEB64D7 for ; Fri, 30 Jun 2023 14:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbjF3Oyx (ORCPT ); Fri, 30 Jun 2023 10:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbjF3Oyn (ORCPT ); Fri, 30 Jun 2023 10:54:43 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FD8B199C; Fri, 30 Jun 2023 07:54:41 -0700 (PDT) X-QQ-mid: bizesmtp62t1688136872tw3c6ubu Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:54:31 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: znfcQSa1hKbueF+mXAgBy3rJOgj1RLfbDdVxw5G9LZsIKSHSDWEo0cPthZn5y 2507pXERHbMQlfcGVi/fPoErK4Q+RhkejsHI7PKAIoYK61wlHUruw2XEBjLind0HIk+RQsP ESu4yDckaqB4Zu8BTqm1n04LvedF4U3iF/SkLxvf8Z3oiOG4m5c6Tny1Igo5PX+/R3qpMRg yZlvGKhBNasKGPiAwMJAAnNO6oxAVrdVDl5DurO9CQzy7f5YuLC2zPOtWfLEI4giP7v/88H pEkPmmeDcjaBK1YbDkRmiJtiPyNN1F+M0m0458Hq55J5tjaRE3Nh39h0bIF/4HvmGeHBytE ZZFY9FD/68V5g2Iz7zu+8a1Dpt9Yl3c8ZwVxpOYETRHTjKCFTyKaT8dwFeFzg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 657531427943538185 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 09/14] tools/nolibc: add rmdir() support Date: Fri, 30 Jun 2023 22:54:24 +0800 Message-Id: <630ad07b61503e1970f93c6f24b3c6e2fc3a1650.1688134400.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. Reviewed-by: Thomas Weißschuh 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 Fri Jun 30 14:55:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698202 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 850D2EB64DA for ; Fri, 30 Jun 2023 14:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232796AbjF3O4B (ORCPT ); Fri, 30 Jun 2023 10:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbjF3O4A (ORCPT ); Fri, 30 Jun 2023 10:56:00 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E90583C35; Fri, 30 Jun 2023 07:55:51 -0700 (PDT) X-QQ-mid: bizesmtp89t1688136942tf8eezrl Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:55:41 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: rZJGTgY0+YPl1Ti/yTwBd86Id6oVjQsowhpNx/GMYyB2MOxQs7beAu2rW5Arc JT9wcxUF4ckea9ztg2+aZJPJ6y5rv6GwKodyUfioNl992oUArIBDJNNuweEKqFBH+4juqYh 2AC+Q4u+WZhtkhOM0Dt+Cutc4yyw/Am1mSnvMDzkB3yL/KXghV0cbsCEdBKwIMFkGJwvPWG OvyYy5ijguBkR4KFGGS1ZSC6HIGZ2H1NusquSuusiDgpo04NMZuMav+kVwWWq61j0bsGrqw O1KyYLxp5ixnzgj88Se3TTQVDmwHtRfylIRHqSxeE9KQ5HaBtoWM9N4xulNDtfTIJ5rcuNJ 5OZOLEN+QZBkyR7bYuX8dGkljemL698iLRCRU67JRXwizBLOKMCPvfR7amZoFMnFbWytcs4 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15980847344132787065 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 10/14] selftests/nolibc: add a new rmdir() test case Date: Fri, 30 Jun 2023 22:55:36 +0800 Message-Id: <1b65441f8f6f115788922459e453e5bf35a4fdf6.1688134400.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. Reviewed-by: Thomas Weißschuh 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 8269f900db76..34a47c512b97 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -737,6 +737,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 Fri Jun 30 14:56:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698369 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 686BCEB64DC for ; Fri, 30 Jun 2023 14:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232068AbjF3O5L (ORCPT ); Fri, 30 Jun 2023 10:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjF3O5K (ORCPT ); Fri, 30 Jun 2023 10:57:10 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D75171E; Fri, 30 Jun 2023 07:57:08 -0700 (PDT) X-QQ-mid: bizesmtp82t1688137018tsiqwx7a Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:56:57 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: +ynUkgUhZJmKaF5lx43msVOqUOEusgk0PNkqlU5Je21DA28KFEa/NSf3ei5GC 8ujOyUUh0oJCOeE0bIFeiDv23kIV2OyzhEBlyx6kIfnhlhooHbcSy/KieZ7PlYewN310ono eeacy8IX7WzDhYNygHg2pO8NrYhe+qtZ7Be2Maskig39IMsqf7Ggr8eTwX++W402Iv8ztEe RyMXx6V38NGtfViJgAGOMrD2l2eKcMLlZRte11ElHDkHXRufUT1IvNk4aMIKMaxkLdhvuko 9hFzgHQsZTjVVud17s0AueJ7Dss7dKpnbgc2NpObJW3bWFc2K/9zzAJcjIpc+1lMM8Sy7uu pUKmL2hKpFuKLE1GrBM5hALFm4CzcgAUraZSdCjO0nzQQDPWrwU2m7OV3iIoOhSZdOhS29e X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7295049176166171116 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 11/14] selftests/nolibc: fix up failures when CONFIG_PROC_FS=n Date: Fri, 30 Jun 2023 22:56:46 +0800 Message-Id: <023e07a05e3af211da893e76ae4328983b19882c.1688134400.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 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. Reviewed-by: Thomas Weißschuh 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 34a47c512b97..b7ea95dad0fb 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1046,8 +1046,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 Fri Jun 30 14:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698201 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 59218EB64DA for ; Fri, 30 Jun 2023 14:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232480AbjF3O60 (ORCPT ); Fri, 30 Jun 2023 10:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjF3O6Z (ORCPT ); Fri, 30 Jun 2023 10:58:25 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD0A359E; Fri, 30 Jun 2023 07:58:23 -0700 (PDT) X-QQ-mid: bizesmtp87t1688137093tnenfezj Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:58:12 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: D2GZf6M6C/iXFYl/ZWwOsCC60g16lUOAO1Y9zKzd1LwnO/woTAQ+CfFAkq+Wq yVeX7w8gzVRaC0SNKCQtyPkZN/zhk/F1PWjZql1ldLzLVQFuQbSiRXTcGXfcbeHLxXXnyQ+ lBWoXyFAGge/HaepE42/QBGraYZT7/W6Y/K26Vrhy2hEl5nmDxNYXX5FANYRVFqUj4XE5mO jTe2Kfpzs4ti027IGCj9+5QK1o8po3R0YfxRGGvR14JiAva+J1DyAaPebh27Xgh/Q6Wxmdu T9vYY1X2oIJAX6qK79cvfirKVYbg83JWPlQPDPwV45vrB5Khperyo2EACncI7za7Elp7jXl zUPTppk7VqkRdqR6/XBT+vVjhRkQZHUuSsSGlj2k7VhjEAUtX5YedXd8D2g7ulSPoo3qCqH X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3647784010068437256 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 12/14] selftests/nolibc: prepare /tmp for tmpfs or ramfs Date: Fri, 30 Jun 2023 22:58:02 +0800 Message-Id: <020ca58ad59035488d6a50b14113ed7401e797f4.1688134400.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 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. Reviewed-by: Thomas Weißschuh 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 b7ea95dad0fb..906b70ddec79 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1053,6 +1053,10 @@ int prepare(void) } } + /* try to mount /tmp if not mounted, if not mountable, use ramfs as tmpfs */ + mkdir("/tmp", 0755); + mount("none", "/tmp", "tmpfs", 0, 0); + return 0; } From patchwork Fri Jun 30 14:59:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698368 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 0216DEB64D7 for ; Fri, 30 Jun 2023 15:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232377AbjF3PAC (ORCPT ); Fri, 30 Jun 2023 11:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbjF3O7r (ORCPT ); Fri, 30 Jun 2023 10:59:47 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1E43ABC; Fri, 30 Jun 2023 07:59:41 -0700 (PDT) X-QQ-mid: bizesmtp86t1688137172t6z8crq0 Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:59:30 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: OtIeQkg1QQG1RpxwZ/4Otz5Iupcb5NPjfY3VZCaKJ6SgS7D8+uWkhgDprvLoA oB0PMopiPJcqeZMc7u6JWS2IV1Y0LhcTTMpAtYxyvZ5MIBPU1hwvkIJlf1skWilaA9XZpJV Zri0mMgAF2ucLHqnxB1RtntODWj70pNmBpDq3eaZ6gKQ/p8xTGas2fRKE4Rx5NM9UkPq3OM GJLNNJT7aVT01VgwY24MuHNQR9XtqDGiwFfBT60AwBfkQQfnkoBXeTjcT4CtM12nBr2Zo1+ JvKaow3EdvCmuqBH8zLDOit155ZIgP323OcH4owv0b+GBs0RfzVHTwSoLdVmDGmYNeNfQ0Z EmVcueUo1DcOiUrRRaGMvR1yqmXsbDZ4uHNCCyb3YyYevUQYtjEv76voh5zdQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 14153631108985947431 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 13/14] selftests/nolibc: add chmod_tmpdir test Date: Fri, 30 Jun 2023 22:59:17 +0800 Message-Id: <7db449df61476b4e27a7fa70f31b6b98c6447660.1688134400.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 create a temp directory to test chmod with tmpfs. Reviewed-by: Thomas Weißschuh 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 906b70ddec79..be2a18cd5bd5 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -699,6 +699,7 @@ int run_syscall(int min, int max) CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break; CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break; CASE_TEST(chmod_self); EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); break; + CASE_TEST(chmod_tmpdir); mkdir("/tmp/blah", 0755); EXPECT_SYSZR(1, chmod("/tmp/blah", 0555)); rmdir("/tmp/blah"); 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 15:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 698200 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 8426DEB64D7 for ; Fri, 30 Jun 2023 15:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232655AbjF3PBI (ORCPT ); Fri, 30 Jun 2023 11:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjF3PBH (ORCPT ); Fri, 30 Jun 2023 11:01:07 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BDF91FF2; Fri, 30 Jun 2023 08:01:05 -0700 (PDT) X-QQ-mid: bizesmtp84t1688137255t2mep54u Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 23:00:54 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: kN2ypXZVqgzWddNeqgphAHxZz9TLgQL4byjbxUc7gzCYE0taS5aYTkz+R184h INKYNRLRzmcQCBMr/Z6JGhxrpqO2iyD4O6lQ1aeMXLMDyEdMt3zFBul6o/oO9nBXyhwGSL2 aC9W0vRwckYxPNBTnyy38DabjTNQyXVqeaKE/XCFVmFY4lTKLfeDzGlRFVBGRp8Tx2Xve0S vJGd49DqhqPa8K/0mJYTkCQpFufxxbD6ILKhqYpNmpWp3V1rkkR88y0dW4mDJ2lFpmdEDZo zEtyxyBvk2uHjDpz/T6A4GDvNynBnqId0fc0WE2IsG/yp+5NCKvxhRz/fIcnUFlaZIt6l77 S4brYv5NuyAUKun4HWdS4LDQxxbt6FXGBo+NsHv6z7z/TPKHZEh9n+1aMsGQYLyyh977AfH WUrfaZPzOQQ= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 323981673361064231 From: Zhangjin Wu 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, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v3 14/14] selftests/nolibc: vfprintf: remove MEMFD_CREATE dependency Date: Fri, 30 Jun 2023 23:00:35 +0800 Message-Id: <10d0316283b1467a9604d2b170f83e0a50483b48.1688134400.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 Reviewed-by: Thomas Weißschuh 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 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+");