1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-02 14:22:51 +03:00

WL #5680 MTR results written to file with well defined format

Added --result-file option, which will produce var/mtr-results.txt
Output has a simple format:

<tag> : <value>  for general info on test run
{
  <tag> : <value>
  ....
}                for each test

Output from failed tests are included but may be truncated.
See WL for more details.
This commit is contained in:
Bjorn Munch
2011-05-09 16:07:43 +02:00
parent 4f3c366e58
commit cb15b0712d
5 changed files with 276 additions and 6 deletions

View File

@ -1,5 +1,5 @@
# -*- cperl -*-
# Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc.
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@ use Carp;
use My::Platform;
use File::Temp qw/ tempfile tempdir /;
use mtr_results;
my $hint_mysqld; # Last resort guess for executable path
@ -80,7 +81,7 @@ sub _gdb {
return if $? >> 8;
return unless $gdb_output;
print <<EOF, $gdb_output, "\n";
resfile_print <<EOF, $gdb_output, "\n";
Output from gdb follows. The first stack trace is from the failing thread.
The following stack traces are from all threads (so the failing one is
duplicated).
@ -124,7 +125,7 @@ sub _dbx {
return if $? >> 8;
return unless $dbx_output;
print <<EOF, $dbx_output, "\n";
resfile_print <<EOF . $dbx_output . "\n";
Output from dbx follows. Stack trace is printed for all threads in order,
above this you should see info about which thread was the failing one.
----------------------------
@ -244,7 +245,7 @@ sub _cdb {
$cdb_output=~ s/^Child\-SP RetAddr Call Site//gm;
$cdb_output=~ s/\+0x([0-9a-fA-F]+)//gm;
print <<EOF, $cdb_output, "\n";
resfile_print <<EOF, $cdb_output, "\n";
Output from cdb follows. Faulting thread is printed twice,with and without function parameters
Search for STACK_TEXT to see the stack trace of
the faulting thread. Callstacks of other threads are printed after it.

View File

@ -1,6 +1,6 @@
# -*- cperl -*-
# Copyright (C) 2008 MySQL AB
#
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
@ -23,6 +23,7 @@ package My::Test;
use strict;
use warnings;
use Carp;
use mtr_results;
sub new {
@ -66,9 +67,26 @@ sub is_failed {
}
my %result_names= (
'MTR_RES_PASSED' => 'pass',
'MTR_RES_FAILED' => 'fail',
'MTR_RES_SKIPPED' => 'skipped',
);
sub write_test {
my ($test, $sock, $header)= @_;
if ($::opt_resfile && defined $test->{'result'}) {
resfile_test_info("result", $result_names{$test->{'result'}});
if ($test->{'timeout'}) {
resfile_test_info("comment", "Timeout");
} elsif (defined $test->{'comment'}) {
resfile_test_info("comment", $test->{'comment'});
}
resfile_test_info("result", "warning") if defined $test->{'check'};
resfile_to_test($test);
}
# Give the test a unique key before serializing it
$test->{key}= "$test" unless defined $test->{key};
@ -113,6 +131,7 @@ sub read_test {
$test->{$key}= _decode($value);
}
}
resfile_from_test($test) if $::opt_resfile;
return $test;
}

View File

@ -34,6 +34,7 @@ use My::Platform;
use POSIX qw[ _exit ];
use IO::Handle qw[ flush ];
require "mtr_io.pl";
use mtr_results;
my $tot_real_time= 0;
@ -96,6 +97,7 @@ sub mtr_report_test_passed ($) {
{
$timer_str= mtr_fromfile("$::opt_vardir/log/timer");
$tinfo->{timer}= $timer_str;
resfile_test_info('duration', $timer_str) if $::opt_resfile;
}
# Big warning if status already set
@ -301,6 +303,7 @@ sub mtr_report_stats ($$;$) {
time - $BASETIME, "seconds executing testcases");
}
resfile_global("duration", time - $BASETIME) if $::opt_resfile;
my $warnlog= "$::opt_vardir/log/warnings";
if ( -f $warnlog )

View File

@ -0,0 +1,167 @@
# -*- cperl -*-
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package mtr_results;
use strict;
use IO::Handle qw[ flush ];
use base qw(Exporter);
our @EXPORT= qw(resfile_init resfile_global resfile_new_test resfile_test_info
resfile_output resfile_output_file resfile_print
resfile_print_test resfile_to_test resfile_from_test );
my %curr_result; # Result for current test
my $curr_output; # Output for current test
my $do_resfile;
END {
close RESF if $do_resfile;
}
sub resfile_init($)
{
my $fname= shift;
open (RESF, " > $fname") or die ("Could not open result file $fname");
%curr_result= ();
$curr_output= "";
$do_resfile= 1;
}
# Strings need to be quoted if they start with white space or ",
# or if they contain newlines. Pass a reference to the string.
# If the string is quoted, " must be escaped, thus \ also must be escaped
sub quote_value($)
{
my $stref= shift;
for ($$stref) {
return unless /^[\s"]/ or /\n/;
s/\\/\\\\/g;
s/"/\\"/g;
$_= '"' . $_ . '"';
}
}
# Output global variable setting to result file.
sub resfile_global($$)
{
return unless $do_resfile;
my ($tag, $val) = @_;
$val= join (' ', @$val) if ref($val) eq 'ARRAY';
quote_value(\$val);
print RESF "$tag : $val\n";
}
# Prepare to add results for new test
sub resfile_new_test()
{
%curr_result= ();
$curr_output= "";
}
# Add (or change) one variable setting for current test
sub resfile_test_info($$)
{
my ($tag, $val) = @_;
return unless $do_resfile;
quote_value(\$val);
$curr_result{$tag} = $val;
}
# Add to output value for current test.
# Will be quoted if necessary, truncated if length over 5000.
sub resfile_output($)
{
return unless $do_resfile;
for (shift) {
my $len= length;
if ($len > 5000) {
my $trlen= $len - 5000;
$_= substr($_, 0, 5000) . "\n[TRUNCATED $trlen chars removed]\n";
}
s/\\/\\\\/g;
s/"/\\"/g;
$curr_output .= $_;
}
}
# Add to output, read from named file
sub resfile_output_file($)
{
resfile_output(::mtr_grab_file(shift)) if $do_resfile;
}
# Print text, and also append to current output if we're collecting results
sub resfile_print($)
{
my $txt= shift;
print($txt);
resfile_output($txt) if $do_resfile;
}
# Print results for current test, then reset
# (So calling a second time without having generated new results
# will have no effect)
sub resfile_print_test()
{
return unless %curr_result;
print RESF "{\n";
while (my ($t, $v) = each %curr_result) {
print RESF "$t : $v\n";
}
if ($curr_output) {
chomp($curr_output);
print RESF " output : " . $curr_output . "\"\n";
}
print RESF "}\n";
IO::Handle::flush(\*RESF);
resfile_new_test();
}
# Add current test results to test object (to send from worker)
sub resfile_to_test($)
{
return unless $do_resfile;
my $tinfo= shift;
my @res_array= %curr_result;
$tinfo->{'resfile'}= \@res_array;
$tinfo->{'output'}= $curr_output if $curr_output;
}
# Get test results (from worker) from test object
sub resfile_from_test($)
{
return unless $do_resfile;
my $tinfo= shift;
my $res_array= $tinfo->{'resfile'};
return unless $res_array;
%curr_result= @$res_array;
$curr_output= $tinfo->{'output'} if defined $tinfo->{'output'};
}
1;