From mboxrd@z Thu Jan 1 00:00:00 1970 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 F1436EEB569 for ; Fri, 8 Sep 2023 18:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245673AbjIHSC3 (ORCPT ); Fri, 8 Sep 2023 14:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238069AbjIHSCX (ORCPT ); Fri, 8 Sep 2023 14:02:23 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F2862695; Fri, 8 Sep 2023 11:01:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3977DC43397; Fri, 8 Sep 2023 18:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694196056; bh=7b2Oe6+qXpTGIi+Hwfw3z7qcnnB7BgV1QYcvYDD1nKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nydx/Bzqj4vZNp4s4Gjm7sImYWdgrUAeaBftLNv1KMKfCCgz2hr9bpWXMsbDl9SF8 Onjw+EvvcqcYK/vBZRNuNcyBkOYRTiSsN22/zWKB+SCYc0Wp16rvutzgKNKlmodjNb 5KFJCa2Y/V7QT/C5ZrYrhNg+ZnsJk3OOF8OsKMK6uuB3ZJ9zx+2+dVyev1x2hP5dFX mDbPyW7fYHiWTe8/Sb2/QIUd/xFJ5ZggYJMooujzbN9+ugtpPwG5h0+EIl6bblIuZX fj/3PI3QXKoWFSheYIuE3rRee0YnJGV9j/ecHqhkmYiMcS5nXLdmK9X7dUlQMcu2po 7RfeDTXF696gg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , Sasha Levin , shuah@kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 6.5 15/16] selftests/nolibc: fix up kernel parameters support Date: Fri, 8 Sep 2023 13:59:52 -0400 Message-Id: <20230908175953.3457942-15-sashal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230908175953.3457942-1-sashal@kernel.org> References: <20230908175953.3457942-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.2 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu [ Upstream commit c388c9920da2679f62bec48d00ca9e80e9d0a364 ] 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 Signed-off-by: Willy Tarreau Signed-off-by: Sasha Levin --- 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 486334981e601..55628a25df0a3 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -939,6 +939,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; @@ -964,10 +993,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 { -- 2.40.1