Skip to content

Commit 2e77def

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-ktest
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-ktest: ktest: Allow options to be used by other options ktest: Create variables for the ktest config files ktest: Reboot after each patchcheck run ktest: Reboot to good kernel after every bisect run ktest: If test failed due to timeout, print that ktest: Fix post install command
2 parents caebc16 + 2a62512 commit 2e77def

2 files changed

Lines changed: 242 additions & 7 deletions

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 149 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
$default{"POWEROFF_ON_SUCCESS"} = 0;
3737
$default{"BUILD_OPTIONS"} = "";
3838
$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39+
$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
3940
$default{"CLEAR_LOG"} = 0;
4041
$default{"BISECT_MANUAL"} = 0;
4142
$default{"BISECT_SKIP"} = 1;
@@ -96,6 +97,7 @@
9697
my $monitor_cnt = 0;
9798
my $sleep_time;
9899
my $bisect_sleep_time;
100+
my $patchcheck_sleep_time;
99101
my $store_failures;
100102
my $timeout;
101103
my $booted_timeout;
@@ -112,6 +114,7 @@
112114

113115
my %entered_configs;
114116
my %config_help;
117+
my %variable;
115118

116119
$config_help{"MACHINE"} = << "EOF"
117120
The machine hostname that you will test.
@@ -260,6 +263,39 @@ sub get_ktest_configs {
260263
}
261264
}
262265

