mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] ktest.pl: Updates for 6.17
@ 2025-06-17 15:43 Steven Rostedt
  2025-06-17 15:43 ` [PATCH 1/4] ktest.pl: Add -D option to override variables Steven Rostedt
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-06-17 15:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Warthog9 Hawley, dhaval


ktest.pl updates:

- Add a "-D" flag to allow overriding the content in the config file.

  Instead of having to tweak a config file for minor changes to run
  a ktest.pl execution, allow for config options to be overridden by
  the command line:

  ktest.pl -D ADD_CONFIG=/tmp/temp_config machine.conf

  The above will make ADD_CONFIG default to /tmp/temp_config

  To have it work for a specific test, add "[<test #>]" to the option:

  ktest.pl '-DBUILD_TYPE[2]=allyesconfig' machine.conf

  The above will change the BUILD_TYPE to "allyesconfig" for test 2.

  This works for temp variables as well (using ":=" instead of "=")

  ktest.pl -D 'ARCH:=arm' machine.conf

  The first "ARCH" variable will be overwritten as "arm". Note if
  there are more than one "ARCH" variables, it will not override the
  later ones.

- Check for recursion in processing default variables

  If a default variable has itself, then do not continue with it.

  ADD_CONFIG = temp_config ${ADD_CONFIG}

  Expects there to be a: ADD_CONFIG := other_config

  But if that temp variable "ADD_CONFIG" does not exist, it will use itself.
  Do not allow that.

Steven Rostedt (4):
      ktest.pl: Add -D option to override variables
      ktest.pl: Allow command option -D to override temp variables
      ktest.pl: Have -D option work without a space
      ktest.pl: Prevent recursion of default variable options

----
 tools/testing/ktest/ktest.pl | 79 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 3 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] ktest.pl: Add -D option to override variables
  2025-06-17 15:43 [PATCH 0/4] ktest.pl: Updates for 6.17 Steven Rostedt
@ 2025-06-17 15:43 ` Steven Rostedt
  2025-06-17 15:43 ` [PATCH 2/4] ktest.pl: Allow command option -D to override temp variables Steven Rostedt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-06-17 15:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Warthog9 Hawley, dhaval

From: Steven Rostedt <rostedt@goodmis.org>

Add -D option that lets the user override variables in the config.

For instance, if the config has: BUILD_NOCLEAN=1 which prevents mrproper
from being called before builds, and the user wants to call it once. The
user can run:

  ktest -D BUILD_NOCLEAN=0 config

And the default "BUILD_NOCLEAN" variable will be disabled.

If the user wants to change the second test to do a build and not boot,
the user can run:

  ktest -D 'TEST_TYPE[2]=build' config

Where the '[#]' is for the test to assign the variable for.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/testing/ktest/ktest.pl | 45 +++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index a5f7fdd0c1fb..8fcc09893986 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -21,6 +21,7 @@ my %opt;
 my %repeat_tests;
 my %repeats;
 my %evals;
+my @command_vars;
 
 #default opts
 my %default = (
@@ -1286,6 +1287,19 @@ sub read_config {
 
     $test_case = __read_config $config, \$test_num;
 
+    foreach my $val (@command_vars) {
+	chomp $val;
+	my %command_overrides;
+	if ($val =~ m/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
+	    my $lvalue = $1;
+	    my $rvalue = $2;
+
+	    set_value($lvalue, $rvalue, 1, \%command_overrides, "COMMAND LINE");
+	} else {
+	    die "Invalid variable definition '$val'\n";
+	}
+    }
+
     # make sure we have all mandatory configs
     get_mandatory_configs;
 
@@ -4242,8 +4256,37 @@ sub cancel_test {
     die "\nCaught Sig Int, test interrupted: $!\n"
 }
 
-$#ARGV < 1 or die "ktest.pl version: $VERSION\n   usage: ktest.pl [config-file]\n";
+sub die_usage {
+    die << "EOF"
+ktest.pl version: $VERSION
+   usage: ktest.pl [options] [config-file]
+    [options]:
+       -D value: Where value can act as an override.
+                -D BUILD_NOCLEAN=1
+                    Sets global BUILD_NOCLEAN to 1
+                -D TEST_TYPE[2]=build
+                    Sets TEST_TYPE of test 2 to "build"
+
+EOF
+;
+}
+
+while ( $#ARGV >= 0 ) {
+    if ( $ARGV[0] eq "-D" ) {
+	shift;
+	die_usage if ($#ARGV < 1);
+	my $val = shift;
+
+	$command_vars[$#command_vars + 1] = $val;
+
+    } elsif ( $ARGV[0] eq "-h" ) {
+	die_usage;
+    } else {
+	last;
+    }
+}
 
+$#ARGV < 1 or die_usage;
 if ($#ARGV == 0) {
     $ktest_config = $ARGV[0];
     if (! -f $ktest_config) {
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] ktest.pl: Allow command option -D to override temp variables
  2025-06-17 15:43 [PATCH 0/4] ktest.pl: Updates for 6.17 Steven Rostedt
  2025-06-17 15:43 ` [PATCH 1/4] ktest.pl: Add -D option to override variables Steven Rostedt
