You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4756 lines
126 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
20 years ago
18 years ago
18 years ago
18 years ago
18 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
18 years ago
18 years ago
18 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
18 years ago
18 years ago
18 years ago
18 years ago
20 years ago
20 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
18 years ago
  1. #!/usr/bin/perl
  2. # -*- cperl -*-
  3. #
  4. ##############################################################################
  5. #
  6. # mysql-test-run.pl
  7. #
  8. # Tool used for executing a suite of .test files
  9. #
  10. # See the "MySQL Test framework manual" for more information
  11. # http://dev.mysql.com/doc/mysqltest/en/index.html
  12. #
  13. #
  14. ##############################################################################
  15. use strict;
  16. use warnings;
  17. BEGIN {
  18. # Check that mysql-test-run.pl is started from mysql-test/
  19. unless ( -f "mysql-test-run.pl" )
  20. {
  21. print "**** ERROR **** ",
  22. "You must start mysql-test-run from the mysql-test/ directory\n";
  23. exit(1);
  24. }
  25. # Check that lib exist
  26. unless ( -d "lib/" )
  27. {
  28. print "**** ERROR **** ",
  29. "Could not find the lib/ directory \n";
  30. exit(1);
  31. }
  32. }
  33. use lib "lib";
  34. use Cwd;
  35. use Getopt::Long;
  36. use My::File::Path; # Patched version of File::Path
  37. use File::Basename;
  38. use File::Copy;
  39. use File::Find;
  40. use File::Temp qw / tempdir /;
  41. use File::Spec::Functions qw / splitdir /;
  42. use My::Platform;
  43. use My::SafeProcess;
  44. use My::ConfigFactory;
  45. use My::Options;
  46. use My::Find;
  47. use My::SysInfo;
  48. use My::CoreDump;
  49. use mtr_cases;
  50. use mtr_report;
  51. use mtr_match;
  52. use mtr_unique;
  53. use IO::Socket::INET;
  54. use IO::Select;
  55. require "lib/mtr_process.pl";
  56. require "lib/mtr_io.pl";
  57. require "lib/mtr_gcov.pl";
  58. require "lib/mtr_misc.pl";
  59. $SIG{INT}= sub { mtr_error("Got ^C signal"); };
  60. our $mysql_version_id;
  61. our $glob_mysql_test_dir;
  62. our $basedir;
  63. our $path_charsetsdir;
  64. our $path_client_bindir;
  65. our $path_client_libdir;
  66. our $path_language;
  67. our $path_current_testlog;
  68. our $path_testlog;
  69. our $default_vardir;
  70. our $opt_vardir; # Path to use for var/ dir
  71. my $path_vardir_trace; # unix formatted opt_vardir for trace files
  72. my $opt_tmpdir; # Path to use for tmp/ dir
  73. my $path_config_file; # The generated config file, var/my.cnf
  74. # Visual Studio produces executables in different sub-directories based on the
  75. # configuration used to build them. To make life easier, an environment
  76. # variable or command-line option may be specified to control which set of
  77. # executables will be used by the test suite.
  78. our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
  79. my $DEFAULT_SUITES= "main,binlog,federated,rpl,rpl_ndb,ndb";
  80. my $opt_suites;
  81. our $opt_verbose= 0; # Verbose output, enable with --verbose
  82. our $exe_mysql;
  83. our $exe_mysqladmin;
  84. our $exe_mysqltest;
  85. our $exe_libtool;
  86. our $opt_big_test= 0;
  87. our @opt_combinations;
  88. our @opt_extra_mysqld_opt;
  89. our $opt_compress;
  90. our $opt_ssl;
  91. our $opt_skip_ssl;
  92. our $opt_ssl_supported;
  93. our $opt_ps_protocol;
  94. our $opt_sp_protocol;
  95. our $opt_cursor_protocol;
  96. our $opt_view_protocol;
  97. our $opt_debug;
  98. our @opt_cases; # The test cases names in argv
  99. our $opt_embedded_server;
  100. # Options used when connecting to an already running server
  101. my %opts_extern;
  102. sub using_extern { return (keys %opts_extern > 0);};
  103. our $opt_fast= 0;
  104. our $opt_force;
  105. our $opt_mem= $ENV{'MTR_MEM'};
  106. our $opt_gcov;
  107. our $opt_gcov_err;
  108. our $opt_gcov_msg;
  109. our $glob_debugger= 0;
  110. our $opt_gdb;
  111. our $opt_client_gdb;
  112. our $opt_ddd;
  113. our $opt_client_ddd;
  114. our $opt_manual_gdb;
  115. our $opt_manual_ddd;
  116. our $opt_manual_debug;
  117. our $opt_debugger;
  118. our $opt_client_debugger;
  119. my $config; # The currently running config
  120. my $current_config_name; # The currently running config file template
  121. my $baseport;
  122. my $opt_build_thread= $ENV{'MTR_BUILD_THREAD'} || "auto";
  123. my $opt_record;
  124. my $opt_report_features;
  125. our $opt_check_testcases= 1;
  126. my $opt_mark_progress;
  127. my $opt_sleep;
  128. my $opt_testcase_timeout= 15; # minutes
  129. my $opt_suite_timeout = 300; # minutes
  130. my $opt_shutdown_timeout= 10; # seconds
  131. my $opt_start_timeout = 180; # seconds
  132. my $opt_start;
  133. my $opt_start_dirty;
  134. my $opt_repeat= 1;
  135. my $opt_retry= 3;
  136. my $opt_retry_failure= 2;
  137. my $opt_strace_client;
  138. our $opt_user = "root";
  139. my $opt_valgrind= 0;
  140. my $opt_valgrind_mysqld= 0;
  141. my $opt_valgrind_mysqltest= 0;
  142. my @default_valgrind_args= ("--show-reachable=yes");
  143. my @valgrind_args;
  144. my $opt_valgrind_path;
  145. my $opt_callgrind;
  146. our $opt_warnings= 1;
  147. our $opt_skip_ndbcluster= 0;
  148. our $opt_skip_ndbcluster_slave= 0;
  149. our $opt_with_ndbcluster;
  150. my $exe_ndbd;
  151. my $exe_ndb_mgmd;
  152. my $exe_ndb_waiter;
  153. our $path_sql_dir;
  154. our $debug_compiled_binaries;
  155. our %mysqld_variables;
  156. my $source_dist= 0;
  157. my $opt_max_save_core= $ENV{MTR_MAX_SAVE_CORE} || 5;
  158. my $opt_max_save_datadir= $ENV{MTR_MAX_SAVE_DATADIR} || 20;
  159. my $opt_max_test_fail= $ENV{MTR_MAX_TEST_FAIL} || 10;
  160. select(STDOUT);
  161. $| = 1; # Automatically flush STDOUT
  162. main();
  163. sub main {
  164. # Default, verbosity on
  165. report_option('verbose', 0);
  166. # This is needed for test log evaluation in "gen-build-status-page"
  167. # in all cases where the calling tool does not log the commands
  168. # directly before it executes them, like "make test-force-pl" in RPM builds.
  169. mtr_report("Logging: $0 ", join(" ", @ARGV));
  170. my $opt_parallel= $ENV{MTR_PARALLEL};
  171. Getopt::Long::Configure("pass_through");
  172. GetOptions('parallel=i' => \$opt_parallel) or usage(0, "Can't read options");
  173. command_line_setup();
  174. if ( $opt_gcov ) {
  175. gcov_prepare($basedir);
  176. }
  177. if (!$opt_suites) {
  178. $opt_suites= $DEFAULT_SUITES;
  179. # Check for any extra suites to enable based on the path name
  180. my %extra_suites=
  181. (
  182. "mysql-5.1-new-ndb" => "ndb_team",
  183. "mysql-5.1-new-ndb-merge" => "ndb_team",
  184. "mysql-5.1-telco-6.2" => "ndb_team",
  185. "mysql-5.1-telco-6.2-merge" => "ndb_team",
  186. "mysql-5.1-telco-6.3" => "ndb_team",
  187. "mysql-6.0-ndb" => "ndb_team",
  188. );
  189. foreach my $dir ( reverse splitdir($basedir) ) {
  190. my $extra_suite= $extra_suites{$dir};
  191. if (defined $extra_suite) {
  192. mtr_report("Found extra suite: $extra_suite");
  193. $opt_suites= "$extra_suite,$opt_suites";
  194. last;
  195. }
  196. }
  197. }
  198. mtr_report("Collecting tests...");
  199. my $tests= collect_test_cases($opt_suites, \@opt_cases);
  200. if ( $opt_report_features ) {
  201. # Put "report features" as the first test to run
  202. my $tinfo = My::Test->new
  203. (
  204. name => 'report_features',
  205. # No result_file => Prints result
  206. path => 'include/report-features.test'.
  207. template_path => "include/default_my.cnf",
  208. master_opt => [],
  209. slave_opt => [],
  210. );
  211. unshift(@$tests, $tinfo);
  212. }
  213. print "vardir: $opt_vardir\n";
  214. initialize_servers();
  215. #######################################################################
  216. my $num_tests= @$tests;
  217. if ( not defined $opt_parallel ) {
  218. # Try to find a suitable value for number of workers
  219. my $sys_info= My::SysInfo->new();
  220. $opt_parallel= $sys_info->num_cpus();
  221. for my $limit (2000, 1500, 1000, 500){
  222. $opt_parallel-- if ($sys_info->min_bogomips() < $limit);
  223. }
  224. $opt_parallel= $num_tests if ($opt_parallel > $num_tests);
  225. $opt_parallel= 1 if ($opt_parallel < 1);
  226. mtr_report("Using parallel: $opt_parallel");
  227. }
  228. # Create server socket on any free port
  229. my $server = new IO::Socket::INET
  230. (
  231. LocalAddr => 'localhost',
  232. Proto => 'tcp',
  233. Listen => $opt_parallel,
  234. );
  235. mtr_error("Could not create testcase server port: $!") unless $server;
  236. my $server_port = $server->sockport();
  237. mtr_report("Using server port $server_port");
  238. # Create child processes
  239. my %children;
  240. for my $child_num (1..$opt_parallel){
  241. my $child_pid= My::SafeProcess::Base::_safe_fork();
  242. if ($child_pid == 0){
  243. $server= undef; # Close the server port in child
  244. $tests= {}; # Don't need the tests list in child
  245. # Use subdir of var and tmp unless only one worker
  246. if ($opt_parallel > 1) {
  247. set_vardir("$opt_vardir/$child_num");
  248. $opt_tmpdir= "$opt_tmpdir/$child_num";
  249. }
  250. run_worker($server_port, $child_num);
  251. exit(1);
  252. }
  253. $children{$child_pid}= 1;
  254. }
  255. #######################################################################
  256. mtr_report();
  257. mtr_print_thick_line();
  258. mtr_print_header();
  259. my $completed= run_test_server($server, $tests, $opt_parallel);
  260. # Send Ctrl-C to any children still running
  261. kill("INT", keys(%children));
  262. # Wait for childs to exit
  263. foreach my $pid (keys %children)
  264. {
  265. my $ret_pid= waitpid($pid, 0);
  266. if ($ret_pid != $pid){
  267. mtr_report("Unknown process $ret_pid exited");
  268. }
  269. else {
  270. delete $children{$ret_pid};
  271. }
  272. }
  273. if ( not defined @$completed ) {
  274. mtr_error("Test suite aborted");
  275. }
  276. if ( @$completed != $num_tests){
  277. if ($opt_force){
  278. # All test should have been run, print any that are still in $tests
  279. foreach my $test ( @$tests ){
  280. $test->print_test();
  281. }
  282. }
  283. # Not all tests completed, failure
  284. mtr_report();
  285. mtr_report("Only ", int(@$completed), " of $num_tests completed.");
  286. mtr_error("Not all tests completed");
  287. }
  288. mtr_print_line();
  289. if ( $opt_gcov ) {
  290. gcov_collect($basedir, $opt_gcov,
  291. $opt_gcov_msg, $opt_gcov_err);
  292. }
  293. mtr_report_stats($completed);
  294. exit(0);
  295. }
  296. sub run_test_server ($$$) {
  297. my ($server, $tests, $childs) = @_;
  298. my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
  299. my $num_saved_datadir= 0; # Number of datadirs saved in vardir/log/ so far.
  300. my $num_failed_test= 0; # Number of tests failed so far
  301. # Scheduler variables
  302. my $max_ndb= $childs / 2;
  303. $max_ndb = 4 if $max_ndb > 4;
  304. $max_ndb = 1 if $max_ndb < 1;
  305. my $num_ndb_tests= 0;
  306. my $completed= [];
  307. my %running;
  308. my $result;
  309. my $suite_timeout_proc= My::SafeProcess->timer($opt_suite_timeout * 60);
  310. my $s= IO::Select->new();
  311. $s->add($server);
  312. while (1) {
  313. my @ready = $s->can_read(1); # Wake up once every second
  314. foreach my $sock (@ready) {
  315. if ($sock == $server) {
  316. # New client connected
  317. my $child= $sock->accept();
  318. mtr_verbose("Client connected");
  319. $s->add($child);
  320. print $child "HELLO\n";
  321. }
  322. else {
  323. my $line= <$sock>;
  324. if (!defined $line) {
  325. # Client disconnected
  326. mtr_verbose("Child closed socket");
  327. $s->remove($sock);
  328. if (--$childs == 0){
  329. $suite_timeout_proc->kill();
  330. return $completed;
  331. }
  332. next;
  333. }
  334. chomp($line);
  335. if ($line eq 'TESTRESULT'){
  336. $result= My::Test::read_test($sock);
  337. # $result->print_test();
  338. # Report test status
  339. mtr_report_test($result);
  340. if ( $result->is_failed() ) {
  341. # Save the workers "savedir" in var/log
  342. my $worker_savedir= $result->{savedir};
  343. my $worker_savename= basename($worker_savedir);
  344. my $savedir= "$opt_vardir/log/$worker_savename";
  345. if ($opt_max_save_datadir > 0 &&
  346. $num_saved_datadir >= $opt_max_save_datadir)
  347. {
  348. mtr_report(" - skipping '$worker_savedir/'");
  349. rmtree($worker_savedir);
  350. }
  351. else {
  352. mtr_report(" - saving '$worker_savedir/' to '$savedir/'");
  353. rename($worker_savedir, $savedir);
  354. if ($opt_max_save_core > 0) {
  355. # Limit number of core files saved
  356. find({ no_chdir => 1,
  357. wanted => sub {
  358. my $core_file= $File::Find::name;
  359. my $core_name= basename($core_file);
  360. if ($core_name =~ "core*"){
  361. mtr_report(" - found '$core_name'",
  362. "($num_saved_cores/$opt_max_save_core)");
  363. My::CoreDump->show($core_file);
  364. if ($num_saved_cores >= $opt_max_save_core) {
  365. mtr_report(" - deleting it, already saved",
  366. "$opt_max_save_core");
  367. unlink("$core_file");
  368. }
  369. ++$num_saved_cores;
  370. }
  371. }
  372. },
  373. $savedir);
  374. }
  375. }
  376. $num_saved_datadir++;
  377. if ( !$opt_force ) {
  378. # Test has failed, force is off
  379. $suite_timeout_proc->kill();
  380. push(@$completed, $result);
  381. return $completed;
  382. }
  383. elsif ($opt_max_test_fail > 0 and
  384. $num_failed_test >= $opt_max_test_fail) {
  385. $suite_timeout_proc->kill();
  386. mtr_report("Too many tests($num_failed_test) failed!",
  387. "Terminating...");
  388. return undef;
  389. }
  390. $num_failed_test++;
  391. }
  392. # Retry test run after test failure
  393. my $retries= $result->{retries} || 2;
  394. my $test_has_failed= $result->{failures} || 0;
  395. if ($test_has_failed and $retries <= $opt_retry){
  396. # Test should be run one more time unless it has failed
  397. # too many times already
  398. my $failures= $result->{failures};
  399. if ($opt_retry > 1 and $failures >= $opt_retry_failure){
  400. mtr_report("\nTest has failed $failures times,",
  401. "no more retries!\n");
  402. }
  403. else {
  404. mtr_report("\nRetrying test, attempt($retries/$opt_retry)...\n");
  405. delete($result->{result});
  406. $result->{retries}= $retries+1;
  407. $result->write_test($sock, 'TESTCASE');
  408. next;
  409. }
  410. }
  411. # Repeat test $opt_repeat number of times
  412. my $repeat= $result->{repeat} || 1;
  413. if ($repeat < $opt_repeat)
  414. {
  415. $result->{retries}= 0;
  416. $result->{failures}= 0;
  417. delete($result->{result});
  418. $result->{repeat}= $repeat+1;
  419. $result->write_test($sock, 'TESTCASE');
  420. next;
  421. }
  422. # Remove from list of running
  423. mtr_error("'", $result->{name},"' is not known to be running")
  424. unless delete $running{$result->key()};
  425. # Update scheduler variables
  426. $num_ndb_tests-- if ($result->{ndb_test});
  427. # Save result in completed list
  428. push(@$completed, $result);
  429. }
  430. elsif ($line eq 'START'){
  431. ; # Send first test
  432. }
  433. else {
  434. mtr_error("Unknown response: '$line' from client");
  435. }
  436. # Find next test to schedule
  437. # - Try to use same configuration as worker used last time
  438. # - Limit number of parallel ndb tests
  439. my $next;
  440. my $second_best;
  441. for(my $i= 0; $i <= $#$tests; $i++)
  442. {
  443. my $t= $tests->[$i];
  444. if (run_testcase_check_skip_test($t)){
  445. # Move the test to completed list
  446. #mtr_report("skip - Moving test $i to completed");
  447. push(@$completed, splice(@$tests, $i, 1));
  448. next;
  449. }
  450. # Limit number of parallell NDB tests
  451. if ($t->{ndb_test} and $num_ndb_tests >= $max_ndb){
  452. #mtr_report("Skipping, num ndb is already at max, $num_ndb_tests");
  453. next;
  454. }
  455. # Prefer same configuration
  456. if (defined $result and
  457. $result->{template_path} eq $t->{template_path})
  458. {
  459. #mtr_report("Test uses same config => good match");
  460. # Test uses same config => good match
  461. $next= splice(@$tests, $i, 1);
  462. last;
  463. }
  464. # Second best choice is the first that does not fulfill
  465. # any of the above conditions
  466. if (!defined $second_best){
  467. #mtr_report("Setting second_best to $i");
  468. $second_best= $i;
  469. }
  470. }
  471. # Use second best choice if no other test has been found
  472. if (!$next and defined $second_best){
  473. #mtr_report("Take second best choice $second_best");
  474. mtr_error("Internal error, second best too large")
  475. if $second_best > $#$tests;
  476. $next= splice(@$tests, $second_best, 1);
  477. }
  478. if ($next) {
  479. #$next->print_test();
  480. $next->write_test($sock, 'TESTCASE');
  481. $running{$next->key()}= $next;
  482. $num_ndb_tests++ if ($next->{ndb_test});
  483. }
  484. else {
  485. # No more test, tell child to exit
  486. #mtr_report("Saying BYE to child");
  487. print $sock "BYE\n";
  488. }
  489. }
  490. }
  491. # ----------------------------------------------------
  492. # Check if test suite timer expired
  493. # ----------------------------------------------------
  494. if ( ! $suite_timeout_proc->wait_one(0) )
  495. {
  496. mtr_report("Test suite timeout! Terminating...");
  497. return undef;
  498. }
  499. }
  500. }
  501. sub run_worker ($) {
  502. my ($server_port, $thread_num)= @_;
  503. $SIG{INT}= sub { exit(1); };
  504. # --------------------------------------------------------------------------
  505. # Set worker name
  506. # --------------------------------------------------------------------------
  507. report_option('name',"worker[$thread_num]");
  508. # --------------------------------------------------------------------------
  509. # Use auto build thread in all but first worker
  510. # --------------------------------------------------------------------------
  511. set_build_thread_ports($thread_num > 1 ? 'auto' : $opt_build_thread);
  512. if (check_ports_free()){
  513. # Some port was not free(which one has already been printed)
  514. mtr_error("Some port(s) was not free")
  515. }
  516. # --------------------------------------------------------------------------
  517. # Turn off verbosity in workers, unless explicitly specified
  518. # --------------------------------------------------------------------------
  519. report_option('verbose', undef) if ($opt_verbose == 0);
  520. environment_setup();
  521. # Connect to server
  522. my $server = new IO::Socket::INET
  523. (
  524. PeerAddr => 'localhost',
  525. PeerPort => $server_port,
  526. Proto => 'tcp'
  527. );
  528. mtr_error("Could not connect to server at port $server_port: $!")
  529. unless $server;
  530. # Read hello from server which it will send when shared
  531. # resources have been setup
  532. my $hello= <$server>;
  533. setup_vardir();
  534. check_running_as_root();
  535. mysql_install_db($thread_num);
  536. if ( using_extern() ) {
  537. create_config_file_for_extern(%opts_extern);
  538. }
  539. # Ask server for first test
  540. print $server "START\n";
  541. while(my $line= <$server>){
  542. chomp($line);
  543. if ($line eq 'TESTCASE'){
  544. my $test= My::Test::read_test($server);
  545. #$test->print_test();
  546. run_testcase($test);
  547. #$test->{result}= 'MTR_RES_PASSED';
  548. # Send it back, now with results set
  549. #$test->print_test();
  550. $test->write_test($server, 'TESTRESULT');
  551. }
  552. elsif ($line eq 'BYE'){
  553. mtr_report("Server said BYE");
  554. exit(0);
  555. }
  556. else {
  557. mtr_error("Could not understand server, '$line'");
  558. }
  559. }
  560. stop_all_servers();
  561. exit(1);
  562. }
  563. sub ignore_option {
  564. my ($opt, $value)= @_;
  565. mtr_report("Ignoring option '$opt'");
  566. }
  567. # Setup any paths that are $opt_vardir related
  568. sub set_vardir {
  569. my ($vardir)= @_;
  570. $opt_vardir= $vardir;
  571. $path_vardir_trace= $opt_vardir;
  572. # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
  573. $path_vardir_trace=~ s/^\w://;
  574. # Location of my.cnf that all clients use
  575. $path_config_file= "$opt_vardir/my.cnf";
  576. $path_testlog= "$opt_vardir/log/mysqltest.log";
  577. $path_current_testlog= "$opt_vardir/log/current_test";
  578. }
  579. sub command_line_setup {
  580. my $opt_comment;
  581. my $opt_usage;
  582. # Read the command line options
  583. # Note: Keep list, and the order, in sync with usage at end of this file
  584. Getopt::Long::Configure("pass_through");
  585. GetOptions(
  586. # Control what engine/variation to run
  587. 'embedded-server' => \$opt_embedded_server,
  588. 'ps-protocol' => \$opt_ps_protocol,
  589. 'sp-protocol' => \$opt_sp_protocol,
  590. 'view-protocol' => \$opt_view_protocol,
  591. 'cursor-protocol' => \$opt_cursor_protocol,
  592. 'ssl|with-openssl' => \$opt_ssl,
  593. 'skip-ssl' => \$opt_skip_ssl,
  594. 'compress' => \$opt_compress,
  595. 'with-ndbcluster|ndb' => \$opt_with_ndbcluster,
  596. 'vs-config' => \$opt_vs_config,
  597. # Config file to use as template for all tests
  598. 'defaults-file=s' => \&collect_option,
  599. # Extra config file to append to all generated configs
  600. 'defaults-extra-file=s' => \&collect_option,
  601. # Control what test suites or cases to run
  602. 'force' => \$opt_force,
  603. 'with-ndbcluster-only' => \&collect_option,
  604. 'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
  605. 'skip-ndbcluster-slave|skip-ndb-slave'
  606. => \$opt_skip_ndbcluster_slave,
  607. 'suite|suites=s' => \$opt_suites,
  608. 'skip-rpl' => \&collect_option,
  609. 'skip-test=s' => \&collect_option,
  610. 'do-test=s' => \&collect_option,
  611. 'start-from=s' => \&collect_option,
  612. 'big-test' => \$opt_big_test,
  613. 'combination=s' => \@opt_combinations,
  614. 'skip-combinations' => \&collect_option,
  615. 'skip-im' => \&ignore_option,
  616. # Specify ports
  617. 'build-thread|mtr-build-thread=i' => \$opt_build_thread,
  618. # Test case authoring
  619. 'record' => \$opt_record,
  620. 'check-testcases!' => \$opt_check_testcases,
  621. 'mark-progress' => \$opt_mark_progress,
  622. # Extra options used when starting mysqld
  623. 'mysqld=s' => \@opt_extra_mysqld_opt,
  624. # Run test on running server
  625. 'extern=s' => \%opts_extern, # Append to hash
  626. # Debugging
  627. 'debug' => \$opt_debug,
  628. 'gdb' => \$opt_gdb,
  629. 'client-gdb' => \$opt_client_gdb,
  630. 'manual-gdb' => \$opt_manual_gdb,
  631. 'manual-debug' => \$opt_manual_debug,
  632. 'ddd' => \$opt_ddd,
  633. 'client-ddd' => \$opt_client_ddd,
  634. 'manual-ddd' => \$opt_manual_ddd,
  635. 'debugger=s' => \$opt_debugger,
  636. 'client-debugger=s' => \$opt_client_debugger,
  637. 'strace-client:s' => \$opt_strace_client,
  638. 'max-save-core=i' => \$opt_max_save_core,
  639. 'max-save-datadir=i' => \$opt_max_save_datadir,
  640. 'max-test-fail=i' => \$opt_max_test_fail,
  641. # Coverage, profiling etc
  642. 'gcov' => \$opt_gcov,
  643. 'valgrind|valgrind-all' => \$opt_valgrind,
  644. 'valgrind-mysqltest' => \$opt_valgrind_mysqltest,
  645. 'valgrind-mysqld' => \$opt_valgrind_mysqld,
  646. 'valgrind-options=s' => sub {
  647. my ($opt, $value)= @_;
  648. # Deprecated option unless it's what we know pushbuild uses
  649. if ($value eq "--gen-suppressions=all --show-reachable=yes") {
  650. push(@valgrind_args, $_) for (split(' ', $value));
  651. return;
  652. }
  653. die("--valgrind-options=s is deprecated. Use ",
  654. "--valgrind-option=s, to be specified several",
  655. " times if necessary");
  656. },
  657. 'valgrind-option=s' => \@valgrind_args,
  658. 'valgrind-path=s' => \$opt_valgrind_path,
  659. 'callgrind' => \$opt_callgrind,
  660. # Directories
  661. 'tmpdir=s' => \$opt_tmpdir,
  662. 'vardir=s' => \$opt_vardir,
  663. 'mem' => \$opt_mem,
  664. 'client-bindir=s' => \$path_client_bindir,
  665. 'client-libdir=s' => \$path_client_libdir,
  666. # Misc
  667. 'report-features' => \$opt_report_features,
  668. 'comment=s' => \$opt_comment,
  669. 'fast' => \$opt_fast,
  670. 'reorder!' => \&collect_option,
  671. 'enable-disabled' => \&collect_option,
  672. 'verbose+' => \$opt_verbose,
  673. 'verbose-restart' => \&report_option,
  674. 'sleep=i' => \$opt_sleep,
  675. 'start-dirty' => \$opt_start_dirty,
  676. 'start' => \$opt_start,
  677. 'print-testcases' => \&collect_option,
  678. 'repeat=i' => \$opt_repeat,
  679. 'retry=i' => \$opt_retry,
  680. 'retry-failure=i' => \$opt_retry_failure,
  681. 'timer!' => \&report_option,
  682. 'user=s' => \$opt_user,
  683. 'testcase-timeout=i' => \$opt_testcase_timeout,
  684. 'suite-timeout=i' => \$opt_suite_timeout,
  685. 'shutdown-timeout=i' => \$opt_shutdown_timeout,
  686. 'warnings!' => \$opt_warnings,
  687. 'timestamp' => \&report_option,
  688. 'timediff' => \&report_option,
  689. 'help|h' => \$opt_usage,
  690. ) or usage("Can't read options");
  691. usage("") if $opt_usage;
  692. # --------------------------------------------------------------------------
  693. # Setup verbosity
  694. # --------------------------------------------------------------------------
  695. if ($opt_verbose != 0){
  696. report_option('verbose', $opt_verbose);
  697. }
  698. if ( -d "../sql" )
  699. {
  700. $source_dist= 1;
  701. }
  702. # Find the absolute path to the test directory
  703. $glob_mysql_test_dir= cwd();
  704. if (IS_CYGWIN)
  705. {
  706. # Use mixed path format i.e c:/path/to/
  707. $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
  708. }
  709. # In most cases, the base directory we find everything relative to,
  710. # is the parent directory of the "mysql-test" directory. For source
  711. # distributions, TAR binary distributions and some other packages.
  712. $basedir= dirname($glob_mysql_test_dir);
  713. # In the RPM case, binaries and libraries are installed in the
  714. # default system locations, instead of having our own private base
  715. # directory. And we install "/usr/share/mysql-test". Moving up one
  716. # more directory relative to "mysql-test" gives us a usable base
  717. # directory for RPM installs.
  718. if ( ! $source_dist and ! -d "$basedir/bin" )
  719. {
  720. $basedir= dirname($basedir);
  721. }
  722. # Look for the client binaries directory
  723. if ($path_client_bindir)
  724. {
  725. # --client-bindir=path set on command line, check that the path exists
  726. $path_client_bindir= mtr_path_exists($path_client_bindir);
  727. }
  728. else
  729. {
  730. $path_client_bindir= mtr_path_exists("$basedir/client_release",
  731. "$basedir/client_debug",
  732. vs_config_dirs('client', ''),
  733. "$basedir/client",
  734. "$basedir/bin");
  735. }
  736. # Look for language files and charsetsdir, use same share
  737. my $path_share= mtr_path_exists("$basedir/share/mysql",
  738. "$basedir/sql/share",
  739. "$basedir/share");
  740. $path_language= mtr_path_exists("$path_share/english");
  741. $path_charsetsdir= mtr_path_exists("$path_share/charsets");
  742. # Look for SQL scripts directory
  743. if ( mtr_file_exists("$path_share/mysql_system_tables.sql") ne "")
  744. {
  745. # The SQL scripts are in path_share
  746. $path_sql_dir= $path_share;
  747. }
  748. else
  749. {
  750. $path_sql_dir= mtr_path_exists("$basedir/share",
  751. "$basedir/scripts");
  752. }
  753. if (using_extern())
  754. {
  755. # Connect to the running mysqld and find out what it supports
  756. collect_mysqld_features_from_running_server();
  757. }
  758. else
  759. {
  760. # Run the mysqld to find out what features are available
  761. collect_mysqld_features();
  762. }
  763. if ( $opt_comment )
  764. {
  765. mtr_report();
  766. mtr_print_thick_line('#');
  767. mtr_report("# $opt_comment");
  768. mtr_print_thick_line('#');
  769. }
  770. foreach my $arg ( @ARGV )
  771. {
  772. if ( $arg =~ /^--skip-/ )
  773. {
  774. push(@opt_extra_mysqld_opt, $arg);
  775. }
  776. elsif ( $arg =~ /^--$/ )
  777. {
  778. # It is an effect of setting 'pass_through' in option processing
  779. # that the lone '--' separating options from arguments survives,
  780. # simply ignore it.
  781. }
  782. elsif ( $arg =~ /^-/ )
  783. {
  784. usage("Invalid option \"$arg\"");
  785. }
  786. else
  787. {
  788. push(@opt_cases, $arg);
  789. }
  790. }
  791. # --------------------------------------------------------------------------
  792. # Find out type of logging that are being used
  793. # --------------------------------------------------------------------------
  794. foreach my $arg ( @opt_extra_mysqld_opt )
  795. {
  796. if ( $arg =~ /binlog[-_]format=(\S+)/ )
  797. {
  798. # Save this for collect phase
  799. collect_option('binlog-format', $1);
  800. mtr_report("Using binlog format '$1'");
  801. }
  802. }
  803. # --------------------------------------------------------------------------
  804. # Find out default storage engine being used(if any)
  805. # --------------------------------------------------------------------------
  806. foreach my $arg ( @opt_extra_mysqld_opt )
  807. {
  808. if ( $arg =~ /default-storage-engine=(\S+)/ )
  809. {
  810. # Save this for collect phase
  811. collect_option('default-storage-engine', $1);
  812. mtr_report("Using default engine '$1'")
  813. }
  814. }
  815. # --------------------------------------------------------------------------
  816. # Check if we should speed up tests by trying to run on tmpfs
  817. # --------------------------------------------------------------------------
  818. if ( defined $opt_mem)
  819. {
  820. mtr_error("Can't use --mem and --vardir at the same time ")
  821. if $opt_vardir;
  822. mtr_error("Can't use --mem and --tmpdir at the same time ")
  823. if $opt_tmpdir;
  824. # Search through list of locations that are known
  825. # to be "fast disks" to find a suitable location
  826. # Use --mem=<dir> as first location to look.
  827. my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
  828. foreach my $fs (@tmpfs_locations)
  829. {
  830. if ( -d $fs )
  831. {
  832. my $template= "var_${opt_build_thread}_XXXX";
  833. $opt_mem= tempdir( $template, DIR => $fs, CLEANUP => 0);
  834. last;
  835. }
  836. }
  837. }
  838. # --------------------------------------------------------------------------
  839. # Set the "var/" directory, the base for everything else
  840. # --------------------------------------------------------------------------
  841. $default_vardir= "$glob_mysql_test_dir/var";
  842. if ( ! $opt_vardir )
  843. {
  844. $opt_vardir= $default_vardir;
  845. }
  846. # We make the path absolute, as the server will do a chdir() before usage
  847. unless ( $opt_vardir =~ m,^/, or
  848. (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) )
  849. {
  850. # Make absolute path, relative test dir
  851. $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
  852. }
  853. set_vardir($opt_vardir);
  854. # --------------------------------------------------------------------------
  855. # Set the "tmp" directory
  856. # --------------------------------------------------------------------------
  857. $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
  858. $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
  859. # --------------------------------------------------------------------------
  860. # fast option
  861. # --------------------------------------------------------------------------
  862. if ($opt_fast){
  863. $opt_shutdown_timeout= 0; # Kill processes instead of nice shutdown
  864. }
  865. # --------------------------------------------------------------------------
  866. # Record flag
  867. # --------------------------------------------------------------------------
  868. if ( $opt_record and ! @opt_cases )
  869. {
  870. mtr_error("Will not run in record mode without a specific test case");
  871. }
  872. # --------------------------------------------------------------------------
  873. # Embedded server flag
  874. # --------------------------------------------------------------------------
  875. if ( $opt_embedded_server )
  876. {
  877. if ( IS_WINDOWS )
  878. {
  879. # Add the location for libmysqld.dll to the path.
  880. my $separator= ";";
  881. my $lib_mysqld=
  882. mtr_path_exists(vs_config_dirs('libmysqld',''));
  883. if ( IS_CYGWIN )
  884. {
  885. $lib_mysqld= posix_path($lib_mysqld);
  886. $separator= ":";
  887. }
  888. $ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld;
  889. }
  890. $opt_skip_ndbcluster= 1; # Turn off use of NDB cluster
  891. $opt_skip_ssl= 1; # Turn off use of SSL
  892. # Turn off use of bin log
  893. push(@opt_extra_mysqld_opt, "--skip-log-bin");
  894. if ( using_extern() )
  895. {
  896. mtr_error("Can't use --extern with --embedded-server");
  897. }
  898. if ($opt_gdb)
  899. {
  900. mtr_warning("Silently converting --gdb to --client-gdb in embedded mode");
  901. $opt_client_gdb= $opt_gdb;
  902. $opt_gdb= undef;
  903. }
  904. if ($opt_ddd)
  905. {
  906. mtr_warning("Silently converting --ddd to --client-ddd in embedded mode");
  907. $opt_client_ddd= $opt_ddd;
  908. $opt_ddd= undef;
  909. }
  910. if ($opt_debugger)
  911. {
  912. mtr_warning("Silently converting --debugger to --client-debugger in embedded mode");
  913. $opt_client_debugger= $opt_debugger;
  914. $opt_debugger= undef;
  915. }
  916. if ( $opt_gdb || $opt_ddd || $opt_manual_gdb || $opt_manual_ddd ||
  917. $opt_manual_debug || $opt_debugger )
  918. {
  919. mtr_error("You need to use the client debug options for the",
  920. "embedded server. Ex: --client-gdb");
  921. }
  922. }
  923. # --------------------------------------------------------------------------
  924. # Big test flags
  925. # --------------------------------------------------------------------------
  926. if ( $opt_big_test )
  927. {
  928. $ENV{'BIG_TEST'}= 1;
  929. }
  930. # --------------------------------------------------------------------------
  931. # Gcov flag
  932. # --------------------------------------------------------------------------
  933. if ( $opt_gcov and ! $source_dist )
  934. {
  935. mtr_error("Coverage test needs the source - please use source dist");
  936. }
  937. # --------------------------------------------------------------------------
  938. # Check debug related options
  939. # --------------------------------------------------------------------------
  940. if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd ||
  941. $opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug ||
  942. $opt_debugger || $opt_client_debugger )
  943. {
  944. # Indicate that we are using debugger
  945. $glob_debugger= 1;
  946. if ( using_extern() )
  947. {
  948. mtr_error("Can't use --extern when using debugger");
  949. }
  950. }
  951. #
  952. # Check valgrind arguments
  953. # --------------------------------------------------------------------------
  954. if ( $opt_valgrind or $opt_valgrind_path or @valgrind_args)
  955. {
  956. mtr_report("Turning on valgrind for all executables");
  957. $opt_valgrind= 1;
  958. $opt_valgrind_mysqld= 1;
  959. $opt_valgrind_mysqltest= 1;
  960. # Increase the timeouts when running with valgrind
  961. $opt_testcase_timeout*= 10;
  962. $opt_suite_timeout*= 6;
  963. $opt_start_timeout*= 10;
  964. }
  965. elsif ( $opt_valgrind_mysqld )
  966. {
  967. mtr_report("Turning on valgrind for mysqld(s) only");
  968. $opt_valgrind= 1;
  969. }
  970. elsif ( $opt_valgrind_mysqltest )
  971. {
  972. mtr_report("Turning on valgrind for mysqltest and mysql_client_test only");
  973. $opt_valgrind= 1;
  974. }
  975. if ( $opt_callgrind )
  976. {
  977. mtr_report("Turning on valgrind with callgrind for mysqld(s)");
  978. $opt_valgrind= 1;
  979. $opt_valgrind_mysqld= 1;
  980. # Set special valgrind options unless options passed on command line
  981. push(@valgrind_args, "--trace-children=yes")
  982. unless @valgrind_args;
  983. }
  984. if ( $opt_valgrind )
  985. {
  986. # Set valgrind_options to default unless already defined
  987. push(@valgrind_args, @default_valgrind_args)
  988. unless @valgrind_args;
  989. mtr_report("Running valgrind with options \"",
  990. join(" ", @valgrind_args), "\"");
  991. }
  992. mtr_report("Checking supported features...");
  993. check_ndbcluster_support(\%mysqld_variables);
  994. check_ssl_support(\%mysqld_variables);
  995. check_debug_support(\%mysqld_variables);
  996. executable_setup();
  997. }
  998. #
  999. # To make it easier for different devs to work on the same host,
  1000. # an environment variable can be used to control all ports. A small
  1001. # number is to be used, 0 - 16 or similar.
  1002. #
  1003. # Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
  1004. # versions of this script, else a 4.0 test run might conflict with a
  1005. # 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
  1006. # all port numbers might not be used in this version of the script.
  1007. #
  1008. # Also note the limitation of ports we are allowed to hand out. This
  1009. # differs between operating systems and configuration, see
  1010. # http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
  1011. # But a fairly safe range seems to be 5001 - 32767
  1012. #
  1013. sub set_build_thread_ports($) {
  1014. my $build_thread= shift || 0;
  1015. if ( lc($build_thread) eq 'auto' ) {
  1016. #mtr_report("Requesting build thread... ");
  1017. $build_thread= mtr_get_unique_id(250, 299);
  1018. if ( !defined $build_thread ) {
  1019. mtr_error("Could not get a unique build thread id");
  1020. }
  1021. #mtr_report(" - got $build_thread");
  1022. }
  1023. $ENV{MTR_BUILD_THREAD}= $build_thread;
  1024. $opt_build_thread= $build_thread;
  1025. # Calculate baseport
  1026. $baseport= $build_thread * 10 + 10000;
  1027. if ( $baseport < 5001 or $baseport + 9 >= 32767 )
  1028. {
  1029. mtr_error("MTR_BUILD_THREAD number results in a port",
  1030. "outside 5001 - 32767",
  1031. "($baseport - $baseport + 9)");
  1032. }
  1033. mtr_report("Using MTR_BUILD_THREAD $build_thread,",
  1034. "with reserved ports $baseport..".($baseport+9));
  1035. }
  1036. sub collect_mysqld_features {
  1037. my $found_variable_list_start= 0;
  1038. my $use_tmpdir;
  1039. if ( defined $opt_tmpdir and -d $opt_tmpdir){
  1040. # Create the tempdir in $opt_tmpdir
  1041. $use_tmpdir= $opt_tmpdir;
  1042. }
  1043. my $tmpdir= tempdir(CLEANUP => 0, # Directory removed by this function
  1044. DIR => $use_tmpdir);
  1045. #
  1046. # Execute "mysqld --no-defaults --help --verbose" to get a
  1047. # list of all features and settings
  1048. #
  1049. # --no-defaults and --skip-grant-tables are to avoid loading
  1050. # system-wide configs and plugins
  1051. #
  1052. # --datadir must exist, mysqld will chdir into it
  1053. #
  1054. my $args;
  1055. mtr_init_args(\$args);
  1056. mtr_add_arg($args, "--no-defaults");
  1057. mtr_add_arg($args, "--datadir=%s", mixed_path($tmpdir));
  1058. mtr_add_arg($args, "--language=%s", $path_language);
  1059. mtr_add_arg($args, "--skip-grant-tables");
  1060. mtr_add_arg($args, "--verbose");
  1061. mtr_add_arg($args, "--help");
  1062. my $exe_mysqld= find_mysqld($basedir);
  1063. my $cmd= join(" ", $exe_mysqld, @$args);
  1064. my $list= `$cmd`;
  1065. foreach my $line (split('\n', $list))
  1066. {
  1067. # First look for version
  1068. if ( !$mysql_version_id )
  1069. {
  1070. # Look for version
  1071. my $exe_name= basename($exe_mysqld);
  1072. mtr_verbose("exe_name: $exe_name");
  1073. if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)/ )
  1074. {
  1075. #print "Major: $1 Minor: $2 Build: $3\n";
  1076. $mysql_version_id= $1*10000 + $2*100 + $3;
  1077. #print "mysql_version_id: $mysql_version_id\n";
  1078. mtr_report("MySQL Version $1.$2.$3");
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if (!$found_variable_list_start)
  1084. {
  1085. # Look for start of variables list
  1086. if ( $line =~ /[\-]+\s[\-]+/ )
  1087. {
  1088. $found_variable_list_start= 1;
  1089. }
  1090. }
  1091. else
  1092. {
  1093. # Put variables into hash
  1094. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  1095. {
  1096. # print "$1=\"$2\"\n";
  1097. $mysqld_variables{$1}= $2;
  1098. }
  1099. else
  1100. {
  1101. # The variable list is ended with a blank line
  1102. if ( $line =~ /^[\s]*$/ )
  1103. {
  1104. last;
  1105. }
  1106. else
  1107. {
  1108. # Send out a warning, we should fix the variables that has no
  1109. # space between variable name and it's value
  1110. # or should it be fixed width column parsing? It does not
  1111. # look like that in function my_print_variables in my_getopt.c
  1112. mtr_warning("Could not parse variable list line : $line");
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. rmtree($tmpdir);
  1119. mtr_error("Could not find version of MySQL") unless $mysql_version_id;
  1120. mtr_error("Could not find variabes list") unless $found_variable_list_start;
  1121. }
  1122. sub collect_mysqld_features_from_running_server ()
  1123. {
  1124. my $mysql= mtr_exe_exists("$path_client_bindir/mysql");
  1125. my $args;
  1126. mtr_init_args(\$args);
  1127. mtr_add_arg($args, "--no-defaults");
  1128. mtr_add_arg($args, "--user=%s", $opt_user);
  1129. while (my ($option, $value)= each( %opts_extern )) {
  1130. mtr_add_arg($args, "--$option=$value");
  1131. }
  1132. mtr_add_arg($args, "--silent"); # Tab separated output
  1133. mtr_add_arg($args, "-e '%s'", "use mysql; SHOW VARIABLES");
  1134. my $cmd= "$mysql " . join(' ', @$args);
  1135. mtr_verbose("cmd: $cmd");
  1136. my $list = `$cmd` or
  1137. mtr_error("Could not connect to extern server using command: '$cmd'");
  1138. foreach my $line (split('\n', $list ))
  1139. {
  1140. # Put variables into hash
  1141. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  1142. {
  1143. # print "$1=\"$2\"\n";
  1144. $mysqld_variables{$1}= $2;
  1145. }
  1146. }
  1147. # Parse version
  1148. my $version_str= $mysqld_variables{'version'};
  1149. if ( $version_str =~ /^([0-9]*)\.([0-9]*)\.([0-9]*)/ )
  1150. {
  1151. #print "Major: $1 Minor: $2 Build: $3\n";
  1152. $mysql_version_id= $1*10000 + $2*100 + $3;
  1153. #print "mysql_version_id: $mysql_version_id\n";
  1154. mtr_report("MySQL Version $1.$2.$3");
  1155. }
  1156. mtr_error("Could not find version of MySQL") unless $mysql_version_id;
  1157. }
  1158. sub find_mysqld {
  1159. my ($mysqld_basedir)= @_;
  1160. my @mysqld_names= ("mysqld", "mysqld-max-nt", "mysqld-max",
  1161. "mysqld-nt");
  1162. if ( $opt_debug ){
  1163. # Put mysqld-debug first in the list of binaries to look for
  1164. mtr_verbose("Adding mysqld-debug first in list of binaries to look for");
  1165. unshift(@mysqld_names, "mysqld-debug");
  1166. }
  1167. return my_find_bin($mysqld_basedir,
  1168. ["sql", "libexec", "sbin"],
  1169. [@mysqld_names]);
  1170. }
  1171. sub executable_setup () {
  1172. #
  1173. # Check if libtool is available in this distribution/clone
  1174. # we need it when valgrinding or debugging non installed binary
  1175. # Otherwise valgrind will valgrind the libtool wrapper or bash
  1176. # and gdb will not find the real executable to debug
  1177. #
  1178. if ( -x "../libtool")
  1179. {
  1180. $exe_libtool= "../libtool";
  1181. if ($opt_valgrind or $glob_debugger)
  1182. {
  1183. mtr_report("Using \"$exe_libtool\" when running valgrind or debugger");
  1184. }
  1185. }
  1186. # Look for the client binaries
  1187. $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin");
  1188. $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql");
  1189. if ( ! $opt_skip_ndbcluster )
  1190. {
  1191. $exe_ndbd=
  1192. my_find_bin($basedir,
  1193. ["storage/ndb/src/kernel", "libexec"],
  1194. "ndbd");
  1195. $exe_ndb_mgmd=
  1196. my_find_bin($basedir,
  1197. ["storage/ndb/src/mgmsrv", "libexec"],
  1198. "ndb_mgmd");
  1199. $exe_ndb_waiter=
  1200. my_find_bin($basedir,
  1201. ["storage/ndb/tools/", "bin"],
  1202. "ndb_waiter");
  1203. }
  1204. # Look for mysqltest executable
  1205. if ( $opt_embedded_server )
  1206. {
  1207. $exe_mysqltest=
  1208. mtr_exe_exists(vs_config_dirs('libmysqld/examples','mysqltest_embedded'),
  1209. "$basedir/libmysqld/examples/mysqltest_embedded",
  1210. "$path_client_bindir/mysqltest_embedded");
  1211. }
  1212. else
  1213. {
  1214. $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest");
  1215. }
  1216. }
  1217. sub client_debug_arg($$) {
  1218. my ($args, $client_name)= @_;
  1219. if ( $opt_debug ) {
  1220. mtr_add_arg($args,
  1221. "--debug=d:t:A,%s/log/%s.trace",
  1222. $path_vardir_trace, $client_name)
  1223. }
  1224. }
  1225. sub mysql_fix_arguments () {
  1226. return "" if ( IS_WINDOWS );
  1227. my $exe=
  1228. mtr_script_exists("$basedir/scripts/mysql_fix_privilege_tables",
  1229. "$path_client_bindir/mysql_fix_privilege_tables");
  1230. my $args;
  1231. mtr_init_args(\$args);
  1232. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1233. mtr_add_arg($args, "--basedir=", $basedir);
  1234. mtr_add_arg($args, "--bindir=", $path_client_bindir);
  1235. mtr_add_arg($args, "--verbose");
  1236. return mtr_args2str($exe, @$args);
  1237. }
  1238. sub client_arguments ($) {
  1239. my $client_name= shift;
  1240. my $client_exe= mtr_exe_exists("$path_client_bindir/$client_name");
  1241. my $args;
  1242. mtr_init_args(\$args);
  1243. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1244. client_debug_arg($args, $client_name);
  1245. return mtr_args2str($client_exe, @$args);
  1246. }
  1247. sub mysqlslap_arguments () {
  1248. my $exe= mtr_exe_maybe_exists("$path_client_bindir/mysqlslap");
  1249. if ( $exe eq "" ) {
  1250. # mysqlap was not found
  1251. if (defined $mysql_version_id and $mysql_version_id >= 50100 ) {
  1252. mtr_error("Could not find the mysqlslap binary");
  1253. }
  1254. return ""; # Don't care about mysqlslap
  1255. }
  1256. my $args;
  1257. mtr_init_args(\$args);
  1258. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1259. client_debug_arg($args, "mysqlslap");
  1260. return mtr_args2str($exe, @$args);
  1261. }
  1262. sub mysqldump_arguments ($) {
  1263. my($group_suffix) = @_;
  1264. my $exe= mtr_exe_exists("$path_client_bindir/mysqldump");
  1265. my $args;
  1266. mtr_init_args(\$args);
  1267. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1268. mtr_add_arg($args, "--defaults-group-suffix=%s", $group_suffix);
  1269. client_debug_arg($args, "mysqldump-$group_suffix");
  1270. return mtr_args2str($exe, @$args);
  1271. }
  1272. sub mysql_client_test_arguments(){
  1273. my $exe;
  1274. # mysql_client_test executable may _not_ exist
  1275. if ( $opt_embedded_server ) {
  1276. $exe= mtr_exe_maybe_exists(
  1277. vs_config_dirs('libmysqld/examples','mysql_client_test_embedded'),
  1278. "$basedir/libmysqld/examples/mysql_client_test_embedded");
  1279. } else {
  1280. $exe= mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
  1281. "$basedir/tests/mysql_client_test",
  1282. "$basedir/bin/mysql_client_test");
  1283. }
  1284. my $args;
  1285. mtr_init_args(\$args);
  1286. if ( $opt_valgrind_mysqltest ) {
  1287. valgrind_arguments($args, \$exe);
  1288. }
  1289. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1290. mtr_add_arg($args, "--testcase");
  1291. mtr_add_arg($args, "--vardir=$opt_vardir");
  1292. client_debug_arg($args,"mysql_client_test");
  1293. return mtr_args2str($exe, @$args);
  1294. }
  1295. #
  1296. # Set environment to be used by childs of this process for
  1297. # things that are constant during the whole lifetime of mysql-test-run
  1298. #
  1299. sub environment_setup {
  1300. umask(022);
  1301. my @ld_library_paths;
  1302. if ($path_client_libdir)
  1303. {
  1304. # Use the --client-libdir passed on commandline
  1305. push(@ld_library_paths, "$path_client_libdir");
  1306. }
  1307. else
  1308. {
  1309. # Setup LD_LIBRARY_PATH so the libraries from this distro/clone
  1310. # are used in favor of the system installed ones
  1311. if ( $source_dist )
  1312. {
  1313. push(@ld_library_paths, "$basedir/libmysql/.libs/",
  1314. "$basedir/libmysql_r/.libs/",
  1315. "$basedir/zlib.libs/");
  1316. }
  1317. else
  1318. {
  1319. push(@ld_library_paths, "$basedir/lib");
  1320. }
  1321. }
  1322. # --------------------------------------------------------------------------
  1323. # Add the path where libndbclient can be found
  1324. # --------------------------------------------------------------------------
  1325. if ( !$opt_skip_ndbcluster )
  1326. {
  1327. push(@ld_library_paths, "$basedir/storage/ndb/src/.libs");
  1328. }
  1329. # --------------------------------------------------------------------------
  1330. # Add the path where mysqld will find udf_example.so
  1331. # --------------------------------------------------------------------------
  1332. my $lib_udf_example=
  1333. mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'),
  1334. "$basedir/sql/.libs/udf_example.so",);
  1335. if ( $lib_udf_example )
  1336. {
  1337. push(@ld_library_paths, dirname($lib_udf_example));
  1338. }
  1339. $ENV{'UDF_EXAMPLE_LIB'}=
  1340. ($lib_udf_example ? basename($lib_udf_example) : "");
  1341. $ENV{'UDF_EXAMPLE_LIB_OPT'}= "--plugin-dir=".
  1342. ($lib_udf_example ? dirname($lib_udf_example) : "");
  1343. # --------------------------------------------------------------------------
  1344. # Add the path where mysqld will find ha_example.so
  1345. # --------------------------------------------------------------------------
  1346. if ($mysql_version_id >= 50100) {
  1347. my $lib_example_plugin=
  1348. mtr_file_exists(vs_config_dirs('storage/example', 'ha_example.dll'),
  1349. "$basedir/storage/example/.libs/ha_example.so",);
  1350. $ENV{'EXAMPLE_PLUGIN'}=
  1351. ($lib_example_plugin ? basename($lib_example_plugin) : "");
  1352. $ENV{'EXAMPLE_PLUGIN_OPT'}= "--plugin-dir=".
  1353. ($lib_example_plugin ? dirname($lib_example_plugin) : "");
  1354. }
  1355. # --------------------------------------------------------------------------
  1356. # Valgrind need to be run with debug libraries otherwise it's almost
  1357. # impossible to add correct supressions, that means if "/usr/lib/debug"
  1358. # is available, it should be added to
  1359. # LD_LIBRARY_PATH
  1360. #
  1361. # But pthread is broken in libc6-dbg on Debian <= 3.1 (see Debian
  1362. # bug 399035, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=399035),
  1363. # so don't change LD_LIBRARY_PATH on that platform.
  1364. # --------------------------------------------------------------------------
  1365. my $debug_libraries_path= "/usr/lib/debug";
  1366. my $deb_version;
  1367. if ( $opt_valgrind and -d $debug_libraries_path and
  1368. (! -e '/etc/debian_version' or
  1369. ($deb_version=
  1370. mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
  1371. $deb_version > 3.1 ) )
  1372. {
  1373. push(@ld_library_paths, $debug_libraries_path);
  1374. }
  1375. $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  1376. $ENV{'LD_LIBRARY_PATH'} ?
  1377. split(':', $ENV{'LD_LIBRARY_PATH'}) : ());
  1378. mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
  1379. $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  1380. $ENV{'DYLD_LIBRARY_PATH'} ?
  1381. split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
  1382. mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
  1383. # The environment variable used for shared libs on AIX
  1384. $ENV{'SHLIB_PATH'}= join(":", @ld_library_paths,
  1385. $ENV{'SHLIB_PATH'} ?
  1386. split(':', $ENV{'SHLIB_PATH'}) : ());
  1387. mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}");
  1388. # The environment variable used for shared libs on hp-ux
  1389. $ENV{'LIBPATH'}= join(":", @ld_library_paths,
  1390. $ENV{'LIBPATH'} ?
  1391. split(':', $ENV{'LIBPATH'}) : ());
  1392. mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
  1393. $ENV{'CHARSETSDIR'}= $path_charsetsdir;
  1394. $ENV{'UMASK'}= "0660"; # The octal *string*
  1395. $ENV{'UMASK_DIR'}= "0770"; # The octal *string*
  1396. #
  1397. # MySQL tests can produce output in various character sets
  1398. # (especially, ctype_xxx.test). To avoid confusing Perl
  1399. # with output which is incompatible with the current locale
  1400. # settings, we reset the current values of LC_ALL and LC_CTYPE to "C".
  1401. # For details, please see
  1402. # Bug#27636 tests fails if LC_* variables set to *_*.UTF-8
  1403. #
  1404. $ENV{'LC_ALL'}= "C";
  1405. $ENV{'LC_CTYPE'}= "C";
  1406. $ENV{'LC_COLLATE'}= "C";
  1407. $ENV{'USE_RUNNING_SERVER'}= using_extern();
  1408. $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
  1409. $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'} || 3306;
  1410. $ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir;
  1411. $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
  1412. # ----------------------------------------------------
  1413. # Setup env for NDB
  1414. # ----------------------------------------------------
  1415. if ( ! $opt_skip_ndbcluster )
  1416. {
  1417. $ENV{'NDB_MGM'}=
  1418. my_find_bin($basedir,
  1419. ["storage/ndb/src/mgmclient", "bin"],
  1420. "ndb_mgm");
  1421. $ENV{'NDB_TOOLS_DIR'}=
  1422. my_find_dir($basedir,
  1423. ["storage/ndb/tools", "bin"]);
  1424. $ENV{'NDB_EXAMPLES_DIR'}=
  1425. my_find_dir($basedir,
  1426. ["storage/ndb/ndbapi-examples", "bin"]);
  1427. $ENV{'NDB_EXAMPLES_BINARY'}=
  1428. my_find_bin($basedir,
  1429. ["storage/ndb/ndbapi-examples/ndbapi_simple", "bin"],
  1430. "ndbapi_simple", NOT_REQUIRED);
  1431. my $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
  1432. $ENV{'NDB_TOOLS_OUTPUT'}= $path_ndb_testrun_log;
  1433. $ENV{'NDB_EXAMPLES_OUTPUT'}= $path_ndb_testrun_log;
  1434. }
  1435. # ----------------------------------------------------
  1436. # mysql clients
  1437. # ----------------------------------------------------
  1438. $ENV{'MYSQL_CHECK'}= client_arguments("mysqlcheck");
  1439. $ENV{'MYSQL_DUMP'}= mysqldump_arguments(".1");
  1440. $ENV{'MYSQL_DUMP_SLAVE'}= mysqldump_arguments(".2");
  1441. $ENV{'MYSQL_SLAP'}= mysqlslap_arguments();
  1442. $ENV{'MYSQL_IMPORT'}= client_arguments("mysqlimport");
  1443. $ENV{'MYSQL_SHOW'}= client_arguments("mysqlshow");
  1444. $ENV{'MYSQL_BINLOG'}= client_arguments("mysqlbinlog");
  1445. $ENV{'MYSQL'}= client_arguments("mysql");
  1446. $ENV{'MYSQL_UPGRADE'}= client_arguments("mysql_upgrade");
  1447. $ENV{'MYSQLADMIN'}= native_path($exe_mysqladmin);
  1448. $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
  1449. $ENV{'MYSQL_FIX_SYSTEM_TABLES'}= mysql_fix_arguments();
  1450. $ENV{'EXE_MYSQL'}= $exe_mysql;
  1451. # ----------------------------------------------------
  1452. # bug25714 executable may _not_ exist in
  1453. # some versions, test using it should be skipped
  1454. # ----------------------------------------------------
  1455. my $exe_bug25714=
  1456. mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
  1457. "$basedir/tests/bug25714");
  1458. $ENV{'MYSQL_BUG25714'}= native_path($exe_bug25714);
  1459. # ----------------------------------------------------
  1460. # mysql_fix_privilege_tables.sql
  1461. # ----------------------------------------------------
  1462. my $file_mysql_fix_privilege_tables=
  1463. mtr_file_exists("$basedir/scripts/mysql_fix_privilege_tables.sql",
  1464. "$basedir/share/mysql_fix_privilege_tables.sql",
  1465. "$basedir/share/mysql/mysql_fix_privilege_tables.sql");
  1466. $ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
  1467. # ----------------------------------------------------
  1468. # my_print_defaults
  1469. # ----------------------------------------------------
  1470. my $exe_my_print_defaults=
  1471. mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
  1472. "$path_client_bindir/my_print_defaults",
  1473. "$basedir/extra/my_print_defaults");
  1474. $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= native_path($exe_my_print_defaults);
  1475. # ----------------------------------------------------
  1476. # Setup env so childs can execute myisampack and myisamchk
  1477. # ----------------------------------------------------
  1478. $ENV{'MYISAMCHK'}= native_path(mtr_exe_exists(
  1479. vs_config_dirs('storage/myisam', 'myisamchk'),
  1480. vs_config_dirs('myisam', 'myisamchk'),
  1481. "$path_client_bindir/myisamchk",
  1482. "$basedir/storage/myisam/myisamchk",
  1483. "$basedir/myisam/myisamchk"));
  1484. $ENV{'MYISAMPACK'}= native_path(mtr_exe_exists(
  1485. vs_config_dirs('storage/myisam', 'myisampack'),
  1486. vs_config_dirs('myisam', 'myisampack'),
  1487. "$path_client_bindir/myisampack",
  1488. "$basedir/storage/myisam/myisampack",
  1489. "$basedir/myisam/myisampack"));
  1490. # ----------------------------------------------------
  1491. # perror
  1492. # ----------------------------------------------------
  1493. my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
  1494. "$basedir/extra/perror",
  1495. "$path_client_bindir/perror");
  1496. $ENV{'MY_PERROR'}= native_path($exe_perror);
  1497. # Create an environment variable to make it possible
  1498. # to detect that valgrind is being used from test cases
  1499. $ENV{'VALGRIND_TEST'}= $opt_valgrind;
  1500. }
  1501. #
  1502. # Remove var and any directories in var/ created by previous
  1503. # tests
  1504. #
  1505. sub remove_stale_vardir () {
  1506. mtr_report("Removing old var directory...");
  1507. # Safety!
  1508. mtr_error("No, don't remove the vardir when running with --extern")
  1509. if using_extern();
  1510. mtr_verbose("opt_vardir: $opt_vardir");
  1511. if ( $opt_vardir eq $default_vardir )
  1512. {
  1513. #
  1514. # Running with "var" in mysql-test dir
  1515. #
  1516. if ( -l $opt_vardir)
  1517. {
  1518. # var is a symlink
  1519. if ( $opt_mem )
  1520. {
  1521. # Remove the directory which the link points at
  1522. mtr_verbose("Removing " . readlink($opt_vardir));
  1523. rmtree(readlink($opt_vardir));
  1524. # Remove the "var" symlink
  1525. mtr_verbose("unlink($opt_vardir)");
  1526. unlink($opt_vardir);
  1527. }
  1528. else
  1529. {
  1530. # Some users creates a soft link in mysql-test/var to another area
  1531. # - allow it, but remove all files in it
  1532. mtr_report(" - WARNING: Using the 'mysql-test/var' symlink");
  1533. # Make sure the directory where it points exist
  1534. mtr_error("The destination for symlink $opt_vardir does not exist")
  1535. if ! -d readlink($opt_vardir);
  1536. foreach my $bin ( glob("$opt_vardir/*") )
  1537. {
  1538. mtr_verbose("Removing bin $bin");
  1539. rmtree($bin);
  1540. }
  1541. }
  1542. }
  1543. else
  1544. {
  1545. # Remove the entire "var" dir
  1546. mtr_verbose("Removing $opt_vardir/");
  1547. rmtree("$opt_vardir/");
  1548. }
  1549. if ( $opt_mem )
  1550. {
  1551. # A symlink from var/ to $opt_mem will be set up
  1552. # remove the $opt_mem dir to assure the symlink
  1553. # won't point at an old directory
  1554. mtr_verbose("Removing $opt_mem");
  1555. rmtree($opt_mem);
  1556. }
  1557. }
  1558. else
  1559. {
  1560. #
  1561. # Running with "var" in some other place
  1562. #
  1563. # Remove the var/ dir in mysql-test dir if any
  1564. # this could be an old symlink that shouldn't be there
  1565. mtr_verbose("Removing $default_vardir");
  1566. rmtree($default_vardir);
  1567. # Remove the "var" dir
  1568. mtr_verbose("Removing $opt_vardir/");
  1569. rmtree("$opt_vardir/");
  1570. }
  1571. }
  1572. #
  1573. # Create var and the directories needed in var
  1574. #
  1575. sub setup_vardir() {
  1576. mtr_report("Creating var directory '$opt_vardir'...");
  1577. if ( $opt_vardir eq $default_vardir )
  1578. {
  1579. #
  1580. # Running with "var" in mysql-test dir
  1581. #
  1582. if ( -l $opt_vardir )
  1583. {
  1584. # it's a symlink
  1585. # Make sure the directory where it points exist
  1586. mtr_error("The destination for symlink $opt_vardir does not exist")
  1587. if ! -d readlink($opt_vardir);
  1588. }
  1589. elsif ( $opt_mem )
  1590. {
  1591. # Runinng with "var" as a link to some "memory" location, normally tmpfs
  1592. mtr_verbose("Creating $opt_mem");
  1593. mkpath($opt_mem);
  1594. mtr_report(" - symlinking 'var' to '$opt_mem'");
  1595. symlink($opt_mem, $opt_vardir);
  1596. }
  1597. }
  1598. if ( ! -d $opt_vardir )
  1599. {
  1600. mtr_verbose("Creating $opt_vardir");
  1601. mkpath($opt_vardir);
  1602. }
  1603. # Ensure a proper error message if vardir couldn't be created
  1604. unless ( -d $opt_vardir and -w $opt_vardir )
  1605. {
  1606. mtr_error("Writable 'var' directory is needed, use the " .
  1607. "'--vardir=<path>' option");
  1608. }
  1609. mkpath("$opt_vardir/log");
  1610. mkpath("$opt_vardir/run");
  1611. # Create var/tmp and tmp - they might be different
  1612. mkpath("$opt_vardir/tmp");
  1613. mkpath($opt_tmpdir) if ($opt_tmpdir ne "$opt_vardir/tmp");
  1614. # On some operating systems, there is a limit to the length of a
  1615. # UNIX domain socket's path far below PATH_MAX.
  1616. # Don't allow that to happen
  1617. if (check_socket_path_length("$opt_tmpdir/testsocket.sock")){
  1618. mtr_error("Socket path '$opt_tmpdir' too long, it would be ",
  1619. "truncated and thus not possible to use for connection to ",
  1620. "MySQL Server. Set a shorter with --tmpdir=<path> option");
  1621. }
  1622. # copy all files from std_data into var/std_data
  1623. # and make them writable
  1624. copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data");
  1625. # Remove old log files
  1626. foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
  1627. {
  1628. unlink($name);
  1629. }
  1630. }
  1631. #
  1632. # Check if running as root
  1633. # i.e a file can be read regardless what mode we set it to
  1634. #
  1635. sub check_running_as_root () {
  1636. my $test_file= "$opt_vardir/test_running_as_root.txt";
  1637. mtr_tofile($test_file, "MySQL");
  1638. chmod(oct("0000"), $test_file);
  1639. my $result="";
  1640. if (open(FILE,"<",$test_file))
  1641. {
  1642. $result= join('', <FILE>);
  1643. close FILE;
  1644. }
  1645. # Some filesystems( for example CIFS) allows reading a file
  1646. # although mode was set to 0000, but in that case a stat on
  1647. # the file will not return 0000
  1648. my $file_mode= (stat($test_file))[2] & 07777;
  1649. mtr_verbose("result: $result, file_mode: $file_mode");
  1650. if ($result eq "MySQL" && $file_mode == 0)
  1651. {
  1652. mtr_warning("running this script as _root_ will cause some " .
  1653. "tests to be skipped");
  1654. $ENV{'MYSQL_TEST_ROOT'}= "YES";
  1655. }
  1656. chmod(oct("0755"), $test_file);
  1657. unlink($test_file);
  1658. }
  1659. sub check_ssl_support ($) {
  1660. my $mysqld_variables= shift;
  1661. if ($opt_skip_ssl)
  1662. {
  1663. mtr_report(" - skipping SSL");
  1664. $opt_ssl_supported= 0;
  1665. $opt_ssl= 0;
  1666. return;
  1667. }
  1668. if ( ! $mysqld_variables->{'ssl'} )
  1669. {
  1670. if ( $opt_ssl)
  1671. {
  1672. mtr_error("Couldn't find support for SSL");
  1673. return;
  1674. }
  1675. mtr_report(" - skipping SSL, mysqld not compiled with SSL");
  1676. $opt_ssl_supported= 0;
  1677. $opt_ssl= 0;
  1678. return;
  1679. }
  1680. mtr_report(" - SSL connections supported");
  1681. $opt_ssl_supported= 1;
  1682. }
  1683. sub check_debug_support ($) {
  1684. my $mysqld_variables= shift;
  1685. if ( ! $mysqld_variables->{'debug'} )
  1686. {
  1687. #mtr_report(" - binaries are not debug compiled");
  1688. $debug_compiled_binaries= 0;
  1689. if ( $opt_debug )
  1690. {
  1691. mtr_error("Can't use --debug, binaries does not support it");
  1692. }
  1693. return;
  1694. }
  1695. mtr_report(" - binaries are debug compiled");
  1696. $debug_compiled_binaries= 1;
  1697. }
  1698. #
  1699. # Helper function to handle configuration-based subdirectories which Visual
  1700. # Studio uses for storing binaries. If opt_vs_config is set, this returns
  1701. # a path based on that setting; if not, it returns paths for the default
  1702. # /release/ and /debug/ subdirectories.
  1703. #
  1704. # $exe can be undefined, if the directory itself will be used
  1705. #
  1706. sub vs_config_dirs ($$) {
  1707. my ($path_part, $exe) = @_;
  1708. $exe = "" if not defined $exe;
  1709. # Don't look in these dirs when not on windows
  1710. return () unless IS_WINDOWS;
  1711. if ($opt_vs_config)
  1712. {
  1713. return ("$basedir/$path_part/$opt_vs_config/$exe");
  1714. }
  1715. return ("$basedir/$path_part/release/$exe",
  1716. "$basedir/$path_part/relwithdebinfo/$exe",
  1717. "$basedir/$path_part/debug/$exe");
  1718. }
  1719. sub check_ndbcluster_support ($) {
  1720. my $mysqld_variables= shift;
  1721. if ($opt_skip_ndbcluster)
  1722. {
  1723. mtr_report(" - skipping ndbcluster");
  1724. $opt_skip_ndbcluster_slave= $opt_skip_ndbcluster;
  1725. return;
  1726. }
  1727. if ( ! $mysqld_variables{'ndb-connectstring'} )
  1728. {
  1729. mtr_report(" - skipping ndbcluster, mysqld not compiled with ndbcluster");
  1730. $opt_skip_ndbcluster= 2;
  1731. $opt_skip_ndbcluster_slave= 2;
  1732. return;
  1733. }
  1734. mtr_report(" - using ndbcluster when necessary, mysqld supports it");
  1735. return;
  1736. }
  1737. sub ndbcluster_wait_started($$){
  1738. my $cluster= shift;
  1739. my $ndb_waiter_extra_opt= shift;
  1740. my $path_waitlog= join('/', $opt_vardir, $cluster->name(), "ndb_waiter.log");
  1741. my $args;
  1742. mtr_init_args(\$args);
  1743. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1744. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  1745. mtr_add_arg($args, "--timeout=%d", $opt_start_timeout);
  1746. if ($ndb_waiter_extra_opt)
  1747. {
  1748. mtr_add_arg($args, "$ndb_waiter_extra_opt");
  1749. }
  1750. # Start the ndb_waiter which will connect to the ndb_mgmd
  1751. # and poll it for state of the ndbd's, will return when
  1752. # all nodes in the cluster is started
  1753. my $res= My::SafeProcess->run
  1754. (
  1755. name => "ndb_waiter ".$cluster->name(),
  1756. path => $exe_ndb_waiter,
  1757. args => \$args,
  1758. output => $path_waitlog,
  1759. error => $path_waitlog,
  1760. append => 1,
  1761. );
  1762. # Check that ndb_mgmd(s) are still alive
  1763. foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
  1764. {
  1765. my $proc= $ndb_mgmd->{proc};
  1766. if ( ! $proc->wait_one(0) )
  1767. {
  1768. mtr_warning("$proc died");
  1769. return 2;
  1770. }
  1771. }
  1772. # Check that all started ndbd(s) are still alive
  1773. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  1774. {
  1775. my $proc= $ndbd->{proc};
  1776. next unless defined $proc;
  1777. if ( ! $proc->wait_one(0) )
  1778. {
  1779. mtr_warning("$proc died");
  1780. return 3;
  1781. }
  1782. }
  1783. if ($res)
  1784. {
  1785. mtr_verbose("ndbcluster_wait_started failed");
  1786. return 1;
  1787. }
  1788. return 0;
  1789. }
  1790. sub ndb_mgmd_wait_started($) {
  1791. my ($cluster)= @_;
  1792. my $retries= 100;
  1793. while ($retries)
  1794. {
  1795. my $result= ndbcluster_wait_started($cluster, "--no-contact");
  1796. if ($result == 0)
  1797. {
  1798. # ndb_mgmd is started
  1799. mtr_verbose("ndb_mgmd is started");
  1800. return 0;
  1801. }
  1802. elsif ($result > 1)
  1803. {
  1804. mtr_warning("Cluster process failed while waiting for start");
  1805. return $result;
  1806. }
  1807. mtr_milli_sleep(100);
  1808. $retries--;
  1809. }
  1810. return 1;
  1811. }
  1812. sub ndb_mgmd_start ($$) {
  1813. my ($cluster, $ndb_mgmd)= @_;
  1814. mtr_verbose("ndb_mgmd_start");
  1815. my $dir= $ndb_mgmd->value("DataDir");
  1816. mkpath($dir) unless -d $dir;
  1817. my $args;
  1818. mtr_init_args(\$args);
  1819. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1820. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  1821. mtr_add_arg($args, "--mycnf");
  1822. mtr_add_arg($args, "--nodaemon");
  1823. my $path_ndb_mgmd_log= "$dir/ndb_mgmd.log";
  1824. $ndb_mgmd->{'proc'}= My::SafeProcess->new
  1825. (
  1826. name => $ndb_mgmd->after('cluster_config.'),
  1827. path => $exe_ndb_mgmd,
  1828. args => \$args,
  1829. output => $path_ndb_mgmd_log,
  1830. error => $path_ndb_mgmd_log,
  1831. append => 1,
  1832. verbose => $opt_verbose,
  1833. );
  1834. mtr_verbose("Started $ndb_mgmd->{proc}");
  1835. # FIXME Should not be needed
  1836. # Unfortunately the cluster nodes will fail to start
  1837. # if ndb_mgmd has not started properly
  1838. if (ndb_mgmd_wait_started($cluster))
  1839. {
  1840. mtr_warning("Failed to wait for start of ndb_mgmd");
  1841. return 1;
  1842. }
  1843. return 0;
  1844. }
  1845. sub ndbd_start {
  1846. my ($cluster, $ndbd)= @_;
  1847. mtr_verbose("ndbd_start");
  1848. my $dir= $ndbd->value("DataDir");
  1849. mkpath($dir) unless -d $dir;
  1850. my $args;
  1851. mtr_init_args(\$args);
  1852. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1853. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  1854. mtr_add_arg($args, "--nodaemon");
  1855. # > 5.0 { 'character-sets-dir' => \&fix_charset_dir },
  1856. my $path_ndbd_log= "$dir/ndbd.log";
  1857. my $proc= My::SafeProcess->new
  1858. (
  1859. name => $ndbd->after('cluster_config.'),
  1860. path => $exe_ndbd,
  1861. args => \$args,
  1862. output => $path_ndbd_log,
  1863. error => $path_ndbd_log,
  1864. append => 1,
  1865. verbose => $opt_verbose,
  1866. );
  1867. mtr_verbose("Started $proc");
  1868. $ndbd->{proc}= $proc;
  1869. return;
  1870. }
  1871. sub ndbcluster_start ($) {
  1872. my $cluster= shift;
  1873. mtr_verbose("ndbcluster_start '".$cluster->name()."'");
  1874. foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
  1875. {
  1876. next if started($ndb_mgmd);
  1877. ndb_mgmd_start($cluster, $ndb_mgmd);
  1878. }
  1879. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  1880. {
  1881. next if started($ndbd);
  1882. ndbd_start($cluster, $ndbd);
  1883. }
  1884. return 0;
  1885. }
  1886. sub create_config_file_for_extern {
  1887. my %opts=
  1888. (
  1889. socket => '/tmp/mysqld.sock',
  1890. port => 3306,
  1891. user => $opt_user,
  1892. password => '',
  1893. @_
  1894. );
  1895. mtr_report("Creating my.cnf file for extern server...");
  1896. my $F= IO::File->new($path_config_file, "w")
  1897. or mtr_error("Can't write to $path_config_file: $!");
  1898. print $F "[client]\n";
  1899. while (my ($option, $value)= each( %opts )) {
  1900. print $F "$option= $value\n";
  1901. mtr_report(" $option= $value");
  1902. }
  1903. print $F <<EOF
  1904. # binlog reads from [client] and [mysqlbinlog]
  1905. [mysqlbinlog]
  1906. character-sets-dir= $path_charsetsdir
  1907. # mysql_fix_privilege_tables.sh don't read from [client]
  1908. [mysql_fix_privilege_tables]
  1909. socket = $opts{'socket'}
  1910. port = $opts{'port'}
  1911. user = $opts{'user'}
  1912. password = $opts{'password'}
  1913. EOF
  1914. ;
  1915. $F= undef; # Close file
  1916. }
  1917. #
  1918. # Kill processes left from previous runs, normally
  1919. # there should be none so make sure to warn
  1920. # if there is one
  1921. #
  1922. sub kill_leftovers ($) {
  1923. my $rundir= shift;
  1924. return unless ( -d $rundir );
  1925. mtr_report("Checking leftover processes...");
  1926. # Scan the "run" directory for process id's to kill
  1927. opendir(RUNDIR, $rundir)
  1928. or mtr_error("kill_leftovers, can't open dir \"$rundir\": $!");
  1929. while ( my $elem= readdir(RUNDIR) )
  1930. {
  1931. # Only read pid from files that end with .pid
  1932. if ( $elem =~ /.*[.]pid$/ )
  1933. {
  1934. my $pidfile= "$rundir/$elem";
  1935. next unless -f $pidfile;
  1936. my $pid= mtr_fromfile($pidfile);
  1937. unlink($pidfile);
  1938. unless ($pid=~ /^(\d+)/){
  1939. # The pid was not a valid number
  1940. mtr_warning("Got invalid pid '$pid' from '$elem'");
  1941. next;
  1942. }
  1943. mtr_report(" - found old pid $pid in '$elem', killing it...");
  1944. my $ret= kill(9, $pid);
  1945. if ($ret == 0) {
  1946. mtr_report(" process did not exist!");
  1947. next;
  1948. }
  1949. my $check_counter= 100;
  1950. while ($ret > 0 and $check_counter--) {
  1951. mtr_milli_sleep(100);
  1952. $ret= kill(0, $pid);
  1953. }
  1954. mtr_report($check_counter ? " ok!" : " failed!");
  1955. }
  1956. else
  1957. {
  1958. mtr_warning("Found non pid file '$elem' in '$rundir'")
  1959. if -f "$rundir/$elem";
  1960. }
  1961. }
  1962. closedir(RUNDIR);
  1963. }
  1964. #
  1965. # Check that all the ports that are going to
  1966. # be used are free
  1967. #
  1968. sub check_ports_free
  1969. {
  1970. my @ports_to_check;
  1971. for ($baseport..$baseport+9){
  1972. push(@ports_to_check, $_);
  1973. }
  1974. #mtr_report("Checking ports...");
  1975. # print "@ports_to_check\n";
  1976. foreach my $port (@ports_to_check){
  1977. if (mtr_ping_port($port)){
  1978. mtr_report(" - 'localhost:$port' was not free");
  1979. return 1; # One port was not free
  1980. }
  1981. }
  1982. return 0; # All ports free
  1983. }
  1984. sub initialize_servers {
  1985. if ( using_extern() )
  1986. {
  1987. # Running against an already started server, if the specified
  1988. # vardir does not already exist it should be created
  1989. if ( ! -d $opt_vardir )
  1990. {
  1991. setup_vardir();
  1992. }
  1993. else
  1994. {
  1995. mtr_verbose("No need to create '$opt_vardir' it already exists");
  1996. }
  1997. }
  1998. else
  1999. {
  2000. # Kill leftovers from previous run
  2001. # using any pidfiles found in var/run
  2002. kill_leftovers("$opt_vardir/run");
  2003. if ( ! $opt_start_dirty )
  2004. {
  2005. remove_stale_vardir();
  2006. setup_vardir();
  2007. mysql_install_db(0);
  2008. }
  2009. }
  2010. }
  2011. #
  2012. # Remove all newline characters expect after semicolon
  2013. #
  2014. sub sql_to_bootstrap {
  2015. my ($sql) = @_;
  2016. my @lines= split(/\n/, $sql);
  2017. my $result= "\n";
  2018. my $delimiter= ';';
  2019. foreach my $line (@lines) {
  2020. # Change current delimiter if line starts with "delimiter"
  2021. if ( $line =~ /^delimiter (.*)/ ) {
  2022. my $new= $1;
  2023. # Remove old delimiter from end of new
  2024. $new=~ s/\Q$delimiter\E$//;
  2025. $delimiter = $new;
  2026. mtr_debug("changed delimiter to $delimiter");
  2027. # No need to add the delimiter to result
  2028. next;
  2029. }
  2030. # Add newline if line ends with $delimiter
  2031. # and convert the current delimiter to semicolon
  2032. if ( $line =~ /\Q$delimiter\E$/ ){
  2033. $line =~ s/\Q$delimiter\E$/;/;
  2034. $result.= "$line\n";
  2035. mtr_debug("Added default delimiter");
  2036. next;
  2037. }
  2038. # Remove comments starting with --
  2039. if ( $line =~ /^\s*--/ ) {
  2040. mtr_debug("Discarded $line");
  2041. next;
  2042. }
  2043. # Replace @HOSTNAME with localhost
  2044. $line=~ s/\'\@HOSTNAME\@\'/localhost/;
  2045. # Default, just add the line without newline
  2046. # but with a space as separator
  2047. $result.= "$line ";
  2048. }
  2049. return $result;
  2050. }
  2051. sub mysql_install_db {
  2052. my ($thread_num)= @_;
  2053. my $data_dir= "$opt_vardir/install.db";
  2054. mtr_report("Installing system database...");
  2055. my $args;
  2056. mtr_init_args(\$args);
  2057. mtr_add_arg($args, "--no-defaults");
  2058. mtr_add_arg($args, "--bootstrap");
  2059. mtr_add_arg($args, "--basedir=%s", $basedir);
  2060. mtr_add_arg($args, "--datadir=%s", $data_dir);
  2061. mtr_add_arg($args, "--loose-skip-innodb");
  2062. mtr_add_arg($args, "--loose-skip-ndbcluster");
  2063. mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/");
  2064. mtr_add_arg($args, "--core-file");
  2065. if ( $opt_debug )
  2066. {
  2067. mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap.trace",
  2068. $path_vardir_trace);
  2069. }
  2070. mtr_add_arg($args, "--language=%s", $path_language);
  2071. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  2072. # If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
  2073. # configure --disable-grant-options), mysqld will not recognize the
  2074. # --bootstrap or --skip-grant-tables options. The user can set
  2075. # MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
  2076. # --bootstrap, to accommodate this.
  2077. my $exe_mysqld_bootstrap = $ENV{'MYSQLD_BOOTSTRAP'} || find_mysqld($basedir);
  2078. # ----------------------------------------------------------------------
  2079. # export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
  2080. # ----------------------------------------------------------------------
  2081. $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
  2082. return if $thread_num > 0; # Only generate MYSQLD_BOOTSTRAP_CMD in workers
  2083. # ----------------------------------------------------------------------
  2084. # Create the bootstrap.sql file
  2085. # ----------------------------------------------------------------------
  2086. my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
  2087. if (-f "$path_sql_dir/mysql_system_tables.sql")
  2088. {
  2089. # Use the mysql database for system tables
  2090. mtr_tofile($bootstrap_sql_file, "use mysql\n");
  2091. # Add the offical mysql system tables
  2092. # for a production system
  2093. mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables.sql",
  2094. $bootstrap_sql_file);
  2095. # Add the mysql system tables initial data
  2096. # for a production system
  2097. mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables_data.sql",
  2098. $bootstrap_sql_file);
  2099. # Add test data for timezone - this is just a subset, on a real
  2100. # system these tables will be populated either by mysql_tzinfo_to_sql
  2101. # or by downloading the timezone table package from our website
  2102. mtr_appendfile_to_file("$path_sql_dir/mysql_test_data_timezone.sql",
  2103. $bootstrap_sql_file);
  2104. }
  2105. else
  2106. {
  2107. # Install db from init_db.sql that exist in early 5.1 and 5.0
  2108. # versions of MySQL
  2109. my $init_file= "$basedir/mysql-test/lib/init_db.sql";
  2110. mtr_report(" - from '$init_file'");
  2111. my $text= mtr_grab_file($init_file) or
  2112. mtr_error("Can't open '$init_file': $!");
  2113. mtr_tofile($bootstrap_sql_file,
  2114. sql_to_bootstrap($text));
  2115. }
  2116. # Fill help tables, just an empty file when running from bk repo
  2117. # but will be replaced by a real fill_help_tables.sql when
  2118. # building the source dist
  2119. mtr_appendfile_to_file("$path_sql_dir/fill_help_tables.sql",
  2120. $bootstrap_sql_file);
  2121. # Remove anonymous users
  2122. mtr_tofile($bootstrap_sql_file,
  2123. "DELETE FROM mysql.user where user= '';\n");
  2124. # Create mtr database
  2125. mtr_tofile($bootstrap_sql_file,
  2126. "CREATE DATABASE mtr;\n");
  2127. # Add help tables and data for warning detection and supression
  2128. mtr_tofile($bootstrap_sql_file,
  2129. sql_to_bootstrap(mtr_grab_file("include/mtr_warnings.sql")));
  2130. # Add procedures for checking server is restored after testcase
  2131. mtr_tofile($bootstrap_sql_file,
  2132. sql_to_bootstrap(mtr_grab_file("include/mtr_check.sql")));
  2133. # Log bootstrap command
  2134. my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
  2135. mtr_tofile($path_bootstrap_log,
  2136. "$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
  2137. # Create directories mysql and test
  2138. mkpath("$data_dir/mysql");
  2139. mkpath("$data_dir/test");
  2140. if ( My::SafeProcess->run
  2141. (
  2142. name => "bootstrap",
  2143. path => $exe_mysqld_bootstrap,
  2144. args => \$args,
  2145. input => $bootstrap_sql_file,
  2146. output => $path_bootstrap_log,
  2147. error => $path_bootstrap_log,
  2148. append => 1,
  2149. verbose => $opt_verbose,
  2150. ) != 0)
  2151. {
  2152. mtr_error("Error executing mysqld --bootstrap\n" .
  2153. "Could not install system database from $bootstrap_sql_file\n" .
  2154. "see $path_bootstrap_log for errors");
  2155. }
  2156. }
  2157. sub run_testcase_check_skip_test($)
  2158. {
  2159. my ($tinfo)= @_;
  2160. # ----------------------------------------------------------------------
  2161. # If marked to skip, just print out and return.
  2162. # Note that a test case not marked as 'skip' can still be
  2163. # skipped later, because of the test case itself in cooperation
  2164. # with the mysqltest program tells us so.
  2165. # ----------------------------------------------------------------------
  2166. if ( $tinfo->{'skip'} )
  2167. {
  2168. mtr_report_test_skipped($tinfo);
  2169. return 1;
  2170. }
  2171. return 0;
  2172. }
  2173. sub run_query {
  2174. my ($tinfo, $mysqld, $query)= @_;
  2175. my $args;
  2176. mtr_init_args(\$args);
  2177. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2178. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  2179. mtr_add_arg($args, "-e %s", $query);
  2180. my $res= My::SafeProcess->run
  2181. (
  2182. name => "run_query -> ".$mysqld->name(),
  2183. path => $exe_mysql,
  2184. args => \$args,
  2185. output => '/dev/null',
  2186. error => '/dev/null'
  2187. );
  2188. return $res
  2189. }
  2190. sub do_before_run_mysqltest($)
  2191. {
  2192. my $tinfo= shift;
  2193. # Remove old files produced by mysqltest
  2194. my $base_file= mtr_match_extension($tinfo->{'result_file'},
  2195. "result"); # Trim extension
  2196. unlink("$base_file.reject");
  2197. unlink("$base_file.progress");
  2198. unlink("$base_file.log");
  2199. unlink("$base_file.warnings");
  2200. if ( $mysql_version_id < 50000 ) {
  2201. # Set environment variable NDB_STATUS_OK to 1
  2202. # if script decided to run mysqltest cluster _is_ installed ok
  2203. $ENV{'NDB_STATUS_OK'} = "1";
  2204. } elsif ( $mysql_version_id < 50100 ) {
  2205. # Set environment variable NDB_STATUS_OK to YES
  2206. # if script decided to run mysqltest cluster _is_ installed ok
  2207. $ENV{'NDB_STATUS_OK'} = "YES";
  2208. }
  2209. }
  2210. #
  2211. # Check all server for sideffects
  2212. #
  2213. # RETURN VALUE
  2214. # 0 ok
  2215. # 1 Check failed
  2216. # >1 Fatal errro
  2217. sub check_testcase($$)
  2218. {
  2219. my ($tinfo, $mode)= @_;
  2220. my $tname= $tinfo->{name};
  2221. # Start the mysqltest processes in parallel to save time
  2222. # also makes it possible to wait for any process to exit during the check
  2223. my %started;
  2224. foreach my $mysqld ( mysqlds() )
  2225. {
  2226. if ( defined $mysqld->{'proc'} )
  2227. {
  2228. my $proc= start_check_testcase($tinfo, $mode, $mysqld);
  2229. $started{$proc->pid()}= $proc;
  2230. }
  2231. }
  2232. # Return immediately if no check proceess was started
  2233. return 0 unless ( keys %started );
  2234. while (1){
  2235. my $result;
  2236. my $proc= My::SafeProcess->wait_any();
  2237. mtr_report("Got $proc");
  2238. if ( delete $started{$proc->pid()} ) {
  2239. my $err_file= $proc->user_data();
  2240. my $base_file= mtr_match_extension($err_file, "err"); # Trim extension
  2241. # One check testcase process returned
  2242. my $res= $proc->exit_status();
  2243. if ( $res == 0){
  2244. # Check completed without problem
  2245. # Remove the .err file the check generated
  2246. unlink($err_file);
  2247. # Remove the .result file the check generated
  2248. if ( $mode eq 'after' ){
  2249. unlink("$base_file.result");
  2250. }
  2251. if ( keys(%started) == 0){
  2252. # All checks completed
  2253. return 0;
  2254. }
  2255. # Wait for next process to exit
  2256. next;
  2257. }
  2258. else
  2259. {
  2260. if ( $mode eq "after" and $res == 1 )
  2261. {
  2262. # Test failed, grab the report mysqltest has created
  2263. my $report= mtr_grab_file($err_file);
  2264. $tinfo->{check}.=
  2265. "\nThe check of testcase '$tname' failed, this is the\n".
  2266. "diff between before and after:\n";
  2267. $tinfo->{check}.= $report;
  2268. # Check failed, mark the test case with that info
  2269. $tinfo->{'check_testcase_failed'}= 1;
  2270. $result= 1;
  2271. }
  2272. elsif ( $res )
  2273. {
  2274. my $report= mtr_grab_file($err_file);
  2275. $tinfo->{comment}.=
  2276. "Could not execute 'check-testcase' $mode testcase '$tname':\n";
  2277. $tinfo->{comment}.= $report;
  2278. $result= 2;
  2279. }
  2280. # Remove the .err file the check generated
  2281. unlink($err_file);
  2282. # Remove the .result file the check generated
  2283. unlink("$base_file.result");
  2284. }
  2285. }
  2286. else {
  2287. # Unknown process returned, most likley a crash, abort everything
  2288. $tinfo->{comment}=
  2289. "Unexpected process $proc returned during ".
  2290. "check testcase $mode test";
  2291. $result= 3;
  2292. }
  2293. # Kill any check processes still running
  2294. map($_->kill(), values(%started));
  2295. return $result;
  2296. }
  2297. }
  2298. # Start run mysqltest on one server
  2299. #
  2300. # RETURN VALUE
  2301. # 0 OK
  2302. # 1 Check failed
  2303. #
  2304. sub start_run_one ($$) {
  2305. my ($mysqld, $run)= @_;
  2306. my $name= "$run-".$mysqld->name();
  2307. my $args;
  2308. mtr_init_args(\$args);
  2309. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2310. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  2311. mtr_add_arg($args, "--silent");
  2312. mtr_add_arg($args, "--skip-safemalloc");
  2313. mtr_add_arg($args, "--test-file=%s", "include/$run.test");
  2314. my $errfile= "$opt_vardir/tmp/$name.err";
  2315. my $proc= My::SafeProcess->new
  2316. (
  2317. name => $name,
  2318. path => $exe_mysqltest,
  2319. error => $errfile,
  2320. output => $errfile,
  2321. args => \$args,
  2322. user_data => $errfile,
  2323. );
  2324. mtr_verbose("Started $proc");
  2325. return $proc;
  2326. }
  2327. #
  2328. # Run script on all servers, collect results
  2329. #
  2330. # RETURN VALUE
  2331. # 0 ok
  2332. # 1 Failure
  2333. sub run_on_all($$)
  2334. {
  2335. my ($tinfo, $run)= @_;
  2336. # Start the mysqltest processes in parallel to save time
  2337. # also makes it possible to wait for any process to exit during the check
  2338. # and to have a timeout process
  2339. my %started;
  2340. foreach my $mysqld ( mysqlds() )
  2341. {
  2342. if ( defined $mysqld->{'proc'} )
  2343. {
  2344. my $proc= start_run_one($mysqld, $run);
  2345. $started{$proc->pid()}= $proc;
  2346. }
  2347. }
  2348. # Return immediately if no check proceess was started
  2349. return 0 unless ( keys %started );
  2350. my $timeout_proc= My::SafeProcess->timer(60); # Seconds
  2351. while (1){
  2352. my $result;
  2353. my $proc= My::SafeProcess->wait_any();
  2354. mtr_report("Got $proc");
  2355. if ( delete $started{$proc->pid()} ) {
  2356. # One mysqltest process returned
  2357. my $err_file= $proc->user_data();
  2358. my $res= $proc->exit_status();
  2359. # Append the report from .err file
  2360. $tinfo->{comment}.= " == $err_file ==\n";
  2361. $tinfo->{comment}.= mtr_grab_file($err_file);
  2362. $tinfo->{comment}.= "\n";
  2363. # Remove the .err file
  2364. unlink($err_file);
  2365. if ( keys(%started) == 0){
  2366. # All completed
  2367. $timeout_proc->kill();
  2368. return 0;
  2369. }
  2370. # Wait for next process to exit
  2371. next;
  2372. }
  2373. elsif ( $proc eq $timeout_proc ) {
  2374. $tinfo->{comment}.= "Timeout $timeout_proc expired for running '$run'";
  2375. }
  2376. else {
  2377. # Unknown process returned, most likley a crash, abort everything
  2378. $tinfo->{comment}.=
  2379. "Unexpected process $proc returned during ".
  2380. "execution of '$run'";
  2381. }
  2382. # Kill any check processes still running
  2383. map($_->kill(), values(%started));
  2384. $timeout_proc->kill();
  2385. return 1;
  2386. }
  2387. }
  2388. sub mark_log {
  2389. my ($log, $tinfo)= @_;
  2390. my $log_msg= "CURRENT_TEST: $tinfo->{name}\n";
  2391. mtr_tofile($log, $log_msg);
  2392. }
  2393. sub find_testcase_skipped_reason($)
  2394. {
  2395. my ($tinfo)= @_;
  2396. # Set default message
  2397. $tinfo->{'comment'}= "Detected by testcase(no log file)";
  2398. # Open the test log file
  2399. my $F= IO::File->new($path_current_testlog)
  2400. or return;
  2401. my $reason;
  2402. while ( my $line= <$F> )
  2403. {
  2404. # Look for "reason: <reason for skipping test>"
  2405. if ( $line =~ /reason: (.*)/ )
  2406. {
  2407. $reason= $1;
  2408. }
  2409. }
  2410. if ( ! $reason )
  2411. {
  2412. mtr_warning("Could not find reason for skipping test in $path_current_testlog");
  2413. $reason= "Detected by testcase(reason unknown) ";
  2414. }
  2415. $tinfo->{'comment'}= $reason;
  2416. }
  2417. sub find_analyze_request
  2418. {
  2419. # Open the test log file
  2420. my $F= IO::File->new($path_current_testlog)
  2421. or return;
  2422. my $analyze;
  2423. while ( my $line= <$F> )
  2424. {
  2425. # Look for "reason: <reason for skipping test>"
  2426. if ( $line =~ /analyze: (.*)/ )
  2427. {
  2428. $analyze= $1;
  2429. }
  2430. }
  2431. return $analyze;
  2432. }
  2433. # Return timezone value of tinfo or default value
  2434. sub timezone {
  2435. my ($tinfo)= @_;
  2436. return $tinfo->{timezone} || "GMT-3";
  2437. }
  2438. # Storage for changed environment variables
  2439. my %old_env;
  2440. #
  2441. # Run a single test case
  2442. #
  2443. # RETURN VALUE
  2444. # 0 OK
  2445. # > 0 failure
  2446. #
  2447. sub run_testcase ($) {
  2448. my $tinfo= shift;
  2449. mtr_verbose("Running test:", $tinfo->{name});
  2450. # -------------------------------------------------------
  2451. # Init variables that can change between each test case
  2452. # -------------------------------------------------------
  2453. my $timezone= timezone($tinfo);
  2454. $ENV{'TZ'}= $timezone;
  2455. mtr_verbose("Setting timezone: $timezone");
  2456. if ( ! using_extern() )
  2457. {
  2458. my @restart= servers_need_restart($tinfo);
  2459. if ( @restart != 0) {
  2460. stop_servers($tinfo, @restart );
  2461. }
  2462. if ( started(all_servers()) == 0 )
  2463. {
  2464. # Remove old datadirs
  2465. clean_datadir();
  2466. # Restore old ENV
  2467. while (my ($option, $value)= each( %old_env )) {
  2468. if (defined $value){
  2469. mtr_verbose("Restoring $option to $value");
  2470. $ENV{$option}= $value;
  2471. } else {
  2472. mtr_verbose("Removing $option");
  2473. delete($ENV{$option});
  2474. }
  2475. }
  2476. %old_env= ();
  2477. mtr_verbose("Generating my.cnf from '$tinfo->{template_path}'");
  2478. # Generate new config file from template
  2479. $config= My::ConfigFactory->new_config
  2480. ( {
  2481. basedir => $basedir,
  2482. template_path => $tinfo->{template_path},
  2483. extra_template_path => $tinfo->{extra_template_path},
  2484. vardir => $opt_vardir,
  2485. tmpdir => $opt_tmpdir,
  2486. baseport => $baseport,
  2487. #hosts => [ 'host1', 'host2' ],
  2488. user => $opt_user,
  2489. password => '',
  2490. ssl => $opt_ssl_supported,
  2491. embedded => $opt_embedded_server,
  2492. }
  2493. );
  2494. # Write the new my.cnf
  2495. $config->save($path_config_file);
  2496. # Remember current config so a restart can occur when a test need
  2497. # to use a different one
  2498. $current_config_name= $tinfo->{template_path};
  2499. #
  2500. # Set variables in the ENV section
  2501. #
  2502. foreach my $option ($config->options_in_group("ENV"))
  2503. {
  2504. # Save old value to restore it before next time
  2505. $old_env{$option->name()}= $ENV{$option->name()};
  2506. mtr_verbose($option->name(), "=",$option->value());
  2507. $ENV{$option->name()}= $option->value();
  2508. }
  2509. }
  2510. # Write start of testcase to log
  2511. mark_log($path_current_testlog, $tinfo);
  2512. if (start_servers($tinfo))
  2513. {
  2514. report_failure_and_restart($tinfo);
  2515. return 1;
  2516. }
  2517. }
  2518. # --------------------------------------------------------------------
  2519. # If --start or --start-dirty given, stop here to let user manually
  2520. # run tests
  2521. # ----------------------------------------------------------------------
  2522. if ( $opt_start or $opt_start_dirty )
  2523. {
  2524. mtr_print("\nStarted", started(all_servers()));
  2525. mtr_print("Waiting for server(s) to exit...");
  2526. my $proc= My::SafeProcess->wait_any();
  2527. if ( grep($proc eq $_, started(all_servers())) )
  2528. {
  2529. mtr_print("Server $proc died");
  2530. exit(1);
  2531. }
  2532. mtr_print("Unknown process $proc died");
  2533. exit(1);
  2534. }
  2535. my $test_timeout_proc= My::SafeProcess->timer($opt_testcase_timeout * 60);
  2536. do_before_run_mysqltest($tinfo);
  2537. if ( $opt_check_testcases and check_testcase($tinfo, "before") ){
  2538. # Failed to record state of server or server crashed
  2539. report_failure_and_restart($tinfo);
  2540. # Stop the test case timer
  2541. $test_timeout_proc->kill();
  2542. return 1;
  2543. }
  2544. my $test= start_mysqltest($tinfo);
  2545. while (1)
  2546. {
  2547. my $proc= My::SafeProcess->wait_any();
  2548. unless ( defined $proc )
  2549. {
  2550. mtr_error("wait_any failed");
  2551. }
  2552. mtr_verbose("Got $proc");
  2553. # ----------------------------------------------------
  2554. # Was it the test program that exited
  2555. # ----------------------------------------------------
  2556. if ($proc eq $test)
  2557. {
  2558. # Stop the test case timer
  2559. $test_timeout_proc->kill();
  2560. my $res= $test->exit_status();
  2561. if ( $res == 0 )
  2562. {
  2563. if ( $opt_warnings and check_warnings($tinfo) )
  2564. {
  2565. # Found unexpected warnings
  2566. report_failure_and_restart($tinfo);
  2567. $res= 1;
  2568. }
  2569. else
  2570. {
  2571. mtr_report_test_passed($tinfo);
  2572. }
  2573. my $check_res;
  2574. if ( $opt_check_testcases and
  2575. $check_res= check_testcase($tinfo, "after"))
  2576. {
  2577. if ($check_res == 1) {
  2578. # Test case had sideeffects, not fatal error, just continue
  2579. stop_all_servers();
  2580. mtr_report("Resuming tests...\n");
  2581. }
  2582. else {
  2583. # Test case check failed fatally, probably a server crashed
  2584. report_failure_and_restart($tinfo);
  2585. return 1;
  2586. }
  2587. }
  2588. }
  2589. elsif ( $res == 62 )
  2590. {
  2591. # Testcase itself tell us to skip this one
  2592. $tinfo->{skip_detected_by_test}= 1;
  2593. # Try to get reason from test log file
  2594. find_testcase_skipped_reason($tinfo);
  2595. mtr_report_test_skipped($tinfo);
  2596. }
  2597. elsif ( $res == 65 )
  2598. {
  2599. # Testprogram killed by signal
  2600. $tinfo->{comment}=
  2601. "testprogram crashed(returned code $res)";
  2602. report_failure_and_restart($tinfo);
  2603. }
  2604. elsif ( $res == 1 )
  2605. {
  2606. # Check if the test tool requests that
  2607. # an analyze script should be run
  2608. my $analyze= find_analyze_request();
  2609. if ($analyze){
  2610. run_on_all($tinfo, "analyze-$analyze");
  2611. }
  2612. # Test case failure reported by mysqltest
  2613. report_failure_and_restart($tinfo);
  2614. }
  2615. else
  2616. {
  2617. # mysqltest failed, probably crashed
  2618. $tinfo->{comment}=
  2619. "mysqltest failed with unexpected return code $res";
  2620. report_failure_and_restart($tinfo);
  2621. }
  2622. # Save info from this testcase run to mysqltest.log
  2623. if( -f $path_current_testlog)
  2624. {
  2625. mtr_appendfile_to_file($path_current_testlog, $path_testlog);
  2626. unlink($path_current_testlog);
  2627. }
  2628. return ($res == 62) ? 0 : $res;
  2629. }
  2630. # ----------------------------------------------------
  2631. # Check if it was an expected crash
  2632. # ----------------------------------------------------
  2633. if ( check_expected_crash_and_restart($proc) )
  2634. {
  2635. next;
  2636. }
  2637. # ----------------------------------------------------
  2638. # Stop the test case timer
  2639. # ----------------------------------------------------
  2640. $test_timeout_proc->kill();
  2641. # ----------------------------------------------------
  2642. # It's not mysqltest that has exited, kill it
  2643. # ----------------------------------------------------
  2644. $test->kill();
  2645. # ----------------------------------------------------
  2646. # Check if it was a server that died
  2647. # ----------------------------------------------------
  2648. if ( grep($proc eq $_, started(all_servers())) )
  2649. {
  2650. # Server failed, probably crashed
  2651. $tinfo->{comment}=
  2652. "Server $proc failed during test run";
  2653. report_failure_and_restart($tinfo);
  2654. return 1;
  2655. }
  2656. # ----------------------------------------------------
  2657. # Check if testcase timer expired
  2658. # ----------------------------------------------------
  2659. if ( $proc eq $test_timeout_proc )
  2660. {
  2661. $tinfo->{comment}=
  2662. "Test case timeout after $opt_testcase_timeout minute(s)\n\n";
  2663. $tinfo->{'timeout'}= $opt_testcase_timeout; # Mark as timeout
  2664. run_on_all($tinfo, 'analyze-timeout');
  2665. report_failure_and_restart($tinfo);
  2666. return 1;
  2667. }
  2668. mtr_error("Unhandled process $proc exited");
  2669. }
  2670. mtr_error("Should never come here");
  2671. }
  2672. # Run include/check-warnings.test
  2673. #
  2674. # RETURN VALUE
  2675. # 0 OK
  2676. # 1 Check failed
  2677. #
  2678. sub start_check_warnings ($$) {
  2679. my $tinfo= shift;
  2680. my $mysqld= shift;
  2681. my $name= "warnings-".$mysqld->name();
  2682. my $args;
  2683. mtr_init_args(\$args);
  2684. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2685. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  2686. mtr_add_arg($args, "--silent");
  2687. mtr_add_arg($args, "--skip-safemalloc");
  2688. mtr_add_arg($args, "--test-file=%s", "include/check-warnings.test");
  2689. if ( $opt_embedded_server )
  2690. {
  2691. # Get the args needed for the embedded server
  2692. # and append them to args prefixed
  2693. # with --sever-arg=
  2694. my $mysqld= $config->group('embedded')
  2695. or mtr_error("Could not get [embedded] section");
  2696. my $mysqld_args;
  2697. mtr_init_args(\$mysqld_args);
  2698. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  2699. mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
  2700. mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
  2701. }
  2702. my $errfile= "$opt_vardir/tmp/$name.err";
  2703. my $proc= My::SafeProcess->new
  2704. (
  2705. name => $name,
  2706. path => $exe_mysqltest,
  2707. error => $errfile,
  2708. output => $errfile,
  2709. args => \$args,
  2710. user_data => $errfile,
  2711. );
  2712. mtr_verbose("Started $proc");
  2713. return $proc;
  2714. }
  2715. #
  2716. # Loop through our list of processes and check the error log
  2717. # for unexepcted errors and warnings
  2718. #
  2719. sub check_warnings ($) {
  2720. my ($tinfo)= @_;
  2721. my $res= 0;
  2722. my $tname= $tinfo->{name};
  2723. # Clear previous warnings
  2724. delete($tinfo->{warnings});
  2725. # Start the mysqltest processes in parallel to save time
  2726. # also makes it possible to wait for any process to exit during the check
  2727. my %started;
  2728. foreach my $mysqld ( mysqlds() )
  2729. {
  2730. if ( defined $mysqld->{'proc'} )
  2731. {
  2732. my $proc= start_check_warnings($tinfo, $mysqld);
  2733. $started{$proc->pid()}= $proc;
  2734. }
  2735. }
  2736. # Return immediately if no check proceess was started
  2737. return 0 unless ( keys %started );
  2738. while (1){
  2739. my $result= 0;
  2740. my $proc= My::SafeProcess->wait_any();
  2741. mtr_report("Got $proc");
  2742. if ( delete $started{$proc->pid()} ) {
  2743. # One check warning process returned
  2744. my $res= $proc->exit_status();
  2745. my $err_file= $proc->user_data();
  2746. if ( $res == 0 or $res == 62 ){
  2747. if ( $res == 0 ) {
  2748. # Check completed with problem
  2749. my $report= mtr_grab_file($err_file);
  2750. # Log to var/log/warnings file
  2751. mtr_tofile("$opt_vardir/log/warnings",
  2752. $tname."\n".$report);
  2753. $tinfo->{'warnings'}.= $report;
  2754. $result= 1;
  2755. }
  2756. if ( $res == 62 ) {
  2757. # Test case was ok and called "skip"
  2758. ;
  2759. }
  2760. # Remove the .err file the check generated
  2761. unlink($err_file);
  2762. if ( keys(%started) == 0){
  2763. # All checks completed
  2764. return $result;
  2765. }
  2766. # Wait for next process to exit
  2767. next;
  2768. }
  2769. else
  2770. {
  2771. my $report= mtr_grab_file($err_file);
  2772. $tinfo->{comment}.=
  2773. "Could not execute 'check-warnings' for testcase '$tname':";
  2774. $tinfo->{comment}.= $report;
  2775. $result= 2;
  2776. }
  2777. # Remove the .err file the check generated
  2778. unlink($err_file);
  2779. }
  2780. else {
  2781. # Unknown process returned, most likley a crash, abort everything
  2782. $tinfo->{comment}=
  2783. "Unexpected process $proc returned during ".
  2784. "check warnings";
  2785. $result= 3;
  2786. }
  2787. # Kill any check processes still running
  2788. map($_->kill(), values(%started));
  2789. return $result;
  2790. }
  2791. return $res;
  2792. return $res;
  2793. }
  2794. #
  2795. # Loop through our list of processes and look for and entry
  2796. # with the provided pid, if found check for the file indicating
  2797. # expected crash and restart it.
  2798. #
  2799. sub check_expected_crash_and_restart {
  2800. my ($proc)= @_;
  2801. foreach my $mysqld ( mysqlds() )
  2802. {
  2803. next unless ( $mysqld->{proc} eq $proc );
  2804. # Check if crash expected by looking at the .expect file
  2805. # in var/tmp
  2806. my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
  2807. if ( -f $expect_file )
  2808. {
  2809. mtr_verbose("Crash was expected, file '$expect_file' exists");
  2810. while (1){
  2811. # If last line in expect file starts with "wait"
  2812. # sleep a little and try again, thus allowing the
  2813. # test script to control when the server should start
  2814. # up again
  2815. my $last_line= mtr_lastlinefromfile($expect_file);
  2816. if ($last_line =~ /^wait/ )
  2817. {
  2818. mtr_verbose("Test says wait before restart");
  2819. mtr_milli_sleep(100);
  2820. next;
  2821. }
  2822. unlink($expect_file);
  2823. # Start server with same settings as last time
  2824. mysqld_start($mysqld, $mysqld->{'started_opts'});
  2825. last;
  2826. }
  2827. }
  2828. return 1;
  2829. }
  2830. # Not an expected crash
  2831. return 0;
  2832. }
  2833. # Remove all files and subdirectories of a directory
  2834. sub clean_dir {
  2835. my ($dir)= @_;
  2836. mtr_verbose("clean_dir: $dir");
  2837. finddepth(
  2838. { no_chdir => 1,
  2839. wanted => sub {
  2840. if (-d $_){
  2841. # A dir
  2842. if ($_ eq $dir){
  2843. # The dir to clean
  2844. return;
  2845. } else {
  2846. mtr_verbose("rmdir: '$_'");
  2847. rmdir($_) or mtr_warning("rmdir($_) failed: $!");
  2848. }
  2849. } else {
  2850. # Hopefully a file
  2851. mtr_verbose("unlink: '$_'");
  2852. unlink($_) or mtr_warning("unlink($_) failed: $!");
  2853. }
  2854. }
  2855. },
  2856. $dir);
  2857. }
  2858. sub clean_datadir {
  2859. mtr_verbose("Cleaning datadirs...");
  2860. if (started(all_servers()) != 0){
  2861. mtr_error("Trying to clean datadir before all servers stopped");
  2862. }
  2863. foreach my $cluster ( clusters() )
  2864. {
  2865. my $cluster_dir= "$opt_vardir/".$cluster->{name};
  2866. mtr_verbose(" - removing '$cluster_dir'");
  2867. rmtree($cluster_dir);
  2868. }
  2869. foreach my $mysqld ( mysqlds() )
  2870. {
  2871. my $mysqld_dir= dirname($mysqld->value('datadir'));
  2872. if (-d $mysqld_dir ) {
  2873. mtr_verbose(" - removing '$mysqld_dir'");
  2874. rmtree($mysqld_dir);
  2875. }
  2876. }
  2877. # Remove all files in tmp and var/tmp
  2878. clean_dir("$opt_vardir/tmp");
  2879. if ($opt_tmpdir ne "$opt_vardir/tmp"){
  2880. clean_dir($opt_tmpdir);
  2881. }
  2882. }
  2883. #
  2884. # Save datadir before it's removed
  2885. #
  2886. sub save_datadir_after_failure($$) {
  2887. my ($dir, $savedir)= @_;
  2888. mtr_report(" - saving '$dir'");
  2889. my $dir_name= basename($dir);
  2890. rename("$dir", "$savedir/$dir_name");
  2891. }
  2892. sub after_failure ($) {
  2893. my ($tinfo)= @_;
  2894. mtr_report("Saving datadirs...");
  2895. my $save_dir= "$opt_vardir/log/";
  2896. $save_dir.= $tinfo->{name};
  2897. # Add combination name if any
  2898. $save_dir.= "-$tinfo->{combination}"
  2899. if defined $tinfo->{combination};
  2900. # Save savedir path for server
  2901. $tinfo->{savedir}= $save_dir;
  2902. mkpath($save_dir) if ! -d $save_dir;
  2903. # Save the used my.cnf file
  2904. copy($path_config_file, $save_dir);
  2905. # Copy the tmp dir
  2906. copytree("$opt_vardir/tmp/", "$save_dir/tmp/");
  2907. if ( clusters() ) {
  2908. foreach my $cluster ( clusters() ) {
  2909. my $cluster_dir= "$opt_vardir/".$cluster->{name};
  2910. save_datadir_after_failure($cluster_dir, $save_dir);
  2911. }
  2912. }
  2913. else {
  2914. foreach my $mysqld ( mysqlds() ) {
  2915. my $data_dir= $mysqld->value('datadir');
  2916. save_datadir_after_failure(dirname($data_dir), $save_dir);
  2917. }
  2918. }
  2919. }
  2920. sub report_failure_and_restart ($) {
  2921. my $tinfo= shift;
  2922. stop_all_servers();
  2923. $tinfo->{'result'}= 'MTR_RES_FAILED';
  2924. my $test_failures= $tinfo->{'failures'} || 0;
  2925. $tinfo->{'failures'}= $test_failures + 1;
  2926. if ( $tinfo->{comment} )
  2927. {
  2928. # The test failure has been detected by mysql-test-run.pl
  2929. # when starting the servers or due to other error, the reason for
  2930. # failing the test is saved in "comment"
  2931. ;
  2932. }
  2933. if ( !defined $tinfo->{logfile} )
  2934. {
  2935. my $logfile= $path_current_testlog;
  2936. if ( defined $logfile )
  2937. {
  2938. if ( -f $logfile )
  2939. {
  2940. # Test failure was detected by test tool and its report
  2941. # about what failed has been saved to file. Save the report
  2942. # in tinfo
  2943. $tinfo->{logfile}= mtr_fromfile($logfile);
  2944. }
  2945. else
  2946. {
  2947. # The test tool report didn't exist, display an
  2948. # error message
  2949. $tinfo->{logfile}= "Could not open test tool report '$logfile'";
  2950. }
  2951. }
  2952. }
  2953. after_failure($tinfo);
  2954. mtr_report_test($tinfo);
  2955. }
  2956. sub run_sh_script {
  2957. my ($script)= @_;
  2958. return 0 unless defined $script;
  2959. mtr_verbose("Running '$script'");
  2960. my $ret= system("/bin/sh $script") >> 8;
  2961. return $ret;
  2962. }
  2963. sub mysqld_stop {
  2964. my $mysqld= shift or die "usage: mysqld_stop(<mysqld>)";
  2965. my $args;
  2966. mtr_init_args(\$args);
  2967. mtr_add_arg($args, "--no-defaults");
  2968. mtr_add_arg($args, "--user=%s", $opt_user);
  2969. mtr_add_arg($args, "--password=");
  2970. mtr_add_arg($args, "--port=%d", $mysqld->value('port'));
  2971. mtr_add_arg($args, "--host=%s", $mysqld->value('#host'));
  2972. mtr_add_arg($args, "--connect_timeout=20");
  2973. mtr_add_arg($args, "--protocol=tcp");
  2974. mtr_add_arg($args, "shutdown");
  2975. My::SafeProcess->run
  2976. (
  2977. name => "mysqladmin shutdown ".$mysqld->name(),
  2978. path => $exe_mysqladmin,
  2979. args => \$args,
  2980. error => "/dev/null",
  2981. );
  2982. }
  2983. sub mysqld_arguments ($$$) {
  2984. my $args= shift;
  2985. my $mysqld= shift;
  2986. my $extra_opts= shift;
  2987. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2988. # When mysqld is run by a root user(euid is 0), it will fail
  2989. # to start unless we specify what user to run as, see BUG#30630
  2990. my $euid= $>;
  2991. if (!IS_WINDOWS and $euid == 0 and
  2992. (grep(/^--user/, @$extra_opts)) == 0) {
  2993. mtr_add_arg($args, "--user=root");
  2994. }
  2995. if ( $opt_valgrind_mysqld )
  2996. {
  2997. mtr_add_arg($args, "--skip-safemalloc");
  2998. if ( $mysql_version_id < 50100 )
  2999. {
  3000. mtr_add_arg($args, "--skip-bdb");
  3001. }
  3002. }
  3003. if ( $mysql_version_id >= 50106 )
  3004. {
  3005. # Turn on logging to both tables and file
  3006. mtr_add_arg($args, "--log-output=table,file");
  3007. }
  3008. # Check if "extra_opt" contains skip-log-bin
  3009. my $skip_binlog= grep(/^(--|--loose-)skip-log-bin/, @$extra_opts);
  3010. # Indicate to mysqld it will be debugged in debugger
  3011. if ( $glob_debugger )
  3012. {
  3013. mtr_add_arg($args, "--gdb");
  3014. }
  3015. my $found_skip_core= 0;
  3016. foreach my $arg ( @$extra_opts )
  3017. {
  3018. # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
  3019. if ($arg eq "--skip-core-file")
  3020. {
  3021. $found_skip_core= 1;
  3022. }
  3023. elsif ($skip_binlog and mtr_match_prefix($arg, "--binlog-format"))
  3024. {
  3025. ; # Dont add --binlog-format when running without binlog
  3026. }
  3027. elsif ($arg eq "--loose-skip-log-bin" and
  3028. $mysqld->option("log-slave-updates"))
  3029. {
  3030. ; # Dont add --skip-log-bin when mysqld have --log-slave-updates in config
  3031. }
  3032. else
  3033. {
  3034. mtr_add_arg($args, "%s", $arg);
  3035. }
  3036. }
  3037. if ( !$found_skip_core )
  3038. {
  3039. mtr_add_arg($args, "%s", "--core-file");
  3040. }
  3041. return $args;
  3042. }
  3043. sub mysqld_start ($$) {
  3044. my $mysqld= shift;
  3045. my $extra_opts= shift;
  3046. mtr_verbose(My::Options::toStr("mysqld_start", @$extra_opts));
  3047. my $exe= find_mysqld($mysqld->value('basedir'));
  3048. my $wait_for_pid_file= 1;
  3049. mtr_error("Internal error: mysqld should never be started for embedded")
  3050. if $opt_embedded_server;
  3051. my $args;
  3052. mtr_init_args(\$args);
  3053. if ( $opt_valgrind_mysqld )
  3054. {
  3055. valgrind_arguments($args, \$exe);
  3056. }
  3057. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  3058. mysqld_arguments($args,$mysqld,$extra_opts);
  3059. if ( $opt_debug )
  3060. {
  3061. mtr_add_arg($args, "--debug=d:t:i:A,%s/log/%s.trace",
  3062. $path_vardir_trace, $mysqld->name());
  3063. }
  3064. if ( $opt_gdb || $opt_manual_gdb )
  3065. {
  3066. gdb_arguments(\$args, \$exe, $mysqld->name());
  3067. }
  3068. elsif ( $opt_ddd || $opt_manual_ddd )
  3069. {
  3070. ddd_arguments(\$args, \$exe, $mysqld->name());
  3071. }
  3072. elsif ( $opt_debugger )
  3073. {
  3074. debugger_arguments(\$args, \$exe, $mysqld->name());
  3075. }
  3076. elsif ( $opt_manual_debug )
  3077. {
  3078. print "\nStart " .$mysqld->name()." in your debugger\n" .
  3079. "dir: $glob_mysql_test_dir\n" .
  3080. "exe: $exe\n" .
  3081. "args: " . join(" ", @$args) . "\n\n" .
  3082. "Waiting ....\n";
  3083. # Indicate the exe should not be started
  3084. $exe= undef;
  3085. }
  3086. else
  3087. {
  3088. # Default to not wait until pid file has been created
  3089. $wait_for_pid_file= 0;
  3090. }
  3091. # Remove the old pidfile if any
  3092. unlink($mysqld->value('pid-file'));
  3093. my $output= $mysqld->value('log-error');
  3094. if ( $opt_valgrind and $opt_debug )
  3095. {
  3096. # When both --valgrind and --debug is selected, send
  3097. # all output to the trace file, making it possible to
  3098. # see the exact location where valgrind complains
  3099. $output= "$opt_vardir/log/".$mysqld->name().".trace";
  3100. }
  3101. if ( defined $exe )
  3102. {
  3103. $mysqld->{'proc'}= My::SafeProcess->new
  3104. (
  3105. name => $mysqld->name(),
  3106. path => $exe,
  3107. args => \$args,
  3108. output => $output,
  3109. error => $output,
  3110. append => 1,
  3111. verbose => $opt_verbose,
  3112. host => undef,
  3113. shutdown => sub { mysqld_stop($mysqld) },
  3114. );
  3115. mtr_verbose("Started $mysqld->{proc}");
  3116. }
  3117. if ( $wait_for_pid_file &&
  3118. !sleep_until_file_created($mysqld->value('pid-file'),
  3119. $opt_start_timeout,
  3120. $mysqld->{'proc'}))
  3121. {
  3122. mtr_error("Failed to start mysqld $mysqld->name()");
  3123. }
  3124. # Remember options used when starting
  3125. $mysqld->{'started_opts'}= $extra_opts;
  3126. return;
  3127. }
  3128. sub stop_all_servers () {
  3129. mtr_verbose("Stopping all servers...");
  3130. # Kill all started servers
  3131. My::SafeProcess::shutdown(0, # shutdown timeout 0 => kill
  3132. started(all_servers()));
  3133. # Remove pidfiles
  3134. foreach my $server ( all_servers() )
  3135. {
  3136. my $pid_file= $server->if_exist('pid-file');
  3137. unlink($pid_file) if defined $pid_file;
  3138. }
  3139. # Mark servers as stopped
  3140. map($_->{proc}= undef, all_servers());
  3141. }
  3142. # Find out if server should be restarted for this test
  3143. sub server_need_restart {
  3144. my ($tinfo, $server)= @_;
  3145. if ( using_extern() )
  3146. {
  3147. mtr_verbose_restart($server, "no restart for --extern server");
  3148. return 0;
  3149. }
  3150. if ( $opt_embedded_server )
  3151. {
  3152. mtr_verbose_restart($server, "no start or restart for embedded server");
  3153. return 0;
  3154. }
  3155. if ( $tinfo->{'force_restart'} ) {
  3156. mtr_verbose_restart($server, "forced in .opt file");
  3157. return 1;
  3158. }
  3159. if ( $tinfo->{template_path} ne $current_config_name)
  3160. {
  3161. mtr_verbose_restart($server, "using different config file");
  3162. return 1;
  3163. }
  3164. if ( $tinfo->{'master_sh'} || $tinfo->{'slave_sh'} )
  3165. {
  3166. mtr_verbose_restart($server, "sh script to run");
  3167. return 1;
  3168. }
  3169. if ( ! started($server) )
  3170. {
  3171. mtr_verbose_restart($server, "not started");
  3172. return 1;
  3173. }
  3174. my $started_tinfo= $server->{'started_tinfo'};
  3175. if ( defined $started_tinfo )
  3176. {
  3177. # Check if timezone of test that server was started
  3178. # with differs from timezone of next test
  3179. if ( timezone($started_tinfo) ne timezone($tinfo) )
  3180. {
  3181. mtr_verbose_restart($server, "different timezone");
  3182. return 1;
  3183. }
  3184. }
  3185. # Temporary re-enable the "always restart slave" hack
  3186. # this should be removed asap, but will require that each rpl
  3187. # testcase cleanup better after itself - ie. stop and reset
  3188. # replication
  3189. # Use the "#!use-slave-opt" marker to detect that this is a "slave"
  3190. # server
  3191. if ( $server->option("#!use-slave-opt") ){
  3192. mtr_verbose_restart($server, "Always restart slave(s)");
  3193. return 1;
  3194. }
  3195. my $is_mysqld= grep ($server eq $_, mysqlds());
  3196. if ($is_mysqld)
  3197. {
  3198. # Check that running process was started with same options
  3199. # as the current test requires
  3200. my $extra_opts= get_extra_opts($server, $tinfo);
  3201. my $started_opts= $server->{'started_opts'};
  3202. if (!My::Options::same($started_opts, $extra_opts) )
  3203. {
  3204. my $use_dynamic_option_switch= 0;
  3205. if (!$use_dynamic_option_switch)
  3206. {
  3207. mtr_verbose_restart($server, "running with different options '" .
  3208. join(" ", @{$extra_opts}) . "' != '" .
  3209. join(" ", @{$started_opts}) . "'" );
  3210. return 1;
  3211. }
  3212. mtr_verbose(My::Options::toStr("started_opts", @$started_opts));
  3213. mtr_verbose(My::Options::toStr("extra_opts", @$extra_opts));
  3214. # Get diff and check if dynamic switch is possible
  3215. my @diff_opts= My::Options::diff($started_opts, $extra_opts);
  3216. mtr_verbose(My::Options::toStr("diff_opts", @diff_opts));
  3217. my $query= My::Options::toSQL(@diff_opts);
  3218. mtr_verbose("Attempting dynamic switch '$query'");
  3219. if (run_query($tinfo, $server, $query)){
  3220. mtr_verbose("Restart: running with different options '" .
  3221. join(" ", @{$extra_opts}) . "' != '" .
  3222. join(" ", @{$started_opts}) . "'" );
  3223. return 1;
  3224. }
  3225. # Remember the dynamically set options
  3226. $server->{'started_opts'}= $extra_opts;
  3227. }
  3228. }
  3229. # Default, no restart
  3230. return 0;
  3231. }
  3232. sub servers_need_restart($) {
  3233. my ($tinfo)= @_;
  3234. return grep { server_need_restart($tinfo, $_); } all_servers();
  3235. }
  3236. #
  3237. # Return list of specific servers
  3238. # - there is no servers in an empty config
  3239. #
  3240. sub _like { return $config ? $config->like($_[0]) : (); }
  3241. sub mysqlds { return _like('mysqld.'); }
  3242. sub ndbds { return _like('cluster_config.ndbd.');}
  3243. sub ndb_mgmds { return _like('cluster_config.ndb_mgmd.'); }
  3244. sub clusters { return _like('mysql_cluster.'); }
  3245. sub all_servers { return ( mysqlds(), ndb_mgmds(), ndbds() ); }
  3246. #
  3247. # Filter a list of servers and return only those that are part
  3248. # of the specified cluster
  3249. #
  3250. sub in_cluster {
  3251. my ($cluster)= shift;
  3252. # Return only processes for a specific cluster
  3253. return grep { $_->suffix() eq $cluster->suffix() } @_;
  3254. }
  3255. #
  3256. # Filter a list of servers and return the SafeProcess
  3257. # for only those that are started or stopped
  3258. #
  3259. sub started { return grep(defined $_, map($_->{proc}, @_)); }
  3260. sub stopped { return grep(!defined $_, map($_->{proc}, @_)); }
  3261. sub envsubst {
  3262. my $string= shift;
  3263. if ( ! defined $ENV{$string} )
  3264. {
  3265. mtr_error(".opt file references '$string' which is not set");
  3266. }
  3267. return $ENV{$string};
  3268. }
  3269. sub get_extra_opts {
  3270. my ($mysqld, $tinfo)= @_;
  3271. my $opts=
  3272. $mysqld->option("#!use-slave-opt") ?
  3273. $tinfo->{slave_opt} : $tinfo->{master_opt};
  3274. # Expand environment variables
  3275. foreach my $opt ( @$opts )
  3276. {
  3277. $opt =~ s/\$\{(\w+)\}/envsubst($1)/ge;
  3278. $opt =~ s/\$(\w+)/envsubst($1)/ge;
  3279. }
  3280. return $opts;
  3281. }
  3282. sub stop_servers($$) {
  3283. my ($tinfo, @servers)= @_;
  3284. # Remember if we restarted for this test case (count restarts)
  3285. $tinfo->{'restarted'}= 1;
  3286. if ( join('|', @servers) eq join('|', all_servers()) )
  3287. {
  3288. # All servers are going down, use some kind of order to
  3289. # avoid too many warnings in the log files
  3290. mtr_report("Restarting all servers");
  3291. # mysqld processes
  3292. My::SafeProcess::shutdown( $opt_shutdown_timeout, started(mysqlds()) );
  3293. # cluster processes
  3294. My::SafeProcess::shutdown( $opt_shutdown_timeout,
  3295. started(ndbds(), ndb_mgmds()) );
  3296. }
  3297. else
  3298. {
  3299. mtr_report("Restarting ", started(@servers));
  3300. # Stop only some servers
  3301. My::SafeProcess::shutdown( $opt_shutdown_timeout,
  3302. started(@servers) );
  3303. }
  3304. foreach my $server (@servers)
  3305. {
  3306. # Mark server as stopped
  3307. $server->{proc}= undef;
  3308. # Forget history
  3309. delete $server->{'started_tinfo'};
  3310. delete $server->{'started_opts'};
  3311. delete $server->{'started_cnf'};
  3312. }
  3313. }
  3314. #
  3315. # start_servers
  3316. #
  3317. # Start servers not already started
  3318. #
  3319. # RETURN
  3320. # 0 OK
  3321. # 1 Start failed
  3322. #
  3323. sub start_servers($) {
  3324. my ($tinfo)= @_;
  3325. # Start clusters
  3326. foreach my $cluster ( clusters() )
  3327. {
  3328. ndbcluster_start($cluster);
  3329. }
  3330. # Start mysqlds
  3331. foreach my $mysqld ( mysqlds() )
  3332. {
  3333. if ( $mysqld->{proc} )
  3334. {
  3335. # Already started
  3336. # Write start of testcase to log file
  3337. mark_log($mysqld->value('log-error'), $tinfo);
  3338. next;
  3339. }
  3340. my $datadir= $mysqld->value('datadir');
  3341. if (!$opt_start_dirty)
  3342. {
  3343. # Don't delete anything if starting dirty
  3344. if (-d $datadir ) {
  3345. mtr_verbose(" - removing '$datadir'");
  3346. rmtree($datadir);
  3347. }
  3348. }
  3349. # Copy datadir from installed system db
  3350. for my $path ( "$opt_vardir", "$opt_vardir/..") {
  3351. my $install_db= "$path/install.db";
  3352. copytree($install_db, $datadir)
  3353. if -d $install_db;
  3354. }
  3355. mtr_error("Failed to copy system db to '$datadir'")
  3356. unless -d $datadir;
  3357. # Create the servers tmpdir
  3358. my $tmpdir= $mysqld->value('tmpdir');
  3359. mkpath($tmpdir) unless -d $tmpdir;
  3360. # Write start of testcase to log file
  3361. mark_log($mysqld->value('log-error'), $tinfo);
  3362. # Run <tname>-master.sh
  3363. if ($mysqld->option('#!run-master-sh') and
  3364. run_sh_script($tinfo->{master_sh}) )
  3365. {
  3366. $tinfo->{'comment'}= "Failed to execute '$tinfo->{master_sh}'";
  3367. return 1;
  3368. }
  3369. # Run <tname>-slave.sh
  3370. if ($mysqld->option('#!run-slave-sh') and
  3371. run_sh_script($tinfo->{slave_sh}))
  3372. {
  3373. $tinfo->{'comment'}= "Failed to execute '$tinfo->{slave_sh}'";
  3374. return 1;
  3375. }
  3376. if (!$opt_embedded_server)
  3377. {
  3378. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  3379. mysqld_start($mysqld,$extra_opts);
  3380. # Save this test case information, so next can examine it
  3381. $mysqld->{'started_tinfo'}= $tinfo;
  3382. }
  3383. }
  3384. # Wait for clusters to start
  3385. foreach my $cluster ( clusters() )
  3386. {
  3387. if (ndbcluster_wait_started($cluster, ""))
  3388. {
  3389. # failed to start
  3390. $tinfo->{'comment'}= "Start of '".$cluster->name()."' cluster failed";
  3391. return 1;
  3392. }
  3393. }
  3394. # Wait for mysqlds to start
  3395. foreach my $mysqld ( mysqlds() )
  3396. {
  3397. next if !started($mysqld);
  3398. if (sleep_until_file_created($mysqld->value('pid-file'),
  3399. $opt_start_timeout,
  3400. $mysqld->{'proc'}) == 0) {
  3401. $tinfo->{comment}=
  3402. "Failed to start ".$mysqld->name();
  3403. my $logfile= $mysqld->value('log-error');
  3404. if ( defined $logfile and -f $logfile )
  3405. {
  3406. $tinfo->{logfile}= mtr_fromfile($logfile);
  3407. }
  3408. else
  3409. {
  3410. $tinfo->{logfile}= "Could not open server logfile: '$logfile'";
  3411. }
  3412. return 1;
  3413. }
  3414. }
  3415. return 0;
  3416. }
  3417. #
  3418. # Run include/check-testcase.test
  3419. # Before a testcase, run in record mode and save result file to var/tmp
  3420. # After testcase, run and compare with the recorded file, they should be equal!
  3421. #
  3422. # RETURN VALUE
  3423. # The newly started process
  3424. #
  3425. sub start_check_testcase ($$$) {
  3426. my $tinfo= shift;
  3427. my $mode= shift;
  3428. my $mysqld= shift;
  3429. my $name= "check-".$mysqld->name();
  3430. # Replace dots in name with underscore to avoid that mysqltest
  3431. # misinterpret's what the filename extension is :(
  3432. $name=~ s/\./_/g;
  3433. my $args;
  3434. mtr_init_args(\$args);
  3435. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  3436. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  3437. mtr_add_arg($args, "--silent");
  3438. mtr_add_arg($args, "--skip-safemalloc");
  3439. mtr_add_arg($args, "--result-file=%s", "$opt_vardir/tmp/$name.result");
  3440. mtr_add_arg($args, "--test-file=%s", "include/check-testcase.test");
  3441. if ( $mode eq "before" )
  3442. {
  3443. mtr_add_arg($args, "--record");
  3444. }
  3445. my $errfile= "$opt_vardir/tmp/$name.err";
  3446. my $proc= My::SafeProcess->new
  3447. (
  3448. name => $name,
  3449. path => $exe_mysqltest,
  3450. error => $errfile,
  3451. args => \$args,
  3452. user_data => $errfile,
  3453. );
  3454. mtr_report("Started $proc");
  3455. return $proc;
  3456. }
  3457. sub run_mysqltest ($) {
  3458. my $proc= start_mysqltest(@_);
  3459. $proc->wait();
  3460. }
  3461. sub start_mysqltest ($) {
  3462. my ($tinfo)= @_;
  3463. my $exe= $exe_mysqltest;
  3464. my $args;
  3465. mtr_init_args(\$args);
  3466. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  3467. mtr_add_arg($args, "--silent");
  3468. mtr_add_arg($args, "--skip-safemalloc");
  3469. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  3470. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  3471. mtr_add_arg($args, "--logdir=%s/log", $opt_vardir);
  3472. # Log line number and time for each line in .test file
  3473. mtr_add_arg($args, "--mark-progress")
  3474. if $opt_mark_progress;
  3475. mtr_add_arg($args, "--database=test");
  3476. if ( $opt_ps_protocol )
  3477. {
  3478. mtr_add_arg($args, "--ps-protocol");
  3479. }
  3480. if ( $opt_sp_protocol )
  3481. {
  3482. mtr_add_arg($args, "--sp-protocol");
  3483. }
  3484. if ( $opt_view_protocol )
  3485. {
  3486. mtr_add_arg($args, "--view-protocol");
  3487. }
  3488. if ( $opt_cursor_protocol )
  3489. {
  3490. mtr_add_arg($args, "--cursor-protocol");
  3491. }
  3492. if ( $opt_strace_client )
  3493. {
  3494. $exe= $opt_strace_client || "strace";
  3495. mtr_add_arg($args, "-o");
  3496. mtr_add_arg($args, "%s/log/mysqltest.strace", $opt_vardir);
  3497. mtr_add_arg($args, "$exe_mysqltest");
  3498. }
  3499. mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
  3500. if ( $opt_compress )
  3501. {
  3502. mtr_add_arg($args, "--compress");
  3503. }
  3504. if ( $opt_sleep )
  3505. {
  3506. mtr_add_arg($args, "--sleep=%d", $opt_sleep);
  3507. }
  3508. if ( $opt_ssl )
  3509. {
  3510. # Turn on SSL for _all_ test cases if option --ssl was used
  3511. mtr_add_arg($args, "--ssl");
  3512. }
  3513. elsif ( $opt_ssl_supported )
  3514. {
  3515. mtr_add_arg($args, "--skip-ssl");
  3516. }
  3517. if ( $opt_embedded_server )
  3518. {
  3519. # Get the args needed for the embedded server
  3520. # and append them to args prefixed
  3521. # with --sever-arg=
  3522. my $mysqld= $config->group('embedded')
  3523. or mtr_error("Could not get [embedded] section");
  3524. my $mysqld_args;
  3525. mtr_init_args(\$mysqld_args);
  3526. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  3527. mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
  3528. mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
  3529. if (IS_WINDOWS)
  3530. {
  3531. # Trick the server to send output to stderr, with --console
  3532. mtr_add_arg($args, "--server-arg=--console");
  3533. }
  3534. }
  3535. # ----------------------------------------------------------------------
  3536. # export MYSQL_TEST variable containing <path>/mysqltest <args>
  3537. # ----------------------------------------------------------------------
  3538. $ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
  3539. # ----------------------------------------------------------------------
  3540. # Add arguments that should not go into the MYSQL_TEST env var
  3541. # ----------------------------------------------------------------------
  3542. if ( $opt_valgrind_mysqltest )
  3543. {
  3544. # Prefix the Valgrind options to the argument list.
  3545. # We do this here, since we do not want to Valgrind the nested invocations
  3546. # of mysqltest; that would mess up the stderr output causing test failure.
  3547. my @args_saved = @$args;
  3548. mtr_init_args(\$args);
  3549. valgrind_arguments($args, \$exe);
  3550. mtr_add_arg($args, "%s", $_) for @args_saved;
  3551. }
  3552. mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'});
  3553. # Number of lines of resut to include in failure report
  3554. mtr_add_arg($args, "--tail-lines=20");
  3555. if ( defined $tinfo->{'result_file'} ) {
  3556. mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
  3557. }
  3558. client_debug_arg($args, "mysqltest");
  3559. if ( $opt_record )
  3560. {
  3561. mtr_add_arg($args, "--record");
  3562. }
  3563. if ( $opt_client_gdb )
  3564. {
  3565. gdb_arguments(\$args, \$exe, "client");
  3566. }
  3567. elsif ( $opt_client_ddd )
  3568. {
  3569. ddd_arguments(\$args, \$exe, "client");
  3570. }
  3571. elsif ( $opt_client_debugger )
  3572. {
  3573. debugger_arguments(\$args, \$exe, "client");
  3574. }
  3575. my $proc= My::SafeProcess->new
  3576. (
  3577. name => "mysqltest",
  3578. path => $exe,
  3579. args => \$args,
  3580. append => 1,
  3581. error => $path_current_testlog,
  3582. verbose => $opt_verbose,
  3583. );
  3584. mtr_verbose("Started $proc");
  3585. return $proc;
  3586. }
  3587. #
  3588. # Modify the exe and args so that program is run in gdb in xterm
  3589. #
  3590. sub gdb_arguments {
  3591. my $args= shift;
  3592. my $exe= shift;
  3593. my $type= shift;
  3594. # Write $args to gdb init file
  3595. my $str= join(" ", @$$args);
  3596. my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
  3597. # Remove the old gdbinit file
  3598. unlink($gdb_init_file);
  3599. if ( $type eq "client" )
  3600. {
  3601. # write init file for client
  3602. mtr_tofile($gdb_init_file,
  3603. "set args $str\n" .
  3604. "break main\n");
  3605. }
  3606. else
  3607. {
  3608. # write init file for mysqld
  3609. mtr_tofile($gdb_init_file,
  3610. "set args $str\n" .
  3611. "break mysql_parse\n" .
  3612. "commands 1\n" .
  3613. "disable 1\n" .
  3614. "end\n" .
  3615. "run");
  3616. }
  3617. if ( $opt_manual_gdb )
  3618. {
  3619. print "\nTo start gdb for $type, type in another window:\n";
  3620. print "gdb -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  3621. # Indicate the exe should not be started
  3622. $$exe= undef;
  3623. return;
  3624. }
  3625. $$args= [];
  3626. mtr_add_arg($$args, "-title");
  3627. mtr_add_arg($$args, "$type");
  3628. mtr_add_arg($$args, "-e");
  3629. if ( $exe_libtool )
  3630. {
  3631. mtr_add_arg($$args, $exe_libtool);
  3632. mtr_add_arg($$args, "--mode=execute");
  3633. }
  3634. mtr_add_arg($$args, "gdb");
  3635. mtr_add_arg($$args, "-x");
  3636. mtr_add_arg($$args, "$gdb_init_file");
  3637. mtr_add_arg($$args, "$$exe");
  3638. $$exe= "xterm";
  3639. }
  3640. #
  3641. # Modify the exe and args so that program is run in ddd
  3642. #
  3643. sub ddd_arguments {
  3644. my $args= shift;
  3645. my $exe= shift;
  3646. my $type= shift;
  3647. # Write $args to ddd init file
  3648. my $str= join(" ", @$$args);
  3649. my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
  3650. # Remove the old gdbinit file
  3651. unlink($gdb_init_file);
  3652. if ( $type eq "client" )
  3653. {
  3654. # write init file for client
  3655. mtr_tofile($gdb_init_file,
  3656. "set args $str\n" .
  3657. "break main\n");
  3658. }
  3659. else
  3660. {
  3661. # write init file for mysqld
  3662. mtr_tofile($gdb_init_file,
  3663. "file $$exe\n" .
  3664. "set args $str\n" .
  3665. "break mysql_parse\n" .
  3666. "commands 1\n" .
  3667. "disable 1\n" .
  3668. "end");
  3669. }
  3670. if ( $opt_manual_ddd )
  3671. {
  3672. print "\nTo start ddd for $type, type in another window:\n";
  3673. print "ddd -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  3674. # Indicate the exe should not be started
  3675. $$exe= undef;
  3676. return;
  3677. }
  3678. my $save_exe= $$exe;
  3679. $$args= [];
  3680. if ( $exe_libtool )
  3681. {
  3682. $$exe= $exe_libtool;
  3683. mtr_add_arg($$args, "--mode=execute");
  3684. mtr_add_arg($$args, "ddd");
  3685. }
  3686. else
  3687. {
  3688. $$exe= "ddd";
  3689. }
  3690. mtr_add_arg($$args, "--command=$gdb_init_file");
  3691. mtr_add_arg($$args, "$save_exe");
  3692. }
  3693. #
  3694. # Modify the exe and args so that program is run in the selected debugger
  3695. #
  3696. sub debugger_arguments {
  3697. my $args= shift;
  3698. my $exe= shift;
  3699. my $debugger= $opt_debugger || $opt_client_debugger;
  3700. if ( $debugger =~ /vcexpress|vc|devenv/ )
  3701. {
  3702. # vc[express] /debugexe exe arg1 .. argn
  3703. # Add /debugexe and name of the exe before args
  3704. unshift(@$$args, "/debugexe");
  3705. unshift(@$$args, "$$exe");
  3706. # Set exe to debuggername
  3707. $$exe= $debugger;
  3708. }
  3709. elsif ( $debugger =~ /windbg/ )
  3710. {
  3711. # windbg exe arg1 .. argn
  3712. # Add name of the exe before args
  3713. unshift(@$$args, "$$exe");
  3714. # Set exe to debuggername
  3715. $$exe= $debugger;
  3716. }
  3717. elsif ( $debugger eq "dbx" )
  3718. {
  3719. # xterm -e dbx -r exe arg1 .. argn
  3720. unshift(@$$args, $$exe);
  3721. unshift(@$$args, "-r");
  3722. unshift(@$$args, $debugger);
  3723. unshift(@$$args, "-e");
  3724. $$exe= "xterm";
  3725. }
  3726. else
  3727. {
  3728. mtr_error("Unknown argument \"$debugger\" passed to --debugger");
  3729. }
  3730. }
  3731. #
  3732. # Modify the exe and args so that program is run in valgrind
  3733. #
  3734. sub valgrind_arguments {
  3735. my $args= shift;
  3736. my $exe= shift;
  3737. if ( $opt_callgrind)
  3738. {
  3739. mtr_add_arg($args, "--tool=callgrind");
  3740. mtr_add_arg($args, "--base=$opt_vardir/log");
  3741. }
  3742. else
  3743. {
  3744. mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
  3745. mtr_add_arg($args, "--alignment=8");
  3746. mtr_add_arg($args, "--leak-check=yes");
  3747. mtr_add_arg($args, "--num-callers=16");
  3748. mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
  3749. if -f "$glob_mysql_test_dir/valgrind.supp";
  3750. }
  3751. # Add valgrind options, can be overriden by user
  3752. mtr_add_arg($args, '%s', $_) for (@valgrind_args);
  3753. mtr_add_arg($args, $$exe);
  3754. $$exe= $opt_valgrind_path || "valgrind";
  3755. if ($exe_libtool)
  3756. {
  3757. # Add "libtool --mode-execute" before the test to execute
  3758. # if running in valgrind(to avoid valgrinding bash)
  3759. unshift(@$args, "--mode=execute", $$exe);
  3760. $$exe= $exe_libtool;
  3761. }
  3762. }
  3763. #
  3764. # Usage
  3765. #
  3766. sub usage ($) {
  3767. my ($message)= @_;
  3768. if ( $message )
  3769. {
  3770. print STDERR "$message\n";
  3771. }
  3772. print <<HERE;
  3773. $0 [ OPTIONS ] [ TESTCASE ]
  3774. Options to control what engine/variation to run
  3775. embedded-server Use the embedded server, i.e. no mysqld daemons
  3776. ps-protocol Use the binary protocol between client and server
  3777. cursor-protocol Use the cursor protocol between client and server
  3778. (implies --ps-protocol)
  3779. view-protocol Create a view to execute all non updating queries
  3780. sp-protocol Create a stored procedure to execute all queries
  3781. compress Use the compressed protocol between client and server
  3782. ssl Use ssl protocol between client and server
  3783. skip-ssl Dont start server with support for ssl connections
  3784. ndb|with-ndbcluster Use cluster as default table type
  3785. vs-config Visual Studio configuration used to create executables
  3786. (default: MTR_VS_CONFIG environment variable)
  3787. config|defaults-file=<config template> Use fixed config template for all
  3788. tests
  3789. defaults_extra_file=<config template> Extra config template to add to
  3790. all generated configs
  3791. Options to control directories to use
  3792. tmpdir=DIR The directory where temporary files are stored
  3793. (default: ./var/tmp).
  3794. vardir=DIR The directory where files generated from the test run
  3795. is stored (default: ./var). Specifying a ramdisk or
  3796. tmpfs will speed up tests.
  3797. mem Run testsuite in "memory" using tmpfs or ramdisk
  3798. Attempts to find a suitable location
  3799. using a builtin list of standard locations
  3800. for tmpfs (/dev/shm)
  3801. The option can also be set using environment
  3802. variable MTR_MEM=[DIR]
  3803. client-bindir=PATH Path to the directory where client binaries are located
  3804. client-libdir=PATH Path to the directory where client libraries are located
  3805. Options to control what test suites or cases to run
  3806. force Continue to run the suite after failure
  3807. with-ndbcluster-only Run only tests that include "ndb" in the filename
  3808. skip-ndb[cluster] Skip all tests that need cluster
  3809. skip-ndb[cluster]-slave Skip all tests that need a slave cluster
  3810. do-test=PREFIX or REGEX
  3811. Run test cases which name are prefixed with PREFIX
  3812. or fulfills REGEX
  3813. skip-test=PREFIX or REGEX
  3814. Skip test cases which name are prefixed with PREFIX
  3815. or fulfills REGEX
  3816. start-from=PREFIX Run test cases starting test prefixed with PREFIX where
  3817. prefix may be suite.testname or just testname
  3818. suite[s]=NAME1,..,NAMEN
  3819. Collect tests in suites from the comma separated
  3820. list of suite names.
  3821. The default is: "$DEFAULT_SUITES"
  3822. skip-rpl Skip the replication test cases.
  3823. big-test Also run tests marked as "big"
  3824. Options that specify ports
  3825. mtr-build-thread=# Specify unique number to calculate port number(s) from.
  3826. build-thread=# Can be set in environment variable MTR_BUILD_THREAD.
  3827. Set MTR_BUILD_THREAD="auto" to automatically aquire
  3828. a build thread id that is unique to current host
  3829. Options for test case authoring
  3830. record TESTNAME (Re)genereate the result file for TESTNAME
  3831. check-testcases Check testcases for sideeffects
  3832. mark-progress Log line number and elapsed time to <testname>.progress
  3833. Options that pass on options
  3834. mysqld=ARGS Specify additional arguments to "mysqld"
  3835. Options to run test on running server
  3836. extern option=value Run only the tests against an already started server
  3837. the options to use for connection to the extern server
  3838. must be specified using name-value pair notation
  3839. For example:
  3840. ./$0 --extern socket=/tmp/mysqld.sock
  3841. Options for debugging the product
  3842. client-ddd Start mysqltest client in ddd
  3843. client-debugger=NAME Start mysqltest in the selected debugger
  3844. client-gdb Start mysqltest client in gdb
  3845. ddd Start mysqld in ddd
  3846. debug Dump trace output for all servers and client programs
  3847. debugger=NAME Start mysqld in the selected debugger
  3848. gdb Start the mysqld(s) in gdb
  3849. manual-debug Let user manually start mysqld in debugger, before
  3850. running test(s)
  3851. manual-gdb Let user manually start mysqld in gdb, before running
  3852. test(s)
  3853. manual-ddd Let user manually start mysqld in ddd, before running
  3854. test(s)
  3855. strace-client=[path] Create strace output for mysqltest client, optionally
  3856. specifying name and path to the trace program to use.
  3857. Example: $0 --strace-client=ktrace
  3858. max-save-core Limit the number of core files saved (to avoid filling
  3859. up disks for heavily crashing server). Defaults to
  3860. $opt_max_save_core, set to 0 for no limit. Set
  3861. it's default with MTR_MAX_SAVE_CORE
  3862. max-save-datadir Limit the number of datadir saved (to avoid filling
  3863. up disks for heavily crashing server). Defaults to
  3864. $opt_max_save_datadir, set to 0 for no limit. Set
  3865. it's default with MTR_MAX_SAVE_DATDIR
  3866. max-test-fail Limit the number of test failurs before aborting
  3867. the current test run. Defaults to
  3868. $opt_max_test_fail, set to 0 for no limit. Set
  3869. it's default with MTR_MAX_TEST_FAIL
  3870. Options for valgrind
  3871. valgrind Run the "mysqltest" and "mysqld" executables using
  3872. valgrind with default options
  3873. valgrind-all Synonym for --valgrind
  3874. valgrind-mysqltest Run the "mysqltest" and "mysql_client_test" executable
  3875. with valgrind
  3876. valgrind-mysqld Run the "mysqld" executable with valgrind
  3877. valgrind-options=ARGS Deprecated, use --valgrind-option
  3878. valgrind-option=ARGS Option to give valgrind, replaces default option(s),
  3879. can be specified more then once
  3880. valgrind-path=[EXE] Path to the valgrind executable
  3881. callgrind Instruct valgrind to use callgrind
  3882. Misc options
  3883. user=USER User for connecting to mysqld(default: $opt_user)
  3884. comment=STR Write STR to the output
  3885. notimer Don't show test case execution time
  3886. verbose More verbose output(use multiple times for even more)
  3887. start Only initialize and start the servers, using the
  3888. startup settings for the first specified test case
  3889. Example:
  3890. $0 --start alias &
  3891. start-dirty Only start the servers (without initialization) for
  3892. the first specified test case
  3893. fast Run as fast as possible, dont't wait for servers
  3894. to shutdown etc.
  3895. repeat=N Run each test N number of times
  3896. retry=N Retry tests that fail N times, limit number of failures
  3897. to $opt_retry_failure
  3898. retry-failure=N Limit number of retries for a failed test
  3899. reorder Reorder tests to get fewer server restarts
  3900. help Get this help text
  3901. testcase-timeout=MINUTES Max test case run time (default $opt_testcase_timeout)
  3902. suite-timeout=MINUTES Max test suite run time (default $opt_suite_timeout)
  3903. shutdown-timeout=SECONDS Max number of seconds to wait for server shutdown
  3904. before killing servers (default $opt_shutdown_timeout)
  3905. warnings Scan the log files for warnings. Use --nowarnings
  3906. to turn off.
  3907. sleep=SECONDS Passed to mysqltest, will be used as fixed sleep time
  3908. HERE
  3909. exit(1);
  3910. }