]> Pileus Git - ~andy/linux/blobdiff - tools/testing/ktest/ktest.pl
ktest: Add CONFIG_BISECT_GOOD option
[~andy/linux] / tools / testing / ktest / ktest.pl
index 1fd29b2daa9204fff6e345c8871799dcb0e04e5e..dbc02de93e59f06d76cc5121b8baeea26396b44c 100755 (executable)
@@ -41,6 +41,7 @@ $default{"CLEAR_LOG"}         = 0;
 $default{"BISECT_MANUAL"}      = 0;
 $default{"BISECT_SKIP"}                = 1;
 $default{"SUCCESS_LINE"}       = "login:";
+$default{"DETECT_TRIPLE_FAULT"} = 1;
 $default{"BOOTED_TIMEOUT"}     = 1;
 $default{"DIE_ON_FAILURE"}     = 1;
 $default{"SSH_EXEC"}           = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
@@ -87,6 +88,7 @@ my $bisect_bad = "";
 my $reverse_bisect;
 my $bisect_manual;
 my $bisect_skip;
+my $config_bisect_good;
 my $in_patchcheck = 0;
 my $run_test;
 my $redirect;
@@ -101,6 +103,7 @@ my $patchcheck_sleep_time;
 my $store_failures;
 my $timeout;
 my $booted_timeout;
+my $detect_triplefault;
 my $console;
 my $success_line;
 my $stop_after_success;
@@ -788,7 +791,7 @@ sub wait_for_input
 
 sub reboot_to {
     if ($reboot_type eq "grub") {
-       run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
+       run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
        return;
     }
 
@@ -836,17 +839,26 @@ sub monitor {
     my $failure_start;
     my $monitor_start = time;
     my $done = 0;
+    my $version_found = 0;
 
     while (!$done) {
 
        if ($booted) {
            $line = wait_for_input($monitor_fp, $booted_timeout);
+           if (!defined($line)) {
+               my $s = $booted_timeout == 1 ? "" : "s";
+               doprint "Successful boot found: break after $booted_timeout second$s\n";
+               last;
+           }
        } else {
            $line = wait_for_input($monitor_fp);
+           if (!defined($line)) {
+               my $s = $timeout == 1 ? "" : "s";
+               doprint "Timed out after $timeout second$s\n";
+               last;
+           }
        }
 
-       last if (!defined($line));
-
        doprint $line;
        print DMESG $line;
 
@@ -896,6 +908,22 @@ sub monitor {
            $bug = 1;
        }
 
+       # Detect triple faults by testing the banner
+       if ($full_line =~ /\bLinux version (\S+).*\n/) {
+           if ($1 eq $version) {
+               $version_found = 1;
+           } elsif ($version_found && $detect_triplefault) {
+               # We already booted into the kernel we are testing,
+               # but now we booted into another kernel?
+               # Consider this a triple fault.
+               doprint "Aleady booted in Linux kernel $version, but now\n";
+               doprint "we booted into Linux kernel $1.\n";
+               doprint "Assuming that this is a triple fault.\n";
+               doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
+               last;
+           }
+       }
+
        if ($line =~ /\n/) {
            $full_line = "";
        }
@@ -1480,7 +1508,7 @@ sub process_config_ignore {
        or dodie "Failed to read $config";
 
     while (<IN>) {
-       if (/^(.*?(CONFIG\S*)(=.*| is not set))/) {
+       if (/^((CONFIG\S*)=.*)/) {
            $config_ignore{$2} = $1;
        }
     }
@@ -1638,7 +1666,7 @@ sub run_config_bisect {
        if (!$found) {
            # try the other half
            doprint "Top half produced no set configs, trying bottom half\n";
-           @tophalf = @start_list[$half .. $#start_list];
+           @tophalf = @start_list[$half + 1 .. $#start_list];
            create_config @tophalf;
            read_current_config \%current_config;
            foreach my $config (@tophalf) {
@@ -1690,7 +1718,7 @@ sub run_config_bisect {
        # remove half the configs we are looking at and see if
        # they are good.
        $half = int($#start_list / 2);
-    } while ($half > 0);
+    } while ($#start_list > 0);
 
     # we found a single config, try it again unless we are running manually
 
@@ -1718,6 +1746,10 @@ sub config_bisect {
 
     my $tmpconfig = "$tmpdir/use_config";
 
+    if (defined($config_bisect_good)) {
+       process_config_ignore $config_bisect_good;
+    }
+
     # Make the file with the bad config and the min config
     if (defined($minconfig)) {
        # read the min config for things to ignore
@@ -2147,10 +2179,12 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
     $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
     $bisect_manual = set_test_option("BISECT_MANUAL", $i);
     $bisect_skip = set_test_option("BISECT_SKIP", $i);
+    $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
     $store_failures = set_test_option("STORE_FAILURES", $i);
     $timeout = set_test_option("TIMEOUT", $i);
     $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
     $console = set_test_option("CONSOLE", $i);
+    $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
     $success_line = set_test_option("SUCCESS_LINE", $i);
     $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
     $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);