diff options
| author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2013-12-11 21:16:59 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2013-12-11 21:16:59 -0500 |
| commit | c75d22d9c675c4c77d87ff36de6e5023f14724ef (patch) | |
| tree | 24b0ac7a13f09f406d22691454e7223b86f5d96c /tools/testing | |
| parent | 8e80bf05ff7e7bda6f1683b1201ada56c4efa4c1 (diff) | |
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>
Diffstat (limited to 'tools/testing')
| -rwxr-xr-x | tools/testing/ktest/ktest.pl | 102 |
1 files changed, 81 insertions, 21 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index b285933873c7..82006c2d88c9 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
| @@ -18,6 +18,7 @@ $| = 1; | |||
| 18 | my %opt; | 18 | my %opt; |
| 19 | my %repeat_tests; | 19 | my %repeat_tests; |
| 20 | my %repeats; | 20 | my %repeats; |
| 21 | my %evals; | ||
| 21 | 22 | ||
| 22 | #default opts | 23 | #default opts |
| 23 | my %default = ( | 24 | my %default = ( |
| @@ -448,6 +449,27 @@ $config_help{"REBOOT_SCRIPT"} = << "EOF" | |||
| 448 | EOF | 449 | EOF |
| 449 | ; | 450 | ; |
| 450 | 451 | ||
| 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 | |||
| 451 | sub read_prompt { | 473 | sub read_prompt { |
| 452 | my ($cancel, $prompt) = @_; | 474 | my ($cancel, $prompt) = @_; |
| 453 | 475 | ||
| @@ -665,6 +687,22 @@ sub set_value { | |||
| 665 | } | 687 | } |
| 666 | } | 688 | } |
| 667 | 689 | ||
| 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 | |||
| 668 | sub set_variable { | 706 | sub set_variable { |
| 669 | my ($lvalue, $rvalue) = @_; | 707 | my ($lvalue, $rvalue) = @_; |
| 670 | 708 | ||
| @@ -950,6 +988,20 @@ sub __read_config { | |||
| 950 | $test_case = 1; | 988 | $test_case = 1; |
| 951 | } | 989 | } |
| 952 | 990 | ||
| 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 | |||
| 953 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { | 1005 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { |
| 954 | 1006 | ||
| 955 | next if ($skip); | 1007 | next if ($skip); |
| @@ -1147,6 +1199,33 @@ sub __eval_option { | |||
| 1147 | return $retval; | 1199 | return $retval; |
| 1148 | } | 1200 | } |
| 1149 | 1201 | ||
| 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 | |||
| 1150 | sub eval_option { | 1229 | sub eval_option { |
| 1151 | my ($name, $option, $i) = @_; | 1230 | my ($name, $option, $i) = @_; |
| 1152 | 1231 | ||
| @@ -1167,28 +1246,9 @@ sub eval_option { | |||
| 1167 | $option = __eval_option($name, $option, $i); | 1246 | $option = __eval_option($name, $option, $i); |
| 1168 | } | 1247 | } |
| 1169 | 1248 | ||
| 1170 | return $option; | 1249 | $option = process_evals($name, $option, $i); |
| 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 | } | ||
| 1188 | 1250 | ||
| 1189 | sub doprint { | 1251 | return $option; |
| 1190 | print @_; | ||
| 1191 | _logit @_; | ||
| 1192 | } | 1252 | } |
| 1193 | 1253 | ||
| 1194 | sub run_command; | 1254 | sub run_command; |
