From patchwork Thu Jun 29 23:29:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9987863vqr; Thu, 29 Jun 2023 16:51:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlFiWgBmuJOIRX2e5Lk/HxlI3NMaMz3aZ9Ajg+MCFbPbiJtZEiQz3duSa24aCjyjj7jx/iyb X-Received: by 2002:a05:6a00:26dd:b0:66d:d03e:3493 with SMTP id p29-20020a056a0026dd00b0066dd03e3493mr1533514pfw.2.1688082679109; Thu, 29 Jun 2023 16:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688082679; cv=none; d=google.com; s=arc-20160816; b=ybdIoz6RwjeVDmSap2qJP5CTpYjtGjJAugdMZEz9nluOShJlb7YtPbwFQ4TDd53O1F mNjw+mOVKBpzTiR8ahn7UAOkWmMsQ7lEeqrgpXdoQ7Mxa5rDLOPcE3NvM4RQpROAV655 Xd6x0dRTM5ztT6J/zGbz2WHGTBabFxg8CUL7fA5PxELtlsc8ruRJTt5sgAWloCQXFFnt 7sZ6UmxjUuMTK7RByWPBgkXO29kc0dn+K4nJdEjb6bUJ65b4A4EckDNqKohpVrPt35EP 4aOVvyP60Qtdykz5vS1w+Aa42Cs8F0P1GC/M3ZkNM0YOJR2iC7smYRAVTGE/0LkI6z1a I7Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=b6nt0VtLN9PoDORpj3/mw2jx1EgRCIuW0ppt4XcES2A=; fh=GzghTQzqgly4pZn8BwQ4U8bZ8zCadAK8Sl/utskeyEs=; b=siWeIUccnlB36U9rkrH/IEKdlWE6anJJQwx60l+CczGfvTXSes+gSfrX4+NbLEEau6 y/6OubbrQpF/8vJLZg9oOdLEAyLidEwB+mw+dJKdAkuZMpuGDZTZTkabepRWjH4855zP rb8201ViwCM5aPfBQFtUocrRJc40oO6D/F4YAkq3/G35vnBZxKawdWegXV+s8vZePfL4 MmtwOhQ9n/23lqQgFQhCOaolGxfRJrvgskM0rHz192R/4I4ZDdRvkiUMOEyS0xLMEEaJ RP/U8dDVxdBWIXkJdJ5w4MbzWgxlMiBqnIPrlDHE46IT9898lp1U7eLblF/ZGqmgOhkO LcZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a056a00158b00b006797c2c00besi8157256pfk.144.2023.06.29.16.51.06; Thu, 29 Jun 2023 16:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231766AbjF2Xaq (ORCPT + 99 others); Thu, 29 Jun 2023 19:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjF2Xam (ORCPT ); Thu, 29 Jun 2023 19:30:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694EC1FE7; Thu, 29 Jun 2023 16:30:40 -0700 (PDT) X-QQ-mid: bizesmtp77t1688081430tg4lkoyb Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 07:30:29 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: CR3LFp2JE4k2yCeR62ZuAGYUgkT1yq1gp7tSCx6PjhF/mNkyHruYzL79SeB7z CxTzPB7K2xFoUA/Ttaf/5FeV6L2uZdCkhc6XFd+y19TuqfuZXiEi8MxdsIwOmgQRqo4pRJU K9nE+AfOZFt1gnTXokRNuOjIyGH60R8MmM8qcVuceDH066+FiI3ebXS5ucV6i39M2LmgDgX jrMaXXzbKZXF1L/CX6tToO/a7QqbP3ZC94AEgLSNMjGkx1IUrGdvDHYo0t+4/y0ZadUrf9Q vKbj105VV3iJAVITKR8OC3793oJJQd58PXOK0m5ZJPs8AqexcipJTcZV9r6PDKW2fFm5tY3 UAyjZgTMxfiyqXCHysiWctOPNpjl1iIdiX5pdzoth3fQjGgjLzGMXhonNol+Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8005163360113825460 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 05/15] selftests/nolibc: fix up kernel parameters support Date: Fri, 30 Jun 2023 07:29:38 +0800 Message-Id: <582776208a75df19d09b8eaafcb6fdad7219abc8.1688078605.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770082983038224382?= X-GMAIL-MSGID: =?utf-8?q?1770082983038224382?= kernel parameters allow pass two types of strings, one type is like 'noapic', another type is like 'panic=5', the first type is passed as arguments of the init program, the second type is passed as environment variables of the init program. when users pass kernel parameters like this: noapic NOLIBC_TEST=syscall our nolibc-test program will use the test setting from argv[1] and ignore the one from NOLIBC_TEST environment variable, and at last, it will print the following line and ignore the whole test setting. Ignoring unknown test name 'noapic' reversing the parsing order does solve the above issue: test = getenv("NOLIBC_TEST"); if (test) test = argv[1]; but it still doesn't work with such kernel parameters (without NOLIBC_TEST environment variable): noapic FOO=bar To support all of the potential kernel parameters, let's verify the test setting from both of argv[1] and NOLIBC_TEST environment variable. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 33 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 96d170cc9b47..223c00e83abf 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1063,6 +1063,35 @@ static const struct test test_names[] = { { 0 } }; +int is_setting_valid(char *test) +{ + int idx, len, test_len, valid = 0; + char delimiter; + + if (!test) + return valid; + + test_len = strlen(test); + + for (idx = 0; test_names[idx].name; idx++) { + len = strlen(test_names[idx].name); + if (test_len < len) + continue; + + if (strncmp(test, test_names[idx].name, len) != 0) + continue; + + delimiter = test[len]; + if (delimiter != ':' && delimiter != ',' && delimiter != '\0') + continue; + + valid = 1; + break; + } + + return valid; +} + int main(int argc, char **argv, char **envp) { int min = 0; @@ -1088,10 +1117,10 @@ int main(int argc, char **argv, char **envp) * syscall:5-15[:.*],stdlib:8-10 */ test = argv[1]; - if (!test) + if (!is_setting_valid(test)) test = getenv("NOLIBC_TEST"); - if (test) { + if (is_setting_valid(test)) { char *comma, *colon, *dash, *value; do {