summaryrefslogtreecommitdiff
path: root/mysql-test/lib
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2005-08-25 06:55:48 +0300
committerunknown <monty@mishka.local>2005-08-25 06:55:48 +0300
commit173e5df37fb315099f9e89ce7d686528e24de5c5 (patch)
tree7dfaa1b1889d948f6f78eb4f70bcf87091e7f02d /mysql-test/lib
parentb11953834d8e9521fd3a2dfc4e2bffd26f865eb8 (diff)
parente0f9b8a807fb09df27b016d0ad3852e3320f72dd (diff)
downloadmariadb-git-173e5df37fb315099f9e89ce7d686528e24de5c5.tar.gz
Merge mishka.local:/home/my/mysql-4.1
into mishka.local:/home/my/mysql-5.0 BitKeeper/etc/ignore: auto-union BitKeeper/deleted/.del-Grep.cpp~ad798e9ae519d667: Auto merged BitKeeper/deleted/.del-Grep.hpp~b05e3af6cfabe387: Auto merged BitKeeper/deleted/.del-ctype_cp932.result: Auto merged BitKeeper/deleted/.del-ctype_cp932.test: Auto merged BitKeeper/deleted/.del-have_lowercase0.inc: Delete: mysql-test/include/have_lowercase0.inc VC++Files/mysql-test/mysql_test_run_new.dsp: Auto merged configure.in: Auto merged mysql-test/include/ps_conv.inc: Auto merged mysql-test/mysql-test-run.pl: Auto merged sql/ha_innodb.cc: Auto merged sql/mysql_priv.h: Auto merged sql/set_var.cc: Auto merged sql/examples/ha_archive.cc: Auto merged sql/examples/ha_example.cc: Auto merged sql/sql_table.cc: Auto merged support-files/mysql.spec.sh: Auto merged VC++Files/client/mysqltest.dsp: manual merge VC++Files/sql/mysqld.dsp: manual merge mysql-test/r/grant2.result: patch merge mysql-test/r/subselect2.result: manual merge mysql-test/t/grant2.test: patch merge mysys/charset.c: Remove already deleted function sql/examples/ha_archive.h: Manual merge sql/sql_acl.cc: manual merge sql/sql_db.cc: merge (no differences) sql/sql_select.cc: manual merge sql/table.h: merge (no differences) tests/mysql_client_test.c: patch merge
Diffstat (limited to 'mysql-test/lib')
-rw-r--r--mysql-test/lib/mtr_process.pl69
-rw-r--r--mysql-test/lib/mtr_report.pl9
-rw-r--r--mysql-test/lib/mtr_timer.pl127
3 files changed, 185 insertions, 20 deletions
diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index 1f18968031c..c9ae92305c2 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -185,10 +185,6 @@ sub spawn_parent_impl {
if ( $mode eq 'run' or $mode eq 'test' )
{
- my $exit_value= -1;
-# my $signal_num= 0;
-# my $dumped_core= 0;
-
if ( $mode eq 'run' )
{
# Simple run of command, we wait for it to return
@@ -199,12 +195,7 @@ sub spawn_parent_impl {
mtr_error("$path ($pid) got lost somehow");
}
- $exit_value= $?;
-# $exit_value= $? >> 8;
-# $signal_num= $? & 127;
-# $dumped_core= $? & 128;
-
- return $exit_value;
+ return mtr_process_exit_status($?);
}
else
{
@@ -218,6 +209,8 @@ sub spawn_parent_impl {
# FIXME is this as it should be? Can't mysqld terminate
# normally from running a test case?
+ my $exit_value= -1;
+ my $saved_exit_value;
my $ret_pid; # What waitpid() returns
while ( ($ret_pid= waitpid(-1,0)) != -1 )
@@ -227,13 +220,28 @@ sub spawn_parent_impl {
# but not $exit_value, this is flagged from
#
+ my $timer_name= mtr_timer_timeout($::glob_timers, $ret_pid);
+ if ( $timer_name )
+ {
+ if ( $timer_name eq "suite" )
+ {
+ # We give up here
+ # FIXME we should only give up the suite, not all of the run?
+ print STDERR "\n";
+ mtr_error("Test suite timeout");
+ }
+ elsif ( $timer_name eq "testcase" )
+ {
+ $saved_exit_value= 63; # Mark as timeout
+ kill(9, $pid); # Kill mysqltest
+ next; # Go on and catch the termination
+ }
+ }
+
if ( $ret_pid == $pid )
{
# We got termination of mysqltest, we are done
- $exit_value= $?;
-# $exit_value= $? >> 8;
-# $signal_num= $? & 127;
-# $dumped_core= $? & 128;
+ $exit_value= mtr_process_exit_status($?);
last;
}
@@ -281,7 +289,7 @@ sub spawn_parent_impl {
}
}
- return $exit_value;
+ return $saved_exit_value || $exit_value;
}
}
else
@@ -292,6 +300,23 @@ sub spawn_parent_impl {
}
+# ----------------------------------------------------------------------
+# We try to emulate how an Unix shell calculates the exit code
+# ----------------------------------------------------------------------
+
+sub mtr_process_exit_status {
+ my $raw_status= shift;
+
+ if ( $raw_status & 127 )
+ {
+ return ($raw_status & 127) + 128; # Signal num + 128
+ }
+ else
+ {
+ return $raw_status >> 8; # Exit code
+ }
+}
+
##############################################################################
#
@@ -331,7 +356,7 @@ sub mtr_kill_leftovers () {
});
}
- mtr_mysqladmin_shutdown(\@args);
+ mtr_mysqladmin_shutdown(\@args, 20);
# We now have tried to terminate nice. We have waited for the listen
# port to be free, but can't really tell if the mysqld process died
@@ -441,7 +466,8 @@ sub mtr_stop_mysqld_servers ($) {
# First try nice normal shutdown using 'mysqladmin'
# ----------------------------------------------------------------------
- mtr_mysqladmin_shutdown($spec);
+ # Shutdown time must be high as slave may be in reconnect
+ mtr_mysqladmin_shutdown($spec, 70);
# ----------------------------------------------------------------------
# We loop with waitpid() nonblocking to see how many of the ones we
@@ -591,8 +617,9 @@ sub mtr_stop_mysqld_servers ($) {
#
##############################################################################
-sub mtr_mysqladmin_shutdown () {
+sub mtr_mysqladmin_shutdown {
my $spec= shift;
+ my $adm_shutdown_tmo= shift;
my %mysql_admin_pids;
my @to_kill_specs;
@@ -631,7 +658,7 @@ sub mtr_mysqladmin_shutdown () {
mtr_add_arg($args, "--protocol=tcp"); # Needed if no --socket
}
mtr_add_arg($args, "--connect_timeout=5");
- mtr_add_arg($args, "--shutdown_timeout=20");
+ mtr_add_arg($args, "--shutdown_timeout=$adm_shutdown_tmo");
mtr_add_arg($args, "shutdown");
# We don't wait for termination of mysqladmin
my $pid= mtr_spawn($::exe_mysqladmin, $args,
@@ -808,11 +835,15 @@ sub sleep_until_file_created ($$$) {
# FIXME something is wrong, we sometimes terminate with "Hangup" written
# to tty, and no STDERR output telling us why.
+# FIXME for some readon, setting HUP to 'IGNORE' will cause exit() to
+# write out "Hangup", and maybe loose some output. We insert a sleep...
+
sub mtr_exit ($) {
my $code= shift;
# cluck("Called mtr_exit()");
local $SIG{HUP} = 'IGNORE';
kill('HUP', -$$);
+ sleep 2;
exit($code);
}
diff --git a/mysql-test/lib/mtr_report.pl b/mysql-test/lib/mtr_report.pl
index b9dab6b8d32..5e1a8308505 100644
--- a/mysql-test/lib/mtr_report.pl
+++ b/mysql-test/lib/mtr_report.pl
@@ -109,7 +109,14 @@ sub mtr_report_test_failed ($) {
my $tinfo= shift;
$tinfo->{'result'}= 'MTR_RES_FAILED';
- print "[ fail ]\n";
+ if ( $tinfo->{'timeout'} )
+ {
+ print "[ fail ] timeout\n";
+ }
+ else
+ {
+ print "[ fail ]\n";
+ }
# FIXME Instead of this test, and meaningless error message in 'else'
# we should write out into $::path_timefile when the error occurs.
diff --git a/mysql-test/lib/mtr_timer.pl b/mysql-test/lib/mtr_timer.pl
new file mode 100644
index 00000000000..aab57d1bc52
--- /dev/null
+++ b/mysql-test/lib/mtr_timer.pl
@@ -0,0 +1,127 @@
+# -*- cperl -*-
+
+# This is a library file used by the Perl version of mysql-test-run,
+# and is part of the translation of the Bourne shell script with the
+# same name.
+
+use Carp qw(cluck);
+use Socket;
+use Errno;
+use strict;
+
+#use POSIX ":sys_wait_h";
+use POSIX 'WNOHANG';
+
+sub mtr_init_timers ();
+sub mtr_timer_start($$$);
+sub mtr_timer_stop($$);
+sub mtr_timer_waitpid($$$);
+
+##############################################################################
+#
+# Initiate a structure shared by all timers
+#
+##############################################################################
+
+sub mtr_init_timers () {
+ my $timers = { timers => {}, pids => {}};
+ return $timers;
+}
+
+
+##############################################################################
+#
+# Start, stop and poll a timer
+#
+# As alarm() isn't portable to Windows, we use separate processes to
+# implement timers. That is why there is a mtr_timer_waitpid(), as this
+# is where we catch a timeout.
+#
+##############################################################################
+
+sub mtr_timer_start($$$) {
+ my ($timers,$name,$duration)= @_;
+
+ if ( exists $timers->{'timers'}->{$name} )
+ {
+ # We have an old running timer, kill it
+ mtr_timer_stop($timers,$name);
+ }
+
+ FORK:
+ {
+ my $tpid= fork();
+
+ if ( ! defined $tpid )
+ {
+ if ( $! == $!{EAGAIN} ) # See "perldoc Errno"
+ {
+ mtr_debug("Got EAGAIN from fork(), sleep 1 second and redo");
+ sleep(1);
+ redo FORK;
+ }
+ else
+ {
+ mtr_error("can't fork");
+ }
+ }
+
+ if ( $tpid )
+ {
+ # Parent, record the information
+ $timers->{'timers'}->{$name}->{'pid'}= $tpid;
+ $timers->{'timers'}->{$name}->{'duration'}= $duration;
+ $timers->{'pids'}->{$tpid}= $name;
+ }
+ else
+ {
+ # Child, redirect output and exec
+ # FIXME do we need to redirect streams?
+ $0= "mtr_timer(timers,$name,$duration)";
+ sleep($duration);
+ exit(0);
+ }
+ }
+}
+
+
+sub mtr_timer_stop ($$) {
+ my ($timers,$name)= @_;
+
+ if ( exists $timers->{'timers'}->{$name} )
+ {
+ my $tpid= $timers->{'timers'}->{$name}->{'pid'};
+
+ # FIXME as Cygwin reuses pids fast, maybe check that is
+ # the expected process somehow?!
+ kill(9, $tpid);
+
+ # As the timers are so simple programs, we trust them to terminate,
+ # and use blocking wait for it. We wait just to avoid a zombie.
+ waitpid($tpid,0);
+
+ delete $timers->{'timers'}->{$name}; # Remove the timer information
+ delete $timers->{'pids'}->{$tpid}; # and PID reference
+
+ return 1;
+ }
+ else
+ {
+ mtr_debug("Asked to stop timer \"$name\" not started");
+ return 0;
+ }
+}
+
+
+sub mtr_timer_timeout ($$) {
+ my ($timers,$pid)= @_;
+
+ return "" unless exists $timers->{'pids'}->{$pid};
+
+ # We got a timeout
+ my $name= $timers->{'pids'}->{$pid};
+ mtr_timer_stop($timers, $timers->{'timers'}->{$name});
+ return $name;
+}
+
+1;