Commit c75d22d9 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt

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: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 8e80bf05
...@@ -18,6 +18,7 @@ $| = 1; ...@@ -18,6 +18,7 @@ $| = 1;
my %opt; my %opt;
my %repeat_tests; my %repeat_tests;
my %repeats; my %repeats;
my %evals;
#default opts #default opts
my %default = ( my %default = (
...@@ -448,6 +449,27 @@ $config_help{"REBOOT_SCRIPT"} = << "EOF" ...@@ -448,6 +449,27 @@ $config_help{"REBOOT_SCRIPT"} = << "EOF"
EOF EOF
; ;
sub _logit {
if (defined($opt{"LOG_FILE"})) {
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
print OUT @_;
close(OUT);
}
}
sub logit {
if (defined($opt{"LOG_FILE"})) {
_logit @_;
} else {
print @_;
}
}
sub doprint {
print @_;
_logit @_;
}
sub read_prompt { sub read_prompt {
my ($cancel, $prompt) = @_; my ($cancel, $prompt) = @_;
...@@ -665,6 +687,22 @@ sub set_value { ...@@ -665,6 +687,22 @@ sub set_value {
} }
} }
sub set_eval {
my ($lvalue, $rvalue, $name) = @_;
my $prvalue = process_variables($rvalue);
my $arr;
if (defined($evals{$lvalue})) {
$arr = $evals{$lvalue};
} else {
$arr = [];
$evals{$lvalue} = $arr;
}
push @{$arr}, $rvalue;
}
sub set_variable { sub set_variable {
my ($lvalue, $rvalue) = @_; my ($lvalue, $rvalue) = @_;
...@@ -950,6 +988,20 @@ sub __read_config { ...@@ -950,6 +988,20 @@ sub __read_config {
$test_case = 1; $test_case = 1;
} }
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
next if ($skip);
my $lvalue = $1;
my $rvalue = $2;
if ($default || $lvalue =~ /\[\d+\]$/) {
set_eval($lvalue, $rvalue, $name);
} else {
my $val = "$lvalue\[$test_num\]";
set_eval($val, $rvalue, $name);
}
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
next if ($skip); next if ($skip);
...@@ -1147,6 +1199,33 @@ sub __eval_option { ...@@ -1147,6 +1199,33 @@ sub __eval_option {
return $retval; return $retval;
} }
sub process_evals {
my ($name, $option, $i) = @_;
my $option_name = "$name\[$i\]";
my $ev;
my $old_option = $option;
if (defined($evals{$option_name})) {
$ev = $evals{$option_name};
} elsif (defined($evals{$name})) {
$ev = $evals{$name};
} else {
return $option;
}
for my $e (@{$ev}) {
eval "\$option =~ $e";
}
if ($option ne $old_option) {
doprint("$name changed from '$old_option' to '$option'\n");
}
return $option;
}
sub eval_option { sub eval_option {
my ($name, $option, $i) = @_; my ($name, $option, $i) = @_;
...@@ -1167,28 +1246,9 @@ sub eval_option { ...@@ -1167,28 +1246,9 @@ sub eval_option {
$option = __eval_option($name, $option, $i); $option = __eval_option($name, $option, $i);
} }
return $option; $option = process_evals($name, $option, $i);
}
sub _logit {
if (defined($opt{"LOG_FILE"})) {
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
print OUT @_;
close(OUT);
}
}
sub logit {
if (defined($opt{"LOG_FILE"})) {
_logit @_;
} else {
print @_;
}
}
sub doprint { return $option;
print @_;
_logit @_;
} }
sub run_command; sub run_command;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment