From 9f23b129eb35c1465aa1733884acad3d95c8fde7 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Wed, 21 Mar 2018 10:24:20 -0400 Subject: ktest: Wait for console process to exit To clean up the console processes that are forked to monitor the console, there needs to be a waitpid(). Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 0c8b61f8398e..4eece2a9772c 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1515,6 +1515,9 @@ sub close_console { doprint "kill child process $pid\n"; kill $close_console_signal, $pid; + doprint "wait for child process $pid to exit\n"; + waitpid($pid, 0); + print "closing!\n"; close($fp); -- cgit v1.2.3-59-g8ed1b From 3e1d3678844b2b1f4c41818bc9a2885cbf5ccef6 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Wed, 21 Mar 2018 10:36:08 -0400 Subject: ktest: Add CONNECT_TIMEOUT to change the connection timeout time Before ktest issues a reboot, it will try to connect to the target machine to make sure that it is still alive. If the target does not respond within 5 seconds, it will power cycle the box instead of issuing a reboot. Five seconds may be too short, and ktest may unnecessarially power cycle the box. I have found 25 seconds seems to be a better timeout for this purpose. But even 25 may be too arbitrary. Add a CONNECT_TIMEOUT option to let the user determine the timeout time before rebooting. By default, it has been raised to 25 seconds. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 7 +++++-- tools/testing/ktest/sample.conf | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 4eece2a9772c..a959b6f79ce5 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -59,6 +59,7 @@ my %default = ( "GRUB_REBOOT" => "grub2-reboot", "SYSLINUX" => "extlinux", "SYSLINUX_PATH" => "/boot/extlinux", + "CONNECT_TIMEOUT" => 25, # required, and we will ask users if they don't have them but we keep the default # value something that is common. @@ -163,6 +164,7 @@ my $store_failures; my $store_successes; my $test_name; my $timeout; +my $connect_timeout; my $booted_timeout; my $detect_triplefault; my $console; @@ -296,6 +298,7 @@ my %option_map = ( "STORE_SUCCESSES" => \$store_successes, "TEST_NAME" => \$test_name, "TIMEOUT" => \$timeout, + "CONNECT_TIMEOUT" => \$connect_timeout, "BOOTED_TIMEOUT" => \$booted_timeout, "CONSOLE" => \$console, "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal, @@ -1328,8 +1331,8 @@ sub reboot { my ($time) = @_; my $powercycle = 0; - # test if the machine can be connected to within 5 seconds - my $stat = run_ssh("echo check machine status", 5); + # test if the machine can be connected to within a few seconds + my $stat = run_ssh("echo check machine status", $connect_timeout); if (!$stat) { doprint("power cycle\n"); $powercycle = 1; diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 6c58cd8bbbae..8df62c837dd1 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -725,6 +725,13 @@ # (default 120) #TIMEOUT = 120 +# The timeout in seconds when to test if the box can be rebooted +# or not. Before issuing the reboot command, a ssh connection +# is attempted to see if the target machine is still active. +# If the target does not connect within this timeout, a power cycle +# is issued instead of a reboot. +# CONNECT_TIMEOUT = 25 + # In between tests, a reboot of the box may occur, and this # is the time to wait for the console after it stops producing # output. Some machines may not produce a large lag on reboot -- cgit v1.2.3-59-g8ed1b From edbd0ede0078bde5eb539e175cd7e0e89cd82df0 Mon Sep 17 00:00:00 2001 From: Scott Wood Date: Sun, 16 Jul 2017 19:16:23 -0500 Subject: ktest: Clarify config file usage Simply telling a new user to edit "the config file" without giving any hints on where that file should go, what it should be named, or where a template can be found, is not particularly helpful. Link: http://lkml.kernel.org/r/20170717001630.10518-1-swood@redhat.com Signed-off-by: Scott Wood Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 3 ++- tools/testing/ktest/sample.conf | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index a959b6f79ce5..c85a9f9342f4 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1143,7 +1143,8 @@ sub __read_config { sub get_test_case { print "What test case would you like to run?\n"; print " (build, install or boot)\n"; - print " Other tests are available but require editing the config file\n"; + print " Other tests are available but require editing ktest.conf\n"; + print " (see tools/testing/ktest/sample.conf)\n"; my $ans = ; chomp $ans; $default{"TEST_TYPE"} = $ans; diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 8df62c837dd1..e628e7c8d875 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -1,6 +1,9 @@ # # Config file for ktest.pl # +# Place your customized version of this, named ktest.conf, in the +# working directory that ktest.pl is run from. +# # Note, all paths must be absolute # -- cgit v1.2.3-59-g8ed1b From 25bc70fa0968dacb40eec37d4340163df48b06cf Mon Sep 17 00:00:00 2001 From: Scott Wood Date: Sun, 16 Jul 2017 19:16:24 -0500 Subject: ktest: Set buildonly=1 for CONFIG_BISECT_TYPE=build Rather than adding a third copy of the same logic, rework it to cover all three buildonly cases at once. In the future, please consider using the same variable to perform the same function regardless of context... Link: http://lkml.kernel.org/r/20170717001630.10518-2-swood@redhat.com Signed-off-by: Scott Wood Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index c85a9f9342f4..80091dfbce4b 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -721,21 +721,13 @@ sub set_value { my $prvalue = process_variables($rvalue); - if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") { + if ($lvalue =~ /^(TEST|BISECT|CONFIG_BISECT)_TYPE(\[.*\])?$/ && + $prvalue !~ /^(config_|)bisect$/ && + $prvalue !~ /^build$/ && + $buildonly) { + # Note if a test is something other than build, then we # 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 mandatory options. - $buildonly = 2; - } - } - - if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") { if ($prvalue ne "install") { $buildonly = 0; } else { -- cgit v1.2.3-59-g8ed1b From 649c0f12defbefc303d0cb7157b090c9cfd92944 Mon Sep 17 00:00:00 2001 From: Scott Wood Date: Sun, 16 Jul 2017 19:16:25 -0500 Subject: ktest: Set do_not_reboot=y for CONFIG_BISECT_TYPE=build Currently setting do_not_reboot is triggered by simple builds and bisect builds, but not config bisect builds. Link: http://lkml.kernel.org/r/20170717001630.10518-3-swood@redhat.com Signed-off-by: Scott Wood Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 80091dfbce4b..f597f9b4e8d5 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1400,7 +1400,8 @@ sub do_not_reboot { return $test_type eq "build" || $no_reboot || ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") || - ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build"); + ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build") || + ($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq "build"); } sub dodie { -- cgit v1.2.3-59-g8ed1b From a9adc261e978b9214fd505030c24e75b07dcf52f Mon Sep 17 00:00:00 2001 From: Scott Wood Date: Sun, 16 Jul 2017 19:16:30 -0500 Subject: ktest: Use config-bisect.pl in ktest.pl Reduce code duplication and take advantage of bisection logic improvements by calling config-bisect.pl. The output of make oldconfig is now copied directly to the desired file, rather than doing assign_configs+save_config, in order to preserve the ordering so that diffing the configs at the end will provide useful output. Link: http://lkml.kernel.org/r/20170717001630.10518-8-swood@redhat.com Signed-off-by: Scott Wood [ Modified to use with new version of config-bisect.pl ] Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 264 +++++++------------------------------------ 1 file changed, 42 insertions(+), 222 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index f597f9b4e8d5..ad00ce699749 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -3092,76 +3092,6 @@ sub create_config { make_oldconfig; } -# compare two config hashes, and return configs with different vals. -# It returns B's config values, but you can use A to see what A was. -sub diff_config_vals { - my ($pa, $pb) = @_; - - # crappy Perl way to pass in hashes. - my %a = %{$pa}; - my %b = %{$pb}; - - my %ret; - - foreach my $item (keys %a) { - if (defined($b{$item}) && $b{$item} ne $a{$item}) { - $ret{$item} = $b{$item}; - } - } - - return %ret; -} - -# compare two config hashes and return the configs in B but not A -sub diff_configs { - my ($pa, $pb) = @_; - - my %ret; - - # crappy Perl way to pass in hashes. - my %a = %{$pa}; - my %b = %{$pb}; - - foreach my $item (keys %b) { - if (!defined($a{$item})) { - $ret{$item} = $b{$item}; - } - } - - return %ret; -} - -# return if two configs are equal or not -# 0 is equal +1 b has something a does not -# +1 if a and b have a different item. -# -1 if a has something b does not -sub compare_configs { - my ($pa, $pb) = @_; - - my %ret; - - # crappy Perl way to pass in hashes. - my %a = %{$pa}; - my %b = %{$pb}; - - foreach my $item (keys %b) { - if (!defined($a{$item})) { - return 1; - } - if ($a{$item} ne $b{$item}) { - return 1; - } - } - - foreach my $item (keys %a) { - if (!defined($b{$item})) { - return -1; - } - } - - return 0; -} - sub run_config_bisect_test { my ($type) = @_; @@ -3174,166 +3104,49 @@ sub run_config_bisect_test { return $ret; } -sub process_failed { - my ($config) = @_; +sub config_bisect_end { + my ($good, $bad) = @_; doprint "\n\n***************************************\n"; - doprint "Found bad config: $config\n"; + doprint "No more config bisecting possible.\n"; + doprint `diff -u $good $bad`; doprint "***************************************\n\n"; } -# used for config bisecting -my $good_config; -my $bad_config; - -sub process_new_config { - my ($tc, $nc, $gc, $bc) = @_; - - my %tmp_config = %{$tc}; - my %good_configs = %{$gc}; - my %bad_configs = %{$bc}; - - my %new_configs; - - my $runtest = 1; - my $ret; - - create_config "tmp_configs", \%tmp_config; - assign_configs \%new_configs, $output_config; - - $ret = compare_configs \%new_configs, \%bad_configs; - if (!$ret) { - doprint "New config equals bad config, try next test\n"; - $runtest = 0; - } - - if ($runtest) { - $ret = compare_configs \%new_configs, \%good_configs; - if (!$ret) { - doprint "New config equals good config, try next test\n"; - $runtest = 0; - } - } - - %{$nc} = %new_configs; - - return $runtest; -} - sub run_config_bisect { - my ($pgood, $pbad) = @_; - - my $type = $config_bisect_type; - - my %good_configs = %{$pgood}; - my %bad_configs = %{$pbad}; - - my %diff_configs = diff_config_vals \%good_configs, \%bad_configs; - my %b_configs = diff_configs \%good_configs, \%bad_configs; - my %g_configs = diff_configs \%bad_configs, \%good_configs; - - my @diff_arr = keys %diff_configs; - my $len_diff = $#diff_arr + 1; - - my @b_arr = keys %b_configs; - my $len_b = $#b_arr + 1; - - my @g_arr = keys %g_configs; - my $len_g = $#g_arr + 1; - - my $runtest = 1; - my %new_configs; + my ($good, $bad, $last_result) = @_; + my $cmd; my $ret; - # First, lets get it down to a single subset. - # Is the problem with a difference in values? - # Is the problem with a missing config? - # Is the problem with a config that breaks things? - - # Enable all of one set and see if we get a new bad - # or good config. - - # first set the good config to the bad values. - - doprint "d=$len_diff g=$len_g b=$len_b\n"; - - # first lets enable things in bad config that are enabled in good config - - if ($len_diff > 0) { - if ($len_b > 0 || $len_g > 0) { - my %tmp_config = %bad_configs; - - doprint "Set tmp config to be bad config with good config values\n"; - foreach my $item (@diff_arr) { - $tmp_config{$item} = $good_configs{$item}; - } - - $runtest = process_new_config \%tmp_config, \%new_configs, - \%good_configs, \%bad_configs; - } - } - - if (!$runtest && $len_diff > 0) { - - if ($len_diff == 1) { - process_failed $diff_arr[0]; - return 1; - } - my %tmp_config = %bad_configs; - - my $half = int($#diff_arr / 2); - my @tophalf = @diff_arr[0 .. $half]; - - doprint "Settings bisect with top half:\n"; - doprint "Set tmp config to be bad config with some good config values\n"; - foreach my $item (@tophalf) { - $tmp_config{$item} = $good_configs{$item}; - } - - $runtest = process_new_config \%tmp_config, \%new_configs, - \%good_configs, \%bad_configs; - - if (!$runtest) { - my %tmp_config = %bad_configs; - - doprint "Try bottom half\n"; - - my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr]; - - foreach my $item (@bottomhalf) { - $tmp_config{$item} = $good_configs{$item}; - } + run_command "$builddir/tools/testing/ktest/config-bisect.pl -b $outputdir $good $bad $last_result"; - $runtest = process_new_config \%tmp_config, \%new_configs, - \%good_configs, \%bad_configs; - } + # config-bisect returns: + # 0 if there is more to bisect + # 1 for finding a good config + # 2 if it can not find any more configs + # -1 (255) on error + if ($run_command_status) { + return $run_command_status; } - if ($runtest) { - $ret = run_config_bisect_test $type; - if ($ret) { - doprint "NEW GOOD CONFIG\n"; - %good_configs = %new_configs; - run_command "mv $good_config ${good_config}.last"; - save_config \%good_configs, $good_config; - %{$pgood} = %good_configs; - } else { - doprint "NEW BAD CONFIG\n"; - %bad_configs = %new_configs; - run_command "mv $bad_config ${bad_config}.last"; - save_config \%bad_configs, $bad_config; - %{$pbad} = %bad_configs; - } - return 0; + $ret = run_config_bisect_test $config_bisect_type; + if ($ret) { + doprint "NEW GOOD CONFIG\n"; + # Return 3 for good config + return 3; + } else { + doprint "NEW BAD CONFIG\n"; + # Return 4 for bad config + return 4; } - - fail "Hmm, need to do a mix match?\n"; - return -1; } sub config_bisect { my ($i) = @_; + my $good_config; + my $bad_config; + my $type = $config_bisect_type; my $ret; @@ -3364,18 +3177,14 @@ sub config_bisect { doprint "Run good configs through make oldconfig\n"; assign_configs \%tmp_configs, $good_config; create_config "$good_config", \%tmp_configs; - assign_configs \%good_configs, $output_config; + $good_config = "$tmpdir/good_config"; + system("cp $output_config $good_config") == 0 or dodie "cp good config"; doprint "Run bad configs through make oldconfig\n"; assign_configs \%tmp_configs, $bad_config; create_config "$bad_config", \%tmp_configs; - assign_configs \%bad_configs, $output_config; - - $good_config = "$tmpdir/good_config"; $bad_config = "$tmpdir/bad_config"; - - save_config \%good_configs, $good_config; - save_config \%bad_configs, $bad_config; + system("cp $output_config $bad_config") == 0 or dodie "cp bad config"; if (defined($config_bisect_check) && $config_bisect_check ne "0") { if ($config_bisect_check ne "good") { @@ -3398,10 +3207,21 @@ sub config_bisect { } } + my $last_run = ""; + do { - $ret = run_config_bisect \%good_configs, \%bad_configs; + $ret = run_config_bisect $good_config, $bad_config, $last_run; + if ($ret == 3) { + $last_run = "good"; + } elsif ($ret == 4) { + $last_run = "bad"; + } print_times; - } while (!$ret); + } while ($ret == 3 || $ret == 4); + + if ($ret == 2) { + config_bisect_end "$good_config.tmp", "$bad_config.tmp"; + } return $ret if ($ret < 0); -- cgit v1.2.3-59-g8ed1b From b337f9790a0c8f0f01abf9fe3e1f48894b773899 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Thu, 22 Mar 2018 16:28:18 -0400 Subject: ktest.pl: Allow for the config-bisect.pl output to display to console When commands are run in ktest, they are only displayed in the ktest log file, but that is not sufficient for outputting the display for config bisects. The result of a config bisect is not shown. Add a way to display the output of "run_command" which is the subroutine used by ktest to execute commands. Use this feature to display the output of config-bisect.pl executions to see the progress as well as the result. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index ad00ce699749..79c2f99629de 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1692,6 +1692,7 @@ sub run_command { my $end_time; my $dolog = 0; my $dord = 0; + my $dostdout = 0; my $pid; $command =~ s/\$SSH_USER/$ssh_user/g; @@ -1710,9 +1711,15 @@ sub run_command { } if (defined($redirect)) { - open (RD, ">$redirect") or - dodie "failed to write to redirect $redirect"; - $dord = 1; + if ($redirect eq 1) { + $dostdout = 1; + # Have the output of the command on its own line + doprint "\n"; + } else { + open (RD, ">$redirect") or + dodie "failed to write to redirect $redirect"; + $dord = 1; + } } my $hit_timeout = 0; @@ -1734,6 +1741,7 @@ sub run_command { } print LOG $line if ($dolog); print RD $line if ($dord); + print $line if ($dostdout); } waitpid($pid, 0); @@ -3118,7 +3126,7 @@ sub run_config_bisect { my $cmd; my $ret; - run_command "$builddir/tools/testing/ktest/config-bisect.pl -b $outputdir $good $bad $last_result"; + run_command "$builddir/tools/testing/ktest/config-bisect.pl -b $outputdir $good $bad $last_result", 1; # config-bisect returns: # 0 if there is more to bisect -- cgit v1.2.3-59-g8ed1b From b2b07ea282721b6c7bed21e95e2c00dd95cb8520 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Thu, 22 Mar 2018 16:36:34 -0400 Subject: ktest.pl: Use diffconfig if available for failed config bisects Check to see if diffconfig is available and use that to diff the configs instead of using 'diff -u', as diffconfig produces much better output of kernel config files. It checks the source directory for the executable. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 79c2f99629de..27505fef2dab 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -3114,10 +3114,14 @@ sub run_config_bisect_test { sub config_bisect_end { my ($good, $bad) = @_; + my $diffexec = "diff -u"; + if (-f "$builddir/scripts/diffconfig") { + $diffexec = "$builddir/scripts/diffconfig"; + } doprint "\n\n***************************************\n"; doprint "No more config bisecting possible.\n"; - doprint `diff -u $good $bad`; + run_command "$diffexec $good $bad", 1; doprint "***************************************\n\n"; } -- cgit v1.2.3-59-g8ed1b From 133087f0623e927dfdf439a1b6a4e819a7a5f3ea Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Wed, 4 Apr 2018 15:42:08 -0400 Subject: ktest.pl: Have ktest.pl pass -r to config-bisect.pl to reset bisect If config-bisect.pl sees that a config_bisect has already been started, it will ask on the command line if it should bisect or not. This will mess up running config_bisect from ktest.pl. Have ktest.pl pass in '-r' to config-bisect.pl and have config-bisect.pl recognize that to reset without asking. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/config-bisect.pl | 21 ++++++++++++++------- tools/testing/ktest/ktest.pl | 6 +++++- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/config-bisect.pl b/tools/testing/ktest/config-bisect.pl index 37cd796efa2b..b28feea7c363 100755 --- a/tools/testing/ktest/config-bisect.pl +++ b/tools/testing/ktest/config-bisect.pl @@ -52,11 +52,11 @@ # If "good" or "bad" is not stated at the end, it will copy the good and # bad configs to the .tmp versions. If a .tmp version already exists, it will -# warn before writing over them. If the last config is labeled "good", then -# it will copy it to the good .tmp version. If the last config is labeled -# "bad", it will copy it to the bad .tmp version. It will continue this until -# it can not merge the two any more without the result being equal to either -# the good or bad .tmp configs. +# warn before writing over them (-r will not warn, and just write over them). +# If the last config is labeled "good", then it will copy it to the good .tmp +# version. If the last config is labeled "bad", it will copy it to the bad +# .tmp version. It will continue this until it can not merge the two any more +# without the result being equal to either the good or bad .tmp configs. my $start = 0; my $val = ""; @@ -67,6 +67,7 @@ my $tree = $pwd; my $build; my $output_config; +my $reset_bisect; sub usage { print << "EOF" @@ -654,6 +655,10 @@ while ($#ARGV >= 0) { $tree = $val; } + elsif ($opt eq "-r") { + $reset_bisect = 1; + } + elsif ($opt eq "-h") { usage; } @@ -721,8 +726,10 @@ if ($start) { $p = "$p$bad exists\n"; } - if (!read_yn "${p}Overwrite and start new bisect anyway?") { - exit (-1); + if (!defined($reset_bisect)) { + if (!read_yn "${p}Overwrite and start new bisect anyway?") { + exit (-1); + } } } run_command "cp $good_start $good" or die "failed to copy to $good\n"; diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 27505fef2dab..fe6a7bb7d7d9 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -3127,10 +3127,14 @@ sub config_bisect_end { sub run_config_bisect { my ($good, $bad, $last_result) = @_; + my $reset = ""; my $cmd; my $ret; - run_command "$builddir/tools/testing/ktest/config-bisect.pl -b $outputdir $good $bad $last_result", 1; + if (!length($last_result)) { + $reset = "-r"; + } + run_command "$builddir/tools/testing/ktest/config-bisect.pl $reset -b $outputdir $good $bad $last_result", 1; # config-bisect returns: # 0 if there is more to bisect -- cgit v1.2.3-59-g8ed1b From 40667fb5fda0483e5c617d133968b17f6854cb9b Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Thu, 5 Apr 2018 12:14:39 -0400 Subject: ktest.pl: Make finding config-bisect.pl dynamic Just looking for config-bisect.pl in the source tree can be risky, especially, if the source tree being tested doesn't have config-bisect.pl in place. Instead, allow the user to set where to find config-bisect.pl with a new option CONFIG_BISECT_EXEC. If this option is not set, by default, ktest.pl will look for config-bisect.pl in the following locations: `pwd`/config-bisect.pl # where ktest.pl was called from `dirname /path/to/ktest.pl`/config-bisect.pl # where ktest.pl exists ${BUILD_DIR}/tools/testing/ktest/config-bisect.pl # where config-bisect.pl exists in the source tree. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 27 ++++++++++++++++++++++++++- tools/testing/ktest/sample.conf | 10 ++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index fe6a7bb7d7d9..e04422d8f844 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -10,6 +10,7 @@ use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); use File::Path qw(mkpath); use File::Copy qw(cp); use FileHandle; +use FindBin; my $VERSION = "0.2"; @@ -165,6 +166,7 @@ my $store_successes; my $test_name; my $timeout; my $connect_timeout; +my $config_bisect_exec; my $booted_timeout; my $detect_triplefault; my $console; @@ -206,6 +208,9 @@ my $install_time; my $reboot_time; my $test_time; +my $pwd; +my $dirname = $FindBin::Bin; + # set when a test is something other that just building or install # which would require more options. my $buildonly = 1; @@ -299,6 +304,7 @@ my %option_map = ( "TEST_NAME" => \$test_name, "TIMEOUT" => \$timeout, "CONNECT_TIMEOUT" => \$connect_timeout, + "CONFIG_BISECT_EXEC" => \$config_bisect_exec, "BOOTED_TIMEOUT" => \$booted_timeout, "CONSOLE" => \$console, "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal, @@ -340,6 +346,7 @@ my %used_options; # default variables that can be used chomp ($variable{"PWD"} = `pwd`); +$pwd = $variable{"PWD"}; $config_help{"MACHINE"} = << "EOF" The machine hostname that you will test. @@ -3134,7 +3141,7 @@ sub run_config_bisect { if (!length($last_result)) { $reset = "-r"; } - run_command "$builddir/tools/testing/ktest/config-bisect.pl $reset -b $outputdir $good $bad $last_result", 1; + run_command "$config_bisect_exec $reset -b $outputdir $good $bad $last_result", 1; # config-bisect returns: # 0 if there is more to bisect @@ -3182,6 +3189,24 @@ sub config_bisect { $good_config = $output_config; } + if (!defined($config_bisect_exec)) { + # First check the location that ktest.pl ran + my @locations = ( "$pwd/config-bisect.pl", + "$dirname/config-bisect.pl", + "$builddir/tools/testing/ktest/config-bisect.pl", + undef ); + foreach my $loc (@locations) { + doprint "loc = $loc\n"; + $config_bisect_exec = $loc; + last if (defined($config_bisect_exec && -x $config_bisect_exec)); + } + if (!defined($config_bisect_exec)) { + fail "Could not find an executable config-bisect.pl\n", + " Set CONFIG_BISECT_EXEC to point to config-bisect.pl"; + return 1; + } + } + # we don't want min configs to cause issues here. doprint "Disabling 'MIN_CONFIG' for this test\n"; undef $minconfig; diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 695983a72465..f5b58addb1d1 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -1179,6 +1179,16 @@ # Set it to "good" to test only the good config and set it # to "bad" to only test the bad config. # +# CONFIG_BISECT_EXEC (optional) +# The config bisect is a separate program that comes with ktest.pl. +# By befault, it will look for: +# `pwd`/config-bisect.pl # the location ktest.pl was executed from. +# If it does not find it there, it will look for: +# `dirname `/config-bisect.pl # The directory that holds ktest.pl +# If it does not find it there, it will look for: +# ${BUILD_DIR}/tools/testing/ktest/config-bisect.pl +# Setting CONFIG_BISECT_EXEC will override where it looks. +# # Example: # TEST_START # TEST_TYPE = config_bisect -- cgit v1.2.3-59-g8ed1b From 5a57299a1f084bbe7e3e9cafb06999793c4a40fb Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Thu, 5 Apr 2018 14:51:42 -0400 Subject: ktest.pl: Detect if a config-bisect was interrupted If a config-bisect was interrupted, then allow the user to continue, or restart a new config-bisect. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index e04422d8f844..d4b22b5c425b 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -3215,6 +3215,20 @@ sub config_bisect { my %bad_configs; my %tmp_configs; + if (-f "$tmpdir/good_config.tmp" || -f "$tmpdir/bad_config.tmp") { + if (read_yn "Interrupted config-bisect. Continue (n - will start new)?") { + if (-f "$tmpdir/good_config.tmp") { + $good_config = "$tmpdir/good_config.tmp"; + } else { + $good_config = "$tmpdir/good_config"; + } + if (-f "$tmpdir/bad_config.tmp") { + $bad_config = "$tmpdir/bad_config.tmp"; + } else { + $bad_config = "$tmpdir/bad_config"; + } + } + } doprint "Run good configs through make oldconfig\n"; assign_configs \%tmp_configs, $good_config; create_config "$good_config", \%tmp_configs; -- cgit v1.2.3-59-g8ed1b From 2ceb2d85b6697e2a3485047d1c908a4908069411 Mon Sep 17 00:00:00 2001 From: Tim Tianyang Chen Date: Mon, 26 Mar 2018 13:08:01 -0700 Subject: Ktest: Add email support Users can define optional variables to get email notifications. Ktest can send emails when the script: * was started * failed with fatal errors and called dodie() * completed all testing Users have to setup the mailer provided in config prior to using this script. Supported mailers: mailx, mail, sendmail mailer specific routines are _sendmail_send(), _mailx_send() Link: http://lkml.kernel.org/r/1522094884-22718-2-git-send-email-tianyang.chen@oracle.com Suggested-by: Dhaval Giani Signed-off-by: Tim Tianyang Chen Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 61 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index d4b22b5c425b..bb43f8631c95 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -23,6 +23,11 @@ my %evals; #default opts my %default = ( + "MAILER" => "sendmail", # default mailer + "EMAIL_ON_ERROR" => 1, + "EMAIL_WHEN_FINISHED" => 1, + "EMAIL_WHEN_CANCELED" => 0, + "EMAIL_WHEN_STARTED" => 0, "NUM_TESTS" => 1, "TEST_TYPE" => "build", "BUILD_TYPE" => "randconfig", @@ -211,6 +216,15 @@ my $test_time; my $pwd; my $dirname = $FindBin::Bin; +my $mailto; +my $mailer; +my $email_on_error; +my $email_when_finished; +my $email_when_started; +my $email_when_canceled; + +my $script_start_time = localtime(); + # set when a test is something other that just building or install # which would require more options. my $buildonly = 1; @@ -236,6 +250,12 @@ my $no_reboot = 1; my $reboot_success = 0; my %option_map = ( + "MAILTO" => \$mailto, + "MAILER" => \$mailer, + "EMAIL_ON_ERROR" => \$email_on_error, + "EMAIL_WHEN_FINISHED" => \$email_when_finished, + "EMAIL_WHEN_STARTED" => \$email_when_started, + "EMAIL_WHEN_CANCELED" => \$email_when_canceled, "MACHINE" => \$machine, "SSH_USER" => \$ssh_user, "TMP_DIR" => \$tmpdir, @@ -1430,6 +1450,11 @@ sub dodie { print " See $opt{LOG_FILE} for more info.\n"; } + if ($email_on_error) { + send_email("KTEST: critical failure for your [$test_type] test", + "Your test started at $script_start_time has failed with:\n@_\n"); + } + if ($monitor_cnt) { # restore terminal settings system("stty $stty_orig"); @@ -4099,6 +4124,26 @@ sub set_test_option { return eval_option($name, $option, $i); } +sub _mailx_send { + my ($subject, $message) = @_; + system("$mailer -s \'$subject\' $mailto <<< \'$message\'"); +} + +sub _sendmail_send { + my ($subject, $message) = @_; + system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto"); +} + +sub send_email { + if (defined($mailto) && defined($mailer)) { + if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} + elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} + else { doprint "\nYour mailer: $mailer is not supported.\n" } + } else { + print "No email sent: email or mailer not specified in config.\n" + } +} + # First we need to do is the builds for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { @@ -4139,9 +4184,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { $start_minconfig_defined = 1; # The first test may override the PRE_KTEST option - if (defined($pre_ktest) && $i == 1) { - doprint "\n"; - run_command $pre_ktest; + if ($i == 1) { + if (defined($pre_ktest)) { + doprint "\n"; + run_command $pre_ktest; + } + if ($email_when_started) { + send_email("KTEST: Your [$test_type] test was started", + "Your test was started on $script_start_time"); + } } # Any test can override the POST_KTEST option @@ -4305,4 +4356,8 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) { doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; +if ($email_when_finished) { + send_email("KTEST: Your [$test_type] test has finished!", + "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!"); +} exit 0; -- cgit v1.2.3-59-g8ed1b From 92db453e7eeb44efd43e977fa5ab417274834a9a Mon Sep 17 00:00:00 2001 From: Tim Tianyang Chen Date: Mon, 26 Mar 2018 13:08:02 -0700 Subject: Ktest: Add SigInt handling User can cancel tests and specify handler's behavior using option 'EMAIL_WHEN_CANCELED'. Link: http://lkml.kernel.org/r/1522094884-22718-3-git-send-email-tianyang.chen@oracle.com Suggested-by: Dhaval Giani Signed-off-by: Tim Tianyang Chen Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index bb43f8631c95..1646af526089 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -4144,6 +4144,16 @@ sub send_email { } } +sub cancel_test { + if ($email_when_canceled) { + send_email("KTEST: Your [$test_type] test was cancelled", + "Your test started at $script_start_time was cancelled: sig int"); + } + die "\nCaught Sig Int, test interrupted: $!\n" +} + +$SIG{INT} = qw(cancel_test); + # First we need to do is the builds for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { -- cgit v1.2.3-59-g8ed1b From df46fce692a649559d64da2826d355b4f28fc526 Mon Sep 17 00:00:00 2001 From: Tim Tianyang Chen Date: Mon, 26 Mar 2018 13:08:03 -0700 Subject: Ktest: Use dodie for critical falures Users should get emails when the script dies because of a critical failure. Critical failures are defined as any errors that could abnormally terminate the script. In order to add email support, this patch converts all die() to dodie() except: * when '-v' is used as an option to get the version of the script. * in Sig-Int handeler because it's not a fatal error to cancel the script. * errors happen during parsing config Link: http://lkml.kernel.org/r/1522094884-22718-4-git-send-email-tianyang.chen@oracle.com Suggested-by: Dhaval Giani Signed-off-by: Tim Tianyang Chen Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 1646af526089..30a4c053f98b 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1506,7 +1506,7 @@ sub exec_console { close($pts); exec $console or - die "Can't open console $console"; + dodie "Can't open console $console"; } sub open_console { @@ -1657,7 +1657,7 @@ sub save_logs { if (!-d $dir) { mkpath($dir) or - die "can't create $dir"; + dodie "can't create $dir"; } my %files = ( @@ -1670,7 +1670,7 @@ sub save_logs { while (my ($name, $source) = each(%files)) { if (-f "$source") { cp "$source", "$dir/$name" or - die "failed to copy $source"; + dodie "failed to copy $source"; } } @@ -1852,7 +1852,7 @@ sub get_grub2_index { $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g; open(IN, "$ssh_grub |") - or die "unable to get $grub_file"; + or dodie "unable to get $grub_file"; my $found = 0; @@ -1867,7 +1867,7 @@ sub get_grub2_index { } close(IN); - die "Could not find '$grub_menu' in $grub_file on $machine" + dodie "Could not find '$grub_menu' in $grub_file on $machine" if (!$found); doprint "$grub_number\n"; $last_grub_menu = $grub_menu; @@ -1895,7 +1895,7 @@ sub get_grub_index { $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g; open(IN, "$ssh_grub |") - or die "unable to get menu.lst"; + or dodie "unable to get menu.lst"; my $found = 0; @@ -1910,7 +1910,7 @@ sub get_grub_index { } close(IN); - die "Could not find '$grub_menu' in /boot/grub/menu on $machine" + dodie "Could not find '$grub_menu' in /boot/grub/menu on $machine" if (!$found); doprint "$grub_number\n"; $last_grub_menu = $grub_menu; @@ -2023,7 +2023,7 @@ sub monitor { my $full_line = ""; open(DMESG, "> $dmesg") or - die "unable to write to $dmesg"; + dodie "unable to write to $dmesg"; reboot_to; @@ -2902,7 +2902,7 @@ sub run_bisect { sub update_bisect_replay { my $tmp_log = "$tmpdir/ktest_bisect_log"; run_command "git bisect log > $tmp_log" or - die "can't create bisect log"; + dodie "can't create bisect log"; return $tmp_log; } @@ -2911,9 +2911,9 @@ sub bisect { my $result; - die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good)); - die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad)); - die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type)); + dodie "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good)); + dodie "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad)); + dodie "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type)); my $good = $bisect_good; my $bad = $bisect_bad; @@ -2976,7 +2976,7 @@ sub bisect { if ($check ne "good") { doprint "TESTING BISECT BAD [$bad]\n"; run_command "git checkout $bad" or - die "Failed to checkout $bad"; + dodie "Failed to checkout $bad"; $result = run_bisect $type; @@ -2988,7 +2988,7 @@ sub bisect { if ($check ne "bad") { doprint "TESTING BISECT GOOD [$good]\n"; run_command "git checkout $good" or - die "Failed to checkout $good"; + dodie "Failed to checkout $good"; $result = run_bisect $type; @@ -2999,7 +2999,7 @@ sub bisect { # checkout where we started run_command "git checkout $head" or - die "Failed to checkout $head"; + dodie "Failed to checkout $head"; } run_command "git bisect start$start_files" or @@ -3316,9 +3316,9 @@ sub patchcheck_reboot { sub patchcheck { my ($i) = @_; - die "PATCHCHECK_START[$i] not defined\n" + dodie "PATCHCHECK_START[$i] not defined\n" if (!defined($patchcheck_start)); - die "PATCHCHECK_TYPE[$i] not defined\n" + dodie "PATCHCHECK_TYPE[$i] not defined\n" if (!defined($patchcheck_type)); my $start = $patchcheck_start; @@ -3332,7 +3332,7 @@ sub patchcheck { if (defined($patchcheck_end)) { $end = $patchcheck_end; } elsif ($cherry) { - die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n"; + dodie "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n"; } # Get the true sha1's since we can use things like HEAD~3 @@ -3396,7 +3396,7 @@ sub patchcheck { doprint "\nProcessing commit \"$item\"\n\n"; run_command "git checkout $sha1" or - die "Failed to checkout $sha1"; + dodie "Failed to checkout $sha1"; # only clean on the first and last patch if ($item eq $list[0] || @@ -3487,7 +3487,7 @@ sub read_kconfig { } open(KIN, "$kconfig") - or die "Can't open $kconfig"; + or dodie "Can't open $kconfig"; while () { chomp; @@ -3648,7 +3648,7 @@ sub get_depends { $dep =~ s/^[^$valid]*[$valid]+//; } else { - die "this should never happen"; + dodie "this should never happen"; } } @@ -3909,7 +3909,7 @@ sub make_min_config { # update new ignore configs if (defined($ignore_config)) { open (OUT, ">$temp_config") - or die "Can't write to $temp_config"; + or dodie "Can't write to $temp_config"; foreach my $config (keys %save_configs) { print OUT "$save_configs{$config}\n"; } @@ -3937,7 +3937,7 @@ sub make_min_config { # Save off all the current mandatory configs open (OUT, ">$temp_config") - or die "Can't write to $temp_config"; + or dodie "Can't write to $temp_config"; foreach my $config (keys %keep_configs) { print OUT "$keep_configs{$config}\n"; } @@ -4177,11 +4177,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { $outputdir = set_test_option("OUTPUT_DIR", $i); $builddir = set_test_option("BUILD_DIR", $i); - chdir $builddir || die "can't change directory to $builddir"; + chdir $builddir || dodie "can't change directory to $builddir"; if (!-d $outputdir) { mkpath($outputdir) or - die "can't create $outputdir"; + dodie "can't create $outputdir"; } $make = "$makecmd O=$outputdir"; @@ -4218,7 +4218,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { if (!-d $tmpdir) { mkpath($tmpdir) or - die "can't create $tmpdir"; + dodie "can't create $tmpdir"; } $ENV{"SSH_USER"} = $ssh_user; @@ -4291,7 +4291,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { if (defined($checkout)) { run_command "git checkout $checkout" or - die "failed to checkout $checkout"; + dodie "failed to checkout $checkout"; } $no_reboot = 0; -- cgit v1.2.3-59-g8ed1b From f5ef48855733360c850be82221ce7454294a1580 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Fri, 6 Apr 2018 15:49:43 -0400 Subject: ktest.pl: No need to print no mailer is specified when mailto is not If the user doesn't want to send mail, then don't bother them with output that says they didn't specify a mailer. That can be annoying. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 30a4c053f98b..07d0a47816e4 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -4135,12 +4135,14 @@ sub _sendmail_send { } sub send_email { - if (defined($mailto) && defined($mailer)) { + if (defined($mailto)) { + if (!defined($mailer)) { + doprint "No email sent: email or mailer not specified in config.\n"; + return; + } if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} else { doprint "\nYour mailer: $mailer is not supported.\n" } - } else { - print "No email sent: email or mailer not specified in config.\n" } } -- cgit v1.2.3-59-g8ed1b From be1546b87f3b60f107b8f8dfef0e268cc12792f1 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Fri, 6 Apr 2018 16:38:56 -0400 Subject: ktest.pl: Add MAIL_PATH option to define where to find the mailer The option MAIL_PATH lets the user decide how to find the mailer they are using. For example, sendmail is usually located in /usr/sbin but is not always in the path of non admin users. Have ktest look through the user's PATH environment variable (adding /usr/sbin) as well, but if that's not good enough, allow the user to define where to find the mailer. Signed-off-by: Steven Rostedt (VMware) squash to mail exec Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 36 +++++++++++++++++++++++++++++++----- tools/testing/ktest/sample.conf | 4 ++++ 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 07d0a47816e4..637545bd9e98 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -23,7 +23,7 @@ my %evals; #default opts my %default = ( - "MAILER" => "sendmail", # default mailer + "MAILER" => "sendmail", # default mailer "EMAIL_ON_ERROR" => 1, "EMAIL_WHEN_FINISHED" => 1, "EMAIL_WHEN_CANCELED" => 0, @@ -218,6 +218,7 @@ my $dirname = $FindBin::Bin; my $mailto; my $mailer; +my $mail_path; my $email_on_error; my $email_when_finished; my $email_when_started; @@ -250,8 +251,9 @@ my $no_reboot = 1; my $reboot_success = 0; my %option_map = ( - "MAILTO" => \$mailto, - "MAILER" => \$mailer, + "MAILTO" => \$mailto, + "MAILER" => \$mailer, + "MAIL_PATH" => \$mail_path, "EMAIL_ON_ERROR" => \$email_on_error, "EMAIL_WHEN_FINISHED" => \$email_when_finished, "EMAIL_WHEN_STARTED" => \$email_when_started, @@ -4126,12 +4128,29 @@ sub set_test_option { sub _mailx_send { my ($subject, $message) = @_; - system("$mailer -s \'$subject\' $mailto <<< \'$message\'"); + system("$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'"); } sub _sendmail_send { my ($subject, $message) = @_; - system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto"); + system("echo -e \"Subject: $subject\n\n$message\" | $mail_path/sendmail -t $mailto"); +} + +sub find_mailer { + my ($mailer) = @_; + + my @paths = split /:/, $ENV{PATH}; + + # sendmail is usually in /usr/sbin + $paths[$#paths + 1] = "/usr/sbin"; + + foreach my $path (@paths) { + if (-x "$path/$mailer") { + return $path; + } + } + + return undef; } sub send_email { @@ -4140,6 +4159,13 @@ sub send_email { doprint "No email sent: email or mailer not specified in config.\n"; return; } + if (!defined($mail_path)) { + # find the mailer + $mail_path = find_mailer $mailer; + if (!defined($mail_path)) { + die "\nCan not find $mailer in PATH\n"; + } + } if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} else { doprint "\nYour mailer: $mailer is not supported.\n" } diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index d1a2626aaa0a..86e7cffc45c0 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -411,6 +411,10 @@ # (default sendmail) #MAILER = sendmail # +# The executable to run +# (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER}) +#MAIL_EXEC = /usr/sbin/sendmail +# # Errors are defined as those would terminate the script # (default 1) #EMAIL_ON_ERROR = 1 -- cgit v1.2.3-59-g8ed1b From 8604b0c4bc9a39f8fa0301bbb15146bcda2a44f7 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Fri, 6 Apr 2018 16:42:34 -0400 Subject: ktest.pl: Kill test if mailer is not supported If the user specifies a MAILTO, but the MAILER is not supported, then kill the test. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 637545bd9e98..3400a23e6a41 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -4168,7 +4168,7 @@ sub send_email { } if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} - else { doprint "\nYour mailer: $mailer is not supported.\n" } + else { die "\nYour mailer: $mailer is not supported.\n" } } } -- cgit v1.2.3-59-g8ed1b From 255769a17b86838eb724da5501eba6a31b0ed1ba Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Fri, 6 Apr 2018 17:16:39 -0400 Subject: ktest.pl: Allow dodie be recursive If dodie cause a function that itself will call dodie, then be able to handle that. This will allow dodie functions to call run_command, which could possibly call dodie. If dodie is called again, simply ignore it. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 3400a23e6a41..ac6750bb5942 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1433,7 +1433,14 @@ sub do_not_reboot { ($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq "build"); } +my $in_die = 0; + sub dodie { + + # avoid recusion + return if ($in_die); + $in_die = 1; + doprint "CRITICAL FAILURE... ", @_, "\n"; my $i = $iteration; -- cgit v1.2.3-59-g8ed1b From 59f89eb1e3ddccdef9a154dd667facfc15bceab1 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Fri, 6 Apr 2018 17:46:27 -0400 Subject: ktest.pl: Use run_command to execute sending mail Instead of open coding system() call, use run_command which will log the sending of email as well. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index ac6750bb5942..f487f91ccf03 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -4135,12 +4135,12 @@ sub set_test_option { sub _mailx_send { my ($subject, $message) = @_; - system("$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'"); + run_command "$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'"; } sub _sendmail_send { my ($subject, $message) = @_; - system("echo -e \"Subject: $subject\n\n$message\" | $mail_path/sendmail -t $mailto"); + run_command "echo \'Subject: $subject\n\n$message\' | $mail_path/sendmail -t $mailto"; } sub find_mailer { -- cgit v1.2.3-59-g8ed1b From c2d84ddb338c829e3ee9d1af6a55325998fcdb82 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (VMware)" Date: Sat, 7 Apr 2018 20:11:19 -0400 Subject: ktest.pl: Add MAIL_COMMAND option to define how to send email Allow the user to override the default way to send email. This will allow the user to add their own mailer and format for sending email. Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 54 ++++++++++++++++++++++++++--------------- tools/testing/ktest/sample.conf | 12 +++++++++ 2 files changed, 46 insertions(+), 20 deletions(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index f487f91ccf03..a14fc309d140 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -219,6 +219,7 @@ my $dirname = $FindBin::Bin; my $mailto; my $mailer; my $mail_path; +my $mail_command; my $email_on_error; my $email_when_finished; my $email_when_started; @@ -254,6 +255,7 @@ my %option_map = ( "MAILTO" => \$mailto, "MAILER" => \$mailer, "MAIL_PATH" => \$mail_path, + "MAIL_COMMAND" => \$mail_command, "EMAIL_ON_ERROR" => \$email_on_error, "EMAIL_WHEN_FINISHED" => \$email_when_finished, "EMAIL_WHEN_STARTED" => \$email_when_started, @@ -4133,16 +4135,6 @@ sub set_test_option { return eval_option($name, $option, $i); } -sub _mailx_send { - my ($subject, $message) = @_; - run_command "$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'"; -} - -sub _sendmail_send { - my ($subject, $message) = @_; - run_command "echo \'Subject: $subject\n\n$message\' | $mail_path/sendmail -t $mailto"; -} - sub find_mailer { my ($mailer) = @_; @@ -4160,22 +4152,44 @@ sub find_mailer { return undef; } +sub do_send_mail { + my ($subject, $message) = @_; + + if (!defined($mail_path)) { + # find the mailer + $mail_path = find_mailer $mailer; + if (!defined($mail_path)) { + die "\nCan not find $mailer in PATH\n"; + } + } + + if (!defined($mail_command)) { + if ($mailer eq "mail" || $mailer eq "mailx") { + $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< \'\$MESSAGE\'"; + } elsif ($mailer eq "sendmail" ) { + $mail_command = "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | \$MAIL_PATH/\$MAILER -t \$MAILTO"; + } else { + die "\nYour mailer: $mailer is not supported.\n"; + } + } + + $mail_command =~ s/\$MAILER/$mailer/g; + $mail_command =~ s/\$MAIL_PATH/$mail_path/g; + $mail_command =~ s/\$MAILTO/$mailto/g; + $mail_command =~ s/\$SUBJECT/$subject/g; + $mail_command =~ s/\$MESSAGE/$message/g; + + run_command $mail_command; +} + sub send_email { + if (defined($mailto)) { if (!defined($mailer)) { doprint "No email sent: email or mailer not specified in config.\n"; return; } - if (!defined($mail_path)) { - # find the mailer - $mail_path = find_mailer $mailer; - if (!defined($mail_path)) { - die "\nCan not find $mailer in PATH\n"; - } - } - if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} - elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} - else { die "\nYour mailer: $mailer is not supported.\n" } + do_send_mail @_; } } diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 86e7cffc45c0..6ca6ca0ce695 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -415,6 +415,18 @@ # (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER}) #MAIL_EXEC = /usr/sbin/sendmail # +# The command used to send mail, which uses the above options +# can be modified. By default if the mailer is "sendmail" then +# MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | $MAIL_PATH/$MAILER -t $MAILTO +# For mail or mailx: +# MAIL_COMMAND = "$MAIL_PATH/$MAILER -s \'$SUBJECT\' $MAILTO <<< \'$MESSAGE\' +# ktest.pl will do the substitution for MAIL_PATH, MAILER, MAILTO at the time +# it sends the mail if "$FOO" format is used. If "${FOO}" format is used, +# then the substitutions will occur at the time the config file is read. +# But note, MAIL_PATH and MAILER require being set by the config file if +# ${MAIL_PATH} or ${MAILER} are used, but not if $MAIL_PATH or $MAILER are. +#MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | $MAIL_PATH/$MAILER -t $MAILTO +# # Errors are defined as those would terminate the script # (default 1) #EMAIL_ON_ERROR = 1 -- cgit v1.2.3-59-g8ed1b From 6cd110a91f52197e3392809cd43466bfe2c524d0 Mon Sep 17 00:00:00 2001 From: Satoru Takeuchi Date: Fri, 22 Sep 2017 13:38:19 +0900 Subject: ktest: Take submenu into account for grub2 menus grub-reboot selects the submenu's first menuentry (title is "1>0") rather than ktest's menuentry (title is "2") by mistake. === $ sudo cat /boot/grub/grub.cfg | grep -E "^menuentry|^submenu" ... menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option '...' { ... submenu 'Advanced options for Ubuntu' $menuentry_id_option '...' { ... menuentry 'ktest' { ... === Correct it by taking submenu entries into account in get_grub2_index(). Link: http://lkml.kernel.org/r/87poaje4as.wl-satoru.takeuchi@gmail.com Signed-off-by: Satoru Takeuchi Signed-off-by: Steven Rostedt (VMware) --- tools/testing/ktest/ktest.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/testing/ktest/ktest.pl') diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index a14fc309d140..777388cc8221 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1872,7 +1872,7 @@ sub get_grub2_index { $grub_number++; $found = 1; last; - } elsif (/^menuentry\s/) { + } elsif (/^menuentry\s|^submenu\s/) { $grub_number++; } } -- cgit v1.2.3-59-g8ed1b