Skip to content

Commit c75d22d

Browse files
committed
ktest: Add eval '=~' command to modify variables in config file
With the added variable ${KERNEL_VERSION}, it is useful to be able to use parts of it for other variables. For example, if you want to create a warnings file for each major kernel version to test sub versions against you can create your warnings file with like this: WARNINGS_FILE = warnings-file-${KERNEL_VERSION} But this may add 3.8.12 or something, and we want all 3.8.* to use the same file, and 3.10.* to use another file, and so on. With the eval command we can, by adding: WARNINGS_FILE =~ s/(-file-\d+\.\d+).*/$1/ Which will chop off the extra characters after the 3.8. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 8e80bf0 commit c75d22d

1 file changed

Lines changed: 81 additions & 21 deletions

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
my %opt;
1919
my %repeat_tests;
2020
my %repeats;
21+
my %evals;
2122

2223
#default opts
2324
my %default = (
@@ -448,6 +449,27 @@
448449
EOF
449450
;
450451

452+
sub _logit {
453+
if (defined($opt{"LOG_FILE"})) {
454+
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
455+
print OUT @_;
456+
close(OUT);
457+
}
458+
}
459+
460+
sub logit {
461+
if (defined($opt{"LOG_FILE"})) {
462+
_logit @_;
463+
} else {
464+
print @_;
465+
}
466+
}
467+
468+
sub doprint {
469+
print @_;
470+
_logit @_;
471+
}
472+
451473
sub read_prompt {
452474
my ($cancel, $prompt) = @_;
453475

@@ -665,6 +687,22 @@ sub set_value {
665687
}
666688
}
667689

690+
sub set_eval {
691+
my ($lvalue, $rvalue, $name) = @_;
692+
693+
my $prvalue = process_variables($rvalue);
694+
my $arr;
695+
696+
if (defined($evals{$lvalue})) {
697+
$arr = $evals{$lvalue};
698+
} else {
699+
$arr = [];
700+
$evals{$lvalue} = $arr;
701+
}
702+
703+
push @{$arr}, $rvalue;
704+
}
705+
668706
sub set_variable {
669707
my ($lvalue, $rvalue) = @_;
670708

@@ -950,6 +988,20 @@ sub __read_config {
950988
$test_case = 1;
951989
}
952990

991+
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
992+
993+
next if ($skip);
994+
995+
my $lvalue = $1;
996+
my $rvalue = $2;
997+
998+
if ($default || $lvalue =~ /\[\d+\]$/) {
999+
set_eval($lvalue, $rvalue, $name);
1000+
} else {
1001+
my $val = "$lvalue\[$test_num\]";
1002+
set_eval($val, $rvalue, $name);
1003+
}
1004+
9531005
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
9541006

9551007
next if ($skip);
@@ -1147,6 +1199,33 @@ sub __eval_option {
11471199
return $retval;
11481200
}
11491201

1202+
sub process_evals {
1203+
my ($name, $option, $i) = @_;
1204+
1205+
my $option_name = "$name\[$i\]";
1206+
my $ev;
1207+
1208+
my $old_option = $option;
1209+
1210+
if (defined($evals{$option_name})) {
1211+
$ev = $evals{$option_name};
1212+
} elsif (defined($evals{$name})) {
1213+
$ev = $evals{$name};
1214+
} else {
1215+
return $option;
1216+
}
1217+
1218+
for my $e (@{$ev}) {
1219+
eval "\$option =~ $e";
1220+
}
1221+
1222+
if ($option ne $old_option) {
1223+
doprint("$name changed from '$old_option' to '$option'\n");
1224+
}
1225+
1226+
return $option;
1227+
}
1228+
11501229
sub eval_option {
11511230
my ($name, $option, $i) = @_;
11521231

@@ -1167,28 +1246,9 @@ sub eval_option {
11671246
$option = __eval_option($name, $option, $i);
11681247
}
11691248

1170-
return $option;
1171-
}
1172-
1173-
sub _logit {
1174-
if (defined($opt{"LOG_FILE"})) {
1175-
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1176-
print OUT @_;
1177-
close(OUT);
1178-
}
1179-
}
1180-
1181-
sub logit {
1182-
if (defined($opt{"LOG_FILE"})) {
1183-
_logit @_;
1184-
} else {
1185-
print @_;
1186-
}
1187-
}
1249+
$option = process_evals($name, $option, $i);
11881250

1189-
sub doprint {
1190-
print @_;
1191-
_logit @_;
1251+
return $option;
11921252
}
11931253

11941254
sub run_command;

0 commit comments

Comments
 (0)