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.

4910 lines
130 KiB

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