Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5482139pxb; Wed, 26 Jan 2022 13:05:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbKp9c7t2vvT0EuYLsC7n2MmMnaDDFrL4feB6U5XBwEROtuTXqR40etuRQuNHHptV9OSES X-Received: by 2002:a05:6402:268b:: with SMTP id w11mr707978edd.399.1643231123723; Wed, 26 Jan 2022 13:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643231123; cv=none; d=google.com; s=arc-20160816; b=uJAlDJUa4VHJr5lLJVwNuRTSlnnNfqqQCqljzGXstNx5EaJ7agH3BA3j+tNB2AD7yC ula2w8poZFPqpKTp24Bu8TQK2aUDn5zTghw4ZM9I+4zQ9sxN7L+9ZRz8Mtvfd+0IpN8Y gt1Q90wOxoEyrWVgf0gEcCX5xtDmTWQh4drqg8gEwQ8ULg3CMg09vHYkiuQiXGsTF98e 7j8bo7cutrdnwoRKDNyJikGTN2GSICmtcrnEBdtC2qW70jcGX9BPzGAd5P97wqfZIKWK KQ61MpbEbSLUAj96qko03pj9VExjBj7DVuIe86YntcJKnkPCMGb3w7PYuow9iG//8jZh /gJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=E0nk5I0SmLxXfFkwkY1q90ZMtWJ7quNcPShePfXDmrM=; b=vBSRnSPmcwbU1Nk6JFtFMAESOvo4FZf5A3YY8nIj9toBu9IcEddj1v6w9UFiF2+ePf swORfCmF8nCdxDjIJJKOAPTDPp5Pi1MbQCoolqnQrAhQi35sbvODryJyC1003RIi/uwQ d6GK9idg+/0I+/a7C8b7dOtGAfUzw82krSKQVfeVqfY1gS9uBRIa8pBrd72KbziN0EGf gVODLnhmQ5LdkuXLva4EMr6E0dZ9BicBNotX47xOpUwkGHf1HaR0IvzzWlsJDZ711Z6A h2lrktV1RktR9ToasTyvqjnmeFBur059wJG5M0ojE02WJO+C/Obb0LK1zS0CC6ujbL56 5bdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp5si188835ejc.435.2022.01.26.13.04.58; Wed, 26 Jan 2022 13:05:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240016AbiAZKcx (ORCPT + 99 others); Wed, 26 Jan 2022 05:32:53 -0500 Received: from foss.arm.com ([217.140.110.172]:58250 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240029AbiAZKco (ORCPT ); Wed, 26 Jan 2022 05:32:44 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 251C91FB; Wed, 26 Jan 2022 02:32:44 -0800 (PST) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 02A9D3F766; Wed, 26 Jan 2022 02:32:42 -0800 (PST) From: Cristian Marussi To: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: shuah@kernel.org, Cristian Marussi , Kees Cook Subject: [PATCH v4] selftests/kselftest/runner.sh: Pass optional command parameters in environment Date: Wed, 26 Jan 2022 10:32:30 +0000 Message-Id: <20220126103230.35285-1-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some testcases allow for optional commandline parameters but as of now there is now way to provide such arguments to the runner script. Add support to retrieve such optional command parameters fron environment variables named so as to include the all-uppercase test executable name, sanitized substituting any non-acceptable varname characters with "_", following the pattern: KSELFTEST__ARGS="options" Optional command parameters support is not available if 'tr' is not installed on the test system. Cc: Kees Cook Signed-off-by: Cristian Marussi --- v3 --> v4 - rebased on v5.17-rc1 v2 --> v3 - improved varname sanitation v1 --> v2 - using env vars instead of settings file - added missing varname sanitation Usage examples: KSELFTEST_RTCTEST_ARGS="/dev/rtc1" /opt/ksft_fixes/run_kselftest.sh -c rtc KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10" /opt/ksft_fixes/run_kselftest.sh -c cpu-hotplug --- tools/testing/selftests/kselftest/runner.sh | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index a9ba782d8ca0..294619ade49f 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh @@ -18,6 +18,8 @@ if [ -z "$BASE_DIR" ]; then exit 1 fi +TR_CMD=$(command -v tr) + # If Perl is unavailable, we must fall back to line-at-a-time prefixing # with sed instead of unbuffered output. tap_prefix() @@ -49,6 +51,31 @@ run_one() # Reset any "settings"-file variables. export kselftest_timeout="$kselftest_default_timeout" + + # Safe default if tr not available + kselftest_cmd_args_ref="KSELFTEST_ARGS" + + # Optional arguments for this command, possibly defined as an + # environment variable built using the test executable in all + # uppercase and sanitized substituting non acceptable shell + # variable name characters with "_" as in: + # + # KSELFTEST__ARGS="" + # + # e.g. + # + # rtctest --> KSELFTEST_RTCTEST_ARGS="/dev/rtc1" + # + # cpu-on-off-test.sh --> KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10" + # + if [ -n "$TR_CMD" ]; then + BASENAME_SANITIZED=$(echo "$BASENAME_TEST" | \ + $TR_CMD -d "[:blank:][:cntrl:]" | \ + $TR_CMD -c "[:alnum:]_" "_" | \ + $TR_CMD [:lower:] [:upper:]) + kselftest_cmd_args_ref="KSELFTEST_${BASENAME_SANITIZED}_ARGS" + fi + # Load per-test-directory kselftest "settings" file. settings="$BASE_DIR/$DIR/settings" if [ -r "$settings" ] ; then @@ -69,7 +96,8 @@ run_one() echo "# Warning: file $TEST is missing!" echo "not ok $test_num $TEST_HDR_MSG" else - cmd="./$BASENAME_TEST" + eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}" + cmd="./$BASENAME_TEST $kselftest_cmd_args" if [ ! -x "$TEST" ]; then echo "# Warning: file $TEST is not executable" -- 2.17.1