Commit 5d48421be3c8a9f753d61b826ecb3ad287d867c0

Authored by Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest:
  ktest: Add INGORE_ERRORS to ignore warnings in boot up
  ktest: Still do reboot even for REBOOT_TYPE = script
  ktest: Fix compare script to test if options are not documented
  ktest: Detect typos in option names
  ktest: Have all values be set by defaults
  ktest: Change initialization of defaults hash to perl format
  ktest: Add options SWITCH_TO_GOOD and SWITCH_TO_TEST
  ktest: Allow overriding bisect test results
  ktest: Evaluate options before processing them
  ktest: Evaluate $KERNEL_VERSION in both install and post install
  ktest: Only ask options needed for install
  ktest: When creating a new config, ask for BUILD_OPTIONS
  ktest: Do not ask for some options if the only test is build
  ktest: Ask for type of test when creating a new config
  ktest: Allow bisect test to restart where it left off
  ktest: When creating new config, allow the use of ${THIS_DIR}
  ktest: Add default for ssh-user, build-target and target-image
  ktest: Allow success logs to be stored
  ktest: Save test output

Showing 3 changed files Side-by-side Diff

tools/testing/ktest/compare-ktest-sample.pl
... ... @@ -2,7 +2,9 @@
2 2  
3 3 open (IN,"ktest.pl");
4 4 while (<IN>) {
  5 + # hashes are now used
5 6 if (/\$opt\{"?([A-Z].*?)(\[.*\])?"?\}/ ||
  7 + /^\s*"?([A-Z].*?)"?\s*=>\s*/ ||
6 8 /set_test_option\("(.*?)"/) {
7 9 $opt{$1} = 1;
8 10 }
... ... @@ -11,7 +13,7 @@
11 13  
12 14 open (IN, "sample.conf");
13 15 while (<IN>) {
14   - if (/^\s*#?\s*(\S+)\s*=/) {
  16 + if (/^\s*#?\s*([A-Z]\S*)\s*=/) {
15 17 $samp{$1} = 1;
16 18 }
17 19 }
tools/testing/ktest/ktest.pl
Changes suppressed. Click to show
... ... @@ -18,41 +18,51 @@
18 18 my %opt;
19 19 my %repeat_tests;
20 20 my %repeats;
21   -my %default;
22 21  
23 22 #default opts
24   -$default{"NUM_TESTS"} = 1;
25   -$default{"REBOOT_TYPE"} = "grub";
26   -$default{"TEST_TYPE"} = "test";
27   -$default{"BUILD_TYPE"} = "randconfig";
28   -$default{"MAKE_CMD"} = "make";
29   -$default{"TIMEOUT"} = 120;
30   -$default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
31   -$default{"SLEEP_TIME"} = 60; # sleep time between tests
32   -$default{"BUILD_NOCLEAN"} = 0;
33   -$default{"REBOOT_ON_ERROR"} = 0;
34   -$default{"POWEROFF_ON_ERROR"} = 0;
35   -$default{"REBOOT_ON_SUCCESS"} = 1;
36   -$default{"POWEROFF_ON_SUCCESS"} = 0;
37   -$default{"BUILD_OPTIONS"} = "";
38   -$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39   -$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
40   -$default{"CLEAR_LOG"} = 0;
41   -$default{"BISECT_MANUAL"} = 0;
42   -$default{"BISECT_SKIP"} = 1;
43   -$default{"SUCCESS_LINE"} = "login:";
44   -$default{"DETECT_TRIPLE_FAULT"} = 1;
45   -$default{"NO_INSTALL"} = 0;
46   -$default{"BOOTED_TIMEOUT"} = 1;
47   -$default{"DIE_ON_FAILURE"} = 1;
48   -$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
49   -$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
50   -$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
51   -$default{"STOP_AFTER_SUCCESS"} = 10;
52   -$default{"STOP_AFTER_FAILURE"} = 60;
53   -$default{"STOP_TEST_AFTER"} = 600;
54   -$default{"LOCALVERSION"} = "-test";
  23 +my %default = (
  24 + "NUM_TESTS" => 1,
  25 + "TEST_TYPE" => "build",
  26 + "BUILD_TYPE" => "randconfig",
  27 + "MAKE_CMD" => "make",
  28 + "TIMEOUT" => 120,
  29 + "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
  30 + "SLEEP_TIME" => 60, # sleep time between tests
  31 + "BUILD_NOCLEAN" => 0,
  32 + "REBOOT_ON_ERROR" => 0,
  33 + "POWEROFF_ON_ERROR" => 0,
  34 + "REBOOT_ON_SUCCESS" => 1,
  35 + "POWEROFF_ON_SUCCESS" => 0,
  36 + "BUILD_OPTIONS" => "",
  37 + "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
  38 + "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
  39 + "CLEAR_LOG" => 0,
  40 + "BISECT_MANUAL" => 0,
  41 + "BISECT_SKIP" => 1,
  42 + "SUCCESS_LINE" => "login:",
  43 + "DETECT_TRIPLE_FAULT" => 1,
  44 + "NO_INSTALL" => 0,
  45 + "BOOTED_TIMEOUT" => 1,
  46 + "DIE_ON_FAILURE" => 1,
  47 + "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
  48 + "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
  49 + "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
  50 + "STOP_AFTER_SUCCESS" => 10,
  51 + "STOP_AFTER_FAILURE" => 60,
  52 + "STOP_TEST_AFTER" => 600,
55 53  
  54 +# required, and we will ask users if they don't have them but we keep the default
  55 +# value something that is common.
  56 + "REBOOT_TYPE" => "grub",
  57 + "LOCALVERSION" => "-test",
  58 + "SSH_USER" => "root",
  59 + "BUILD_TARGET" => "arch/x86/boot/bzImage",
  60 + "TARGET_IMAGE" => "/boot/vmlinuz-test",
  61 +
  62 + "LOG_FILE" => undef,
  63 + "IGNORE_UNUSED" => 0,
  64 +);
  65 +
56 66 my $ktest_config;
57 67 my $version;
58 68 my $machine;
... ... @@ -73,6 +83,8 @@
73 83 my $power_cycle;
74 84 my $reboot;
75 85 my $reboot_on_error;
  86 +my $switch_to_good;
  87 +my $switch_to_test;
76 88 my $poweroff_on_error;
77 89 my $die_on_failure;
78 90 my $powercycle_after_reboot;
79 91  
80 92  
81 93  
... ... @@ -92,17 +104,24 @@
92 104 my $start_minconfig_defined;
93 105 my $output_minconfig;
94 106 my $ignore_config;
  107 +my $ignore_errors;
95 108 my $addconfig;
96 109 my $in_bisect = 0;
97   -my $bisect_bad = "";
  110 +my $bisect_bad_commit = "";
98 111 my $reverse_bisect;
99 112 my $bisect_manual;
100 113 my $bisect_skip;
101 114 my $config_bisect_good;
  115 +my $bisect_ret_good;
  116 +my $bisect_ret_bad;
  117 +my $bisect_ret_skip;
  118 +my $bisect_ret_abort;
  119 +my $bisect_ret_default;
102 120 my $in_patchcheck = 0;
103 121 my $run_test;
104 122 my $redirect;
105 123 my $buildlog;
  124 +my $testlog;
106 125 my $dmesg;
107 126 my $monitor_fp;
108 127 my $monitor_pid;
... ... @@ -112,6 +131,7 @@
112 131 my $patchcheck_sleep_time;
113 132 my $ignore_warnings;
114 133 my $store_failures;
  134 +my $store_successes;
115 135 my $test_name;
116 136 my $timeout;
117 137 my $booted_timeout;
118 138  
... ... @@ -124,10 +144,34 @@
124 144 my $stop_test_after;
125 145 my $build_target;
126 146 my $target_image;
  147 +my $checkout;
127 148 my $localversion;
128 149 my $iteration = 0;
129 150 my $successes = 0;
130 151  
  152 +my $bisect_good;
  153 +my $bisect_bad;
  154 +my $bisect_type;
  155 +my $bisect_start;
  156 +my $bisect_replay;
  157 +my $bisect_files;
  158 +my $bisect_reverse;
  159 +my $bisect_check;
  160 +
  161 +my $config_bisect;
  162 +my $config_bisect_type;
  163 +
  164 +my $patchcheck_type;
  165 +my $patchcheck_start;
  166 +my $patchcheck_end;
  167 +
  168 +# set when a test is something other that just building or install
  169 +# which would require more options.
  170 +my $buildonly = 1;
  171 +
  172 +# set when creating a new config
  173 +my $newconfig = 0;
  174 +
131 175 my %entered_configs;
132 176 my %config_help;
133 177 my %variable;
134 178  
... ... @@ -136,11 +180,99 @@
136 180 # do not force reboots on config problems
137 181 my $no_reboot = 1;
138 182  
  183 +my %option_map = (
  184 + "MACHINE" => \$machine,
  185 + "SSH_USER" => \$ssh_user,
  186 + "TMP_DIR" => \$tmpdir,
  187 + "OUTPUT_DIR" => \$outputdir,
  188 + "BUILD_DIR" => \$builddir,
  189 + "TEST_TYPE" => \$test_type,
  190 + "BUILD_TYPE" => \$build_type,
  191 + "BUILD_OPTIONS" => \$build_options,
  192 + "PRE_BUILD" => \$pre_build,
  193 + "POST_BUILD" => \$post_build,
  194 + "PRE_BUILD_DIE" => \$pre_build_die,
  195 + "POST_BUILD_DIE" => \$post_build_die,
  196 + "POWER_CYCLE" => \$power_cycle,
  197 + "REBOOT" => \$reboot,
  198 + "BUILD_NOCLEAN" => \$noclean,
  199 + "MIN_CONFIG" => \$minconfig,
  200 + "OUTPUT_MIN_CONFIG" => \$output_minconfig,
  201 + "START_MIN_CONFIG" => \$start_minconfig,
  202 + "IGNORE_CONFIG" => \$ignore_config,
  203 + "TEST" => \$run_test,
  204 + "ADD_CONFIG" => \$addconfig,
  205 + "REBOOT_TYPE" => \$reboot_type,
  206 + "GRUB_MENU" => \$grub_menu,
  207 + "POST_INSTALL" => \$post_install,
  208 + "NO_INSTALL" => \$no_install,
  209 + "REBOOT_SCRIPT" => \$reboot_script,
  210 + "REBOOT_ON_ERROR" => \$reboot_on_error,
  211 + "SWITCH_TO_GOOD" => \$switch_to_good,
  212 + "SWITCH_TO_TEST" => \$switch_to_test,
  213 + "POWEROFF_ON_ERROR" => \$poweroff_on_error,
  214 + "DIE_ON_FAILURE" => \$die_on_failure,
  215 + "POWER_OFF" => \$power_off,
  216 + "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
  217 + "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
  218 + "SLEEP_TIME" => \$sleep_time,
  219 + "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
  220 + "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
  221 + "IGNORE_WARNINGS" => \$ignore_warnings,
  222 + "IGNORE_ERRORS" => \$ignore_errors,
  223 + "BISECT_MANUAL" => \$bisect_manual,
  224 + "BISECT_SKIP" => \$bisect_skip,
  225 + "CONFIG_BISECT_GOOD" => \$config_bisect_good,
  226 + "BISECT_RET_GOOD" => \$bisect_ret_good,
  227 + "BISECT_RET_BAD" => \$bisect_ret_bad,
  228 + "BISECT_RET_SKIP" => \$bisect_ret_skip,
  229 + "BISECT_RET_ABORT" => \$bisect_ret_abort,
  230 + "BISECT_RET_DEFAULT" => \$bisect_ret_default,
  231 + "STORE_FAILURES" => \$store_failures,
  232 + "STORE_SUCCESSES" => \$store_successes,
  233 + "TEST_NAME" => \$test_name,
  234 + "TIMEOUT" => \$timeout,
  235 + "BOOTED_TIMEOUT" => \$booted_timeout,
  236 + "CONSOLE" => \$console,
  237 + "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
  238 + "SUCCESS_LINE" => \$success_line,
  239 + "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
  240 + "STOP_AFTER_SUCCESS" => \$stop_after_success,
  241 + "STOP_AFTER_FAILURE" => \$stop_after_failure,
  242 + "STOP_TEST_AFTER" => \$stop_test_after,
  243 + "BUILD_TARGET" => \$build_target,
  244 + "SSH_EXEC" => \$ssh_exec,
  245 + "SCP_TO_TARGET" => \$scp_to_target,
  246 + "CHECKOUT" => \$checkout,
  247 + "TARGET_IMAGE" => \$target_image,
  248 + "LOCALVERSION" => \$localversion,
  249 +
  250 + "BISECT_GOOD" => \$bisect_good,
  251 + "BISECT_BAD" => \$bisect_bad,
  252 + "BISECT_TYPE" => \$bisect_type,
  253 + "BISECT_START" => \$bisect_start,
  254 + "BISECT_REPLAY" => \$bisect_replay,
  255 + "BISECT_FILES" => \$bisect_files,
  256 + "BISECT_REVERSE" => \$bisect_reverse,
  257 + "BISECT_CHECK" => \$bisect_check,
  258 +
  259 + "CONFIG_BISECT" => \$config_bisect,
  260 + "CONFIG_BISECT_TYPE" => \$config_bisect_type,
  261 +
  262 + "PATCHCHECK_TYPE" => \$patchcheck_type,
  263 + "PATCHCHECK_START" => \$patchcheck_start,
  264 + "PATCHCHECK_END" => \$patchcheck_end,
  265 +);
  266 +
  267 +# Options may be used by other options, record them.
  268 +my %used_options;
  269 +
139 270 # default variables that can be used
140 271 chomp ($variable{"PWD"} = `pwd`);
141 272  
142 273 $config_help{"MACHINE"} = << "EOF"
143 274 The machine hostname that you will test.
  275 + For build only tests, it is still needed to differentiate log files.
144 276 EOF
145 277 ;
146 278 $config_help{"SSH_USER"} = << "EOF"
147 279  
... ... @@ -150,11 +282,15 @@
150 282 ;
151 283 $config_help{"BUILD_DIR"} = << "EOF"
152 284 The directory that contains the Linux source code (full path).
  285 + You can use \${PWD} that will be the path where ktest.pl is run, or use
  286 + \${THIS_DIR} which is assigned \${PWD} but may be changed later.
153 287 EOF
154 288 ;
155 289 $config_help{"OUTPUT_DIR"} = << "EOF"
156 290 The directory that the objects will be built (full path).
157 291 (can not be same as BUILD_DIR)
  292 + You can use \${PWD} that will be the path where ktest.pl is run, or use
  293 + \${THIS_DIR} which is assigned \${PWD} but may be changed later.
158 294 EOF
159 295 ;
160 296 $config_help{"BUILD_TARGET"} = << "EOF"
... ... @@ -162,6 +298,11 @@
162 298 (relative to OUTPUT_DIR)
163 299 EOF
164 300 ;
  301 +$config_help{"BUILD_OPTIONS"} = << "EOF"
  302 + Options to add to \"make\" when building.
  303 + i.e. -j20
  304 +EOF
  305 + ;
165 306 $config_help{"TARGET_IMAGE"} = << "EOF"
166 307 The place to put your image on the test machine.
167 308 EOF
168 309  
169 310  
170 311  
171 312  
172 313  
... ... @@ -227,27 +368,55 @@
227 368 EOF
228 369 ;
229 370  
230   -sub read_yn {
231   - my ($prompt) = @_;
  371 +sub read_prompt {
  372 + my ($cancel, $prompt) = @_;
232 373  
233 374 my $ans;
234 375  
235 376 for (;;) {
236   - print "$prompt [Y/n] ";
  377 + if ($cancel) {
  378 + print "$prompt [y/n/C] ";
  379 + } else {
  380 + print "$prompt [Y/n] ";
  381 + }
237 382 $ans = <STDIN>;
238 383 chomp $ans;
239 384 if ($ans =~ /^\s*$/) {
240   - $ans = "y";
  385 + if ($cancel) {
  386 + $ans = "c";
  387 + } else {
  388 + $ans = "y";
  389 + }
241 390 }
242 391 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
243   - print "Please answer either 'y' or 'n'.\n";
  392 + if ($cancel) {
  393 + last if ($ans =~ /^c$/i);
  394 + print "Please answer either 'y', 'n' or 'c'.\n";
  395 + } else {
  396 + print "Please answer either 'y' or 'n'.\n";
  397 + }
244 398 }
  399 + if ($ans =~ /^c/i) {
  400 + exit;
  401 + }
245 402 if ($ans !~ /^y$/i) {
246 403 return 0;
247 404 }
248 405 return 1;
249 406 }
250 407  
  408 +sub read_yn {
  409 + my ($prompt) = @_;
  410 +
  411 + return read_prompt 0, $prompt;
  412 +}
  413 +
  414 +sub read_ync {
  415 + my ($prompt) = @_;
  416 +
  417 + return read_prompt 1, $prompt;
  418 +}
  419 +
251 420 sub get_ktest_config {
252 421 my ($config) = @_;
253 422 my $ans;
... ... @@ -261,7 +430,7 @@
261 430  
262 431 for (;;) {
263 432 print "$config = ";
264   - if (defined($default{$config})) {
  433 + if (defined($default{$config}) && length($default{$config})) {
265 434 print "\[$default{$config}\] ";
266 435 }
267 436 $ans = <STDIN>;
268 437  
269 438  
270 439  
... ... @@ -274,22 +443,37 @@
274 443 next;
275 444 }
276 445 }
277   - $entered_configs{$config} = process_variables($ans);
  446 + $entered_configs{$config} = ${ans};
278 447 last;
279 448 }
280 449 }
281 450  
282 451 sub get_ktest_configs {
283 452 get_ktest_config("MACHINE");
284   - get_ktest_config("SSH_USER");
285 453 get_ktest_config("BUILD_DIR");
286 454 get_ktest_config("OUTPUT_DIR");
287   - get_ktest_config("BUILD_TARGET");
288   - get_ktest_config("TARGET_IMAGE");
289   - get_ktest_config("POWER_CYCLE");
290   - get_ktest_config("CONSOLE");
  455 +
  456 + if ($newconfig) {
  457 + get_ktest_config("BUILD_OPTIONS");
  458 + }
  459 +
  460 + # options required for other than just building a kernel
  461 + if (!$buildonly) {
  462 + get_ktest_config("POWER_CYCLE");
  463 + get_ktest_config("CONSOLE");
  464 + }
  465 +
  466 + # options required for install and more
  467 + if ($buildonly != 1) {
  468 + get_ktest_config("SSH_USER");
  469 + get_ktest_config("BUILD_TARGET");
  470 + get_ktest_config("TARGET_IMAGE");
  471 + }
  472 +
291 473 get_ktest_config("LOCALVERSION");
292 474  
  475 + return if ($buildonly);
  476 +
293 477 my $rtype = $opt{"REBOOT_TYPE"};
294 478  
295 479 if (!defined($rtype)) {
... ... @@ -303,8 +487,6 @@
303 487  
304 488 if ($rtype eq "grub") {
305 489 get_ktest_config("GRUB_MENU");
306   - } else {
307   - get_ktest_config("REBOOT_SCRIPT");
308 490 }
309 491 }
310 492  
... ... @@ -334,6 +516,10 @@
334 516 } else {
335 517 # put back the origin piece.
336 518 $retval = "$retval\$\{$var\}";
  519 + # This could be an option that is used later, save
  520 + # it so we don't warn if this option is not one of
  521 + # ktests options.
  522 + $used_options{$var} = 1;
337 523 }
338 524 $value = $end;
339 525 }
... ... @@ -348,6 +534,19 @@
348 534 sub set_value {
349 535 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
350 536  
  537 + my $prvalue = process_variables($rvalue);
  538 +
  539 + if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
  540 + # Note if a test is something other than build, then we
  541 + # will need other manditory options.
  542 + if ($prvalue ne "install") {
  543 + $buildonly = 0;
  544 + } else {
  545 + # install still limits some manditory options.
  546 + $buildonly = 2;
  547 + }
  548 + }
  549 +
351 550 if (defined($opt{$lvalue})) {
352 551 if (!$override || defined(${$overrides}{$lvalue})) {
353 552 my $extra = "";
354 553  
... ... @@ -356,13 +555,12 @@
356 555 }
357 556 die "$name: $.: Option $lvalue defined more than once!\n$extra";
358 557 }
359   - ${$overrides}{$lvalue} = $rvalue;
  558 + ${$overrides}{$lvalue} = $prvalue;
360 559 }
361 560 if ($rvalue =~ /^\s*$/) {
362 561 delete $opt{$lvalue};
363 562 } else {
364   - $rvalue = process_variables($rvalue);
365   - $opt{$lvalue} = $rvalue;
  563 + $opt{$lvalue} = $prvalue;
366 564 }
367 565 }
368 566  
... ... @@ -712,6 +910,15 @@
712 910 return $test_case;
713 911 }
714 912  
  913 +sub get_test_case {
  914 + print "What test case would you like to run?\n";
  915 + print " (build, install or boot)\n";
  916 + print " Other tests are available but require editing the config file\n";
  917 + my $ans = <STDIN>;
  918 + chomp $ans;
  919 + $default{"TEST_TYPE"} = $ans;
  920 +}
  921 +
