diff options
Diffstat (limited to 'mysql-test/lib')
26 files changed, 490 insertions, 111 deletions
diff --git a/mysql-test/lib/My/ConfigFactory.pm b/mysql-test/lib/My/ConfigFactory.pm index 8fb0e27eb77..e672b094405 100644 --- a/mysql-test/lib/My/ConfigFactory.pm +++ b/mysql-test/lib/My/ConfigFactory.pm @@ -1,4 +1,20 @@ # -*- cperl -*- +# 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 Library 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 +# Library 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 My::ConfigFactory; use strict; @@ -130,7 +146,11 @@ sub fix_tmpdir { sub fix_log_error { my ($self, $config, $group_name, $group)= @_; my $dir= $self->{ARGS}->{vardir}; - return "$dir/log/$group_name.err"; + if ( $::opt_valgrind and $::opt_debug ) { + return "$dir/log/$group_name.trace"; + } else { + return "$dir/log/$group_name.err"; + } } sub fix_log { diff --git a/mysql-test/lib/My/CoreDump.pm b/mysql-test/lib/My/CoreDump.pm index 3ac9e385070..b0c4a1337d8 100644 --- a/mysql-test/lib/My/CoreDump.pm +++ b/mysql-test/lib/My/CoreDump.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 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 @@ -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. diff --git a/mysql-test/lib/My/File/Path.pm b/mysql-test/lib/My/File/Path.pm index 6e6d23ad9f0..14fb43e8d98 100644 --- a/mysql-test/lib/My/File/Path.pm +++ b/mysql-test/lib/My/File/Path.pm @@ -1,4 +1,19 @@ # -*- cperl -*- +# Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc. +# +# 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 My::File::Path; use strict; diff --git a/mysql-test/lib/My/Find.pm b/mysql-test/lib/My/Find.pm index b2fec0d77b8..9d1d2915012 100644 --- a/mysql-test/lib/My/Find.pm +++ b/mysql-test/lib/My/Find.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (c) 2004, 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 @@ -28,8 +28,6 @@ use My::Platform; use base qw(Exporter); our @EXPORT= qw(my_find_bin my_find_dir my_find_file NOT_REQUIRED); -our $vs_config_dir; - my $bin_extension= ".exe" if IS_WINDOWS; # Helper function to be used for fourth parameter to find functions @@ -158,7 +156,7 @@ sub my_find_paths { # User can select to look in a special build dir # which is a subdirectory of any of the paths my @extra_dirs; - my $build_dir= $vs_config_dir || $ENV{MTR_VS_CONFIG} || $ENV{MTR_BUILD_DIR}; + my $build_dir= $::opt_vs_config || $ENV{MTR_VS_CONFIG} || $ENV{MTR_BUILD_DIR}; push(@extra_dirs, $build_dir) if defined $build_dir; if (defined $extension){ diff --git a/mysql-test/lib/My/Options.pm b/mysql-test/lib/My/Options.pm index 3bfbe1fc90e..dcd934084e2 100644 --- a/mysql-test/lib/My/Options.pm +++ b/mysql-test/lib/My/Options.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (C) 2008 MySQL AB # # 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 diff --git a/mysql-test/lib/My/Platform.pm b/mysql-test/lib/My/Platform.pm index 371120ab644..cbe8f929d71 100644 --- a/mysql-test/lib/My/Platform.pm +++ b/mysql-test/lib/My/Platform.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc. # # 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 diff --git a/mysql-test/lib/My/SafeProcess.pm b/mysql-test/lib/My/SafeProcess.pm index 59186f50703..45a37c35ded 100644 --- a/mysql-test/lib/My/SafeProcess.pm +++ b/mysql-test/lib/My/SafeProcess.pm @@ -1,14 +1,15 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 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. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library 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. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library 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 @@ -138,6 +139,7 @@ sub new { my $host = delete($opts{'host'}); my $shutdown = delete($opts{'shutdown'}); my $user_data= delete($opts{'user_data'}); + my $envs = delete($opts{'envs'}); # if (defined $host) { # $safe_script= "lib/My/SafeProcess/safe_process_cpcd.pl"; @@ -160,6 +162,13 @@ sub new { # Point the safe_process at the right parent if running on cygwin push(@safe_args, "--parent-pid=".Cygwin::pid_to_winpid($$)) if IS_CYGWIN; + foreach my $env_var (@$envs) { + croak("Missing = in env string") unless $env_var =~ /=/; + croak("Env string $env_var seen, probably missing value for --mysqld-env") + if $env_var =~ /^--/; + push @safe_args, "--env $env_var"; + } + push(@safe_args, "--"); push(@safe_args, $path); # The program safe_process should execute diff --git a/mysql-test/lib/My/SafeProcess/Base.pm b/mysql-test/lib/My/SafeProcess/Base.pm index 9a6871264b8..c0c70e48082 100644 --- a/mysql-test/lib/My/SafeProcess/Base.pm +++ b/mysql-test/lib/My/SafeProcess/Base.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc. # # 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 diff --git a/mysql-test/lib/My/SafeProcess/Makefile.am b/mysql-test/lib/My/SafeProcess/Makefile.am deleted file mode 100644 index 33cab066611..00000000000 --- a/mysql-test/lib/My/SafeProcess/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2000-2006 MySQL AB -# -# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -testroot = $(prefix) -safedir = $(testroot)/mysql-test/lib/My/SafeProcess -#nobase_bin_PROGRAMS = ... -safe_PROGRAMS = my_safe_process - -my_safe_process_SOURCES = safe_process.cc - -EXTRA_DIST = safe_kill_win.cc \ - safe_process_win.cc \ - CMakeLists.txt diff --git a/mysql-test/lib/My/SafeProcess/safe_kill_win.cc b/mysql-test/lib/My/SafeProcess/safe_kill_win.cc index f72b851d0b6..72fe874e621 100644 --- a/mysql-test/lib/My/SafeProcess/safe_kill_win.cc +++ b/mysql-test/lib/My/SafeProcess/safe_kill_win.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 MySQL AB +/* Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc. 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 diff --git a/mysql-test/lib/My/SafeProcess/safe_process.cc b/mysql-test/lib/My/SafeProcess/safe_process.cc index 12b335ec444..2f90b65f62e 100644 --- a/mysql-test/lib/My/SafeProcess/safe_process.cc +++ b/mysql-test/lib/My/SafeProcess/safe_process.cc @@ -1,4 +1,4 @@ -/* 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 @@ -176,7 +176,7 @@ int main(int argc, char* const argv[] ) } else { if ( strcmp(arg, "--verbose") == 0 ) verbose++; - else if ( strncmp(arg, "--parent-pid", 10) == 0 ) + else if ( strncmp(arg, "--parent-pid", 12) == 0 ) { /* Override parent_pid with a value provided by user */ const char* start; @@ -185,10 +185,15 @@ int main(int argc, char* const argv[] ) start++; /* Step past = */ if ((parent_pid= atoi(start)) == 0) die("Invalid value '%s' passed to --parent-id", start); - } else if ( strcmp(arg, "--nocore") == 0 ) + } + else if ( strcmp(arg, "--nocore") == 0 ) { nocore = true; // Don't allow the process to dump core } + else if ( strncmp (arg, "--env ", 6) == 0 ) + { + putenv(strdup(arg+6)); + } else die("Unknown option: %s", arg); } diff --git a/mysql-test/lib/My/SafeProcess/safe_process.pl b/mysql-test/lib/My/SafeProcess/safe_process.pl index e3114a749d3..54b0073f8df 100644 --- a/mysql-test/lib/My/SafeProcess/safe_process.pl +++ b/mysql-test/lib/My/SafeProcess/safe_process.pl @@ -94,7 +94,7 @@ eval { local $SIG{INT}= \&handle_signal; local $SIG{CHLD}= sub { message("Got signal @_"); - kill(9, -$child_pid); + kill('KILL', -$child_pid); my $ret= waitpid($child_pid, 0); if ($? & 127){ exit(65); # Killed by signal @@ -134,7 +134,7 @@ if ( $@ ) { # Use negative pid in order to kill the whole # process group # -my $ret= kill(9, -$child_pid); +my $ret= kill('KILL', -$child_pid); message("Killed child: $child_pid, ret: $ret"); if ($ret > 0) { message("Killed child: $child_pid"); diff --git a/mysql-test/lib/My/SafeProcess/safe_process_win.cc b/mysql-test/lib/My/SafeProcess/safe_process_win.cc index 8fffede0b62..7e0ae68b4de 100644 --- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc +++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 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 @@ -220,6 +220,10 @@ int main(int argc, const char** argv ) { nocore= TRUE; } + else if ( strncmp (arg, "--env ", 6) == 0 ) + { + putenv(strdup(arg+6)); + } else die("Unknown option: %s", arg); } diff --git a/mysql-test/lib/My/SysInfo.pm b/mysql-test/lib/My/SysInfo.pm index f1ba5fb610f..b8569e415e8 100644 --- a/mysql-test/lib/My/SysInfo.pm +++ b/mysql-test/lib/My/SysInfo.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (C) 2008 MySQL AB # # 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 diff --git a/mysql-test/lib/My/Test.pm b/mysql-test/lib/My/Test.pm index c8bfbd34521..f9eed945e41 100644 --- a/mysql-test/lib/My/Test.pm +++ b/mysql-test/lib/My/Test.pm @@ -1,4 +1,18 @@ # -*- cperl -*- +# 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. +# +# 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 # @@ -10,6 +24,7 @@ use strict; use warnings; use Carp; use Storable(); +use mtr_results; sub new { @@ -47,9 +62,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}; @@ -67,8 +99,8 @@ sub read_test { my $test= Storable::thaw($serialized); die "wrong class (hack attempt?)" unless ref($test) eq 'My::Test'; + resfile_from_test($test) if $::opt_resfile; return $test; } - 1; diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm index 631a5d8c348..5b091193bff 100644 --- a/mysql-test/lib/mtr_cases.pm +++ b/mysql-test/lib/mtr_cases.pm @@ -1,6 +1,6 @@ # -*- cperl -*- -# Copyright (C) 2005-2006 MySQL AB -# +# Copyright (c) 2005, 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. @@ -130,7 +130,7 @@ sub collect_test_cases ($$$$) { { last unless $opt_reorder; # test->{name} is always in suite.name format - if ( $test->{name} =~ /.*\.$tname/ ) + if ( $test->{name} =~ /^$sname.*\.$tname$/ ) { $found= 1; last; @@ -157,8 +157,6 @@ sub collect_test_cases ($$$$) { if ( $opt_reorder && !$quick_collect) { # Reorder the test cases in an order that will make them faster to run - my %sort_criteria; - # Make a mapping of test name to a string that represents how that test # should be sorted among the other tests. Put the most important criterion # first, then a sub-criterion, then sub-sub-criterion, etc. @@ -170,24 +168,31 @@ sub collect_test_cases ($$$$) { # Append the criteria for sorting, in order of importance. # push(@criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "A" : "B")); + push(@criteria, $tinfo->{template_path}); # Group test with equal options together. # Ending with "~" makes empty sort later than filled my $opts= $tinfo->{'master_opt'} ? $tinfo->{'master_opt'} : []; push(@criteria, join("!", sort @{$opts}) . "~"); + # Add slave opts if any + if ($tinfo->{'slave_opt'}) + { + push(@criteria, join("!", sort @{$tinfo->{'slave_opt'}})); + } + # This sorts tests with force-restart *before* identical tests + push(@criteria, $tinfo->{force_restart} ? "force-restart" : "no-restart"); - $sort_criteria{$tinfo->fullname()} = join(" ", @criteria); + $tinfo->{criteria}= join(" ", @criteria); } - @$cases = sort { - $sort_criteria{$a->fullname()} . $a->fullname() cmp - $sort_criteria{$b->fullname()} . $b->fullname() } @$cases; + @$cases = sort {$a->{criteria} cmp $b->{criteria}; } @$cases; # For debugging the sort-order # foreach my $tinfo (@$cases) # { - # print $sort_criteria{$tinfo->fullname()}," -> \t",$tinfo->fullname(),"\n"; + # my $tname= $tinfo->{name} . ' ' . $tinfo->{combination}; + # my $crit= $tinfo->{criteria}; + # print("$tname\n\t$crit\n"); # } - } if (defined $print_testcases){ @@ -204,8 +209,11 @@ sub collect_test_cases ($$$$) { sub split_testname { my ($test_name)= @_; - # Get rid of directory part and split name on .'s - my @parts= split(/\./, basename($test_name)); + # If .test file name is used, get rid of directory part + $test_name= basename($test_name) if $test_name =~ /\.test$/; + + # Now split name on .'s + my @parts= split(/\./, $test_name); if (@parts == 1){ # Only testname given, ex: alias @@ -259,9 +267,11 @@ sub collect_one_suite "mysql-test/suite", "mysql-test", # Look in storage engine specific suite dirs - "storage/*/mysql-test-suites" + "storage/*/mtr", + # Look in plugin specific suite dir + "plugin/$suite/tests", ], - [$suite]); + [$suite, "mtr"]); } mtr_verbose("suitedir: $suitedir"); } diff --git a/mysql-test/lib/mtr_gcov.pl b/mysql-test/lib/mtr_gcov.pl index 2f211b7566d..a6e1f8efd5f 100644 --- a/mysql-test/lib/mtr_gcov.pl +++ b/mysql-test/lib/mtr_gcov.pl @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004, 2006 MySQL AB +# Copyright (c) 2004, 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 @@ -33,7 +33,7 @@ sub gcov_prepare ($) { # # Collect gcov statistics. # Arguments: -# $dir basedir, normally source directory +# $dir basedir, normally build directory # $gcov gcov utility program [path] name # $gcov_msg message file name # $gcov_err error file name @@ -45,31 +45,26 @@ sub gcov_collect ($$$) { my $start_dir= cwd(); print "Collecting source coverage info using '$gcov'...$basedir\n"; - -f "$start_dir/$gcov_msg" and unlink("$start_dir/$gcov_msg"); - -f "$start_dir/$gcov_err" and unlink("$start_dir/$gcov_err"); + -f "$dir/$gcov_msg" and unlink("$dir/$gcov_msg"); + -f "$dir/$gcov_err" and unlink("$dir/$gcov_err"); my @dirs= `find "$dir" -type d -print | sort`; #print "List of directories:\n@dirs\n"; foreach my $d ( @dirs ) { - my $dir_reported= 0; chomp($d); chdir($d) or next; - foreach my $f ( (glob("*.h"), glob("*.cc"), glob("*.c")) ) { - $f =~ /(.*)\.[ch]c?/; - -f "$1.gcno" or next; - if (!$dir_reported) { - print "Collecting in '$d'...\n"; - $dir_reported= 1; - } - system("$gcov $f 2>>$start_dir/$gcov_err >>$start_dir/$gcov_msg"); - system("perl", "$basedir/mysql-test/lib/process-purecov-annotations.pl", "$f.gcov"); + my @flist= glob("*.*.gcno"); + print ("Collecting in '$d'...\n") if @flist; + foreach my $f (@flist) { + system("$gcov $f 2>>$dir/$gcov_err >>$dir/$gcov_msg"); + system("perl", "$basedir/mysql-test/lib/process-purecov-annotations.pl", "$f.gcov"); } chdir($start_dir); } - print "gcov info in $gcov_msg, errors in $gcov_err\n"; + print "gcov info in $dir/$gcov_msg, errors in $dir/$gcov_err\n"; } diff --git a/mysql-test/lib/mtr_gprof.pl b/mysql-test/lib/mtr_gprof.pl index 5820a4007b8..a5e05b28723 100644 --- a/mysql-test/lib/mtr_gprof.pl +++ b/mysql-test/lib/mtr_gprof.pl @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004 MySQL AB +# Copyright (C) 2004 MySQL AB, 2009 Sun Microsystems, Inc. # # 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 diff --git a/mysql-test/lib/mtr_io.pl b/mysql-test/lib/mtr_io.pl index 21581798ddc..6a6b3a3d028 100644 --- a/mysql-test/lib/mtr_io.pl +++ b/mysql-test/lib/mtr_io.pl @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (C) 2004-2007 MySQL AB, 2008 Sun Microsystems, Inc. # # 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 diff --git a/mysql-test/lib/mtr_match.pm b/mysql-test/lib/mtr_match.pm index 40afd4e0336..6fc9832ac43 100644 --- a/mysql-test/lib/mtr_match.pm +++ b/mysql-test/lib/mtr_match.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (C) 2004-2008 MySQL AB # # 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 diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl index 388d252502a..83b02525ad1 100644 --- a/mysql-test/lib/mtr_misc.pl +++ b/mysql-test/lib/mtr_misc.pl @@ -1,15 +1,16 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB -# -# 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. -# +# Copyright (c) 2004, 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 Library 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. -# +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library 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 @@ -30,9 +31,18 @@ sub mtr_script_exists(@); sub mtr_file_exists(@); sub mtr_exe_exists(@); sub mtr_exe_maybe_exists(@); +sub mtr_compress_file($); sub mtr_milli_sleep($); sub start_timer($); sub has_expired($); +sub init_timers(); +sub mark_time_used($); +sub mark_time_idle(); +sub add_total_times($); +sub print_times_used($$); +sub print_total_times($); + +our $opt_report_times; ############################################################################## # @@ -190,6 +200,40 @@ sub mtr_exe_exists (@) { } } +# +# Try to compress file using tools that might be available. +# If zip/gzip is not available, just silently ignore. +# + +sub mtr_compress_file ($) { + my ($filename)= @_; + + mtr_error ("File to compress not found: $filename") unless -f $filename; + + my $did_compress= 0; + + if (IS_WINDOWS) + { + # Capture stderr + my $ziperr= `zip $filename.zip $filename 2>&1`; + if ($?) { + print "$ziperr\n" if $ziperr !~ /recognized as an internal or external/; + } else { + unlink($filename); + $did_compress=1; + } + } + else + { + my $gzres= system("gzip $filename"); + $did_compress= ! $gzres; + if ($gzres && $gzres != -1) { + mtr_error ("Error: have gzip but it fails to compress core file"); + } + } + mtr_print("Compressed file $filename") if $did_compress; +} + sub mtr_milli_sleep ($) { die "usage: mtr_milli_sleep(milliseconds)" unless @_ == 1; @@ -225,4 +269,87 @@ sub start_timer ($) { return time + $_[0]; } sub has_expired ($) { return $_[0] && time gt $_[0]; } +# Below code is for time usage reporting + +use Time::HiRes qw(gettimeofday); + +my %time_used= ( + 'collect' => 0, + 'restart' => 0, + 'check' => 0, + 'ch-warn' => 0, + 'test' => 0, + 'init' => 0, + 'admin' => 0, +); + +my %time_text= ( + 'collect' => "Collecting test cases", + 'restart' => "Server stop/start", + 'check' => "Check-testcase", + 'ch-warn' => "Check for warnings", + 'test' => "Test execution", + 'init' => "Initialization/cleanup", + 'admin' => "Test administration", +); + +# Counts number of reports from workers + +my $time_totals= 0; + +my $last_timer_set; + +sub init_timers() { + $last_timer_set= gettimeofday(); +} + +sub mark_time_used($) { + my ($name)= @_; + return unless $opt_report_times; + die "Unknown timer $name" unless exists $time_used{$name}; + + my $curr_time= gettimeofday(); + $time_used{$name}+= int (($curr_time - $last_timer_set) * 1000 + .5); + $last_timer_set= $curr_time; +} + +sub mark_time_idle() { + $last_timer_set= gettimeofday() if $opt_report_times; +} + +sub add_total_times($) { + my ($dummy, $num, @line)= split (" ", $_[0]); + + $time_totals++; + foreach my $elem (@line) { + my ($name, $spent)= split (":", $elem); + $time_used{$name}+= $spent; + } +} + +sub print_times_used($$) { + my ($server, $num)= @_; + return unless $opt_report_times; + + my $output= "SPENT $num"; + foreach my $name (keys %time_used) { + my $spent= $time_used{$name}; + $output.= " $name:$spent"; + } + print $server $output . "\n"; +} + +sub print_total_times($) { + # Don't print if we haven't received all worker data + return if $time_totals != $_[0]; + + foreach my $name (keys %time_used) + { + my $spent= $time_used{$name}/1000; + my $text= $time_text{$name}; + print ("Spent $spent seconds on $text\n"); + } +} + + 1; diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl index a42627c93cd..88e714f6f8d 100644 --- a/mysql-test/lib/mtr_process.pl +++ b/mysql-test/lib/mtr_process.pl @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2004-2006 MySQL AB +# Copyright (c) 2004, 2010, 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 @@ -116,18 +116,20 @@ sub sleep_until_file_created ($$$) { return 1; } + my $seconds= ($loop * $sleeptime) / 1000; + # Check if it died after the fork() was successful if ( defined $proc and ! $proc->wait_one(0) ) { - mtr_warning("Process $proc died"); + mtr_warning("Process $proc died after mysql-test-run waited $seconds " . + "seconds for $pidfile to be created."); return 0; } mtr_debug("Sleep $sleeptime milliseconds waiting for $pidfile"); # Print extra message every 60 seconds - my $seconds= ($loop * $sleeptime) / 1000; - if ( $seconds > 1 and int($seconds * 10) % 600 == 0 ) + if ( $seconds > 1 && int($seconds * 10) % 600 == 0 && $seconds < $timeout ) { my $left= $timeout - $seconds; mtr_warning("Waited $seconds seconds for $pidfile to be created, " . @@ -138,6 +140,8 @@ sub sleep_until_file_created ($$$) { } + mtr_warning("Timeout after mysql-test-run waited $timeout seconds " . + "for the process $proc to create a pid file."); return 0; } diff --git a/mysql-test/lib/mtr_report.pm b/mysql-test/lib/mtr_report.pm index a90c367178d..189ed19d801 100644 --- a/mysql-test/lib/mtr_report.pm +++ b/mysql-test/lib/mtr_report.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright 2004-2008 MySQL AB, 2008 Sun Microsystems, Inc. +# Copyright (c) 2004, 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 @@ -32,7 +32,9 @@ our @EXPORT= qw(report_option mtr_print_line mtr_print_thick_line use mtr_match; use My::Platform; use POSIX qw[ _exit ]; +use IO::Handle qw[ flush ]; require "mtr_io.pl"; +use mtr_results; my $tot_real_time= 0; @@ -68,7 +70,7 @@ sub _mtr_report_test_name ($) { print _name(). _timestamp(); printf "%-40s ", $tname; my $worker = $tinfo->{worker}; - printf "w$worker " if $worker; + print "w$worker " if defined $worker; return $tname; } @@ -91,6 +93,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 @@ -125,7 +128,8 @@ sub mtr_report_test ($) { # Find out if this test case is an experimental one, so we can treat # the failure as an expected failure instead of a regression. for my $exp ( @$::experimental_test_cases ) { - if ( $exp ne $test_name ) { + # Include pattern match for combinations + if ( $exp ne $test_name && $test_name !~ /^$exp / ) { # if the expression is not the name of this test case, but has # an asterisk at the end, determine if the characters up to # but excluding the asterisk are the same @@ -228,7 +232,8 @@ sub mtr_report_stats ($$$$) { # Find out how we where doing # ---------------------------------------------------------------------- - my $tot_skiped= 0; + my $tot_skipped= 0; + my $tot_skipdetect= 0; my $tot_passed= 0; my $tot_failed= 0; my $tot_tests= 0; @@ -245,8 +250,9 @@ sub mtr_report_stats ($$$$) { } elsif ( $tinfo->{'result'} eq 'MTR_RES_SKIPPED' ) { - # Test was skipped - $tot_skiped++; + # Test was skipped (disabled not counted) + $tot_skipped++ unless $tinfo->{'disable'}; + $tot_skipdetect++ if $tinfo->{'skip_detected_by_test'}; } elsif ( $tinfo->{'result'} eq 'MTR_RES_PASSED' ) { @@ -296,6 +302,8 @@ sub mtr_report_stats ($$$$) { time - $BASETIME, "seconds executing testcases"); } + resfile_global("duration", time - $BASETIME) if $::opt_resfile; + my $warnlog= "$::opt_vardir/log/warnings"; if ( ! $::glob_use_running_server && !$::opt_extern && -f $warnlog) { @@ -382,6 +390,9 @@ MSG print " $_\n" for @$extra_warnings; } + print "$tot_skipped tests were skipped, ". + "$tot_skipdetect by the test itself.\n\n" if $tot_skipped; + if ( $tot_failed != 0 || $found_problems) { mtr_error("there were failing test cases"); @@ -404,7 +415,7 @@ MSG ############################################################################## sub mtr_print_line () { - print '-' x 60 . "\n"; + print '-' x 74 . "\n"; } @@ -414,13 +425,18 @@ sub mtr_print_thick_line { } -sub mtr_print_header () { +sub mtr_print_header ($) { + my ($wid) = @_; print "\n"; printf "TEST"; - print " " x 38; + if ($wid) { + print " " x 34 . "WORKER "; + } else { + print " " x 38; + } print "RESULT "; - print "TIME (ms)" if $timer; - print "\n"; + print "TIME (ms) or " if $timer; + print "COMMENT\n"; mtr_print_line(); print "\n"; } @@ -490,6 +506,7 @@ sub mtr_warning (@) { # Print error to screen and then exit sub mtr_error (@) { + IO::Handle::flush(\*STDOUT) if IS_WINDOWS; print STDERR _name(). _timestamp(). "mysql-test-run: *** ERROR: ". join(" ", @_). "\n"; if (IS_WINDOWS) diff --git a/mysql-test/lib/mtr_results.pm b/mysql-test/lib/mtr_results.pm new file mode 100644 index 00000000000..92b03756c04 --- /dev/null +++ b/mysql-test/lib/mtr_results.pm @@ -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; diff --git a/mysql-test/lib/mtr_stress.pl b/mysql-test/lib/mtr_stress.pl index 702bc178ae5..ab4214791d0 100644 --- a/mysql-test/lib/mtr_stress.pl +++ b/mysql-test/lib/mtr_stress.pl @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2006 MySQL AB +# Copyright (C) 2004-2007 MySQL AB, 2009 Sun Microsystems, Inc. # # 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 diff --git a/mysql-test/lib/mtr_unique.pm b/mysql-test/lib/mtr_unique.pm index 6b60157422d..506af448266 100644 --- a/mysql-test/lib/mtr_unique.pm +++ b/mysql-test/lib/mtr_unique.pm @@ -1,5 +1,5 @@ # -*- cperl -*- -# Copyright (C) 2006 MySQL AB +# Copyright (C) 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc. # # 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 |