Commit 9fd8f1b2 authored by Sergei Golubchik's avatar Sergei Golubchik

mtr: update titlebar when the test ends, not when it starts

otherwise it reaches "0 tests left" state and then waits for
a few minutes  for all workers to complete their tests.

show failures. account for retries.
parent e64dc071
......@@ -37,8 +37,20 @@ use My::Platform;
use POSIX qw[ _exit ];
use IO::Handle qw[ flush ];
use mtr_results;
use Term::ANSIColor;
use English;
my $tot_real_time= 0;
my $tests_done= 0;
my $tests_failed= 0;
our $timestamp= 0;
our $timediff= 0;
our $name;
our $verbose;
our $verbose_restart= 0;
our $timer= 1;
our $tests_total;
my %color_map = qw/pass green
retry-pass green
......@@ -47,20 +59,39 @@ my %color_map = qw/pass green
disabled bright_black
skipped yellow
reset reset/;
sub xterm_color {
if (-t STDOUT and defined $ENV{TERM} and $ENV{TERM} =~ /xterm/) {
syswrite STDOUT, color($color_map{$_[0]});
my $set_titlebar;
my $set_color= sub { };
if (-t STDOUT) {
if (IS_WINDOWS) {
eval {
require Win32::Console;
$set_titlebar = sub { &Win32::Console::Title($_[0]);};
}
} elsif ($ENV{TERM} =~ /xterm/) {
$set_titlebar = sub { syswrite STDOUT, "\e]0;$_[0]\a"; };
$set_color = sub { syswrite STDOUT, color($color_map{$_[0]}); }
}
}
my $tot_real_time= 0;
sub titlebar_stat($) {
our $timestamp= 0;
our $timediff= 0;
our $name;
our $verbose;
our $verbose_restart= 0;
our $timer= 1;
sub time_format($) {
sprintf '%d:%02d:%02d', $_[0]/3600, ($_[0]/60)%60, $_[0]%60;
}
$tests_done++;
$tests_failed++ if $_[0] =~ /fail/;
$tests_total++ if $_[0] =~ /retry/;
my $spent = time - $BASETIME;
my $left = $tests_total - $tests_done;
&$set_titlebar(sprintf "mtr: spent %s on %d tests. %s (%d tests) left, %d failed",
time_format($spent), $tests_done,
time_format($spent/$tests_done * $left), $left, $tests_failed);
}
sub report_option {
my ($opt, $value)= @_;
......@@ -321,8 +352,6 @@ sub mtr_report_stats ($$$$) {
if ( $timer )
{
use English;
mtr_report("Spent", sprintf("%.3f", $tot_real_time),"of",
time - $BASETIME, "seconds executing testcases");
}
......@@ -620,10 +649,11 @@ sub mtr_report (@) {
my @s = split /\[ (\S+) \]/, _name() . "@_\n";
if (@s > 1) {
print $s[0];
xterm_color($s[1]);
&$set_color($s[1]);
print "[ $s[1] ]";
xterm_color('reset');
&$set_color('reset');
print $s[2];
titlebar_stat($s[1]) if $set_titlebar;
} else {
print $s[0];
}
......
......@@ -369,32 +369,6 @@ my $opt_stop_keep_alive= $ENV{MTR_STOP_KEEP_ALIVE};
select(STDOUT);
$| = 1; # Automatically flush STDOUT
my $set_titlebar;
BEGIN {
if (IS_WINDOWS) {
my $have_win32_console= 0;
eval {
require Win32::Console;
Win32::Console->import();
$have_win32_console = 1;
};
eval 'sub HAVE_WIN32_CONSOLE { $have_win32_console }';
} else {
eval 'sub HAVE_WIN32_CONSOLE { 0 }';
}
}
if (-t STDOUT) {
if (IS_WINDOWS and HAVE_WIN32_CONSOLE) {
$set_titlebar = sub {Win32::Console::Title $_[0];};
} elsif (defined $ENV{TERM} and $ENV{TERM} =~ /xterm/) {
$set_titlebar = sub { syswrite STDOUT, "\e];$_[0]\a"; };
}
}
main();
sub have_wsrep() {
......@@ -632,7 +606,7 @@ sub main {
}
#######################################################################
my $num_tests= @$tests;
my $num_tests= $mtr_report::tests_total= @$tests;
if ( $opt_parallel eq "auto" ) {
# Try to find a suitable value for number of workers
if (IS_WINDOWS)
......@@ -1073,8 +1047,6 @@ sub run_test_server ($$$) {
delete $next->{reserved};
}
titlebar_stat(scalar(@$tests)) if $set_titlebar;
if ($next) {
# We don't need this any more
delete $next->{criteria};
......@@ -6666,23 +6638,3 @@ sub list_options ($) {
exit(1);
}
sub time_format($) {
sprintf '%d:%02d:%02d', $_[0]/3600, ($_[0]/60)%60, $_[0]%60;
}
our $num_tests;
sub titlebar_stat {
my ($left) = @_;
# 2.5 -> best by test
$num_tests = $left + 2.5 unless $num_tests;
my $done = $num_tests - $left;
my $spent = time - $^T;
&$set_titlebar(sprintf "mtr: spent %s on %d tests. %s (%d tests) left",
time_format($spent), $done,
time_format($spent/$done * $left), $left);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment