Skip to contentSkip to conversation

ktest.pl: Updates for 6.17

PATCH New Steven Rostedt 1 participant 5 messages Jun 17, 2025 Ktest

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover ktest.pl: Updates for 6.17

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(-)
author maintainer
#1 lore raw

PATCH 1/4 ktest.pl: Add -D option to override variables

From: Steven Rostedt <[email protected]>

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.

---
 tools/testing/ktest/ktest.pl | 45 +++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
tools/testing/ktest/ktest.pl +44 -1
index a5f7fdd0c1fb..8fcc09893986 100755
@@ -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) {
Signature · 1 line
2.47.2
author maintainer
#2 lore raw

PATCH 2/4 ktest.pl: Allow command option -D to override temp variables

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

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

---
 tools/testing/ktest/ktest.pl | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
tools/testing/ktest/ktest.pl +20 -2
index 8fcc09893986..c441934f1def 100755
@@ -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;
Signature · 1 line
2.47.2
author maintainer
#3 lore raw

PATCH 3/4 ktest.pl: Have -D option work without a space

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

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

---
 tools/testing/ktest/ktest.pl | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/testing/ktest/ktest.pl +9 -0
index c441934f1def..075c386af5e5 100755
@@ -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 {
Signature · 1 line
2.47.2
author maintainer
#4 lore raw

PATCH 4/4 ktest.pl: Prevent recursion of default variable options

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

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.

---
 tools/testing/ktest/ktest.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/ktest/ktest.pl +4 -1
index 075c386af5e5..b2971430d7e4 100755
@@ -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";
Signature · 1 line
2.47.2