@ 2025-06-17 15:43 ` Steven Rostedt
  2025-06-17 15:43 ` [PATCH 3/4] ktest.pl: Have -D option work without a space Steven Rostedt
  2025-06-17 15:43 ` [PATCH 4/4] ktest.pl: Prevent recursion of default variable options Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-06-17 15:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Warthog9 Hawley, dhaval

From: Steven Rostedt <rostedt@goodmis.org>

Currently -D only updates the persistent variables that are defined with
"=". Allow it to also override all temp variables that are defined with
":=".

 ktest.pl -D 'USE_TEMP_DIR:=1' -D 'TEST_TYPE[2]=build' config

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/testing/ktest/ktest.pl | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8fcc09893986..c441934f1def 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -22,6 +22,7 @@ my %repeat_tests;
 my %repeats;
 my %evals;
 my @command_vars;
+my %command_tmp_vars;
 
 #default opts
 my %default = (
@@ -901,14 +902,22 @@ sub set_eval {
 }
 
 sub set_variable {
-    my ($lvalue, $rvalue) = @_;
+    my ($lvalue, $rvalue, $command) = @_;
 
+    # Command line variables override all others
+    if (defined($command_tmp_vars{$lvalue})) {
+	return;
+    }
     if ($rvalue =~ /^\s*$/) {
 	delete $variable{$lvalue};
     } else {
 	$rvalue = process_variables($rvalue);
 	$variable{$lvalue} = $rvalue;
     }
+
+    if (defined($command)) {
+	$command_tmp_vars{$lvalue} = 1;
+    }
 }
 
 sub process_compare {
@@ -4267,6 +4276,11 @@ ktest.pl version: $VERSION
                 -D TEST_TYPE[2]=build
                     Sets TEST_TYPE of test 2 to "build"
 
+	        It can also override all temp variables.
+                 -D USE_TEMP_DIR:=1
+                    Will override all variables that use
+                    "USE_TEMP_DIR="
+
 EOF
 ;
 }
@@ -4277,7 +4291,11 @@ while ( $#ARGV >= 0 ) {
 	die_usage if ($#ARGV < 1);
 	my $val = shift;
 
-	$command_vars[$#command_vars + 1] = $val;
+	if ($val =~ m/(.*?):=(.*)$/) {
+	    set_variable($1, $2, 1);
+	} else {
+	    $command_vars[$#command_vars + 1] = $val;
+	}
 
     } elsif ( $ARGV[0] eq "-h" ) {
 	die_usage;
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] ktest.pl: Have -D option work without a space
  2025-06-17 15:43 [PATCH 0/4] ktest.pl: Updates for 6.17 Steven Rostedt
  2025-06-17 15:43 ` [PATCH 1/4] ktest.pl: Add -D option to override variables Steven Rostedt
  2025-06-17 15:43 ` [PATCH 2/4] ktest.pl: Allow command option -D to override temp variables Steven Rostedt
@ 2025-06-17 15:43 ` Steven Rostedt
  2025-06-17 15:43 ` [PATCH 4/4] ktest.pl: Prevent recursion of default variable options Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-06-17 15:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Warthog9 Hawley, dhaval

From: Steven Rostedt <rostedt@goodmis.org>

Allow -DBUILD_TYPE=boot work the same as -D BUILD_TYPE=boot just like
normal single character option does in most applications.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/testing/ktest/ktest.pl | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index c441934f1def..075c386af5e5 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -4297,6 +4297,15 @@ while ( $#ARGV >= 0 ) {
 	    $command_vars[$#command_vars + 1] = $val;
 	}
 
+    } elsif ( $ARGV[0] =~ m/^-D(.*)/) {
+	my $val = $1;
+	shift;
+
+	if ($val =~ m/(.*?):=(.*)$/) {
+	    set_variable($1, $2, 1);
+	} else {
+	    $command_vars[$#command_vars + 1] = $val;
+	}
     } elsif ( $ARGV[0] eq "-h" ) {
 	die_usage;
     } else {
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] ktest.pl: Prevent recursion of default variable options
  2025-06-17 15:43 [PATCH 0/4] ktest.pl: Updates for 6.17 Steven Rostedt
                   ` (2 preceding siblings ...)
  2025-06-17 15:43 ` [PATCH 3/4] ktest.pl: Have -D option work without a space Steven Rostedt
@ 2025-06-17 15:43 ` Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-06-17 15:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Warthog9 Hawley, dhaval

