Commit 2e77defc5da779888f3cf65e66cd3d47ae2d690f
Exists in
master
and in
20 other branches
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
Showing 2 changed files Side-by-side Diff
tools/testing/ktest/ktest.pl
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 | $default{"POWEROFF_ON_SUCCESS"} = 0; |
37 | 37 | $default{"BUILD_OPTIONS"} = ""; |
38 | 38 | $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects |
39 | +$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks | |
39 | 40 | $default{"CLEAR_LOG"} = 0; |
40 | 41 | $default{"BISECT_MANUAL"} = 0; |
41 | 42 | $default{"BISECT_SKIP"} = 1; |
... | ... | @@ -96,6 +97,7 @@ |
96 | 97 | my $monitor_cnt = 0; |
97 | 98 | my $sleep_time; |
98 | 99 | my $bisect_sleep_time; |
100 | +my $patchcheck_sleep_time; | |
99 | 101 | my $store_failures; |
100 | 102 | my $timeout; |
101 | 103 | my $booted_timeout; |
... | ... | @@ -112,6 +114,7 @@ |
112 | 114 | |
113 | 115 | my %entered_configs; |
114 | 116 | my %config_help; |
117 | +my %variable; | |
115 | 118 | |
116 | 119 | $config_help{"MACHINE"} = << "EOF" |
117 | 120 | The machine hostname that you will test. |
... | ... | @@ -260,6 +263,39 @@ |
260 | 263 | } |
261 | 264 | } |
262 | 265 | |
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 | + | |
263 | 299 | sub set_value { |
264 | 300 | my ($lvalue, $rvalue) = @_; |
265 | 301 | |
266 | 302 | |
... | ... | @@ -269,10 +305,22 @@ |
269 | 305 | if ($rvalue =~ /^\s*$/) { |
270 | 306 | delete $opt{$lvalue}; |
271 | 307 | } else { |
308 | + $rvalue = process_variables($rvalue); | |
272 | 309 | $opt{$lvalue} = $rvalue; |
273 | 310 | } |
274 | 311 | } |
275 | 312 | |
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 | + | |
276 | 324 | sub read_config { |
277 | 325 | my ($config) = @_; |
278 | 326 | |
... | ... | @@ -385,6 +433,22 @@ |
385 | 433 | $repeats{$val} = $repeat; |
386 | 434 | } |
387 | 435 | } |
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 | + | |
388 | 452 | } else { |
389 | 453 | die "$name: $.: Garbage found in config\n$_"; |
390 | 454 | } |
... | ... | @@ -838,6 +902,7 @@ |
838 | 902 | |
839 | 903 | if ($stop_test_after > 0 && !$booted && !$bug) { |
840 | 904 | if (time - $monitor_start > $stop_test_after) { |
905 | + doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n"; | |
841 | 906 | $done = 1; |
842 | 907 | } |
843 | 908 | } |
... | ... | @@ -907,7 +972,7 @@ |
907 | 972 | return if (!defined($post_install)); |
908 | 973 | |
909 | 974 | my $cp_post_install = $post_install; |
910 | - $cp_post_install = s/\$KERNEL_VERSION/$version/g; | |
975 | + $cp_post_install =~ s/\$KERNEL_VERSION/$version/g; | |
911 | 976 | run_command "$cp_post_install" or |
912 | 977 | dodie "Failed to run post install"; |
913 | 978 | } |
914 | 979 | |
... | ... | @@ -1247,14 +1312,14 @@ |
1247 | 1312 | |
1248 | 1313 | if ($failed) { |
1249 | 1314 | $result = 0; |
1250 | - | |
1251 | - # reboot the box to a good kernel | |
1252 | - if ($type ne "build") { | |
1253 | - bisect_reboot; | |
1254 | - } | |
1255 | 1315 | } else { |
1256 | 1316 | $result = 1; |
1257 | 1317 | } |
1318 | + | |
1319 | + # reboot the box to a kernel we can ssh to | |
1320 | + if ($type ne "build") { | |
1321 | + bisect_reboot; | |
1322 | + } | |
1258 | 1323 | $in_bisect = 0; |
1259 | 1324 | |
1260 | 1325 | return $result; |
... | ... | @@ -1763,6 +1828,14 @@ |
1763 | 1828 | success $i; |
1764 | 1829 | } |
1765 | 1830 | |
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 | + | |
1766 | 1839 | sub patchcheck { |
1767 | 1840 | my ($i) = @_; |
1768 | 1841 | |
... | ... | @@ -1854,6 +1927,8 @@ |
1854 | 1927 | end_monitor; |
1855 | 1928 | return 0 if ($failed); |
1856 | 1929 | |
1930 | + patchcheck_reboot; | |
1931 | + | |
1857 | 1932 | } |
1858 | 1933 | $in_patchcheck = 0; |
1859 | 1934 | success $i; |
... | ... | @@ -1944,7 +2019,7 @@ |
1944 | 2019 | } |
1945 | 2020 | } |
1946 | 2021 | |
1947 | -sub set_test_option { | |
2022 | +sub __set_test_option { | |
1948 | 2023 | my ($name, $i) = @_; |
1949 | 2024 | |
1950 | 2025 | my $option = "$name\[$i\]"; |
... | ... | @@ -1970,6 +2045,72 @@ |
1970 | 2045 | return undef; |
1971 | 2046 | } |
1972 | 2047 | |
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 | + | |
1973 | 2114 | # First we need to do is the builds |
1974 | 2115 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
1975 | 2116 | |
... | ... | @@ -2003,6 +2144,7 @@ |
2003 | 2144 | $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); |
2004 | 2145 | $sleep_time = set_test_option("SLEEP_TIME", $i); |
2005 | 2146 | $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); |
2147 | + $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i); | |
2006 | 2148 | $bisect_manual = set_test_option("BISECT_MANUAL", $i); |
2007 | 2149 | $bisect_skip = set_test_option("BISECT_SKIP", $i); |
2008 | 2150 | $store_failures = set_test_option("STORE_FAILURES", $i); |
tools/testing/ktest/sample.conf
... | ... | @@ -73,7 +73,96 @@ |
73 | 73 | # ktest will fail to execute, and no tests will run. |
74 | 74 | # |
75 | 75 | |
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. | |
76 | 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. | |
165 | + | |
77 | 166 | #### Mandatory Default Options #### |
78 | 167 | |
79 | 168 | # These options must be in the default section, although most |
... | ... | @@ -365,6 +454,10 @@ |
365 | 454 | # The time in between bisects to sleep (in seconds) |
366 | 455 | # (default 60) |
367 | 456 | #BISECT_SLEEP_TIME = 60 |
457 | + | |
458 | +# The time in between patch checks to sleep (in seconds) | |
459 | +# (default 60) | |
460 | +#PATCHCHECK_SLEEP_TIME = 60 | |
368 | 461 | |
369 | 462 | # Reboot the target box on error (default 0) |
370 | 463 | #REBOOT_ON_ERROR = 0 |