715 922 sub read_config {
716 923 my ($config) = @_;
717 924  
... ... @@ -726,10 +933,7 @@
726 933 # was a test specified?
727 934 if (!$test_case) {
728 935 print "No test case specified.\n";
729   - print "What test case would you like to run?\n";
730   - my $ans = <STDIN>;
731   - chomp $ans;
732   - $default{"TEST_TYPE"} = $ans;
  936 + get_test_case;
733 937 }
734 938  
735 939 # set any defaults
... ... @@ -739,6 +943,37 @@
739 943 $opt{$default} = $default{$default};
740 944 }
741 945 }
  946 +
  947 + if ($opt{"IGNORE_UNUSED"} == 1) {
  948 + return;
  949 + }
  950 +
  951 + my %not_used;
  952 +
  953 + # check if there are any stragglers (typos?)
  954 + foreach my $option (keys %opt) {
  955 + my $op = $option;
  956 + # remove per test labels.
  957 + $op =~ s/\[.*\]//;
  958 + if (!exists($option_map{$op}) &&
  959 + !exists($default{$op}) &&
  960 + !exists($used_options{$op})) {
  961 + $not_used{$op} = 1;
  962 + }
  963 + }
  964 +
  965 + if (%not_used) {
  966 + my $s = "s are";
  967 + $s = " is" if (keys %not_used == 1);
  968 + print "The following option$s not used; could be a typo:\n";
  969 + foreach my $option (keys %not_used) {
  970 + print "$option\n";
  971 + }
  972 + print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
  973 + if (!read_yn "Do you want to continue?") {
  974 + exit -1;
  975 + }
  976 + }
742 977 }
743 978  
744 979 sub __eval_option {
... ... @@ -873,6 +1108,17 @@
873 1108 }
874 1109 }
875 1110  
  1111 +sub reboot_to_good {
  1112 + my ($time) = @_;
  1113 +
  1114 + if (defined($switch_to_good)) {
  1115 + run_command $switch_to_good;
  1116 + return;
  1117 + }
  1118 +
  1119 + reboot $time;
  1120 +}
  1121 +
876 1122 sub do_not_reboot {
877 1123 my $i = $iteration;
878 1124  
... ... @@ -889,7 +1135,7 @@
889 1135 if ($reboot_on_error && !do_not_reboot) {
890 1136  
891 1137 doprint "REBOOTING\n";
892   - reboot;
  1138 + reboot_to_good;
893 1139  
894 1140 } elsif ($poweroff_on_error && defined($power_off)) {
895 1141 doprint "POWERING OFF\n";
... ... @@ -975,6 +1221,43 @@
975 1221 print "** Monitor flushed **\n";
976 1222 }
977 1223  
  1224 +sub save_logs {
  1225 + my ($result, $basedir) = @_;
  1226 + my @t = localtime;
  1227 + my $date = sprintf "%04d%02d%02d%02d%02d%02d",
  1228 + 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
  1229 +
  1230 + my $type = $build_type;
  1231 + if ($type =~ /useconfig/) {
  1232 + $type = "useconfig";
  1233 + }
  1234 +
  1235 + my $dir = "$machine-$test_type-$type-$result-$date";
  1236 +
  1237 + $dir = "$basedir/$dir";
  1238 +
  1239 + if (!-d $dir) {
  1240 + mkpath($dir) or
  1241 + die "can't create $dir";
  1242 + }
  1243 +
  1244 + my %files = (
  1245 + "config" => $output_config,
  1246 + "buildlog" => $buildlog,
  1247 + "dmesg" => $dmesg,
  1248 + "testlog" => $testlog,
  1249 + );
  1250 +
  1251 + while (my ($name, $source) = each(%files)) {
  1252 + if (-f "$source") {
  1253 + cp "$source", "$dir/$name" or
  1254 + die "failed to copy $source";
  1255 + }
  1256 + }
  1257 +
  1258 + doprint "*** Saved info to $dir ***\n";
  1259 +}
  1260 +
978 1261 sub fail {
979 1262  
980 1263 if ($die_on_failure) {
... ... @@ -988,7 +1271,7 @@
988 1271 # no need to reboot for just building.
989 1272 if (!do_not_reboot) {
990 1273 doprint "REBOOTING\n";
991   - reboot $sleep_time;
  1274 + reboot_to_good $sleep_time;
992 1275 }
993 1276  
994 1277 my $name = "";
995 1278  
... ... @@ -1003,39 +1286,10 @@
1003 1286 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1004 1287 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1005 1288  
1006   - return 1 if (!defined($store_failures));
  1289 + if (defined($store_failures)) {
  1290 + save_logs "fail", $store_failures;
  1291 + }
1007 1292  
1008   - my @t = localtime;
1009   - my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1010   - 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1011   -
1012   - my $type = $build_type;
1013   - if ($type =~ /useconfig/) {
1014   - $type = "useconfig";
1015   - }
1016   -
1017   - my $dir = "$machine-$test_type-$type-fail-$date";
1018   - my $faildir = "$store_failures/$dir";
1019   -
1020   - if (!-d $faildir) {
1021   - mkpath($faildir) or
1022   - die "can't create $faildir";
1023   - }
1024   - if (-f "$output_config") {
1025   - cp "$output_config", "$faildir/config" or
1026   - die "failed to copy .config";
1027   - }
1028   - if (-f $buildlog) {
1029   - cp $buildlog, "$faildir/buildlog" or
1030   - die "failed to move $buildlog";
1031   - }
1032   - if (-f $dmesg) {
1033   - cp $dmesg, "$faildir/dmesg" or
1034   - die "failed to move $dmesg";
1035   - }
1036   -
1037   - doprint "*** Saved info to $faildir ***\n";
1038   -
1039 1293 return 1;
1040 1294 }
1041 1295  
1042 1296  
1043 1297  
... ... @@ -1170,13 +1424,16 @@
1170 1424 }
1171 1425  
1172 1426 sub reboot_to {
  1427 + if (defined($switch_to_test)) {
  1428 + run_command $switch_to_test;
  1429 + }
  1430 +
1173 1431 if ($reboot_type eq "grub") {
1174 1432 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1175   - reboot;
1176   - return;
  1433 + } elsif (defined $reboot_script) {
  1434 + run_command "$reboot_script";
1177 1435 }
1178   -
1179   - run_command "$reboot_script";
  1436 + reboot;
1180 1437 }
1181 1438  
1182 1439 sub get_sha1 {
... ... @@ -1274,7 +1531,7 @@
1274 1531 }
1275 1532  
1276 1533 if ($full_line =~ /call trace:/i) {
1277   - if (!$bug && !$skip_call_trace) {
  1534 + if (!$ignore_errors && !$bug && !$skip_call_trace) {
1278 1535 $bug = 1;
1279 1536 $failure_start = time;
1280 1537 }
1281 1538  
... ... @@ -1341,12 +1598,19 @@
1341 1598 return 1;
1342 1599 }
1343 1600  
  1601 +sub eval_kernel_version {
  1602 + my ($option) = @_;
  1603 +
  1604 + $option =~ s/\$KERNEL_VERSION/$version/g;
  1605 +
  1606 + return $option;
  1607 +}
  1608 +
1344 1609 sub do_post_install {
1345 1610  
1346 1611 return if (!defined($post_install));
1347 1612  
1348   - my $cp_post_install = $post_install;
1349   - $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
  1613 + my $cp_post_install = eval_kernel_version $post_install;
1350 1614 run_command "$cp_post_install" or
1351 1615 dodie "Failed to run post install";
1352 1616 }
... ... @@ -1355,7 +1619,9 @@
1355 1619  
1356 1620 return if ($no_install);
1357 1621  
1358   - run_scp "$outputdir/$build_target", "$target_image" or
  1622 + my $cp_target = eval_kernel_version $target_image;
  1623 +
  1624 + run_scp "$outputdir/$build_target", "$cp_target" or
1359 1625 dodie "failed to copy image";
1360 1626  
1361 1627 my $install_mods = 0;
1362 1628  
... ... @@ -1640,9 +1906,13 @@
1640 1906 doprint "*******************************************\n";
1641 1907 doprint "*******************************************\n";
1642 1908  
  1909 + if (defined($store_successes)) {
  1910 + save_logs "success", $store_successes;
  1911 + }
  1912 +
1643 1913 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1644 1914 doprint "Reboot and wait $sleep_time seconds\n";
1645   - reboot $sleep_time;
  1915 + reboot_to_good $sleep_time;
1646 1916 }
1647 1917 }
1648 1918  
1649 1919  
... ... @@ -1669,7 +1939,10 @@
1669 1939 $poweroff_on_error = 0;
1670 1940 $die_on_failure = 1;
1671 1941  
  1942 + $redirect = "$testlog";
