Skip to content

Commit 2223228

Browse files
committed
Merge tag 'ktest-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest
Pull ktest updates from Steven Rostedt: - Add new -D option that allows to override variables and options For example: ./ktest.pl -DPATCH_START:=HEAD~1 -DOUTPUT_DIR=/work/build/urgent config The above sets the variable "PATCH_START" to HEAD~1 and the OUTPUT_DIR option to "/work/build/urgent". This is useful because currently the only way to make a slight change to a config file is by modifying that config file. For one time changes, this can be annoying. Having a way to do a one time override from the command line simplifies the workflow. Temp variables (PATCH_START) will override every temp variable in the config file, whereas options will act like a normal OVERRIDE option and will only affect the session they define. -DBUILD_OUTPUT=/work/git/linux.git Replaces the default BUILD_OUTPUT option. '-DBUILD_OUTPUT[2]=/work/git/linux.git' Only replaces the BUILD_OUTPUT variable for test #2. - If an option contains itself, just drop it instead of going into an infinite loop and failing to parse (it doesn't crash, it detects the recursion after 100 iterations anyway). Some configs may define a variable with the same name as the option: ADD_CONFIG := $(ADD_CONFIG) But if the option doesn't exist, it the above will fail to parse. In these cases, just ignore evaluating the option inside the definition of another option if it has the same name. - Display the BUILD_DIR and OUTPUT_DIR options at the start of every test It is useful to know which kernel source and what destination a test is using when it starts, in case a mistake is made. This makes it easier to abort the test if the wrong source or destination is being used instead of waiting until the test completes. - Add new PATCHCHECK_SKIP option When testing a series of commits that also includes changes to the Linux tools directory, it is useless to test the changes in tools as they may not affect the kernel itself. Doing tests on the kernel for changes that do not affect the kernel is a waste of time. Add a PATCHCHECK_SKIP that takes a series of shas that will be skipped while doing the individual commit tests. * tag 'ktest-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest: ktest.pl: Add new PATCHCHECK_SKIP option to skip testing individual commits ktest.pl: Always display BUILD_DIR and OUTPUT_DIR at the start of tests ktest.pl: Prevent recursion of default variable options ktest.pl: Have -D option work without a space ktest.pl: Allow command option -D to override temp variables ktest.pl: Add -D option to override options
2 parents b7dbc2e + a5e7163 commit 2223228

File tree

2 files changed

+115
-3
lines changed

2 files changed

+115
-3
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
my %repeat_tests;
2222
my %repeats;
2323
my %evals;
24+
my @command_vars;
25+
my %command_tmp_vars;
2426

2527
#default opts
2628
my %default = (
@@ -216,6 +218,7 @@
216218
my $patchcheck_start;
217219
my $patchcheck_cherry;
218220
my $patchcheck_end;
221+
my $patchcheck_skip;
219222

220223
my $build_time;
221224
my $install_time;
@@ -380,6 +383,7 @@
380383
"PATCHCHECK_START" => \$patchcheck_start,
381384
"PATCHCHECK_CHERRY" => \$patchcheck_cherry,
382385
"PATCHCHECK_END" => \$patchcheck_end,
386+
"PATCHCHECK_SKIP" => \$patchcheck_skip,
383387
);
384388

385389
# Options may be used by other options, record them.
@@ -900,14 +904,22 @@ sub set_eval {
900904
}
901905

902906
sub set_variable {
903-
my ($lvalue, $rvalue) = @_;
907+
my ($lvalue, $rvalue, $command) = @_;
904908

909+
# Command line variables override all others
910+
if (defined($command_tmp_vars{$lvalue})) {
911+
return;
912+
}
905913
if ($rvalue =~ /^\s*$/) {
906914
delete $variable{$lvalue};
907915
} else {
908916
$rvalue = process_variables($rvalue);
909917
$variable{$lvalue} = $rvalue;
910918
}
919+
920+
if (defined($command)) {
921+
$command_tmp_vars{$lvalue} = 1;
922+
}
911923
}
912924

913925
sub process_compare {
@@ -1286,6 +1298,19 @@ sub read_config {
12861298

12871299
$test_case = __read_config $config, \$test_num;
12881300

1301+
foreach my $val (@command_vars) {
1302+
chomp $val;
1303+
my %command_overrides;
1304+
if ($val =~ m/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1305+
my $lvalue = $1;
1306+
my $rvalue = $2;
1307+
1308+
set_value($lvalue, $rvalue, 1, \%command_overrides, "COMMAND LINE");
1309+
} else {
1310+
die "Invalid option definition '$val'\n";
1311+
}
1312+
}
1313+
12891314
# make sure we have all mandatory configs
12901315
get_mandatory_configs;
12911316

@@ -1371,7 +1396,10 @@ sub __eval_option {
13711396
# If a variable contains itself, use the default var
13721397
if (($var eq $name) && defined($opt{$var})) {
13731398
$o = $opt{$var};
1374-
$retval = "$retval$o";
1399+
# Only append if the default doesn't contain itself
1400+
if ($o !~ m/\$\{$var\}/) {
1401+
$retval = "$retval$o";
1402+
}
13751403
} elsif (defined($opt{$o})) {
13761404
$o = $opt{$o};
13771405
$retval = "$retval$o";
@@ -3511,11 +3539,37 @@ sub patchcheck {
35113539
@list = reverse @list;
35123540
}
35133541

3542+
my %skip_list;
3543+
my $will_skip = 0;
3544+
3545+
if (defined($patchcheck_skip)) {
3546+
foreach my $s (split /\s+/, $patchcheck_skip) {
3547+
$s = `git log --pretty=oneline $s~1..$s`;
3548+
$s =~ s/^(\S+).*/$1/;
3549+
chomp $s;
3550+
$skip_list{$s} = 1;
3551+
$will_skip++;
3552+
}
3553+
}
3554+
35143555
doprint("Going to test the following commits:\n");
35153556
foreach my $l (@list) {
3557+
my $sha1 = $l;
3558+
$sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3559+
next if (defined($skip_list{$sha1}));
35163560
doprint "$l\n";
35173561
}
35183562

3563+
if ($will_skip) {
3564+
doprint("\nSkipping the following commits:\n");
3565+
foreach my $l (@list) {
3566+
my $sha1 = $l;
3567+
$sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3568+
next if (!defined($skip_list{$sha1}));
3569+
doprint "$l\n";
3570+
}
3571+
}
3572+
35193573
my $save_clean = $noclean;
35203574
my %ignored_warnings;
35213575

@@ -3530,6 +3584,11 @@ sub patchcheck {
35303584
my $sha1 = $item;
35313585
$sha1 =~ s/^([[:xdigit:]]+).*/$1/;
35323586

3587+
if (defined($skip_list{$sha1})) {
3588+
doprint "\nSkipping \"$item\"\n\n";
3589+
next;
3590+
}
3591+
35333592
doprint "\nProcessing commit \"$item\"\n\n";
35343593

35353594
run_command "git checkout $sha1" or
@@ -4242,8 +4301,55 @@ sub cancel_test {
42424301
die "\nCaught Sig Int, test interrupted: $!\n"
42434302
}
42444303

4245-
$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
4304+
sub die_usage {
4305+
die << "EOF"
4306+
ktest.pl version: $VERSION
4307+
usage: ktest.pl [options] [config-file]
4308+
[options]:
4309+
-D value: Where value can act as an option override.
4310+
-D BUILD_NOCLEAN=1
4311+
Sets global BUILD_NOCLEAN to 1
4312+
-D TEST_TYPE[2]=build
4313+
Sets TEST_TYPE of test 2 to "build"
4314+
4315+
It can also override all temp variables.
4316+
-D USE_TEMP_DIR:=1
4317+
Will override all variables that use
4318+
"USE_TEMP_DIR="
4319+
4320+
EOF
4321+
;
4322+
}
4323+
4324+
while ( $#ARGV >= 0 ) {
4325+
if ( $ARGV[0] eq "-D" ) {
4326+
shift;
4327+
die_usage if ($#ARGV < 1);
4328+
my $val = shift;
4329+
4330+
if ($val =~ m/(.*?):=(.*)$/) {
4331+
set_variable($1, $2, 1);
4332+
} else {
4333+
$command_vars[$#command_vars + 1] = $val;
4334+
}
4335+
4336+
} elsif ( $ARGV[0] =~ m/^-D(.*)/) {
4337+
my $val = $1;
4338+
shift;
4339+
4340+
if ($val =~ m/(.*?):=(.*)$/) {
4341+
set_variable($1, $2, 1);
4342+
} else {
4343+
$command_vars[$#command_vars + 1] = $val;
4344+
}
4345+
} elsif ( $ARGV[0] eq "-h" ) {
4346+
die_usage;
4347+
} else {
4348+
last;
4349+
}
4350+
}
42464351

4352+
$#ARGV < 1 or die_usage;
42474353
if ($#ARGV == 0) {
42484354
$ktest_config = $ARGV[0];
42494355
if (! -f $ktest_config) {
@@ -4466,6 +4572,10 @@ sub cancel_test {
44664572

44674573
doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
44684574

4575+
# Always show which build directory and output directory is being used
4576+
doprint "BUILD_DIR=$builddir\n";
4577+
doprint "OUTPUT_DIR=$outputdir\n\n";
4578+
44694579
if (defined($pre_test)) {
44704580
my $ret = run_command $pre_test;
44714581
if (!$ret && defined($pre_test_die) &&

tools/testing/ktest/sample.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,8 @@
10171017
# Note, PATCHCHECK_CHERRY requires PATCHCHECK_END to be defined.
10181018
# (default 0)
10191019
#
1020+
# PATCHCHECK_SKIP is an optional list of shas to skip testing
1021+
#
10201022
# PATCHCHECK_TYPE is required and is the type of test to run:
10211023
# build, boot, test.
10221024
#

0 commit comments

Comments
 (0)