aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-05-23 11:20:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-23 11:20:44 -0400
commit2e77defc5da779888f3cf65e66cd3d47ae2d690f (patch)
treea9b961e698a03b08e96a3d07d8545a5fea4289dd /tools
parentcaebc160ce3f76761cc62ad96ef6d6f30f54e3dd (diff)
parent2a62512bceb44ad45f78aa7ca0e9cfaee9eae46f (diff)
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
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/ktest/ktest.pl156
-rw-r--r--tools/testing/ktest/sample.conf93
2 files changed, 242 insertions, 7 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8ce792ea08e9..1fd29b2daa92 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -36,6 +36,7 @@ $default{"REBOOT_ON_SUCCESS"} = 1;
36$default{"POWEROFF_ON_SUCCESS"} = 0; 36$default{"POWEROFF_ON_SUCCESS"} = 0;
37$default{"BUILD_OPTIONS"} = ""; 37$default{"BUILD_OPTIONS"} = "";
38$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects 38$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
39$default{"CLEAR_LOG"} = 0; 40$default{"CLEAR_LOG"} = 0;
40$default{"BISECT_MANUAL"} = 0; 41$default{"BISECT_MANUAL"} = 0;
41$default{"BISECT_SKIP"} = 1; 42$default{"BISECT_SKIP"} = 1;
@@ -96,6 +97,7 @@ my $monitor_pid;
96my $monitor_cnt = 0; 97my $monitor_cnt = 0;
97my $sleep_time; 98my $sleep_time;
98my $bisect_sleep_time; 99my $bisect_sleep_time;
100my $patchcheck_sleep_time;
99my $store_failures; 101my $store_failures;
100my $timeout; 102my $timeout;
101my $booted_timeout; 103my $booted_timeout;
@@ -112,6 +114,7 @@ my $successes = 0;
112 114
113my %entered_configs; 115my %entered_configs;
114my %config_help; 116my %config_help;
117my %variable;
115 118
116$config_help{"MACHINE"} = << "EOF" 119$config_help{"MACHINE"} = << "EOF"
117 The machine hostname that you will test. 120 The machine hostname that you will test.
@@ -260,6 +263,39 @@ sub get_ktest_configs {
260 } 263 }
261} 264}
262 265
266sub 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
263sub set_value { 299sub set_value {
264 my ($lvalue, $rvalue) = @_; 300 my ($lvalue, $rvalue) = @_;
265 301
@@ -269,10 +305,22 @@ sub set_value {
269 if ($rvalue =~ /^\s*$/) { 305 if ($rvalue =~ /^\s*$/) {
270 delete $opt{$lvalue}; 306 delete $opt{$lvalue};
271 } else { 307 } else {
308 $rvalue = process_variables($rvalue);
272 $opt{$lvalue} = $rvalue; 309 $opt{$lvalue} = $rvalue;
273 } 310 }
274} 311}
275 312
313sub 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
276sub read_config { 324sub read_config {
277 my ($config) = @_; 325 my ($config) = @_;
278 326
@@ -385,6 +433,22 @@ sub read_config {
385 $repeats{$val} = $repeat; 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 } else { 452 } else {
389 die "$name: $.: Garbage found in config\n$_"; 453 die "$name: $.: Garbage found in config\n$_";
390 } 454 }
@@ -838,6 +902,7 @@ sub monitor {
838 902
839 if ($stop_test_after > 0 && !$booted && !$bug) { 903 if ($stop_test_after > 0 && !$booted && !$bug) {
840 if (time - $monitor_start > $stop_test_after) { 904 if (time - $monitor_start > $stop_test_after) {
905 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
841 $done = 1; 906 $done = 1;
842 } 907 }
843 } 908 }
@@ -907,7 +972,7 @@ sub install {
907 return if (!defined($post_install)); 972 return if (!defined($post_install));
908 973
909 my $cp_post_install = $post_install; 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 run_command "$cp_post_install" or 976 run_command "$cp_post_install" or
912 dodie "Failed to run post install"; 977 dodie "Failed to run post install";
913} 978}
@@ -1247,14 +1312,14 @@ sub run_bisect_test {
1247 1312
1248 if ($failed) { 1313 if ($failed) {
1249 $result = 0; 1314 $result = 0;
1250
1251 # reboot the box to a good kernel
1252 if ($type ne "build") {
1253 bisect_reboot;
1254 }
1255 } else { 1315 } else {
1256 $result = 1; 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 $in_bisect = 0; 1323 $in_bisect = 0;
1259 1324
1260 return $result; 1325 return $result;
@@ -1763,6 +1828,14 @@ sub config_bisect {
1763 success $i; 1828 success $i;
1764} 1829}
1765 1830
1831sub 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
1766sub patchcheck { 1839sub patchcheck {
1767 my ($i) = @_; 1840 my ($i) = @_;
1768 1841
@@ -1854,6 +1927,8 @@ sub patchcheck {
1854 end_monitor; 1927 end_monitor;
1855 return 0 if ($failed); 1928 return 0 if ($failed);
1856 1929
1930 patchcheck_reboot;
1931
1857 } 1932 }
1858 $in_patchcheck = 0; 1933 $in_patchcheck = 0;
1859 success $i; 1934 success $i;
@@ -1944,7 +2019,7 @@ for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1944 } 2019 }
1945} 2020}
1946 2021
1947sub set_test_option { 2022sub __set_test_option {
1948 my ($name, $i) = @_; 2023 my ($name, $i) = @_;
1949 2024
1950 my $option = "$name\[$i\]"; 2025 my $option = "$name\[$i\]";
@@ -1970,6 +2045,72 @@ sub set_test_option {
1970 return undef; 2045 return undef;
1971} 2046}
1972 2047
2048sub 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
2088sub 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# First we need to do is the builds 2114# First we need to do is the builds
1974for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { 2115for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1975 2116
@@ -2003,6 +2144,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2003 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); 2144 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
2004 $sleep_time = set_test_option("SLEEP_TIME", $i); 2145 $sleep_time = set_test_option("SLEEP_TIME", $i);
2005 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); 2146 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
2147 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
2006 $bisect_manual = set_test_option("BISECT_MANUAL", $i); 2148 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
2007 $bisect_skip = set_test_option("BISECT_SKIP", $i); 2149 $bisect_skip = set_test_option("BISECT_SKIP", $i);
2008 $store_failures = set_test_option("STORE_FAILURES", $i); 2150 $store_failures = set_test_option("STORE_FAILURES", $i);
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index 4c5d6bd74a02..48cbcc80602a 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -73,6 +73,95 @@
73# ktest will fail to execute, and no tests will run. 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.
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.
76 165
77#### Mandatory Default Options #### 166#### Mandatory Default Options ####
78 167
@@ -366,6 +455,10 @@
366# (default 60) 455# (default 60)
367#BISECT_SLEEP_TIME = 60 456#BISECT_SLEEP_TIME = 60
368 457
458# The time in between patch checks to sleep (in seconds)
459# (default 60)
460#PATCHCHECK_SLEEP_TIME = 60
461
369# Reboot the target box on error (default 0) 462# Reboot the target box on error (default 0)
370#REBOOT_ON_ERROR = 0 463#REBOOT_ON_ERROR = 0
371 464