ktest: Add BISECT_SKIP
[deliverable/linux.git] / tools / testing / ktest / ktest.pl
index e1c62eeb88f5f845640b49ddb2fb00313039928e..0f62916a43f71c3222d1b990f977b644eb81966e 100755 (executable)
@@ -37,6 +37,8 @@ $default{"POWEROFF_ON_SUCCESS"}       = 0;
 $default{"BUILD_OPTIONS"}      = "";
 $default{"BISECT_SLEEP_TIME"}  = 60;   # sleep time between bisects
 $default{"CLEAR_LOG"}          = 0;
+$default{"BISECT_MANUAL"}      = 0;
+$default{"BISECT_SKIP"}                = 1;
 $default{"SUCCESS_LINE"}       = "login:";
 $default{"BOOTED_TIMEOUT"}     = 1;
 $default{"DIE_ON_FAILURE"}     = 1;
@@ -81,6 +83,8 @@ my $addconfig;
 my $in_bisect = 0;
 my $bisect_bad = "";
 my $reverse_bisect;
+my $bisect_manual;
+my $bisect_skip;
 my $in_patchcheck = 0;
 my $run_test;
 my $redirect;
@@ -462,6 +466,10 @@ sub dodie {
        `$power_off`;
     }
 
+    if (defined($opt{"LOG_FILE"})) {
+       print " See $opt{LOG_FILE} for more info.\n";
+    }
+
     die @_, "\n";
 }
 
@@ -816,6 +824,7 @@ sub monitor {
        }
 
        if ($full_line =~ /Kernel panic -/) {
+           $failure_start = time;
            $bug = 1;
        }
 
@@ -925,6 +934,18 @@ sub check_buildlog {
     return 1;
 }
 
+sub make_oldconfig {
+    my ($defconfig) = @_;
+
+    if (!run_command "$defconfig $make oldnoconfig") {
+       # Perhaps oldnoconfig doesn't exist in this version of the kernel
+       # try a yes '' | oldconfig
+       doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
+       run_command "yes '' | $defconfig $make oldconfig" or
+           dodie "failed make config oldconfig";
+    }
+}
+
 sub build {
     my ($type) = @_;
     my $defconfig = "";
@@ -970,8 +991,12 @@ sub build {
        $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
     }
 
-    run_command "$defconfig $make $type" or
-       dodie "failed make config";
+    if ($type eq "oldnoconfig") {
+       make_oldconfig $defconfig;
+    } else {
+       run_command "$defconfig $make $type" or
+           dodie "failed make config";
+    }
 
     $redirect = "$buildlog";
     if (!run_command "$make $build_options") {
@@ -1025,6 +1050,21 @@ sub get_version {
     doprint "$version\n";
 }
 
+sub answer_bisect {
+    for (;;) {
+       doprint "Pass or fail? [p/f]";
+       my $ans = <STDIN>;
+       chomp $ans;
+       if ($ans eq "p" || $ans eq "P") {
+           return 1;
+       } elsif ($ans eq "f" || $ans eq "F") {
+           return 0;
+       } else {
+           print "Please answer 'P' or 'F'\n";
+       }
+    }
+}
+
 sub child_run_test {
     my $failed = 0;
 
@@ -1131,7 +1171,15 @@ sub run_git_bisect {
     return 1;
 }
 
-# returns 1 on success, 0 on failure
+sub bisect_reboot {
+    doprint "Reboot and sleep $bisect_sleep_time seconds\n";
+    reboot;
+    start_monitor;
+    wait_for_monitor $bisect_sleep_time;
+    end_monitor;
+}
+
+# returns 1 on success, 0 on failure, -1 on skip
 sub run_bisect_test {
     my ($type, $buildtype) = @_;
 
@@ -1145,6 +1193,10 @@ sub run_bisect_test {
     build $buildtype or $failed = 1;
 
     if ($type ne "build") {
+       if ($failed && $bisect_skip) {
+           $in_bisect = 0;
+           return -1;
+       }
        dodie "Failed on build" if $failed;
 
        # Now boot the box
@@ -1156,6 +1208,12 @@ sub run_bisect_test {
        monitor or $failed = 1;
 
        if ($type ne "boot") {
+           if ($failed && $bisect_skip) {
+               end_monitor;
+               bisect_reboot;
+               $in_bisect = 0;
+               return -1;
+           }
            dodie "Failed on boot" if $failed;
 
            do_run_test or $failed = 1;
@@ -1168,11 +1226,7 @@ sub run_bisect_test {
 
        # reboot the box to a good kernel
        if ($type ne "build") {
-           doprint "Reboot and sleep $bisect_sleep_time seconds\n";
-           reboot;
-           start_monitor;
-           wait_for_monitor $bisect_sleep_time;
-           end_monitor;
+           bisect_reboot;
        }
     } else {
        $result = 1;
@@ -1193,16 +1247,22 @@ sub run_bisect {
 
     my $ret = run_bisect_test $type, $buildtype;
 
+    if ($bisect_manual) {
+       $ret = answer_bisect;
+    }
 
     # Are we looking for where it worked, not failed?
     if ($reverse_bisect) {
        $ret = !$ret;
     }
 
-    if ($ret) {
+    if ($ret > 0) {
        return "good";
-    } else {
+    } elsif ($ret == 0) {
        return  "bad";
+    } elsif ($bisect_skip) {
+       doprint "HIT A BAD COMMIT ... SKIPPING\n";
+       return "skip";
     }
 }
 
@@ -1390,9 +1450,7 @@ sub create_config {
     close(OUT);
 
 #    exit;
-    run_command "$make oldnoconfig" or
-       dodie "failed make config oldconfig";
-
+    make_oldconfig "";
 }
 
 sub compare_configs {
@@ -1505,7 +1563,9 @@ sub run_config_bisect {
        }
 
        $ret = run_config_bisect_test $type;
-
+       if ($bisect_manual) {
+           $ret = answer_bisect;
+       }
        if ($ret) {
            process_passed %current_config;
            return 0;
@@ -1536,7 +1596,13 @@ sub run_config_bisect {
        $half = int($#start_list / 2);
     } while ($half > 0);
 
-    # we found a single config, try it again
+    # we found a single config, try it again unless we are running manually
+
+    if ($bisect_manual) {
+       process_failed $start_list[0];
+       return 1;
+    }
+
     my @tophalf = @start_list[0 .. 0];
 
     $ret = run_config_bisect_test $type;
@@ -1594,8 +1660,7 @@ sub config_bisect {
     close(IN);
 
     # Now run oldconfig with the minconfig (and addconfigs)
-    run_command "$defconfig $make oldnoconfig" or
-       dodie "failed make config oldconfig";
+    make_oldconfig $defconfig;
 
     # check to see what we lost (or gained)
     open (IN, $output_config)
@@ -1907,6 +1972,8 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
     $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
     $sleep_time = set_test_option("SLEEP_TIME", $i);
     $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
+    $bisect_manual = set_test_option("BISECT_MANUAL", $i);
+    $bisect_skip = set_test_option("BISECT_SKIP", $i);
     $store_failures = set_test_option("STORE_FAILURES", $i);
     $timeout = set_test_option("TIMEOUT", $i);
     $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
This page took 0.026181 seconds and 5 git commands to generate.