]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge tag 'ktest-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 28 Feb 2017 07:07:59 +0000 (23:07 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 28 Feb 2017 07:07:59 +0000 (23:07 -0800)
Pull ktest updates from Steven Rostedt:
 "These are various fixes that I have made and never got around to
  pushing. I've been asked to get the upstream repo back up-to-date"

* tag 'ktest-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest:
  ktest: Add variable run_command_status to save status of commands executed
  ktest.pl: Powercycle the box on reboot if no connection can be made
  ktest: Add timeout to ssh command
  ktest: Fix child exit code processing
  ktest: Have POST_TEST run after the test has totally completed

1  2 
tools/testing/ktest/ktest.pl

index be93ab02b4903d54fcf1a3787392146a2d75472b,29470b5547119acfb3497fd6dc01e946a503954a..6e4eb2fc2d1e78edc356692dcadfe3bfaebd65ec
@@@ -179,6 -179,7 +179,7 @@@ my $localversion
  my $iteration = 0;
  my $successes = 0;
  my $stty_orig;
+ my $run_command_status = 0;
  
  my $bisect_good;
  my $bisect_bad;
@@@ -719,14 -720,14 +720,14 @@@ sub set_value 
  
      if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
        # Note if a test is something other than build, then we
 -      # will need other manditory options.
 +      # will need other mandatory options.
        if ($prvalue ne "install") {
            # for bisect, we need to check BISECT_TYPE
            if ($prvalue ne "bisect") {
                $buildonly = 0;
            }
        } else {
 -          # install still limits some manditory options.
 +          # install still limits some mandatory options.
            $buildonly = 2;
        }
      }
        if ($prvalue ne "install") {
            $buildonly = 0;
        } else {
 -          # install still limits some manditory options.
 +          # install still limits some mandatory options.
            $buildonly = 2;
        }
      }
@@@ -1325,26 -1326,44 +1326,44 @@@ sub wait_for_monitor
  
  sub reboot {
      my ($time) = @_;
+     my $powercycle = 0;
  
-     # Make sure everything has been written to disk
-     run_ssh("sync");
+     # test if the machine can be connected to within 5 seconds
+     my $stat = run_ssh("echo check machine status", 5);
+     if (!$stat) {
+       doprint("power cycle\n");
+       $powercycle = 1;
+     }
+     if ($powercycle) {
+       run_command "$power_cycle";
  
-     if (defined($time)) {
        start_monitor;
        # flush out current monitor
        # May contain the reboot success line
        wait_for_monitor 1;
-     }
  
-     # try to reboot normally
-     if (run_command $reboot) {
-       if (defined($powercycle_after_reboot)) {
-           sleep $powercycle_after_reboot;
+     } else {
+       # Make sure everything has been written to disk
+       run_ssh("sync");
+       if (defined($time)) {
+           start_monitor;
+           # flush out current monitor
+           # May contain the reboot success line
+           wait_for_monitor 1;
+       }
+       # try to reboot normally
+       if (run_command $reboot) {
+           if (defined($powercycle_after_reboot)) {
+               sleep $powercycle_after_reboot;
+               run_command "$power_cycle";
+           }
+       } else {
+           # nope? power cycle it.
            run_command "$power_cycle";
        }
-     } else {
-       # nope? power cycle it.
-       run_command "$power_cycle";
      }
  
      if (defined($time)) {
@@@ -1412,6 -1431,10 +1431,10 @@@ sub dodie 
            system("stty $stty_orig");
      }
  
+     if (defined($post_test)) {
+       run_command $post_test;
+     }
      die @_, "\n";
  }
  
@@@ -1624,10 -1647,6 +1647,6 @@@ sub save_logs 
  
  sub fail {
  
-       if (defined($post_test)) {
-               run_command $post_test;
-       }
        if ($die_on_failure) {
                dodie @_;
        }
            save_logs "fail", $store_failures;
          }
  
+       if (defined($post_test)) {
+               run_command $post_test;
+       }
        return 1;
  }
  
  sub run_command {
-     my ($command, $redirect) = @_;
+     my ($command, $redirect, $timeout) = @_;
      my $start_time;
      my $end_time;
      my $dolog = 0;
      my $dord = 0;
      my $pid;
  
-     $start_time = time;
      $command =~ s/\$SSH_USER/$ssh_user/g;
      $command =~ s/\$MACHINE/$machine/g;
  
      doprint("$command ... ");
+     $start_time = time;
  
      $pid = open(CMD, "$command 2>&1 |") or
        (fail "unable to exec $command" and return 0);
        $dord = 1;
      }
  
-     while (<CMD>) {
-       print LOG if ($dolog);
-       print RD  if ($dord);
+     my $hit_timeout = 0;
+     while (1) {
+       my $fp = \*CMD;
+       if (defined($timeout)) {
+           doprint "timeout = $timeout\n";
+       }
+       my $line = wait_for_input($fp, $timeout);
+       if (!defined($line)) {
+           my $now = time;
+           if (defined($timeout) && (($now - $start_time) >= $timeout)) {
+               doprint "Hit timeout of $timeout, killing process\n";
+               $hit_timeout = 1;
+               kill 9, $pid;
+           }
+           last;
+       }
+       print LOG $line if ($dolog);
+       print RD $line if ($dord);
      }
  
      waitpid($pid, 0);
-     my $failed = $?;
+     # shift 8 for real exit status
+     $run_command_status = $? >> 8;
  
      close(CMD);
      close(LOG) if ($dolog);
        doprint "[$delta seconds] ";
      }
  
-     if ($failed) {
+     if ($hit_timeout) {
+       $run_command_status = 1;
+     }
+     if ($run_command_status) {
        doprint "FAILED!\n";
      } else {
        doprint "SUCCESS\n";
      }
  
-     return !$failed;
+     return !$run_command_status;
  }
  
  sub run_ssh {
-     my ($cmd) = @_;
+     my ($cmd, $timeout) = @_;
      my $cp_exec = $ssh_exec;
  
      $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
-     return run_command "$cp_exec";
+     return run_command "$cp_exec", undef , $timeout;
  }
  
  sub run_scp {
@@@ -2489,10 -2532,6 +2532,6 @@@ sub halt 
  sub success {
      my ($i) = @_;
  
-     if (defined($post_test)) {
-       run_command $post_test;
-     }
      $successes++;
  
      my $name = "";
        doprint "Reboot and wait $sleep_time seconds\n";
        reboot_to_good $sleep_time;
      }
+     if (defined($post_test)) {
+       run_command $post_test;
+     }
  }
  
  sub answer_bisect {
  }
  
  sub child_run_test {
-     my $failed = 0;
  
      # child should have no power
      $reboot_on_error = 0;
      $poweroff_on_error = 0;
      $die_on_failure = 1;
  
-     run_command $run_test, $testlog or $failed = 1;
+     run_command $run_test, $testlog;
  
-     exit $failed;
+     exit $run_command_status;
  }
  
  my $child_done;
@@@ -2629,7 -2671,7 +2671,7 @@@ sub do_run_test 
      }
  
      waitpid $child_pid, 0;
-     $child_exit = $?;
+     $child_exit = $? >> 8;
  
      my $end_time = time;
      $test_time = $end_time - $start_time;
@@@ -3330,7 -3372,6 +3372,6 @@@ sub config_bisect 
      save_config \%good_configs, $good_config;
      save_config \%bad_configs, $bad_config;
  
      if (defined($config_bisect_check) && $config_bisect_check ne "0") {
        if ($config_bisect_check ne "good") {
            doprint "Testing bad config\n";
@@@ -3989,7 -4030,7 +4030,7 @@@ sub make_min_config 
                }
            }
  
 -          # Save off all the current mandidory configs
 +          # Save off all the current mandatory configs
            open (OUT, ">$temp_config")
                or die "Can't write to $temp_config";
            foreach my $config (keys %keep_configs) {