1672 1943 run_command $run_test or $failed = 1;
  1944 + undef $redirect;
  1945 +
1673 1946 exit $failed;
1674 1947 }
1675 1948  
... ... @@ -1744,6 +2017,43 @@
1744 2017 waitpid $child_pid, 0;
1745 2018 $child_exit = $?;
1746 2019  
  2020 + if (!$bug && $in_bisect) {
  2021 + if (defined($bisect_ret_good)) {
  2022 + if ($child_exit == $bisect_ret_good) {
  2023 + return 1;
  2024 + }
  2025 + }
  2026 + if (defined($bisect_ret_skip)) {
  2027 + if ($child_exit == $bisect_ret_skip) {
  2028 + return -1;
  2029 + }
  2030 + }
  2031 + if (defined($bisect_ret_abort)) {
  2032 + if ($child_exit == $bisect_ret_abort) {
  2033 + fail "test abort" and return -2;
  2034 + }
  2035 + }
  2036 + if (defined($bisect_ret_bad)) {
  2037 + if ($child_exit == $bisect_ret_skip) {
  2038 + return 0;
  2039 + }
  2040 + }
  2041 + if (defined($bisect_ret_default)) {
  2042 + if ($bisect_ret_default eq "good") {
  2043 + return 1;
  2044 + } elsif ($bisect_ret_default eq "bad") {
  2045 + return 0;
  2046 + } elsif ($bisect_ret_default eq "skip") {
  2047 + return -1;
  2048 + } elsif ($bisect_ret_default eq "abort") {
  2049 + return -2;
  2050 + } else {
  2051 + fail "unknown default action: $bisect_ret_default"
  2052 + and return -2;
  2053 + }
  2054 + }
  2055 + }
  2056 +
