aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-11-08 18:41:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-08 18:41:10 -0500
commit98393b8ff2ca98b5b984e73a291b81b326e25184 (patch)
treeeebde91713a68c633a322cce66821b67c434d4b9 /tools
parent3b7546211d53f600e15ca7867adbf3c085b8ecc9 (diff)
parent815e2bd7d609da9c7615ea28a3990064a394312f (diff)
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: (21 commits) ktest: Evaluate variables entered on the command line ktest: Add variable ${PWD} ktest: Add another monitor flush before installing kernel ktest: Do not opencode reboot in grub setting ktest: Add processing of complex conditionals ktest: Fix parsing of config section lines ktest: Sort make_min_config configs by dependecies ktest: Add DEFINED keyword for IF statements ktest: Add OVERRIDE keyword to DEFAULTS section ktest: Consolidate TEST_TYPE and DEFAULT code ktest: Add INCLUDE keyword to include other config files ktest: Let IF keyword take comparisons ktest: Add IF and ELSE to config sections ktest: Do not reboot on config or build issues ktest: Add option REBOOT_SUCCESS_LINE to stop waiting after a reboot ktest: Add NO_INSTALL option to not install for a test ktest: Fail when grub menu not found ktest: Include monitor in reboot code ktest: Only need to save .config when doing mrproper ktest: Create outputdir if it does not exist ...
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/ktest/ktest.pl515
-rw-r--r--tools/testing/ktest/sample.conf146
2 files changed, 553 insertions, 108 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8d02ccb10c59..30e2befd6f2a 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -42,6 +42,7 @@ $default{"BISECT_MANUAL"} = 0;
42$default{"BISECT_SKIP"} = 1; 42$default{"BISECT_SKIP"} = 1;
43$default{"SUCCESS_LINE"} = "login:"; 43$default{"SUCCESS_LINE"} = "login:";
44$default{"DETECT_TRIPLE_FAULT"} = 1; 44$default{"DETECT_TRIPLE_FAULT"} = 1;
45$default{"NO_INSTALL"} = 0;
45$default{"BOOTED_TIMEOUT"} = 1; 46$default{"BOOTED_TIMEOUT"} = 1;
46$default{"DIE_ON_FAILURE"} = 1; 47$default{"DIE_ON_FAILURE"} = 1;
47$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND"; 48$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
@@ -84,6 +85,7 @@ my $grub_number;
84my $target; 85my $target;
85my $make; 86my $make;
86my $post_install; 87my $post_install;
88my $no_install;
87my $noclean; 89my $noclean;
88my $minconfig; 90my $minconfig;
89my $start_minconfig; 91my $start_minconfig;
@@ -115,6 +117,7 @@ my $timeout;
115my $booted_timeout; 117my $booted_timeout;
116my $detect_triplefault; 118my $detect_triplefault;
117my $console; 119my $console;
120my $reboot_success_line;
118my $success_line; 121my $success_line;
119my $stop_after_success; 122my $stop_after_success;
120my $stop_after_failure; 123my $stop_after_failure;
@@ -130,6 +133,12 @@ my %config_help;
130my %variable; 133my %variable;
131my %force_config; 134my %force_config;
132 135
136# do not force reboots on config problems
137my $no_reboot = 1;
138
139# default variables that can be used
140chomp ($variable{"PWD"} = `pwd`);
141
133$config_help{"MACHINE"} = << "EOF" 142$config_help{"MACHINE"} = << "EOF"
134 The machine hostname that you will test. 143 The machine hostname that you will test.
135EOF 144EOF
@@ -241,6 +250,7 @@ sub read_yn {
241 250
242sub get_ktest_config { 251sub get_ktest_config {
243 my ($config) = @_; 252 my ($config) = @_;
253 my $ans;
244 254
245 return if (defined($opt{$config})); 255 return if (defined($opt{$config}));
246 256
@@ -254,16 +264,17 @@ sub get_ktest_config {
254 if (defined($default{$config})) { 264 if (defined($default{$config})) {
255 print "\[$default{$config}\] "; 265 print "\[$default{$config}\] ";
256 } 266 }
257 $entered_configs{$config} = <STDIN>; 267 $ans = <STDIN>;
258 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/; 268 $ans =~ s/^\s*(.*\S)\s*$/$1/;
259 if ($entered_configs{$config} =~ /^\s*$/) { 269 if ($ans =~ /^\s*$/) {
260 if ($default{$config}) { 270 if ($default{$config}) {
261 $entered_configs{$config} = $default{$config}; 271 $ans = $default{$config};
262 } else { 272 } else {
263 print "Your answer can not be blank\n"; 273 print "Your answer can not be blank\n";
264 next; 274 next;
265 } 275 }
266 } 276 }
277 $entered_configs{$config} = process_variables($ans);
267 last; 278 last;
268 } 279 }
269} 280}
@@ -298,7 +309,7 @@ sub get_ktest_configs {
298} 309}
299 310
300sub process_variables { 311sub process_variables {
301 my ($value) = @_; 312 my ($value, $remove_undef) = @_;
302 my $retval = ""; 313 my $retval = "";
303 314
304 # We want to check for '\', and it is just easier 315 # We want to check for '\', and it is just easier
@@ -316,6 +327,10 @@ sub process_variables {
316 $retval = "$retval$begin"; 327 $retval = "$retval$begin";
317 if (defined($variable{$var})) { 328 if (defined($variable{$var})) {
318 $retval = "$retval$variable{$var}"; 329 $retval = "$retval$variable{$var}";
330 } elsif (defined($remove_undef) && $remove_undef) {
331 # for if statements, any variable that is not defined,
332 # we simple convert to 0
333 $retval = "${retval}0";
319 } else { 334 } else {
320 # put back the origin piece. 335 # put back the origin piece.
321 $retval = "$retval\$\{$var\}"; 336 $retval = "$retval\$\{$var\}";
@@ -331,10 +346,17 @@ sub process_variables {
331} 346}
332 347
333sub set_value { 348sub set_value {
334 my ($lvalue, $rvalue) = @_; 349 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
335 350
336 if (defined($opt{$lvalue})) { 351 if (defined($opt{$lvalue})) {
337 die "Error: Option $lvalue defined more than once!\n"; 352 if (!$override || defined(${$overrides}{$lvalue})) {
353 my $extra = "";
354 if ($override) {
355 $extra = "In the same override section!\n";
356 }
357 die "$name: $.: Option $lvalue defined more than once!\n$extra";
358 }
359 ${$overrides}{$lvalue} = $rvalue;
338 } 360 }
339 if ($rvalue =~ /^\s*$/) { 361 if ($rvalue =~ /^\s*$/) {
340 delete $opt{$lvalue}; 362 delete $opt{$lvalue};
@@ -355,86 +377,274 @@ sub set_variable {
355 } 377 }
356} 378}
357 379
358sub read_config { 380sub process_compare {
359 my ($config) = @_; 381 my ($lval, $cmp, $rval) = @_;
382
383 # remove whitespace
384
385 $lval =~ s/^\s*//;
386 $lval =~ s/\s*$//;
387
388 $rval =~ s/^\s*//;
389 $rval =~ s/\s*$//;
390
391 if ($cmp eq "==") {
392 return $lval eq $rval;
393 } elsif ($cmp eq "!=") {
394 return $lval ne $rval;
395 }
396
397 my $statement = "$lval $cmp $rval";
398 my $ret = eval $statement;
399
400 # $@ stores error of eval
401 if ($@) {
402 return -1;
403 }
404
405 return $ret;
406}
407
408sub value_defined {
409 my ($val) = @_;
410
411 return defined($variable{$2}) ||
412 defined($opt{$2});
413}
414
415my $d = 0;
416sub process_expression {
417 my ($name, $val) = @_;
418
419 my $c = $d++;
420
421 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
422 my $express = $1;
423
424 if (process_expression($name, $express)) {
425 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
426 } else {
427 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
428 }
429 }
430
431 $d--;
432 my $OR = "\\|\\|";
433 my $AND = "\\&\\&";
434
435 while ($val =~ s/^(.*?)($OR|$AND)//) {
436 my $express = $1;
437 my $op = $2;
438
439 if (process_expression($name, $express)) {
440 if ($op eq "||") {
441 return 1;
442 }
443 } else {
444 if ($op eq "&&") {
445 return 0;
446 }
447 }
448 }
449
450 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
451 my $ret = process_compare($1, $2, $3);
452 if ($ret < 0) {
453 die "$name: $.: Unable to process comparison\n";
454 }
455 return $ret;
456 }
457
458 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
459 if (defined $1) {
460 return !value_defined($2);
461 } else {
462 return value_defined($2);
463 }
464 }
465
466 if ($val =~ /^\s*0\s*$/) {
467 return 0;
468 } elsif ($val =~ /^\s*\d+\s*$/) {
469 return 1;
470 }
471
472 die ("$name: $.: Undefined content $val in if statement\n");
473}
474
475sub process_if {
476 my ($name, $value) = @_;
477
478 # Convert variables and replace undefined ones with 0
479 my $val = process_variables($value, 1);
480 my $ret = process_expression $name, $val;
481
482 return $ret;
483}
360 484
361 open(IN, $config) || die "can't read file $config"; 485sub __read_config {
486 my ($config, $current_test_num) = @_;
487
488 my $in;
489 open($in, $config) || die "can't read file $config";
362 490
363 my $name = $config; 491 my $name = $config;
364 $name =~ s,.*/(.*),$1,; 492 $name =~ s,.*/(.*),$1,;
365 493
366 my $test_num = 0; 494 my $test_num = $$current_test_num;
367 my $default = 1; 495 my $default = 1;
368 my $repeat = 1; 496 my $repeat = 1;
369 my $num_tests_set = 0; 497 my $num_tests_set = 0;
370 my $skip = 0; 498 my $skip = 0;
371 my $rest; 499 my $rest;
500 my $line;
372 my $test_case = 0; 501 my $test_case = 0;
502 my $if = 0;
503 my $if_set = 0;
504 my $override = 0;
373 505
374 while (<IN>) { 506 my %overrides;
507
508 while (<$in>) {
375 509
376 # ignore blank lines and comments 510 # ignore blank lines and comments
377 next if (/^\s*$/ || /\s*\#/); 511 next if (/^\s*$/ || /\s*\#/);
378 512
379 if (/^\s*TEST_START(.*)/) { 513 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
380 514
381 $rest = $1; 515 my $type = $1;
516 $rest = $2;
517 $line = $2;
382 518
383 if ($num_tests_set) { 519 my $old_test_num;
384 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; 520 my $old_repeat;
385 } 521 $override = 0;
522
523 if ($type eq "TEST_START") {
524
525 if ($num_tests_set) {
526 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
527 }
386 528
387 my $old_test_num = $test_num; 529 $old_test_num = $test_num;
388 my $old_repeat = $repeat; 530 $old_repeat = $repeat;
389 531
390 $test_num += $repeat; 532 $test_num += $repeat;
391 $default = 0; 533 $default = 0;
392 $repeat = 1; 534 $repeat = 1;
535 } else {
536 $default = 1;
537 }
393 538
394 if ($rest =~ /\s+SKIP(.*)/) { 539 # If SKIP is anywhere in the line, the command will be skipped
395 $rest = $1; 540 if ($rest =~ s/\s+SKIP\b//) {
396 $skip = 1; 541 $skip = 1;
397 } else { 542 } else {
398 $test_case = 1; 543 $test_case = 1;
399 $skip = 0; 544 $skip = 0;
400 } 545 }
401 546
402 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) { 547 if ($rest =~ s/\sELSE\b//) {
403 $repeat = $1; 548 if (!$if) {
404 $rest = $2; 549 die "$name: $.: ELSE found with out matching IF section\n$_";
405 $repeat_tests{"$test_num"} = $repeat; 550 }
551 $if = 0;
552
553 if ($if_set) {
554 $skip = 1;
555 } else {
556 $skip = 0;
557 }
406 } 558 }
407 559
408 if ($rest =~ /\s+SKIP(.*)/) { 560 if ($rest =~ s/\sIF\s+(.*)//) {
409 $rest = $1; 561 if (process_if($name, $1)) {
410 $skip = 1; 562 $if_set = 1;
563 } else {
564 $skip = 1;
565 }
566 $if = 1;
567 } else {
568 $if = 0;
569 $if_set = 0;
411 } 570 }
412 571
413 if ($rest !~ /^\s*$/) { 572 if (!$skip) {
414 die "$name: $.: Gargbage found after TEST_START\n$_"; 573 if ($type eq "TEST_START") {
574 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
575 $repeat = $1;
576 $repeat_tests{"$test_num"} = $repeat;
577 }
578 } elsif ($rest =~ s/\sOVERRIDE\b//) {
579 # DEFAULT only
580 $override = 1;
581 # Clear previous overrides
582 %overrides = ();
583 }
584 }
585
586 if (!$skip && $rest !~ /^\s*$/) {
587 die "$name: $.: Gargbage found after $type\n$_";
415 } 588 }
416 589
417 if ($skip) { 590 if ($skip && $type eq "TEST_START") {
418 $test_num = $old_test_num; 591 $test_num = $old_test_num;
419 $repeat = $old_repeat; 592 $repeat = $old_repeat;
420 } 593 }
421 594
422 } elsif (/^\s*DEFAULTS(.*)$/) { 595 } elsif (/^\s*ELSE\b(.*)$/) {
423 $default = 1; 596 if (!$if) {
424 597 die "$name: $.: ELSE found with out matching IF section\n$_";
598 }
425 $rest = $1; 599 $rest = $1;
426 600 if ($if_set) {
427 if ($rest =~ /\s+SKIP(.*)/) {
428 $rest = $1;
429 $skip = 1; 601 $skip = 1;
602 $rest = "";
430 } else { 603 } else {
431 $skip = 0; 604 $skip = 0;
605
606 if ($rest =~ /\sIF\s+(.*)/) {
607 # May be a ELSE IF section.
608 if (!process_if($name, $1)) {
609 $skip = 1;
610 }
611 $rest = "";
612 } else {
613 $if = 0;
614 }
432 } 615 }
433 616
434 if ($rest !~ /^\s*$/) { 617 if ($rest !~ /^\s*$/) {
435 die "$name: $.: Gargbage found after DEFAULTS\n$_"; 618 die "$name: $.: Gargbage found after DEFAULTS\n$_";
436 } 619 }
437 620
621 } elsif (/^\s*INCLUDE\s+(\S+)/) {
622
623 next if ($skip);
624
625 if (!$default) {
626 die "$name: $.: INCLUDE can only be done in default sections\n$_";
627 }
628
629 my $file = process_variables($1);
630
631 if ($file !~ m,^/,) {
632 # check the path of the config file first
633 if ($config =~ m,(.*)/,) {
634 if (-f "$1/$file") {
635 $file = "$1/$file";
636 }
637 }
638 }
639
640 if ( ! -r $file ) {
641 die "$name: $.: Can't read file $file\n$_";
642 }
643
644 if (__read_config($file, \$test_num)) {
645 $test_case = 1;
646 }
647
438 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { 648 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
439 649
440 next if ($skip); 650 next if ($skip);
@@ -460,10 +670,10 @@ sub read_config {
460 } 670 }
461 671
462 if ($default || $lvalue =~ /\[\d+\]$/) { 672 if ($default || $lvalue =~ /\[\d+\]$/) {
463 set_value($lvalue, $rvalue); 673 set_value($lvalue, $rvalue, $override, \%overrides, $name);
464 } else { 674 } else {
465 my $val = "$lvalue\[$test_num\]"; 675 my $val = "$lvalue\[$test_num\]";
466 set_value($val, $rvalue); 676 set_value($val, $rvalue, $override, \%overrides, $name);
467 677
468 if ($repeat > 1) { 678 if ($repeat > 1) {
469 $repeats{$val} = $repeat; 679 $repeats{$val} = $repeat;
@@ -490,13 +700,26 @@ sub read_config {
490 } 700 }
491 } 701 }
492 702
493 close(IN);
494
495 if ($test_num) { 703 if ($test_num) {
496 $test_num += $repeat - 1; 704 $test_num += $repeat - 1;
497 $opt{"NUM_TESTS"} = $test_num; 705 $opt{"NUM_TESTS"} = $test_num;
498 } 706 }
499 707
708 close($in);
709
710 $$current_test_num = $test_num;
711
712 return $test_case;
713}
714
715sub read_config {
716 my ($config) = @_;
717
718 my $test_case;
719 my $test_num = 0;
720
721 $test_case = __read_config $config, \$test_num;
722
500 # make sure we have all mandatory configs 723 # make sure we have all mandatory configs
501 get_ktest_configs; 724 get_ktest_configs;
502 725
@@ -603,8 +826,20 @@ sub doprint {
603} 826}
604 827
605sub run_command; 828sub run_command;
829sub start_monitor;
830sub end_monitor;
831sub wait_for_monitor;
606 832
607sub reboot { 833sub reboot {
834 my ($time) = @_;
835
836 if (defined($time)) {
837 start_monitor;
838 # flush out current monitor
839 # May contain the reboot success line
840 wait_for_monitor 1;
841 }
842
608 # try to reboot normally 843 # try to reboot normally
609 if (run_command $reboot) { 844 if (run_command $reboot) {
610 if (defined($powercycle_after_reboot)) { 845 if (defined($powercycle_after_reboot)) {
@@ -615,12 +850,17 @@ sub reboot {
615 # nope? power cycle it. 850 # nope? power cycle it.
616 run_command "$power_cycle"; 851 run_command "$power_cycle";
617 } 852 }
853
854 if (defined($time)) {
855 wait_for_monitor($time, $reboot_success_line);
856 end_monitor;
857 }
618} 858}
619 859
620sub do_not_reboot { 860sub do_not_reboot {
621 my $i = $iteration; 861 my $i = $iteration;
622 862
623 return $test_type eq "build" || 863 return $test_type eq "build" || $no_reboot ||
624 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") || 864 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
625 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build"); 865 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
626} 866}
@@ -693,16 +933,29 @@ sub end_monitor {
693} 933}
694 934
695sub wait_for_monitor { 935sub wait_for_monitor {
696 my ($time) = @_; 936 my ($time, $stop) = @_;
937 my $full_line = "";
697 my $line; 938 my $line;
939 my $booted = 0;
698 940
699 doprint "** Wait for monitor to settle down **\n"; 941 doprint "** Wait for monitor to settle down **\n";
700 942
701 # read the monitor and wait for the system to calm down 943 # read the monitor and wait for the system to calm down
702 do { 944 while (!$booted) {
703 $line = wait_for_input($monitor_fp, $time); 945 $line = wait_for_input($monitor_fp, $time);
704 print "$line" if (defined($line)); 946 last if (!defined($line));
705 } while (defined($line)); 947 print "$line";
948 $full_line .= $line;
949
950 if (defined($stop) && $full_line =~ /$stop/) {
951 doprint "wait for monitor detected $stop\n";
952 $booted = 1;
953 }
954
955 if ($line =~ /\n/) {
956 $full_line = "";
957 }
958 }
706 print "** Monitor flushed **\n"; 959 print "** Monitor flushed **\n";
707} 960}
708 961
@@ -719,10 +972,7 @@ sub fail {
719 # no need to reboot for just building. 972 # no need to reboot for just building.
720 if (!do_not_reboot) { 973 if (!do_not_reboot) {
721 doprint "REBOOTING\n"; 974 doprint "REBOOTING\n";
722 reboot; 975 reboot $sleep_time;
723 start_monitor;
724 wait_for_monitor $sleep_time;
725 end_monitor;
726 } 976 }
727 977
728 my $name = ""; 978 my $name = "";
@@ -854,9 +1104,12 @@ sub get_grub_index {
854 open(IN, "$ssh_grub |") 1104 open(IN, "$ssh_grub |")
855 or die "unable to get menu.lst"; 1105 or die "unable to get menu.lst";
856 1106
1107 my $found = 0;
1108
857 while (<IN>) { 1109 while (<IN>) {
858 if (/^\s*title\s+$grub_menu\s*$/) { 1110 if (/^\s*title\s+$grub_menu\s*$/) {
859 $grub_number++; 1111 $grub_number++;
1112 $found = 1;
860 last; 1113 last;
861 } elsif (/^\s*title\s/) { 1114 } elsif (/^\s*title\s/) {
862 $grub_number++; 1115 $grub_number++;
@@ -865,7 +1118,7 @@ sub get_grub_index {
865 close(IN); 1118 close(IN);
866 1119
867 die "Could not find '$grub_menu' in /boot/grub/menu on $machine" 1120 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
868 if ($grub_number < 0); 1121 if (!$found);
869 doprint "$grub_number\n"; 1122 doprint "$grub_number\n";
870} 1123}
871 1124
@@ -902,7 +1155,8 @@ sub wait_for_input
902 1155
903sub reboot_to { 1156sub reboot_to {
904 if ($reboot_type eq "grub") { 1157 if ($reboot_type eq "grub") {
905 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'"; 1158 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1159 reboot;
906 return; 1160 return;
907 } 1161 }
908 1162
@@ -1083,6 +1337,8 @@ sub do_post_install {
1083 1337
1084sub install { 1338sub install {
1085 1339
1340 return if ($no_install);
1341
1086 run_scp "$outputdir/$build_target", "$target_image" or 1342 run_scp "$outputdir/$build_target", "$target_image" or
1087 dodie "failed to copy image"; 1343 dodie "failed to copy image";
1088 1344
@@ -1140,6 +1396,11 @@ sub get_version {
1140} 1396}
1141 1397
1142sub start_monitor_and_boot { 1398sub start_monitor_and_boot {
1399 # Make sure the stable kernel has finished booting
1400 start_monitor;
1401 wait_for_monitor 5;
1402 end_monitor;
1403
1143 get_grub_index; 1404 get_grub_index;
1144 get_version; 1405 get_version;
1145 install; 1406 install;
@@ -1250,6 +1511,10 @@ sub build {
1250 1511
1251 unlink $buildlog; 1512 unlink $buildlog;
1252 1513
1514 # Failed builds should not reboot the target
1515 my $save_no_reboot = $no_reboot;
1516 $no_reboot = 1;
1517
1253 if (defined($pre_build)) { 1518 if (defined($pre_build)) {
1254 my $ret = run_command $pre_build; 1519 my $ret = run_command $pre_build;
1255 if (!$ret && defined($pre_build_die) && 1520 if (!$ret && defined($pre_build_die) &&
@@ -1272,15 +1537,15 @@ sub build {
1272 # allow for empty configs 1537 # allow for empty configs
1273 run_command "touch $output_config"; 1538 run_command "touch $output_config";
1274 1539
1275 run_command "mv $output_config $outputdir/config_temp" or 1540 if (!$noclean) {
1276 dodie "moving .config"; 1541 run_command "mv $output_config $outputdir/config_temp" or
1542 dodie "moving .config";
1277 1543
1278 if (!$noclean && !run_command "$make mrproper") { 1544 run_command "$make mrproper" or dodie "make mrproper";
1279 dodie "make mrproper";
1280 }
1281 1545
1282 run_command "mv $outputdir/config_temp $output_config" or 1546 run_command "mv $outputdir/config_temp $output_config" or
1283 dodie "moving config_temp"; 1547 dodie "moving config_temp";
1548 }
1284 1549
1285 } elsif (!$noclean) { 1550 } elsif (!$noclean) {
1286 unlink "$output_config"; 1551 unlink "$output_config";
@@ -1318,10 +1583,15 @@ sub build {
1318 1583
1319 if (!$build_ret) { 1584 if (!$build_ret) {
1320 # bisect may need this to pass 1585 # bisect may need this to pass
1321 return 0 if ($in_bisect); 1586 if ($in_bisect) {
1587 $no_reboot = $save_no_reboot;
1588 return 0;
1589 }
1322 fail "failed build" and return 0; 1590 fail "failed build" and return 0;
1323 } 1591 }
1324 1592
1593 $no_reboot = $save_no_reboot;
1594
1325 return 1; 1595 return 1;
1326} 1596}
1327 1597
@@ -1356,10 +1626,7 @@ sub success {
1356 1626
1357 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { 1627 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1358 doprint "Reboot and wait $sleep_time seconds\n"; 1628 doprint "Reboot and wait $sleep_time seconds\n";
1359 reboot; 1629 reboot $sleep_time;
1360 start_monitor;
1361 wait_for_monitor $sleep_time;
1362 end_monitor;
1363 } 1630 }
1364} 1631}
1365 1632
@@ -1500,10 +1767,7 @@ sub run_git_bisect {
1500 1767
1501sub bisect_reboot { 1768sub bisect_reboot {
1502 doprint "Reboot and sleep $bisect_sleep_time seconds\n"; 1769 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1503 reboot; 1770 reboot $bisect_sleep_time;
1504 start_monitor;
1505 wait_for_monitor $bisect_sleep_time;
1506 end_monitor;
1507} 1771}
1508 1772
1509# returns 1 on success, 0 on failure, -1 on skip 1773# returns 1 on success, 0 on failure, -1 on skip
@@ -2066,10 +2330,7 @@ sub config_bisect {
2066 2330
2067sub patchcheck_reboot { 2331sub patchcheck_reboot {
2068 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n"; 2332 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2069 reboot; 2333 reboot $patchcheck_sleep_time;
2070 start_monitor;
2071 wait_for_monitor $patchcheck_sleep_time;
2072 end_monitor;
2073} 2334}
2074 2335
2075sub patchcheck { 2336sub patchcheck {
@@ -2178,12 +2439,31 @@ sub patchcheck {
2178} 2439}
2179 2440
2180my %depends; 2441my %depends;
2442my %depcount;
2181my $iflevel = 0; 2443my $iflevel = 0;
2182my @ifdeps; 2444my @ifdeps;
2183 2445
2184# prevent recursion 2446# prevent recursion
2185my %read_kconfigs; 2447my %read_kconfigs;
2186 2448
2449sub add_dep {
2450 # $config depends on $dep
2451 my ($config, $dep) = @_;
2452
2453 if (defined($depends{$config})) {
2454 $depends{$config} .= " " . $dep;
2455 } else {
2456 $depends{$config} = $dep;
2457 }
2458
2459 # record the number of configs depending on $dep
2460 if (defined $depcount{$dep}) {
2461 $depcount{$dep}++;
2462 } else {
2463 $depcount{$dep} = 1;
2464 }
2465}
2466
2187# taken from streamline_config.pl 2467# taken from streamline_config.pl
2188sub read_kconfig { 2468sub read_kconfig {
2189 my ($kconfig) = @_; 2469 my ($kconfig) = @_;
@@ -2230,30 +2510,19 @@ sub read_kconfig {
2230 $config = $2; 2510 $config = $2;
2231 2511
2232 for (my $i = 0; $i < $iflevel; $i++) { 2512 for (my $i = 0; $i < $iflevel; $i++) {
2233 if ($i) { 2513 add_dep $config, $ifdeps[$i];
2234 $depends{$config} .= " " . $ifdeps[$i];
2235 } else {
2236 $depends{$config} = $ifdeps[$i];
2237 }
2238 $state = "DEP";
2239 } 2514 }
2240 2515
2241 # collect the depends for the config 2516 # collect the depends for the config
2242 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) { 2517 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2243 2518
2244 if (defined($depends{$1})) { 2519 add_dep $config, $1;
2245 $depends{$config} .= " " . $1;
2246 } else {
2247 $depends{$config} = $1;
2248 }
2249 2520
2250 # Get the configs that select this config 2521 # Get the configs that select this config
2251 } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) { 2522 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2252 if (defined($depends{$1})) { 2523
2253 $depends{$1} .= " " . $config; 2524 # selected by depends on config
2254 } else { 2525 add_dep $1, $config;
2255 $depends{$1} = $config;
2256 }
2257 2526
2258 # Check for if statements 2527 # Check for if statements
2259 } elsif (/^if\s+(.*\S)\s*$/) { 2528 } elsif (/^if\s+(.*\S)\s*$/) {
@@ -2365,11 +2634,18 @@ sub make_new_config {
2365 close OUT; 2634 close OUT;
2366} 2635}
2367 2636
2637sub chomp_config {
2638 my ($config) = @_;
2639
2640 $config =~ s/CONFIG_//;
2641
2642 return $config;
2643}
2644
2368sub get_depends { 2645sub get_depends {
2369 my ($dep) = @_; 2646 my ($dep) = @_;
2370 2647
2371 my $kconfig = $dep; 2648 my $kconfig = chomp_config $dep;
2372 $kconfig =~ s/CONFIG_//;
2373 2649
2374 $dep = $depends{"$kconfig"}; 2650 $dep = $depends{"$kconfig"};
2375 2651
@@ -2419,8 +2695,7 @@ sub test_this_config {
2419 return undef; 2695 return undef;
2420 } 2696 }
2421 2697
2422 my $kconfig = $config; 2698 my $kconfig = chomp_config $config;
2423 $kconfig =~ s/CONFIG_//;
2424 2699
2425 # Test dependencies first 2700 # Test dependencies first
2426 if (defined($depends{"$kconfig"})) { 2701 if (defined($depends{"$kconfig"})) {
@@ -2510,6 +2785,14 @@ sub make_min_config {
2510 2785
2511 my @config_keys = keys %min_configs; 2786 my @config_keys = keys %min_configs;
2512 2787
2788 # All configs need a depcount
2789 foreach my $config (@config_keys) {
2790 my $kconfig = chomp_config $config;
2791 if (!defined $depcount{$kconfig}) {
2792 $depcount{$kconfig} = 0;
2793 }
2794 }
2795
2513 # Remove anything that was set by the make allnoconfig 2796 # Remove anything that was set by the make allnoconfig
2514 # we shouldn't need them as they get set for us anyway. 2797 # we shouldn't need them as they get set for us anyway.
2515 foreach my $config (@config_keys) { 2798 foreach my $config (@config_keys) {
@@ -2548,8 +2831,13 @@ sub make_min_config {
2548 # Now disable each config one by one and do a make oldconfig 2831 # Now disable each config one by one and do a make oldconfig
2549 # till we find a config that changes our list. 2832 # till we find a config that changes our list.
2550 2833
2551 # Put configs that did not modify the config at the end.
2552 my @test_configs = keys %min_configs; 2834 my @test_configs = keys %min_configs;
2835
2836 # Sort keys by who is most dependent on
2837 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2838 @test_configs ;
2839
2840 # Put configs that did not modify the config at the end.
2553 my $reset = 1; 2841 my $reset = 1;
2554 for (my $i = 0; $i < $#test_configs; $i++) { 2842 for (my $i = 0; $i < $#test_configs; $i++) {
2555 if (!defined($nochange_config{$test_configs[0]})) { 2843 if (!defined($nochange_config{$test_configs[0]})) {
@@ -2659,10 +2947,7 @@ sub make_min_config {
2659 } 2947 }
2660 2948
2661 doprint "Reboot and wait $sleep_time seconds\n"; 2949 doprint "Reboot and wait $sleep_time seconds\n";
2662 reboot; 2950 reboot $sleep_time;
2663 start_monitor;
2664 wait_for_monitor $sleep_time;
2665 end_monitor;
2666 } 2951 }
2667 2952
2668 success $i; 2953 success $i;
@@ -2783,6 +3068,9 @@ sub set_test_option {
2783# First we need to do is the builds 3068# First we need to do is the builds
2784for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { 3069for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2785 3070
3071 # Do not reboot on failing test options
3072 $no_reboot = 1;
3073
2786 $iteration = $i; 3074 $iteration = $i;
2787 3075
2788 my $makecmd = set_test_option("MAKE_CMD", $i); 3076 my $makecmd = set_test_option("MAKE_CMD", $i);
@@ -2811,6 +3099,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2811 $reboot_type = set_test_option("REBOOT_TYPE", $i); 3099 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2812 $grub_menu = set_test_option("GRUB_MENU", $i); 3100 $grub_menu = set_test_option("GRUB_MENU", $i);
2813 $post_install = set_test_option("POST_INSTALL", $i); 3101 $post_install = set_test_option("POST_INSTALL", $i);
3102 $no_install = set_test_option("NO_INSTALL", $i);
2814 $reboot_script = set_test_option("REBOOT_SCRIPT", $i); 3103 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2815 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i); 3104 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2816 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); 3105 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
@@ -2832,6 +3121,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2832 $console = set_test_option("CONSOLE", $i); 3121 $console = set_test_option("CONSOLE", $i);
2833 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i); 3122 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
2834 $success_line = set_test_option("SUCCESS_LINE", $i); 3123 $success_line = set_test_option("SUCCESS_LINE", $i);
3124 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
2835 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i); 3125 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2836 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i); 3126 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
2837 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i); 3127 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
@@ -2850,9 +3140,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2850 3140
2851 chdir $builddir || die "can't change directory to $builddir"; 3141 chdir $builddir || die "can't change directory to $builddir";
2852 3142
2853 if (!-d $tmpdir) { 3143 foreach my $dir ($tmpdir, $outputdir) {
2854 mkpath($tmpdir) or 3144 if (!-d $dir) {
2855 die "can't create $tmpdir"; 3145 mkpath($dir) or
3146 die "can't create $dir";
3147 }
2856 } 3148 }
2857 3149
2858 $ENV{"SSH_USER"} = $ssh_user; 3150 $ENV{"SSH_USER"} = $ssh_user;
@@ -2889,8 +3181,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2889 $run_type = "ERROR"; 3181 $run_type = "ERROR";
2890 } 3182 }
2891 3183
3184 my $installme = "";
3185 $installme = " no_install" if ($no_install);
3186
2892 doprint "\n\n"; 3187 doprint "\n\n";
2893 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n"; 3188 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
2894 3189
2895 unlink $dmesg; 3190 unlink $dmesg;
2896 unlink $buildlog; 3191 unlink $buildlog;
@@ -2911,6 +3206,9 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2911 die "failed to checkout $checkout"; 3206 die "failed to checkout $checkout";
2912 } 3207 }
2913 3208
3209 $no_reboot = 0;
3210
3211
2914 if ($test_type eq "bisect") { 3212 if ($test_type eq "bisect") {
2915 bisect $i; 3213 bisect $i;
2916 next; 3214 next;
@@ -2929,6 +3227,13 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2929 build $build_type or next; 3227 build $build_type or next;
2930 } 3228 }
2931 3229
3230 if ($test_type eq "install") {
3231 get_version;
3232 install;
3233 success $i;
3234 next;
3235 }
3236
2932 if ($test_type ne "build") { 3237 if ($test_type ne "build") {
2933 my $failed = 0; 3238 my $failed = 0;
2934 start_monitor_and_boot or $failed = 1; 3239 start_monitor_and_boot or $failed = 1;
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index b8bcd14b5a4d..dbedfa196727 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -72,6 +72,128 @@
72# the same option name under the same test or as default 72# the same option name under the same test or as default
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# DEFAULTS OVERRIDE
76#
77# Options defined in the DEFAULTS section can not be duplicated
78# even if they are defined in two different DEFAULT sections.
79# This is done to catch mistakes where an option is added but
80# the previous option was forgotten about and not commented.
81#
82# The OVERRIDE keyword can be added to a section to allow this
83# section to override other DEFAULT sections values that have
84# been defined previously. It will only override options that
85# have been defined before its use. Options defined later
86# in a non override section will still error. The same option
87# can not be defined in the same section even if that section
88# is marked OVERRIDE.
89#
90#
91#
92# Both TEST_START and DEFAULTS sections can also have the IF keyword
93# The value after the IF must evaluate into a 0 or non 0 positive
94# integer, and can use the config variables (explained below).
95#
96# DEFAULTS IF ${IS_X86_32}
97#
98# The above will process the DEFAULTS section if the config
99# variable IS_X86_32 evaluates to a non zero positive integer
100# otherwise if it evaluates to zero, it will act the same
101# as if the SKIP keyword was used.
102#
103# The ELSE keyword can be used directly after a section with
104# a IF statement.
105#
106# TEST_START IF ${RUN_NET_TESTS}
107# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
108#
109# ELSE
110#
111# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-normal
112#
113#
114# The ELSE keyword can also contain an IF statement to allow multiple
115# if then else sections. But all the sections must be either
116# DEFAULT or TEST_START, they can not be a mixture.
117#
118# TEST_START IF ${RUN_NET_TESTS}
119# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
120#
121# ELSE IF ${RUN_DISK_TESTS}
122# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-tests
123#
124# ELSE IF ${RUN_CPU_TESTS}
125# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-cpu
126#
127# ELSE
128# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
129#
130# The if statement may also have comparisons that will and for
131# == and !=, strings may be used for both sides.
132#
133# BOX_TYPE := x86_32
134#
135# DEFAULTS IF ${BOX_TYPE} == x86_32
136# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-32
137# ELSE
138# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-64
139#
140# The DEFINED keyword can be used by the IF statements too.
141# It returns true if the given config variable or option has been defined
142# or false otherwise.
143#
144#
145# DEFAULTS IF DEFINED USE_CC
146# CC := ${USE_CC}
147# ELSE
148# CC := gcc
149#
150#
151# As well as NOT DEFINED.
152#
153# DEFAULTS IF NOT DEFINED MAKE_CMD
154# MAKE_CMD := make ARCH=x86
155#
156#
157# And/or ops (&&,||) may also be used to make complex conditionals.
158#
159# TEST_START IF (DEFINED ALL_TESTS || ${MYTEST} == boottest) && ${MACHINE} == gandalf
160#
161# Notice the use of paranthesis. Without any paranthesis the above would be
162# processed the same as:
163#
164# TEST_START IF DEFINED ALL_TESTS || (${MYTEST} == boottest && ${MACHINE} == gandalf)
165#
166#
167#
168# INCLUDE file
169#
170# The INCLUDE keyword may be used in DEFAULT sections. This will
171# read another config file and process that file as well. The included
172# file can include other files, add new test cases or default
173# statements. Config variables will be passed to these files and changes
174# to config variables will be seen by top level config files. Including
175# a file is processed just like the contents of the file was cut and pasted
176# into the top level file, except, that include files that end with
177# TEST_START sections will have that section ended at the end of
178# the include file. That is, an included file is included followed
179# by another DEFAULT keyword.
180#
181# Unlike other files referenced in this config, the file path does not need
182# to be absolute. If the file does not start with '/', then the directory
183# that the current config file was located in is used. If no config by the
184# given name is found there, then the current directory is searched.
185#
186# INCLUDE myfile
187# DEFAULT
188#
189# is the same as:
190#
191# INCLUDE myfile
192#
193# Note, if the include file does not contain a full path, the file is
194# searched first by the location of the original include file, and then
195# by the location that ktest.pl was executed in.
196#
75 197
76#### Config variables #### 198#### Config variables ####
77# 199#
@@ -253,9 +375,10 @@
253 375
254# The default test type (default test) 376# The default test type (default test)
255# The test types may be: 377# The test types may be:
256# build - only build the kernel, do nothing else 378# build - only build the kernel, do nothing else
257# boot - build and boot the kernel 379# install - build and install, but do nothing else (does not reboot)
258# test - build, boot and if TEST is set, run the test script 380# boot - build, install, and boot the kernel
381# test - build, boot and if TEST is set, run the test script
259# (If TEST is not set, it defaults back to boot) 382# (If TEST is not set, it defaults back to boot)
260# bisect - Perform a bisect on the kernel (see BISECT_TYPE below) 383# bisect - Perform a bisect on the kernel (see BISECT_TYPE below)
261# patchcheck - Do a test on a series of commits in git (see PATCHCHECK below) 384# patchcheck - Do a test on a series of commits in git (see PATCHCHECK below)
@@ -293,6 +416,13 @@
293# or on some systems: 416# or on some systems:
294#POST_INSTALL = ssh user@target /sbin/dracut -f /boot/initramfs-test.img $KERNEL_VERSION 417#POST_INSTALL = ssh user@target /sbin/dracut -f /boot/initramfs-test.img $KERNEL_VERSION
295 418
419# If for some reason you just want to boot the kernel and you do not
420# want the test to install anything new. For example, you may just want
421# to boot test the same kernel over and over and do not want to go through
422# the hassle of installing anything, you can set this option to 1
423# (default 0)
424#NO_INSTALL = 1
425
296# If there is a script that you require to run before the build is done 426# If there is a script that you require to run before the build is done
297# you can specify it with PRE_BUILD. 427# you can specify it with PRE_BUILD.
298# 428#
@@ -415,6 +545,14 @@
415# (default "login:") 545# (default "login:")
416#SUCCESS_LINE = login: 546#SUCCESS_LINE = login:
417 547
548# To speed up between reboots, defining a line that the
549# default kernel produces that represents that the default
550# kernel has successfully booted and can be used to pass
551# a new test kernel to it. Otherwise ktest.pl will wait till
552# SLEEP_TIME to continue.
553# (default undefined)
554#REBOOT_SUCCESS_LINE = login:
555
418# In case the console constantly fills the screen, having 556# In case the console constantly fills the screen, having
419# a specified time to stop the test after success is recommended. 557# a specified time to stop the test after success is recommended.
420# (in seconds) 558# (in seconds)
@@ -480,6 +618,8 @@
480# another test. If a reboot to the reliable kernel happens, 618# another test. If a reboot to the reliable kernel happens,
481# we wait SLEEP_TIME for the console to stop producing output 619# we wait SLEEP_TIME for the console to stop producing output
482# before starting the next test. 620# before starting the next test.
621#
622# You can speed up reboot times even more by setting REBOOT_SUCCESS_LINE.
483# (default 60) 623# (default 60)
484#SLEEP_TIME = 60 624#SLEEP_TIME = 60
485 625