diff options
Diffstat (limited to 'mysql-test/mysql-test-run.pl')
-rwxr-xr-x | mysql-test/mysql-test-run.pl | 255 |
1 files changed, 190 insertions, 65 deletions
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index a596c827d46..1f420d2acde 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -111,12 +111,24 @@ my $path_vardir_trace; # unix formatted opt_vardir for trace files my $opt_tmpdir; # Path to use for tmp/ dir my $opt_tmpdir_pid; +my $opt_start; +my $opt_start_dirty; +my $opt_start_exit; +my $start_only; + END { if ( defined $opt_tmpdir_pid and $opt_tmpdir_pid == $$ ) { - # Remove the tempdir this process has created - mtr_verbose("Removing tmpdir '$opt_tmpdir"); - rmtree($opt_tmpdir); + if (!$opt_start_exit) + { + # Remove the tempdir this process has created + mtr_verbose("Removing tmpdir $opt_tmpdir"); + rmtree($opt_tmpdir); + } + else + { + mtr_warning("tmpdir $opt_tmpdir should be removed after the server has finished"); + } } } @@ -191,8 +203,8 @@ our $opt_client_debugger; my $config; # The currently running config my $current_config_name; # The currently running config file template -our $opt_experimental; -our $experimental_test_cases; +our @opt_experimentals; +our $experimental_test_cases= []; my $baseport; # $opt_build_thread may later be set from $opt_port_base @@ -216,18 +228,16 @@ my $opt_suite_timeout = $ENV{MTR_SUITE_TIMEOUT} || 360; # minutes my $opt_shutdown_timeout= $ENV{MTR_SHUTDOWN_TIMEOUT} || 10; # seconds my $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds -sub testcase_timeout { return $opt_testcase_timeout * 60; }; sub suite_timeout { return $opt_suite_timeout * 60; }; sub check_timeout { return $opt_testcase_timeout * 6; }; -my $opt_start; -my $opt_start_dirty; -my $start_only; my $opt_wait_all; +my $opt_user_args; my $opt_repeat= 1; my $opt_retry= 1; my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2); my $opt_reorder= 1; +my $opt_force_restart= 0; my $opt_strace_client; @@ -245,9 +255,21 @@ my $opt_callgrind; my %mysqld_logs; my $opt_debug_sync_timeout= 300; # Default timeout for WAIT_FOR actions. +sub testcase_timeout ($) { + my ($tinfo)= @_; + if (exists $tinfo->{'case-timeout'}) { + # Return test specific timeout if *longer* that the general timeout + my $test_to= $tinfo->{'case-timeout'}; + $test_to*= 10 if $opt_valgrind; + return $test_to * 60 if $test_to > $opt_testcase_timeout; + } + return $opt_testcase_timeout * 60; +} + our $opt_warnings= 1; -our $opt_skip_ndbcluster= 0; +our $opt_include_ndbcluster= 0; +our $opt_skip_ndbcluster= 1; my $exe_ndbd; my $exe_ndb_mgmd; @@ -375,6 +397,12 @@ sub main { mtr_report("Using parallel: $opt_parallel"); } + if ($opt_parallel > 1 && $opt_start_exit) { + mtr_warning("Parallel and --start-and-exit cannot be combined\n" . + "Setting parallel to 1"); + $opt_parallel= 1; + } + # Create server socket on any free port my $server = new IO::Socket::INET ( @@ -415,6 +443,8 @@ sub main { my ($prefix, $fail, $completed, $extra_warnings)= run_test_server($server, $tests, $opt_parallel); + exit(0) if $opt_start_exit; + # Send Ctrl-C to any children still running kill("INT", keys(%children)); @@ -601,13 +631,15 @@ sub run_test_server ($$$) { if ($test_has_failed and $retries <= $opt_retry){ # Test should be run one more time unless it has failed # too many times already + my $tname= $result->{name}; my $failures= $result->{failures}; if ($opt_retry > 1 and $failures >= $opt_retry_failure){ - mtr_report("\nTest has failed $failures times,", + mtr_report("\nTest $tname has failed $failures times,", "no more retries!\n"); } else { - mtr_report("\nRetrying test, attempt($retries/$opt_retry)...\n"); + mtr_report("\nRetrying test $tname, ". + "attempt($retries/$opt_retry)...\n"); delete($result->{result}); $result->{retries}= $retries+1; $result->write_test($sock, 'TESTCASE'); @@ -893,6 +925,7 @@ sub command_line_setup { # Control what test suites or cases to run 'force' => \$opt_force, 'with-ndbcluster-only' => \&collect_option, + 'include-ndbcluster' => \$opt_include_ndbcluster, 'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster, 'suite|suites=s' => \$opt_suites, 'skip-rpl' => \&collect_option, @@ -902,7 +935,7 @@ sub command_line_setup { 'big-test' => \$opt_big_test, 'combination=s' => \@opt_combinations, 'skip-combinations' => \&collect_option, - 'experimental=s' => \$opt_experimental, + 'experimental=s' => \@opt_experimentals, 'skip-im' => \&ignore_option, 'staging-run' => \$opt_staging_run, @@ -976,13 +1009,16 @@ sub command_line_setup { 'report-features' => \$opt_report_features, 'comment=s' => \$opt_comment, 'fast' => \$opt_fast, + 'force-restart' => \$opt_force_restart, 'reorder!' => \$opt_reorder, 'enable-disabled' => \&collect_option, 'verbose+' => \$opt_verbose, 'verbose-restart' => \&report_option, 'sleep=i' => \$opt_sleep, 'start-dirty' => \$opt_start_dirty, + 'start-and-exit' => \$opt_start_exit, 'start' => \$opt_start, + 'user-args' => \$opt_user_args, 'wait-all' => \$opt_wait_all, 'print-testcases' => \&collect_option, 'repeat=i' => \$opt_repeat, @@ -1088,43 +1124,47 @@ sub command_line_setup { mtr_print_thick_line('#'); } - if ( $opt_experimental ) + if ( @opt_experimentals ) { # $^O on Windows considered not generic enough my $plat= (IS_WINDOWS) ? 'windows' : $^O; - # read the list of experimental test cases from the file specified on + # read the list of experimental test cases from the files specified on # the command line - open(FILE, "<", $opt_experimental) or mtr_error("Can't read experimental file: $opt_experimental"); - mtr_report("Using experimental file: $opt_experimental"); $experimental_test_cases = []; - while(<FILE>) { - chomp; - # remove comments (# foo) at the beginning of the line, or after a - # blank at the end of the line - s/( +|^)#.*$//; - # If @ platform specifier given, use this entry only if it contains - # @<platform> or @!<xxx> where xxx != platform - if (/\@.*/) - { - next if (/\@!$plat/); - next unless (/\@$plat/ or /\@!/); - # Then remove @ and everything after it - s/\@.*$//; - } - # remove whitespace - s/^ +//; - s/ +$//; - # if nothing left, don't need to remember this line - if ( $_ eq "" ) { - next; + foreach my $exp_file (@opt_experimentals) + { + open(FILE, "<", $exp_file) + or mtr_error("Can't read experimental file: $exp_file"); + mtr_report("Using experimental file: $exp_file"); + while(<FILE>) { + chomp; + # remove comments (# foo) at the beginning of the line, or after a + # blank at the end of the line + s/( +|^)#.*$//; + # If @ platform specifier given, use this entry only if it contains + # @<platform> or @!<xxx> where xxx != platform + if (/\@.*/) + { + next if (/\@!$plat/); + next unless (/\@$plat/ or /\@!/); + # Then remove @ and everything after it + s/\@.*$//; + } + # remove whitespace + s/^ +//; + s/ +$//; + # if nothing left, don't need to remember this line + if ( $_ eq "" ) { + next; + } + # remember what is left as the name of another test case that should be + # treated as experimental + print " - $_\n"; + push @$experimental_test_cases, $_; } - # remember what is left as the name of another test case that should be - # treated as experimental - print " - $_\n"; - push @$experimental_test_cases, $_; + close FILE; } - close FILE; } foreach my $arg ( @ARGV ) @@ -1398,7 +1438,7 @@ sub command_line_setup { # -------------------------------------------------------------------------- # Modified behavior with --start options # -------------------------------------------------------------------------- - if ($opt_start or $opt_start_dirty) { + if ($opt_start or $opt_start_dirty or $opt_start_exit) { collect_option ('quick-collect', 1); $start_only= 1; } @@ -1411,12 +1451,23 @@ sub command_line_setup { } # -------------------------------------------------------------------------- + # Check use of user-args + # -------------------------------------------------------------------------- + + if ($opt_user_args) { + mtr_error("--user-args only valid with --start options") + unless $start_only; + mtr_error("--user-args cannot be combined with named suites or tests") + if $opt_suites || @opt_cases; + } + + # -------------------------------------------------------------------------- # Check use of wait-all # -------------------------------------------------------------------------- if ($opt_wait_all && ! $start_only) { - mtr_error("--wait-all can only be used with --start or --start-dirty"); + mtr_error("--wait-all can only be used with --start options"); } # -------------------------------------------------------------------------- @@ -2154,6 +2205,12 @@ sub environment_setup { # Create an environment variable to make it possible # to detect that valgrind is being used from test cases $ENV{'VALGRIND_TEST'}= $opt_valgrind; + + # Add dir of this perl to aid mysqltest in finding perl + my $perldir= dirname($^X); + my $pathsep= ":"; + $pathsep= ";" if IS_WINDOWS && ! IS_CYGWIN; + $ENV{'PATH'}= "$ENV{'PATH'}".$pathsep.$perldir; } @@ -2459,14 +2516,12 @@ sub fix_vs_config_dir () { my $modified = 1e30; $opt_vs_config=""; - for my $dir (qw(client/*.dir libmysql/libmysql.dir sql/mysqld.dir - sql/udf_example.dir storage/*/*.dir plugin/*/*.dir)) { - for (<$basedir/$dir/*/BuildLog.htm>) { - if (-M $_ < $modified) - { - $modified = -M _; - $opt_vs_config = basename(dirname($_)); - } + + for (<$basedir/sql/*/mysqld.exe>) { + if (-M $_ < $modified) + { + $modified = -M _; + $opt_vs_config = basename(dirname($_)); } } @@ -2478,6 +2533,11 @@ sub fix_vs_config_dir () { sub check_ndbcluster_support ($) { my $mysqld_variables= shift; + if ($opt_include_ndbcluster) + { + $opt_skip_ndbcluster= 0; + } + if ($opt_skip_ndbcluster) { mtr_report(" - skipping ndbcluster"); @@ -2987,6 +3047,7 @@ sub default_mysqld { my $config= My::ConfigFactory->new_config ( { basedir => $basedir, + testdir => $glob_mysql_test_dir, template_path => "include/default_my.cnf", vardir => $opt_vardir, tmpdir => $opt_tmpdir, @@ -3262,7 +3323,8 @@ sub check_testcase($$) my %started; foreach my $mysqld ( mysqlds() ) { - if ( defined $mysqld->{'proc'} ) + # Skip if server has been restarted with additional options + if ( defined $mysqld->{'proc'} && ! exists $mysqld->{'restart_opts'} ) { my $proc= start_check_testcase($tinfo, $mode, $mysqld); $started{$proc->pid()}= $proc; @@ -3315,7 +3377,8 @@ sub check_testcase($$) "\nMTR's internal check of the test case '$tname' failed. This means that the test case does not preserve the state that existed before the test case was executed. Most likely the test case did not -do a proper clean-up. +do a proper clean-up. It could also be caused by the previous test run +by this thread, if the server wasn't restarted. This is the diff of the states of the servers before and after the test case was executed:\n"; $tinfo->{check}.= $report; @@ -3361,6 +3424,10 @@ test case was executed:\n"; # Kill any check processes still running map($_->kill(), values(%started)); + mtr_warning("Check-testcase failed, this could also be caused by the" . + " previous test run by this worker thread") + if $result > 1 && $mode eq "before"; + return $result; } @@ -3712,6 +3779,7 @@ sub run_testcase ($$) { $config= My::ConfigFactory->new_config ( { basedir => $basedir, + testdir => $glob_mysql_test_dir, template_path => $tinfo->{template_path}, extra_template_path => $tinfo->{extra_template_path}, vardir => $opt_vardir, @@ -3755,6 +3823,11 @@ sub run_testcase ($$) { # Write start of testcase to log mark_log($path_current_testlog, $tinfo); + # Make sure the safe_process also exits from now on + if ($opt_start_exit) { + My::SafeProcess->start_exit(); + } + if (start_servers($tinfo)) { report_failure_and_restart($tinfo); @@ -3779,6 +3852,18 @@ sub run_testcase ($$) { mtr_print ($mysqld->name() . " " . $mysqld->value('port') . " " . $mysqld->value('socket')); } + if ( $opt_start_exit ) + { + mtr_print("Server(s) started, not waiting for them to finish"); + if (IS_WINDOWS) + { + POSIX::_exit(0); # exit hangs here in ActiveState Perl + } + else + { + exit(0); + } + } mtr_print("Waiting for server(s) to exit..."); if ( $opt_wait_all ) { My::SafeProcess->wait_all(); @@ -3797,7 +3882,7 @@ sub run_testcase ($$) { } } - my $test_timeout= start_timer(testcase_timeout()); + my $test_timeout= start_timer(testcase_timeout($tinfo)); do_before_run_mysqltest($tinfo); @@ -3902,6 +3987,9 @@ sub run_testcase ($$) { # Try to get reason from test log file find_testcase_skipped_reason($tinfo); mtr_report_test_skipped($tinfo); + # Restart if skipped due to missing perl, it may have had side effects + stop_all_servers($opt_shutdown_timeout) + if ($tinfo->{'comment'} =~ /^perl not found/); } elsif ( $res == 65 ) { @@ -4008,7 +4096,7 @@ sub run_testcase ($$) { { my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log"; $tinfo->{comment}= - "Test case timeout after ".testcase_timeout(). + "Test case timeout after ".testcase_timeout($tinfo). " seconds\n\n"; # Add 20 last executed commands from test case log file if (-e $log_file_name) @@ -4017,7 +4105,7 @@ sub run_testcase ($$) { "== $log_file_name == \n". mtr_lastlinesfromfile($log_file_name, 20)."\n"; } - $tinfo->{'timeout'}= testcase_timeout(); # Mark as timeout + $tinfo->{'timeout'}= testcase_timeout($tinfo); # Mark as timeout run_on_all($tinfo, 'analyze-timeout'); report_failure_and_restart($tinfo); @@ -4142,7 +4230,9 @@ sub get_log_from_proc ($$) { foreach my $mysqld (all_servers()) { if ($mysqld->{proc} eq $proc) { my @srv_lines= extract_server_log($mysqld->if_exist('#log-error'), $name); - $srv_log= "\nServer log from this test:\n" . join ("", @srv_lines); + $srv_log= "\nServer log from this test:\n" . + "----------SERVER LOG START-----------\n". join ("", @srv_lines) . + "----------SERVER LOG END-------------\n"; last; } } @@ -4237,6 +4327,7 @@ sub extract_warning_lines ($) { qr/Slave SQL thread retried transaction/, qr/Slave \(additional info\)/, qr/Incorrect information in file/, + qr/Incorrect key file for table .*crashed.*/, qr/Slave I\/O: Get master SERVER_ID failed with error:.*/, qr/Slave I\/O: Get master clock failed with error:.*/, qr/Slave I\/O: Get master COLLATION_SERVER failed with error:.*/, @@ -4497,6 +4588,16 @@ sub check_expected_crash_and_restart { next; } + # If last line begins "restart:", the rest of the line is read as + # extra command line options to add to the restarted mysqld. + # Anything other than 'wait' or 'restart:' (with a colon) will + # result in a restart with original mysqld options. + if ($last_line =~ /restart:(.+)/) { + my @rest_opt= split(' ', $1); + $mysqld->{'restart_opts'}= \@rest_opt; + } else { + delete $mysqld->{'restart_opts'}; + } unlink($expect_file); # Start server with same settings as last time @@ -4735,7 +4836,7 @@ sub mysqld_arguments ($$$) { mtr_add_arg($args, "%s--disable-sync-frm"); - if (!using_extern() and $mysql_version_id >= 50106 ) + if (!using_extern() and $mysql_version_id >= 50106 && !$opt_user_args) { # Turn on logging to file and tables mtr_add_arg($args, "%s--log-output=table,file"); @@ -4773,7 +4874,7 @@ sub mysqld_arguments ($$$) { } } $opt_skip_core = $found_skip_core; - if ( !$found_skip_core ) + if ( !$found_skip_core && !$opt_user_args ) { mtr_add_arg($args, "%s", "--core-file"); } @@ -4781,7 +4882,7 @@ sub mysqld_arguments ($$$) { # Enable the debug sync facility, set default wait timeout. # Facility stays disabled if timeout value is zero. mtr_add_arg($args, "--loose-debug-sync-timeout=%s", - $opt_debug_sync_timeout); + $opt_debug_sync_timeout) unless $opt_user_args; return $args; } @@ -4813,7 +4914,13 @@ sub mysqld_start ($$) { } mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld')); - mysqld_arguments($args,$mysqld,$extra_opts); + + # Add any additional options from an in-test restart + my @all_opts= @$extra_opts; + if (exists $mysqld->{'restart_opts'}) { + push (@all_opts, @{$mysqld->{'restart_opts'}}); + } + mysqld_arguments($args,$mysqld,\@all_opts); if ( $opt_debug ) { @@ -4956,6 +5063,11 @@ sub server_need_restart { return 1; } + if ( $opt_force_restart ) { + mtr_verbose_restart($server, "forced restart turned on"); + return 1; + } + if ( $tinfo->{template_path} ne $current_config_name) { mtr_verbose_restart($server, "using different config file"); @@ -5006,7 +5118,10 @@ sub server_need_restart { my $extra_opts= get_extra_opts($server, $tinfo); my $started_opts= $server->{'started_opts'}; - if (!My::Options::same($started_opts, $extra_opts) ) + # Also, always restart if server had been restarted with additional + # options within test. + if (!My::Options::same($started_opts, $extra_opts) || + exists $server->{'restart_opts'}) { my $use_dynamic_option_switch= 0; if (!$use_dynamic_option_switch) @@ -5075,6 +5190,9 @@ sub stopped { return grep(!defined $_, map($_->{proc}, @_)); } sub get_extra_opts { + # No extra options if --user-args + return \@opt_extra_mysqld_opt if $opt_user_args; + my ($mysqld, $tinfo)= @_; my $opts= @@ -5656,7 +5774,8 @@ Options to control what test suites or cases to run force Continue to run the suite after failure with-ndbcluster-only Run only tests that include "ndb" in the filename - skip-ndb[cluster] Skip all tests that need cluster + skip-ndb[cluster] Skip all tests that need cluster. Default. + include-ndb[cluster] Enable all tests that need cluster do-test=PREFIX or REGEX Run test cases which name are prefixed with PREFIX or fulfills REGEX @@ -5769,13 +5888,19 @@ Misc options startup settings for the first specified test case Example: $0 --start alias & + start-and-exit Same as --start, but mysql-test-run terminates and + leaves just the server running start-dirty Only start the servers (without initialization) for the first specified test case + user-args In combination with start* and no test name, drops + arguments to mysqld except those speficied with + --mysqld (if any) wait-all If --start or --start-dirty option is used, wait for all servers to exit before finishing the process fast Run as fast as possible, dont't wait for servers to shutdown etc. - parallel=N Run tests in N parallel threads (default 1) + force-restart Always restart servers between tests + parallel=N Run tests in N parallel threads (default=1) Use parallel=auto for auto-setting of N repeat=N Run each test N number of times retry=N Retry tests that fail up to N times (default $opt_retry). |