Commit d30534c9 authored by anozdrin@mysql.com's avatar anozdrin@mysql.com

Implement WL#2789 "Instance Manager: test using mysql-test-run testing framework"

parent d7d307fb
......@@ -50,6 +50,7 @@ dist-hook:
$(distdir)/std_data $(distdir)/lib
-$(INSTALL_DATA) $(srcdir)/t/*.def $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.imtest $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.opt $(srcdir)/t/*.sh $(srcdir)/t/*.slave-mi $(distdir)/t
......@@ -73,6 +74,7 @@ install-data-local:
$(INSTALL_DATA) $(srcdir)/README $(DESTDIR)$(testdir)
-$(INSTALL_DATA) $(srcdir)/t/*.def $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.imtest $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.opt $(DESTDIR)$(testdir)/t
......
......@@ -8,7 +8,7 @@ use File::Basename;
use strict;
sub collect_test_cases ($);
sub collect_one_test_case ($$$$$$);
sub collect_one_test_case ($$$$$$$);
##############################################################################
#
......@@ -40,13 +40,84 @@ sub collect_test_cases ($) {
if ( @::opt_cases )
{
foreach my $tname ( @::opt_cases ) { # Run in specified order, no sort
$tname= basename($tname, ".test");
my $elem= "$tname.test";
my $elem= undef;
my $component_id= undef;
# Get rid of directory part (path). Leave the extension since it is used
# to understand type of the test.
$tname = basename($tname);
# Check if the extenstion has been specified.
if ( mtr_match_extension($tname, "test") )
{
$elem= $tname;
$tname=~ s/\.test$//;
$component_id= 'mysqld';
}
elsif ( mtr_match_extension($tname, "imtest") )
{
$elem= $tname;
$tname =~ s/\.imtest$//;
$component_id= 'im';
if ( $::glob_use_embedded_server )
{
mtr_report(
"Instance Manager's tests are not available in embedded mode." .
"Test case '$tname' is skipped.");
next;
}
unless ( $::exe_im )
{
mtr_report(
"Instance Manager executable is unavailable. " .
"Test case '$tname' is skipped.");
next;
}
}
# If target component is known, check that the specified test case
# exists.
#
# Otherwise, try to guess the target component.
if ( defined $component_id )
{
if ( ! -f "$testdir/$elem")
{
mtr_error("Test case $tname ($testdir/$elem) is not found");
}
collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,{});
}
else
{
my $mysqld_test_exists = -f "$testdir/$tname.test";
my $im_test_exists = -f "$testdir/$tname.imtest";
if ( $mysqld_test_exists && $im_test_exists )
{
mtr_error("Ambiguos test case name ($tname)");
}
elsif ( ! $mysqld_test_exists && !$im_test_exists )
{
mtr_error("Test case $tname is not found");
}
elsif ( $mysqld_test_exists )
{
$elem= "$tname.test";
$component_id= 'mysqld';
}
elsif ( $im_test_exists )
{
$elem= "$tname.imtest";
$component_id= 'im';
}
}
collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,{},
$component_id);
}
closedir TESTDIR;
}
......@@ -70,11 +141,26 @@ sub collect_test_cases ($) {
}
foreach my $elem ( sort readdir(TESTDIR) ) {
my $tname= mtr_match_extension($elem,"test");
next if ! defined $tname;
my $component_id= undef;
my $tname= undef;
if ($tname= mtr_match_extension($elem, 'test'))
{
$component_id = 'mysqld';
}
elsif ($tname= mtr_match_extension($elem, 'imtest'))
{
$component_id = 'im';
}
else
{
next;
}
next if $::opt_do_test and ! defined mtr_match_prefix($elem,$::opt_do_test);
collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,\%disabled);
collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,\%disabled,
$component_id);
}
closedir TESTDIR;
}
......@@ -112,13 +198,14 @@ sub collect_test_cases ($) {
##############################################################################
sub collect_one_test_case($$$$$$) {
sub collect_one_test_case($$$$$$$) {
my $testdir= shift;
my $resdir= shift;
my $tname= shift;
my $elem= shift;
my $cases= shift;
my $disabled=shift;
my $component_id= shift;
my $path= "$testdir/$elem";
......@@ -138,6 +225,7 @@ sub collect_one_test_case($$$$$$) {
my $tinfo= {};
$tinfo->{'name'}= $tname;
$tinfo->{'result_file'}= "$resdir/$tname.result";
$tinfo->{'component_id'} = $component_id;
push(@$cases, $tinfo);
if ( $::opt_skip_test and defined mtr_match_prefix($tname,$::opt_skip_test) )
......@@ -188,6 +276,7 @@ sub collect_one_test_case($$$$$$) {
my $master_sh= "$testdir/$tname-master.sh";
my $slave_sh= "$testdir/$tname-slave.sh";
my $disabled_file= "$testdir/$tname.disabled";
my $im_opt_file= "$testdir/$tname-im.opt";
$tinfo->{'master_opt'}= $::glob_win32 ? ["--default-time-zone=+3:00"] : [];
$tinfo->{'slave_opt'}= $::glob_win32 ? ["--default-time-zone=+3:00"] : [];
......@@ -290,6 +379,15 @@ sub collect_one_test_case($$$$$$) {
}
}
if ( -f $im_opt_file )
{
$tinfo->{'im_opts'} = mtr_get_opts_from_file($im_opt_file);
}
else
{
$tinfo->{'im_opts'} = [];
}
# FIXME why this late?
if ( $disabled->{$tname} )
{
......
......@@ -12,16 +12,17 @@ use strict;
#use POSIX ":sys_wait_h";
use POSIX 'WNOHANG';
sub mtr_run ($$$$$$);
sub mtr_spawn ($$$$$$);
sub mtr_run ($$$$$$;$);
sub mtr_spawn ($$$$$$;$);
sub mtr_stop_mysqld_servers ($);
sub mtr_kill_leftovers ();
sub mtr_record_dead_children ();
sub mtr_exit ($);
sub sleep_until_file_created ($$$);
sub mtr_kill_processes ($);
# static in C
sub spawn_impl ($$$$$$$);
sub spawn_impl ($$$$$$$$);
##############################################################################
#
......@@ -32,37 +33,43 @@ sub spawn_impl ($$$$$$$);
# This function try to mimic the C version used in "netware/mysql_test_run.c"
# FIXME learn it to handle append mode as well, a "new" flag or a "append"
sub mtr_run ($$$$$$) {
sub mtr_run ($$$$$$;$) {
my $path= shift;
my $arg_list_t= shift;
my $input= shift;
my $output= shift;
my $error= shift;
my $pid_file= shift;
my $spawn_opts= shift;
return spawn_impl($path,$arg_list_t,'run',$input,$output,$error,$pid_file);
return spawn_impl($path,$arg_list_t,'run',$input,$output,$error,$pid_file,
$spawn_opts);
}
sub mtr_run_test ($$$$$$) {
sub mtr_run_test ($$$$$$;$) {
my $path= shift;
my $arg_list_t= shift;
my $input= shift;
my $output= shift;
my $error= shift;
my $pid_file= shift;
my $spawn_opts= shift;
return spawn_impl($path,$arg_list_t,'test',$input,$output,$error,$pid_file);
return spawn_impl($path,$arg_list_t,'test',$input,$output,$error,$pid_file,
$spawn_opts);
}
sub mtr_spawn ($$$$$$) {
sub mtr_spawn ($$$$$$;$) {
my $path= shift;
my $arg_list_t= shift;
my $input= shift;
my $output= shift;
my $error= shift;
my $pid_file= shift;
my $spawn_opts= shift;
return spawn_impl($path,$arg_list_t,'spawn',$input,$output,$error,$pid_file);
return spawn_impl($path,$arg_list_t,'spawn',$input,$output,$error,$pid_file,
$spawn_opts);
}
......@@ -72,7 +79,7 @@ sub mtr_spawn ($$$$$$) {
#
##############################################################################
sub spawn_impl ($$$$$$$) {
sub spawn_impl ($$$$$$$$) {
my $path= shift;
my $arg_list_t= shift;
my $mode= shift;
......@@ -80,6 +87,7 @@ sub spawn_impl ($$$$$$$) {
my $output= shift;
my $error= shift;
my $pid_file= shift; # FIXME
my $spawn_opts= shift;
if ( $::opt_script_debug )
{
......@@ -89,6 +97,18 @@ sub spawn_impl ($$$$$$$) {
print STDERR "#### ", "STDOUT $output\n" if $output;
print STDERR "#### ", "STDERR $error\n" if $error;
print STDERR "#### ", "$mode : $path ", join(" ",@$arg_list_t), "\n";
print STDERR "#### ", "spawn options:\n";
if ($spawn_opts)
{
foreach my $key (sort keys %{$spawn_opts})
{
print STDERR "#### ", " - $key: $spawn_opts->{$key}\n";
}
}
else
{
print STDERR "#### ", " none\n";
}
print STDERR "#### ", "-" x 78, "\n";
}
......@@ -135,9 +155,16 @@ sub spawn_impl ($$$$$$$) {
# $ENV{'COMSPEC'}= "$::glob_cygwin_shell -c";
}
my $log_file_open_mode = '>';
if ($spawn_opts and $spawn_opts->{'append_log_file'})
{
$log_file_open_mode = '>>';
}
if ( $output )
{
if ( ! open(STDOUT,">",$output) )
if ( ! open(STDOUT,$log_file_open_mode,$output) )
{
mtr_error("can't redirect STDOUT to \"$output\": $!");
}
......@@ -154,7 +181,7 @@ sub spawn_impl ($$$$$$$) {
}
else
{
if ( ! open(STDERR,">",$error) )
if ( ! open(STDERR,$log_file_open_mode,$error) )
{
mtr_error("can't redirect STDERR to \"$output\": $!");
}
......@@ -534,16 +561,7 @@ sub mtr_stop_mysqld_servers ($) {
start_reap_all(); # Avoid zombies
SIGNAL:
foreach my $sig (15,9)
{
my $retries= 20; # FIXME 20 seconds, this is silly!
kill($sig, keys %mysqld_pids);
while ( $retries-- and kill(0, keys %mysqld_pids) )
{
mtr_debug("Sleep 1 second waiting for processes to die");
sleep(1) # Wait one second
}
}
mtr_kill_processes(\keys (%mysqld_pids));
stop_reap_all(); # Get into control again
......@@ -805,7 +823,7 @@ sub sleep_until_file_created ($$$) {
}
# Check if it died after the fork() was successful
if ( waitpid($pid,&WNOHANG) == $pid )
if ( $pid > 0 && waitpid($pid,&WNOHANG) == $pid )
{
return 0;
}
......@@ -826,6 +844,21 @@ sub sleep_until_file_created ($$$) {
}
sub mtr_kill_processes ($) {
my $pids = shift;
foreach my $sig (15,9)
{
my $retries= 20; # FIXME 20 seconds, this is silly!
kill($sig, @{$pids});
while ( $retries-- and kill(0, @{$pids}) )
{
mtr_debug("Sleep 1 second waiting for processes to die");
sleep(1) # Wait one second
}
}
}
##############################################################################
#
# When we exit, we kill off all children
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment