Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ktest: Allow a test option to use its default option

Options are allowed to use other options, for example:

LOG_FILE = ${OUTPUT_DIR}/${MACHINE}.log

where the option LOG_FILE used the options OUTPUT_DIR and MACHINE.

But if a test option were to use a default option, it will not get
substituted:

OUTPUT_DIR = ${THIS_DIR}/${MACHINE}

TEST_START
OUTPUT_DIR = ${OUTPUT_DIR}/t1

For the above test, OUTPUT_DIR will stay literally "${OUTPUT_DIR}/t1"
and not be converted to "${THIS_DIR}/${MACHINE}/t1". When the test runs,
it will pass the ${OUTPUT_DIR} to the shell, which would probaly
interpret it as "", and the output directory will end up as "/t1".

Change the code where if a test option has its own option name in
its defined field, and a default option exists, then substitute the
default option in its place.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

+10 -6
+10 -6
tools/testing/ktest/ktest.pl
··· 1074 1074 } 1075 1075 1076 1076 sub __eval_option { 1077 - my ($option, $i) = @_; 1077 + my ($name, $option, $i) = @_; 1078 1078 1079 1079 # Add space to evaluate the character before $ 1080 1080 $option = " $option"; ··· 1106 1106 my $o = "$var\[$i\]"; 1107 1107 my $parento = "$var\[$parent\]"; 1108 1108 1109 - if (defined($opt{$o})) { 1109 + # If a variable contains itself, use the default var 1110 + if (($var eq $name) && defined($opt{$var})) { 1111 + $o = $opt{$var}; 1112 + $retval = "$retval$o"; 1113 + } elsif (defined($opt{$o})) { 1110 1114 $o = $opt{$o}; 1111 1115 $retval = "$retval$o"; 1112 1116 } elsif ($repeated && defined($opt{$parento})) { ··· 1134 1130 } 1135 1131 1136 1132 sub eval_option { 1137 - my ($option, $i) = @_; 1133 + my ($name, $option, $i) = @_; 1138 1134 1139 1135 my $prev = ""; 1140 1136 ··· 1150 1146 "Check for recursive variables\n"; 1151 1147 } 1152 1148 $prev = $option; 1153 - $option = __eval_option($option, $i); 1149 + $option = __eval_option($name, $option, $i); 1154 1150 } 1155 1151 1156 1152 return $option; ··· 3687 3683 read_config $ktest_config; 3688 3684 3689 3685 if (defined($opt{"LOG_FILE"})) { 3690 - $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1); 3686 + $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1); 3691 3687 } 3692 3688 3693 3689 # Append any configs entered in manually to the config file. ··· 3764 3760 my $option = __set_test_option($name, $i); 3765 3761 return $option if (!defined($option)); 3766 3762 3767 - return eval_option($option, $i); 3763 + return eval_option($name, $option, $i); 3768 3764 } 3769 3765 3770 3766 # First we need to do is the builds