266+
sub process_variables {
267+
my ($value) = @_;
268+
my $retval = "";
269+
270+
# We want to check for '\', and it is just easier
271+
# to check the previous characet of '$' and not need
272+
# to worry if '$' is the first character. By adding
273+
# a space to $value, we can just check [^\\]\$ and
274+
# it will still work.
275+
$value = " $value";
276+
277+
while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
278+
my $begin = $1;
279+
my $var = $2;
280+
my $end = $3;
281+
# append beginning of value to retval
282+
$retval = "$retval$begin";
283+
if (defined($variable{$var})) {
284+
$retval = "$retval$variable{$var}";
285+
} else {
286+
# put back the origin piece.
287+
$retval = "$retval\$\{$var\}";
288+
}
289+
$value = $end;
290+
}
291+
$retval = "$retval$value";
292+
293+
# remove the space added in the beginning
294+
$retval =~ s/ //;
295+
296+
return "$retval"
297+
}
298+
263299
sub set_value {
264300
my ($lvalue, $rvalue) = @_;
265301

@@ -269,10 +305,22 @@ sub set_value {
269305
if ($rvalue =~ /^\s*$/) {
270306
delete $opt{$lvalue};
271307
} else {
308+
$rvalue = process_variables($rvalue);
272309
$opt{$lvalue} = $rvalue;
273310
}
274311
}
275312

313+
sub set_variable {
314+
my ($lvalue, $rvalue) = @_;
315+
316+
if ($rvalue =~ /^\s*$/) {
317+
delete $variable{$lvalue};
318+
} else {
319+
$rvalue = process_variables($rvalue);
320+
$variable{$lvalue} = $rvalue;
321+
}
322+
}
323+
276324
sub read_config {
277325
my ($config) = @_;
278326

@@ -385,6 +433,22 @@ sub read_config {
385433
$repeats{$val} = $repeat;
386434
}
387435
}
436+
} elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
437+
next if ($skip);
438+
439+
my $lvalue = $1;
440+
my $rvalue = $2;
441+
442+
# process config variables.
443+
# Config variables are only active while reading the
444+
# config and can be defined anywhere. They also ignore
445+
# TEST_START and DEFAULTS, but are skipped if they are in
446+
# on of these sections that have SKIP defined.
447+
# The save variable can be
448+
# defined multiple times and the new one simply overrides
449+
# the prevous one.
450+
set_variable($lvalue, $rvalue);
451+
388452
} else {
389453
die "$name: $.: Garbage found in config\n$_";
390454
}
@@ -838,6 +902,7 @@ sub monitor {
838902

839903
if ($stop_test_after > 0 && !$booted && !$bug) {
840904
if (time - $monitor_start > $stop_test_after) {
905+
doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
841906
$done = 1;
842907
}
843908
}
@@ -907,7 +972,7 @@ sub install {
907972
return if (!defined($post_install));
908973

909974
my $cp_post_install = $post_install;
910-
$cp_post_install = s/\$KERNEL_VERSION/$version/g;
975+
$cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
911976
run_command "$cp_post_install" or
912977
dodie "Failed to run post install";
913978
}
@@ -1247,14 +1312,14 @@ sub run_bisect_test {
12471312

12481313
if ($failed) {
12491314
$result = 0;
1250-
1251-
# reboot the box to a good kernel
1252-
if ($type ne "build") {
1253-
bisect_reboot;
1254-
}
12551315
} else {
12561316
$result = 1;
12571317
}
1318+
1319+
# reboot the box to a kernel we can ssh to
1320+
if ($type ne "build") {
1321+
bisect_reboot;
1322+
}
12581323
$in_bisect = 0;
12591324

12601325
return $result;
@@ -1763,6 +1828,14 @@ sub config_bisect {
17631828
success $i;
17641829
}
17651830

1831+
sub patchcheck_reboot {
1832+
doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
1833+
reboot;
1834+
start_monitor;
1835+
wait_for_monitor $patchcheck_sleep_time;
1836+
end_monitor;
1837+
}
1838+
17661839
sub patchcheck {
17671840
my ($i) = @_;
17681841

@@ -1854,6 +1927,8 @@ sub patchcheck {
18541927
end_monitor;
18551928
return 0 if ($failed);
18561929

1930+
patchcheck_reboot;
1931+
18571932
}
18581933
$in_patchcheck = 0;
18591934
success $i;
@@ -1944,7 +2019,7 @@ sub patchcheck {
19442019
}
19452020
}
19462021

1947-
sub set_test_option {
2022+
sub __set_test_option {
19482023
my ($name, $i) = @_;
19492024

19502025
my $option = "$name\[$i\]";
@@ -1970,6 +2045,72 @@ sub set_test_option {
19702045
return undef;
19712046
}
19722047

2048+
sub eval_option {
2049+
my ($option, $i) = @_;
2050+
2051+
# Add space to evaluate the character before $
2052+
$option = " $option";
2053+
my $retval = "";
2054+
2055+
while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
2056+
my $start = $1;
2057+
my $var = $2;
2058+
my $end = $3;
2059+
2060+
# Append beginning of line
2061+
$retval = "$retval$start";
2062+
2063+
# If the iteration option OPT[$i] exists, then use that.
2064+
# otherwise see if the default OPT (without [$i]) exists.
2065+
2066+
my $o = "$var\[$i\]";
2067+
2068+
if (defined($opt{$o})) {
2069+
$o = $opt{$o};
2070+
$retval = "$retval$o";
2071+
} elsif (defined($opt{$var})) {
2072+
$o = $opt{$var};
2073+
$retval = "$retval$o";
2074+
} else {
2075+
$retval = "$retval\$\{$var\}";
2076+
}
2077+
2078+
$option = $end;
2079+
}
2080+
2081+
$retval = "$retval$option";
2082+
2083+
$retval =~ s/^ //;
2084+
2085+
return $retval;
2086+
}
2087+
2088+
sub set_test_option {
2089+
my ($name, $i) = @_;
2090+
2091+
my $option = __set_test_option($name, $i);
2092+
return $option if (!defined($option));
2093+
2094+
my $prev = "";
2095+
2096+
# Since an option can evaluate to another option,
2097+
# keep iterating until we do not evaluate any more
2098+
# options.
2099+
my $r = 0;
2100+
while ($prev ne $option) {
2101+
# Check for recursive evaluations.
2102+
# 100 deep should be more than enough.
2103+
if ($r++ > 100) {
2104+
die "Over 100 evaluations accurred with $name\n" .
2105+
"Check for recursive variables\n";
2106+
}
2107+
$prev = $option;
2108+
$option = eval_option($option, $i);
2109+
}
2110+
2111+
return $option;
2112+
}
2113+
19732114
# First we need to do is the builds
19742115
for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
19752116

@@ -2003,6 +2144,7 @@ sub set_test_option {
20032144
$poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
20042145
$sleep_time = set_test_option("SLEEP_TIME", $i);
20052146
$bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
2147+
$patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
20062148
$bisect_manual = set_test_option("BISECT_MANUAL", $i);
20072149
$bisect_skip = set_test_option("BISECT_SKIP", $i);
20082150
$store_failures = set_test_option("STORE_FAILURES", $i);

‎tools/testing/ktest/sample.conf‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,95 @@
7373
# ktest will fail to execute, and no tests will run.
7474
#
7575

76+
#### Config variables ####
77+
#
78+
# This config file can also contain "config variables".
79+
# These are assigned with ":=" instead of the ktest option
80+
# assigment "=".
81+
#
82+
# The difference between ktest options and config variables
83+
# is that config variables can be used multiple times,
84+
# where each instance will override the previous instance.
85+
# And that they only live at time of processing this config.
86+
#
87+
# The advantage to config variables are that they can be used
88+
# by any option or any other config variables to define thing
89+
# that you may use over and over again in the options.
90+
#
91+
# For example:
92+
#
93+
# USER := root
94+
# TARGET := mybox
95+
# TEST_CASE := ssh ${USER}@${TARGET} /path/to/my/test
96+
#
97+
# TEST_START
98+
# MIN_CONFIG = config1
99+
# TEST = ${TEST_CASE}
100+
#
101+
# TEST_START
102+
# MIN_CONFIG = config2
103+
# TEST = ${TEST_CASE}
104+
#
105+
# TEST_CASE := ssh ${USER}@${TARGET} /path/to/my/test2
106+
#
107+
# TEST_START
108+
# MIN_CONFIG = config1
109+
# TEST = ${TEST_CASE}
110+
#
111+
# TEST_START
112+
# MIN_CONFIG = config2
113+
# TEST = ${TEST_CASE}
114+
#
115+
# TEST_DIR := /home/me/test
116+
#
117+
# BUILD_DIR = ${TEST_DIR}/linux.git
118+
# OUTPUT_DIR = ${TEST_DIR}/test
119+
#
120+
# Note, the config variables are evaluated immediately, thus
121+
# updating TARGET after TEST_CASE has been assigned does nothing
122+
# to TEST_CASE.
123+
#
124+
# As shown in the example, to evaluate a config variable, you
125+
# use the ${X} convention. Simple $X will not work.
126+
#
127+
# If the config variable does not exist, the ${X} will not
128+
# be evaluated. Thus:
129+
#
130+
# MAKE_CMD = PATH=/mypath:${PATH} make
131+
#
132+
# If PATH is not a config variable, then the ${PATH} in
133+
# the MAKE_CMD option will be evaluated by the shell when
134+
# the MAKE_CMD option is passed into shell processing.
135+
136+
#### Using options in other options ####
137+
#
138+
# Options that are defined in the config file may also be used
139+
# by other options. All options are evaulated at time of
140+
# use (except that config variables are evaluated at config
141+
# processing time).
142+
#
143+
# If an ktest option is used within another option, instead of
144+
# typing it again in that option you can simply use the option
145+
# just like you can config variables.
146+
#
147+
# MACHINE = mybox
148+
#
149+
# TEST = ssh root@${MACHINE} /path/to/test
150+
#
151+
# The option will be used per test case. Thus:
152+
#
153+
# TEST_TYPE = test
154+
# TEST = ssh root@{MACHINE}
155+
#
156+
# TEST_START
157+
# MACHINE = box1
158+
#
159+
# TEST_START
160+
# MACHINE = box2
161+
#
162+
# For both test cases, MACHINE will be evaluated at the time
163+
# of the test case. The first test will run ssh root@box1
164+
# and the second will run ssh root@box2.
76165

77166
#### Mandatory Default Options ####
78167

@@ -366,6 +455,10 @@
366455
# (default 60)
367456
#BISECT_SLEEP_TIME = 60
368457

458+
# The time in between patch checks to sleep (in seconds)
459+
# (default 60)
460+
#PATCHCHECK_SLEEP_TIME = 60
461+
369462
# Reboot the target box on error (default 0)
370463
#REBOOT_ON_ERROR = 0
371464

0 commit comments

Comments
 (0)