From: Steven Rostedt <rostedt@goodmis.org>

If a default variable contains itself, do not recurse on it.

For example:

  ADD_CONFIG := ${CONFIG_DIR}/temp_config
  DEFAULTS
  ADD_CONFIG = ${CONFIG_DIR}/default_config ${ADD_CONFIG}

The above works because the temp variable ADD_CONFIG (is a temp because it
is created with ":=") is already defined, it will be substituted in the
variable option. But if it gets commented out:

  # ADD_CONFIG := ${CONFIG_DIR}/temp_config
  DEFAULTS
  ADD_CONFIG = ${CONFIG_DIR}/default_config ${ADD_CONFIG}

Then the above will go into a recursive loop where ${ADD_CONFIG} will
get replaced with the current definition of ADD_CONFIG which contains the
${ADD_CONFIG} and that will also try to get converted. ktest.pl will error
after 100 attempts of recursion and fail.

When replacing a variable with the default variable, if the default
variable contains itself, do not replace it.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/testing/ktest/ktest.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 075c386af5e5..b2971430d7e4 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -1394,7 +1394,10 @@ sub __eval_option {
 	# If a variable contains itself, use the default var
 	if (($var eq $name) && defined($opt{$var})) {
 	    $o = $opt{$var};
-	    $retval = "$retval$o";
+	    # Only append if the default doesn't contain itself
+	    if ($o !~ m/\$\{$var\}/) {
+		$retval = "$retval$o";
+	    }
 	} elsif (defined($opt{$o})) {
 	    $o = $opt{$o};
 	    $retval = "$retval$o";
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-17 15:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-17 15:43 [PATCH 0/4] ktest.pl: Updates for 6.17 Steven Rostedt
2025-06-17 15:43 ` [PATCH 1/4] ktest.pl: Add -D option to override variables Steven Rostedt
2025-06-17 15:43 ` [PATCH 2/4] ktest.pl: Allow command option -D to override temp variables Steven Rostedt
2025-06-17 15:43 ` [PATCH 3/4] ktest.pl: Have -D option work without a space Steven Rostedt
2025-06-17 15:43 ` [PATCH 4/4] ktest.pl: Prevent recursion of default variable options Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®