From patchwork Thu Dec 8 02:29:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 31115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp521775wrr; Wed, 7 Dec 2022 18:31:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4a4ns7wvXe1ibmcrvGD3V09vmvRE8cKGTd9NokjgevxIdn7wxfaMRjyjJbzKTsBULOxJMF X-Received: by 2002:a17:903:251:b0:189:78d9:fe3c with SMTP id j17-20020a170903025100b0018978d9fe3cmr56220884plh.101.1670466712735; Wed, 07 Dec 2022 18:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670466712; cv=none; d=google.com; s=arc-20160816; b=U/QXyWxx6iPtUxt4fGZVMWPthPvqAHMGPthmRY2JWhjhKepwAQhNEilEBj0v5ae617 JUCFu3/hRRh11azir9NEUuiSXHuPqqRTHkO5MQUUSIgwDoqY6wIv18u6ePNwoSIuYF8/ FidOwNGnt6tSvsFs+ufPC8FRyoCg9Q6JinVmb62nv7w3VoxRvXRBCuEfiuF8BC3/lx3z THozQ1H1IGchsKKixy6z2uv5zrf4NNoFI18wHKGJ5fqRhDg5AbMkWcuK2wrjFxTFeaLN gun/jNhkT5Zm78mO2oHeXLN1NdENYdqm/adopDDgHs5hFQC/C+0KnHF04Ic7yMniJ8xj Ldiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=yNclr6rXGavYlS/MGwkTjO1oEy7mUBtPN/4bFHSlWd4=; b=lyFz98SP2A1e78At1mJAplQNnkPe4rmIrKEextBy/cF4N0w045qT96dB3uUXAtBwTu PG54fTDtKdCT5fNWGRZ0tG9IzeqJfAVWl3TDgkn0R6O3KEunVc3hKVTSY18YpKhop6ne vFcu4VymIEQrX+TkGizEejqaaXYN0KeRcGUwp/da4tBDTSRL4hj4end3VL4pJuxrj39j YIeVji0J4d1Qr8wnqBweCluOe1lOciqPnckpkLCP/MkBB8UhF0Zuy5vCwP0628h6f0as hQTY6ZA6a1Hkq5c3BiM77/gJBVAfEW1vYW996iIaki38YmjPrzWf8KySoUZrTmnSTGPS qD1Q== 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 bh4-20020a170902a98400b00189af470730si18917407plb.43.2022.12.07.18.31.39; Wed, 07 Dec 2022 18:31:52 -0800 (PST) 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 S229646AbiLHCaE (ORCPT + 99 others); Wed, 7 Dec 2022 21:30:04 -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 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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?1751611303635920522?= X-GMAIL-MSGID: =?utf-8?q?1751611303635920522?= 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 := ${shell hostname} DEFAULTS IF "${HOSTNAME}" == "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 = $3; # append beginning of value to retval $retval = "$retval$begin"; - if (defined($variable{$var})) { + if ($var =~ s/^shell\s+//) { + $retval = `$var`; + if ($?) { + doprint "WARNING: $var returned an error\n"; + } else { + chomp $retval; + } + } elsif (defined($variable{$var})) { $retval = "$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.conf 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 := ${shell hostname} +# DEFAULTS IF "${HOSTNAME}" == "frodo" +# #### Using options in other options #### #