1747 2057 if ($bug || $child_exit) {
1748 2058 return 0 if $in_bisect;
1749 2059 fail "test failed" and return 0;
... ... @@ -1770,7 +2080,7 @@
1770 2080 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1771 2081 doprint "$1 [$2]\n";
1772 2082 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1773   - $bisect_bad = $1;
  2083 + $bisect_bad_commit = $1;
1774 2084 doprint "Found bad commit... $1\n";
1775 2085 return 0;
1776 2086 } else {
... ... @@ -1783,7 +2093,7 @@
1783 2093  
1784 2094 sub bisect_reboot {
1785 2095 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1786   - reboot $bisect_sleep_time;
  2096 + reboot_to_good $bisect_sleep_time;
1787 2097 }
1788 2098  
1789 2099 # returns 1 on success, 0 on failure, -1 on skip
1790 2100  
1791 2101  
... ... @@ -1868,21 +2178,28 @@
1868 2178 }
1869 2179 }
1870 2180  
  2181 +sub update_bisect_replay {
  2182 + my $tmp_log = "$tmpdir/ktest_bisect_log";
  2183 + run_command "git bisect log > $tmp_log" or
  2184 + die "can't create bisect log";
  2185 + return $tmp_log;
  2186 +}
  2187 +
1871 2188 sub bisect {
1872 2189 my ($i) = @_;
1873 2190  
1874 2191 my $result;
1875 2192  
1876   - die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1877   - die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1878   - die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
  2193 + die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
  2194 + die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
  2195 + die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
1879 2196  
1880   - my $good = $opt{"BISECT_GOOD[$i]"};
1881   - my $bad = $opt{"BISECT_BAD[$i]"};
1882   - my $type = $opt{"BISECT_TYPE[$i]"};
1883   - my $start = $opt{"BISECT_START[$i]"};
1884   - my $replay = $opt{"BISECT_REPLAY[$i]"};
1885   - my $start_files = $opt{"BISECT_FILES[$i]"};
  2197 + my $good = $bisect_good;
  2198 + my $bad = $bisect_bad;
  2199 + my $type = $bisect_type;
  2200 + my $start = $bisect_start;
  2201 + my $replay = $bisect_replay;
  2202 + my $start_files = $bisect_files;
1886 2203  
1887 2204 if (defined($start_files)) {
1888 2205 $start_files = " -- " . $start_files;
... ... @@ -1894,8 +2211,7 @@
1894 2211 $good = get_sha1($good);
1895 2212 $bad = get_sha1($bad);
1896 2213  
1897   - if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1898   - $opt{"BISECT_REVERSE[$i]"} == 1) {
  2214 + if (defined($bisect_reverse) && $bisect_reverse == 1) {
1899 2215 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1900 2216 $reverse_bisect = 1;
1901 2217 } else {
1902 2218  
... ... @@ -1907,9 +2223,32 @@
1907 2223 $type = "boot";
1908 2224 }
1909 2225  
1910   - my $check = $opt{"BISECT_CHECK[$i]"};
1911   - if (defined($check) && $check ne "0") {
  2226 + # Check if a bisect was running
  2227 + my $bisect_start_file = "$builddir/.git/BISECT_START";
1912 2228  
  2229 + my $check = $bisect_check;
  2230 + my $do_check = defined($check) && $check ne "0";
  2231 +
  2232 + if ( -f $bisect_start_file ) {
  2233 + print "Bisect in progress found\n";
  2234 + if ($do_check) {
  2235 + print " If you say yes, then no checks of good or bad will be done\n";
  2236 + }
  2237 + if (defined($replay)) {
  2238 + print "** BISECT_REPLAY is defined in config file **";
  2239 + print " Ignore config option and perform new git bisect log?\n";
  2240 + if (read_ync " (yes, no, or cancel) ") {
  2241 + $replay = update_bisect_replay;
  2242 + $do_check = 0;
  2243 + }
  2244 + } elsif (read_yn "read git log and continue?") {
  2245 + $replay = update_bisect_replay;
  2246 + $do_check = 0;
  2247 + }
  2248 + }
  2249 +
  2250 + if ($do_check) {
  2251 +
1913 2252 # get current HEAD
1914 2253 my $head = get_sha1("HEAD");
1915 2254  
... ... @@ -1973,7 +2312,7 @@
1973 2312 run_command "git bisect reset" or
1974 2313 dodie "could not reset git bisect";
1975 2314  
1976   - doprint "Bad commit was [$bisect_bad]\n";
  2315 + doprint "Bad commit was [$bisect_bad_commit]\n";
1977 2316  
1978 2317 success $i;
1979 2318 }
... ... @@ -2129,7 +2468,7 @@
2129 2468 }
2130 2469  
2131 2470 doprint "***** RUN TEST ***\n";
2132   - my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
  2471 + my $type = $config_bisect_type;
2133 2472 my $ret;
2134 2473 my %current_config;
2135 2474  
... ... @@ -2233,7 +2572,7 @@
2233 2572 sub config_bisect {
2234 2573 my ($i) = @_;
2235 2574  
2236   - my $start_config = $opt{"CONFIG_BISECT[$i]"};
  2575 + my $start_config = $config_bisect;
2237 2576  
2238 2577 my $tmpconfig = "$tmpdir/use_config";
2239 2578  
2240 2579  
2241 2580  
2242 2581  
2243 2582  
2244 2583  
... ... @@ -2346,29 +2685,29 @@
2346 2685  
2347 2686 sub patchcheck_reboot {
2348 2687 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2349   - reboot $patchcheck_sleep_time;
  2688 + reboot_to_good $patchcheck_sleep_time;
2350 2689 }
2351 2690  
2352 2691 sub patchcheck {
2353 2692 my ($i) = @_;
2354 2693  
2355 2694 die "PATCHCHECK_START[$i] not defined\n"
2356   - if (!defined($opt{"PATCHCHECK_START[$i]"}));
  2695 + if (!defined($patchcheck_start));
2357 2696 die "PATCHCHECK_TYPE[$i] not defined\n"
2358   - if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
  2697 + if (!defined($patchcheck_type));
2359 2698  
2360   - my $start = $opt{"PATCHCHECK_START[$i]"};
  2699 + my $start = $patchcheck_start;
2361 2700  
2362 2701 my $end = "HEAD";
2363   - if (defined($opt{"PATCHCHECK_END[$i]"})) {
2364   - $end = $opt{"PATCHCHECK_END[$i]"};
  2702 + if (defined($patchcheck_end)) {
  2703 + $end = $patchcheck_end;
2365 2704 }
2366 2705  
2367 2706 # Get the true sha1's since we can use things like HEAD~3
2368 2707 $start = get_sha1($start);
2369 2708 $end = get_sha1($end);
2370 2709  
2371   - my $type = $opt{"PATCHCHECK_TYPE[$i]"};
  2710 + my $type = $patchcheck_type;
2372 2711  
2373 2712 # Can't have a test without having a test to run
2374 2713 if ($type eq "test" && !defined($run_test)) {
... ... @@ -2963,7 +3302,7 @@
2963 3302 }
2964 3303  
2965 3304 doprint "Reboot and wait $sleep_time seconds\n";
2966   - reboot $sleep_time;
  3305 + reboot_to_good $sleep_time;
2967 3306 }
2968 3307  
2969 3308 success $i;
2970 3309  
2971 3310  
... ... @@ -2985,13 +3324,27 @@
2985 3324 }
2986 3325  
2987 3326 if (! -f $ktest_config) {
  3327 + $newconfig = 1;
  3328 + get_test_case;
2988 3329 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2989 3330 print OUT << "EOF"
2990 3331 # Generated by ktest.pl
2991 3332 #
  3333 +
  3334 +# PWD is a ktest.pl variable that will result in the process working
  3335 +# directory that ktest.pl is executed in.
  3336 +
  3337 +# THIS_DIR is automatically assigned the PWD of the path that generated
  3338 +# the config file. It is best to use this variable when assigning other
  3339 +# directory paths within this directory. This allows you to easily
  3340 +# move the test cases to other locations or to other machines.
  3341 +#
  3342 +THIS_DIR := $variable{"PWD"}
  3343 +
2992 3344 # Define each test with TEST_START
2993 3345 # The config options below it will override the defaults
2994 3346 TEST_START
  3347 +TEST_TYPE = $default{"TEST_TYPE"}
2995 3348  
2996 3349 DEFAULTS
2997 3350 EOF
... ... @@ -3011,7 +3364,7 @@
3011 3364 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3012 3365 foreach my $config (@new_configs) {
3013 3366 print OUT "$config = $entered_configs{$config}\n";
3014   - $opt{$config} = $entered_configs{$config};
  3367 + $opt{$config} = process_variables($entered_configs{$config});
3015 3368 }
3016 3369 }
3017 3370  
... ... @@ -3091,61 +3444,10 @@
3091 3444  
3092 3445 my $makecmd = set_test_option("MAKE_CMD", $i);
3093 3446  
3094   - $machine = set_test_option("MACHINE", $i);
3095   - $ssh_user = set_test_option("SSH_USER", $i);
3096   - $tmpdir = set_test_option("TMP_DIR", $i);
3097   - $outputdir = set_test_option("OUTPUT_DIR", $i);
3098   - $builddir = set_test_option("BUILD_DIR", $i);
3099   - $test_type = set_test_option("TEST_TYPE", $i);
3100   - $build_type = set_test_option("BUILD_TYPE", $i);
3101   - $build_options = set_test_option("BUILD_OPTIONS", $i);
3102   - $pre_build = set_test_option("PRE_BUILD", $i);
3103   - $post_build = set_test_option("POST_BUILD", $i);
3104   - $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3105   - $post_build_die = set_test_option("POST_BUILD_DIE", $i);
3106   - $power_cycle = set_test_option("POWER_CYCLE", $i);
3107   - $reboot = set_test_option("REBOOT", $i);
3108   - $noclean = set_test_option("BUILD_NOCLEAN", $i);
3109   - $minconfig = set_test_option("MIN_CONFIG", $i);
3110   - $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3111   - $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3112   - $ignore_config = set_test_option("IGNORE_CONFIG", $i);
3113   - $run_test = set_test_option("TEST", $i);
3114   - $addconfig = set_test_option("ADD_CONFIG", $i);
3115   - $reboot_type = set_test_option("REBOOT_TYPE", $i);
3116   - $grub_menu = set_test_option("GRUB_MENU", $i);
3117   - $post_install = set_test_option("POST_INSTALL", $i);
3118   - $no_install = set_test_option("NO_INSTALL", $i);
3119   - $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3120   - $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3121   - $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3122   - $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3123   - $power_off = set_test_option("POWER_OFF", $i);
3124