summaryrefslogtreecommitdiff
path: root/mysql-test/lib
diff options
context:
space:
mode:
authorBjorn Munch <Bjorn.Munch@sun.com>2010-02-22 14:52:11 +0100
committerBjorn Munch <Bjorn.Munch@sun.com>2010-02-22 14:52:11 +0100
commitac0d9be1962c71484dbbc16958e97e8ee368d8ea (patch)
tree5d8f58b7cdfa07f84d1ad9d29e8f802a03399c43 /mysql-test/lib
parent57a40848848274a83313f0d57bb184307e0ff87b (diff)
parentaa457a4aef6978e5621208d2b1d5240c8dd23c48 (diff)
downloadmariadb-git-ac0d9be1962c71484dbbc16958e97e8ee368d8ea.tar.gz
merge from 5.1-mtr
Diffstat (limited to 'mysql-test/lib')
-rw-r--r--mysql-test/lib/My/SafeProcess.pm133
-rwxr-xr-xmysql-test/lib/My/SafeProcess/safe_process_win.cc22
-rw-r--r--mysql-test/lib/mtr_cases.pm28
-rw-r--r--mysql-test/lib/mtr_gprof.pl45
-rw-r--r--mysql-test/lib/mtr_misc.pl13
-rw-r--r--mysql-test/lib/mtr_report.pm37
-rw-r--r--mysql-test/lib/mtr_stress.pl2
-rw-r--r--mysql-test/lib/v1/mtr_stress.pl2
-rwxr-xr-xmysql-test/lib/v1/mysql-test-run.pl5
9 files changed, 138 insertions, 149 deletions
diff --git a/mysql-test/lib/My/SafeProcess.pm b/mysql-test/lib/My/SafeProcess.pm
index 7e102b628ca..bfcad910a16 100644
--- a/mysql-test/lib/My/SafeProcess.pm
+++ b/mysql-test/lib/My/SafeProcess.pm
@@ -81,24 +81,28 @@ sub is_child {
}
-# Find the safe process binary or script
my @safe_process_cmd;
my $safe_kill;
-if (IS_WIN32PERL or IS_CYGWIN){
- # Use my_safe_process.exe
- my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
- "my_safe_process");
- push(@safe_process_cmd, $exe);
-
- # Use my_safe_kill.exe
- $safe_kill= my_find_bin(".", "lib/My/SafeProcess", "my_safe_kill");
-}
-else
-{
- # Use my_safe_process
- my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
- "my_safe_process");
- push(@safe_process_cmd, $exe);
+
+# Find the safe process binary or script
+sub find_bin {
+ if (IS_WIN32PERL or IS_CYGWIN)
+ {
+ # Use my_safe_process.exe
+ my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
+ "my_safe_process");
+ push(@safe_process_cmd, $exe);
+
+ # Use my_safe_kill.exe
+ $safe_kill= my_find_bin(".", "lib/My/SafeProcess", "my_safe_kill");
+ }
+ else
+ {
+ # Use my_safe_process
+ my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
+ "my_safe_process");
+ push(@safe_process_cmd, $exe);
+ }
}
@@ -184,63 +188,6 @@ sub run {
}
#
-# Start a process that returns after "duration" seconds
-# or when it's parent process does not exist anymore
-#
-sub timer {
- my $class= shift;
- my $duration= shift or croak "duration required";
- my $parent_pid= $$;
-
- my $pid= My::SafeProcess::Base::_safe_fork();
- if ($pid){
- # Parent
- my $proc= bless
- ({
- SAFE_PID => $pid,
- SAFE_NAME => "timer",
- PARENT => $$,
- }, $class);
-
- # Put the new process in list of running
- $running{$pid}= $proc;
- return $proc;
- }
-
- # Child, install signal handlers and sleep for "duration"
- $SIG{INT}= 'IGNORE';
-
- $SIG{TERM}= sub {
- #print STDERR "timer $$: woken up, exiting!\n";
- exit(0);
- };
-
- $0= "safe_timer($duration)";
-
- if (IS_WIN32PERL){
- # Just a thread in same process
- sleep($duration);
- print STDERR "timer $$: expired after $duration seconds\n";
- exit(0);
- }
-
- my $count_down= $duration;
- while($count_down--){
-
- # Check that parent is still alive
- if (kill(0, $parent_pid) == 0){
- #print STDERR "timer $$: parent gone, exiting!\n";
- exit(0);
- }
-
- sleep(1);
- }
- print STDERR "timer $$: expired after $duration seconds\n";
- exit(0);
-}
-
-
-#
# Shutdown process nicely, and wait for shutdown_timeout seconds
# If processes hasn't shutdown, kill them hard and wait for return
#
@@ -338,12 +285,12 @@ sub start_kill {
$ret= system($safe_kill, $winpid) >> 8;
if ($ret == 3){
- print "Couldn't open the winpid: $winpid ",
+ print "Couldn't open the winpid: $winpid ".
"for pid: $pid, try one more time\n";
sleep(1);
$winpid= _winpid($pid);
$ret= system($safe_kill, $winpid) >> 8;
- print "Couldn't open the winpid: $winpid ",
+ print "Couldn't open the winpid: $winpid ".
"for pid: $pid, continue and see what happens...\n";
}
}
@@ -538,6 +485,40 @@ sub wait_any {
#
+# Wait for any process to exit, or a timeout
+#
+# Returns a reference to the SafeProcess that
+# exited or a pseudo-process with $proc->{timeout} == 1
+#
+
+sub wait_any_timeout {
+ my $class= shift;
+ my $timeout= shift;
+ my $proc;
+ my $millis=10;
+
+ do {
+ ::mtr_milli_sleep($millis);
+ # Slowly increse interval up to max. 1 second
+ $millis++ if $millis < 1000;
+ # Return a "fake" process for timeout
+ if (::has_expired($timeout)) {
+ $proc= bless
+ ({
+ SAFE_PID => 0,
+ SAFE_NAME => "timer",
+ timeout => 1,
+ }, $class);
+ } else {
+ $proc= check_any();
+ }
+ } while (! $proc);
+
+ return $proc;
+}
+
+
+#
# Wait for all processes to exit
#
sub wait_all {
@@ -594,7 +575,7 @@ sub self2str {
sub _verbose {
return unless $_verbose;
- print STDERR " ## ", @_, "\n";
+ print STDERR " ## ". @_. "\n";
}
diff --git a/mysql-test/lib/My/SafeProcess/safe_process_win.cc b/mysql-test/lib/My/SafeProcess/safe_process_win.cc
index aa9093fb2b4..896bd599f4f 100755
--- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc
+++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc
@@ -186,14 +186,20 @@ int main(int argc, const char** argv )
die("No real args -> nothing to do");
/* Copy the remaining args to child_arg */
for (int j= i+1; j < argc; j++) {
- if (strchr (argv[j], ' ')) {
- /* Protect with "" if this arg contains a space */
- to+= _snprintf(to, child_args + sizeof(child_args) - to,
- "\"%s\" ", argv[j]);
- } else {
- to+= _snprintf(to, child_args + sizeof(child_args) - to,
- "%s ", argv[j]);
- }
+ arg= argv[j];
+ if (strchr (arg, ' ') &&
+ arg[0] != '\"' &&
+ arg[strlen(arg)] != '\"')
+ {
+ /* Quote arg that contains spaces and are not quoted already */
+ to+= _snprintf(to, child_args + sizeof(child_args) - to,
+ "\"%s\" ", arg);
+ }
+ else
+ {
+ to+= _snprintf(to, child_args + sizeof(child_args) - to,
+ "%s ", arg);
+ }
}
break;
} else {
diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm
index ef3c2a43e87..1b6896e5a80 100644
--- a/mysql-test/lib/mtr_cases.pm
+++ b/mysql-test/lib/mtr_cases.pm
@@ -40,7 +40,6 @@ our $default_storage_engine;
our $opt_with_ndbcluster_only;
our $defaults_file;
our $defaults_extra_file;
-our $reorder= 1;
our $quick_collect;
sub collect_option {
@@ -99,7 +98,8 @@ sub init_pattern {
#
##############################################################################
-sub collect_test_cases ($$) {
+sub collect_test_cases ($$$) {
+ my $opt_reorder= shift; # True if we're reordering tests
my $suites= shift; # Semicolon separated list of test suites
my $opt_cases= shift;
my $cases= []; # Array of hash(one hash for each testcase)
@@ -118,10 +118,16 @@ sub collect_test_cases ($$) {
!(IS_WINDOWS && $::opt_embedded_server) &&
$lib_innodb_plugin);
- foreach my $suite (split(",", $suites))
+ # If not reordering, we also shouldn't group by suites, unless
+ # no test cases were named.
+ # This also effects some logic in the loop following this.
+ if ($opt_reorder or !@$opt_cases)
{
- push(@$cases, collect_one_suite($suite, $opt_cases));
- last if $some_test_found;
+ foreach my $suite (split(",", $suites))
+ {
+ push(@$cases, collect_one_suite($suite, $opt_cases));
+ last if $some_test_found;
+ }
}
if ( @$opt_cases )
@@ -135,6 +141,7 @@ sub collect_test_cases ($$) {
my ($sname, $tname, $extension)= split_testname($test_name_spec);
foreach my $test ( @$cases )
{
+ last unless $opt_reorder;
# test->{name} is always in suite.name format
if ( $test->{name} =~ /.*\.$tname/ )
{
@@ -144,12 +151,13 @@ sub collect_test_cases ($$) {
}
if ( not $found )
{
+ $sname= "main" if !$opt_reorder and !$sname;
mtr_error("Could not find '$tname' in '$suites' suite(s)") unless $sname;
- # If suite was part of name, find it there
- my ($this_case) = collect_one_suite($sname, [ $tname ]);
- if ($this_case)
+ # If suite was part of name, find it there, may come with combinations
+ my @this_case = collect_one_suite($sname, [ $tname ]);
+ if (@this_case)
{
- push (@$cases, $this_case);
+ push (@$cases, @this_case);
}
else
{
@@ -159,7 +167,7 @@ sub collect_test_cases ($$) {
}
}
- if ( $reorder && !$quick_collect)
+ if ( $opt_reorder && !$quick_collect)
{
# Reorder the test cases in an order that will make them faster to run
my %sort_criteria;
diff --git a/mysql-test/lib/mtr_gprof.pl b/mysql-test/lib/mtr_gprof.pl
index f6615301dd7..5820a4007b8 100644
--- a/mysql-test/lib/mtr_gprof.pl
+++ b/mysql-test/lib/mtr_gprof.pl
@@ -20,43 +20,20 @@
use strict;
-# These are not to be prefixed with "mtr_"
+sub gprof_collect ($@) {
+ my ($exe_mysqld, @gprof_dirs)= @_;
-sub gprof_prepare ();
-sub gprof_collect ();
+ print ("Collecting gprof reports.....\n");
-##############################################################################
-#
-#
-#
-##############################################################################
-
-sub gprof_prepare () {
-
- rmtree($::opt_gprof_dir);
- mkdir($::opt_gprof_dir);
-}
-
-# FIXME what about master1 and slave1?!
-sub gprof_collect () {
-
- if ( -f "$::master->[0]->{'path_myddir'}/gmon.out" )
- {
- # FIXME check result code?!
- mtr_run("gprof",
- [$::exe_master_mysqld,
- "$::master->[0]->{'path_myddir'}/gmon.out"],
- $::opt_gprof_master, "", "", "");
- print "Master execution profile has been saved in $::opt_gprof_master\n";
- }
- if ( -f "$::slave->[0]->{'path_myddir'}/gmon.out" )
+ foreach my $datadir (@gprof_dirs)
{
- # FIXME check result code?!
- mtr_run("gprof",
- [$::exe_slave_mysqld,
- "$::slave->[0]->{'path_myddir'}/gmon.out"],
- $::opt_gprof_slave, "", "", "");
- print "Slave execution profile has been saved in $::opt_gprof_slave\n";
+ my $gprof_msg= "$datadir/gprof.msg";
+ my $gprof_err= "$datadir/gprof.err";
+ if ( -f "$datadir/gmon.out" )
+ {
+ system("gprof $exe_mysqld $datadir/gmon.out 2>$gprof_err >$gprof_msg");
+ print ("GPROF output in $gprof_msg, errors in $gprof_err\n");
+ }
}
}
diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl
index 658eb270535..97eb693b52e 100644
--- a/mysql-test/lib/mtr_misc.pl
+++ b/mysql-test/lib/mtr_misc.pl
@@ -30,7 +30,9 @@ sub mtr_script_exists(@);
sub mtr_file_exists(@);
sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@);
-
+sub mtr_milli_sleep($);
+sub start_timer($);
+sub has_expired($);
##############################################################################
#
@@ -167,11 +169,18 @@ sub mtr_exe_exists (@) {
}
-sub mtr_milli_sleep {
+sub mtr_milli_sleep ($) {
die "usage: mtr_milli_sleep(milliseconds)" unless @_ == 1;
my ($millis)= @_;
select(undef, undef, undef, ($millis/1000));
}
+# Simple functions to start and check timers (have to be actively polled)
+# Timer can be "killed" by setting it to 0
+
+sub start_timer ($) { return time + $_[0]; }
+
+sub has_expired ($) { return $_[0] && time gt $_[0]; }
+
1;
diff --git a/mysql-test/lib/mtr_report.pm b/mysql-test/lib/mtr_report.pm
index 937e19111fb..1c4b940bbee 100644
--- a/mysql-test/lib/mtr_report.pm
+++ b/mysql-test/lib/mtr_report.pm
@@ -69,7 +69,7 @@ sub _mtr_report_test_name ($) {
$tname.= " '$tinfo->{combination}'"
if defined $tinfo->{combination};
- print _name(), _timestamp();
+ print _name(). _timestamp();
printf "%-40s ", $tname;
my $worker = $tinfo->{worker};
printf "w$worker " if $worker;
@@ -222,8 +222,8 @@ sub mtr_report_test ($) {
}
-sub mtr_report_stats ($;$) {
- my ($tests, $dont_error)= @_;
+sub mtr_report_stats ($$;$) {
+ my ($prefix, $tests, $dont_error)= @_;
# ----------------------------------------------------------------------
# Find out how we where doing
@@ -328,6 +328,9 @@ sub mtr_report_stats ($;$) {
}
}
+ # Print summary line prefix
+ print "$prefix: ";
+
# Print a list of testcases that failed
if ( $tot_failed != 0 )
{
@@ -387,13 +390,13 @@ sub mtr_report_stats ($;$) {
##############################################################################
sub mtr_print_line () {
- print '-' x 60, "\n";
+ print '-' x 60 . "\n";
}
sub mtr_print_thick_line {
my $char= shift || '=';
- print $char x 78, "\n";
+ print $char x 78 . "\n";
}
@@ -451,7 +454,7 @@ sub _timestamp {
# Always print message to screen
sub mtr_print (@) {
- print _name(), join(" ", @_), "\n";
+ print _name(). join(" ", @_). "\n";
}
@@ -459,22 +462,22 @@ sub mtr_print (@) {
sub mtr_report (@) {
if (defined $verbose)
{
- print _name(), join(" ", @_), "\n";
+ print _name(). join(" ", @_). "\n";
}
}
# Print warning to screen
sub mtr_warning (@) {
- print STDERR _name(), _timestamp(),
- "mysql-test-run: WARNING: ", join(" ", @_), "\n";
+ print STDERR _name(). _timestamp().
+ "mysql-test-run: WARNING: ". join(" ", @_). "\n";
}
# Print error to screen and then exit
sub mtr_error (@) {
- print STDERR _name(), _timestamp(),
- "mysql-test-run: *** ERROR: ", join(" ", @_), "\n";
+ print STDERR _name(). _timestamp().
+ "mysql-test-run: *** ERROR: ". join(" ", @_). "\n";
if (IS_WINDOWS)
{
POSIX::_exit(1);
@@ -489,8 +492,8 @@ sub mtr_error (@) {
sub mtr_debug (@) {
if ( $verbose > 2 )
{
- print STDERR _name(),
- _timestamp(), "####: ", join(" ", @_), "\n";
+ print STDERR _name().
+ _timestamp(). "####: ". join(" ", @_). "\n";
}
}
@@ -498,8 +501,8 @@ sub mtr_debug (@) {
sub mtr_verbose (@) {
if ( $verbose )
{
- print STDERR _name(), _timestamp(),
- "> ",join(" ", @_),"\n";
+ print STDERR _name(). _timestamp().
+ "> ".join(" ", @_)."\n";
}
}
@@ -509,8 +512,8 @@ sub mtr_verbose_restart (@) {
my $proc= $server->{proc};
if ( $verbose_restart )
{
- print STDERR _name(),_timestamp(),
- "> Restart $proc - ",join(" ", @args),"\n";
+ print STDERR _name()._timestamp().
+ "> Restart $proc - ".join(" ", @args)."\n";
}
}
diff --git a/mysql-test/lib/mtr_stress.pl b/mysql-test/lib/mtr_stress.pl
index cd5c7b0dbb7..702bc178ae5 100644
--- a/mysql-test/lib/mtr_stress.pl
+++ b/mysql-test/lib/mtr_stress.pl
@@ -150,7 +150,7 @@ sub run_stress_test ()
mtr_add_arg($args, "--verbose");
mtr_add_arg($args, "--cleanup");
mtr_add_arg($args, "--log-error-details");
- mtr_add_arg($args, "--abort-on-error");
+ mtr_add_arg($args, "--abort-on-error=1");
if ( $::opt_stress_init_file )
{
diff --git a/mysql-test/lib/v1/mtr_stress.pl b/mysql-test/lib/v1/mtr_stress.pl
index 93b06b32c5f..40800c9729b 100644
--- a/mysql-test/lib/v1/mtr_stress.pl
+++ b/mysql-test/lib/v1/mtr_stress.pl
@@ -150,7 +150,7 @@ sub run_stress_test ()
mtr_add_arg($args, "--verbose");
mtr_add_arg($args, "--cleanup");
mtr_add_arg($args, "--log-error-details");
- mtr_add_arg($args, "--abort-on-error");
+ mtr_add_arg($args, "--abort-on-error=1");
if ( $::opt_stress_init_file )
{
diff --git a/mysql-test/lib/v1/mysql-test-run.pl b/mysql-test/lib/v1/mysql-test-run.pl
index caece1d355d..5d06d9c4dd8 100755
--- a/mysql-test/lib/v1/mysql-test-run.pl
+++ b/mysql-test/lib/v1/mysql-test-run.pl
@@ -905,6 +905,11 @@ sub command_line_setup () {
mtr_report("Using default engine '$used_default_engine'")
if defined $used_default_engine;
+ if ($glob_win32 and defined $opt_mem) {
+ mtr_report("--mem not supported on Windows, ignored");
+ $opt_mem= undef;
+ }
+
# --------------------------------------------------------------------------
# Check if we should speed up tests by trying to run on tmpfs
# --------------------------------------------------------------------------