Debian Codegraph @

mysql-test/mariadb-test-run.pl

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #!/usr/bin/perl
2 # -*- cperl -*-
3
4 # Copyright (c) 2004, 2014, Oracle and/or its affiliates.
5 # Copyright (c) 2009, 2022, MariaDB Corporation
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
19
20 #
21 ##############################################################################
22 #
23 # mysql-test-run.pl
24 #
25 # Tool used for executing a suite of .test files
26 #
27 # See the "MySQL Test framework manual" for more information
28 # https://mariadb.com/kb/en/library/mysqltest/
29 #
30 #
31 ##############################################################################
32
33 use strict;
34 use warnings;
35
36 BEGIN {
37 # Check that mysql-test-run.pl is started from mysql-test/
38 unless ( -f "mariadb-test-run.pl" )
39 {
40 print "**** ERROR **** ",
41 "You must start mysql-test-run from the mysql-test/ directory\n";
42 exit(1);
43 }
44 # Check that lib exist
45 unless ( -d "lib/" )
46 {
47 print "**** ERROR **** ",
48 "Could not find the lib/ directory \n";
49 exit(1);
50 }
51
52 # Check backward compatibility support
53 # By setting the environment variable MTR_VERSION
54 # it's possible to use a previous version of
55 # mysql-test-run.pl
56 my $version= $ENV{MTR_VERSION} || 2;
57 if ( $version == 1 )
58 {
59 print "=======================================================\n";
60 print " WARNING: Using mariadb-test-run.pl version 1! \n";
61 print "=======================================================\n";
62 # Should use exec() here on *nix but this appears not to work on Windows
63 exit(system($^X, "lib/v1/mariadb-test-run.pl", @ARGV) >> 8);
64 }
65 elsif ( $version == 2 )
66 {
67 # This is the current version, just continue
68 ;
69 }
70 else
71 {
72 print "ERROR: Version $version of mariadb-test-run does not exist!\n";
73 exit(1);
74 }
75 }
76
77 use lib "lib";
78
79 use Cwd ;
80 use POSIX ":sys_wait_h";
81 use Getopt::Long qw(:config bundling);
82 use My::File::Path; # Patched version of File::Path
83 use File::Basename;
84 use File::Copy;
85 use File::Find;
86 use File::Temp qw/tempdir/;
87 use File::Spec::Functions qw/splitdir rel2abs/;
88 use My::Platform;
89 use My::SafeProcess;
90 use My::ConfigFactory;
91 use My::Options;
92 use My::Tee;
93 use My::Find;
94 use My::SysInfo;
95 use My::CoreDump;
96 use My::Debugger;
97 use mtr_cases;
98 use mtr_report;
99 use mtr_match;
100 use mtr_unique;
101 use mtr_results;
102 use IO::Socket::INET;
103 use IO::Select;
104 use Time::HiRes qw(gettimeofday);
105
106 sub realpath($) { (IS_WINDOWS) ? $_[0] : Cwd::realpath($_[0]) }
107
108 require "mtr_process.pl";
109 require "mtr_io.pl";
110 require "mtr_gprof.pl";
111 require "mtr_misc.pl";
112
113 my $opt_valgrind;
114 my $valgrind_reports= 0;
115
116 $SIG{INT}= sub { mtr_error("Got ^C signal"); };
117 $SIG{HUP}= sub { mtr_error("Hangup detected on controlling terminal"); };
118
119 our $mysql_version_id;
120 my $mysql_version_extra;
121 our $glob_mysql_test_dir;
122 our $basedir;
123 our $bindir;
124
125 our $path_charsetsdir;
126 our $path_client_bindir;
127 our $path_client_libdir;
128 our $path_language;
129
130 our $path_current_testlog;
131 our $path_testlog;
132
133 our $opt_open_files_limit;
134
135 our $default_vardir;
136 our $opt_vardir; # Path to use for var/ dir
137 our $plugindir;
138 our $opt_xml_report; # XML output
139 our $client_plugindir;
140 my $path_vardir_trace; # unix formatted opt_vardir for trace files
141 my $opt_tmpdir; # Path to use for tmp/ dir
142 my $opt_tmpdir_pid;
143
144 my $opt_start;
145 my $opt_start_dirty;
146 my $opt_start_exit;
147 my $start_only;
148 my $file_wsrep_provider;
149 my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
150
151 our @global_suppressions;
152
153 END {
154 if ( defined $opt_tmpdir_pid and $opt_tmpdir_pid == $$ )
155 {
156 if (!$opt_start_exit)
157 {
158 # Remove the tempdir this process has created
159 mtr_verbose("Removing tmpdir $opt_tmpdir");
160 rmtree($opt_tmpdir);
161 }
162 else
163 {
164 mtr_warning("tmpdir $opt_tmpdir should be removed after the server has finished");
165 }
166 }
167 }
168
169 sub env_or_val($$) { defined $ENV{$_[0]} ? $ENV{$_[0]} : $_[1] }
170
171 my $path_config_file; # The generated config file, var/my.cnf
172
173 # Visual Studio produces executables in different sub-directories based on the
174 # configuration used to build them. To make life easier, an environment
175 # variable or command-line option may be specified to control which set of
176 # executables will be used by the test suite.
177 our $multiconfig = $ENV{'MTR_VS_CONFIG'};
178
179 my @DEFAULT_SUITES= qw(
180 main-
181 archive-
182 atomic-
183 binlog-
184 binlog_encryption-
185 client-
186 csv-
187 compat/oracle-
188 compat/mssql-
189 compat/maxdb-
190 encryption-
191 events-
192 federated-
193 funcs_1-
194 funcs_2-
195 gcol-
196 handler-
197 heap-
198 innodb-
199 innodb_fts-
200 innodb_gis-
201 innodb_i_s-
202 innodb_zip-
203 json-
204 maria-
205 mariabackup-
206 merge-
207 multi_source-
208 optimizer_unfixed_bugs-
209 parts-
210 perfschema-
211 plugins-
212 roles-
213 rpl-
214 stress-
215 sys_vars-
216 sql_sequence-
217 unit-
218 vcol-
219 versioning-
220 period-
221 sysschema-
222 );
223 my $opt_suites;
224
225 our $opt_verbose= 0; # Verbose output, enable with --verbose
226 our $exe_patch;
227 our $exe_mysql;
228 our $exe_mysql_plugin;
229 our $exe_mysqladmin;
230 our $exe_mysqltest;
231 our $exe_libtool;
232 our $exe_mysql_embedded;
233 our $exe_mariadb_conv;
234
235 our $opt_big_test= 0;
236 our $opt_staging_run= 0;
237
238 our @opt_combinations;
239
240 our @opt_extra_mysqld_opt;
241 our @opt_mysqld_envs;
242
243 my $opt_stress;
244 my $opt_tail_lines= 20;
245
246 my $opt_dry_run;
247
248 my $opt_compress;
249 my $opt_ssl;
250 my $opt_skip_ssl;
251 my @opt_skip_test_list;
252 our $opt_ssl_supported;
253 our $opt_ps_protocol;
254 my $opt_sp_protocol;
255 our $opt_cursor_protocol;
256 my $opt_view_protocol;
257 my $opt_non_blocking_api;
258
259 our $opt_debug;
260 my $debug_d= "d,*";
261 my $opt_debug_common;
262 our $opt_debug_server;
263 our @opt_cases; # The test cases names in argv
264 our $opt_embedded_server;
265
266 # Options used when connecting to an already running server
267 my %opts_extern;
268 sub using_extern { return (keys %opts_extern > 0);};
269
270 our $opt_fast= 0;
271 our $opt_force= 0;
272 our $opt_skip_not_found= 0;
273 our $opt_mem= $ENV{'MTR_MEM'};
274 our $opt_clean_vardir= $ENV{'MTR_CLEAN_VARDIR'};
275 our $opt_catalogs= 0;
276 our $opt_catalog_name="";
277 our $catalog_name="def";
278
279 our $opt_gcov;
280 our $opt_gprof;
281 our %gprof_dirs;
282
283 my $config; # The currently running config
284 my $current_config_name; # The currently running config file template
285
286 our @opt_experimentals;
287 our $experimental_test_cases= [];
288
289 our $baseport;
290 # $opt_build_thread may later be set from $opt_port_base
291 my $opt_build_thread= $ENV{'MTR_BUILD_THREAD'} || "auto";
292 my $opt_port_base= $ENV{'MTR_PORT_BASE'} || "auto";
293 my $build_thread= 0;
294
295 my $opt_record;
296
297 our $opt_resfile= $ENV{'MTR_RESULT_FILE'} || 0;
298
299 my $opt_skip_core;
300
301 our $opt_check_testcases= 1;
302 my $opt_mark_progress;
303 my $opt_max_connections;
304 our $opt_report_times= 0;
305
306 my $opt_sleep;
307
308 our $opt_retry= 1;
309 our $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2);
310 our $opt_testcase_timeout= $ENV{MTR_TESTCASE_TIMEOUT} || 15; # minutes
311 our $opt_suite_timeout = $ENV{MTR_SUITE_TIMEOUT} || 360; # minutes
312 our $opt_shutdown_timeout= $ENV{MTR_SHUTDOWN_TIMEOUT} || 10; # seconds
313 our $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds
314
315 sub suite_timeout { return $opt_suite_timeout * 60; };
316
317 my $opt_wait_all;
318 my $opt_user_args;
319 my $opt_repeat= 1;
320 my $opt_reorder= 1;
321 my $opt_force_restart= 0;
322
323 our $opt_user = "root";
324
325 my %mysqld_logs;
326 my $opt_debug_sync_timeout= 300; # Default timeout for WAIT_FOR actions.
327 my $warn_seconds = 60;
328
329 my $rebootstrap_re= '--innodb[-_](?:page[-_]size|checksum[-_]algorithm|undo[-_]tablespaces|log[-_]group[-_]home[-_]dir|data[-_]home[-_]dir)|data[-_]file[-_]path|force_rebootstrap';
330
331 sub testcase_timeout ($) { return $opt_testcase_timeout * 60; }
332 sub check_timeout ($) { return testcase_timeout($_[0]); }
333
334 our $opt_warnings= 1;
335
336 our %mysqld_variables;
337 our @optional_plugins;
338
339 my $source_dist= -d "../sql";
340
341 my $opt_max_save_core= env_or_val(MTR_MAX_SAVE_CORE => 5);
342 my $opt_max_save_datadir= env_or_val(MTR_MAX_SAVE_DATADIR => 20);
343 my $opt_max_test_fail= env_or_val(MTR_MAX_TEST_FAIL => 10);
344 my $opt_core_on_failure= 0;
345
346 my $opt_parallel= $ENV{MTR_PARALLEL} || 1;
347 # Some galera tests starts 6 galera nodes. Each galera node requires
348 # three ports: 6*3 = 18. Plus 6 ports are needed for 6 mariadbd servers.
349 # Since the number of ports is rounded up to 10 everywhere, we will
350 # take 30 as the default value:
351 my $opt_port_group_size = $ENV{MTR_PORT_GROUP_SIZE} || 30;
352
353 # lock file to stop tests
354 my $opt_stop_file= $ENV{MTR_STOP_FILE};
355 # print messages when test suite is stopped (for buildbot)
356 my $opt_stop_keep_alive= $ENV{MTR_STOP_KEEP_ALIVE};
357
358 select(STDOUT);
359 $| = 1; # Automatically flush STDOUT
360
361 main();
362
363 sub main {
364 $ENV{MTR_PERL}= mixed_path($^X);
365
366 # Default, verbosity on
367 report_option('verbose', 0);
368
369 # This is needed for test log evaluation in "gen-build-status-page"
370 # in all cases where the calling tool does not log the commands
371 # directly before it executes them, like "make test-force-pl" in RPM builds.
372 mtr_report("Logging: $0 ", join(" ", @ARGV));
373
374 command_line_setup();
375
376 # --help will not reach here, so now it's safe to assume we have binaries
377 My::SafeProcess::find_bin();
378
379 print "vardir: $opt_vardir\n";
380 initialize_servers();
381 init_timers();
382
383 unless (IS_WINDOWS) {
384 binmode(STDOUT,":via(My::Tee)") or die "binmode(STDOUT, :via(My::Tee)):$!";
385 binmode(STDERR,":via(My::Tee)") or die "binmode(STDERR, :via(My::Tee)):$!";
386 }
387
388 mtr_report("Checking supported features...");
389
390 executable_setup();
391
392 # --debug[-common] implies we run debug server
393 $opt_debug_server= 1 if $opt_debug || $opt_debug_common;
394
395 if (using_extern())
396 {
397 # Connect to the running mysqld and find out what it supports
398 collect_mysqld_features_from_running_server();
399 }
400 else
401 {
402 # Run the mysqld to find out what features are available
403 collect_mysqld_features();
404 }
405 check_ssl_support();
406 check_debug_support();
407 environment_setup();
408
409 if (!$opt_suites) {
410 $opt_suites= join ',', collect_default_suites(@DEFAULT_SUITES);
411 }
412 mtr_report("Using suites: $opt_suites") unless @opt_cases;
413
414 mtr_report("Collecting tests...");
415 my $tests= collect_test_cases($opt_reorder, $opt_suites, \@opt_cases, \@opt_skip_test_list);
416 if (@$tests == 0) {
417 mtr_report("No tests to run...");
418 exit 0;
419 }
420
421 mark_time_used('collect');
422
423 if (!using_extern())
424 {
425 mysql_install_db(default_mysqld(), "$opt_vardir/install.db");
426 make_readonly("$opt_vardir/install.db");
427 }
428 if ($opt_dry_run)
429 {
430 for (@$tests) {
431 print $_->fullname(), "\n";
432 }
433 exit 0;
434 }
435
436 if ($opt_gcov) {
437 system './dgcov.pl --purge';
438 }
439
440 #######################################################################
441 my $num_tests= $mtr_report::tests_total= @$tests;
442 if ( $opt_parallel eq "auto" ) {
443 # Try to find a suitable value for number of workers
444 if (IS_WINDOWS)
445 {
446 $opt_parallel= $ENV{NUMBER_OF_PROCESSORS} || 1;
447 }
448 elsif (IS_MAC || IS_FREEBSD)
449 {
450 $opt_parallel= `sysctl -n hw.ncpu`;
451 }
452 else
453 {
454 my $sys_info= My::SysInfo->new();
455 $opt_parallel= $sys_info->num_cpus()+int($sys_info->min_bogomips()/500)-4;
456 }
457 my $max_par= $ENV{MTR_MAX_PARALLEL} || 8;
458 $opt_parallel= $max_par if ($opt_parallel > $max_par);
459 $opt_parallel= $num_tests if ($opt_parallel > $num_tests);
460 $opt_parallel= 1 if ($opt_parallel < 1);
461 mtr_report("Using parallel: $opt_parallel");
462 }
463 $ENV{MTR_PARALLEL} = $opt_parallel;
464
465 if ($opt_parallel > 1 && ($opt_start_exit || $opt_stress)) {
466 mtr_warning("Parallel cannot be used with --start-and-exit or --stress\n" .
467 "Setting parallel to 1");
468 $opt_parallel= 1;
469 }
470
471 # Create server socket on any free port
472 my $server = new IO::Socket::INET
473 (
474 LocalAddr => 'localhost',
475 Proto => 'tcp',
476 Listen => $opt_parallel,
477 );
478 mtr_error("Could not create testcase server port: $!") unless $server;
479 my $server_port = $server->sockport();
480
481 if ($opt_resfile) {
482 resfile_init("$opt_vardir/mtr-results.txt");
483 print_global_resfile();
484 }
485
486 # Create child processes
487 my %children;
488 for my $child_num (1..$opt_parallel){
489 my $child_pid= My::SafeProcess::Base::_safe_fork();
490 if ($child_pid == 0){
491 $server= undef; # Close the server port in child
492 $tests= {}; # Don't need the tests list in child
493
494 # Use subdir of var and tmp unless only one worker
495 if ($opt_parallel > 1) {
496 set_vardir("$opt_vardir/$child_num");
497 $opt_tmpdir= "$opt_tmpdir/$child_num";
498 }
499
500 init_timers();
501 run_worker($server_port, $child_num);
502 exit(1);
503 }
504
505 $children{$child_pid}= 1;
506 }
507 #######################################################################
508
509 mtr_report();
510 mtr_print_thick_line();
511 mtr_print_header($opt_parallel > 1);
512
513 mark_time_used('init');
514
515 my ($prefix, $fail, $completed, $extra_warnings)=
516 Manager::run($server, $tests, \%children);
517
518 exit(0) if $opt_start_exit;
519
520 # Send Ctrl-C to any children still running
521 kill("INT", keys(%children));
522
523 if (!IS_WINDOWS) {
524 # Wait for children to exit
525 foreach my $pid (keys %children)
526 {
527 my $ret_pid= waitpid($pid, 0);
528 if ($ret_pid == -1) {
529 # Child was automatically reaped. Probably not possible
530 # unless you $SIG{CHLD}= 'IGNORE'
531 mtr_warning("Child ${pid} was automatically reaped (this should never happen)");
532 } elsif ($ret_pid != $pid) {
533 confess("Unexpected PID ${ret_pid} instead of expected ${pid}");
534 }
535 my $exit_status= ($? >> 8);
536 mtr_verbose2("Child ${pid} exited with status ${exit_status}");
537 delete $children{$ret_pid};
538 }
539 }
540
541 if ( not @$completed ) {
542 my $test_name= mtr_grab_file($path_testlog);
543 $test_name =~ s/^CURRENT_TEST:\s//;
544 chomp($test_name);
545 my $tinfo = My::Test->new(name => $test_name);
546 $tinfo->{result}= 'MTR_RES_FAILED';
547 $tinfo->{comment}=' ';
548 mtr_report_test($tinfo);
549 mtr_error("Test suite aborted");
550 }
551
552 if ( @$completed != $num_tests){
553
554 # Not all tests completed, failure
555 mtr_report();
556 mtr_report("Only ", int(@$completed), " of $num_tests completed.");
557 }
558
559 if ($opt_valgrind) {
560 # Create minimalistic "test" for the reporting
561 my $tinfo = My::Test->new
562 (
563 suite => { name => 'valgrind', },
564 name => 'valgrind_report',
565 );
566 # Set dummy worker id to align report with normal tests
567 $tinfo->{worker} = 0 if $opt_parallel > 1;
568 if ($valgrind_reports) {
569 $tinfo->{result}= 'MTR_RES_FAILED';
570 $tinfo->{comment}= "Valgrind reported failures at shutdown, see above";
571 $tinfo->{failures}= 1;
572 } else {
573 $tinfo->{result}= 'MTR_RES_PASSED';
574 }
575 mtr_report_test($tinfo);
576 push @$completed, $tinfo;
577 ++$num_tests
578 }
579
580 mtr_print_line();
581
582 print_total_times($opt_parallel) if $opt_report_times;
583 mtr_report_stats($prefix, $fail, $completed, $extra_warnings);
584
585 if ($opt_gcov) {
586 mtr_report("Running dgcov");
587 system "./dgcov.pl --generate > $opt_vardir/last_changes.dgcov";
588 }
589
590 if ( @$completed != $num_tests)
591 {
592 mtr_error("Not all tests completed (only ". scalar(@$completed) .
593 " of $num_tests)");
594 }
595
596 remove_vardir_subs() if $opt_clean_vardir;
597
598 exit(0);
599 }
600
601
602 package Manager;
603 use POSIX ":sys_wait_h";
604 use File::Basename;
605 use File::Find;
606 use IO::Socket::INET;
607 use IO::Select;
608 use mtr_report;
609 use My::Platform;
610
611 my $num_saved_datadir; # Number of datadirs saved in vardir/log/ so far.
612 my $num_failed_test; # Number of tests failed so far
613 my $test_failure; # Set true if test suite failed
614 my $extra_warnings; # Warnings found during server shutdowns
615
616 my $completed;
617 my %running;
618 my $result;
619 my $exe_mysqld; # Used as hint to CoreDump
620 my %names;
621
622 sub parse_protocol($$) {
623 my $sock= shift;
624 my $line= shift;
625
626 if ($line eq 'TESTRESULT'){
627 mtr_verbose2("Got TESTRESULT from ". $names{$sock});
628 $result= My::Test::read_test($sock);
629
630 # Report test status
631 mtr_report_test($result);
632
633 if ( $result->is_failed() ) {
634
635 # Save the workers "savedir" in var/log
636 my $worker_savedir= $result->{savedir};
637 my $worker_savename= basename($worker_savedir);
638 my $savedir= "$opt_vardir/log/$worker_savename";
639
640 # Move any core files from e.g. mysqltest
641 foreach my $coref (glob("core*"), glob("*.dmp"))
642 {
643 mtr_report(" - found '$coref', moving it to '$worker_savedir'");
644 ::move($coref, $worker_savedir);
645 }
646
647 find(
648 {
649 no_chdir => 1,
650 wanted => sub
651 {
652 My::CoreDump::core_wanted(\$num_saved_cores,
653 $opt_max_save_core,
654 @opt_cases == 0,
655 $exe_mysqld, $opt_parallel);
656 }
657 },
658 $worker_savedir);
659
660 if ($num_saved_datadir >= $opt_max_save_datadir)
661 {
662 mtr_report(" - skipping '$worker_savedir/'");
663 main::rmtree($worker_savedir);
664 }
665 else
666 {
667 mtr_report(" - saving '$worker_savedir/' to '$savedir/'");
668 rename($worker_savedir, $savedir);
669 $num_saved_datadir++;
670 }
671 main::resfile_print_test();
672 $num_failed_test++ unless ($result->{retries} ||
673 $result->{exp_fail});
674
675 $test_failure= 1;
676 if ( !$opt_force ) {
677 # Test has failed, force is off
678 push(@$completed, $result);
679 if ($result->{'dont_kill_server'})
680 {
681 mtr_verbose2("${line}: saying BYE to ". $names{$sock});
682 print $sock "BYE\n";
683 return 2;
684 }
685 return ["Failure", 1, $completed, $extra_warnings];
686 }
687 elsif ($opt_max_test_fail > 0 and
688 $num_failed_test >= $opt_max_test_fail) {
689 push(@$completed, $result);
690 mtr_report("Too many tests($num_failed_test) failed!",
691 "Terminating...");
692 return ["Too many failed", 1, $completed, $extra_warnings];
693 }
694 }
695
696 main::resfile_print_test();
697 # Retry test run after test failure
698 my $retries= $result->{retries} || 2;
699 my $test_has_failed= $result->{failures} || 0;
700 if ($test_has_failed and $retries <= $opt_retry){
701 # Test should be run one more time unless it has failed
702 # too many times already
703 my $tname= $result->{name};
704 my $failures= $result->{failures};
705 if ($opt_retry > 1 and $failures >= $opt_retry_failure){
706 mtr_report("\nTest $tname has failed $failures times,",
707 "no more retries!\n");
708 }
709 else {
710 mtr_report("\nRetrying test $tname, ".
711 "attempt($retries/$opt_retry)...\n");
712 #saving the log file as filename.failed in case of retry
713 if ( $result->is_failed() ) {
714 my $worker_logdir= $result->{savedir};
715 my $log_file_name=dirname($worker_logdir)."/".$result->{shortname}.".log";
716
717 if (-e $log_file_name) {
718 $result->{'logfile-failed'} = ::mtr_lastlinesfromfile($log_file_name, 20);
719 } else {
720 $result->{'logfile-failed'} = "";
721 }
722
723 rename $log_file_name, $log_file_name.".failed";
724 }
725 {
726 local @$result{'retries', 'result'};
727 delete $result->{result};
728 $result->{retries}= $retries+1;
729 $result->write_test($sock, 'TESTCASE');
730 }
731 push(@$completed, $result);
732 return 2;
733 }
734 }
735
736 # Repeat test $opt_repeat number of times
737 my $repeat= $result->{repeat} || 1;
738 if ($repeat < $opt_repeat)
739 {
740 $result->{retries}= 0;
741 $result->{rep_failures}++ if $result->{failures};
742 $result->{failures}= 0;
743 delete($result->{result});
744 $result->{repeat}= $repeat+1;
745 $result->write_test($sock, 'TESTCASE');
746 return 2;
747 }
748
749 # Remove from list of running
750 mtr_error("'", $result->{name},"' is not known to be running")
751 unless delete $running{$result->key()};
752
753 # Save result in completed list
754 push(@$completed, $result);
755
756 } # if ($line eq 'TESTRESULT')
757 elsif ($line=~ /^START (.*)$/){
758 # Send first test
759 $names{$sock}= $1;
760 }
761 elsif ($line eq 'WARNINGS'){
762 my $fake_test= My::Test::read_test($sock);
763 my $test_list= join (" ", @{$fake_test->{testnames}});
764 push @$extra_warnings, $test_list;
765 my $report= $fake_test->{'warnings'};
766 mtr_report("***Warnings generated in error logs during shutdown ".
767 "after running tests: $test_list\n\n$report");
768 $test_failure= 1;
769 if ( !$opt_force ) {
770 # Test failure due to warnings, force is off
771 mtr_verbose2("Socket loop exiting 3");
772 return ["Warnings in log", 1, $completed, $extra_warnings];
773 }
774 return 1;
775 }
776 elsif ($line =~ /^SPENT/) {
777 main::add_total_times($line);
778 }
779 elsif ($line eq 'VALGREP' && $opt_valgrind) {
780 $valgrind_reports= 1;
781 }
782 else {
783 mtr_error("Unknown response: '$line' from client");
784 }
785 return 0;
786 }
787
788 sub run ($$$) {
789 my ($server, $tests, $children) = @_;
790 my $suite_timeout= main::start_timer(main::suite_timeout());
791 $exe_mysqld= main::find_mysqld($bindir) || ""; # Used as hint to CoreDump
792 $num_saved_datadir= 0; # Number of datadirs saved in vardir/log/ so far.
793 $num_failed_test= 0; # Number of tests failed so far
794 $test_failure= 0; # Set true if test suite failed
795 $extra_warnings= []; # Warnings found during server shutdowns
796 $completed= [];
797
798 my $s= IO::Select->new();
799 my $childs= 0;
800
801 $s->add($server);
802 while (1) {
803 if ($opt_stop_file)
804 {
805 if (mtr_wait_lock_file($opt_stop_file, $opt_stop_keep_alive))
806 {
807 # We were waiting so restart timer process
808 my $suite_timeout= main::start_timer(main::suite_timeout());
809 }
810 }
811
812 main::mark_time_used('admin');
813 my @ready = $s->can_read(1); # Wake up once every second
814 if (@ready > 0) {
815 mtr_verbose2("Got ". (0 + @ready). " connection(s)");
816 }
817 main::mark_time_idle();
818 my $i= 0;
819 sock_loop: foreach my $sock (@ready) {
820 ++$i;
821 if ($sock == $server) {
822 # New client connected
823 ++$childs;
824 my $child= $sock->accept();
825 mtr_verbose2("Connection ${i}: Worker connected (got ${childs} childs)");
826 $s->add($child);
827 print $child "HELLO\n";
828 }
829 else {
830 my $j= 0;
831 $sock->blocking(0);
832 while (my $line= <$sock>) {
833 ++$j;
834 chomp($line);
835 mtr_verbose2("Connection ${i}.${j}". (exists $names{$sock} ? " from $names{$sock}" : "") .": $line");
836
837 $sock->blocking(1);
838 my $res= parse_protocol($sock, $line);
839 $sock->blocking(0);
840 if (ref $res eq 'ARRAY') {
841 return @$res;
842 } elsif ($res == 1) {
843 next;
844 } elsif ($res == 2) {
845 next sock_loop;
846 }
847 if (IS_WINDOWS and !IS_CYGWIN) {
848 # Strawberry and ActiveState don't support blocking(0), the next iteration will be blocked!
849 # If there is next response now in the buffer and it is TESTRESULT we are affected by MDEV-30836 and the manager will hang.
850 last;
851 }
852 }
853 $sock->blocking(1);
854 if ($j == 0) {
855 # Client disconnected
856 --$childs;
857 mtr_verbose2((exists $names{$sock} ? $names{$sock} : "Worker"). " closed socket (left ${childs} childs)");
858 $s->remove($sock);
859 $sock->close;
860 next;
861 }
862
863 # Find next test to schedule
864 # - Try to use same configuration as worker used last time
865
866 my $next;
867 my $second_best;
868 for(my $i= 0; $i <= @$tests; $i++)
869 {
870 my $t= $tests->[$i];
871
872 last unless defined $t;
873
874 if (main::run_testcase_check_skip_test($t)){
875 # Move the test to completed list
876 #mtr_report("skip - Moving test $i to completed");
877 push(@$completed, splice(@$tests, $i, 1));
878
879 # Since the test at pos $i was taken away, next
880 # test will also be at $i -> redo
881 redo;
882 }
883
884 # From secondary choices, we prefer to pick a 'long-running' test if
885 # possible; this helps avoid getting stuck with a few of those at the
886 # end of high --parallel runs, with most workers being idle.
887 if (!defined $second_best ||
888 ($t->{'long_test'} && !($tests->[$second_best]{'long_test'}))){
889 #mtr_report("Setting second_best to $i");
890 $second_best= $i;
891 }
892
893 # Smart allocation of next test within this thread.
894
895 if ($opt_reorder and $opt_parallel > 1 and defined $result)
896 {
897 my $wid= $result->{worker};
898 # Reserved for other thread, try next
899 next if (defined $t->{reserved} and $t->{reserved} != $wid);
900 if (! defined $t->{reserved})
901 {
902 # Force-restart not relevant when comparing *next* test
903 $t->{criteria} =~ s/force-restart$/no-restart/;
904 my $criteria= $t->{criteria};
905 # Reserve similar tests for this worker, but not too many
906 my $maxres= (@$tests - $i) / $opt_parallel + 1;
907 for (my $j= $i+1; $j <= $i + $maxres; $j++)
908 {
909 my $tt= $tests->[$j];
910 last unless defined $tt;
911 last if $tt->{criteria} ne $criteria;
912 $tt->{reserved}= $wid;
913 }
914 }
915 }
916
917 # At this point we have found next suitable test
918 $next= splice(@$tests, $i, 1);
919 last;
920 } # for(my $i= 0; $i <= @$tests; $i++)
921
922 # Use second best choice if no other test has been found
923 if (!$next and defined $second_best){
924 #mtr_report("Take second best choice $second_best");
925 mtr_error("Internal error, second best too large($second_best)")
926 if $second_best > $#$tests;
927 $next= splice(@$tests, $second_best, 1);
928 delete $next->{reserved};
929 }
930
931 if ($next) {
932 # We don't need this any more
933 delete $next->{criteria};
934 $next->write_test($sock, 'TESTCASE');
935 $running{$next->key()}= $next;
936 }
937 else {
938 # No more test, tell child to exit
939 mtr_verbose2("Saying BYE to ". $names{$sock});
940 print $sock "BYE\n";
941 } # else (!$next)
942 } # else ($sock != $server)
943 } # foreach my $sock (@ready)
944
945 if (!IS_WINDOWS) {
946 foreach my $pid (keys %$children)
947 {
948 my $res= waitpid($pid, WNOHANG);
949 if ($res == $pid || $res == -1) {
950 if ($res == -1) {
951 # Child was automatically reaped. Probably not possible
952 # unless you $SIG{CHLD}= 'IGNORE'
953 mtr_warning("Child ${pid} was automatically reaped (this should never happen)");
954 }
955 my $exit_status= ($? >> 8);
956 mtr_verbose2("Child ${pid} exited with status ${exit_status}");
957 delete $children->{$pid};
958 if (!%$children && $childs) {
959 mtr_verbose2("${childs} children didn't close socket before dying!");
960 $childs= 0;
961 }
962 } elsif ($res != 0) {
963 confess("Unexpected result ${res} on waitpid(${pid}, WNOHANG)");
964 }
965 }
966 }
967
968 if ($childs == 0){
969 return ("Completed", $test_failure, $completed, $extra_warnings);
970 }
971
972 # ----------------------------------------------------
973 # Check if test suite timer expired
974 # ----------------------------------------------------
975 if ( main::has_expired($suite_timeout) )
976 {
977 mtr_report("Test suite timeout! Terminating...");
978 return ("Timeout", 1, $completed, $extra_warnings);
979 }
980 }
981 }
982
983 1;
984
985 package main;
986
987 sub run_worker ($) {
988 my ($server_port, $thread_num)= @_;
989
990 $SIG{INT}= sub { exit(1); };
991 $SIG{HUP}= sub { exit(1); };
992
993 # Connect to server
994 my $server = new IO::Socket::INET
995 (
996 PeerAddr => 'localhost',
997 PeerPort => $server_port,
998 Proto => 'tcp'
999 );
1000 mtr_error("Could not connect to server at port $server_port: $!")
1001 unless $server;
1002
1003 # --------------------------------------------------------------------------
1004 # Set worker name
1005 # --------------------------------------------------------------------------
1006 report_option('name',"worker[". sprintf("%02d", $thread_num). "]");
1007 my $proc_title= basename($0). " ${mtr_report::name} :". $server->sockport(). " -> :${server_port}";
1008 $0= $proc_title;
1009 mtr_verbose2("Running at PID $$");
1010
1011 # --------------------------------------------------------------------------
1012 # Set different ports per thread
1013 # --------------------------------------------------------------------------
1014 set_build_thread_ports($thread_num);
1015
1016 # --------------------------------------------------------------------------
1017 # Turn off verbosity in workers, unless explicitly specified
1018 # --------------------------------------------------------------------------
1019 report_option('verbose', undef) if ($opt_verbose == 0);
1020
1021 environment_setup();
1022
1023 # Read hello from server which it will send when shared
1024 # resources have been setup
1025 my $hello= <$server>;
1026
1027 setup_vardir();
1028 check_running_as_root();
1029
1030 if ( using_extern() ) {
1031 create_config_file_for_extern(%opts_extern);
1032 }
1033
1034 # Ask server for first test
1035 print $server "START ${mtr_report::name}\n";
1036
1037 mark_time_used('init');
1038
1039 while (my $line= <$server>){
1040 chomp($line);
1041 if ($line eq 'TESTCASE'){
1042 my $test= My::Test::read_test($server);
1043 $0= $proc_title. " ". $test->{name};
1044
1045 # Clear comment and logfile, to avoid
1046 # reusing them from previous test
1047 delete($test->{'comment'});
1048 delete($test->{'logfile'});
1049
1050 # A sanity check. Should this happen often we need to look at it.
1051 if (defined $test->{reserved} && $test->{reserved} != $thread_num) {
1052 my $tres= $test->{reserved};
1053 mtr_warning("Test reserved for w$tres picked up by w$thread_num");
1054 }
1055 $test->{worker} = $thread_num if $opt_parallel > 1;
1056
1057 run_testcase($test, $server);
1058 #$test->{result}= 'MTR_RES_PASSED';
1059 # Send it back, now with results set
1060 mtr_verbose2('Writing TESTRESULT');
1061 $test->write_test($server, 'TESTRESULT');
1062 mark_time_used('restart');
1063 }
1064 elsif ($line eq 'BYE'){
1065 mtr_verbose2("Manager said BYE");
1066 # We need to gracefully shut down the servers to see any
1067 # Valgrind memory leak errors etc. since last server restart.
1068 if ($opt_warnings) {
1069 stop_servers(reverse all_servers());
1070 if(check_warnings_post_shutdown($server)) {
1071 # Warnings appeared in log file(s) during final server shutdown.
1072 exit(1);
1073 }
1074 }
1075 else {
1076 stop_all_servers($opt_shutdown_timeout);
1077 }
1078 mark_time_used('restart');
1079 my $valgrind_reports= 0;
1080 if ($opt_valgrind) {
1081 $valgrind_reports= valgrind_exit_reports();
1082 print $server "VALGREP\n" if $valgrind_reports;
1083 }
1084 if ( $opt_gprof ) {
1085 gprof_collect (find_mysqld($bindir), keys %gprof_dirs);
1086 }
1087 mark_time_used('admin');
1088 print_times_used($server, $thread_num);
1089 exit($valgrind_reports);
1090 }
1091 else {
1092 mtr_error("Could not understand server, '$line'");
1093 }
1094 }
1095
1096 stop_all_servers();
1097
1098 exit(1);
1099 }
1100
1101
1102 # Setup any paths that are $opt_vardir related
1103 sub set_vardir {
1104 ($opt_vardir)= @_;
1105
1106 $path_vardir_trace= $opt_vardir;
1107 # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
1108 $path_vardir_trace=~ s/^\w://;
1109
1110 # Location of my.cnf that all clients use
1111 $path_config_file= "$opt_vardir/my.cnf";
1112
1113 $path_testlog= "$opt_vardir/log/mysqltest.log";
1114 $path_current_testlog= "$opt_vardir/log/current_test";
1115
1116 }
1117
1118
1119 sub print_global_resfile {
1120 resfile_global("start_time", isotime $^T);
1121 resfile_global("user_id", $<);
1122 resfile_global("embedded-server", $opt_embedded_server ? 1 : 0);
1123 resfile_global("ps-protocol", $opt_ps_protocol ? 1 : 0);
1124 resfile_global("sp-protocol", $opt_sp_protocol ? 1 : 0);
1125 resfile_global("view-protocol", $opt_view_protocol ? 1 : 0);
1126 resfile_global("cursor-protocol", $opt_cursor_protocol ? 1 : 0);
1127 resfile_global("ssl", $opt_ssl ? 1 : 0);
1128 resfile_global("compress", $opt_compress ? 1 : 0);
1129 resfile_global("parallel", $opt_parallel);
1130 resfile_global("check-testcases", $opt_check_testcases ? 1 : 0);
1131 resfile_global("mariadbd", \@opt_extra_mysqld_opt);
1132 resfile_global("debug", $opt_debug ? 1 : 0);
1133 resfile_global("gcov", $opt_gcov ? 1 : 0);
1134 resfile_global("gprof", $opt_gprof ? 1 : 0);
1135 resfile_global("mem", $opt_mem);
1136 resfile_global("tmpdir", $opt_tmpdir);
1137 resfile_global("vardir", $opt_vardir);
1138 resfile_global("fast", $opt_fast ? 1 : 0);
1139 resfile_global("force-restart", $opt_force_restart ? 1 : 0);
1140 resfile_global("reorder", $opt_reorder ? 1 : 0);
1141 resfile_global("sleep", $opt_sleep);
1142 resfile_global("repeat", $opt_repeat);
1143 resfile_global("user", $opt_user);
1144 resfile_global("testcase-timeout", $opt_testcase_timeout);
1145 resfile_global("suite-timeout", $opt_suite_timeout);
1146 resfile_global("shutdown-timeout", $opt_shutdown_timeout ? 1 : 0);
1147 resfile_global("warnings", $opt_warnings ? 1 : 0);
1148 resfile_global("max-connections", $opt_max_connections);
1149 resfile_global("product", "MariaDB");
1150 resfile_global("xml-report", $opt_xml_report);
1151 # Somewhat hacky code to convert numeric version back to dot notation
1152 my $v1= int($mysql_version_id / 10000);
1153 my $v2= int(($mysql_version_id % 10000)/100);
1154 my $v3= $mysql_version_id % 100;
1155 resfile_global("version", "$v1.$v2.$v3");
1156 }
1157
1158
1159
1160 sub command_line_setup {
1161 my $opt_comment;
1162 my $opt_usage;
1163 my $opt_list_options;
1164
1165 # Read the command line options
1166 # Note: Keep list in sync with usage at end of this file
1167 Getopt::Long::Configure("pass_through");
1168 my %options=(
1169 # Control what engine/variation to run
1170 'embedded-server' => \$opt_embedded_server,
1171 'ps-protocol' => \$opt_ps_protocol,
1172 'sp-protocol' => \$opt_sp_protocol,
1173 'view-protocol' => \$opt_view_protocol,
1174 'cursor-protocol' => \$opt_cursor_protocol,
1175 'non-blocking-api' => \$opt_non_blocking_api,
1176 'ssl|with-openssl' => \$opt_ssl,
1177 'skip-ssl' => \$opt_skip_ssl,
1178 'compress' => \$opt_compress,
1179 'vs-config=s' => \$multiconfig,
1180
1181 # Max number of parallel threads to use
1182 'parallel=s' => \$opt_parallel,
1183
1184 # Config file to use as template for all tests
1185 'defaults-file=s' => \&collect_option,
1186 # Extra config file to append to all generated configs
1187 'defaults-extra-file=s' => \&collect_option,
1188
1189 # Control what test suites or cases to run
1190 'force+' => \$opt_force,
1191 'skip-not-found' => \$opt_skip_not_found,
1192 'suite|suites=s' => \$opt_suites,
1193 'skip-rpl' => \&collect_option,
1194 'skip-test=s' => \&collect_option,
1195 'do-test=s' => \&collect_option,
1196 'start-from=s' => \&collect_option,
1197 'big-test+' => \$opt_big_test,
1198 'combination=s' => \@opt_combinations,
1199 'experimental=s' => \@opt_experimentals,
1200 'staging-run' => \$opt_staging_run,
1201
1202 # Specify ports
1203 'build-thread|mtr-build-thread=i' => \$opt_build_thread,
1204 'port-base|mtr-port-base=i' => \$opt_port_base,
1205 'port-group-size=s' => \$opt_port_group_size,
1206
1207 # Test case authoring
1208 'record' => \$opt_record,
1209 'check-testcases!' => \$opt_check_testcases,
1210 'mark-progress' => \$opt_mark_progress,
1211
1212 # Extra options used when starting mariadbd
1213 'mariadbd=s' => \@opt_extra_mysqld_opt,
1214 'mariadbd-env=s' => \@opt_mysqld_envs,
1215 # mysqld is an alias for mariadbd
1216 'mysqld=s' => \@opt_extra_mysqld_opt,
1217 'mysqld-env=s' => \@opt_mysqld_envs,
1218
1219 # Run test on running server
1220 'extern=s' => \%opts_extern, # Append to hash
1221
1222 # Debugging
1223 'debug' => \$opt_debug,
1224 'debug-common' => \$opt_debug_common,
1225 'debug-server' => \$opt_debug_server,
1226 'max-save-core=i' => \$opt_max_save_core,
1227 'max-save-datadir=i' => \$opt_max_save_datadir,
1228 'max-test-fail=i' => \$opt_max_test_fail,
1229 'core-on-failure' => \$opt_core_on_failure,
1230
1231 # Coverage, profiling etc
1232 'gcov' => \$opt_gcov,
1233 'gprof' => \$opt_gprof,
1234 'debug-sync-timeout=i' => \$opt_debug_sync_timeout,
1235
1236 # Directories
1237 'tmpdir=s' => \$opt_tmpdir,
1238 'vardir=s' => \$opt_vardir,
1239 'mem' => \$opt_mem,
1240 'clean-vardir' => \$opt_clean_vardir,
1241 'client-bindir=s' => \$path_client_bindir,
1242 'client-libdir=s' => \$path_client_libdir,
1243
1244 # Misc
1245 'comment=s' => \$opt_comment,
1246 'fast' => \$opt_fast,
1247 'force-restart' => \$opt_force_restart,
1248 'reorder!' => \$opt_reorder,
1249 'enable-disabled' => \&collect_option,
1250 'verbose|v+' => \$opt_verbose,
1251 'verbose-restart' => \&report_option,
1252 'sleep=i' => \$opt_sleep,
1253 'start-dirty' => \$opt_start_dirty,
1254 'start-and-exit' => \$opt_start_exit,
1255 'start' => \$opt_start,
1256 'user-args' => \$opt_user_args,
1257 'wait-all' => \$opt_wait_all,
1258 'print-testcases' => \&collect_option,
1259 'repeat=i' => \$opt_repeat,
1260 'retry=i' => \$opt_retry,
1261 'retry-failure=i' => \$opt_retry_failure,
1262 'timer!' => \&report_option,
1263 'user=s' => \$opt_user,
1264 'testcase-timeout=i' => \$opt_testcase_timeout,
1265 'suite-timeout=i' => \$opt_suite_timeout,
1266 'shutdown-timeout=i' => \$opt_shutdown_timeout,
1267 'warnings!' => \$opt_warnings,
1268 'timestamp' => \&report_option,
1269 'timediff' => \&report_option,
1270 'stop-file=s' => \$opt_stop_file,
1271 'stop-keep-alive=i' => \$opt_stop_keep_alive,
1272 'max-connections=i' => \$opt_max_connections,
1273 'report-times' => \$opt_report_times,
1274 'result-file' => \$opt_resfile,
1275 'stress=s' => \$opt_stress,
1276 'tail-lines=i' => \$opt_tail_lines,
1277 'dry-run' => \$opt_dry_run,
1278
1279 'help|h' => \$opt_usage,
1280 # list-options is internal, not listed in help
1281 'list-options' => \$opt_list_options,
1282 'skip-test-list=s' => \@opt_skip_test_list,
1283 'xml-report=s' => \$opt_xml_report,
1284 'open-files-limit=i', => \$opt_open_files_limit,
1285
1286 My::Debugger::options(),
1287 My::CoreDump::options(),
1288 My::Platform::options()
1289 );
1290
1291 # fix options (that take an optional argument and *only* after = sign
1292 @ARGV = My::Debugger::fix_options(@ARGV);
1293 GetOptions(%options) or usage("Can't read options");
1294 usage("") if $opt_usage;
1295 list_options(\%options) if $opt_list_options;
1296
1297 # --------------------------------------------------------------------------
1298 # Setup verbosity
1299 # --------------------------------------------------------------------------
1300 if ($opt_verbose != 0){
1301 report_option('verbose', $opt_verbose);
1302 }
1303
1304 # Negative values aren't meaningful on integer options
1305 foreach(grep(/=i$/, keys %options))
1306 {
1307 if (defined ${$options{$_}} &&
1308 do { no warnings "numeric"; int ${$options{$_}} < 0})
1309 {
1310 my $v= (split /=/)[0];
1311 die("$v doesn't accept a negative value:");
1312 }
1313 }
1314
1315 # Find the absolute path to the test directory
1316 $glob_mysql_test_dir= cwd();
1317 if ($glob_mysql_test_dir =~ / /)
1318 {
1319 die("Working directory \"$glob_mysql_test_dir\" contains space\n".
1320 "Bailing out, cannot function properly with space in path");
1321 }
1322 if (IS_CYGWIN)
1323 {
1324 if (My::Platform::check_cygwin_subshell()) {
1325 die("Cygwin /bin/sh subshell requires fix with --cygwin-subshell-fix=do\n");
1326 }
1327 # Use mixed path format i.e c:/path/to/
1328 $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
1329 }
1330
1331 # In most cases, the base directory we find everything relative to,
1332 # is the parent directory of the "mysql-test" directory. For source
1333 # distributions, TAR binary distributions and some other packages.
1334 $basedir= dirname($glob_mysql_test_dir);
1335
1336 # In the RPM case, binaries and libraries are installed in the
1337 # default system locations, instead of having our own private base
1338 # directory. And we install "/usr/share/mariadb-test". Moving up one
1339 # more directory relative to "mariadb-test" gives us a usable base
1340 # directory for RPM installs.
1341 if ( ! $source_dist and ! -d "$basedir/bin" )
1342 {
1343 $basedir= dirname($basedir);
1344 }
1345 # For .deb, it's like RPM, but installed in /usr/share/mariadb/mariadb-test.
1346 # So move up one more directory level yet.
1347 if ( ! $source_dist and ! -d "$basedir/bin" )
1348 {
1349 $basedir= dirname($basedir);
1350 }
1351
1352 # Respect MTR_BINDIR variable, which is typically set in to the
1353 # build directory in out-of-source builds.
1354 $bindir=$ENV{MTR_BINDIR}||$basedir;
1355
1356 fix_vs_config_dir();
1357
1358 # Look for the client binaries directory
1359 if ($path_client_bindir)
1360 {
1361 # --client-bindir=path set on command line, check that the path exists
1362 $path_client_bindir= mtr_path_exists($path_client_bindir);
1363 }
1364 else
1365 {
1366 $path_client_bindir= mtr_path_exists("$bindir/client_release",
1367 "$bindir/client_debug",
1368 "$bindir/client/$multiconfig",
1369 "$bindir/client$multiconfig",
1370 "$bindir/client",
1371 "$bindir/bin");
1372 }
1373
1374 # Look for language files and charsetsdir, use same share
1375 $path_language= mtr_path_exists("$bindir/share/mariadb",
1376 "$bindir/share/mysql",
1377 "$bindir/sql/share",
1378 "$bindir/share");
1379 my $path_share= $path_language;
1380 $path_charsetsdir = mtr_path_exists("$basedir/share/mariadb/charsets",
1381 "$basedir/share/mysql/charsets",
1382 "$basedir/sql/share/charsets",
1383 "$basedir/share/charsets");
1384 if ( $opt_comment )
1385 {
1386 mtr_report();
1387 mtr_print_thick_line('#');
1388 mtr_report("# $opt_comment");
1389 mtr_print_thick_line('#');
1390 }
1391
1392 if ( @opt_experimentals )
1393 {
1394 # $^O on Windows considered not generic enough
1395 my $plat= (IS_WINDOWS) ? 'windows' : $^O;
1396
1397 # read the list of experimental test cases from the files specified on
1398 # the command line
1399 $experimental_test_cases = [];
1400 foreach my $exp_file (@opt_experimentals)
1401 {
1402 open(FILE, "<", $exp_file)
1403 or mtr_error("Can't read experimental file: $exp_file");
1404 mtr_report("Using experimental file: $exp_file");
1405 while(<FILE>) {
1406 chomp;
1407 # remove comments (# foo) at the beginning of the line, or after a
1408 # blank at the end of the line
1409 s/(\s+|^)#.*$//;
1410 # If @ platform specifier given, use this entry only if it contains
1411 # @<platform> or @!<xxx> where xxx != platform
1412 if (/\@.*/)
1413 {
1414 next if (/\@!$plat/);
1415 next unless (/\@$plat/ or /\@!/);
1416 # Then remove @ and everything after it
1417 s/\@.*$//;
1418 }
1419 # remove whitespace
1420 s/^\s+//;
1421 s/\s+$//;
1422 # if nothing left, don't need to remember this line
1423 if ( $_ eq "" ) {
1424 next;
1425 }
1426 # remember what is left as the name of another test case that should be
1427 # treated as experimental
1428 print " - $_\n";
1429 push @$experimental_test_cases, $_;
1430 }
1431 close FILE;
1432 }
1433 }
1434
1435 foreach my $arg ( @ARGV )
1436 {
1437 if ( $arg =~ /^--skip-/ )
1438 {
1439 push(@opt_extra_mysqld_opt, $arg);
1440 }
1441 elsif ( $arg =~ /^--$/ )
1442 {
1443 # It is an effect of setting 'pass_through' in option processing
1444 # that the lone '--' separating options from arguments survives,
1445 # simply ignore it.
1446 }
1447 elsif ( $arg =~ /^-/ )
1448 {
1449 usage("Invalid option \"$arg\"");
1450 }
1451 else
1452 {
1453 push(@opt_cases, $arg);
1454 }
1455 }
1456
1457 if ( @opt_cases )
1458 {
1459 # Run big tests if explicitly specified on command line
1460 $opt_big_test= 1;
1461 }
1462
1463 # --------------------------------------------------------------------------
1464 # Find out type of logging that are being used
1465 # --------------------------------------------------------------------------
1466 foreach my $arg ( @opt_extra_mysqld_opt )
1467 {
1468 if ( $arg =~ /binlog[-_]format=(\S+)/ )
1469 {
1470 # Save this for collect phase
1471 collect_option('binlog-format', $1);
1472 mtr_report("Using binlog format '$1'");
1473 }
1474 }
1475
1476
1477 # --------------------------------------------------------------------------
1478 # Find out default storage engine being used(if any)
1479 # --------------------------------------------------------------------------
1480 foreach my $arg ( @opt_extra_mysqld_opt )
1481 {
1482 if ( $arg =~ /default-storage-engine=(\S+)/ )
1483 {
1484 # Save this for collect phase
1485 collect_option('default-storage-engine', $1);
1486 mtr_report("Using default engine '$1'")
1487 }
1488 }
1489
1490 if (IS_WINDOWS and defined $opt_mem) {
1491 mtr_report("--mem not supported on Windows, ignored");
1492 $opt_mem= undef;
1493 }
1494
1495 if ($opt_port_base ne "auto")
1496 {
1497 if (my $rem= $opt_port_base % 10)
1498 {
1499 mtr_warning ("Port base $opt_port_base rounded down to multiple of 10");
1500 $opt_port_base-= $rem;
1501 }
1502 $opt_build_thread= $opt_port_base / 10 - 1000;
1503 }
1504
1505 # --------------------------------------------------------------------------
1506 # Check if we should speed up tests by trying to run on tmpfs
1507 # --------------------------------------------------------------------------
1508 if ( defined $opt_mem)
1509 {
1510 mtr_error("Can't use --mem and --vardir at the same time ")
1511 if $opt_vardir;
1512 mtr_error("Can't use --mem and --tmpdir at the same time ")
1513 if $opt_tmpdir;
1514
1515 # Search through list of locations that are known
1516 # to be "fast disks" to find a suitable location
1517 my @tmpfs_locations= ("/run/shm", "/dev/shm", "/tmp");
1518
1519 # Use $ENV{'MTR_MEM'} as first location to look (if defined)
1520 unshift(@tmpfs_locations, $ENV{'MTR_MEM'}) if defined $ENV{'MTR_MEM'};
1521
1522 foreach my $fs (@tmpfs_locations)
1523 {
1524 if ( -d $fs && ! -l $fs && -w $fs )
1525 {
1526 my $template= "var_${opt_build_thread}_XXXX";
1527 $opt_mem= tempdir( $template, DIR => $fs, CLEANUP => 0);
1528 last;
1529 }
1530 }
1531 }
1532
1533 # --------------------------------------------------------------------------
1534 # Set the "var/" directory, the base for everything else
1535 # --------------------------------------------------------------------------
1536 my $vardir_location= (defined $ENV{MTR_BINDIR}
1537 ? "$ENV{MTR_BINDIR}/mysql-test"
1538 : $glob_mysql_test_dir);
1539 $vardir_location= realpath $vardir_location;
1540 $default_vardir= "$vardir_location/var";
1541
1542 if ( ! $opt_vardir )
1543 {
1544 $opt_vardir= $default_vardir;
1545 }
1546
1547 # We make the path absolute, as the server will do a chdir() before usage
1548 unless ( $opt_vardir =~ m,^/, or
1549 (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:[/\\],i) )
1550 {
1551 # Make absolute path, relative test dir
1552 $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
1553 }
1554
1555 set_vardir($opt_vardir);
1556
1557 # --------------------------------------------------------------------------
1558 # Set the "tmp" directory
1559 # --------------------------------------------------------------------------
1560 if ( ! $opt_tmpdir )
1561 {
1562 $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
1563
1564 if (check_socket_path_length("$opt_tmpdir/mysql_testsocket.sock"))
1565 {
1566 mtr_report("Too long tmpdir path '$opt_tmpdir'",
1567 " creating a shorter one...");
1568
1569 # Create temporary directory in standard location for temporary files
1570 $opt_tmpdir= tempdir( TMPDIR => 1, CLEANUP => 0 );
1571 mtr_report(" - using tmpdir: '$opt_tmpdir'\n");
1572
1573 # Remember pid that created dir so it's removed by correct process
1574 $opt_tmpdir_pid= $$;
1575 }
1576 }
1577 $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
1578
1579 # --------------------------------------------------------------------------
1580 # fast option
1581 # --------------------------------------------------------------------------
1582 if ($opt_fast){
1583 $opt_shutdown_timeout= 0; # Kill processes instead of nice shutdown
1584 }
1585
1586 # --------------------------------------------------------------------------
1587 # Check parallel value
1588 # --------------------------------------------------------------------------
1589 if ($opt_parallel ne "auto" && $opt_parallel < 1)
1590 {
1591 mtr_error("0 or negative parallel value makes no sense, use 'auto' or positive number");
1592 }
1593
1594 # --------------------------------------------------------------------------
1595 # Record flag
1596 # --------------------------------------------------------------------------
1597 if ( $opt_record and ! @opt_cases )
1598 {
1599 mtr_error("Will not run in record mode without a specific test case");
1600 }
1601
1602 if ( $opt_record ) {
1603 # Use only one worker with --record
1604 $opt_parallel= 1;
1605 }
1606
1607 # --------------------------------------------------------------------------
1608 # Embedded server flag
1609 # --------------------------------------------------------------------------
1610 if ( $opt_embedded_server )
1611 {
1612 $opt_skip_ssl= 1; # Turn off use of SSL
1613
1614 # Turn off use of bin log
1615 push(@opt_extra_mysqld_opt, "--skip-log-bin");
1616
1617 if ( using_extern() )
1618 {
1619 mtr_error("Can't use --extern with --embedded-server");
1620 }
1621 }
1622
1623 # --------------------------------------------------------------------------
1624 # Big test and staging_run flags
1625 # --------------------------------------------------------------------------
1626 if ( $opt_big_test )
1627 {
1628 $ENV{'BIG_TEST'}= 1;
1629 }
1630 $ENV{'STAGING_RUN'}= $opt_staging_run;
1631
1632 # --------------------------------------------------------------------------
1633 # Gcov flag
1634 # --------------------------------------------------------------------------
1635 if ( ($opt_gcov or $opt_gprof) and ! $source_dist )
1636 {
1637 mtr_error("Coverage test needs the source - please use source dist");
1638 }
1639
1640 $ENV{ASAN_OPTIONS}= "abort_on_error=1:" . ($ENV{ASAN_OPTIONS} || '');
1641 $ENV{ASAN_OPTIONS}= "suppressions=${glob_mysql_test_dir}/asan.supp:" .
1642 $ENV{ASAN_OPTIONS}
1643 if -f "$glob_mysql_test_dir/asan.supp" and not IS_WINDOWS;
1644 # The following can be useful when a test fails without any asan report
1645 # on stderr like with openssl_1.test
1646 # $ENV{ASAN_OPTIONS}= "log_path=${opt_vardir}/log/asan:" . $ENV{ASAN_OPTIONS};
1647
1648 # Add leak suppressions
1649 $ENV{LSAN_OPTIONS}= "suppressions=${glob_mysql_test_dir}/lsan.supp:print_suppressions=0"
1650 if -f "$glob_mysql_test_dir/lsan.supp" and not IS_WINDOWS;
1651
1652 mtr_verbose("ASAN_OPTIONS=$ENV{ASAN_OPTIONS}");
1653
1654 # --------------------------------------------------------------------------
1655 # Modified behavior with --start options
1656 # --------------------------------------------------------------------------
1657 if ($opt_start or $opt_start_dirty or $opt_start_exit) {
1658 collect_option ('quick-collect', 1);
1659 $start_only= 1;
1660 }
1661 if ($opt_debug)
1662 {
1663 $opt_testcase_timeout= 7 * 24 * 60;
1664 $opt_suite_timeout= 7 * 24 * 60;
1665 $opt_retry= 1;
1666 $opt_retry_failure= 1;
1667 }
1668
1669 # --------------------------------------------------------------------------
1670 # Check use of user-args
1671 # --------------------------------------------------------------------------
1672
1673 if ($opt_user_args) {
1674 mtr_error("--user-args only valid with --start options")
1675 unless $start_only;
1676 mtr_error("--user-args cannot be combined with named suites or tests")
1677 if $opt_suites || @opt_cases;
1678 }
1679
1680 # --------------------------------------------------------------------------
1681 # Check use of wait-all
1682 # --------------------------------------------------------------------------
1683
1684 if ($opt_wait_all && ! $start_only)
1685 {
1686 mtr_error("--wait-all can only be used with --start options");
1687 }
1688
1689 # --------------------------------------------------------------------------
1690 # Gather stress-test options and modify behavior
1691 # --------------------------------------------------------------------------
1692
1693 if ($opt_stress)
1694 {
1695 $opt_stress=~ s/,/ /g;
1696 $opt_user_args= 1;
1697 mtr_error("--stress cannot be combined with named ordinary suites or tests")
1698 if $opt_suites || @opt_cases;
1699 $opt_suites="stress";
1700 @opt_cases= ("wrapper");
1701 $ENV{MST_OPTIONS}= $opt_stress;
1702 }
1703
1704 # --------------------------------------------------------------------------
1705 # Check timeout arguments
1706 # --------------------------------------------------------------------------
1707
1708 mtr_error("Invalid value '$opt_testcase_timeout' supplied ".
1709 "for option --testcase-timeout")
1710 if ($opt_testcase_timeout <= 0);
1711 mtr_error("Invalid value '$opt_suite_timeout' supplied ".
1712 "for option --testsuite-timeout")
1713 if ($opt_suite_timeout <= 0);
1714
1715 if ($opt_debug_common)
1716 {
1717 $opt_debug= 1;
1718 $debug_d= "d,query,info,error,enter,exit";
1719 }
1720
1721 My::CoreDump::pre_setup();
1722 }
1723
1724
1725 #
1726 # To make it easier for different devs to work on the same host,
1727 # an environment variable can be used to control all ports. A small
1728 # number is to be used, 0 - 16 or similar.
1729 #
1730 # Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
1731 # versions of this script, else a 4.0 test run might conflict with a
1732 # 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
1733 # all port numbers might not be used in this version of the script.
1734 #
1735 # Also note the limitation of ports we are allowed to hand out. This
1736 # differs between operating systems and configuration, see
1737 # http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
1738 # But a fairly safe range seems to be 5001 - 32767
1739 #
1740 sub set_build_thread_ports($) {
1741 my $thread= shift || 0;
1742
1743 if ( lc($opt_build_thread) eq 'auto' ) {
1744 my $found_free = 0;
1745 $build_thread = 300; # Start attempts from here
1746 my $build_thread_upper = $build_thread + ($opt_parallel > 1500
1747 ? 3000
1748 : 2 * $opt_parallel) + 300;
1749 while (! $found_free)
1750 {
1751 $build_thread= mtr_get_unique_id($build_thread, $build_thread_upper);
1752 if ( !defined $build_thread ) {
1753 mtr_error("Could not get a unique build thread id");
1754 }
1755 $found_free= check_ports_free($build_thread);
1756 # If not free, release and try from next number
1757 if (! $found_free) {
1758 mtr_release_unique_id();
1759 $build_thread++;
1760 }
1761 }
1762 }
1763 else
1764 {
1765 $build_thread = $opt_build_thread + $thread - 1;
1766 if (! check_ports_free($build_thread)) {
1767 # Some port was not free(which one has already been printed)
1768 mtr_error("Some port(s) was not free")
1769 }
1770 }
1771 $ENV{MTR_BUILD_THREAD}= $build_thread;
1772
1773 # Calculate baseport
1774 $baseport= $build_thread * $opt_port_group_size + 10000;
1775 if ( $baseport < 5001 or $baseport + $opt_port_group_size >= 32767 )
1776 {
1777 mtr_error("MTR_BUILD_THREAD number results in a port",
1778 "outside 5001 - 32767",
1779 "($baseport - $baseport + $opt_port_group_size)");
1780 }
1781
1782 mtr_report("Using MTR_BUILD_THREAD $build_thread,",
1783 "with reserved ports $baseport..".($baseport+($opt_port_group_size-1)));
1784
1785 }
1786
1787
1788 sub collect_mysqld_features {
1789 #
1790 # Execute "mysqld --no-defaults --help --verbose" to get a
1791 # list of all features and settings
1792 #
1793 # --no-defaults and --skip-grant-tables are to avoid loading
1794 # system-wide configs and plugins
1795 #
1796 # --datadir must exist, mysqld will chdir into it
1797 #
1798 my $args;
1799 mtr_init_args(\$args);
1800 mtr_add_arg($args, "--no-defaults");
1801 mtr_add_arg($args, "--datadir=%s", $opt_vardir);
1802 mtr_add_arg($args, "--basedir=%s", $basedir);
1803 mtr_add_arg($args, "--lc-messages-dir=%s", $path_language);
1804 mtr_add_arg($args, "--skip-grant-tables");
1805 mtr_add_arg($args, "--log-warnings=0");
1806 mtr_add_arg($args, "--log-slow-admin-statements=0");
1807 mtr_add_arg($args, "--log-queries-not-using-indexes=0");
1808 mtr_add_arg($args, "--log-slow-slave-statements=0");
1809 mtr_add_arg($args, "--verbose");
1810 mtr_add_arg($args, "--help");
1811
1812 my $exe_mysqld= find_mysqld($bindir);
1813 my $cmd= join(" ", $exe_mysqld, @$args);
1814
1815 mtr_verbose("cmd: $cmd");
1816
1817 my $list= `$cmd`;
1818
1819 # to simplify the parsing, we'll merge all nicely formatted --help texts
1820 $list =~ s/\n {22}(\S)/ $1/g;
1821
1822 my @list= split '\R', $list;
1823
1824 $mysql_version_id= 0;
1825 my $exe= basename($exe_mysqld);
1826 while (defined(my $line = shift @list)){
1827 if ($line =~ /\W\Q$exe\E\s+Ver\s(\d+)\.(\d+)\.(\d+)(\S*)/ ) {
1828 $mysql_version_id= $1*10000 + $2*100 + $3;
1829 mtr_report("MariaDB Version $1.$2.$3$4");
1830 last;
1831 }
1832 }
1833 mtr_error("Could not find version of MariaDB")
1834 unless $mysql_version_id > 0;
1835
1836 for (@list)
1837 {
1838 # first part of the help - command-line options.
1839 if (/Copyright/ .. /^-{30,}/) {
1840 # here we want to detect all not mandatory plugins
1841 # they are listed in the --help output as
1842 # --archive[=name]
1843 # Enable or disable ARCHIVE plugin. Possible values are ON, OFF,
1844 # FORCE (don't start if the plugin fails to load),
1845 # FORCE_PLUS_PERMANENT (like FORCE, but the plugin can not be uninstalled).
1846 # For Innodb I_S plugins that are referenced in sys schema
1847 # do not make them optional, to prevent diffs in tests.
1848 push @optional_plugins, $1
1849 if /^ --([-a-z0-9]+)\[=name\] +Enable or disable \w+ plugin. One of: ON, OFF, FORCE/
1850 and $1 ne "innodb-metrics"
1851 and $1 ne "innodb-buffer-page"
1852 and $1 ne "innodb-lock-waits"
1853 and $1 ne "innodb-locks"
1854 and $1 ne "innodb-trx"
1855 and $1 ne "gssapi";
1856 next;
1857 }
1858
1859 last if /^\r?$/; # then goes a list of variables, it ends with an empty line
1860
1861 # Put a variable into hash
1862 /^([\S]+)[ \t]+(.*?)\r?$/ or die "Could not parse mysqld --help: $_\n";
1863 $mysqld_variables{$1}= $2;
1864 }
1865 mtr_error("Could not find variabes list") unless %mysqld_variables;
1866 }
1867
1868
1869 sub collect_mysqld_features_from_running_server ()
1870 {
1871 my $mysql= mtr_exe_exists("$path_client_bindir/mariadb");
1872
1873 my $args;
1874 mtr_init_args(\$args);
1875
1876 mtr_add_arg($args, "--no-defaults");
1877 mtr_add_arg($args, "--user=%s", $opt_user);
1878
1879 while (my ($option, $value)= each( %opts_extern )) {
1880 mtr_add_arg($args, "--$option=$value");
1881 }
1882
1883 mtr_add_arg($args, "--silent"); # Tab separated output
1884 mtr_add_arg($args, "-e \"use mysql; SHOW VARIABLES\"");
1885 my $cmd= "$mysql " . join(' ', @$args);
1886 mtr_verbose("cmd: $cmd");
1887
1888 my $list = `$cmd` or
1889 mtr_error("Could not connect to extern server using command: '$cmd'");
1890 foreach my $line (split('\R', $list ))
1891 {
1892 # Put variables into hash
1893 if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
1894 {
1895 my $name= $1;
1896 my $value=$2;
1897 $name =~ s/_/-/g;
1898 # print "$name=\"$value\"\n";
1899 $mysqld_variables{$name}= $value;
1900 }
1901 }
1902
1903 # Parse version
1904 my $version_str= $mysqld_variables{'version'};
1905 if ( $version_str =~ /^([0-9]*)\.([0-9]*)\.([0-9]*)([^\s]*)/ )
1906 {
1907 #print "Major: $1 Minor: $2 Build: $3\n";
1908 $mysql_version_id= $1*10000 + $2*100 + $3;
1909 #print "mysql_version_id: $mysql_version_id\n";
1910 mtr_report("MariaDB Version $1.$2.$3");
1911 $mysql_version_extra= $4;
1912 }
1913 mtr_error("Could not find version of MariaDBL") unless $mysql_version_id;
1914 }
1915
1916 sub find_mysqld {
1917
1918 my ($mysqld_basedir)= $ENV{MTR_BINDIR_FORCED} || $ENV{MTR_BINDIR} || @_;
1919
1920 my @mysqld_names= ("mariadbd", "mysqld", "mysqld-max-nt", "mysqld-max",
1921 "mysqld-nt");
1922
1923 if ( $opt_debug_server ){
1924 # Put mysqld-debug first in the list of binaries to look for
1925 mtr_verbose("Adding mysqld-debug first in list of binaries to look for");
1926 unshift(@mysqld_names, "mysqld-debug");
1927 }
1928
1929 return my_find_bin($mysqld_basedir,
1930 ["sql", "libexec", "sbin", "bin"],
1931 [@mysqld_names]);
1932 }
1933
1934
1935 sub executable_setup () {
1936
1937 $exe_patch='patch' if `patch -v`;
1938
1939 # Look for the client binaries
1940 $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mariadb-admin");
1941 $exe_mysql= mtr_exe_exists("$path_client_bindir/mariadb");
1942 $exe_mysql_plugin= mtr_exe_exists("$path_client_bindir/mariadb-plugin");
1943 $exe_mariadb_conv= mtr_exe_exists("$path_client_bindir/mariadb-conv");
1944
1945 $exe_mysql_embedded= mtr_exe_maybe_exists("$bindir/libmysqld/examples/mariadb-embedded",
1946 "$bindir/libmysqld/examples/mysql_embedded");
1947
1948 # Look for mysqltest executable
1949 if ( $opt_embedded_server )
1950 {
1951 $exe_mysqltest=
1952 mtr_exe_exists("$bindir/libmysqld/examples$multiconfig/mariadb-test-embedded",
1953 "$path_client_bindir/mariadb-test-embedded");
1954 }
1955 else
1956 {
1957 if ( defined $ENV{'MYSQL_TEST'} )
1958 {
1959 $exe_mysqltest=$ENV{'MYSQL_TEST'};
1960 print "===========================================================\n";
1961 print "WARNING:The mysqltest binary is fetched from $exe_mysqltest\n";
1962 print "===========================================================\n";
1963 }
1964 else
1965 {
1966 $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mariadb-test");
1967 }
1968 }
1969
1970 }
1971
1972
1973 sub client_debug_arg($$) {
1974 my ($args, $client_name)= @_;
1975
1976 # Workaround for Bug #50627: drop any debug opt
1977 return if $client_name =~ /^mariadb-binlog/;
1978
1979 if ( $opt_debug ) {
1980 mtr_add_arg($args,
1981 "--loose-debug-dbug=d,info,warning,warnings:t:A,%s/log/%s.trace",
1982 $path_vardir_trace, $client_name)
1983 }
1984 }
1985
1986
1987 sub client_arguments ($;$) {
1988 my $client_name= shift;
1989 my $group_suffix= shift;
1990 my $client_exe= mtr_exe_exists("$path_client_bindir/$client_name");
1991
1992 my $args;
1993 mtr_init_args(\$args);
1994 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
1995 if (defined($group_suffix)) {
1996 mtr_add_arg($args, "--defaults-group-suffix=%s", $group_suffix);
1997 client_debug_arg($args, "$client_name-$group_suffix");
1998 }
1999 else
2000 {
2001 client_debug_arg($args, $client_name);
2002 }
2003 return mtr_args2str($client_exe, @$args);
2004 }
2005
2006
2007 sub mysqlbinlog_arguments () {
2008 my $exe= mtr_exe_exists("$path_client_bindir/mariadb-binlog");
2009
2010 my $args;
2011 mtr_init_args(\$args);
2012 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
2013 mtr_add_arg($args, "--local-load=%s", $opt_tmpdir);
2014 client_debug_arg($args, "mysqlbinlog");
2015 return mtr_args2str($exe, @$args);
2016 }
2017
2018
2019 sub mysqlslap_arguments () {
2020 my $exe= mtr_exe_maybe_exists("$path_client_bindir/mariadb-slap");
2021 if ( $exe eq "" ) {
2022 # mysqlap was not found
2023
2024 if (defined $mysql_version_id and $mysql_version_id >= 50100 ) {
2025 mtr_error("Could not find the mariadb-slap binary");
2026 }
2027 return ""; # Don't care about mariadb-slap
2028 }
2029
2030 my $args;
2031 mtr_init_args(\$args);
2032 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
2033 client_debug_arg($args, "mysqlslap");
2034 return mtr_args2str($exe, @$args);
2035 }
2036
2037
2038 sub mysqldump_arguments ($) {
2039 my($group_suffix) = @_;
2040 my $exe= mtr_exe_exists("$path_client_bindir/mariadb-dump");
2041
2042 my $args;
2043 mtr_init_args(\$args);
2044 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
2045 mtr_add_arg($args, "--defaults-group-suffix=%s", $group_suffix);
2046 client_debug_arg($args, "mysqldump-$group_suffix");
2047 return mtr_args2str($exe, @$args);
2048 }
2049
2050
2051 sub mysql_client_test_arguments(){
2052 my $exe;
2053 # mysql_client_test executable may _not_ exist
2054 if ( $opt_embedded_server ) {
2055 $exe= mtr_exe_maybe_exists(
2056 "$bindir/libmysqld/examples$multiconfig/mariadb-client-test-embedded",
2057 "$bindir/bin/mariadb-client-test-embedded",
2058 "$bindir/libmysqld/examples$multiconfig/mysql_client_test_embedded",
2059 "$bindir/bin/mysql_client_test_embedded");
2060 } else {
2061 $exe= mtr_exe_maybe_exists("$bindir/tests$multiconfig/mariadb-client-test",
2062 "$bindir/bin/mariadb-client-test",
2063 "$bindir/tests$multiconfig/mysql_client_test",
2064 "$bindir/bin/mysql_client_test");
2065 }
2066
2067 my $args;
2068 mtr_init_args(\$args);
2069 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
2070 mtr_add_arg($args, "--testcase");
2071 mtr_add_arg($args, "--vardir=$opt_vardir");
2072 client_debug_arg($args,"mysql_client_test");
2073 my $ret=mtr_args2str($exe, @$args);
2074 return $ret;
2075 }
2076
2077 sub tool_arguments ($$) {
2078 my($sedir, $tool_name) = @_;
2079 my $exe= my_find_bin($bindir,
2080 [$sedir, "bin"],
2081 $tool_name);
2082
2083 my $args;
2084 mtr_init_args(\$args);
2085 client_debug_arg($args, $tool_name);
2086 return mtr_args2str($exe, @$args);
2087 }
2088
2089 # This is not used to actually start a mysqld server, just to allow test
2090 # scripts to run the mysqld binary to test invalid server startup options.
2091 sub mysqld_client_arguments () {
2092 my $default_mysqld= default_mysqld();
2093 my $exe = find_mysqld($bindir);
2094 my $args;
2095 mtr_init_args(\$args);
2096 mtr_add_arg($args, "--no-defaults");
2097 mtr_add_arg($args, "--basedir=%s", $basedir);
2098 mtr_add_arg($args, "--character-sets-dir=%s", $default_mysqld->value("character-sets-dir"));
2099 mtr_add_arg($args, "--language=%s", $default_mysqld->value("language"));
2100 return mtr_args2str($exe, @$args);
2101 }
2102
2103
2104 sub have_maria_support () {
2105 my $maria_var= $mysqld_variables{'aria-recover-options'};
2106 return defined $maria_var;
2107 }
2108
2109
2110 sub environment_setup {
2111
2112 umask(022);
2113
2114 $ENV{'USE_RUNNING_SERVER'}= using_extern();
2115
2116 my @ld_library_paths;
2117
2118 if ($path_client_libdir)
2119 {
2120 # Use the --client-libdir passed on commandline
2121 push(@ld_library_paths, "$path_client_libdir");
2122 }
2123 else
2124 {
2125 # Setup LD_LIBRARY_PATH so the libraries from this distro/clone
2126 # are used in favor of the system installed ones
2127 if ( $source_dist )
2128 {
2129 push(@ld_library_paths, "$basedir/libmysql/.libs/",
2130 "$basedir/libmysql_r/.libs/",
2131 "$basedir/zlib/.libs/");
2132 if ($^O eq "darwin")
2133 {
2134 # it is MAC OS and we have to add dynamic libraries paths
2135 push @ld_library_paths, grep {<$_/*.dylib>}
2136 (<$bindir/storage/*/.libs/>,<$bindir/plugin/*/.libs/>,
2137 <$bindir/plugin/*/*/.libs/>,<$bindir/storage/*/*/.libs>);
2138 }
2139 }
2140 else
2141 {
2142 push(@ld_library_paths, "$basedir/lib", "$basedir/lib/mysql");
2143 }
2144 }
2145
2146 $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
2147 $ENV{'LD_LIBRARY_PATH'} ?
2148 split(':', $ENV{'LD_LIBRARY_PATH'}) : ());
2149
2150 My::Debugger::pre_setup();
2151
2152 mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
2153
2154 $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
2155 $ENV{'DYLD_LIBRARY_PATH'} ?
2156 split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
2157 mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
2158
2159 # The environment variable used for shared libs on AIX
2160 $ENV{'SHLIB_PATH'}= join(":", @ld_library_paths,
2161 $ENV{'SHLIB_PATH'} ?
2162 split(':', $ENV{'SHLIB_PATH'}) : ());
2163 mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}");
2164
2165 # The environment variable used for shared libs on hp-ux
2166 $ENV{'LIBPATH'}= join(":", @ld_library_paths,
2167 $ENV{'LIBPATH'} ?
2168 split(':', $ENV{'LIBPATH'}) : ());
2169 mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
2170
2171 $ENV{'UMASK'}= "0660"; # The octal *string*
2172 $ENV{'UMASK_DIR'}= "0770"; # The octal *string*
2173
2174 #
2175 # MariaDB tests can produce output in various character sets
2176 # (especially, ctype_xxx.test). To avoid confusing Perl
2177 # with output which is incompatible with the current locale
2178 # settings, we reset the current values of LC_ALL and LC_CTYPE to "C".
2179 # For details, please see
2180 # Bug#27636 tests fails if LC_* variables set to *_*.UTF-8
2181 #
2182 $ENV{'LC_ALL'}= "C";
2183 $ENV{'LC_CTYPE'}= "C";
2184 $ENV{'LC_COLLATE'}= "C";
2185
2186 $ENV{'GNUTLS_SYSTEM_PRIORITY_FILE'}='/dev/null';
2187 $ENV{'OPENSSL_CONF'}= $mysqld_variables{'version-ssl-library'} gt 'OpenSSL 1.1.1'
2188 ? "$glob_mysql_test_dir/lib/openssl.cnf" : '/dev/null';
2189
2190 $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
2191 $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'port'};
2192 $ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir;
2193 $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
2194 $ENV{'MYSQLTEST_REAL_VARDIR'}= realpath $opt_vardir;
2195 $ENV{'MYSQL_BINDIR'}= $bindir;
2196 $ENV{'MYSQL_SHAREDIR'}= $path_language;
2197 $ENV{'MYSQL_CHARSETSDIR'}= $path_charsetsdir;
2198
2199 if (IS_WINDOWS)
2200 {
2201 $ENV{'SECURE_LOAD_PATH'}= $glob_mysql_test_dir."\\std_data";
2202 }
2203 else
2204 {
2205 $ENV{'SECURE_LOAD_PATH'}= $glob_mysql_test_dir."/std_data";
2206 }
2207
2208 #
2209 # Some stupid^H^H^H^H^H^Hignorant network providers set up "wildcard DNS"
2210 # servers that return some given web server address for any lookup of a
2211 # non-existent host name. This confuses test cases that want to test the
2212 # behaviour when connecting to a non-existing host, so we need to be able
2213 # to disable those tests when DNS is broken.
2214 #
2215 $ENV{HAVE_BROKEN_DNS}= defined(gethostbyname('invalid_hostname'));
2216
2217 # ----------------------------------------------------
2218 # mysql clients
2219 # ----------------------------------------------------
2220 $ENV{'MYSQL_CHECK'}= client_arguments("mariadb-check");
2221 $ENV{'MYSQL_DUMP'}= mysqldump_arguments(".1");
2222 $ENV{'MYSQL_DUMP_SLAVE'}= mysqldump_arguments(".2");
2223 $ENV{'MYSQL_SLAP'}= mysqlslap_arguments();
2224 $ENV{'MYSQL_IMPORT'}= client_arguments("mariadb-import");
2225 $ENV{'MYSQL_SHOW'}= client_arguments("mariadb-show");
2226 $ENV{'MYSQL_BINLOG'}= mysqlbinlog_arguments();
2227 $ENV{'MYSQL'}= client_arguments("mariadb");
2228 $ENV{'MYSQL_SLAVE'}= client_arguments("mariadb", ".2");
2229 $ENV{'MYSQL_UPGRADE'}= client_arguments("mariadb-upgrade");
2230 $ENV{'MYSQLADMIN'}= client_arguments("mariadb-admin");
2231 $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
2232 $ENV{'EXE_MYSQL'}= $exe_mysql;
2233 $ENV{'MYSQL_PLUGIN'}= $exe_mysql_plugin;
2234 $ENV{'MYSQL_EMBEDDED'}= $exe_mysql_embedded;
2235 $ENV{'MARIADB_CONV'}= "$exe_mariadb_conv --character-sets-dir=$path_charsetsdir";
2236 if(IS_WINDOWS)
2237 {
2238 $ENV{'MYSQL_INSTALL_DB_EXE'}= mtr_exe_exists("$bindir/sql$multiconfig/mariadb-install-db",
2239 "$bindir/bin/mariadb-install-db");
2240 $ENV{'MARIADB_UPGRADE_SERVICE_EXE'}= mtr_exe_exists("$bindir/sql$multiconfig/mariadb-upgrade-service",
2241 "$bindir/bin/mariadb-upgrade-service");
2242 $ENV{'MARIADB_UPGRADE_EXE'}= mtr_exe_exists("$path_client_bindir/mariadb-upgrade");
2243 }
2244
2245 my $client_config_exe=
2246 mtr_exe_maybe_exists(
2247 "$bindir/libmariadb/mariadb_config$multiconfig/mariadb_config",
2248 "$bindir/bin/mariadb_config");
2249 if ($client_config_exe)
2250 {
2251 my $tls_info= `$client_config_exe --tlsinfo`;
2252 ($ENV{CLIENT_TLS_LIBRARY},$ENV{CLIENT_TLS_LIBRARY_VERSION})=
2253 split(/ /, $tls_info, 2);
2254 }
2255 my $exe_mysqld= find_mysqld($basedir);
2256 $ENV{'MYSQLD'}= $exe_mysqld;
2257 my $extra_opts= join (" ", @opt_extra_mysqld_opt);
2258 $ENV{'MYSQLD_CMD'}= "$exe_mysqld --defaults-group-suffix=.1 ".
2259 "--defaults-file=$path_config_file $extra_opts";
2260
2261 # ----------------------------------------------------
2262 # bug25714 executable may _not_ exist in
2263 # some versions, test using it should be skipped
2264 # ----------------------------------------------------
2265 my $exe_bug25714=
2266 mtr_exe_maybe_exists("$bindir/tests$multiconfig/bug25714");
2267 $ENV{'MYSQL_BUG25714'}= native_path($exe_bug25714);
2268
2269 # ----------------------------------------------------
2270 # mysql_fix_privilege_tables.sql
2271 # ----------------------------------------------------
2272 my $file_mysql_fix_privilege_tables=
2273 mtr_file_exists("$bindir/scripts/mariadb_fix_privilege_tables.sql",
2274 "$bindir/share/mariadb_fix_privilege_tables.sql",
2275 "$bindir/share/mariadb/mariadb_fix_privilege_tables.sql",
2276 "$bindir/share/mysql/mariadb_fix_privilege_tables.sql");
2277 $ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
2278
2279 # ----------------------------------------------------
2280 # my_print_defaults
2281 # ----------------------------------------------------
2282 my $exe_my_print_defaults=
2283 mtr_exe_exists("$bindir/extra$multiconfig/my_print_defaults",
2284 "$path_client_bindir/my_print_defaults");
2285 $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= native_path($exe_my_print_defaults);
2286
2287 # ----------------------------------------------------
2288 # mariadb-migrate-config-file
2289 # ----------------------------------------------------
2290 my $exe_mariadb_migrate_config_file=
2291 mtr_exe_maybe_exists("$bindir/extra$multiconfig/mariadb-migrate-config-file",
2292 "$path_client_bindir/mariadb-migrate-config-file");
2293 $ENV{'MARIADB_MIGRATE_CONFIG_FILE'}= native_path($exe_mariadb_migrate_config_file) if $exe_mariadb_migrate_config_file;
2294
2295 # ----------------------------------------------------
2296 # myisam tools
2297 # ----------------------------------------------------
2298 $ENV{'MYISAMLOG'}= tool_arguments("storage/myisam", "myisamlog", );
2299 $ENV{'MYISAMCHK'}= tool_arguments("storage/myisam", "myisamchk");
2300 $ENV{'MYISAMPACK'}= tool_arguments("storage/myisam", "myisampack");
2301 $ENV{'MYISAM_FTDUMP'}= tool_arguments("storage/myisam", "myisam_ftdump");
2302
2303 # ----------------------------------------------------
2304 # aria tools
2305 # ----------------------------------------------------
2306 if (have_maria_support())
2307 {
2308 $ENV{'MARIA_CHK'}= tool_arguments("storage/maria", "aria_chk");
2309 $ENV{'MARIA_PACK'}= tool_arguments("storage/maria", "aria_pack");
2310 }
2311
2312 # ----------------------------------------------------
2313 # mysqlhotcopy
2314 # ----------------------------------------------------
2315 my $mysqlhotcopy=
2316 mtr_pl_maybe_exists("$bindir/scripts/mysqlhotcopy") ||
2317 mtr_pl_maybe_exists("$path_client_bindir/mysqlhotcopy");
2318 if ($mysqlhotcopy)
2319 {
2320 $ENV{'MYSQLHOTCOPY'}= $mysqlhotcopy;
2321 }
2322
2323 # ----------------------------------------------------
2324 # perror
2325 # ----------------------------------------------------
2326 my $exe_perror= mtr_exe_exists("$bindir/extra$multiconfig/perror",
2327 "$path_client_bindir/perror");
2328 $ENV{'MY_PERROR'}= native_path($exe_perror);
2329
2330 # ----------------------------------------------------
2331 # mysql_tzinfo_to_sql
2332 # ----------------------------------------------------
2333 my $exe_mysql_tzinfo_to_sql= mtr_exe_exists("$basedir/sql$multiconfig/mariadb-tzinfo-to-sql",
2334 "$path_client_bindir/mariadb-tzinfo-to-sql",
2335 "$bindir/sql$multiconfig/mariadb-tzinfo-to-sql");
2336 $ENV{'MYSQL_TZINFO_TO_SQL'}= native_path($exe_mysql_tzinfo_to_sql);
2337
2338 # ----------------------------------------------------
2339 # replace
2340 # ----------------------------------------------------
2341 my $exe_replace= mtr_exe_exists(vs_config_dirs('extra', 'replace'),
2342 "$basedir/extra/replace",
2343 "$bindir/extra$multiconfig/replace",
2344 "$path_client_bindir/replace");
2345 $ENV{'REPLACE'}= native_path($exe_replace);
2346
2347 # ----------------------------------------------------
2348 # innochecksum
2349 # ----------------------------------------------------
2350 my $exe_innochecksum=
2351 mtr_exe_maybe_exists("$bindir/extra$multiconfig/innochecksum",
2352 "$path_client_bindir/innochecksum");
2353 $ENV{'INNOCHECKSUM'}= native_path($exe_innochecksum) if $exe_innochecksum;
2354
2355 # ----------------------------------------------------
2356 # mariabackup
2357 # ----------------------------------------------------
2358 my $exe_mariabackup= mtr_exe_maybe_exists(
2359 "$bindir/extra/mariabackup$multiconfig/mariadb-backup",
2360 "$path_client_bindir/mariadb-backup",
2361 "$bindir/extra/mariabackup$multiconfig/mariabackup",
2362 "$path_client_bindir/mariabackup");
2363
2364 $ENV{XTRABACKUP}= native_path($exe_mariabackup) if $exe_mariabackup;
2365
2366 my $exe_xbstream= mtr_exe_maybe_exists(
2367 "$bindir/extra/mariabackup/$multiconfig/mbstream",
2368 "$path_client_bindir/mbstream");
2369 $ENV{XBSTREAM}= native_path($exe_xbstream) if $exe_xbstream;
2370
2371 $ENV{INNOBACKUPEX}= "$exe_mariabackup --innobackupex";
2372
2373 # Add dir of this perl to aid mysqltest in finding perl
2374 my $perldir= dirname($^X);
2375 my $pathsep= ":";
2376 $pathsep= ";" if IS_WINDOWS && ! IS_CYGWIN;
2377 $ENV{'PATH'}= "$ENV{'PATH'}".$pathsep.$perldir;
2378 }
2379
2380
2381 sub remove_vardir_subs() {
2382 foreach my $sdir ( glob("$opt_vardir/*") ) {
2383 mtr_verbose("Removing subdir $sdir");
2384 rmtree($sdir);
2385 }
2386 }
2387
2388 #
2389 # Remove var and any directories in var/ created by previous
2390 # tests
2391 #
2392 sub remove_stale_vardir () {
2393
2394 mtr_report("Removing old var directory...");
2395
2396 # Safety!
2397 mtr_error("No, don't remove the vardir when running with --extern")
2398 if using_extern();
2399
2400 mtr_verbose("opt_vardir: $opt_vardir");
2401 if ( $opt_vardir eq $default_vardir )
2402 {
2403 #
2404 # Running with "var" in mysql-test dir
2405 #
2406 if ( -l $opt_vardir)
2407 {
2408 # var is a symlink
2409
2410 if ( $opt_mem )
2411 {
2412 # Remove the directory which the link points at
2413 mtr_verbose("Removing " . readlink($opt_vardir));
2414 rmtree(readlink($opt_vardir));
2415
2416 # Remove the "var" symlink
2417 mtr_verbose("unlink($opt_vardir)");
2418 unlink($opt_vardir);
2419 }
2420 else
2421 {
2422 # Some users creates a soft link in mysql-test/var to another area
2423 # - allow it, but remove all files in it
2424
2425 mtr_report(" - WARNING: Using the 'mysql-test/var' symlink");
2426
2427 # Make sure the directory where it points exist
2428 if (! -d readlink($opt_vardir))
2429 {
2430 mtr_report("The destination for symlink $opt_vardir does not exist; Removing it and creating a new var directory");
2431 unlink($opt_vardir);
2432 }
2433 remove_vardir_subs();
2434 }
2435 }
2436 else
2437 {
2438 # Remove the entire "var" dir
2439 mtr_verbose("Removing $opt_vardir/");
2440 rmtree("$opt_vardir/");
2441 }
2442
2443 if ( $opt_mem )
2444 {
2445 # A symlink from var/ to $opt_mem will be set up
2446 # remove the $opt_mem dir to assure the symlink
2447 # won't point at an old directory
2448 mtr_verbose("Removing $opt_mem");
2449 rmtree($opt_mem);
2450 }
2451
2452 }
2453 else
2454 {
2455 #
2456 # Running with "var" in some other place
2457 #
2458
2459 # Don't remove the var/ dir in mysql-test dir as it may be in
2460 # use by another mysql-test-run run with --vardir
2461 # mtr_verbose("Removing $default_vardir");
2462 # rmtree($default_vardir);
2463
2464 # Remove the "var" dir
2465 mtr_verbose("Removing $opt_vardir/");
2466 rmtree("$opt_vardir/");
2467 }
2468 # Remove the "tmp" dir
2469 mtr_verbose("Removing $opt_tmpdir/");
2470 rmtree("$opt_tmpdir/");
2471 }
2472
2473 sub set_plugin_var($) {
2474 local $_ = $_[0];
2475 s/\.\w+$//;
2476 $ENV{"\U${_}_SO"} = $_[0];
2477 }
2478
2479 #
2480 # Create var and the directories needed in var
2481 #
2482 sub setup_vardir() {
2483 mtr_report("Creating var directory '$opt_vardir'...");
2484
2485 if ( $opt_vardir eq $default_vardir )
2486 {
2487 #
2488 # Running with "var" in mysql-test dir
2489 #
2490 if ( -l $opt_vardir )
2491 {
2492 # it's a symlink
2493
2494 # Make sure the directory where it points exist
2495 if (! -d readlink($opt_vardir))
2496 {
2497 mtr_report("The destination for symlink $opt_vardir does not exist; Removing it and creating a new var directory");
2498 unlink($opt_vardir);
2499 }
2500 }
2501 elsif ( $opt_mem )
2502 {
2503 # Runinng with "var" as a link to some "memory" location, normally tmpfs
2504 mtr_verbose("Creating $opt_mem");
2505 mkpath($opt_mem);
2506
2507 mtr_report(" - symlinking 'var' to '$opt_mem'");
2508 symlink($opt_mem, $opt_vardir);
2509 }
2510 }
2511
2512 if ( ! -d $opt_vardir )
2513 {
2514 mtr_verbose("Creating $opt_vardir");
2515 mkpath($opt_vardir);
2516 }
2517
2518 # Ensure a proper error message if vardir couldn't be created
2519 unless ( -d $opt_vardir and -w $opt_vardir )
2520 {
2521 mtr_error("Writable 'var' directory is needed, use the " .
2522 "'--vardir=<path>' option");
2523 }
2524
2525 mkpath("$opt_vardir/log");
2526 mkpath("$opt_vardir/run");
2527
2528 # Create var/tmp and tmp - they might be different
2529 mkpath("$opt_vardir/tmp");
2530 mkpath($opt_tmpdir) if ($opt_tmpdir ne "$opt_vardir/tmp");
2531
2532 # On some operating systems, there is a limit to the length of a
2533 # UNIX domain socket's path far below PATH_MAX.
2534 # Don't allow that to happen
2535 if (check_socket_path_length("$opt_tmpdir/testsocket.sock")){
2536 mtr_error("Socket path '$opt_tmpdir' too long, it would be ",
2537 "truncated and thus not possible to use for connection to ",
2538 "MariaDB Server. Set a shorter with --tmpdir=<path> option");
2539 }
2540
2541 # copy all files from std_data into var/std_data
2542 # and make them world readable
2543 copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data", "0022");
2544
2545 unless($plugindir)
2546 {
2547 # create a plugin dir and copy or symlink plugins into it
2548 if ($source_dist)
2549 {
2550 $plugindir="$opt_vardir/plugins";
2551 # Source builds collect both client plugins and server plugins in the
2552 # same directory.
2553 $client_plugindir= $plugindir;
2554 mkpath($plugindir);
2555 if (IS_WINDOWS)
2556 {
2557 $ENV{PATH} .= ";".$plugindir; # to load vcpkg dependencies (libcurl.dll etc)
2558 if (!$opt_embedded_server)
2559 {
2560 for (<$bindir/storage/*$multiconfig/*.dll>,
2561 <$bindir/plugin/*$multiconfig/*.dll>,
2562 <$bindir/libmariadb$multiconfig/*.dll>,
2563 <$bindir/sql$multiconfig/*.dll>)
2564 {
2565 my $pname=basename($_);
2566 copy rel2abs($_), "$plugindir/$pname";
2567 set_plugin_var($pname);
2568 }
2569 }
2570 }
2571 else
2572 {
2573 my $opt_use_copy= 1;
2574 if (symlink "$opt_vardir/run", "$plugindir/symlink_test")
2575 {
2576 $opt_use_copy= 0;
2577 unlink "$plugindir/symlink_test";
2578 }
2579
2580 for (<$bindir/storage/*$multiconfig/*.so>,
2581 <$bindir/plugin/*$multiconfig/*.so>,
2582 <$bindir/libmariadb/plugins/*/*.so>,
2583 <$bindir/libmariadb/$multiconfig/*.so>,
2584 <$bindir/sql$multiconfig/*.so>)
2585 {
2586 my $pname=basename($_);
2587 if ($opt_use_copy)
2588 {
2589 copy rel2abs($_), "$plugindir/$pname";
2590 }
2591 else
2592 {
2593 symlink rel2abs($_), "$plugindir/$pname";
2594 }
2595 set_plugin_var($pname);
2596 }
2597 }
2598 }
2599 else
2600 {
2601 # hm, what paths work for debs and for rpms ?
2602 for (<$bindir/lib64/mysql/plugin/*.so>,
2603 <$bindir/lib/mysql/plugin/*.so>,
2604 <$bindir/lib64/mariadb/plugin/*.so>,
2605 <$bindir/lib/mariadb/plugin/*.so>,
2606 <$bindir/lib/plugin/*.so>, # bintar
2607 <$bindir/lib/plugin/*.dll>)
2608 {
2609 my $pname= basename($_);
2610 set_plugin_var($pname);
2611 $plugindir= dirname($_) unless $plugindir;
2612 }
2613
2614 # Note: client plugins can be installed separately from server plugins,
2615 # as is the case for Debian packaging.
2616 for (<$bindir/lib/*/libmariadb3/plugin>)
2617 {
2618 $client_plugindir= $_ if <$_/*.so>;
2619 }
2620 $client_plugindir= $plugindir unless $client_plugindir;
2621 }
2622 }
2623
2624 # Remove old log files
2625 foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
2626 {
2627 unlink($name);
2628 }
2629 }
2630
2631
2632 #
2633 # Check if running as root
2634 # i.e a file can be read regardless what mode we set it to
2635 #
2636 sub check_running_as_root () {
2637 my $test_file= "$opt_vardir/test_running_as_root.txt";
2638 mtr_tofile($test_file, "MySQL");
2639 chmod(oct("0000"), $test_file);
2640
2641 my $result="";
2642 if (open(FILE,"<",$test_file))
2643 {
2644 $result= join('', <FILE>);
2645 close FILE;
2646 }
2647
2648 # Some filesystems( for example CIFS) allows reading a file
2649 # although mode was set to 0000, but in that case a stat on
2650 # the file will not return 0000
2651 my $file_mode= (stat($test_file))[2] & 07777;
2652
2653 mtr_verbose("result: $result, file_mode: $file_mode");
2654 if ($result eq "MySQL" && $file_mode == 0)
2655 {
2656 mtr_warning("running this script as _root_ will cause some " .
2657 "tests to be skipped");
2658 $ENV{'MYSQL_TEST_ROOT'}= "1";
2659 }
2660
2661 chmod(oct("0755"), $test_file);
2662 unlink($test_file);
2663 }
2664
2665
2666 sub check_ssl_support {
2667 if ($opt_skip_ssl)
2668 {
2669 mtr_report(" - skipping SSL");
2670 $opt_ssl_supported= 0;
2671 $opt_ssl= 0;
2672 return;
2673 }
2674
2675 if ( ! $mysqld_variables{'ssl'} )
2676 {
2677 if ( $opt_ssl)
2678 {
2679 mtr_error("Couldn't find support for SSL");
2680 return;
2681 }
2682 mtr_report(" - skipping SSL, mysqld not compiled with SSL");
2683 $opt_ssl_supported= 0;
2684 $opt_ssl= 0;
2685 return;
2686 }
2687 mtr_report(" - SSL connections supported");
2688 $opt_ssl_supported= 1;
2689 }
2690
2691 sub check_debug_support {
2692 if (defined $mysqld_variables{'debug-dbug'})
2693 {
2694 mtr_report(" - binaries are debug compiled");
2695 }
2696 elsif ($opt_debug_server)
2697 {
2698 mtr_error("Can't use --debug[-server], binary does not support it");
2699 }
2700 }
2701
2702
2703 #
2704 # Helper function to find the correct value for the multiconfig
2705 # if it was not set explicitly.
2706 #
2707 # the configuration with the most recent build dir in sql/ is selected.
2708 #
2709 # note: looking for all BuildLog.htm files everywhere in the tree with the
2710 # help of File::Find would be possibly more precise, but it is also
2711 # many times slower. Thus we are only looking at the server, client
2712 # executables, and plugins - that is, something that can affect the test suite
2713 #
2714 sub fix_vs_config_dir () {
2715 return $multiconfig="/$multiconfig" if $multiconfig;
2716
2717 my $modified = 1e30;
2718 $multiconfig="";
2719
2720
2721 for (<$bindir/sql/*/mysqld.exe>,
2722 <$bindir/sql/*/mysqld>
2723 ) { #/
2724 if (-M $_ < $modified)
2725 {
2726 $modified = -M _;
2727 $multiconfig = basename(dirname($_));
2728 }
2729 }
2730
2731 mtr_report("VS config: $multiconfig");
2732 $multiconfig="/$multiconfig" if $multiconfig;
2733 }
2734
2735
2736 #
2737 # Helper function to handle configuration-based subdirectories which Visual
2738 # Studio uses for storing binaries. If multiconfig is set, this returns
2739 # a path based on that setting; if not, it returns paths for the default
2740 # /release/ and /debug/ subdirectories.
2741 #
2742 # $exe can be undefined, if the directory itself will be used
2743 #
2744 sub vs_config_dirs ($$) {
2745 my ($path_part, $exe) = @_;
2746
2747 $exe = "" if not defined $exe;
2748
2749 # Don't look in these dirs when not on windows
2750 return () unless IS_WINDOWS;
2751
2752 if ($multiconfig)
2753 {
2754 return ("$basedir/$path_part/$multiconfig/$exe");
2755 }
2756
2757 return ("$basedir/$path_part/release/$exe",
2758 "$basedir/$path_part/relwithdebinfo/$exe",
2759 "$basedir/$path_part/debug/$exe");
2760 }
2761
2762 sub mysql_server_start($) {
2763 my ($mysqld, $tinfo) = @_;
2764
2765 if ( $mysqld->{proc} )
2766 {
2767 # Already started
2768
2769 # Write start of testcase to log file
2770 mark_log($mysqld->value('log-error'), $tinfo);
2771
2772 return;
2773 }
2774
2775 my $datadir= $mysqld->value('datadir');
2776 if (not $opt_start_dirty)
2777 {
2778
2779 my @options= ('log-bin', 'relay-log');
2780 foreach my $option_name ( @options ) {
2781 next unless $mysqld->option($option_name);
2782
2783 my $file_name= $mysqld->value($option_name);
2784 next unless
2785 defined $file_name and
2786 -e $file_name;
2787
2788 mtr_debug(" -removing '$file_name'");
2789 unlink($file_name) or die ("unable to remove file '$file_name'");
2790 }
2791
2792 if (-d $datadir ) {
2793 mtr_verbose(" - removing '$datadir'");
2794 rmtree($datadir);
2795 }
2796 }
2797
2798 my $mysqld_basedir= $mysqld->value('basedir');
2799 my $extra_opts= get_extra_opts($mysqld, $tinfo);
2800
2801 if ( $basedir eq $mysqld_basedir )
2802 {
2803 if (! $opt_start_dirty) # If dirty, keep possibly grown system db
2804 {
2805 # Some InnoDB options are incompatible with the default bootstrap.
2806 # If they are used, re-bootstrap
2807 my @rebootstrap_opts;
2808 @rebootstrap_opts = grep {/$rebootstrap_re/o} @$extra_opts if $extra_opts;
2809 if (@rebootstrap_opts)
2810 {
2811 mtr_verbose("Re-bootstrap with @rebootstrap_opts");
2812 mysql_install_db($mysqld, undef, \@rebootstrap_opts);
2813 }
2814 else {
2815 # Copy datadir from installed system db
2816 my $path= ($opt_parallel == 1) ? "$opt_vardir" : "$opt_vardir/..";
2817 my $install_db= "$path/install.db";
2818 mtr_verbose("copying $install_db to $datadir");
2819 copytree($install_db, $datadir) if -d $install_db;
2820 mtr_error("Failed to copy system db to '$datadir'") unless -d $datadir;
2821 }
2822 }
2823 }
2824 else
2825 {
2826 mysql_install_db($mysqld); # For versional testing
2827
2828 mtr_error("Failed to install system db to '$datadir'")
2829 unless -d $datadir;
2830
2831 }
2832
2833 # Create the servers tmpdir
2834 my $tmpdir= $mysqld->value('tmpdir');
2835 mkpath($tmpdir) unless -d $tmpdir;
2836
2837 # Write start of testcase to log file
2838 mark_log($mysqld->value('log-error'), $tinfo);
2839
2840 # Run <tname>-master.sh
2841 if ($mysqld->option('#!run-master-sh') and
2842 defined $tinfo->{master_sh} and
2843 run_system('/bin/sh ' . $tinfo->{master_sh}) )
2844 {
2845 $tinfo->{'comment'}= "Failed to execute '$tinfo->{master_sh}'";
2846 return 1;
2847 }
2848
2849 # Run <tname>-slave.sh
2850 if ($mysqld->option('#!run-slave-sh') and
2851 defined $tinfo->{slave_sh} and
2852 run_system('/bin/sh ' . $tinfo->{slave_sh}))
2853 {
2854 $tinfo->{'comment'}= "Failed to execute '$tinfo->{slave_sh}'";
2855 return 1;
2856 }
2857
2858 if (!$opt_embedded_server)
2859 {
2860 mysqld_start($mysqld, $extra_opts) or
2861 mtr_error("Failed to start mysqld ".$mysqld->name()." with command "
2862 . $ENV{MYSQLD_LAST_CMD});
2863
2864 # Save this test case information, so next can examine it
2865 $mysqld->{'started_tinfo'}= $tinfo;
2866 }
2867
2868 # If wsrep is on, we need to wait until the first
2869 # server starts and bootstraps the cluster before
2870 # starting other servers. The bootsrap server in the
2871 # configuration should always be the first which has
2872 # wsrep_on=ON
2873 if (wsrep_on($mysqld) && wsrep_is_bootstrap_server($mysqld))
2874 {
2875 mtr_verbose("Waiting for wsrep bootstrap server to start");
2876 if ($mysqld->{WAIT}->($mysqld))
2877 {
2878 return 1;
2879 }
2880 }
2881 }
2882
2883 sub mysql_server_wait {
2884 my ($mysqld, $tinfo) = @_;
2885 my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
2886
2887 if (!sleep_until_file_created($mysqld->value('pid-file'), $expect_file,
2888 $opt_start_timeout, $mysqld->{'proc'},
2889 $warn_seconds))
2890 {
2891 $tinfo->{comment}= "Failed to start ".$mysqld->name() . "\n";
2892 return 1;
2893 }
2894
2895 if (wsrep_on($mysqld))
2896 {
2897 mtr_verbose("Waiting for wsrep server " . $mysqld->name() . " to be ready");
2898 if (!wait_wsrep_ready($tinfo, $mysqld))
2899 {
2900 return 1;
2901 }
2902 }
2903
2904 return 0;
2905 }
2906
2907 sub create_config_file_for_extern {
2908 my %opts=
2909 (
2910 socket => '/tmp/mysqld.sock',
2911 port => 3306,
2912 user => $opt_user,
2913 password => '',
2914 @_
2915 );
2916
2917 mtr_report("Creating my.cnf file for extern server...");
2918 my $F= IO::File->new($path_config_file, "w")
2919 or mtr_error("Can't write to $path_config_file: $!");
2920
2921 print $F "[client]\n";
2922 while (my ($option, $value)= each( %opts )) {
2923 print $F "$option= $value\n";
2924 mtr_report(" $option= $value");
2925 }
2926
2927 print $F <<EOF
2928
2929 # binlog reads from [client] and [mysqlbinlog]
2930 [mysqlbinlog]
2931 character-sets-dir= $path_charsetsdir
2932 local-load= $opt_tmpdir
2933
2934 EOF
2935 ;
2936
2937 $F= undef; # Close file
2938 }
2939
2940
2941 #
2942 # Kill processes left from previous runs, normally
2943 # there should be none so make sure to warn
2944 # if there is one
2945 #
2946 sub kill_leftovers ($) {
2947 my $rundir= shift;
2948 return unless ( -d $rundir );
2949
2950 mtr_report("Checking leftover processes...");
2951
2952 # Scan the "run" directory for process id's to kill
2953 opendir(RUNDIR, $rundir)
2954 or mtr_error("kill_leftovers, can't open dir \"$rundir\": $!");
2955 while ( my $elem= readdir(RUNDIR) )
2956 {
2957 # Only read pid from files that end with .pid
2958 if ( $elem =~ /.*[.]pid$/ )
2959 {
2960 my $pidfile= "$rundir/$elem";
2961 next unless -f $pidfile;
2962 my $pid= mtr_fromfile($pidfile);
2963 unlink($pidfile);
2964 unless ($pid=~ /^(\d+)/){
2965 # The pid was not a valid number
2966 mtr_warning("Got invalid pid '$pid' from '$elem'");
2967 next;
2968 }
2969 mtr_report(" - found old pid $pid in '$elem', killing it...");
2970
2971 my $ret= kill("KILL", $pid);
2972 if ($ret == 0) {
2973 mtr_report(" process did not exist!");
2974 next;
2975 }
2976
2977 my $check_counter= 100;
2978 while ($ret > 0 and $check_counter--) {
2979 mtr_milli_sleep(100);
2980 $ret= kill(0, $pid);
2981 }
2982 mtr_report($check_counter ? " ok!" : " failed!");
2983 }
2984 else
2985 {
2986 mtr_warning("Found non pid file '$elem' in '$rundir'")
2987 if -f "$rundir/$elem";
2988 }
2989 }
2990 closedir(RUNDIR);
2991 }
2992
2993 #
2994 # Check that all the ports that are going to
2995 # be used are free
2996 #
2997 sub check_ports_free ($)
2998 {
2999 my $bthread= shift;
3000 my $portbase = $bthread * $opt_port_group_size + 10000;
3001 for ($portbase..$portbase+($opt_port_group_size-1)){
3002 if (mtr_ping_port($_)){
3003 mtr_report(" - 'localhost:$_' was not free");
3004 return 0; # One port was not free
3005 }
3006 }
3007
3008 return 1; # All ports free
3009 }
3010
3011
3012 sub initialize_servers {
3013
3014 if ( using_extern() )
3015 {
3016 # Running against an already started server, if the specified
3017 # vardir does not already exist it should be created
3018 if ( ! -d $opt_vardir )
3019 {
3020 setup_vardir();
3021 }
3022 else
3023 {
3024 mtr_verbose("No need to create '$opt_vardir' it already exists");
3025 }
3026 }
3027 else
3028 {
3029 # Kill leftovers from previous run
3030 # using any pidfiles found in var/run
3031 kill_leftovers("$opt_vardir/run");
3032
3033 if ( ! $opt_start_dirty )
3034 {
3035 remove_stale_vardir();
3036 setup_vardir();
3037 }
3038 }
3039 }
3040
3041
3042 #
3043 # Remove all newline characters expect after semicolon
3044 #
3045 sub sql_to_bootstrap {
3046 my ($sql) = @_;
3047 my @lines= split(/\R/, $sql);
3048 my $result= "\n";
3049 my $delimiter= ';';
3050
3051 foreach my $line (@lines) {
3052
3053 # Change current delimiter if line starts with "delimiter"
3054 if ( $line =~ /^delimiter (.*)/ ) {
3055 my $new= $1;
3056 # Remove old delimiter from end of new
3057 $new=~ s/\Q$delimiter\E$//;
3058 $delimiter = $new;
3059 mtr_debug("changed delimiter to $delimiter");
3060 # No need to add the delimiter to result
3061 next;
3062 }
3063
3064 # Add newline if line ends with $delimiter
3065 # and convert the current delimiter to semicolon
3066 if ( $line =~ /\Q$delimiter\E$/ ){
3067 $line =~ s/\Q$delimiter\E$/;/;
3068 $result.= "$line\n";
3069 mtr_debug("Added default delimiter");
3070 next;
3071 }
3072
3073 # Remove comments starting with --
3074 if ( $line =~ /^\s*--/ ) {
3075 mtr_debug("Discarded $line");
3076 next;
3077 }
3078
3079 # Replace @HOSTNAME with localhost
3080 $line=~ s/\'\@HOSTNAME\@\'/localhost/;
3081
3082 # Default, just add the line without newline
3083 # but with a space as separator
3084 $result.= "$line ";
3085
3086 }
3087 return $result;
3088 }
3089
3090
3091 sub default_mysqld {
3092 # Generate new config file from template
3093 environment_setup();
3094 my $config= My::ConfigFactory->new_config
3095 ( {
3096 basedir => $basedir,
3097 testdir => $glob_mysql_test_dir,
3098 template_path => "include/default_my.cnf",
3099 vardir => $opt_vardir,
3100 tmpdir => $opt_tmpdir,
3101 baseport => 0,
3102 user => $opt_user,
3103 password => '',
3104 }
3105 );
3106
3107 my $mysqld= $config->group('mysqld.1')
3108 or mtr_error("Couldn't find mysqld.1 in default config");
3109 return $mysqld;
3110 }
3111
3112
3113 sub mysql_install_db {
3114 my ($mysqld, $datadir, $extra_opts)= @_;
3115
3116 my $install_datadir= $datadir || $mysqld->value('datadir');
3117 my $install_basedir= $mysqld->value('basedir');
3118 my $install_lang= $mysqld->value('lc-messages-dir');
3119 my $install_chsdir= $mysqld->value('character-sets-dir');
3120
3121 mtr_report("Installing system database...");
3122
3123 my $args;
3124 mtr_init_args(\$args);
3125 mtr_add_arg($args, "--no-defaults");
3126 mtr_add_arg($args, "--disable-getopt-prefix-matching");
3127 mtr_add_arg($args, "--bootstrap");
3128 mtr_add_arg($args, "--basedir=%s", $install_basedir);
3129 mtr_add_arg($args, "--datadir=%s", $install_datadir);
3130 mtr_add_arg($args, "--plugin-dir=%s", $plugindir);
3131 mtr_add_arg($args, "--default-storage-engine=myisam");
3132 mtr_add_arg($args, "--loose-skip-plugin-$_") for @optional_plugins;
3133 # starting from 10.0 bootstrap scripts require InnoDB
3134 mtr_add_arg($args, "--loose-innodb");
3135 mtr_add_arg($args, "--loose-innodb-log-file-size=10M");
3136 mtr_add_arg($args, "--loose-innodb-fast-shutdown=0");
3137 mtr_add_arg($args, "--disable-sync-frm");
3138 mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/");
3139 mtr_add_arg($args, "--core-file");
3140 mtr_add_arg($args, "--console");
3141 mtr_add_arg($args, "--character-set-server=utf8mb4");
3142 mtr_add_arg($args, "--loose-disable-performance-schema");
3143
3144 if ( $opt_debug )
3145 {
3146 mtr_add_arg($args, "--debug-dbug=$debug_d:t:i:A,%s/log/bootstrap.trace",
3147 $path_vardir_trace);
3148 }
3149
3150 mtr_add_arg($args, "--lc-messages-dir=%s", $install_lang);
3151 mtr_add_arg($args, "--character-sets-dir=%s", $install_chsdir);
3152
3153 # InnoDB arguments that affect file location and sizes may
3154 # need to be given to the bootstrap process as well as the
3155 # server process.
3156 foreach my $extra_opt ( @opt_extra_mysqld_opt ) {
3157 if ($extra_opt =~ /--innodb/) {
3158 mtr_add_arg($args, $extra_opt);
3159 }
3160 }
3161
3162 # If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
3163 # configure --disable-grant-options), mysqld will not recognize the
3164 # --bootstrap or --skip-grant-tables options. The user can set
3165 # MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
3166 # --bootstrap, to accommodate this.
3167 my $exe_mysqld_bootstrap =
3168 $ENV{'MYSQLD_BOOTSTRAP'} || find_mysqld($install_basedir);
3169
3170 # ----------------------------------------------------------------------
3171 # export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
3172 # ----------------------------------------------------------------------
3173 $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args)
3174 unless defined $ENV{'MYSQLD_BOOTSTRAP_CMD'};
3175
3176 # Extra options can come not only from the command line, but also
3177 # from option files or combinations. We want them on a command line
3178 # that is executed now, because otherwise the datadir might be
3179 # incompatible with the test settings, but not on the general
3180 # $MYSQLD_BOOTSTRAP_CMD line
3181 foreach my $extra_opt ( @$extra_opts ) {
3182 mtr_add_arg($args, $extra_opt);
3183 }
3184
3185 # ----------------------------------------------------------------------
3186 # Create the bootstrap.sql file
3187 # ----------------------------------------------------------------------
3188 my $bootstrap_sql_file= "$opt_vardir/log/bootstrap.sql";
3189 $ENV{'MYSQL_BOOTSTRAP_SQL_FILE'}= $bootstrap_sql_file;
3190
3191 if (! -e $bootstrap_sql_file)
3192 {
3193 My::Debugger::setup_boot_args(\$args, \$exe_mysqld_bootstrap, $bootstrap_sql_file);
3194
3195 my $path_sql= my_find_file($install_basedir,
3196 ["mysql", "sql/share", "share/mariadb",
3197 "share/mysql", "share", "scripts"],
3198 "mariadb_system_tables.sql",
3199 NOT_REQUIRED);
3200
3201 if (-f $path_sql )
3202 {
3203 my $sql_dir= dirname($path_sql);
3204 # Use the mysql database for system tables
3205 mtr_tofile($bootstrap_sql_file, "use mysql;\n");
3206
3207 # Add the offical mysql system tables
3208 # for a production system
3209 mtr_appendfile_to_file("$sql_dir/mariadb_system_tables.sql",
3210 $bootstrap_sql_file);
3211
3212 my $gis_sp_path = $source_dist ? "$bindir/scripts" : $sql_dir;
3213 mtr_appendfile_to_file("$gis_sp_path/maria_add_gis_sp_bootstrap.sql",
3214 $bootstrap_sql_file);
3215
3216 # Add the performance tables
3217 # for a production system
3218 mtr_appendfile_to_file("$sql_dir/mariadb_performance_tables.sql",
3219 $bootstrap_sql_file);
3220
3221 # Add the mysql system tables initial data
3222 # for a production system
3223 mtr_appendfile_to_file("$sql_dir/mariadb_system_tables_data.sql",
3224 $bootstrap_sql_file);
3225
3226 # Add test data for timezone - this is just a subset, on a real
3227 # system these tables will be populated either by mysql_tzinfo_to_sql
3228 # or by downloading the timezone table package from our website
3229 mtr_appendfile_to_file("$sql_dir/mariadb_test_data_timezone.sql",
3230 $bootstrap_sql_file);
3231
3232 # Fill help tables, just an empty file when running from bk repo
3233 # but will be replaced by a real fill_help_tables.sql when
3234 # building the source dist
3235 mtr_appendfile_to_file("$sql_dir/fill_help_tables.sql",
3236 $bootstrap_sql_file);
3237
3238 # Append sys schema
3239 mtr_appendfile_to_file("$gis_sp_path/mariadb_sys_schema.sql",
3240 $bootstrap_sql_file);
3241
3242 mtr_tofile($bootstrap_sql_file, "CREATE DATABASE IF NOT EXISTS test CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;\n");
3243
3244 # mysql.gtid_slave_pos was created in InnoDB, but many tests
3245 # run without InnoDB. Alter it to Aria now
3246 mtr_tofile($bootstrap_sql_file, "ALTER TABLE gtid_slave_pos ENGINE=Aria transactional=0;\n");
3247 }
3248 else
3249 {
3250 # Install db from init_db.sql that exist in early 5.1 and 5.0
3251 # versions of MySQL
3252 my $init_file= "$install_basedir/mysql-test/lib/init_db.sql";
3253 mtr_report(" - from '$init_file'");
3254 my $text= mtr_grab_file($init_file) or
3255 mtr_error("Can't open '$init_file': $!");
3256
3257 mtr_tofile($bootstrap_sql_file,
3258 sql_to_bootstrap($text));
3259 }
3260
3261 # Remove anonymous users
3262 mtr_tofile($bootstrap_sql_file,
3263 "DELETE FROM mysql.global_priv where user= '';\n");
3264
3265 # Create mtr database
3266 mtr_tofile($bootstrap_sql_file,
3267 "CREATE DATABASE mtr CHARSET=utf8mb4;\n");
3268
3269 # Add help tables and data for warning detection and supression
3270 mtr_tofile($bootstrap_sql_file,
3271 sql_to_bootstrap(mtr_grab_file("include/mtr_warnings.sql")));
3272
3273 # Add procedures for checking server is restored after testcase
3274 mtr_tofile($bootstrap_sql_file,
3275 sql_to_bootstrap(mtr_grab_file("include/mtr_check.sql")));
3276 }
3277
3278 # Log bootstrap command
3279 my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
3280 mtr_tofile($path_bootstrap_log,
3281 "$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
3282
3283 # Create directories mysql
3284 mkpath("$install_datadir/mysql");
3285
3286 my $realtime= gettimeofday();
3287 if ( My::SafeProcess->run
3288 (
3289 name => "bootstrap",
3290 path => $exe_mysqld_bootstrap,
3291 args => \$args,
3292 input => $bootstrap_sql_file,
3293 output => $path_bootstrap_log,
3294 error => $path_bootstrap_log,
3295 append => 1,
3296 verbose => $opt_verbose,
3297 ) != 0)
3298 {
3299 find(
3300 {
3301 no_chdir => 1,
3302 wanted => sub
3303 {
3304 My::CoreDump::core_wanted(\$num_saved_cores,
3305 $opt_max_save_core,
3306 @opt_cases == 0,
3307 $exe_mysqld_bootstrap, $opt_parallel);
3308 }
3309 },
3310 $install_datadir);
3311
3312 my $data= mtr_grab_file($path_bootstrap_log);
3313 mtr_error("Error executing mariadbd --bootstrap\n" .
3314 "Could not install system database from $bootstrap_sql_file\n" .
3315 "The $path_bootstrap_log file contains:\n$data\n");
3316 }
3317 else
3318 {
3319 mtr_verbose("Spent " . sprintf("%.3f", (gettimeofday() - $realtime)) . " seconds in bootstrap");
3320 }
3321 }
3322
3323
3324 sub run_testcase_check_skip_test($)
3325 {
3326 my ($tinfo)= @_;
3327
3328 # ----------------------------------------------------------------------
3329 # Skip some tests silently
3330 # ----------------------------------------------------------------------
3331
3332 my $start_from= $mtr_cases::start_from;
3333 if ( $start_from )
3334 {
3335 if ($tinfo->{'name'} eq $start_from ||
3336 $tinfo->{'shortname'} eq $start_from)
3337 {
3338 ## Found parting test. Run this test and all tests after this one
3339 $mtr_cases::start_from= "";
3340 }
3341 else
3342 {
3343 $tinfo->{'result'}= 'MTR_RES_SKIPPED';
3344 return 1;
3345 }
3346 }
3347
3348 # ----------------------------------------------------------------------
3349 # If marked to skip, just print out and return.
3350 # Note that a test case not marked as 'skip' can still be
3351 # skipped later, because of the test case itself in cooperation
3352 # with the mysqltest program tells us so.
3353 # ----------------------------------------------------------------------
3354
3355 if ( $tinfo->{'skip'} )
3356 {
3357 mtr_report_test_skipped($tinfo) unless $start_only;
3358 return 1;
3359 }
3360
3361 return 0;
3362 }
3363
3364
3365 sub run_query {
3366 my ($tinfo, $mysqld, $query)= @_;
3367
3368 my $args;
3369 mtr_init_args(\$args);
3370 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
3371 mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
3372
3373 mtr_add_arg($args, "-e %s", $query);
3374
3375 my $res= My::SafeProcess->run
3376 (
3377 name => "run_query -> ".$mysqld->name(),
3378 path => $exe_mysql,
3379 args => \$args,
3380 output => '/dev/null',
3381 error => '/dev/null'
3382 );
3383
3384 return $res
3385 }
3386
3387
3388 sub do_before_run_mysqltest($)
3389 {
3390 my $tinfo= shift;
3391 my $resfile= $tinfo->{result_file};
3392 return unless defined $resfile;
3393
3394 # Remove old files produced by mysqltest
3395 die "unsupported result file name $resfile, stoping" unless
3396 $resfile =~ /^(.*?)((?:,\w+)*)\.(rdiff|result|result~)$/;
3397 my ($base_file, $suites, $ext)= ($1, $2, $3);
3398 # if the result file is a diff, make a proper result file
3399 if ($ext eq 'rdiff') {
3400 my $base_result = $tinfo->{base_result};
3401 my $resdir= dirname($resfile);
3402 # we'll use a separate extension for generated result files
3403 # to be able to distinguish them from manually created
3404 # version-controlled results, and to ignore them in git.
3405 my $dest = "$base_file$suites.result~";
3406 my @cmd = ($exe_patch);
3407 if ($^O eq "MSWin32") {
3408 push @cmd, '--binary';
3409 }
3410 push @cmd, (qw/-r - -f -s -o/, $dest . $$, $base_result, $resfile);
3411 if (-w $resdir) {
3412 # don't rebuild a file if it's up to date
3413 unless (-e $dest and -M $dest < -M $resfile
3414 and -M $dest < -M $base_result) {
3415 run_system(@cmd);
3416 rename $cmd[-3], $dest or unlink $cmd[-3];
3417 }
3418 } else {
3419 $dest = $opt_tmpdir . '/' . basename($dest);
3420 $cmd[-3] = $dest . $$;
3421 run_system(@cmd);
3422 rename $cmd[-3], $dest or unlink $cmd[-3];
3423 }
3424
3425 $tinfo->{result_file} = $dest;
3426 }
3427
3428 unlink("$base_file.reject");
3429 unlink("$base_file.progress");
3430 unlink("$base_file.log");
3431 unlink("$base_file.warnings");
3432 }
3433
3434
3435 #
3436 # Check all server for sideffects
3437 #
3438 # RETURN VALUE
3439 # 0 ok
3440 # 1 Check failed
3441 # >1 Fatal errro
3442
3443 sub check_testcase($$)
3444 {
3445 my ($tinfo, $mode)= @_;
3446 my $tname= $tinfo->{name};
3447
3448 # Start the mysqltest processes in parallel to save time
3449 # also makes it possible to wait for any process to exit during the check
3450 my %started;
3451 foreach my $mysqld ( mysqlds() )
3452 {
3453 # Skip if server has been restarted with additional options
3454 if ( defined $mysqld->{'proc'} && ! exists $mysqld->{'restart_opts'} )
3455 {
3456 my $proc= start_check_testcase($tinfo, $mode, $mysqld);
3457 $started{$proc->pid()}= $proc;
3458 }
3459 }
3460
3461 # Return immediately if no check proceess was started
3462 return 0 unless ( keys %started );
3463
3464 my $timeout= start_timer(check_timeout($tinfo));
3465
3466 while (1){
3467 my $result;
3468 my $proc= My::SafeProcess->wait_any_timeout($timeout);
3469 mtr_report("Got $proc");
3470
3471 if ( delete $started{$proc->pid()} ) {
3472
3473 my $err_file= $proc->user_data();
3474 my $base_file= mtr_match_extension($err_file, "err"); # Trim extension
3475
3476 # One check testcase process returned
3477 my $res= $proc->exit_status();
3478
3479 if ( $res == 0){
3480 # Check completed without problem
3481
3482 # Remove the .err file the check generated
3483 unlink($err_file);
3484
3485 # Remove the .result file the check generated
3486 if ( $mode eq 'after' ){
3487 unlink("$base_file.result");
3488 }
3489
3490 if ( keys(%started) == 0){
3491 # All checks completed
3492 mark_time_used('check');
3493 return 0;
3494 }
3495 # Wait for next process to exit
3496 next;
3497 }
3498 else
3499 {
3500 if ( $mode eq "after" and $res == 1 )
3501 {
3502 # Test failed, grab the report mysqltest has created
3503 my $report= mtr_grab_file($err_file);
3504 $tinfo->{check}.=
3505 "\nMTR's internal check of the test case '$tname' failed.
3506 This means that the test case does not preserve the state that existed
3507 before the test case was executed. Most likely the test case did not
3508 do a proper clean-up. It could also be caused by the previous test run
3509 by this thread, if the server wasn't restarted.
3510 This is the diff of the states of the servers before and after the
3511 test case was executed:\n";
3512 $tinfo->{check}.= $report;
3513
3514 # Check failed, mark the test case with that info
3515 $tinfo->{'check_testcase_failed'}= 1;
3516 $result= 1;
3517 }
3518 elsif ( $res )
3519 {
3520 my $report= mtr_grab_file($err_file);
3521 $tinfo->{comment}.=
3522 "Could not execute 'check-testcase' $mode ".
3523 "testcase '$tname' (res: $res):\n";
3524 $tinfo->{comment}.= $report;
3525
3526 $result= 2;
3527 }
3528 else
3529 {
3530 # Remove the .result file the check generated
3531 unlink("$base_file.result");
3532 }
3533 # Remove the .err file the check generated
3534 unlink($err_file);
3535
3536 }
3537 }
3538 elsif ( $proc->{timeout} ) {
3539 $tinfo->{comment}.= "Timeout for 'check-testcase' expired after "
3540 .check_timeout($tinfo)." seconds";
3541 $result= 4;
3542 }
3543 else {
3544 # Unknown process returned, most likley a crash, abort everything
3545 $tinfo->{comment}=
3546 "The server $proc crashed while running ".
3547 "'check testcase $mode test'".
3548 get_log_from_proc($proc, $tinfo->{name});
3549 $result= 3;
3550 }
3551
3552 # Kill any check processes still running
3553 map($_->kill(), values(%started));
3554
3555 mtr_warning("Check-testcase failed, this could also be caused by the" .
3556 " previous test run by this worker thread")
3557 if $result > 1 && $mode eq "before";
3558 mark_time_used('check');
3559
3560 return $result;
3561 }
3562
3563 mtr_error("INTERNAL_ERROR: check_testcase");
3564 }
3565
3566
3567 # Start run mysqltest on one server
3568 #
3569 # RETURN VALUE
3570 # 0 OK
3571 # 1 Check failed
3572 #
3573 sub start_run_one ($$) {
3574 my ($mysqld, $run)= @_;
3575
3576 my $name= "$run-".$mysqld->name();
3577
3578 my $args;
3579 mtr_init_args(\$args);
3580
3581 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
3582 mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
3583
3584 mtr_add_arg($args, "--silent");
3585 mtr_add_arg($args, "--test-file=%s", "include/$run.test");
3586
3587 my $errfile= "$opt_vardir/tmp/$name.err";
3588 my $proc= My::SafeProcess->new
3589 (
3590 name => $name,
3591 path => $exe_mysqltest,
3592 error => $errfile,
3593 output => $errfile,
3594 args => \$args,
3595 user_data => $errfile,
3596 verbose => $opt_verbose,
3597 );
3598 mtr_verbose("Started $proc");
3599 return $proc;
3600 }
3601
3602
3603 #
3604 # Run script on all servers, collect results
3605 #
3606 # RETURN VALUE
3607 # 0 ok
3608 # 1 Failure
3609
3610 sub run_on_all($$)
3611 {
3612 my ($tinfo, $run)= @_;
3613
3614 # Start the mysqltest processes in parallel to save time
3615 # also makes it possible to wait for any process to exit during the check
3616 # and to have a timeout process
3617 my %started;
3618 foreach my $mysqld ( mysqlds() )
3619 {
3620 if ( defined $mysqld->{'proc'} )
3621 {
3622 my $proc= start_run_one($mysqld, $run);
3623 $started{$proc->pid()}= $proc;
3624 }
3625 }
3626
3627 # Return immediately if no check proceess was started
3628 return 0 unless ( keys %started );
3629
3630 my $timeout= start_timer(check_timeout($tinfo));
3631
3632 while (1){
3633 my $result;
3634 my $proc= My::SafeProcess->wait_any_timeout($timeout);
3635 mtr_report("Got $proc");
3636
3637 if ( delete $started{$proc->pid()} ) {
3638
3639 # One mysqltest process returned
3640 my $err_file= $proc->user_data();
3641 my $res= $proc->exit_status();
3642
3643 # Append the report from .err file
3644 $tinfo->{comment}.= " == $err_file ==\n";
3645 $tinfo->{comment}.= mtr_grab_file($err_file);
3646 $tinfo->{comment}.= "\n";
3647
3648 # Remove the .err file
3649 unlink($err_file);
3650
3651 if ( keys(%started) == 0){
3652 # All completed
3653 return 0;
3654 }
3655
3656 # Wait for next process to exit
3657 next;
3658 }
3659 elsif ($proc->{timeout}) {
3660 $tinfo->{comment}.= "Timeout for '$run' expired after "
3661 .check_timeout($tinfo)." seconds";
3662 }
3663 else {
3664 # Unknown process returned, most likley a crash, abort everything
3665 $tinfo->{comment}.=
3666 "The server $proc crashed while running '$run'".
3667 get_log_from_proc($proc, $tinfo->{name});
3668 }
3669
3670 # Kill any check processes still running
3671 map($_->kill(), values(%started));
3672
3673 return 1;
3674 }
3675 mtr_error("INTERNAL_ERROR: run_on_all");
3676 }
3677
3678
3679 sub mark_log {
3680 my ($log, $tinfo)= @_;
3681 my $log_msg= "CURRENT_TEST: $tinfo->{name}\n";
3682 pre_write_errorlog($log, $tinfo->{name});
3683 mtr_tofile($log, $log_msg);
3684 }
3685
3686
3687 sub find_testcase_skipped_reason($)
3688 {
3689 my ($tinfo)= @_;
3690
3691 # Set default message
3692 $tinfo->{'comment'}= "Detected by testcase(no log file)";
3693
3694 # Open the test log file
3695 my $F= IO::File->new($path_current_testlog)
3696 or return;
3697 my $reason;
3698
3699 while ( my $line= <$F> )
3700 {
3701 # Look for "reason: <reason for skipping test>"
3702 if ( $line =~ /reason: (.*)/ )
3703 {
3704 $reason= $1;
3705 }
3706 }
3707
3708 if ( ! $reason )
3709 {
3710 mtr_warning("Could not find reason for skipping test in $path_current_testlog");
3711 $reason= "Detected by testcase(reason unknown) ";
3712 }
3713 $tinfo->{'comment'}= $reason;
3714 }
3715
3716
3717 sub find_analyze_request
3718 {
3719 # Open the test log file
3720 my $F= IO::File->new($path_current_testlog)
3721 or return;
3722 my $analyze;
3723
3724 while ( my $line= <$F> )
3725 {
3726 # Look for "reason: <reason for skipping test>"
3727 if ( $line =~ /analyze: (.*)/ )
3728 {
3729 $analyze= $1;
3730 }
3731 }
3732
3733 return $analyze;
3734 }
3735
3736 # The test can leave a file in var/tmp/ to signal
3737 # that all servers should be restarted
3738 sub restart_forced_by_test($)
3739 {
3740 my $file = shift;
3741 my $restart = 0;
3742 foreach my $mysqld ( mysqlds() )
3743 {
3744 my $datadir = $mysqld->value('datadir');
3745 my $force_restart_file = "$datadir/mtr/$file";
3746 if ( -f $force_restart_file )
3747 {
3748 mtr_verbose("Restart of servers forced by test");
3749 $restart = 1;
3750 last;
3751 }
3752 }
3753 return $restart;
3754 }
3755
3756 # Return timezone value of tinfo or default value
3757 sub timezone {
3758 my ($tinfo)= @_;
3759 local $_ = $tinfo->{timezone};
3760 return 'DEFAULT' unless defined $_;
3761 no warnings 'uninitialized';
3762 s/\$\{(\w+)\}/$ENV{$1}/ge;
3763 s/\$(\w+)/$ENV{$1}/ge;
3764 $_;
3765 }
3766
3767 sub mycnf_create {
3768 my ($config) = @_;
3769 my $res;
3770
3771 foreach my $group ($config->option_groups()) {
3772 $res .= "[$group->{name}]\n";
3773
3774 foreach my $option ($group->options()) {
3775 $res .= $option->name();
3776 my $value= $option->value();
3777 if (defined $value) {
3778 $res .= "=$value";
3779 }
3780 $res .= "\n";
3781 }
3782 $res .= "\n";
3783 }
3784 $res;
3785 }
3786
3787 sub config_files($) {
3788 my ($tinfo) = @_;
3789 (
3790 'my.cnf' => \&mycnf_create,
3791 $tinfo->{suite}->config_files()
3792 );
3793 }
3794
3795 sub _like { return $config ? $config->like($_[0]) : (); }
3796 sub mysqlds { return _like('mysqld\.'); }
3797
3798 sub fix_servers($) {
3799 my ($tinfo) = @_;
3800 return () unless $config;
3801 my %servers = (
3802 qr/mysqld\./ => {
3803 SORT => 300,
3804 START => \&mysql_server_start,
3805 WAIT => \&mysql_server_wait,
3806 },
3807 $tinfo->{suite}->servers()
3808 );
3809 for ($config->groups()) {
3810 while (my ($re,$prop) = each %servers) {
3811 @$_{keys %$prop} = values %$prop if $_->{name} =~ /^$re/;
3812 }
3813 }
3814 }
3815
3816 sub all_servers {
3817 return unless $config;
3818 ( sort { $a->{SORT} <=> $b->{SORT} }
3819 grep { defined $_->{SORT} } $config->groups() );
3820 }
3821
3822 # Storage for changed environment variables
3823 our %old_env;
3824
3825 sub resfile_report_test ($) {
3826 my $tinfo= shift;
3827
3828 resfile_new_test();
3829
3830 resfile_test_info("name", $tinfo->{name});
3831 resfile_test_info("variation", $tinfo->{combination})
3832 if $tinfo->{combination};
3833 resfile_test_info("start_time", isotime time);
3834 }
3835
3836
3837 #
3838 # Run a single test case
3839 #
3840 # RETURN VALUE
3841 # 0 OK
3842 # > 0 failure
3843 #
3844
3845 sub run_testcase ($$) {
3846 my ($tinfo, $server_socket)= @_;
3847 my $print_freq=20;
3848
3849 mtr_verbose("Running test:", $tinfo->{name});
3850 $ENV{'MTR_TEST_NAME'} = $tinfo->{name};
3851 resfile_report_test($tinfo) if $opt_resfile;
3852
3853 for my $key (grep { /^MTR_COMBINATION/ } keys %ENV)
3854 {
3855 delete $ENV{$key};
3856 }
3857
3858 if (ref $tinfo->{combinations} eq 'ARRAY')
3859 {
3860 for (my $i = 0; $i < @{$tinfo->{combinations}}; ++$i )
3861 {
3862 my $combination = $tinfo->{combinations}->[$i];
3863 # Allow only alphanumerics plus _ - + . in combination names,
3864 # or anything beginning with -- (the latter comes from --combination)
3865 if ($combination && $combination !~ /^\w[-\w\.\+]*$/
3866 && $combination !~ /^--/)
3867 {
3868 mtr_error("Combination '$combination' contains illegal characters");
3869 }
3870 $ENV{"MTR_COMBINATION_". uc(${combination})} = 1;
3871 }
3872 $ENV{"MTR_COMBINATIONS"} = join(',', @{$tinfo->{combinations}});
3873 }
3874 elsif (exists $tinfo->{combinations})
3875 {
3876 die 'Unexpected type of $tinfo->{combinations}';
3877 }
3878
3879 # -------------------------------------------------------
3880 # Init variables that can change between each test case
3881 # -------------------------------------------------------
3882 my $timezone= timezone($tinfo);
3883 if ($timezone ne 'DEFAULT') {
3884 $ENV{'TZ'}= $timezone;
3885 } else {
3886 delete($ENV{'TZ'});
3887 }
3888 $ENV{MTR_SUITE_DIR} = $tinfo->{suite}->{dir};
3889 mtr_verbose("Setting timezone: $timezone");
3890
3891 if ( ! using_extern() )
3892 {
3893 my @restart= servers_need_restart($tinfo);
3894 if ( @restart != 0) {
3895 # Remember that we restarted for this test case (count restarts)
3896 $tinfo->{'restarted'}= 1;
3897 stop_servers(reverse @restart);
3898 if ($opt_warnings) {
3899 check_warnings_post_shutdown($server_socket);
3900 }
3901 }
3902
3903 if ( started(all_servers()) == 0 )
3904 {
3905
3906 # Remove old datadirs
3907 clean_datadir() unless $opt_start_dirty;
3908
3909 # Restore old ENV
3910 while (my ($option, $value)= each( %old_env )) {
3911 if (defined $value){
3912 mtr_verbose("Restoring $option to $value");
3913 $ENV{$option}= $value;
3914
3915 } else {
3916 mtr_verbose("Removing $option");
3917 delete($ENV{$option});
3918 }
3919 }
3920 %old_env= ();
3921
3922 mtr_verbose("Generating my.cnf from '$tinfo->{template_path}'");
3923
3924 # Generate new config file from template
3925 $config= My::ConfigFactory->new_config
3926 ( {
3927 testname => $tinfo->{name},
3928 basedir => $basedir,
3929 testdir => $glob_mysql_test_dir,
3930 template_path => $tinfo->{template_path},
3931 extra_template_path => $tinfo->{extra_template_path},
3932 vardir => $opt_vardir,
3933 tmpdir => $opt_tmpdir,
3934 baseport => $baseport,
3935 user => $opt_user,
3936 password => '',
3937 ssl => $opt_ssl_supported,
3938 embedded => $opt_embedded_server,
3939 }
3940 );
3941
3942 fix_servers($tinfo);
3943
3944 # Write config files:
3945 my %config_files = config_files($tinfo);
3946 while (my ($file, $generate) = each %config_files) {
3947 next unless $generate;
3948 my ($path) = "$opt_vardir/$file";
3949 open (F, '>', $path) or die "Could not open '$path': $!";
3950 print F &$generate($config);
3951 close F;
3952 }
3953
3954 # Remember current config so a restart can occur when a test need
3955 # to use a different one
3956 $current_config_name= $tinfo->{template_path};
3957
3958 #
3959 # Set variables in the ENV section
3960 #
3961 foreach my $option ($config->options_in_group("ENV"))
3962 {
3963 my ($name, $val)= ($option->name(), $option->value());
3964
3965 # Save old value to restore it before next time
3966 $old_env{$name}= $ENV{$name};
3967
3968 unless (defined $val) {
3969 mtr_warning("Uninitialized value for ", $name,
3970 ", group [ENV], file ", $current_config_name);
3971 } else {
3972 mtr_verbose($name, "=", $val);
3973 $ENV{$name}= $val;
3974 }
3975 }
3976 }
3977
3978 # Set up things for catalogs
3979 # The values of MARIADB_TOPDIR and MARIAD_DATADIR should
3980 # be taken from the values used by the default (first)
3981 # connection that is used by mariadb-test.
3982 my ($mysqld, @servers);
3983 @servers= all_servers();
3984 $mysqld= $servers[0];
3985 $ENV{'MARIADB_TOPDIR'}= $mysqld->value('datadir');
3986 if (!$opt_catalogs)
3987 {
3988 $ENV{'MARIADB_DATADIR'}= $mysqld->value('datadir');
3989 }
3990 else
3991 {
3992 $ENV{'MARIADB_DATADIR'}= $mysqld->value('datadir') . "/" . $catalog_name;
3993 }
3994
3995 # Write start of testcase to log
3996 mark_log($path_current_testlog, $tinfo);
3997
3998 # Make sure the safe_process also exits from now on
3999 if ($opt_start_exit) {
4000 My::SafeProcess->start_exit();
4001 }
4002
4003 if (start_servers($tinfo))
4004 {
4005 report_failure_and_restart($tinfo);
4006 unlink $path_current_testlog;
4007 return 1;
4008 }
4009 }
4010 mark_time_used('restart');
4011
4012 # --------------------------------------------------------------------
4013 # If --start or --start-dirty given, stop here to let user manually
4014 # run tests
4015 # If --wait-all is also given, do the same, but don't die if one
4016 # server exits
4017 # ----------------------------------------------------------------------
4018
4019 if ( $start_only )
4020 {
4021 mtr_print("\nStarted", started(all_servers()));
4022 mtr_print("Using config for test", $tinfo->{name});
4023 mtr_print("Port and socket path for server(s):");
4024 foreach my $mysqld ( mysqlds() )
4025 {
4026 mtr_print ($mysqld->name() . " " . $mysqld->value('port') .
4027 " " . $mysqld->value('socket'));
4028 }
4029 if ( $opt_start_exit )
4030 {
4031 mtr_print("Server(s) started, not waiting for them to finish");
4032 if (IS_WINDOWS)
4033 {
4034 POSIX::_exit(0); # exit hangs here in ActiveState Perl
4035 }
4036 else
4037 {
4038 exit(0);
4039 }
4040 }
4041 mtr_print("Waiting for server(s) to exit...");
4042 if ( $opt_wait_all ) {
4043 My::SafeProcess->wait_all();
4044 mtr_print( "All servers exited" );
4045 exit(1);
4046 }
4047 else {
4048 my $proc= My::SafeProcess->wait_any();
4049 if ( grep($proc eq $_, started(all_servers())) )
4050 {
4051 mtr_print("Server $proc died");
4052 exit(1);
4053 }
4054 mtr_print("Unknown process $proc died");
4055 exit(1);
4056 }
4057 }
4058
4059 my $test_timeout= start_timer(testcase_timeout($tinfo));
4060
4061 do_before_run_mysqltest($tinfo);
4062
4063 mark_time_used('admin');
4064
4065 if ( $opt_check_testcases and check_testcase($tinfo, "before") ){
4066 # Failed to record state of server or server crashed
4067 report_failure_and_restart($tinfo);
4068
4069 return 1;
4070 }
4071
4072 my $test= $tinfo->{suite}->start_test($tinfo);
4073 # Set to a list of processes we have to keep waiting (expectedly died servers)
4074 my %keep_waiting_proc = ();
4075 my $print_timeout= start_timer($print_freq * 60);
4076
4077 while (1)
4078 {
4079 my $proc;
4080 if (%keep_waiting_proc)
4081 {
4082 # Any other process exited?
4083 $proc = My::SafeProcess->check_any();
4084 if ($proc)
4085 {
4086 mtr_verbose ("Found exited process $proc");
4087 }
4088 else
4089 {
4090 # Also check if timer has expired, if so cancel waiting
4091 if ( has_expired($test_timeout) )
4092 {
4093 %keep_waiting_proc = ();
4094 }
4095 }
4096 }
4097 if (!%keep_waiting_proc && !$proc)
4098 {
4099 if ($test_timeout > $print_timeout)
4100 {
4101 $proc= My::SafeProcess->wait_any_timeout($print_timeout);
4102 if ($proc->{timeout})
4103 {
4104 #print out that the test is still on
4105 mtr_print("Test still running: $tinfo->{name}");
4106 #reset the timer
4107 $print_timeout= start_timer($print_freq * 60);
4108 next;
4109 }
4110 }
4111 else
4112 {
4113 $proc= My::SafeProcess->wait_any_timeout($test_timeout);
4114 }
4115 }
4116
4117 if ($proc and $proc eq $test) # mysqltest itself exited
4118 {
4119 my $res= $test->exit_status();
4120
4121 if (($res == 0 or $res == 62) and $opt_warnings and check_warnings($tinfo) )
4122 {
4123 # If test case suceeded, but it has produced unexpected
4124 # warnings, continue with $res == 1;
4125 # but if the test was skipped, it should remain skipped
4126 $res= 1 if $res == 0;
4127 resfile_output($tinfo->{'warnings'}) if $opt_resfile;
4128 }
4129
4130 if ( $res == 0 )
4131 {
4132 my $check_res;
4133 if ( restart_forced_by_test('force_restart') )
4134 {
4135 stop_all_servers($opt_shutdown_timeout);
4136 }
4137 elsif ( $opt_check_testcases and
4138 $check_res= check_testcase($tinfo, "after"))
4139 {
4140 if ($check_res == 1) {
4141 # Test case had sideeffects, not fatal error, just continue
4142 if ($opt_warnings) {
4143 # Checking error logs for warnings, so need to stop server
4144 # gracefully so that memory leaks etc. can be properly detected.
4145 stop_servers(reverse all_servers());
4146 check_warnings_post_shutdown($server_socket);
4147 # Even if we got warnings here, we should not fail this
4148 # particular test, as the warnings may be caused by an earlier
4149 # test.
4150 } else {
4151 # Not checking warnings, so can do a hard shutdown.
4152 stop_all_servers($opt_shutdown_timeout);
4153 }
4154 mtr_report("Resuming tests...\n");
4155 resfile_output($tinfo->{'check'}) if $opt_resfile;
4156 }
4157 else {
4158 # Test case check failed fatally, probably a server crashed
4159 report_failure_and_restart($tinfo);
4160 return 1;
4161 }
4162 }
4163 mtr_report_test_passed($tinfo);
4164 }
4165 elsif ( $res == 62 )
4166 {
4167 # Testcase itself tell us to skip this one
4168 $tinfo->{skip_detected_by_test}= 1;
4169 # Try to get reason from test log file
4170 find_testcase_skipped_reason($tinfo);
4171 mtr_report_test_skipped($tinfo);
4172 # Restart if skipped due to missing perl, it may have had side effects
4173 if ( restart_forced_by_test('force_restart_if_skipped') ||
4174 $tinfo->{'comment'} =~ /^perl not found/ )
4175 {
4176 stop_all_servers($opt_shutdown_timeout);
4177 }
4178 }
4179 elsif ( $res == 65 )
4180 {
4181 # Testprogram killed by signal
4182 $tinfo->{comment}=
4183 "testprogram crashed(returned code $res)";
4184 report_failure_and_restart($tinfo);
4185 }
4186 elsif ( $res == 1 )
4187 {
4188 # Check if the test tool requests that
4189 # an analyze script should be run
4190 my $analyze= find_analyze_request();
4191 if ($analyze){
4192 run_on_all($tinfo, "analyze-$analyze");
4193 }
4194
4195 # Wait a bit and see if a server died, if so report that instead
4196 mtr_milli_sleep(100);
4197 my $srvproc= My::SafeProcess::check_any();
4198 if ($srvproc && grep($srvproc eq $_, started(all_servers()))) {
4199 $proc= $srvproc;
4200 goto SRVDIED;
4201 }
4202
4203 # Test case failure reported by mysqltest
4204 report_failure_and_restart($tinfo);
4205 }
4206 else
4207 {
4208 # mysqltest failed, probably crashed
4209 $tinfo->{comment}=
4210 "mysqltest failed with unexpected return code $res\n";
4211 report_failure_and_restart($tinfo);
4212 }
4213
4214 # Save info from this testcase run to mysqltest.log
4215 if( -f $path_current_testlog)
4216 {
4217 if ($opt_resfile && $res && $res != 62) {
4218 resfile_output_file($path_current_testlog);
4219 }
4220 mtr_appendfile_to_file($path_current_testlog, $path_testlog);
4221 unlink($path_current_testlog);
4222 }
4223
4224 return ($res == 62) ? 0 : $res;
4225 } # if ($proc and $proc eq $test)
4226 elsif ($proc)
4227 {
4228 # It was not mysqltest that exited, add to a wait-to-be-started-again list.
4229 $keep_waiting_proc{$proc} = 1;
4230 }
4231
4232 mtr_verbose("Got " . join(",", keys(%keep_waiting_proc)));
4233
4234 mark_time_used('test');
4235 foreach my $wait_for_proc (keys(%keep_waiting_proc)) {
4236 # ----------------------------------------------------
4237 # Check if it was an expected crash
4238 # ----------------------------------------------------
4239 my @mysqld = grep($wait_for_proc eq $_->{proc}, mysqlds());
4240 goto SRVDIED unless @mysqld;
4241 my $check_crash = check_expected_crash_and_restart($mysqld[0]);
4242 if ($check_crash == 0) # unexpected exit/crash of $wait_for_proc
4243 {
4244 $proc= $mysqld[0]->{proc};
4245 goto SRVDIED;
4246 }
4247 elsif ($check_crash == 1) # $wait_for_proc was started again by check_expected_crash_and_restart()
4248 {
4249 delete $keep_waiting_proc{$wait_for_proc};
4250 }
4251 elsif ($check_crash == 2) # we must keep waiting
4252 {
4253 # do nothing
4254 }
4255 } # foreach my $wait_for_proc
4256
4257 next;
4258
4259 SRVDIED:
4260 # ----------------------------------------------------
4261 # Stop the test case timer
4262 # ----------------------------------------------------
4263 $test_timeout= 0;
4264
4265 # ----------------------------------------------------
4266 # Check if it was a server that died
4267 # ----------------------------------------------------
4268 if ( grep($proc eq $_, started(all_servers())) )
4269 {
4270 # Server failed, probably crashed
4271 $tinfo->{comment}=
4272 "Server $proc failed during test run" .
4273 get_log_from_proc($proc, $tinfo->{name});
4274
4275 # ----------------------------------------------------
4276 # It's not mysqltest that has exited, kill it
4277 # ----------------------------------------------------
4278 $test->kill();
4279
4280 report_failure_and_restart($tinfo);
4281 return 1;
4282 }
4283
4284 # Try to dump core for mysqltest and all servers
4285 foreach my $proc ($test, started(all_servers()))
4286 {
4287 mtr_print("Trying to dump core for $proc");
4288 if ($proc->dump_core())
4289 {
4290 $proc->wait_one(20);
4291 }
4292 }
4293
4294 # ----------------------------------------------------
4295 # It's not mysqltest that has exited, kill it
4296 # ----------------------------------------------------
4297 $test->kill();
4298
4299 # ----------------------------------------------------
4300 # Check if testcase timer expired
4301 # ----------------------------------------------------
4302 if ( $proc->{timeout} )
4303 {
4304 my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
4305 $tinfo->{comment}=
4306 "Test case timeout after ".testcase_timeout($tinfo).
4307 " seconds\n\n";
4308 # Add 20 last executed commands from test case log file
4309 if (-e $log_file_name)
4310 {
4311 $tinfo->{comment}.=
4312 "== $log_file_name == \n".
4313 mtr_lastlinesfromfile($log_file_name, 20)."\n";
4314 }
4315 $tinfo->{'timeout'}= testcase_timeout($tinfo); # Mark as timeout
4316 run_on_all($tinfo, 'analyze-timeout');
4317
4318 report_failure_and_restart($tinfo);
4319 return 1;
4320 }
4321
4322 mtr_error("Unhandled process $proc exited");
4323 }
4324 mtr_error("Should never come here");
4325 }
4326
4327
4328 # Keep track of last position in mysqld error log where we scanned for
4329 # warnings, so we can attribute any warnings found to the correct test
4330 # suite or server restart.
4331 our $last_warning_position= { };
4332
4333 # Called just before a mysqld server is started or a testcase is run,
4334 # to keep track of which tests have been run since last restart, and
4335 # of when the error log is reset.
4336 #
4337 # Second argument $test_name is test name, or undef for server restart.
4338 sub pre_write_errorlog {
4339 my ($error_log, $test_name)= @_;
4340
4341 if (! -e $error_log) {
4342 # If the error log is moved away, reset the warning parse position.
4343 delete $last_warning_position->{$error_log};
4344 }
4345
4346 if (defined($test_name)) {
4347 $last_warning_position->{$error_log}{test_names}= []
4348 unless exists($last_warning_position->{$error_log}{test_names});
4349 push @{$last_warning_position->{$error_log}{test_names}}, $test_name;
4350 } else {
4351 # Server restart, so clear the list of tests run since last restart.
4352 # (except the last one (if any), which is the test about to be run).
4353 if (defined($last_warning_position->{$error_log}{test_names}) &&
4354 @{$last_warning_position->{$error_log}{test_names}}) {
4355 $last_warning_position->{$error_log}{test_names}=
4356 [$last_warning_position->{$error_log}{test_names}[-1]];
4357 } else {
4358 $last_warning_position->{$error_log}{test_names}= [];
4359 }
4360 }
4361 }
4362
4363 # Extract server log from after the last occurrence of named test
4364 # Return as an array of lines
4365 #
4366
4367 sub extract_server_log ($$) {
4368 my ($error_log, $tname) = @_;
4369
4370 return unless $error_log;
4371
4372 # Open the servers .err log file and read all lines
4373 # belonging to current test into @lines
4374 my $Ferr = IO::File->new($error_log)
4375 or mtr_error("Could not open file '$error_log' for reading: $!");
4376
4377 my @lines;
4378 my $found_test= 0; # Set once we've found the log of this test
4379 while ( my $line = <$Ferr> )
4380 {
4381 if ($found_test)
4382 {
4383 # If test wasn't last after all, discard what we found, test again.
4384 if ( $line =~ /^CURRENT_TEST:/)
4385 {
4386 @lines= ();
4387 $found_test= $line =~ /^CURRENT_TEST: $tname/;
4388 }
4389 else
4390 {
4391 push(@lines, $line);
4392 if (scalar(@lines) > 1000000) {
4393 $Ferr = undef;
4394 mtr_warning("Too much log in $error_log, bailing out from extracting");
4395 return ();
4396 }
4397 }
4398 }
4399 else
4400 {
4401 # Search for beginning of test, until found
4402 $found_test= 1 if ($line =~ /^CURRENT_TEST: $tname/);
4403 }
4404 }
4405 $Ferr = undef; # Close error log file
4406
4407 return @lines;
4408 }
4409
4410 # Get log from server identified from its $proc object, from named test
4411 # Return as a single string
4412 #
4413
4414 sub get_log_from_proc ($$) {
4415 my ($proc, $name)= @_;
4416 my $srv_log= "";
4417
4418 foreach my $mysqld (all_servers()) {
4419 if ($mysqld->{proc} eq $proc) {
4420 my @srv_lines= extract_server_log($mysqld->if_exist('log-error'), $name);
4421 $srv_log= "\nServer log from this test:\n" .
4422 "----------SERVER LOG START-----------\n". join ("", @srv_lines) .
4423 "----------SERVER LOG END-------------\n";
4424 last;
4425 }
4426 }
4427 return $srv_log;
4428 }
4429
4430 #
4431 # Perform a rough examination of the servers
4432 # error log and write all lines that look
4433 # suspicious into $error_log.warnings
4434 #
4435
4436 sub extract_warning_lines ($$) {
4437 my ($error_log, $append) = @_;
4438
4439 # Open the servers .err log file and read all lines
4440 # belonging to current tets into @lines
4441 my $Ferr = IO::File->new($error_log)
4442 or return [];
4443 my $last_pos= $last_warning_position->{$error_log}{seek_pos};
4444 $Ferr->seek($last_pos, 0) if defined($last_pos);
4445 # If the seek fails, we will parse the whole error log, at least we will not
4446 # miss any warnings.
4447
4448 my @lines= <$Ferr>;
4449 $last_warning_position->{$error_log}{seek_pos}= $Ferr->tell();
4450 $Ferr = undef; # Close error log file
4451
4452 # mysql_client_test.test sends a COM_DEBUG packet to the server
4453 # to provoke a safemalloc leak report, ignore any warnings
4454 # between "Begin/end safemalloc memory dump"
4455 if ( grep(/Begin safemalloc memory dump:/, @lines) > 0)
4456 {
4457 my $discard_lines= 1;
4458 foreach my $line ( @lines )
4459 {
4460 if ($line =~ /Begin safemalloc memory dump:/){
4461 $discard_lines = 1;
4462 } elsif ($line =~ /End safemalloc memory dump./){
4463 $discard_lines = 0;
4464 }
4465
4466 if ($discard_lines){
4467 $line = "ignored";
4468 }
4469 }
4470 }
4471
4472 # Write all suspicious lines to $error_log.warnings file
4473 my $warning_log = "$error_log.warnings";
4474 my $Fwarn = IO::File->new($warning_log, $append ? "a+" : "w")
4475 or die("Could not open file '$warning_log' for writing: $!");
4476 if (!$append)
4477 {
4478 print $Fwarn "Suspicious lines from $error_log\n";
4479 }
4480
4481 my @patterns =
4482 (
4483 qr/^Warning|(mysqld|mariadbd): Warning|\[Warning\]/,
4484 qr/^Error:|\[ERROR\]/,
4485 qr/^==\d+==\s+\S/, # valgrind errors
4486 qr/InnoDB: Warning|InnoDB: Error/,
4487 qr/^safe_mutex:|allocated at line/,
4488 qr/missing DBUG_RETURN/,
4489 qr/Attempting backtrace/,
4490 qr/Assertion .* failed/,
4491 qr/Sanitizer/,
4492 qr/runtime error:/,
4493 );
4494 # These are taken from the include/mtr_warnings.sql global suppression
4495 # list. They occur delayed, so they can be parsed during shutdown rather
4496 # than during the per-test check.
4497 #
4498 # ToDo: having the warning suppressions inside the mysqld we are trying to
4499 # check is in any case horrible. We should change it to all be done here
4500 # within the Perl code, which is both simpler, easier, faster, and more
4501 # robust. We could still have individual test cases put in suppressions by
4502 # parsing statically or by writing dynamically to a CSV table read by the
4503 # Perl code.
4504 my @antipatterns =
4505 (
4506 @global_suppressions,
4507 qr/error .*connecting to master/,
4508 qr/InnoDB: Dumping buffer pool.*/,
4509 qr/InnoDB: Buffer pool.*/,
4510 qr/InnoDB: Could not free any blocks in the buffer pool!/,
4511 qr/InnoDB: innodb_open_files .* should not be greater than/,
4512 qr/InnoDB: Trying to delete tablespace.*but there are.*pending/,
4513 qr/InnoDB: Tablespace 1[0-9]* was not found at .*, and innodb_force_recovery was set/,
4514 qr/InnoDB: Long wait \([0-9]+ seconds\) for double-write buffer flush/,
4515 qr/Slave: Unknown table 't1' .* 1051/,
4516 qr/Slave SQL:.*(Internal MariaDB error code: [[:digit:]]+|Query:.*)/,
4517 qr/slave SQL thread aborted/,
4518 qr/unknown option '--loose[-_]/,
4519 qr/unknown variable 'loose[-_]/,
4520 #qr/Invalid .*old.* table or database name/,
4521 qr/Now setting lower_case_table_names to [02]/,
4522 qr/Setting lower_case_table_names=2/,
4523 qr/You have forced lower_case_table_names to 0/,
4524 qr/deprecated/,
4525 qr/Slave SQL thread retried transaction/,
4526 qr/Slave \(additional info\)/,
4527 qr/Incorrect information in file/,
4528 qr/Simulating error for/,
4529 qr/Slave I\/O: Get master SERVER_ID failed with error:.*/,
4530 qr/Slave I\/O: Get master clock failed with error:.*/,
4531 qr/Slave I\/O: Get master COLLATION_SERVER failed with error:.*/,
4532 qr/Slave I\/O: Get master TIME_ZONE failed with error:.*/,
4533 qr/Slave I\/O: Get master \@\@GLOBAL.gtid_domain_id failed with error:.*/,
4534 qr/Slave I\/O: Setting \@slave_connect_state failed with error:.*/,
4535 qr/Slave I\/O: Setting \@slave_gtid_strict_mode failed with error:.*/,
4536 qr/Slave I\/O: Setting \@slave_gtid_ignore_duplicates failed with error:.*/,
4537 qr/Slave I\/O: Setting \@slave_until_gtid failed with error:.*/,
4538 qr/Slave I\/O: Get master GTID position failed with error:.*/,
4539 qr/Slave I\/O: error reconnecting to master '.*' - retry-time: [1-3] retries/,
4540 qr/Slave I\/0: Master command COM_BINLOG_DUMP failed/,
4541 qr/Error reading packet/,
4542 qr/Lost connection to MariaDB server at 'reading initial communication packet'/,
4543 qr/Could not read packet:.* state: [2-3] /,
4544 qr/Could not read packet:.* errno: 104 /,
4545 qr/Could not read packet:.* errno: 0 .* length: 0/,
4546 qr/Could not write packet:.* errno: 32 /,
4547 qr/Could not write packet:.* errno: 104 /,
4548 qr/Semisync ack receiver got error 1158/,
4549 qr/Semisync ack receiver got hangup/,
4550 qr/Connection was killed/,
4551 qr/Failed on request_dump/,
4552 qr/Slave: Can't drop database.* database doesn't exist/,
4553 qr/Slave: Operation DROP USER failed for 'create_rout_db'/,
4554 qr|Checking table: '\..mtr.test_suppressions'|,
4555 qr|Table \./test/bug53592 has a primary key in InnoDB data dictionary, but not in|,
4556 qr|Table '\..mtr.test_suppressions' is marked as crashed and should be repaired|,
4557 qr|Table 'test_suppressions' is marked as crashed and should be repaired|,
4558 qr|Can't open shared library|,
4559 qr|Couldn't load plugin named .*EXAMPLE.*|,
4560 qr|InnoDB: Error: table 'test/bug39438'|,
4561 qr| entry '.*' ignored in --skip-name-resolve mode|,
4562 qr|mysqld got signal 6|,
4563 qr|Error while setting value 'pool-of-threads' to 'thread_handling'|,
4564 qr|Access denied for user|,
4565 qr|Aborted connection|,
4566 qr|table.*is full|,
4567 qr/\[ERROR\] (mysqld|mariadbd): \Z/, # Warning from Aria recovery
4568 qr|Linux Native AIO|, # warning that aio does not work on /dev/shm
4569 qr|io_uring_queue_init\(\) failed with|,
4570 qr|InnoDB: io_uring failed: falling back to libaio|,
4571 qr/InnoDB: Failed to set O_DIRECT on file/,
4572 qr|setrlimit could not change the size of core files to 'infinity';|,
4573 qr|failed to retrieve the MAC address|,
4574 qr|Plugin 'FEEDBACK' init function returned error|,
4575 qr|Plugin 'FEEDBACK' registration as a INFORMATION SCHEMA failed|,
4576 qr|'log-bin-use-v1-row-events' is MySQL .* compatible option|,
4577 qr|InnoDB: Setting thread \d+ nice to \d+ failed, current nice \d+, errno 13|, # setpriority() fails under valgrind
4578 qr|Failed to setup SSL|,
4579 qr|SSL error: Failed to set ciphers to use|,
4580 qr/Plugin 'InnoDB' will be forced to shutdown/,
4581 qr|Could not increase number of max_open_files to more than|,
4582 qr|Changed limits: max_open_files|,
4583 qr/InnoDB: Error table encrypted but encryption service not available.*/,
4584 qr/InnoDB: Could not find a valid tablespace file for*/,
4585 qr/InnoDB: Tablespace open failed for*/,
4586 qr/InnoDB: Failed to find tablespace for table*/,
4587 qr/InnoDB: Space */,
4588 qr|InnoDB: You may have to recover from a backup|,
4589 qr|InnoDB: It is also possible that your operatingsystem has corrupted its own file cache|,
4590 qr|InnoDB: and rebooting your computer removes the error|,
4591 qr|InnoDB: If the corrupt page is an index page you can also try to|,
4592 qr|nnoDB: fix the corruption by dumping, dropping, and reimporting|,
4593 qr|InnoDB: the corrupt table. You can use CHECK|,
4594 qr|InnoDB: TABLE to scan your table for corruption|,
4595 qr/InnoDB: See also */,
4596 qr/InnoDB: Cannot open .*ib_buffer_pool.* for reading: No such file or directory*/,
4597 qr/InnoDB: Table .*mysql.*innodb_table_stats.* not found./,
4598 qr/InnoDB: User stopword table .* does not exist./,
4599 qr/Dump thread [0-9]+ last sent to server [0-9]+ binlog file:pos .+/,
4600 qr/Detected table cache mutex contention at instance .* waits. Additional table cache instance cannot be activated: consider raising table_open_cache_instances. Number of active instances/,
4601 qr/WSREP: Failed to guess base node address/,
4602 qr/WSREP: Guessing address for incoming client/,
4603
4604 qr/InnoDB: Difficult to find free blocks in the buffer pool*/,
4605 # Disable test for UBSAN on dynamically loaded objects
4606 qr/runtime error: member call.*object.*'Handler_share'/,
4607 qr/sql_type\.cc.* runtime error: member call.*object.* 'Type_collection'/,
4608 );
4609
4610 my $matched_lines= [];
4611 LINE: foreach my $line ( @lines )
4612 {
4613 PAT: foreach my $pat ( @patterns )
4614 {
4615 if ( $line =~ /$pat/ )
4616 {
4617 foreach my $apat (@antipatterns)
4618 {
4619 next LINE if $line =~ $apat;
4620 }
4621 print $Fwarn $line;
4622 push @$matched_lines, $line;
4623 last PAT;
4624 }
4625 }
4626 }
4627 $Fwarn = undef; # Close file
4628
4629 if (scalar(@$matched_lines) > 0 &&
4630 defined($last_warning_position->{$error_log}{test_names})) {
4631 return ($last_warning_position->{$error_log}{test_names}, $matched_lines);
4632 } else {
4633 return ([], $matched_lines);
4634 }
4635 }
4636
4637
4638 # Run include/check-warnings.inc
4639 #
4640 # RETURN VALUE
4641 # 0 OK
4642 # 1 Check failed
4643 #
4644 sub start_check_warnings ($$) {
4645 my $tinfo= shift;
4646 my $mysqld= shift;
4647
4648 my $name= "warnings-".$mysqld->name();
4649
4650 my $log_error= $mysqld->value('log-error');
4651 # To be communicated to the test
4652 $ENV{MTR_LOG_ERROR}= $log_error;
4653 extract_warning_lines($log_error, 0);
4654
4655 my $args;
4656 mtr_init_args(\$args);
4657
4658 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
4659 mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
4660 mtr_add_arg($args, "--test-file=%s", "include/check-warnings.inc");
4661
4662 if ( $opt_embedded_server )
4663 {
4664
4665 # Get the args needed for the embedded server
4666 # and append them to args prefixed
4667 # with --sever-arg=
4668
4669 my $mysqld= $config->group('embedded')
4670 or mtr_error("Could not get [embedded] section");
4671
4672 my $mysqld_args;
4673 mtr_init_args(\$mysqld_args);
4674 my $extra_opts= get_extra_opts($mysqld, $tinfo);
4675 mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
4676 mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
4677 }
4678
4679 my $errfile= "$opt_vardir/tmp/$name.err";
4680 my $proc= My::SafeProcess->new
4681 (
4682 name => $name,
4683 path => $exe_mysqltest,
4684 error => $errfile,
4685 output => $errfile,
4686 args => \$args,
4687 user_data => [$errfile, $mysqld],
4688 verbose => $opt_verbose,
4689 );
4690 mtr_verbose("Started $proc");
4691 return $proc;
4692 }
4693
4694
4695 #
4696 # Loop through our list of processes and check the error log
4697 # for unexpected errors and warnings
4698 #
4699 sub check_warnings ($) {
4700 my ($tinfo)= @_;
4701 my $res= 0;
4702
4703 my $tname= $tinfo->{name};
4704
4705 # Clear previous warnings
4706 delete($tinfo->{warnings});
4707
4708 # Start the mysqltest processes in parallel to save time
4709 # also makes it possible to wait for any process to exit during the check
4710 my %started;
4711 foreach my $mysqld ( mysqlds() )
4712 {
4713 if ( defined $mysqld->{'proc'} )
4714 {
4715 my $proc= start_check_warnings($tinfo, $mysqld);
4716 $started{$proc->pid()}= $proc;
4717 }
4718 }
4719
4720 # Return immediately if no check proceess was started
4721 return 0 unless ( keys %started );
4722
4723 my $timeout= start_timer(check_timeout($tinfo));
4724
4725 my $result= 0;
4726 while (1){
4727 my $proc= My::SafeProcess->wait_any_timeout($timeout);
4728 mtr_report("Got $proc");
4729
4730 if ( delete $started{$proc->pid()} ) {
4731 # One check warning process returned
4732 my $res= $proc->exit_status();
4733 my ($err_file, $mysqld)= @{$proc->user_data()};
4734
4735 if ( $res == 0 or $res == 62 ){
4736
4737 if ( $res == 0 ) {
4738 # Check completed with problem
4739 my $report= mtr_grab_file($err_file);
4740 # Log to var/log/warnings file
4741 mtr_tofile("$opt_vardir/log/warnings",
4742 $tname."\n".$report);
4743
4744 $tinfo->{'warnings'}.= $report;
4745 $result= 1;
4746 }
4747
4748 if ( $res == 62 ) {
4749 # Test case was ok and called "skip"
4750 # Remove the .err file the check generated
4751 unlink($err_file);
4752 }
4753
4754 if ( keys(%started) == 0){
4755 # All checks completed
4756 mark_time_used('ch-warn');
4757 return $result;
4758 }
4759 # Wait for next process to exit
4760 next;
4761 }
4762 else
4763 {
4764 my $report= mtr_grab_file($err_file);
4765 $tinfo->{comment}.=
4766 "Could not execute 'check-warnings' for ".
4767 "testcase '$tname' (res: $res) server: '".
4768 $mysqld->name() ."':\n";
4769 $tinfo->{comment}.= $report;
4770
4771 $result= 2;
4772 }
4773 }
4774 elsif ( $proc->{timeout} ) {
4775 $tinfo->{comment}.= "Timeout for 'check warnings' expired after "
4776 .check_timeout($tinfo)." seconds";
4777 $result= 4;
4778 }
4779 else {
4780 # Unknown process returned, most likley a crash, abort everything
4781 $tinfo->{comment}=
4782 "The server $proc crashed while running 'check warnings'".
4783 get_log_from_proc($proc, $tinfo->{name});
4784 $result= 3;
4785 }
4786
4787 # Kill any check processes still running
4788 map($_->kill(), values(%started));
4789
4790 mark_time_used('ch-warn');
4791 return $result;
4792 }
4793
4794 mtr_error("INTERNAL_ERROR: check_warnings");
4795 }
4796
4797 # Check for warnings generated during shutdown of a mysqld server.
4798 # If any, report them to master server, and return true; else just return
4799 # false.
4800
4801 sub check_warnings_post_shutdown {
4802 my ($server_socket)= @_;
4803 my $testname_hash= { };
4804 my $report= '';
4805 foreach my $mysqld ( mysqlds())
4806 {
4807 my ($testlist, $match_lines)=
4808 extract_warning_lines($mysqld->value('log-error'), 1);
4809 $testname_hash->{$_}= 1 for @$testlist;
4810 $report.= join('', @$match_lines);
4811 }
4812 my @warning_tests= keys(%$testname_hash);
4813 if (@warning_tests) {
4814 my $fake_test= My::Test->new(testnames => \@warning_tests);
4815 $fake_test->{'warnings'}= $report;
4816 $fake_test->write_test($server_socket, 'WARNINGS');
4817 }
4818 }
4819
4820 #
4821 # Check for the file indicating expected crash and restart it.
4822 #
4823 sub check_expected_crash_and_restart {
4824 my $mysqld = shift;
4825
4826 # Check if crash expected by looking at the .expect file
4827 # in var/tmp
4828 my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
4829 if ( -f $expect_file )
4830 {
4831 mtr_verbose("Crash was expected, file '$expect_file' exists");
4832
4833 for (my $waits = 0; $waits < 50; mtr_milli_sleep(100), $waits++)
4834 {
4835 # Race condition seen on Windows: try again until file not empty
4836 next if -z $expect_file;
4837 # If last line in expect file starts with "wait"
4838 # sleep a little and try again, thus allowing the
4839 # test script to control when the server should start
4840 # up again. Keep trying for up to 5s at a time.
4841 my $last_line= mtr_lastlinesfromfile($expect_file, 1);
4842 if ($last_line =~ /^wait/ )
4843 {
4844 mtr_verbose("Test says wait before restart") if $waits == 0;
4845 next;
4846 }
4847 delete $ENV{MTR_BINDIR_FORCED};
4848
4849 # Ignore any partial or unknown command
4850 next unless $last_line =~ /^restart/;
4851 # If last line begins "restart:", the rest of the line is read as
4852 # extra command line options to add to the restarted mysqld.
4853 # Anything other than 'wait' or 'restart:' (with a colon) will
4854 # result in a restart with original mysqld options.
4855 if ($last_line =~ /restart_bindir\s+(\S+)(:.+)?/) {
4856 $ENV{MTR_BINDIR_FORCED}= $1;
4857 if ($2) {
4858 my @rest_opt= split(' ', $2);
4859 $mysqld->{'restart_opts'}= \@rest_opt;
4860 }
4861 } elsif ($last_line =~ /restart:(.+)/) {
4862 my @rest_opt= split(' ', $1);
4863 $mysqld->{'restart_opts'}= \@rest_opt;
4864 } else {
4865 delete $mysqld->{'restart_opts'};
4866 }
4867 unlink($expect_file);
4868
4869 # Start server with same settings as last time
4870 return mysqld_start($mysqld, $mysqld->{'started_opts'});
4871 }
4872 # Loop ran through: we should keep waiting after a re-check
4873 return 2;
4874 }
4875
4876 # Not an expected crash
4877 return 0;
4878 }
4879
4880
4881 # Remove all files and subdirectories of a directory
4882 sub clean_dir {
4883 my ($dir)= @_;
4884 mtr_verbose("clean_dir: $dir");
4885 finddepth(
4886 { no_chdir => 1,
4887 wanted => sub {
4888 if (-d $_){
4889 # A dir
4890 if ($_ eq $dir){
4891 # The dir to clean
4892 return;
4893 } else {
4894 mtr_verbose("rmdir: '$_'");
4895 rmdir($_) or mtr_warning("rmdir($_) failed: $!");
4896 }
4897 } else {
4898 # Hopefully a file
4899 mtr_verbose("unlink: '$_'");
4900 unlink($_) or mtr_warning("unlink($_) failed: $!");
4901 }
4902 }
4903 },
4904 $dir);
4905 }
4906
4907
4908 sub clean_datadir {
4909 mtr_verbose("Cleaning datadirs...");
4910
4911 if (started(all_servers()) != 0){
4912 mtr_error("Trying to clean datadir before all servers stopped");
4913 }
4914
4915 for (all_servers())
4916 {
4917 my $dir= "$opt_vardir/".$_->{name};
4918 mtr_verbose(" - removing '$dir'");
4919 rmtree($dir);
4920 }
4921
4922 # Remove all files in tmp and var/tmp
4923 clean_dir("$opt_vardir/tmp");
4924 if ($opt_tmpdir ne "$opt_vardir/tmp"){
4925 clean_dir($opt_tmpdir);
4926 }
4927 }
4928
4929
4930 #
4931 # Save datadir before it's removed
4932 #
4933 sub save_datadir_after_failure($$) {
4934 my ($dir, $savedir)= @_;
4935
4936 mtr_report(" - saving '$dir'");
4937 my $dir_name= basename($dir);
4938 rename("$dir", "$savedir/$dir_name");
4939 }
4940
4941
4942 sub after_failure ($) {
4943 my ($tinfo)= @_;
4944
4945 mtr_report("Saving datadirs...");
4946
4947 my $save_dir= "$opt_vardir/log/";
4948 $save_dir.= $tinfo->{name};
4949 # Add combination name if any
4950 $save_dir.= '-' . join(',', sort @{$tinfo->{combinations}})
4951 if defined $tinfo->{combinations};
4952
4953 # Save savedir path for server
4954 $tinfo->{savedir}= $save_dir;
4955
4956 mkpath($save_dir) if ! -d $save_dir;
4957
4958 #
4959 # Create a log of files in vardir (good for buildbot)
4960 #
4961 if (!IS_WINDOWS)
4962 {
4963 my $Flog= IO::File->new("$opt_vardir/log/files.log", "w");
4964 if ($Flog)
4965 {
4966 print $Flog scalar(`/bin/ls -Rl $opt_vardir/*`);
4967 close($Flog);
4968 }
4969 }
4970
4971 # Save the used config files
4972 my %config_files = config_files($tinfo);
4973 while (my ($file, $generate) = each %config_files) {
4974 copy("$opt_vardir/$file", $save_dir);
4975 }
4976
4977 # Copy the tmp dir
4978 copytree("$opt_vardir/tmp/", "$save_dir/tmp/");
4979
4980 foreach (all_servers()) {
4981 my $dir= "$opt_vardir/".$_->{name};
4982 save_datadir_after_failure($dir, $save_dir);
4983 }
4984 }
4985
4986
4987 sub report_failure_and_restart ($) {
4988 my $tinfo= shift;
4989
4990 if ($opt_valgrind && ($tinfo->{'warnings'} || $tinfo->{'timeout'}) &&
4991 $opt_core_on_failure == 0)
4992 {
4993 # In these cases we may want valgrind report from normal termination
4994 $tinfo->{'dont_kill_server'}= 1;
4995 }
4996 # Shutdown properly if not to be killed (for valgrind)
4997 stop_all_servers($tinfo->{'dont_kill_server'} ? $opt_shutdown_timeout : 0);
4998
4999 $tinfo->{'result'}= 'MTR_RES_FAILED';
5000
5001 my $test_failures= $tinfo->{'failures'} || 0;
5002 $tinfo->{'failures'}= $test_failures + 1;
5003
5004
5005 if ( $tinfo->{comment} )
5006 {
5007 # The test failure has been detected by mysql-test-run.pl
5008 # when starting the servers or due to other error, the reason for
5009 # failing the test is saved in "comment"
5010 ;
5011 }
5012
5013 if ( !defined $tinfo->{logfile} )
5014 {
5015 my $logfile= $path_current_testlog;
5016 if ( defined $logfile )
5017 {
5018 if ( -f $logfile )
5019 {
5020 # Test failure was detected by test tool and its report
5021 # about what failed has been saved to file. Save the report
5022 # in tinfo
5023 $tinfo->{logfile}= mtr_fromfile($logfile);
5024 # If no newlines in the test log:
5025 # (it will contain the CURRENT_TEST written by mtr, so is not empty)
5026 if ($tinfo->{logfile} !~ /\n/)
5027 {
5028 # Show how far it got before suddenly failing
5029 $tinfo->{comment}.= "mysqltest failed but provided no output\n";
5030 my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
5031 if (-e $log_file_name) {
5032 $tinfo->{comment}.=
5033 "The result from queries just before the failure was:".
5034 "\n< snip >\n".
5035 mtr_lastlinesfromfile($log_file_name, $opt_tail_lines)."\n";
5036 }
5037 }
5038 }
5039 else
5040 {
5041 # The test tool report didn't exist, display an
5042 # error message
5043 $tinfo->{logfile}= "Could not open test tool report '$logfile'";
5044 }
5045 }
5046 }
5047
5048 after_failure($tinfo);
5049
5050 mtr_report_test($tinfo);
5051
5052 }
5053
5054
5055 sub run_system(@) {
5056 mtr_verbose("Running '$_[0]'");
5057 my $ret= system(@_) >> 8;
5058 return $ret;
5059 }
5060
5061
5062 sub mysqld_stop {
5063 my $mysqld= shift or die "usage: mysqld_stop(<mysqld>)";
5064
5065 my $args;
5066 mtr_init_args(\$args);
5067
5068 mtr_add_arg($args, "--no-defaults");
5069 mtr_add_arg($args, "--character-sets-dir=%s", $mysqld->value('character-sets-dir'));
5070 mtr_add_arg($args, "--user=%s", $opt_user);
5071 mtr_add_arg($args, "--password=");
5072 mtr_add_arg($args, "--port=%d", $mysqld->value('port'));
5073 mtr_add_arg($args, "--host=%s", $mysqld->value('#host'));
5074 mtr_add_arg($args, "--connect_timeout=20");
5075 mtr_add_arg($args, "--protocol=tcp");
5076 mtr_add_arg($args, "--disable-ssl-verify-server-cert");
5077
5078 mtr_add_arg($args, "shutdown");
5079
5080 My::SafeProcess->run
5081 (
5082 name => "mysqladmin shutdown ".$mysqld->name(),
5083 path => $exe_mysqladmin,
5084 args => \$args,
5085 error => "$opt_vardir/log/mysqladmin.err",
5086
5087 );
5088 }
5089
5090
5091 sub mysqld_arguments ($$$) {
5092 my $args= shift;
5093 my $mysqld= shift;
5094 my $extra_opts= shift;
5095
5096 my @defaults = grep(/^--defaults-file=/, @$extra_opts);
5097 if (@defaults > 0) {
5098 mtr_add_arg($args, pop(@defaults))
5099 }
5100 else {
5101 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
5102 }
5103
5104 # When mysqld is run by a root user(euid is 0), it will fail
5105 # to start unless we specify what user to run as, see BUG#30630
5106 my $euid= $>;
5107 if (!IS_WINDOWS and $euid == 0 and
5108 (grep(/^--user/, @$extra_opts)) == 0) {
5109 mtr_add_arg($args, "--user=root");
5110 }
5111
5112 if (!using_extern() and !$opt_user_args)
5113 {
5114 # Turn on logging to file
5115 mtr_add_arg($args, "%s--log-output=file");
5116 }
5117
5118 # Check if "extra_opt" contains --log-bin
5119 my $skip_binlog= not grep /^--(loose-)?log-bin/, @$extra_opts;
5120
5121 my $found_skip_core= 0;
5122 foreach my $arg ( @$extra_opts )
5123 {
5124 # Skip --defaults-file option since it's handled above.
5125 next if $arg =~ /^--defaults-file/;
5126
5127 # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
5128 if ($arg eq "--skip-core-file")
5129 {
5130 $found_skip_core= 1;
5131 }
5132 elsif ($skip_binlog and mtr_match_prefix($arg, "--binlog-format"))
5133 {
5134 ; # Dont add --binlog-format when running without binlog
5135 }
5136 elsif ($arg eq "--loose-skip-log-bin" and
5137 $mysqld->option("log-slave-updates"))
5138 {
5139 ; # Dont add --skip-log-bin when mysqld have --log-slave-updates in config
5140 }
5141 else
5142 {
5143 mtr_add_arg($args, "%s", $arg);
5144 }
5145 }
5146 $opt_skip_core = $found_skip_core;
5147 if ( !$found_skip_core && !$opt_user_args )
5148 {
5149 mtr_add_arg($args, "%s", "--core-file");
5150 }
5151
5152 # Enable the debug sync facility, set default wait timeout.
5153 # Facility stays disabled if timeout value is zero.
5154 mtr_add_arg($args, "--loose-debug-sync-timeout=%s",
5155 $opt_debug_sync_timeout) unless $opt_user_args;
5156
5157 return $args;
5158 }
5159
5160
5161
5162 sub mysqld_start ($$) {
5163 my $mysqld= shift;
5164 my $extra_opts= shift;
5165
5166 mtr_verbose(My::Options::toStr("mysqld_start", @$extra_opts));
5167
5168 my $exe= find_mysqld($mysqld->value('basedir'));
5169
5170 mtr_error("Internal error: mysqld should never be started for embedded")
5171 if $opt_embedded_server;
5172
5173 my $args;
5174 mtr_init_args(\$args);
5175
5176 mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
5177
5178 # Add any additional options from an in-test restart
5179 my @all_opts= @$extra_opts;
5180 if (exists $mysqld->{'restart_opts'}) {
5181 push (@all_opts, @{$mysqld->{'restart_opts'}});
5182 mtr_verbose(My::Options::toStr("mysqld_start restart",
5183 @{$mysqld->{'restart_opts'}}));
5184 }
5185 mysqld_arguments($args,$mysqld,\@all_opts);
5186
5187 if ( $opt_debug )
5188 {
5189 mtr_add_arg($args, "--debug-dbug=$debug_d:t:i:A,%s/log/%s.trace",
5190 $path_vardir_trace, $mysqld->name());
5191 }
5192
5193
5194 # Command line for mysqld started for *this particular test*.
5195 # Differs from "generic" MYSQLD_CMD by including all command line
5196 # options from *.opt and *.combination files.
5197 $ENV{'MYSQLD_LAST_CMD'}= "$exe @$args";
5198 my $oldexe= $exe;
5199
5200 My::Debugger::setup_args(\$args, \$exe, $mysqld->name());
5201 $ENV{'VALGRIND_TEST'}= $opt_valgrind = int(($exe || '') eq 'valgrind');
5202
5203 # Remove the old pidfile if any
5204 unlink($mysqld->value('pid-file'));
5205
5206 my $output= $mysqld->value('log-error');
5207
5208 if ( $opt_valgrind and $opt_debug )
5209 {
5210 # When both --valgrind and --debug is selected, send
5211 # all output to the trace file, making it possible to
5212 # see the exact location where valgrind complains
5213
5214 # Write a message about this to the normal log file
5215 my $trace_name= "$opt_vardir/log/".$mysqld->name().".trace";
5216 mtr_tofile($output,
5217 "NOTE: When running with --valgrind --debug the output from ",
5218 "mysqld (where the valgrind messages shows up) is stored ",
5219 "together with the trace file to make it ",
5220 "easier to find the exact position of valgrind errors.",
5221 "See trace file $trace_name.\n");
5222 $output= $trace_name;
5223
5224 }
5225 # Remember this log file for valgrind error report search
5226 $mysqld_logs{$output}= 1 if $opt_valgrind;
5227 # Remember data dir for gmon.out files if using gprof
5228 $gprof_dirs{$mysqld->value('datadir')}= 1 if $opt_gprof;
5229
5230 if ( defined $exe )
5231 {
5232 mtr_tofile($output, "\$ $exe @$args\n");
5233 pre_write_errorlog($output);
5234 $mysqld->{'proc'}= My::SafeProcess->new
5235 (
5236 name => $mysqld->name(),
5237 path => $exe,
5238 args => \$args,
5239 output => $output,
5240 error => $output,
5241 append => 1,
5242 verbose => $opt_verbose,
5243 nocore => $opt_skip_core,
5244 host => undef,
5245 shutdown => sub { mysqld_stop($mysqld) },
5246 envs => \@opt_mysqld_envs,
5247 );
5248 mtr_verbose("Started $mysqld->{proc}");
5249 }
5250
5251 $mysqld->{'started_opts'}= $extra_opts;
5252
5253 my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
5254 my $rc= $oldexe eq ($exe || '') ||
5255 sleep_until_file_created($mysqld->value('pid-file'), $expect_file,
5256 $opt_start_timeout, $mysqld->{'proc'}, $warn_seconds);
5257 if (!$rc)
5258 {
5259 # Report failure about the last test case before exit
5260 my $test_name= mtr_grab_file($path_current_testlog);
5261 $test_name =~ s/^CURRENT_TEST:\s//;
5262 my $tinfo = My::Test->new(name => $test_name);
5263 $tinfo->{result}= 'MTR_RES_FAILED';
5264 $tinfo->{failures}= 1;
5265 $tinfo->{logfile}=get_log_from_proc($mysqld->{'proc'}, $tinfo->{name});
5266 report_option('verbose', 1);
5267 mtr_report_test($tinfo);
5268 }
5269 return $rc;
5270 }
5271
5272
5273 sub stop_all_servers () {
5274 my $shutdown_timeout = $_[0] or 0;
5275
5276 mtr_verbose("Stopping all servers...");
5277
5278 # Kill all started servers
5279 My::SafeProcess::shutdown($shutdown_timeout,
5280 started(all_servers()));
5281
5282 # Remove pidfiles
5283 foreach my $server ( all_servers() )
5284 {
5285 my $pid_file= $server->if_exist('pid-file');
5286 unlink($pid_file) if defined $pid_file;
5287 }
5288
5289 # Mark servers as stopped
5290 map($_->{proc}= undef, all_servers());
5291
5292 }
5293
5294
5295 # Find out if server should be restarted for this test
5296 sub server_need_restart {
5297 my ($tinfo, $server)= @_;
5298
5299 if ( using_extern() )
5300 {
5301 mtr_verbose_restart($server, "no restart for --extern server");
5302 return 0;
5303 }
5304
5305 if ( $tinfo->{'force_restart'} ) {
5306 mtr_verbose_restart($server, "forced in .opt file");
5307 return 1;
5308 }
5309
5310 if ( $opt_force_restart ) {
5311 mtr_verbose_restart($server, "forced restart turned on");
5312 return 1;
5313 }
5314
5315 if ( $tinfo->{template_path} ne $current_config_name)
5316 {
5317 mtr_verbose_restart($server, "using different config file");
5318 return 1;
5319 }
5320
5321 if ( $tinfo->{'master_sh'} || $tinfo->{'slave_sh'} )
5322 {
5323 mtr_verbose_restart($server, "sh script to run");
5324 return 1;
5325 }
5326
5327 if ( ! started($server) )
5328 {
5329 mtr_verbose_restart($server, "not started");
5330 return 1;
5331 }
5332
5333 my $started_tinfo= $server->{'started_tinfo'};
5334 if ( defined $started_tinfo )
5335 {
5336
5337 # Check if timezone of test that server was started
5338 # with differs from timezone of next test
5339 if ( timezone($started_tinfo) ne timezone($tinfo) )
5340 {
5341 mtr_verbose_restart($server, "different timezone");
5342 return 1;
5343 }
5344 }
5345
5346 if ($server->name() =~ /^mysqld\./)
5347 {
5348
5349 # Check that running process was started with same options
5350 # as the current test requires
5351 my $extra_opts= get_extra_opts($server, $tinfo);
5352 my $started_opts= $server->{'started_opts'};
5353
5354 # Also, always restart if server had been restarted with additional
5355 # options within test.
5356 if (!My::Options::same($started_opts, $extra_opts) ||
5357 exists $server->{'restart_opts'})
5358 {
5359 delete $server->{'restart_opts'};
5360 my $use_dynamic_option_switch= 0;
5361 my $restart_opts = delete $server->{'restart_opts'} || [];
5362 if (!$use_dynamic_option_switch)
5363 {
5364 mtr_verbose_restart($server, "running with different options '" .
5365 join(" ", @{$extra_opts}) . "' != '" .
5366 join(" ", @{$started_opts}, @{$restart_opts}) . "'" );
5367 return 1;
5368 }
5369
5370 mtr_verbose(My::Options::toStr("started_opts", @$started_opts));
5371 mtr_verbose(My::Options::toStr("extra_opts", @$extra_opts));
5372
5373 # Get diff and check if dynamic switch is possible
5374 my @diff_opts= My::Options::diff($started_opts, $extra_opts);
5375 mtr_verbose(My::Options::toStr("diff_opts", @diff_opts));
5376
5377 my $query= My::Options::toSQL(@diff_opts);
5378 mtr_verbose("Attempting dynamic switch '$query'");
5379 if (run_query($tinfo, $server, $query)){
5380 mtr_verbose("Restart: running with different options '" .
5381 join(" ", @{$extra_opts}) . "' != '" .
5382 join(" ", @{$started_opts}) . "'" );
5383 return 1;
5384 }
5385
5386 # Remember the dynamically set options
5387 $server->{'started_opts'}= $extra_opts;
5388 }
5389 }
5390
5391 # Default, no restart
5392 return 0;
5393 }
5394
5395
5396 sub servers_need_restart($) {
5397 my ($tinfo)= @_;
5398 return grep { server_need_restart($tinfo, $_); } all_servers();
5399 }
5400
5401
5402
5403 ############################################
5404
5405 ############################################
5406
5407 #
5408 # Filter a list of servers and return the SafeProcess
5409 # for only those that are started or stopped
5410 #
5411 sub started { return grep(defined $_, map($_->{proc}, @_)); }
5412 sub stopped { return grep(!defined $_, map($_->{proc}, @_)); }
5413
5414
5415 sub get_extra_opts {
5416 # No extra options if --user-args
5417 return \@opt_extra_mysqld_opt if $opt_user_args;
5418
5419 my ($mysqld, $tinfo)= @_;
5420
5421 my $opts=
5422 $mysqld->option("#!use-slave-opt") ?
5423 $tinfo->{slave_opt} : $tinfo->{master_opt};
5424
5425 # Expand environment variables
5426 foreach my $opt ( @$opts )
5427 {
5428 no warnings 'uninitialized';
5429 $opt =~ s/\$\{(\w+)\}/$ENV{$1}/ge;
5430 $opt =~ s/\$(\w+)/$ENV{$1}/ge;
5431 }
5432 return $opts;
5433 }
5434
5435
5436 sub stop_servers($$) {
5437 my (@servers)= @_;
5438
5439 mtr_report("Stopping ", started(@servers));
5440
5441 My::SafeProcess::shutdown($opt_shutdown_timeout,
5442 started(@servers));
5443
5444 foreach my $server (@servers)
5445 {
5446 # Mark server as stopped
5447 $server->{proc}= undef;
5448
5449 # Forget history
5450 delete $server->{'started_tinfo'};
5451 delete $server->{'started_opts'};
5452 delete $server->{'started_cnf'};
5453 }
5454 }
5455
5456 #
5457 # run_query_output
5458 #
5459 # Run a query against a server using mysql client. The output of
5460 # the query will be written into outfile.
5461 #
5462 sub run_query_output {
5463 my ($mysqld, $query, $outfile)= @_;
5464 my $args;
5465
5466 mtr_init_args(\$args);
5467 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
5468 mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
5469 mtr_add_arg($args, "--silent");
5470 mtr_add_arg($args, "--execute=%s", $query);
5471
5472 my $res= My::SafeProcess->run
5473 (
5474 name => "run_query_output -> ".$mysqld->name(),
5475 path => $exe_mysql,
5476 args => \$args,
5477 output => $outfile,
5478 error => $outfile
5479 );
5480
5481 return $res
5482 }
5483
5484
5485 #
5486 # wsrep_wait_ready
5487 #
5488 # Wait until the server has been joined to the cluster and is
5489 # ready for operation.
5490 #
5491 # RETURN
5492 # 1 Server is ready
5493 # 0 Server didn't transition to ready state within start timeout
5494 #
5495 sub wait_wsrep_ready($$) {
5496 my ($tinfo, $mysqld)= @_;
5497
5498 my $sleeptime= 100; # Milliseconds
5499 my $loops= ($opt_start_timeout * 1000) / $sleeptime;
5500
5501 my $name= $mysqld->name();
5502 my $outfile= "$opt_vardir/tmp/$name.wsrep_ready";
5503 my $query= "SET SESSION wsrep_sync_wait = 0;
5504 SELECT VARIABLE_NAME, VARIABLE_VALUE
5505 FROM INFORMATION_SCHEMA.GLOBAL_STATUS
5506 WHERE VARIABLE_NAME = 'wsrep_ready'";
5507
5508 for (my $loop= 1; $loop <= $loops; $loop++)
5509 {
5510 # Careful... if MTR runs with option 'verbose' then the
5511 # file contains also SafeProcess verbose output
5512 if (run_query_output($mysqld, $query, $outfile) == 0 &&
5513 mtr_grab_file($outfile) =~ /WSREP_READY\s+ON/)
5514 {
5515 unlink($outfile);
5516 return 1;
5517 }
5518 mtr_milli_sleep($sleeptime);
5519 }
5520
5521 $tinfo->{logfile}= "WSREP did not transition to state READY";
5522 return 0;
5523 }
5524
5525 #
5526 # wsrep_is_bootstrap_server
5527 #
5528 # Check if the server is the first one to be started in the
5529 # cluster.
5530 #
5531 # RETURN
5532 # 1 The server is a bootstrap server
5533 # 0 The server is not a bootstrap server
5534 #
5535 sub wsrep_is_bootstrap_server($) {
5536 my $mysqld= shift;
5537
5538 my $cluster_address= $mysqld->if_exist('wsrep-cluster-address') ||
5539 $mysqld->if_exist('wsrep_cluster_address');
5540 if (defined $cluster_address)
5541 {
5542 return $cluster_address eq "gcomm://" || $cluster_address eq "'gcomm://'";
5543 }
5544 return 0;
5545 }
5546
5547 #
5548 # wsrep_on
5549 #
5550 # Check if wsrep has been enabled for a server.
5551 #
5552 # RETURN
5553 # 1 Wsrep has been enabled
5554 # 0 Wsrep is not enabled
5555 #
5556 sub wsrep_on($) {
5557 my $mysqld= shift;
5558 #check if wsrep_on= is set in configuration
5559 if ($mysqld->if_exist('wsrep-on')) {
5560 my $on= "".$mysqld->value('wsrep-on');
5561 if ($on eq "1" || $on eq "ON") {
5562 return 1;
5563 }
5564 }
5565 return 0;
5566 }
5567
5568
5569 #
5570 # start_servers
5571 #
5572 # Start servers not already started
5573 #
5574 # RETURN
5575 # 0 OK
5576 # 1 Start failed
5577 #
5578 sub start_servers($) {
5579 my ($tinfo)= @_;
5580
5581 for (all_servers()) {
5582 $_->{START}->($_, $tinfo) if $_->{START};
5583 }
5584
5585 for (all_servers()) {
5586 next unless $_->{WAIT} and started($_);
5587 if ($_->{WAIT}->($_, $tinfo)) {
5588 return 1;
5589 }
5590 }
5591 return 0;
5592 }
5593
5594
5595 #
5596 # Run include/check-testcase.inc
5597 # Before a testcase, run in record mode and save result file to var/tmp
5598 # After testcase, run and compare with the recorded file, they should be equal!
5599 #
5600 # RETURN VALUE
5601 # The newly started process
5602 #
5603 sub start_check_testcase ($$$) {
5604 my $tinfo= shift;
5605 my $mode= shift;
5606 my $mysqld= shift;
5607
5608 my $name= "check-".$mysqld->name();
5609 # Replace dots in name with underscore to avoid that mysqltest
5610 # misinterpret's what the filename extension is :(
5611 $name=~ s/\./_/g;
5612
5613 my $args;
5614 mtr_init_args(\$args);
5615
5616 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
5617 mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
5618 mtr_add_arg($args, "--result-file=%s", "$opt_vardir/tmp/$name.result");
5619 mtr_add_arg($args, "--test-file=%s", "include/check-testcase.inc");
5620 mtr_add_arg($args, "--verbose");
5621
5622 if ( $mode eq "before" )
5623 {
5624 mtr_add_arg($args, "--record");
5625 }
5626 my $errfile= "$opt_vardir/tmp/$name.err";
5627
5628 my $exe= $exe_mysqltest;
5629 My::Debugger::setup_client_args(\$args, \$exe);
5630 my $proc= My::SafeProcess->new
5631 (
5632 name => $name,
5633 path => $exe,
5634 error => $errfile,
5635 output => $errfile,
5636 args => \$args,
5637 user_data => $errfile,
5638 verbose => $opt_verbose,
5639 );
5640
5641 mtr_report("Started $proc");
5642 return $proc;
5643 }
5644
5645
5646 sub run_mysqltest ($) {
5647 my $proc= start_mysqltest(@_);
5648 $proc->wait();
5649 }
5650
5651
5652 sub start_mysqltest ($) {
5653 my ($tinfo)= @_;
5654 my $exe= $exe_mysqltest;
5655 my $args;
5656
5657 mark_time_used('admin');
5658
5659 mtr_init_args(\$args);
5660
5661 mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
5662 if ($opt_verbose > 1) {
5663 mtr_add_arg($args, "--verbose");
5664 } else {
5665 mtr_add_arg($args, "--silent");
5666 }
5667 mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
5668 mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
5669 mtr_add_arg($args, "--logdir=%s/log", $opt_vardir);
5670
5671 # Log line number and time for each line in .test file
5672 mtr_add_arg($args, "--mark-progress")
5673 if $opt_mark_progress;
5674
5675 mtr_add_arg($args, "--database=test");
5676
5677 if ( $opt_ps_protocol )
5678 {
5679 mtr_add_arg($args, "--ps-protocol");
5680 }
5681
5682 if ( $opt_sp_protocol )
5683 {
5684 mtr_add_arg($args, "--sp-protocol");
5685 }
5686
5687 if ( $opt_view_protocol )
5688 {
5689 mtr_add_arg($args, "--view-protocol");
5690 }
5691
5692 if ( $opt_cursor_protocol )
5693 {
5694 mtr_add_arg($args, "--cursor-protocol");
5695 }
5696
5697 if ( $opt_non_blocking_api )
5698 {
5699 mtr_add_arg($args, "--non-blocking-api");
5700 }
5701
5702 mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
5703
5704 if ( $opt_compress )
5705 {
5706 mtr_add_arg($args, "--compress");
5707 }
5708
5709 if ( $opt_sleep )
5710 {
5711 mtr_add_arg($args, "--sleep=%d", $opt_sleep);
5712 }
5713
5714 if ( $opt_ssl )
5715 {
5716 # Turn on SSL for _all_ test cases if option --ssl was used
5717 mtr_add_arg($args, "--ssl");
5718 }
5719
5720 if ( $opt_max_connections ) {
5721 mtr_add_arg($args, "--max-connections=%d", $opt_max_connections);
5722 }
5723
5724 if ( $opt_embedded_server )
5725 {
5726
5727 # Get the args needed for the embedded server
5728 # and append them to args prefixed
5729 # with --sever-arg=
5730
5731 my $mysqld= $config->group('embedded')
5732 or mtr_error("Could not get [embedded] section");
5733
5734 my $mysqld_args;
5735 mtr_init_args(\$mysqld_args);
5736 my $extra_opts= get_extra_opts($mysqld, $tinfo);
5737 mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
5738 mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
5739 }
5740
5741 # ----------------------------------------------------------------------
5742 # export MYSQL_TEST variable containing <path>/mysqltest <args>
5743 # ----------------------------------------------------------------------
5744 $ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
5745
5746 if ($opt_force > 1)
5747 {
5748 mtr_add_arg($args, "--continue-on-error");
5749 }
5750
5751 my $suite = $tinfo->{suite};
5752 if ($suite->{parent}) {
5753 mtr_add_arg($args, "--overlay-dir=%s/", $suite->{dir});
5754 mtr_add_arg($args, "--suite-dir=%s/", $suite->{parent}->{dir});
5755 } else {
5756 mtr_add_arg($args, "--suite-dir=%s/", $suite->{dir});
5757 }
5758
5759 mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'});
5760
5761 # Number of lines of resut to include in failure report
5762 mtr_add_arg($args, "--tail-lines=%d", $opt_tail_lines);
5763
5764 if ( defined $tinfo->{'result_file'} ) {
5765 mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
5766 }
5767
5768 mtr_add_arg($args, "--wait-for-pos-timeout=%d", $opt_debug_sync_timeout);
5769
5770 client_debug_arg($args, "mysqltest");
5771
5772 if ( $opt_record )
5773 {
5774 mtr_add_arg($args, "--record");
5775
5776 # When recording to a non existing result file
5777 # the name of that file is in "record_file"
5778 if ( defined $tinfo->{'record_file'} ) {
5779 mtr_add_arg($args, "--result-file=%s", $tinfo->{record_file});
5780 }
5781 }
5782
5783 My::Debugger::setup_client_args(\$args, \$exe);
5784
5785 my $proc= My::SafeProcess->new
5786 (
5787 name => "mysqltest",
5788 path => $exe,
5789 args => \$args,
5790 append => 1,
5791 error => $path_current_testlog,
5792 verbose => $opt_verbose,
5793 open_files_limit => $opt_open_files_limit,
5794 );
5795 mtr_verbose("Started $proc");
5796 return $proc;
5797 }
5798
5799 #
5800 # Search server logs for valgrind reports printed at mysqld termination
5801 #
5802 sub valgrind_exit_reports() {
5803 my $found_err= 0;
5804
5805 foreach my $log_file (keys %mysqld_logs)
5806 {
5807 my @culprits= ();
5808 my $valgrind_rep= "";
5809 my $found_report= 0;
5810 my $err_in_report= 0;
5811
5812 my $LOGF = IO::File->new($log_file)
5813 or mtr_error("Could not open file '$log_file' for reading: $!");
5814
5815 while ( my $line = <$LOGF> )
5816 {
5817 if ($line =~ /^CURRENT_TEST: (.+)$/)
5818 {
5819 my $testname= $1;
5820 # If we have a report, report it if needed and start new list of tests
5821 if ($found_report)
5822 {
5823 if ($err_in_report)
5824 {
5825 mtr_print ("Valgrind report from $log_file after tests:\n",
5826 @culprits);
5827 mtr_print_line();
5828 print ("$valgrind_rep\n");
5829 $found_err= 1;
5830 $err_in_report= 0;
5831 }
5832 # Make ready to collect new report
5833 @culprits= ();
5834 $found_report= 0;
5835 $valgrind_rep= "";
5836 }
5837 push (@culprits, $testname);
5838 next;
5839 }
5840 # This line marks the start of a valgrind report
5841 $found_report= 1 if $line =~ /^==\d+== .* SUMMARY:/;
5842
5843 if ($found_report) {
5844 $line=~ s/^==\d+== //;
5845 $valgrind_rep .= $line;
5846 $err_in_report= 1 if $line =~ /ERROR SUMMARY: [1-9]/;
5847 $err_in_report= 1 if $line =~ /definitely lost: [1-9]/;
5848 $err_in_report= 1 if $line =~ /possibly lost: [1-9]/;
5849 }
5850 }
5851
5852 $LOGF= undef;
5853
5854 if ($err_in_report) {
5855 mtr_print ("Valgrind report from $log_file after tests:\n", @culprits);
5856 mtr_print_line();
5857 print ("$valgrind_rep\n");
5858 $found_err= 1;
5859 }
5860 }
5861
5862 return $found_err;
5863 }
5864
5865 #
5866 # Usage
5867 #
5868 sub usage ($) {
5869 my ($message)= @_;
5870
5871 if ( $message )
5872 {
5873 print STDERR "$message\n";
5874 print STDERR "For full list of options, use $0 --help\n";
5875 exit(1);
5876 }
5877
5878 local $"= ','; # for @DEFAULT_SUITES below
5879
5880 print <<HERE . My::Debugger::help() . My::CoreDump::help() . <<HERE;
5881
5882 $0 [ OPTIONS ] [ TESTCASE ]
5883
5884 Where test case can be specified as:
5885
5886 testcase[.test] Runs the test case named 'testcase' from all suits
5887 path-to-testcase
5888 [suite.]testcase[,combination]
5889
5890 Examples:
5891
5892 alias
5893 main.alias 'main' is the name of the main test suite
5894 rpl.rpl_invoked_features,mix,innodb
5895 suite/rpl/t/rpl.rpl_invoked_features
5896
5897 Options to control what engine/variation to run:
5898
5899 embedded-server Use the embedded server, i.e. no mysqld daemons
5900 ps-protocol Use the binary protocol between client and server
5901 cursor-protocol Use the cursor protocol between client and server
5902 (implies --ps-protocol)
5903 view-protocol Create a view to execute all non updating queries
5904 sp-protocol Create a stored procedure to execute all queries
5905 non-blocking-api Use the non-blocking client API
5906 compress Use the compressed protocol between client and server
5907 ssl Use ssl protocol between client and server
5908 skip-ssl Don't start server with support for ssl connections
5909 vs-config Visual Studio configuration used to create executables
5910 (default: MTR_VS_CONFIG environment variable)
5911 parallel=# How many parallel test should be run
5912 defaults-file=<config template> Use fixed config template for all
5913 tests
5914 defaults-extra-file=<config template> Extra config template to add to
5915 all generated configs
5916 combination=<opt> Use at least twice to run tests with specified
5917 options to mysqld
5918 dry-run Don't run any tests, print the list of tests
5919 that were selected for execution
5920
5921 Options to control directories to use
5922 tmpdir=DIR The directory where temporary files are stored
5923 (default: ./var/tmp).
5924 vardir=DIR The directory where files generated from the test run
5925 is stored (default: ./var). Specifying a ramdisk or
5926 tmpfs will speed up tests.
5927 mem[=DIR] Run testsuite in "memory" using tmpfs or ramdisk
5928 Attempts to use DIR first if specified else
5929 uses a builtin list of standard locations
5930 for tmpfs (/run/shm, /dev/shm, /tmp)
5931 The option can also be set using environment
5932 variable MTR_MEM=[DIR]
5933 clean-vardir Clean vardir if tests were successful and if
5934 running in "memory". Otherwise this option is ignored
5935 client-bindir=PATH Path to the directory where client binaries are located
5936 client-libdir=PATH Path to the directory where client libraries are located
5937
5938
5939 Options to control what test suites or cases to run
5940
5941 force Continue after a failure. When specified once, a
5942 failure in a test file will abort this test file, and
5943 the execution will continue from the next test file.
5944 When specified twice, execution will continue executing
5945 the failed test file from the next command.
5946 skip-not-found It is not an error if a test was not found in a
5947 specified test suite. Test will be marked as skipped.
5948 do-test=PREFIX or REGEX
5949 Run test cases which name are prefixed with PREFIX
5950 or fulfills REGEX
5951 skip-test=PREFIX or REGEX
5952 Skip test cases which name are prefixed with PREFIX
5953 or fulfills REGEX
5954 start-from=PREFIX Run test cases starting test prefixed with PREFIX where
5955 prefix may be suite.testname or just testname
5956 suite[s]=NAME1,..,NAMEN
5957 Collect tests in suites from the comma separated
5958 list of suite names.
5959 The default is: "@DEFAULT_SUITES"
5960 skip-rpl Skip the replication test cases.
5961 big-test Also run tests marked as "big". Repeat this option
5962 twice to run only "big" tests.
5963 staging-run Run a limited number of tests (no slow tests). Used
5964 for running staging trees with valgrind.
5965 enable-disabled Run also tests marked as disabled
5966 print-testcases Don't run the tests but print details about all the
5967 selected tests, in the order they would be run.
5968 skip-test-list=FILE Skip the tests listed in FILE. Each line in the file
5969 is an entry and should be formatted as:
5970 <TESTNAME> : <COMMENT>
5971 force-restart Always restart servers between tests. This makes it
5972 easier to see from which test warnings may come from.
5973
5974 Options that specify ports
5975
5976 mtr-port-base=# Base for port numbers, ports from this number to
5977 port-base=# number+9 are reserved. Should be divisible by 10;
5978 if not it will be rounded down. May be set with
5979 environment variable MTR_PORT_BASE. If this value is
5980 set and is not "auto", it overrides build-thread.
5981 mtr-build-thread=# Specify unique number to calculate port number(s) from.
5982 build-thread=# Can be set in environment variable MTR_BUILD_THREAD.
5983 Set MTR_BUILD_THREAD="auto" to automatically aquire
5984 a build thread id that is unique to current host
5985 port-group-size=N Reserve groups of TCP ports of size N for each MTR thread
5986
5987
5988 Options for test case authoring
5989
5990 record TESTNAME (Re)genereate the result file for TESTNAME
5991 check-testcases Check testcases for sideeffects
5992 mark-progress Log line number and elapsed time to <testname>.progress
5993
5994 Options that pass on options (these may be repeated)
5995
5996 mariadbd=ARGS Specify additional arguments to "mariadbd"
5997 mysqld Alias for mariadbd.
5998 mariadbd-env=VAR=VAL Specify additional environment settings for "mariadbd"
5999 mysqld-env Alias for mariadbd-env.
6000
6001 Options to run test on running server
6002
6003 extern option=value Run only the tests against an already started server
6004 the options to use for connection to the extern server
6005 must be specified using name-value pair notation
6006 For example:
6007 ./$0 --extern socket=/tmp/mysqld.sock
6008
6009 Options for debugging the product
6010
6011 debug Dump trace output for all servers and client programs
6012 debug-common Same as debug, but sets 'd' debug flags to
6013 "query,info,error,enter,exit"
6014 debug-server Use debug version of server, but without turning on
6015 tracing
6016 max-save-core Limit the number of core files saved (to avoid filling
6017 up disks for heavily crashing server). Defaults to
6018 $opt_max_save_core. Set its default with
6019 MTR_MAX_SAVE_CORE
6020 max-save-datadir Limit the number of datadir saved (to avoid filling
6021 up disks for heavily crashing server). Defaults to
6022 $opt_max_save_datadir. Set its default with
6023 MTR_MAX_SAVE_DATADIR
6024 max-test-fail Limit the number of test failures before aborting
6025 the current test run. Defaults to
6026 $opt_max_test_fail, set to 0 for no limit. Set
6027 it's default with MTR_MAX_TEST_FAIL
6028 core-in-failure Generate a core even if run server is run with valgrind
6029 HERE
6030
6031 Misc options
6032 user=USER User for connecting to mysqld(default: $opt_user)
6033 comment=STR Write STR to the output
6034 timer Show test case execution time.
6035 verbose More verbose output(use multiple times for even more)
6036 verbose-restart Write when and why servers are restarted
6037 start Only initialize and start the servers, using the
6038 startup settings for the first specified test case
6039 Example:
6040 $0 --start alias &
6041 start-and-exit Same as --start, but mysql-test-run terminates and
6042 leaves just the server running
6043 start-dirty Only start the servers (without initialization) for
6044 the first specified test case
6045 user-args In combination with start* and no test name, drops
6046 arguments to mariadbd except those specified with
6047 --mariadbd (if any)
6048 wait-all If --start or --start-dirty option is used, wait for all
6049 servers to exit before finishing the process
6050 fast Run as fast as possible, don't wait for servers
6051 to shutdown etc.
6052 force-restart Always restart servers between tests
6053 parallel=N Run tests in N parallel threads (default 1)
6054 Use parallel=auto for auto-setting of N
6055 repeat=N Run each test N number of times
6056 retry=N Retry tests that fail up to N times (default $opt_retry).
6057 Retries are also limited by the maximum number of
6058 failures before stopping, set with the --retry-failure
6059 option
6060 retry-failure=N When using the --retry option to retry failed tests,
6061 stop when N failures have occurred (default $opt_retry_failure)
6062 reorder Reorder tests to get fewer server restarts
6063 help Get this help text
6064
6065 testcase-timeout=MINUTES Max test case run time (default $opt_testcase_timeout)
6066 suite-timeout=MINUTES Max test suite run time (default $opt_suite_timeout)
6067 shutdown-timeout=SECONDS Max number of seconds to wait for server shutdown
6068 before killing servers (default $opt_shutdown_timeout)
6069 warnings Scan the log files for warnings. Use --nowarnings
6070 to turn off.
6071
6072 stop-file=file (also MTR_STOP_FILE environment variable) if this
6073 file detected mysql test will not start new tests
6074 until the file will be removed.
6075 stop-keep-alive=sec (also MTR_STOP_KEEP_ALIVE environment variable)
6076 works with stop-file, print messages every sec
6077 seconds when mysql test is waiting to removing
6078 the file (for buildbot)
6079
6080 sleep=SECONDS Passed to mysqltest, will be used as fixed sleep time
6081 debug-sync-timeout=NUM Set default timeout for WAIT_FOR debug sync
6082 actions. Disable facility with NUM=0.
6083 gcov Collect coverage information after the test.
6084 The result is a gcov file per source and header file.
6085 gprof Collect profiling information using gprof.
6086 experimental=<file> Refer to list of tests considered experimental;
6087 failures will be marked exp-fail instead of fail.
6088 timestamp Print timestamp before each test report line
6089 timediff With --timestamp, also print time passed since
6090 *previous* test started
6091 max-connections=N Max number of open connection to server in mysqltest
6092 open-files-limit=N Max number of open files allowed for any of the children
6093 of my_safe_process. Default is 1024.
6094 report-times Report how much time has been spent on different
6095 phases of test execution.
6096 stress=ARGS Run stress test, providing options to
6097 mysql-stress-test.pl. Options are separated by comma.
6098 xml-report=<file> Output xml file of the results.
6099 tail-lines=N Number of lines of the result to include in a failure
6100 report.
6101
6102 Some options that control enabling a feature for normal test runs,
6103 can be turned off by prepending 'no' to the option, e.g. --notimer.
6104 This applies to reorder, timer, check-testcases and warnings.
6105
6106 HERE
6107 exit(1);
6108
6109 }
6110
6111 sub list_options ($) {
6112 my $hash= shift;
6113
6114 for (keys %$hash) {
6115 s/([:=].*|[+!])$//;
6116 s/\|/\n--/g;
6117 print "--$_\n";
6118 }
6119
6120 exit(1);
6121 }