Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp965664pxb; Fri, 28 Jan 2022 14:24:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUSzaz+G3u5OU0AkeSl3k3dIIQXIZUGzHrFed4IdbTMmPEbjYTw/cR9YYnmP+mfLZjRwVa X-Received: by 2002:a62:b40e:: with SMTP id h14mr10316450pfn.79.1643408671365; Fri, 28 Jan 2022 14:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643408671; cv=none; d=google.com; s=arc-20160816; b=fiendvRoQs9Ncb3bJc0FXdIkehbVBYU/yJG2RkiX8MxPf3mWWf5pqlMbA/OeUY8U6M B/sRkOmYdovSln4fAxbGgQNkWGFz7LM0ywvR5gLRPuruoTiK3qkJPBJ6Q1ONeFCoRY4s kaCfYjFNHj78OVWzKjMhADHqRMiB68b2K4fOqLy95Z372n5w+J3ZrnJRDNDVDHuXNH5I 2IPbawHjQ73cAEZL0oPBtqj8Bz60eNHJBQP9vj95ZewFn+mKWAyW9cTRNWCE6+Qqj1Cv xxptjOkd735f7E7gxy1eKf0fiLr4qTzYQu08M4kUInBIjbCz0jWDvJCFOmZlC6hIn8Jk 0yZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=RYM+OoI+sRVj0DaSYGxbB41tOrylxhqAidM+/G1N3g0=; b=09cpsd2MfTmzVcpyrmgFtBtArNlVKheAKfVGtBx6/afbPaeavo2R000V8qou9hI5zJ +8uIA2cygLFoKqsaYweDQtRZwEdpFzy9c7Ahc2njlNuAP1NonRc1bF0zehKzQT9HehMQ JI/kUWmYv0ybNvezyOhnUP7W/Flr5Iw8GDaGX8Itx+N2gndecO3SPApu3xCr7VsMON6O okk/vUH3t7CGQiqcAdjjZ7al+fZGtSsvZHeeoN5idC3F+ZRsgFAYL1ijnn1FxjjqUi4+ ++OJZjYOrpt3vbP/oXXPuRIJt0EAeh/Q2MBuMZ5omdViTCo/LgL0DC2WRJdp28RPsD7J a/Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=aUmOfv6a; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si6377704plb.321.2022.01.28.14.24.19; Fri, 28 Jan 2022 14:24:31 -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; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=aUmOfv6a; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243589AbiA0Xfz (ORCPT + 99 others); Thu, 27 Jan 2022 18:35:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241405AbiA0Xfy (ORCPT ); Thu, 27 Jan 2022 18:35:54 -0500 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A50FC061747 for ; Thu, 27 Jan 2022 15:35:54 -0800 (PST) Received: by mail-il1-x133.google.com with SMTP id w5so3961979ilo.2 for ; Thu, 27 Jan 2022 15:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=RYM+OoI+sRVj0DaSYGxbB41tOrylxhqAidM+/G1N3g0=; b=aUmOfv6amDCIBKl7cyPdoqr3OVRCXg/GstZMqtSv+fITjqVWvfqyOq/r0cMRiImy7f jbXsYP0X2iG49ox22cjU1ue9zF3rsmeyuVuo8MfW9gXAxR/U7nhC6eGB0v5bHYIi9yuY gVjAWZgleK+Hx7zcLbv28glClAnV0OyI80Af8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=RYM+OoI+sRVj0DaSYGxbB41tOrylxhqAidM+/G1N3g0=; b=HDtqSaDj+6Jq8xPE0ZXwR8buaW6okLwhKqEHUb1Fs7+f78Ra3WK+iyq1KnXGXUDpJA RNqaCQYQzf+L8FadWOoJ2cU9FdoRuXIDM4C9seAkkcdab2DGJsKuoBNxtURNX2HljoZB LXOOMNWDiENRzEvl174B479bH9QmHCtRLl4S9fmly8rdcUDpT160e10JqgBy3koVNpAe bmgUWzguT+xm15fP/ee+DX+IjEkqo0hjSRKHHXbMBa4kOLUCIiz2bltVi8l+V5sHwu/t tWXMIHQ64QEqqL7cT3BW43K6pv73rnB1xjQDxsSV7Cw7QvhT1T4bE+xyr/+j5e73gFvG o6TA== X-Gm-Message-State: AOAM531mLSHCR9vQgudkUNm4g5JLt9mcKHXWkpiYlYIGqKmR+7VewuE7 XGa3O6bMMtBVFzWKys/miiL56Q== X-Received: by 2002:a05:6e02:1a8d:: with SMTP id k13mr4160072ilv.257.1643326553510; Thu, 27 Jan 2022 15:35:53 -0800 (PST) Received: from ?IPv6:2601:282:8200:4c:fcdb:3423:ed25:a583? ([2601:282:8200:4c:fcdb:3423:ed25:a583]) by smtp.gmail.com with ESMTPSA id y11sm12708870ilp.18.2022.01.27.15.35.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jan 2022 15:35:53 -0800 (PST) Subject: Re: [PATCH v4] selftests/kselftest/runner.sh: Pass optional command parameters in environment To: Cristian Marussi , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: shuah@kernel.org, Kees Cook , Shuah Khan References: <20220126103230.35285-1-cristian.marussi@arm.com> From: Shuah Khan Message-ID: <6905ff91-c363-91b3-7240-8bb728f45c39@linuxfoundation.org> Date: Thu, 27 Jan 2022 16:35:51 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220126103230.35285-1-cristian.marussi@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/26/22 3:32 AM, Cristian Marussi wrote: > 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" > > Looks good to me. Applying to linux-kselftest next for 5.18 thanks, -- Shuah