summaryrefslogtreecommitdiff
path: root/mysql-test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/lib')
-rw-r--r--mysql-test/lib/My/SafeProcess.pm133
-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
7 files changed, 106 insertions, 131 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/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 4202334a244..c90c4c30e00 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
# --------------------------------------------------------------------------