From patchwork Fri Jul 7 18:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305150 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 64A32EB64D9 for ; Fri, 7 Jul 2023 18:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbjGGSWy (ORCPT ); Fri, 7 Jul 2023 14:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjGGSWy (ORCPT ); Fri, 7 Jul 2023 14:22:54 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E8391FEF; Fri, 7 Jul 2023 11:22:52 -0700 (PDT) X-QQ-mid: bizesmtp72t1688754163tbz6971n Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:22:42 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: QNtCjCnA38/H8JL0FER4UCqbooVsJKjujOZR7fq9q4G4ESPFiFBGxztBtSgfP PZsdw5sU119JWuA2HNJG/m4x0mXNF/z/OS8dmW0Cg2+xJ8gVBgpMI6Zav7XN7up1qM2y2oA oZ1+HgVmMp3HRpuxUYTC0LVUkxCvY0bhOeeCZakge+0az92sUVw28BTtt0ncnttqGRFn849 pC/01mK0+HW4HqJTG2aWVWd9zs1QB4H6sZThngmPEvtEbJcYPUJcAuRMnOKiTqaLIqIXGau z41S45Tp5E3YncOK+NJzAH3C+8Tiv8RkSZad1GD68651407qqv47L/zz7YClpFUYGD5T3UI 3gebTUjnabwoCh364SLMcwiPnmmT9acCpgX6HtDkkTyitn5TR4= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3309041285388814565 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v4 01/18] selftests/nolibc: add run-libc-test target Date: Sat, 8 Jul 2023 02:22:39 +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 run and report glibc or musl based libc-test. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 000621f21adc..d408b688b291 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -132,6 +132,10 @@ nolibc-test: nolibc-test.c sysroot/$(ARCH)/include libc-test: nolibc-test.c $(QUIET_CC)$(CC) -o $@ $< +run-libc-test: libc-test + $(Q)./libc-test > "$(CURDIR)/run.out" || : + $(Q)$(REPORT) $(CURDIR)/run.out + # qemu user-land test run-user: nolibc-test $(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || : From patchwork Fri Jul 7 18:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305151 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 45AAFEB64D9 for ; Fri, 7 Jul 2023 18:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbjGGSYV (ORCPT ); Fri, 7 Jul 2023 14:24:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbjGGSYU (ORCPT ); Fri, 7 Jul 2023 14:24:20 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15DFD2126; Fri, 7 Jul 2023 11:24:18 -0700 (PDT) X-QQ-mid: bizesmtp82t1688754249t623xsi4 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:24:07 +0800 (CST) X-QQ-SSF: 00200000000000D0W000000A0000000 X-QQ-FEAT: 3+QwQJFiZ1m2Ploce0hyNTg1J83yb786TJK2GyCTBRIg7tzl3nHVtx+YUkoDw wUqgOD9XgSC9h8wF341Dd5ODgw8WdqB5CmFg2clJVnxtyVpKabaxf7uHI1fz7gKRZ9CaGuR 92mUPSY4EqdGtr+Zkgr3eNmHU1woh0EcRMad5poTkOVBaLPNxwb4guaZ9u6Yna0QmhT+vEA 5hJ9RpbORV0m5lK2XkqMf06LiuKws1gcCfS/TAI68wy7bVOivdy3RP1vTEgV0IGAGfG7XDv hU1Ebppi/WE2kSzDuzNYIFXrNQjI09JXU4/Id2uwsYL9NKXCYfHJMj9vDRblNup0tIkB3wu bfVRx2vnKhWpjNqimF0tqXHsJh6uJni2Ju4apqVlfql8m4fOP8= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1607707009084266309 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 02/18] selftests/nolibc: stat_fault: silence NULL argument warning with glibc Date: Sat, 8 Jul 2023 02:23:45 +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 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 06c561c4b09d..b4b64125d418 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -742,7 +742,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 Jul 7 18:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305152 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 D09D4EB64D9 for ; Fri, 7 Jul 2023 18:25:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229515AbjGGSZd (ORCPT ); Fri, 7 Jul 2023 14:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbjGGSZd (ORCPT ); Fri, 7 Jul 2023 14:25:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A1951FEF; Fri, 7 Jul 2023 11:25:31 -0700 (PDT) X-QQ-mid: bizesmtp70t1688754321tmaef10w Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:25:20 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: eCJvJF4ptHAtnbbaPwc47aTRbhYkkrfXtqT9G41b5rpNHFwk2Vwq29QTGN+1N QhHOU4ekwfeupUA5ICP/pbXkF1za1ckb77bO4HdRm88TKxiykufqnCu4oVIlXNNUCviQvjz /Nk6ToRqvIw0rn+n9mR6Bzrkil92rYxg3PLnb+AdgzS0uTMx8jQi+gjZSBE4pfspWtYf4G7 vyTtV9RA+mhar+9xk8A17WOp15ObCy4Va0A8I+9++PangUMrTVKZyfMRXZaWR9/Q4xRVVmF V00caUFP00VVnetlMH4kw2/nnJZtmC4JmPoZOT2as/Qh4oEJHsNROofRUoB39ouPIR4670+ e4me1glggNeMnMemhMx10tGgI5ArASsCaCdBsgEyDcJmqGFn3AxxyH8vh+H96UpptOOUtsf X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10722182004068960664 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 03/18] selftests/nolibc: gettid: restore for glibc and musl Date: Sat, 8 Jul 2023 02:25:11 +0800 Message-Id: <879d87ac5eccbaa08bb471f88f5253d4b9d496cf.1688750763.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 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 b4b64125d418..b63afe1975c4 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -668,6 +668,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; @@ -675,6 +676,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 */ @@ -684,9 +690,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 Jul 7 18:26: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: 13305153 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 75FFEEB64D9 for ; Fri, 7 Jul 2023 18:26:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231280AbjGGS0u (ORCPT ); Fri, 7 Jul 2023 14:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbjGGS0t (ORCPT ); Fri, 7 Jul 2023 14:26:49 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A46821FEF; Fri, 7 Jul 2023 11:26:47 -0700 (PDT) X-QQ-mid: bizesmtp77t1688754397ti6mrfex Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:26:36 +0800 (CST) X-QQ-SSF: 00200000000000D0W000000A0000000 X-QQ-FEAT: lO87fmWkX3EaHwlleNUDHGjVqaGc0+ZZIdig5664u8XhYAXp/F/zmRuny3En9 LeRYrCHxNGL1pIAzgA1hz3p7HWq/VJs+OtPcEMG25UNx023fPX+gKhz5tMcjUN122YhxosM uJbkRAva89uNOtOCqakmMEDzb7CQwPHziMhytE6KDm7OJk0hBGVXICW6C/G5OoC6VdGrzQU Fj53PhfimB0Kc0NHYhng7GBrqsjhz91v5CW5ix85EaCHjq+R/TZTU9CugGM1yij0DIo0iHD LJQY+5niPwdsa/s5o1JGtBtxp2AtsWc8xPCNHLKHhFrhQucD2KYDqmpJwEMmhNGcQZW3MsW ZsBfzwsJydwUgFEv12w17X6D+OCGtShoFofmIXP/3/ZvvbROlIOqIpcHGBlvg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5110181960524252780 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 04/18] selftests/nolibc: add _LARGEFILE64_SOURCE for musl Date: Sat, 8 Jul 2023 02:26:24 +0800 Message-Id: <0026b19f1f89a27375e8a225baac2f923cd4020b.1688750763.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 _GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the default configuration doesn't enable _LARGEFILE64_SOURCE. From include/dirent.h of musl, getdents64 is provided as getdents when _LARGEFILE64_SOURCE is defined. #if defined(_LARGEFILE64_SOURCE) ... #define getdents64 getdents #endif Let's define _LARGEFILE64_SOURCE to fix up this compile error: tools/testing/selftests/nolibc/nolibc-test.c: In function ‘test_getdents64’: tools/testing/selftests/nolibc/nolibc-test.c:453:8: warning: implicit declaration of function ‘getdents64’; did you mean ‘getdents’? [-Wimplicit-function-declaration] 453 | ret = getdents64(fd, (void *)buffer, sizeof(buffer)); | ^~~~~~~~~~ | getdents /usr/bin/ld: /tmp/ccKILm5u.o: in function `test_getdents64': nolibc-test.c:(.text+0xe3e): undefined reference to `getdents64' collect2: error: ld returned 1 exit status 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 b63afe1975c4..db743144d8f3 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #define _GNU_SOURCE +#define _LARGEFILE64_SOURCE /* libc-specific include files * The program may be built in 3 ways: From patchwork Fri Jul 7 18:27:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305154 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 CAFC7EB64D9 for ; Fri, 7 Jul 2023 18:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbjGGS2j (ORCPT ); Fri, 7 Jul 2023 14:28:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjGGS2i (ORCPT ); Fri, 7 Jul 2023 14:28:38 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9EB31FEF; Fri, 7 Jul 2023 11:28:36 -0700 (PDT) X-QQ-mid: bizesmtp82t1688754507tdrg1h9k Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:28:25 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: WRZea3rwxQma1wpQojp2HUJO9toSuvJ58BA/rW1MdlujMgmE8wzOE1f+ZAxm1 yi/ylEk0muyExC0A3VRaNALKw0dhvoB6nK1Uvs3MifFLYvfb6J6rJ0lVmS3T4dY2Mavdjo4 p7KbkKbvwZMBTvPM5oe/J0DppeEk6wtXg0frKQlHMtFGnMwbVYHdJGWhWi31oGbycVDq+fQ 5mQakxviZLkxKfx1HHtQNqiJVmTM5CTH4hRi5v/AlKQbQsSK1SOx4nDJGw5sbmRqC+SSyFU lx1gUKfdYZ+qD6iBEKWwoWYHGtiW5WJCDEbqviC8tUyIXvJG44r5jMWU0/8aaJ0FSYHd2v3 M149xlrC9bP8pgEQ6KjcVgvoZKPhKVycGTrccOpuZGT+FablhFdjoYv/lLQsTQW40gI6INY X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10073504210191357973 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 05/18] selftests/nolibc: fix up int_fast16/32_t test cases for musl Date: Sat, 8 Jul 2023 02:27:40 +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/ 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 db743144d8f3..fea1b06131f6 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; @@ -827,11 +831,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 Jul 7 18:29:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305155 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 72892C0015E for ; Fri, 7 Jul 2023 18:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232073AbjGGSaJ (ORCPT ); Fri, 7 Jul 2023 14:30:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjGGSaI (ORCPT ); Fri, 7 Jul 2023 14:30:08 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7322684; Fri, 7 Jul 2023 11:30:05 -0700 (PDT) X-QQ-mid: bizesmtp90t1688754595ts3n5v37 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:29:54 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: XBN7tc9DADJx3xrBBNujCbgqiQFsrVO7Qw97Fa4yASrCH5l/MPK8XyD0c+v9H VuIGWjq4fXE8uh1ZrceDIUrqxS9IVjYcxdH09ev5PE+FesVf6Ga0X7q/j97L8j/JuBt0WvJ MEVKdynPhOv69sVotBquSeLNASL4Hasl9Nu3gZrFdmaLgJzlDaNesJ3fsoDD87gB9ivRjVU GxfpnYvmB9VZSnrgAfBP9Qekr3TmHkd1MOf+zwY8D3bddaRLx8UBO3IfKGM+Pk9nCrbIu0h lko7AVERcKQ2JgpPJRGsRxMGyFZytzYbrz+sicbowtZdEOCNIXJJWMYXF108CnhvRTliN/C 46z1PlZbwgejlj5NLbTczrqrDVWQ9nC4g9ZhknhTKT8wvkjSVnVVgQdlKa3QdWai7N+XAU2 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5061810002461843469 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v4 06/18] tools/nolibc: types.h: add RB_ flags for reboot() Date: Sat, 8 Jul 2023 02:29:30 +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 Both glibc and musl provide RB_ flags via for reboot(), they don't need to include , let nolibc provide RB_ flags too. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 1 - tools/include/nolibc/types.h | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 61a3204b00d7..804bc0231ec7 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -21,7 +21,6 @@ #include #include /* for O_* and AT_* */ #include /* for statx() */ -#include /* for LINUX_REBOOT_* */ #include #include "arch.h" diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 5e1bac8509ec..23963e48d8ee 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -9,8 +9,9 @@ #include "std.h" #include -#include +#include /* for LINUX_REBOOT_* */ #include +#include /* Only the generic macros and types may be defined here. The arch-specific @@ -92,6 +93,15 @@ #define SEEK_CUR 1 #define SEEK_END 2 +/* flags for reboot */ +#define RB_AUTOBOOT LINUX_REBOOT_CMD_RESTART +#define RB_HALT_SYSTEM LINUX_REBOOT_CMD_HALT +#define RB_ENABLE_CAD LINUX_REBOOT_CMD_CAD_ON +#define RB_DISABLE_CAD LINUX_REBOOT_CMD_CAD_OFF +#define RB_POWER_OFF LINUX_REBOOT_CMD_POWER_OFF +#define RB_SW_SUSPEND LINUX_REBOOT_CMD_SW_SUSPEND +#define RB_KEXEC LINUX_REBOOT_CMD_KEXEC + /* Macros used on waitpid()'s return status */ #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) #define WIFEXITED(status) (((status) & 0x7f) == 0) From patchwork Fri Jul 7 18:30:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305156 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 8E2C3EB64D9 for ; Fri, 7 Jul 2023 18:31:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232449AbjGGSbO (ORCPT ); Fri, 7 Jul 2023 14:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjGGSbN (ORCPT ); Fri, 7 Jul 2023 14:31:13 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B54F61FEF; Fri, 7 Jul 2023 11:31:11 -0700 (PDT) X-QQ-mid: bizesmtp70t1688754662te5egk8k Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:31:01 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: PKnEab4175t4fCCOaBAG1HRV81wFqu79uG2ElbrfdLJwsbLmf/CHfWIq9WAI9 mMFnF0T8uJJKqWbNdtqiG25QO4SZTc/5v+vF0QjEbwoV6LvXa+rvxJh3jEdUlFWVb6LR4qT ggOTspUaWlNe0z1hX91OLQPCKvzL9hlo7r/mLz8b4kn5RD2Ba+xtkmtkwHXvOGNVRH0Ryh/ RL0wtktRXRgVSMi0RCpmdFuu+PKJ3ojDGKMN6iFeFcEWjz9JTziXwBImIl+XxB0eEVMK8om hAV/dbwMFZjxwn+E1mOxPIH3n+1uxl5juYkt7Ck667Ld7eCN2B7c16RCpWfm+RdsvtA4kCK jA/t04jmFwNVxd8rX5tkljtH2Nounrgw7iUqiTzDPbo0Pe9HIc9xFbPP9h4AQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11273642194411821185 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v4 07/18] selftests/nolibc: prefer to Date: Sat, 8 Jul 2023 02:30:58 +0800 Message-Id: <08f966f8e00b3537701bb10ef651f2ccf3e2d8b4.1688750763.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 Since both glibc and musl provide RB_ flags via , and we just add RB_ flags for nolibc, let's use RB_ flags instead of LINUX_REBOOT_ flags and only reserve the required header. This allows compile libc-test for musl libc without the linux headers. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index fea1b06131f6..12ecae85403e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -15,7 +15,6 @@ #include #ifndef _NOLIBC_STDIO_H /* standard libcs need more includes */ -#include #include #include #include @@ -1180,7 +1179,7 @@ int main(int argc, char **argv, char **envp) */ printf("Leaving init with final status: %d\n", !!ret); if (ret == 0) - reboot(LINUX_REBOOT_CMD_POWER_OFF); + reboot(RB_POWER_OFF); #if defined(__x86_64__) /* QEMU started with "-device isa-debug-exit -no-reboot" will * exit with status code 2N+1 when N is written to 0x501. We From patchwork Fri Jul 7 18:32:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305157 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 C8797EB64D9 for ; Fri, 7 Jul 2023 18:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbjGGScY (ORCPT ); Fri, 7 Jul 2023 14:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjGGScX (ORCPT ); Fri, 7 Jul 2023 14:32:23 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64884212D; Fri, 7 Jul 2023 11:32:20 -0700 (PDT) X-QQ-mid: bizesmtp74t1688754730tpmddvxk Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:32:09 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 9/hKuvo8r2qiKs0BPsLMkVVPxkrgNn124DaeUI3gW/2bweN4vdNsce4iGWkD7 ZB2emfcApeHYHTfsqGTYiqSed7FywLk6HU+Mb0R+XH7O9u06ONfFMBAOhzZPZq22C3dr8PL nM668nQAteMf+MMHG0ZCElWSyAIyMJEcA7pIQnxJ+NrDu9Xtx7VpqZtaT1pJ2pymT2dnghr 7VpfAHHiRNwPcexj6u6v+L9JRwtv08SpMAPS5F2YfD2tRfOi38NcMGDn/iRtJxuqLG2t5Rv Bdxnh1wTNfLPGNawmx7Buv8C8BRKI358K2Ewnt12zy5hQDUhGn7gwIAs+ibRCoafmHC5LLN a6wiJdGXfCOoFDsnmmnJseOsvjM6hC5pw57rLumL3MmoIdNhUW7y6bgwl7Q67bJFbDJGHlO X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13503057603950490039 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 08/18] selftests/nolibc: fix up kernel parameters support Date: Sat, 8 Jul 2023 02:32:05 +0800 Message-Id: <93926809dc98816da6d2fc343727dda61f25dbfa.1688750763.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. 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 12ecae85403e..319cd51eff01 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1072,6 +1072,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; @@ -1098,10 +1127,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 Jul 7 18:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305158 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 0B9DFC001DF for ; Fri, 7 Jul 2023 18:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232620AbjGGSde (ORCPT ); Fri, 7 Jul 2023 14:33:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232602AbjGGSd3 (ORCPT ); Fri, 7 Jul 2023 14:33:29 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA2612130; Fri, 7 Jul 2023 11:33:27 -0700 (PDT) X-QQ-mid: bizesmtp64t1688754798tei8vcry Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:33:17 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 86xnumbl2QwZqoafYHr2RqKYeHwXs6/DxFrlWgoKjAo71LMc57iPjLvpwNtxs rv2en+DwkBn01/z+yElDIEasXOEtdCeE+srxGkNFj5lpAjDUOVm7g4ENrFOvBQnqsbsUduY wegAh4ZxhwBdZCHVCys9Cf2kav+pZSoM4HmR35q2qbEsWQxj4xaES03gNrnZwx8Q3jMcNef Bav9D5CDbAc3vz84DZfIQ0Za6fnfh62xfc7jjEmxYsXZzCZj24f7ZB2m2Q5/MVd3boIvAUh YBCoEbAQZQwfHoMtCMexX035S+/iItReKLC7r331Mr8xRTGeig+FyWO+KMOWT/EXmGsMort LCz00QPY42D8ayzq4ZRKaUHwnGOLk8IasK3n2b0AcphoJeszaIvgTa9NqPC3Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5977546286406332268 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 09/18] selftests/nolibc: link_cross: use /proc/self/cmdline Date: Sat, 8 Jul 2023 02:33:13 +0800 Message-Id: <2f9e9a1fee0132c1422fee94013b43d6c8237e38.1688750763.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 319cd51eff01..cf38df6e036c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -731,7 +731,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 Jul 7 18:34:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305159 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 BC35DEB64D9 for ; Fri, 7 Jul 2023 18:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232404AbjGGSer (ORCPT ); Fri, 7 Jul 2023 14:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232501AbjGGSeq (ORCPT ); Fri, 7 Jul 2023 14:34:46 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20E782685; Fri, 7 Jul 2023 11:34:43 -0700 (PDT) X-QQ-mid: bizesmtp67t1688754875tv67uwp3 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:34:34 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: lO87fmWkX3HpsLfCTb5+tVIiOoTKdAOMqPvXKyQaIVThl5VL9goMsQIls+Xbj kl3u0in0xHM7RNVC00ryMWbvQRHgGvwn3XpXtpN4DpADWw2EIUnWs5VZdhMrNM2Ad2hQdWK onn7iIrumRQb33g1ICrYHJOJqYlQwUuULrBTP6A5za9MXEVNQfQ2F9dkFvvYVSMAp0rcXTX ILIWuBznvTEtO6aJ3MWIyQPf+L+eODvh5sHZHL38mjvHFXIl44cFcNA2Mi3SS95AjK6p/lv PvDRYv46O7Ht0Ig5ygo5CxVKVcRVEd3wkQm0PMJKY3xI6yARcFZ5ti5OeMY1K+9hwtp5i2W ThpacGhwgfI8uHEkZhLK36wYrMogXXYqJspOsc3Ghdhg2KjCOY= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7451315100261662590 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 10/18] tools/nolibc: add rmdir() support Date: Sat, 8 Jul 2023 02:34:21 +0800 Message-Id: <3d6088e256c5b3961b433b52431f43e52f3e0634.1688750763.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 804bc0231ec7..dee56894a811 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -611,6 +611,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 Jul 7 18:35: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: 13305163 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 758ECEB64D9 for ; Fri, 7 Jul 2023 18:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbjGGSgz (ORCPT ); Fri, 7 Jul 2023 14:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjGGSgy (ORCPT ); Fri, 7 Jul 2023 14:36:54 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43301212C; Fri, 7 Jul 2023 11:36:53 -0700 (PDT) X-QQ-mid: bizesmtp62t1688755003thv00ahq Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:36:41 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 1U/NVTUyJNRN0eVRoV/JWKQm+a7U3weNCZBdkyyMVSia0m71d1xtzIa8DOFhA N0TwrxzgpjWXzP9zfmgoZW2Cufl34X2a+7w15wEMPe6E6pCL8x89GM8y3nqpEplu4Jh08NG wsA2vv/+RVoM0f1g++R8yCGzItWPV8YFh2hs0PIVaOxM1GTVKfSTMvGjsCrixlqXAiitUv6 WEBlCPAs6c3IM6uS/mu7sR8aRhMlNeJa35Wq6CsUV2w1C8yFHEd6fvn7pWIDlyDT/oIDv4S tLXiej9Sa9n4XS1/EO3weE9bQntTf7GZ03qvZXlRQjwI62XEXxYTtFL3J0mMHuF6dINvORw XG4QYAA1iwkZljCnA4xHGyADfv6qS7gJA9kjPtRKHs9hNYfVp3Nj1+I7Zbpf9R2szIdGLT2 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15480877985008218786 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 11/18] selftests/nolibc: add a new rmdir() test case Date: Sat, 8 Jul 2023 02:35:38 +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 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 cf38df6e036c..deff804e0753 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -745,6 +745,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 Jul 7 18:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305164 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 906E5EB64DA for ; Fri, 7 Jul 2023 18:38:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231249AbjGGSiH (ORCPT ); Fri, 7 Jul 2023 14:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjGGSiG (ORCPT ); Fri, 7 Jul 2023 14:38:06 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D896D2130; Fri, 7 Jul 2023 11:38:04 -0700 (PDT) X-QQ-mid: bizesmtp76t1688755075t7a4e2ih Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:37:54 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ShvZ91UTFj5yB/+Ev38CMV6CIpBprc4qrbbU2hYxpW1GkZvzMatwzYL4FyhsW 3PRijSlAFL9abUjBsl9bR0EMlSyhRsjaTrNV0VJIz9o2Lu3s/NxlwYtWnq5IZlpkP8qwLGZ byyUrdoh7A4uqCtoGF++2PSdPA/ghnEGO55qrfHpYNJR8v0kep7i2XxsZSuOzQpBbMK69ka PtjnVo06Ej+OrvisdUcKHfKsWkMhfgkIAsSMqnNV5Jh3OdURa4Ccfkun3cDNHID0Dd9gxM+ rO728L8eoQTBwez3nXhh7MOx4PQwCd1Yju0SaeD4mkq4bp/B1gSMysr++ZXflvaxUHsCV6A wcc8O2OMkrgxrhWjIV49plnXKA5wQaw5nCuXfaraIM5mKFGlDBUp2SaFKsJkw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8013575817692833523 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 12/18] selftests/nolibc: fix up failures when CONFIG_PROC_FS=n Date: Sat, 8 Jul 2023 02:37:45 +0800 Message-Id: <563c1ceb201ad95221610ef3a4aaed48640b4e8d.1688750763.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 deff804e0753..5497ee86cf40 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1056,8 +1056,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 Jul 7 18:38:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305165 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 9BF48EB64D9 for ; Fri, 7 Jul 2023 18:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbjGGSjS (ORCPT ); Fri, 7 Jul 2023 14:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjGGSjR (ORCPT ); Fri, 7 Jul 2023 14:39:17 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA4832684; Fri, 7 Jul 2023 11:39:14 -0700 (PDT) X-QQ-mid: bizesmtp62t1688755145t75gkm14 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:39:04 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: KvvwR/hcPA3zMYK1CcceBKsYTp/4/3pjRiGuKwCnZov/MPcdg6J8HujwWwHn5 /8+dmG2yvIOgNqB0jCgFmPi5Ha91Smk+4wKn891hXp8XbdYOjS79GGq20AcOIqAKxPAl8/0 4Cz0RXglli0Mvtl8Yq9J6jkbxTgmjSd16/syAnHj5NP8vI2kdNHnj4e5lM/CiJjdEv/GHL+ 97VoOznzLptB5D3ml4BUFJHo4EbLyPAS4mFOXcyXji3b9CNlU5SCnSwGILew7dI1cBLOl8y HhUDN+VuesWus3Y8xdcf3anZt6OUgJrj69kSKyIhv8LnqVl7ZK36w1QsGhaH42/m1v3jAcz gnjSZjbRmd4zusUN7+Bcc0TlLy63T2l89IpnXOhwe1rNEufsfDLVAoqfiFX6g== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13821968345218044229 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 13/18] selftests/nolibc: prepare /tmp for tmpfs or ramfs Date: Sat, 8 Jul 2023 02:38:57 +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 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 5497ee86cf40..6b863f7b677c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1063,6 +1063,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 Jul 7 18:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305179 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 254A4EB64D9 for ; Fri, 7 Jul 2023 18:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbjGGSlK (ORCPT ); Fri, 7 Jul 2023 14:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbjGGSlJ (ORCPT ); Fri, 7 Jul 2023 14:41:09 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB2292686; Fri, 7 Jul 2023 11:41:06 -0700 (PDT) X-QQ-mid: bizesmtp89t1688755258tl15jmsd Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:40:56 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: pMHwdq3i9JMdscoC4rTMu/NiAUoIRiiFj3qeqqHtFAEulmGT9cGyKGZzstgvB EuvAHvEWur986HyyMuCngFP7Y9/35QpomwUGhdan4ddVmrh4/z3FyI1kAT+wbbhQqj1wNmY lyFDJoSZrwQdG+YhAVAC/1IhLwK2D7jlHutttbAKCXDDU2q6TUCFm3U2bppd+h5FKYR9H0w Zm0ga1G4kQSD8wwF57ei8KmUCLA1jiQTrPCoaQMzWqbKo5CtGWWmUYV3RQCPEvixPWIpfks VvW3wrSGK6TShyAzvTg2GVs0EowUSjJxDeYvxeN+801tpi3D3QCQ29gHA3DMHlC1tfeOkXG fR0VzH8ZEJaQpOBCcABNTa4fjjUvaZ/U54BV4N16uvPkMMTcrQ2XZH4HmN02JVUA9LCDb2p VcOV2RIPInI= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6393069016375536476 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 14/18] selftests/nolibc: vfprintf: remove MEMFD_CREATE dependency Date: Sat, 8 Jul 2023 02:40:08 +0800 Message-Id: <94bdca8d8610e85bb1683bf10a5005ca92c3cb57.1688750763.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 6b863f7b677c..494195890e4b 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -875,10 +875,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+"); From patchwork Fri Jul 7 18:42:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305180 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 02703EB64D9 for ; Fri, 7 Jul 2023 18:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbjGGSnA (ORCPT ); Fri, 7 Jul 2023 14:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232712AbjGGSmy (ORCPT ); Fri, 7 Jul 2023 14:42:54 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5B12684; Fri, 7 Jul 2023 11:42:51 -0700 (PDT) X-QQ-mid: bizesmtp78t1688755361teq9xbkx Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:42:40 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: CR3LFp2JE4nH57ZbWfbpkynHmLRqBni2IKe5Hryw+3skA19dDY1bF6R4kIxbq oqTWzkbWrAXmYcKLOEF7Nysxicv3HEL8I8SurRZeGfKZx8CUXH39S2TX++/GRDf3kTfasZm EZNdcgFqqy2mhE4rIszH+lLV+kvqdWqrm7zA4c63RpdsxBPepWxHorukBNQrtdoYXbA37Rm RQNe0IY+Y+AS/o+Qmo/YhfA497Ns+5w+RT+c8QgSElqosOf6dUO073FHy4tpVByEWNOPC1Z VgGikTFw3EgAxouDFC/cCOyhjGjWg0okvA0i9Nmp40vPReOUvzRJazH+4adv7svGonENGHC gmvh9BlWpozE4xCUe9RnGikPEBfK82MxxnbWI+NIPXmc2H2pK9m7bTaB2vkCEfRoqO1H8VX X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4020998193701605089 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v4 15/18] selftests/nolibc: chdir_root: restore current path after test Date: Sat, 8 Jul 2023 02:42:01 +0800 Message-Id: <94cc3448a992e38a0ed22d5089b8a42235db24cb.1688750763.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 PWD environment variable has the path of the nolibc-test program, the current path must be the same as it, otherwise, the test cases will fail with relative path (e.g. ./nolibc-test). Since only chdir_root really changes the current path, let's restore it with the PWD environment variable. 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 494195890e4b..0ed207495ea6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -703,7 +703,7 @@ int run_syscall(int min, int max) CASE_TEST(sbrk_0); EXPECT_PTRNE(1, sbrk(0), (void *)-1); break; CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break; CASE_TEST(brk); EXPECT_SYSZR(1, brk(sbrk(0))); break; - CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); break; + CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break; 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; From patchwork Fri Jul 7 18:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305181 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 1F5C7EB64D9 for ; Fri, 7 Jul 2023 18:44:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232723AbjGGSoS (ORCPT ); Fri, 7 Jul 2023 14:44:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232718AbjGGSoR (ORCPT ); Fri, 7 Jul 2023 14:44:17 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A0722684; Fri, 7 Jul 2023 11:44:15 -0700 (PDT) X-QQ-mid: bizesmtp63t1688755446tq21jiw8 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:44:05 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: uGhnJwy6xZK2nzJD+cc5kZhLnCKCdne1Sfn1JdSmLb7re57uLtOqm35U5ddys GFLzxnlh1Sxv6m4JRyUpmAa4AIbblGLl2nbv0I7OsuFuxSujLPifjVJnU2WipHjHY77aTAn XMCJ3xtv5jkAvnSMwtWG48/N8VTl2MX/ViF1B1zJqPghy6LXYvGq4ZNjVJtY/XuxjwlNHqp oJkZJPtS5NCXhYajJbNwoVS4uq2RRHjszfLxMJc0FCnvZcmkwuyLfu59mf2cJ+BThUvUqmP 3JtWYClB+QxvgFQG6MUHTGZ7ZCatDTbHkalQcS7xZx003ILw4PMM7fmfXkJ88fEadcnCqw1 0THSH3uA2CMbwSauyKirykkIZd/0j2iyLyqeWk2j2HNDc8hI6S8Mj9qqR6sU48rRqf1YyvU X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6129854655699815004 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 16/18] selftests/nolibc: stat_timestamps: remove procfs dependency Date: Sat, 8 Jul 2023 02:43:44 +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 argv0 instead of '/proc/self', use '/' for the worst case. 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 0ed207495ea6..2065b5b0d171 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -584,7 +584,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(argv0, &st) && stat("/", &st)) return 1; if (st.st_atim.tv_sec != st.st_atime || st.st_atim.tv_nsec > 1000000000) From patchwork Fri Jul 7 18:45:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305182 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 089A3EB64D9 for ; Fri, 7 Jul 2023 18:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231587AbjGGSp2 (ORCPT ); Fri, 7 Jul 2023 14:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjGGSp2 (ORCPT ); Fri, 7 Jul 2023 14:45:28 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE522130; Fri, 7 Jul 2023 11:45:26 -0700 (PDT) X-QQ-mid: bizesmtp67t1688755517t6zf8zx8 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:45:16 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: Xz3VOcA7Mr23TD+MxBGuqCLuoaQVTw9wn1kX2MooEVE7xaVCf2Ulc9NFyLVp4 J2s7OzOFoftCwuXSVhAq4XJYt0Bue03Q18ZXrM8uvRsnudoZ58mWFkJz4yNFBkdOXL5xGMy CAdhWhwFThY9IuFQswZCjPkQsCMI5iCg0vm8IBYnrufY9/Sj5hImKJsCPCTfn+HK69z3W73 Vc70g/bvm+n06Lj6Qj0uWrJ6OgXUfrgXjF0YAfROflWkrTqyUmWc4SG0SDCW0ht3EFP6zx6 ldzx+YG5BRFT+wO2ILNcZQgD0Vyfm2FqutCTFvZPHk4E4pRKB/PaMlMCFT/aeN2VJbws/U1 g1iL+8qT8tm/WUsZEWokHzfTcNXtuijoW7U4DpiTgajggeXt2exFfunqENitR74BnUWMQRy X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5870997765808739935 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v4 17/18] selftests/nolibc: chroot_exe: remove procfs dependency Date: Sat, 8 Jul 2023 02:45:08 +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 Since argv0 also works for CONFIG_PROC_FS=n, let's use it instead of '/proc/self/exe'. 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 2065b5b0d171..c74b2af2414e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -710,7 +710,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_SYSER(1, chroot(argv0), -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 Jul 7 18:46:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13305183 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 ED6B2EB64D9 for ; Fri, 7 Jul 2023 18:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230503AbjGGSrM (ORCPT ); Fri, 7 Jul 2023 14:47:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbjGGSrL (ORCPT ); Fri, 7 Jul 2023 14:47:11 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD91CAC; Fri, 7 Jul 2023 11:47:09 -0700 (PDT) X-QQ-mid: bizesmtp79t1688755620th4o4fq9 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 02:46:59 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: swyrzWPvyR2YsBS+GP8c8VCuAw6ly3u9jQq5KwZxHb0xtgpoYXkfWu3pVJOQ9 ys+i2xXVpkqyPF3E/3/ARVmgKkgA8+l8q4LWeAGtBEdFmpFqCwlx525QsO2WBpCDOZk1Mzn kgNXhK1hobQGI6JixpPn6cJnbpOP8TvkTaR3BXQsnxS1Nmb8mY1aip9nCuKbZqFPKWChQFQ 3OObuv6i2dVBRM0VU/RXq8oNJiFJn7QE64l+GWPHCsHftDnAnNE69xmnGAXzuMEXz7xfP4b B3Fwh9/gx6GQZHK6Afo6oBvlpNd9j7DtMZb0wCrDx1DBtSx3QfpeRzpTkoAvFHz4SSnBFBV bHbpt4aZkJFmbmAn4G5huzHV0wwFRSTE6KjrcYT1dKjJjfnqDv3L43cZNyFSQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6858150708780378719 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 18/18] selftests/nolibc: add chmod_argv0 test Date: Sat, 8 Jul 2023 02:46:20 +0800 Message-Id: <23f35e7c435e5ff254b2c75239eed0aa4ee36b25.1688750763.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 argv0 is readable and chmodable, let's use it for chmod test, but a safe umask should be used, the readable and executable modes should be reserved. 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 c74b2af2414e..10247fbbdace 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -706,6 +706,7 @@ int run_syscall(int min, int max) CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break; CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break; CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break; + CASE_TEST(chmod_argv0); EXPECT_SYSZR(1, chmod(argv0, 0555)); break; CASE_TEST(chmod_self); EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); 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;