Skip to content

Commit

Permalink
ktest.pl: Add shell commands to variables
Browse files Browse the repository at this point in the history
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"

Link: https://lkml.kernel.org/r/20221207212944.277ee850@gandalf.local.home

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
rostedt committed Dec 9, 2022
1 parent 26df05a commit 88a51b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tools/testing/ktest/ktest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tools/testing/ktest/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command>}
# expression. Note, this is case sensitive, thus ${SHELL <command>}
# will not work.
#
# HOSTNAME := ${shell hostname}
# DEFAULTS IF "${HOSTNAME}" == "frodo"
#

#### Using options in other options ####
#
Expand Down

0 comments on commit 88a51b4

Please sign in to comment.