From nobody Thu Sep 18 08:32:21 2025 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 D3682C4708E for ; Thu, 8 Dec 2022 02:30:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbiLHCaF (ORCPT ); Wed, 7 Dec 2022 21:30:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbiLHC3z (ORCPT ); Wed, 7 Dec 2022 21:29:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2985B93A4F for ; Wed, 7 Dec 2022 18:29:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D068AB821EB for ; Thu, 8 Dec 2022 02:29:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2A54C433C1; Thu, 8 Dec 2022 02:29:45 +0000 (UTC) Date: Wed, 7 Dec 2022 21:29:44 -0500 From: Steven Rostedt To: LKML Cc: John 'Warthog9' Hawley , Masami Hiramatsu Subject: [PATCH] ktest.pl: Add shell commands to variables Message-ID: <20221207212944.277ee850@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" Allow variables to execute shell commands. Note, these are processed when they are first seen while parsing the config file. This is useful if you have the same config file used for multiple hosts (as they may be in a git repository). HOSTNAME :=3D ${shell hostname} DEFAULTS IF "${HOSTNAME}" =3D=3D "frodo" Signed-off-by: Steven Rostedt (Google) --- tools/testing/ktest/ktest.pl | 9 ++++++++- tools/testing/ktest/sample.conf | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 1737c59e4ff6..ac59999ed3de 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -802,7 +802,14 @@ sub process_variables { my $end =3D $3; # append beginning of value to retval $retval =3D "$retval$begin"; - if (defined($variable{$var})) { + if ($var =3D~ s/^shell\s+//) { + $retval =3D `$var`; + if ($?) { + doprint "WARNING: $var returned an error\n"; + } else { + chomp $retval; + } + } elsif (defined($variable{$var})) { $retval =3D "$retval$variable{$var}"; } elsif (defined($remove_undef) && $remove_undef) { # for if statements, any variable that is not defined, diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.c= onf index 5e7d1d729752..2d0fe15a096d 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -259,6 +259,14 @@ # If PATH is not a config variable, then the ${PATH} in # the MAKE_CMD option will be evaluated by the shell when # the MAKE_CMD option is passed into shell processing. +# +# Shell commands can also be inserted with the ${shell } +# expression. Note, this is case sensitive, thus ${SHELL } +# will not work. +# +# HOSTNAME :=3D ${shell hostname} +# DEFAULTS IF "${HOSTNAME}" =3D=3D "frodo" +# =20 #### Using options in other options #### # --=20 2.35.1