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.

5165 lines
143 KiB

21 years ago
21 years ago
21 years ago
21 years ago
21 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 file
  9. #
  10. # See the "MySQL Test framework manual" for more information
  11. # http://dev.mysql.com/doc/mysqltest/en/index.html
  12. #
  13. # Please keep the test framework tools identical in all versions!
  14. #
  15. ##############################################################################
  16. #
  17. # Coding style directions for this perl script
  18. #
  19. # - To make this Perl script easy to alter even for those that not
  20. # code Perl that often, keeep the coding style as close as possible to
  21. # the C/C++ MySQL coding standard.
  22. #
  23. # - All lists of arguments to send to commands are Perl lists/arrays,
  24. # not strings we append args to. Within reason, most string
  25. # concatenation for arguments should be avoided.
  26. #
  27. # - Functions defined in the main program are not to be prefixed,
  28. # functions in "library files" are to be prefixed with "mtr_" (for
  29. # Mysql-Test-Run). There are some exceptions, code that fits best in
  30. # the main program, but are put into separate files to avoid
  31. # clutter, may be without prefix.
  32. #
  33. # - All stat/opendir/-f/ is to be kept in collect_test_cases(). It
  34. # will create a struct that the rest of the program can use to get
  35. # the information. This separates the "find information" from the
  36. # "do the work" and makes the program more easy to maintain.
  37. #
  38. # - The rule when it comes to the logic of this program is
  39. #
  40. # command_line_setup() - is to handle the logic between flags
  41. # collect_test_cases() - is to do its best to select what tests
  42. # to run, dig out options, if needs restart etc.
  43. # run_testcase() - is to run a single testcase, and follow the
  44. # logic set in both above. No, or rare file
  45. # system operations. If a test seems complex,
  46. # it should probably not be here.
  47. #
  48. # A nice way to trace the execution of this script while debugging
  49. # is to use the Devel::Trace package found at
  50. # "http://www.plover.com/~mjd/perl/Trace/" and run this script like
  51. # "perl -d:Trace mysql-test-run.pl"
  52. #
  53. $Devel::Trace::TRACE= 0; # Don't trace boring init stuff
  54. #require 5.6.1;
  55. use File::Path;
  56. use File::Basename;
  57. use File::Copy;
  58. use File::Temp qw / tempdir /;
  59. use Cwd;
  60. use Getopt::Long;
  61. use Sys::Hostname;
  62. use IO::Socket;
  63. use IO::Socket::INET;
  64. use strict;
  65. use warnings;
  66. select(STDOUT);
  67. $| = 1; # Automatically flush STDOUT
  68. our $glob_win32_perl= ($^O eq "MSWin32"); # ActiveState Win32 Perl
  69. our $glob_cygwin_perl= ($^O eq "cygwin"); # Cygwin Perl
  70. our $glob_win32= ($glob_win32_perl or $glob_cygwin_perl);
  71. our $glob_netware= ($^O eq "NetWare"); # NetWare
  72. require "lib/mtr_cases.pl";
  73. require "lib/mtr_im.pl";
  74. require "lib/mtr_process.pl";
  75. require "lib/mtr_timer.pl";
  76. require "lib/mtr_io.pl";
  77. require "lib/mtr_gcov.pl";
  78. require "lib/mtr_gprof.pl";
  79. require "lib/mtr_report.pl";
  80. require "lib/mtr_diff.pl";
  81. require "lib/mtr_match.pl";
  82. require "lib/mtr_misc.pl";
  83. require "lib/mtr_stress.pl";
  84. require "lib/mtr_unique.pl";
  85. $Devel::Trace::TRACE= 1;
  86. ##############################################################################
  87. #
  88. # Default settings
  89. #
  90. ##############################################################################
  91. # Misc global variables
  92. our $mysql_version_id;
  93. our $glob_mysql_test_dir= undef;
  94. our $glob_mysql_bench_dir= undef;
  95. our $glob_hostname= undef;
  96. our $glob_scriptname= undef;
  97. our $glob_timers= undef;
  98. our $glob_use_running_ndbcluster= 0;
  99. our $glob_use_running_ndbcluster_slave= 0;
  100. our $glob_use_embedded_server= 0;
  101. our @glob_test_mode;
  102. our $glob_basedir;
  103. our $path_charsetsdir;
  104. our $path_client_bindir;
  105. our $path_language;
  106. our $path_timefile;
  107. our $path_snapshot;
  108. our $path_mysqltest_log;
  109. our $path_current_test_log;
  110. our $path_my_basedir;
  111. our $opt_vardir; # A path but set directly on cmd line
  112. our $path_vardir_trace; # unix formatted opt_vardir for trace files
  113. our $opt_tmpdir; # A path but set directly on cmd line
  114. # Visual Studio produces executables in different sub-directories based on the
  115. # configuration used to build them. To make life easier, an environment
  116. # variable or command-line option may be specified to control which set of
  117. # executables will be used by the test suite.
  118. our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
  119. our $default_vardir;
  120. our $opt_usage;
  121. our $opt_suite;
  122. our $opt_script_debug= 0; # Script debugging, enable with --script-debug
  123. our $opt_verbose= 0; # Verbose output, enable with --verbose
  124. our $exe_master_mysqld;
  125. our $exe_mysql;
  126. our $exe_mysqladmin;
  127. our $exe_mysql_upgrade;
  128. our $exe_mysqlbinlog;
  129. our $exe_mysql_client_test;
  130. our $exe_mysqld;
  131. our $exe_mysqlcheck;
  132. our $exe_mysqldump;
  133. our $exe_mysqlslap;
  134. our $exe_mysqlimport;
  135. our $exe_mysqlshow;
  136. our $exe_mysql_fix_system_tables;
  137. our $file_mysql_fix_privilege_tables;
  138. our $exe_mysqltest;
  139. our $exe_ndbd;
  140. our $exe_ndb_mgmd;
  141. our $exe_slave_mysqld;
  142. our $exe_im;
  143. our $exe_my_print_defaults;
  144. our $exe_perror;
  145. our $lib_udf_example;
  146. our $exe_libtool;
  147. our $opt_bench= 0;
  148. our $opt_small_bench= 0;
  149. our $opt_big_test= 0;
  150. our @opt_extra_mysqld_opt;
  151. our $opt_compress;
  152. our $opt_ssl;
  153. our $opt_skip_ssl;
  154. our $opt_ssl_supported;
  155. our $opt_ps_protocol;
  156. our $opt_sp_protocol;
  157. our $opt_cursor_protocol;
  158. our $opt_view_protocol;
  159. our $opt_debug;
  160. our $opt_do_test;
  161. our @opt_cases; # The test cases names in argv
  162. our $opt_embedded_server;
  163. our $opt_extern= 0;
  164. our $opt_socket;
  165. our $opt_fast;
  166. our $opt_force;
  167. our $opt_reorder= 0;
  168. our $opt_enable_disabled;
  169. our $opt_mem= $ENV{'MTR_MEM'};
  170. our $opt_gcov;
  171. our $opt_gcov_err;
  172. our $opt_gcov_msg;
  173. our $glob_debugger= 0;
  174. our $opt_gdb;
  175. our $opt_client_gdb;
  176. our $opt_ddd;
  177. our $opt_client_ddd;
  178. our $opt_manual_gdb;
  179. our $opt_manual_ddd;
  180. our $opt_manual_debug;
  181. our $opt_mtr_build_thread=0;
  182. our $opt_debugger;
  183. our $opt_client_debugger;
  184. our $opt_gprof;
  185. our $opt_gprof_dir;
  186. our $opt_gprof_master;
  187. our $opt_gprof_slave;
  188. our $master;
  189. our $slave;
  190. our $clusters;
  191. our $instance_manager;
  192. our $opt_master_myport;
  193. our $opt_slave_myport;
  194. our $im_port;
  195. our $im_mysqld1_port;
  196. our $im_mysqld2_port;
  197. our $opt_ndbcluster_port;
  198. our $opt_ndbconnectstring;
  199. our $opt_ndbcluster_port_slave;
  200. our $opt_ndbconnectstring_slave;
  201. our $opt_record;
  202. my $opt_report_features;
  203. our $opt_check_testcases;
  204. our $opt_mark_progress;
  205. our $opt_skip;
  206. our $opt_skip_rpl;
  207. our $max_slave_num= 0;
  208. our $max_master_num= 1;
  209. our $use_innodb;
  210. our $opt_skip_test;
  211. our $opt_skip_im;
  212. our $opt_sleep;
  213. our $opt_testcase_timeout;
  214. our $opt_suite_timeout;
  215. my $default_testcase_timeout= 15; # 15 min max
  216. my $default_suite_timeout= 180; # 3 hours max
  217. our $opt_start_and_exit;
  218. our $opt_start_dirty;
  219. our $opt_start_from;
  220. our $opt_strace_client;
  221. our $opt_timer= 1;
  222. our $opt_user;
  223. our $opt_valgrind= 0;
  224. our $opt_valgrind_mysqld= 0;
  225. our $opt_valgrind_mysqltest= 0;
  226. our $default_valgrind_options= "--show-reachable=yes";
  227. our $opt_valgrind_options;
  228. our $opt_valgrind_path;
  229. our $opt_callgrind;
  230. our $opt_stress= "";
  231. our $opt_stress_suite= "main";
  232. our $opt_stress_mode= "random";
  233. our $opt_stress_threads= 5;
  234. our $opt_stress_test_count= 0;
  235. our $opt_stress_loop_count= 0;
  236. our $opt_stress_test_duration= 0;
  237. our $opt_stress_init_file= "";
  238. our $opt_stress_test_file= "";
  239. our $opt_wait_for_master;
  240. our $opt_wait_for_slave;
  241. our $opt_warnings;
  242. our $opt_udiff;
  243. our $opt_skip_ndbcluster= 0;
  244. our $opt_skip_ndbcluster_slave= 0;
  245. our $opt_with_ndbcluster= 0;
  246. our $opt_with_ndbcluster_only= 0;
  247. our $glob_ndbcluster_supported= 0;
  248. our $opt_ndb_extra_test= 0;
  249. our $opt_skip_master_binlog= 0;
  250. our $opt_skip_slave_binlog= 0;
  251. our $exe_ndb_mgm;
  252. our $exe_ndb_waiter;
  253. our $path_ndb_tools_dir;
  254. our $path_ndb_examples_dir;
  255. our $exe_ndb_example;
  256. our $path_ndb_testrun_log;
  257. our $path_sql_dir;
  258. our @data_dir_lst;
  259. our $used_binlog_format;
  260. our $used_default_engine;
  261. our $debug_compiled_binaries;
  262. our $glob_tot_real_time= 0;
  263. our %mysqld_variables;
  264. my $source_dist= 0;
  265. our $opt_max_save_core= 5;
  266. my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
  267. ######################################################################
  268. #
  269. # Function declarations
  270. #
  271. ######################################################################
  272. sub main ();
  273. sub initial_setup ();
  274. sub command_line_setup ();
  275. sub set_mtr_build_thread_ports($);
  276. sub datadir_list_setup ();
  277. sub executable_setup ();
  278. sub environment_setup ();
  279. sub kill_running_servers ();
  280. sub remove_stale_vardir ();
  281. sub setup_vardir ();
  282. sub check_ssl_support ($);
  283. sub check_running_as_root();
  284. sub check_ndbcluster_support ($);
  285. sub rm_ndbcluster_tables ($);
  286. sub ndbcluster_start_install ($);
  287. sub ndbcluster_start ($$);
  288. sub ndbcluster_wait_started ($$);
  289. sub mysqld_wait_started($);
  290. sub run_benchmarks ($);
  291. sub initialize_servers ();
  292. sub mysql_install_db ();
  293. sub install_db ($$);
  294. sub copy_install_db ($$);
  295. sub run_testcase ($);
  296. sub run_testcase_stop_servers ($$$);
  297. sub run_testcase_start_servers ($);
  298. sub run_testcase_check_skip_test($);
  299. sub report_failure_and_restart ($);
  300. sub do_before_start_master ($);
  301. sub do_before_start_slave ($);
  302. sub ndbd_start ($$$);
  303. sub ndb_mgmd_start ($);
  304. sub mysqld_start ($$$);
  305. sub mysqld_arguments ($$$$);
  306. sub stop_all_servers ();
  307. sub run_mysqltest ($);
  308. sub usage ($);
  309. ######################################################################
  310. #
  311. # Main program
  312. #
  313. ######################################################################
  314. main();
  315. sub main () {
  316. command_line_setup();
  317. check_ndbcluster_support(\%mysqld_variables);
  318. check_ssl_support(\%mysqld_variables);
  319. check_debug_support(\%mysqld_variables);
  320. executable_setup();
  321. environment_setup();
  322. signal_setup();
  323. if ( $opt_gcov )
  324. {
  325. gcov_prepare();
  326. }
  327. if ( $opt_gprof )
  328. {
  329. gprof_prepare();
  330. }
  331. if ( $opt_bench )
  332. {
  333. initialize_servers();
  334. run_benchmarks(shift); # Shift what? Extra arguments?!
  335. }
  336. elsif ( $opt_stress )
  337. {
  338. initialize_servers();
  339. run_stress_test()
  340. }
  341. else
  342. {
  343. # Figure out which tests we are going to run
  344. my $tests= collect_test_cases($opt_suite);
  345. # Turn off NDB and other similar options if no tests use it
  346. my ($need_ndbcluster,$need_im);
  347. foreach my $test (@$tests)
  348. {
  349. next if $test->{skip};
  350. $need_ndbcluster||= $test->{ndb_test};
  351. $need_im||= $test->{component_id} eq 'im';
  352. # Count max number of slaves used by a test case
  353. if ( $test->{slave_num} > $max_slave_num)
  354. {
  355. $max_slave_num= $test->{slave_num};
  356. mtr_error("Too many slaves") if $max_slave_num > 3;
  357. }
  358. # Count max number of masters used by a test case
  359. if ( $test->{master_num} > $max_master_num)
  360. {
  361. $max_master_num= $test->{master_num};
  362. mtr_error("Too many masters") if $max_master_num > 2;
  363. mtr_error("Too few masters") if $max_master_num < 1;
  364. }
  365. $use_innodb||= $test->{'innodb_test'};
  366. }
  367. # Check if cluster can be skipped
  368. if ( !$need_ndbcluster )
  369. {
  370. $opt_skip_ndbcluster= 1;
  371. $opt_skip_ndbcluster_slave= 1;
  372. }
  373. # Check if slave cluster can be skipped
  374. if ($max_slave_num == 0)
  375. {
  376. $opt_skip_ndbcluster_slave= 1;
  377. }
  378. # Check if im can be skipped
  379. if ( ! $need_im )
  380. {
  381. $opt_skip_im= 1;
  382. }
  383. initialize_servers();
  384. if ( $opt_report_features ) {
  385. run_report_features();
  386. }
  387. run_suite($opt_suite, $tests);
  388. }
  389. mtr_exit(0);
  390. }
  391. ##############################################################################
  392. #
  393. # Default settings
  394. #
  395. ##############################################################################
  396. sub command_line_setup () {
  397. # These are defaults for things that are set on the command line
  398. $opt_suite= "main"; # Special default suite
  399. my $opt_comment;
  400. $opt_master_myport= 9306;
  401. $opt_slave_myport= 9308;
  402. $opt_ndbcluster_port= 9310;
  403. $opt_ndbcluster_port_slave= 9311;
  404. $im_port= 9312;
  405. $im_mysqld1_port= 9313;
  406. $im_mysqld2_port= 9314;
  407. # If so requested, we try to avail ourselves of a unique build thread number.
  408. if ( $ENV{'MTR_BUILD_THREAD'} ) {
  409. if ( lc($ENV{'MTR_BUILD_THREAD'}) eq 'auto' ) {
  410. print "Requesting build thread... ";
  411. $ENV{'MTR_BUILD_THREAD'} = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
  412. print "got ".$ENV{'MTR_BUILD_THREAD'}."\n";
  413. }
  414. }
  415. if ( $ENV{'MTR_BUILD_THREAD'} )
  416. {
  417. set_mtr_build_thread_ports($ENV{'MTR_BUILD_THREAD'});
  418. }
  419. # This is needed for test log evaluation in "gen-build-status-page"
  420. # in all cases where the calling tool does not log the commands
  421. # directly before it executes them, like "make test-force-pl" in RPM builds.
  422. print "Logging: $0 ", join(" ", @ARGV), "\n";
  423. # Read the command line
  424. # Note: Keep list, and the order, in sync with usage at end of this file
  425. Getopt::Long::Configure("pass_through");
  426. GetOptions(
  427. # Control what engine/variation to run
  428. 'embedded-server' => \$opt_embedded_server,
  429. 'ps-protocol' => \$opt_ps_protocol,
  430. 'sp-protocol' => \$opt_sp_protocol,
  431. 'view-protocol' => \$opt_view_protocol,
  432. 'cursor-protocol' => \$opt_cursor_protocol,
  433. 'ssl|with-openssl' => \$opt_ssl,
  434. 'skip-ssl' => \$opt_skip_ssl,
  435. 'compress' => \$opt_compress,
  436. 'bench' => \$opt_bench,
  437. 'small-bench' => \$opt_small_bench,
  438. 'with-ndbcluster|ndb' => \$opt_with_ndbcluster,
  439. 'vs-config' => \$opt_vs_config,
  440. # Control what test suites or cases to run
  441. 'force' => \$opt_force,
  442. 'with-ndbcluster-only' => \$opt_with_ndbcluster_only,
  443. 'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
  444. 'skip-ndbcluster-slave|skip-ndb-slave'
  445. => \$opt_skip_ndbcluster_slave,
  446. 'ndb-extra-test' => \$opt_ndb_extra_test,
  447. 'skip-master-binlog' => \$opt_skip_master_binlog,
  448. 'skip-slave-binlog' => \$opt_skip_slave_binlog,
  449. 'do-test=s' => \$opt_do_test,
  450. 'start-from=s' => \$opt_start_from,
  451. 'suite=s' => \$opt_suite,
  452. 'skip-rpl' => \$opt_skip_rpl,
  453. 'skip-im' => \$opt_skip_im,
  454. 'skip-test=s' => \$opt_skip_test,
  455. 'big-test' => \$opt_big_test,
  456. # Specify ports
  457. 'master_port=i' => \$opt_master_myport,
  458. 'slave_port=i' => \$opt_slave_myport,
  459. 'ndbcluster-port|ndbcluster_port=i' => \$opt_ndbcluster_port,
  460. 'ndbcluster-port-slave=i' => \$opt_ndbcluster_port_slave,
  461. 'im-port=i' => \$im_port, # Instance Manager port.
  462. 'im-mysqld1-port=i' => \$im_mysqld1_port, # Port of mysqld, controlled by IM
  463. 'im-mysqld2-port=i' => \$im_mysqld2_port, # Port of mysqld, controlled by IM
  464. 'mtr-build-thread=i' => \$opt_mtr_build_thread,
  465. # Test case authoring
  466. 'record' => \$opt_record,
  467. 'check-testcases' => \$opt_check_testcases,
  468. 'mark-progress' => \$opt_mark_progress,
  469. # Extra options used when starting mysqld
  470. 'mysqld=s' => \@opt_extra_mysqld_opt,
  471. # Run test on running server
  472. 'extern' => \$opt_extern,
  473. 'ndb-connectstring=s' => \$opt_ndbconnectstring,
  474. 'ndb-connectstring-slave=s' => \$opt_ndbconnectstring_slave,
  475. # Debugging
  476. 'gdb' => \$opt_gdb,
  477. 'client-gdb' => \$opt_client_gdb,
  478. 'manual-gdb' => \$opt_manual_gdb,
  479. 'manual-debug' => \$opt_manual_debug,
  480. 'ddd' => \$opt_ddd,
  481. 'client-ddd' => \$opt_client_ddd,
  482. 'manual-ddd' => \$opt_manual_ddd,
  483. 'debugger=s' => \$opt_debugger,
  484. 'client-debugger=s' => \$opt_client_debugger,
  485. 'strace-client' => \$opt_strace_client,
  486. 'master-binary=s' => \$exe_master_mysqld,
  487. 'slave-binary=s' => \$exe_slave_mysqld,
  488. 'max-save-core=i' => \$opt_max_save_core,
  489. # Coverage, profiling etc
  490. 'gcov' => \$opt_gcov,
  491. 'gprof' => \$opt_gprof,
  492. 'valgrind|valgrind-all' => \$opt_valgrind,
  493. 'valgrind-mysqltest' => \$opt_valgrind_mysqltest,
  494. 'valgrind-mysqld' => \$opt_valgrind_mysqld,
  495. 'valgrind-options=s' => \$opt_valgrind_options,
  496. 'valgrind-path=s' => \$opt_valgrind_path,
  497. 'callgrind' => \$opt_callgrind,
  498. # Stress testing
  499. 'stress' => \$opt_stress,
  500. 'stress-suite=s' => \$opt_stress_suite,
  501. 'stress-threads=i' => \$opt_stress_threads,
  502. 'stress-test-file=s' => \$opt_stress_test_file,
  503. 'stress-init-file=s' => \$opt_stress_init_file,
  504. 'stress-mode=s' => \$opt_stress_mode,
  505. 'stress-loop-count=i' => \$opt_stress_loop_count,
  506. 'stress-test-count=i' => \$opt_stress_test_count,
  507. 'stress-test-duration=i' => \$opt_stress_test_duration,
  508. # Directories
  509. 'tmpdir=s' => \$opt_tmpdir,
  510. 'vardir=s' => \$opt_vardir,
  511. 'benchdir=s' => \$glob_mysql_bench_dir,
  512. 'mem' => \$opt_mem,
  513. # Misc
  514. 'report-features' => \$opt_report_features,
  515. 'comment=s' => \$opt_comment,
  516. 'debug' => \$opt_debug,
  517. 'fast' => \$opt_fast,
  518. 'reorder' => \$opt_reorder,
  519. 'enable-disabled' => \$opt_enable_disabled,
  520. 'script-debug' => \$opt_script_debug,
  521. 'verbose' => \$opt_verbose,
  522. 'sleep=i' => \$opt_sleep,
  523. 'socket=s' => \$opt_socket,
  524. 'start-dirty' => \$opt_start_dirty,
  525. 'start-and-exit' => \$opt_start_and_exit,
  526. 'timer!' => \$opt_timer,
  527. 'unified-diff|udiff' => \$opt_udiff,
  528. 'user=s' => \$opt_user,
  529. 'testcase-timeout=i' => \$opt_testcase_timeout,
  530. 'suite-timeout=i' => \$opt_suite_timeout,
  531. 'warnings|log-warnings' => \$opt_warnings,
  532. 'help|h' => \$opt_usage,
  533. ) or usage("Can't read options");
  534. usage("") if $opt_usage;
  535. $glob_scriptname= basename($0);
  536. if ($opt_mtr_build_thread != 0)
  537. {
  538. set_mtr_build_thread_ports($opt_mtr_build_thread)
  539. }
  540. elsif ($ENV{'MTR_BUILD_THREAD'})
  541. {
  542. $opt_mtr_build_thread= $ENV{'MTR_BUILD_THREAD'};
  543. }
  544. # We require that we are in the "mysql-test" directory
  545. # to run mysql-test-run
  546. if (! -f $glob_scriptname)
  547. {
  548. mtr_error("Can't find the location for the mysql-test-run script\n" .
  549. "Go to to the mysql-test directory and execute the script " .
  550. "as follows:\n./$glob_scriptname");
  551. }
  552. if ( -d "../sql" )
  553. {
  554. $source_dist= 1;
  555. }
  556. $glob_hostname= mtr_short_hostname();
  557. # Find the absolute path to the test directory
  558. $glob_mysql_test_dir= cwd();
  559. if ( $glob_cygwin_perl )
  560. {
  561. # Windows programs like 'mysqld' needs Windows paths
  562. $glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`;
  563. chomp($glob_mysql_test_dir);
  564. }
  565. # In most cases, the base directory we find everything relative to,
  566. # is the parent directory of the "mysql-test" directory. For source
  567. # distributions, TAR binary distributions and some other packages.
  568. $glob_basedir= dirname($glob_mysql_test_dir);
  569. # In the RPM case, binaries and libraries are installed in the
  570. # default system locations, instead of having our own private base
  571. # directory. And we install "/usr/share/mysql-test". Moving up one
  572. # more directory relative to "mysql-test" gives us a usable base
  573. # directory for RPM installs.
  574. if ( ! $source_dist and ! -d "$glob_basedir/bin" )
  575. {
  576. $glob_basedir= dirname($glob_basedir);
  577. }
  578. # Expect mysql-bench to be located adjacent to the source tree, by default
  579. $glob_mysql_bench_dir= "$glob_basedir/../mysql-bench"
  580. unless defined $glob_mysql_bench_dir;
  581. $glob_mysql_bench_dir= undef
  582. unless -d $glob_mysql_bench_dir;
  583. $path_my_basedir=
  584. $source_dist ? $glob_mysql_test_dir : $glob_basedir;
  585. $glob_timers= mtr_init_timers();
  586. #
  587. # Find the mysqld executable to be able to find the mysqld version
  588. # number as early as possible
  589. #
  590. # Look for the client binaries directory
  591. $path_client_bindir= mtr_path_exists("$glob_basedir/client_release",
  592. "$glob_basedir/client_debug",
  593. vs_config_dirs('client', ''),
  594. "$glob_basedir/client",
  595. "$glob_basedir/bin");
  596. if (!$opt_extern)
  597. {
  598. $exe_mysqld= mtr_exe_exists (vs_config_dirs('sql', 'mysqld'),
  599. "$glob_basedir/sql/mysqld",
  600. "$path_client_bindir/mysqld-max-nt",
  601. "$path_client_bindir/mysqld-max",
  602. "$path_client_bindir/mysqld-nt",
  603. "$path_client_bindir/mysqld",
  604. "$path_client_bindir/mysqld-debug",
  605. "$path_client_bindir/mysqld-max",
  606. "$glob_basedir/libexec/mysqld",
  607. "$glob_basedir/bin/mysqld",
  608. "$glob_basedir/sbin/mysqld");
  609. # Use the mysqld found above to find out what features are available
  610. collect_mysqld_features();
  611. }
  612. else
  613. {
  614. $mysqld_variables{'port'}= 3306;
  615. $mysqld_variables{'master-port'}= 3306;
  616. }
  617. if ( $opt_comment )
  618. {
  619. print "\n";
  620. print '#' x 78, "\n";
  621. print "# $opt_comment\n";
  622. print '#' x 78, "\n\n";
  623. }
  624. foreach my $arg ( @ARGV )
  625. {
  626. if ( $arg =~ /^--skip-/ )
  627. {
  628. push(@opt_extra_mysqld_opt, $arg);
  629. }
  630. elsif ( $arg =~ /^--$/ )
  631. {
  632. # It is an effect of setting 'pass_through' in option processing
  633. # that the lone '--' separating options from arguments survives,
  634. # simply ignore it.
  635. }
  636. elsif ( $arg =~ /^-/ )
  637. {
  638. usage("Invalid option \"$arg\"");
  639. }
  640. else
  641. {
  642. push(@opt_cases, $arg);
  643. }
  644. }
  645. # --------------------------------------------------------------------------
  646. # Find out type of logging that are being used
  647. # --------------------------------------------------------------------------
  648. # NOTE if the default binlog format is changed, this has to be changed
  649. $used_binlog_format= "stmt";
  650. if (!$opt_extern && $mysql_version_id >= 50100 )
  651. {
  652. $used_binlog_format= "mixed"; # Default value for binlog format
  653. foreach my $arg ( @opt_extra_mysqld_opt )
  654. {
  655. if ( $arg =~ /binlog-format=(\S+)/ )
  656. {
  657. $used_binlog_format= $1;
  658. }
  659. }
  660. mtr_report("Using binlog format '$used_binlog_format'");
  661. }
  662. # --------------------------------------------------------------------------
  663. # Find out default storage engine being used(if any)
  664. # --------------------------------------------------------------------------
  665. if ( $opt_with_ndbcluster )
  666. {
  667. # --ndb or --with-ndbcluster turns on --default-storage-engine=ndbcluster
  668. push(@opt_extra_mysqld_opt, "--default-storage-engine=ndbcluster");
  669. }
  670. foreach my $arg ( @opt_extra_mysqld_opt )
  671. {
  672. if ( $arg =~ /default-storage-engine=(\S+)/ )
  673. {
  674. $used_default_engine= $1;
  675. }
  676. }
  677. mtr_report("Using default engine '$used_default_engine'")
  678. if defined $used_default_engine;
  679. # --------------------------------------------------------------------------
  680. # Check if we should speed up tests by trying to run on tmpfs
  681. # --------------------------------------------------------------------------
  682. if ( defined $opt_mem )
  683. {
  684. mtr_error("Can't use --mem and --vardir at the same time ")
  685. if $opt_vardir;
  686. mtr_error("Can't use --mem and --tmpdir at the same time ")
  687. if $opt_tmpdir;
  688. # Search through list of locations that are known
  689. # to be "fast disks" to list to find a suitable location
  690. # Use --mem=<dir> as first location to look.
  691. my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
  692. foreach my $fs (@tmpfs_locations)
  693. {
  694. if ( -d $fs )
  695. {
  696. mtr_report("Using tmpfs in $fs");
  697. $opt_mem= "$fs/var";
  698. $opt_mem .= $opt_mtr_build_thread if $opt_mtr_build_thread;
  699. last;
  700. }
  701. }
  702. }
  703. # --------------------------------------------------------------------------
  704. # Set the "var/" directory, as it is the base for everything else
  705. # --------------------------------------------------------------------------
  706. $default_vardir= "$glob_mysql_test_dir/var";
  707. if ( ! $opt_vardir )
  708. {
  709. $opt_vardir= $default_vardir;
  710. }
  711. elsif ( $mysql_version_id < 50000 and
  712. $opt_vardir ne $default_vardir)
  713. {
  714. # Version 4.1 and --vardir was specified
  715. # Only supported as a symlink from var/
  716. # by setting up $opt_mem that symlink will be created
  717. if ( ! $glob_win32 )
  718. {
  719. # Only platforms that have native symlinks can use the vardir trick
  720. $opt_mem= $opt_vardir;
  721. mtr_report("Using 4.1 vardir trick");
  722. }
  723. $opt_vardir= $default_vardir;
  724. }
  725. $path_vardir_trace= $opt_vardir;
  726. # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
  727. $path_vardir_trace=~ s/^\w://;
  728. # We make the path absolute, as the server will do a chdir() before usage
  729. unless ( $opt_vardir =~ m,^/, or
  730. ($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) )
  731. {
  732. # Make absolute path, relative test dir
  733. $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
  734. }
  735. # --------------------------------------------------------------------------
  736. # Set tmpdir
  737. # --------------------------------------------------------------------------
  738. $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
  739. $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
  740. # --------------------------------------------------------------------------
  741. # Check im suport
  742. # --------------------------------------------------------------------------
  743. if ($opt_extern)
  744. {
  745. mtr_report("Disable instance manager when running with extern mysqld");
  746. $opt_skip_im= 1;
  747. }
  748. elsif ( $mysql_version_id < 50000 )
  749. {
  750. # Instance manager is not supported until 5.0
  751. $opt_skip_im= 1;
  752. }
  753. elsif ( $glob_win32 )
  754. {
  755. mtr_report("Disable Instance manager - testing not supported on Windows");
  756. $opt_skip_im= 1;
  757. }
  758. # --------------------------------------------------------------------------
  759. # Record flag
  760. # --------------------------------------------------------------------------
  761. if ( $opt_record and ! @opt_cases )
  762. {
  763. mtr_error("Will not run in record mode without a specific test case");
  764. }
  765. # --------------------------------------------------------------------------
  766. # Embedded server flag
  767. # --------------------------------------------------------------------------
  768. if ( $opt_embedded_server )
  769. {
  770. $glob_use_embedded_server= 1;
  771. push(@glob_test_mode, "embedded");
  772. $opt_skip_rpl= 1; # We never run replication with embedded
  773. $opt_skip_ndbcluster= 1; # Turn off use of NDB cluster
  774. $opt_skip_ssl= 1; # Turn off use of SSL
  775. if ( $opt_extern )
  776. {
  777. mtr_error("Can't use --extern with --embedded-server");
  778. }
  779. }
  780. # --------------------------------------------------------------------------
  781. # ps protcol flag
  782. # --------------------------------------------------------------------------
  783. if ( $opt_ps_protocol )
  784. {
  785. push(@glob_test_mode, "ps-protocol");
  786. }
  787. # --------------------------------------------------------------------------
  788. # Ndb cluster flags
  789. # --------------------------------------------------------------------------
  790. if ( $opt_ndbconnectstring )
  791. {
  792. $glob_use_running_ndbcluster= 1;
  793. mtr_error("Can't specify --ndb-connectstring and --skip-ndbcluster")
  794. if $opt_skip_ndbcluster;
  795. mtr_error("Can't specify --ndb-connectstring and --ndbcluster-port")
  796. if $opt_ndbcluster_port;
  797. }
  798. else
  799. {
  800. # Set default connect string
  801. $opt_ndbconnectstring= "host=localhost:$opt_ndbcluster_port";
  802. }
  803. if ( $opt_ndbconnectstring_slave )
  804. {
  805. $glob_use_running_ndbcluster_slave= 1;
  806. mtr_error("Can't specify ndb-connectstring_slave and " .
  807. "--skip-ndbcluster-slave")
  808. if $opt_skip_ndbcluster;
  809. mtr_error("Can't specify --ndb-connectstring-slave and " .
  810. "--ndbcluster-port-slave")
  811. if $opt_ndbcluster_port_slave;
  812. }
  813. else
  814. {
  815. # Set default connect string
  816. $opt_ndbconnectstring_slave= "host=localhost:$opt_ndbcluster_port_slave";
  817. }
  818. # --------------------------------------------------------------------------
  819. # Bench flags
  820. # --------------------------------------------------------------------------
  821. if ( $opt_small_bench )
  822. {
  823. $opt_bench= 1;
  824. }
  825. # --------------------------------------------------------------------------
  826. # Big test flags
  827. # --------------------------------------------------------------------------
  828. if ( $opt_big_test )
  829. {
  830. $ENV{'BIG_TEST'}= 1;
  831. }
  832. # --------------------------------------------------------------------------
  833. # Gcov flag
  834. # --------------------------------------------------------------------------
  835. if ( $opt_gcov and ! $source_dist )
  836. {
  837. mtr_error("Coverage test needs the source - please use source dist");
  838. }
  839. # --------------------------------------------------------------------------
  840. # Check debug related options
  841. # --------------------------------------------------------------------------
  842. if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd ||
  843. $opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug ||
  844. $opt_debugger || $opt_client_debugger )
  845. {
  846. # Indicate that we are using debugger
  847. $glob_debugger= 1;
  848. if ( $opt_extern )
  849. {
  850. mtr_error("Can't use --extern when using debugger");
  851. }
  852. }
  853. # --------------------------------------------------------------------------
  854. # Check if special exe was selected for master or slave
  855. # --------------------------------------------------------------------------
  856. $exe_master_mysqld= $exe_master_mysqld || $exe_mysqld;
  857. $exe_slave_mysqld= $exe_slave_mysqld || $exe_mysqld;
  858. # --------------------------------------------------------------------------
  859. # Check valgrind arguments
  860. # --------------------------------------------------------------------------
  861. if ( $opt_valgrind or $opt_valgrind_path or defined $opt_valgrind_options)
  862. {
  863. mtr_report("Turning on valgrind for all executables");
  864. $opt_valgrind= 1;
  865. $opt_valgrind_mysqld= 1;
  866. $opt_valgrind_mysqltest= 1;
  867. }
  868. elsif ( $opt_valgrind_mysqld )
  869. {
  870. mtr_report("Turning on valgrind for mysqld(s) only");
  871. $opt_valgrind= 1;
  872. }
  873. elsif ( $opt_valgrind_mysqltest )
  874. {
  875. mtr_report("Turning on valgrind for mysqltest and mysql_client_test only");
  876. $opt_valgrind= 1;
  877. }
  878. if ( $opt_callgrind )
  879. {
  880. mtr_report("Turning on valgrind with callgrind for mysqld(s)");
  881. $opt_valgrind= 1;
  882. $opt_valgrind_mysqld= 1;
  883. # Set special valgrind options unless options passed on command line
  884. $opt_valgrind_options="--trace-children=yes"
  885. unless defined $opt_valgrind_options;
  886. }
  887. if ( $opt_valgrind )
  888. {
  889. # Set valgrind_options to default unless already defined
  890. $opt_valgrind_options=$default_valgrind_options
  891. unless defined $opt_valgrind_options;
  892. mtr_report("Running valgrind with options \"$opt_valgrind_options\"");
  893. }
  894. if ( ! $opt_testcase_timeout )
  895. {
  896. $opt_testcase_timeout= $default_testcase_timeout;
  897. $opt_testcase_timeout*= 10 if $opt_valgrind;
  898. }
  899. if ( ! $opt_suite_timeout )
  900. {
  901. $opt_suite_timeout= $default_suite_timeout;
  902. $opt_suite_timeout*= 6 if $opt_valgrind;
  903. }
  904. if ( ! $opt_user )
  905. {
  906. if ( $opt_extern )
  907. {
  908. $opt_user= "test";
  909. }
  910. else
  911. {
  912. $opt_user= "root"; # We want to do FLUSH xxx commands
  913. }
  914. }
  915. # On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be
  916. # considered different, so avoid the extra slash (/) in the socket
  917. # paths.
  918. my $sockdir = $opt_tmpdir;
  919. $sockdir =~ s|/+$||;
  920. # On some operating systems, there is a limit to the length of a
  921. # UNIX domain socket's path far below PATH_MAX, so try to avoid long
  922. # socket path names.
  923. $sockdir = tempdir(CLEANUP => 0) if ( length($sockdir) >= 80 );
  924. $master->[0]=
  925. {
  926. pid => 0,
  927. type => "master",
  928. idx => 0,
  929. path_myddir => "$opt_vardir/master-data",
  930. path_myerr => "$opt_vardir/log/master.err",
  931. path_pid => "$opt_vardir/run/master.pid",
  932. path_sock => "$sockdir/master.sock",
  933. port => $opt_master_myport,
  934. start_timeout => 400, # enough time create innodb tables
  935. cluster => 0, # index in clusters list
  936. start_opts => [],
  937. };
  938. $master->[1]=
  939. {
  940. pid => 0,
  941. type => "master",
  942. idx => 1,
  943. path_myddir => "$opt_vardir/master1-data",
  944. path_myerr => "$opt_vardir/log/master1.err",
  945. path_pid => "$opt_vardir/run/master1.pid",
  946. path_sock => "$sockdir/master1.sock",
  947. port => $opt_master_myport + 1,
  948. start_timeout => 400, # enough time create innodb tables
  949. cluster => 0, # index in clusters list
  950. start_opts => [],
  951. };
  952. $slave->[0]=
  953. {
  954. pid => 0,
  955. type => "slave",
  956. idx => 0,
  957. path_myddir => "$opt_vardir/slave-data",
  958. path_myerr => "$opt_vardir/log/slave.err",
  959. path_pid => "$opt_vardir/run/slave.pid",
  960. path_sock => "$sockdir/slave.sock",
  961. port => $opt_slave_myport,
  962. start_timeout => 400,
  963. cluster => 1, # index in clusters list
  964. start_opts => [],
  965. };
  966. $slave->[1]=
  967. {
  968. pid => 0,
  969. type => "slave",
  970. idx => 1,
  971. path_myddir => "$opt_vardir/slave1-data",
  972. path_myerr => "$opt_vardir/log/slave1.err",
  973. path_pid => "$opt_vardir/run/slave1.pid",
  974. path_sock => "$sockdir/slave1.sock",
  975. port => $opt_slave_myport + 1,
  976. start_timeout => 300,
  977. cluster => -1, # index in clusters list
  978. start_opts => [],
  979. };
  980. $slave->[2]=
  981. {
  982. pid => 0,
  983. type => "slave",
  984. idx => 2,
  985. path_myddir => "$opt_vardir/slave2-data",
  986. path_myerr => "$opt_vardir/log/slave2.err",
  987. path_pid => "$opt_vardir/run/slave2.pid",
  988. path_sock => "$sockdir/slave2.sock",
  989. port => $opt_slave_myport + 2,
  990. start_timeout => 300,
  991. cluster => -1, # index in clusters list
  992. start_opts => [],
  993. };
  994. $instance_manager=
  995. {
  996. path_err => "$opt_vardir/log/im.err",
  997. path_log => "$opt_vardir/log/im.log",
  998. path_pid => "$opt_vardir/run/im.pid",
  999. path_angel_pid => "$opt_vardir/run/im.angel.pid",
  1000. path_sock => "$sockdir/im.sock",
  1001. port => $im_port,
  1002. start_timeout => $master->[0]->{'start_timeout'},
  1003. admin_login => 'im_admin',
  1004. admin_password => 'im_admin_secret',
  1005. admin_sha1 => '*598D51AD2DFF7792045D6DF3DDF9AA1AF737B295',
  1006. password_file => "$opt_vardir/im.passwd",
  1007. defaults_file => "$opt_vardir/im.cnf",
  1008. };
  1009. $instance_manager->{'instances'}->[0]=
  1010. {
  1011. server_id => 1,
  1012. port => $im_mysqld1_port,
  1013. path_datadir => "$opt_vardir/im_mysqld_1.data",
  1014. path_sock => "$sockdir/mysqld_1.sock",
  1015. path_pid => "$opt_vardir/run/mysqld_1.pid",
  1016. start_timeout => 400, # enough time create innodb tables
  1017. old_log_format => 1
  1018. };
  1019. $instance_manager->{'instances'}->[1]=
  1020. {
  1021. server_id => 2,
  1022. port => $im_mysqld2_port,
  1023. path_datadir => "$opt_vardir/im_mysqld_2.data",
  1024. path_sock => "$sockdir/mysqld_2.sock",
  1025. path_pid => "$opt_vardir/run/mysqld_2.pid",
  1026. nonguarded => 1,
  1027. start_timeout => 400, # enough time create innodb tables
  1028. old_log_format => 1
  1029. };
  1030. my $data_dir= "$opt_vardir/ndbcluster-$opt_ndbcluster_port";
  1031. $clusters->[0]=
  1032. {
  1033. name => "Master",
  1034. nodes => 2,
  1035. port => "$opt_ndbcluster_port",
  1036. data_dir => "$data_dir",
  1037. connect_string => "$opt_ndbconnectstring",
  1038. path_pid => "$data_dir/ndb_3.pid", # Nodes + 1
  1039. pid => 0, # pid of ndb_mgmd
  1040. installed_ok => 0,
  1041. };
  1042. $data_dir= "$opt_vardir/ndbcluster-$opt_ndbcluster_port_slave";
  1043. $clusters->[1]=
  1044. {
  1045. name => "Slave",
  1046. nodes => 1,
  1047. port => "$opt_ndbcluster_port_slave",
  1048. data_dir => "$data_dir",
  1049. connect_string => "$opt_ndbconnectstring_slave",
  1050. path_pid => "$data_dir/ndb_2.pid", # Nodes + 1
  1051. pid => 0, # pid of ndb_mgmd
  1052. installed_ok => 0,
  1053. };
  1054. # Init pids of ndbd's
  1055. foreach my $cluster ( @{$clusters} )
  1056. {
  1057. for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
  1058. {
  1059. my $nodeid= $idx+1;
  1060. $cluster->{'ndbds'}->[$idx]=
  1061. {
  1062. pid => 0,
  1063. nodeid => $nodeid,
  1064. path_pid => "$cluster->{'data_dir'}/ndb_${nodeid}.pid",
  1065. path_fs => "$cluster->{'data_dir'}/ndb_${nodeid}_fs",
  1066. };
  1067. }
  1068. }
  1069. if ( $opt_extern )
  1070. {
  1071. # Turn off features not supported when running with extern server
  1072. $opt_skip_rpl= 1;
  1073. $opt_skip_ndbcluster= 1;
  1074. # Setup master->[0] with the settings for the extern server
  1075. $master->[0]->{'path_sock'}= $opt_socket ? $opt_socket : "/tmp/mysql.sock";
  1076. mtr_report("Using extern server at '$master->[0]->{path_sock}'");
  1077. }
  1078. else
  1079. {
  1080. mtr_error("--socket can only be used in combination with --extern")
  1081. if $opt_socket;
  1082. }
  1083. $path_timefile= "$opt_vardir/log/mysqltest-time";
  1084. $path_mysqltest_log= "$opt_vardir/log/mysqltest.log";
  1085. $path_current_test_log= "$opt_vardir/log/current_test";
  1086. $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
  1087. $path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/";
  1088. if ( $opt_valgrind and $opt_debug )
  1089. {
  1090. # When both --valgrind and --debug is selected, send
  1091. # all output to the trace file, making it possible to
  1092. # see the exact location where valgrind complains
  1093. foreach my $mysqld (@{$master}, @{$slave})
  1094. {
  1095. my $sidx= $mysqld->{idx} ? "$mysqld->{idx}" : "";
  1096. $mysqld->{path_myerr}=
  1097. "$opt_vardir/log/" . $mysqld->{type} . "$sidx.trace";
  1098. }
  1099. }
  1100. }
  1101. #
  1102. # To make it easier for different devs to work on the same host,
  1103. # an environment variable can be used to control all ports. A small
  1104. # number is to be used, 0 - 16 or similar.
  1105. #
  1106. # Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
  1107. # versions of this script, else a 4.0 test run might conflict with a
  1108. # 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
  1109. # all port numbers might not be used in this version of the script.
  1110. #
  1111. # Also note the limitation of ports we are allowed to hand out. This
  1112. # differs between operating systems and configuration, see
  1113. # http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
  1114. # But a fairly safe range seems to be 5001 - 32767
  1115. #
  1116. sub set_mtr_build_thread_ports($) {
  1117. my $mtr_build_thread= shift;
  1118. if ( lc($mtr_build_thread) eq 'auto' ) {
  1119. print "Requesting build thread... ";
  1120. $ENV{'MTR_BUILD_THREAD'} = $mtr_build_thread = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
  1121. print "got ".$mtr_build_thread."\n";
  1122. }
  1123. # Up to two masters, up to three slaves
  1124. $opt_master_myport= $mtr_build_thread * 10 + 10000; # and 1
  1125. $opt_slave_myport= $opt_master_myport + 2; # and 3 4
  1126. $opt_ndbcluster_port= $opt_master_myport + 5;
  1127. $opt_ndbcluster_port_slave= $opt_master_myport + 6;
  1128. $im_port= $opt_master_myport + 7;
  1129. $im_mysqld1_port= $opt_master_myport + 8;
  1130. $im_mysqld2_port= $opt_master_myport + 9;
  1131. if ( $opt_master_myport < 5001 or $opt_master_myport + 10 >= 32767 )
  1132. {
  1133. mtr_error("MTR_BUILD_THREAD number results in a port",
  1134. "outside 5001 - 32767",
  1135. "($opt_master_myport - $opt_master_myport + 10)");
  1136. }
  1137. }
  1138. sub datadir_list_setup () {
  1139. # Make a list of all data_dirs
  1140. for (my $idx= 0; $idx < $max_master_num; $idx++)
  1141. {
  1142. push(@data_dir_lst, $master->[$idx]->{'path_myddir'});
  1143. }
  1144. for (my $idx= 0; $idx < $max_slave_num; $idx++)
  1145. {
  1146. push(@data_dir_lst, $slave->[$idx]->{'path_myddir'});
  1147. }
  1148. unless ($opt_skip_im)
  1149. {
  1150. foreach my $instance (@{$instance_manager->{'instances'}})
  1151. {
  1152. push(@data_dir_lst, $instance->{'path_datadir'});
  1153. }
  1154. }
  1155. }
  1156. ##############################################################################
  1157. #
  1158. # Set paths to various executable programs
  1159. #
  1160. ##############################################################################
  1161. sub collect_mysqld_features () {
  1162. my $found_variable_list_start= 0;
  1163. #
  1164. # Execute "mysqld --no-defaults --help --verbose" to get a
  1165. # list of all features and settings
  1166. #
  1167. my $list= `$exe_mysqld --no-defaults --verbose --help`;
  1168. foreach my $line (split('\n', $list))
  1169. {
  1170. # First look for version
  1171. if ( !$mysql_version_id )
  1172. {
  1173. # Look for version
  1174. my $exe_name= basename($exe_mysqld);
  1175. mtr_verbose("exe_name: $exe_name");
  1176. if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)/ )
  1177. {
  1178. #print "Major: $1 Minor: $2 Build: $3\n";
  1179. $mysql_version_id= $1*10000 + $2*100 + $3;
  1180. #print "mysql_version_id: $mysql_version_id\n";
  1181. mtr_report("MySQL Version $1.$2.$3");
  1182. }
  1183. }
  1184. else
  1185. {
  1186. if (!$found_variable_list_start)
  1187. {
  1188. # Look for start of variables list
  1189. if ( $line =~ /[\-]+\s[\-]+/ )
  1190. {
  1191. $found_variable_list_start= 1;
  1192. }
  1193. }
  1194. else
  1195. {
  1196. # Put variables into hash
  1197. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  1198. {
  1199. # print "$1=\"$2\"\n";
  1200. $mysqld_variables{$1}= $2;
  1201. }
  1202. else
  1203. {
  1204. # The variable list is ended with a blank line
  1205. if ( $line =~ /^[\s]*$/ )
  1206. {
  1207. last;
  1208. }
  1209. else
  1210. {
  1211. # Send out a warning, we should fix the variables that has no
  1212. # space between variable name and it's value
  1213. # or should it be fixed width column parsing? It does not
  1214. # look like that in function my_print_variables in my_getopt.c
  1215. mtr_warning("Could not parse variable list line : $line");
  1216. }
  1217. }
  1218. }
  1219. }
  1220. }
  1221. mtr_error("Could not find version of MySQL") unless $mysql_version_id;
  1222. mtr_error("Could not find variabes list") unless $found_variable_list_start;
  1223. }
  1224. sub run_query($$) {
  1225. my ($mysqld, $query)= @_;
  1226. my $args;
  1227. mtr_init_args(\$args);
  1228. mtr_add_arg($args, "--no-defaults");
  1229. mtr_add_arg($args, "--user=%s", $opt_user);
  1230. mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
  1231. mtr_add_arg($args, "--socket=%s", $mysqld->{'path_sock'});
  1232. mtr_add_arg($args, "--silent"); # Tab separated output
  1233. mtr_add_arg($args, "-e '%s'", $query);
  1234. my $cmd= "$exe_mysql " . join(' ', @$args);
  1235. mtr_verbose("cmd: $cmd");
  1236. return `$cmd`;
  1237. }
  1238. sub collect_mysqld_features_from_running_server ()
  1239. {
  1240. my $list= run_query($master->[0], "use mysql; SHOW VARIABLES");
  1241. foreach my $line (split('\n', $list))
  1242. {
  1243. # Put variables into hash
  1244. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  1245. {
  1246. print "$1=\"$2\"\n";
  1247. $mysqld_variables{$1}= $2;
  1248. }
  1249. }
  1250. }
  1251. sub executable_setup_im () {
  1252. # Look for instance manager binary - mysqlmanager
  1253. $exe_im=
  1254. mtr_exe_maybe_exists(
  1255. "$glob_basedir/server-tools/instance-manager/mysqlmanager",
  1256. "$glob_basedir/libexec/mysqlmanager",
  1257. "$glob_basedir/bin/mysqlmanager",
  1258. "$glob_basedir/sbin/mysqlmanager");
  1259. return ($exe_im eq "");
  1260. }
  1261. sub executable_setup_ndb () {
  1262. # Look for ndb tols and binaries
  1263. my $ndb_path= mtr_file_exists("$glob_basedir/ndb",
  1264. "$glob_basedir/storage/ndb",
  1265. "$glob_basedir/bin");
  1266. $exe_ndbd=
  1267. mtr_exe_maybe_exists("$ndb_path/src/kernel/ndbd",
  1268. "$ndb_path/ndbd");
  1269. $exe_ndb_mgm=
  1270. mtr_exe_maybe_exists("$ndb_path/src/mgmclient/ndb_mgm",
  1271. "$ndb_path/ndb_mgm");
  1272. $exe_ndb_mgmd=
  1273. mtr_exe_maybe_exists("$ndb_path/src/mgmsrv/ndb_mgmd",
  1274. "$ndb_path/ndb_mgmd");
  1275. $exe_ndb_waiter=
  1276. mtr_exe_maybe_exists("$ndb_path/tools/ndb_waiter",
  1277. "$ndb_path/ndb_waiter");
  1278. # May not exist
  1279. $path_ndb_tools_dir= mtr_file_exists("$ndb_path/tools",
  1280. "$ndb_path");
  1281. # May not exist
  1282. $path_ndb_examples_dir=
  1283. mtr_file_exists("$ndb_path/ndbapi-examples",
  1284. "$ndb_path/examples");
  1285. # May not exist
  1286. $exe_ndb_example=
  1287. mtr_file_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple");
  1288. return ( $exe_ndbd eq "" or
  1289. $exe_ndb_mgm eq "" or
  1290. $exe_ndb_mgmd eq "" or
  1291. $exe_ndb_waiter eq "");
  1292. }
  1293. sub executable_setup () {
  1294. #
  1295. # Check if libtool is available in this distribution/clone
  1296. # we need it when valgrinding or debugging non installed binary
  1297. # Otherwise valgrind will valgrind the libtool wrapper or bash
  1298. # and gdb will not find the real executable to debug
  1299. #
  1300. if ( -x "../libtool")
  1301. {
  1302. $exe_libtool= "../libtool";
  1303. if ($opt_valgrind or $glob_debugger)
  1304. {
  1305. mtr_report("Using \"$exe_libtool\" when running valgrind or debugger");
  1306. }
  1307. }
  1308. # Look for language files and charsetsdir, use same share
  1309. my $path_share= mtr_path_exists("$glob_basedir/share/mysql",
  1310. "$glob_basedir/sql/share",
  1311. "$glob_basedir/share");
  1312. $path_language= mtr_path_exists("$path_share/english");
  1313. $path_charsetsdir= mtr_path_exists("$path_share/charsets");
  1314. # Look for my_print_defaults
  1315. $exe_my_print_defaults=
  1316. mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
  1317. "$path_client_bindir/my_print_defaults",
  1318. "$glob_basedir/extra/my_print_defaults");
  1319. # Look for perror
  1320. $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
  1321. "$glob_basedir/extra/perror",
  1322. "$path_client_bindir/perror");
  1323. # Look for the client binaries
  1324. $exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck");
  1325. $exe_mysqldump= mtr_exe_exists("$path_client_bindir/mysqldump");
  1326. $exe_mysqlimport= mtr_exe_exists("$path_client_bindir/mysqlimport");
  1327. $exe_mysqlshow= mtr_exe_exists("$path_client_bindir/mysqlshow");
  1328. $exe_mysqlbinlog= mtr_exe_exists("$path_client_bindir/mysqlbinlog");
  1329. $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin");
  1330. $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql");
  1331. if (!$opt_extern)
  1332. {
  1333. # Look for SQL scripts directory
  1334. if ( mtr_file_exists("$path_share/mysql_system_tables.sql") ne "")
  1335. {
  1336. # The SQL scripts are in path_share
  1337. $path_sql_dir= $path_share;
  1338. }
  1339. else
  1340. {
  1341. $path_sql_dir= mtr_path_exists("$glob_basedir/share",
  1342. "$glob_basedir/scripts");
  1343. }
  1344. if ( $mysql_version_id >= 50100 ) {
  1345. $exe_mysqlslap= mtr_exe_exists("$path_client_bindir/mysqlslap");
  1346. }
  1347. if ( $mysql_version_id >= 50000 and !$glob_use_embedded_server ) {
  1348. $exe_mysql_upgrade= mtr_exe_exists("$path_client_bindir/mysql_upgrade")
  1349. } else {
  1350. $exe_mysql_upgrade= "";
  1351. }
  1352. if ( ! $glob_win32 ) {
  1353. # Look for mysql_fix_system_table script
  1354. $exe_mysql_fix_system_tables=
  1355. mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables",
  1356. "$path_client_bindir/mysql_fix_privilege_tables");
  1357. }
  1358. # Look for mysql_fix_privilege_tables.sql script
  1359. $file_mysql_fix_privilege_tables=
  1360. mtr_file_exists("$glob_basedir/scripts/mysql_fix_privilege_tables.sql",
  1361. "$glob_basedir/share/mysql_fix_privilege_tables.sql");
  1362. if ( ! $opt_skip_ndbcluster and executable_setup_ndb()) {
  1363. mtr_warning("Could not find all required ndb binaries, " .
  1364. "all ndb tests will fail, use --skip-ndbcluster to " .
  1365. "skip testing it.");
  1366. foreach my $cluster (@{$clusters}) {
  1367. $cluster->{"executable_setup_failed"}= 1;
  1368. }
  1369. }
  1370. if ( ! $opt_skip_im and executable_setup_im()) {
  1371. mtr_warning("Could not find all required instance manager binaries, " .
  1372. "all im tests will fail, use --skip-im to " .
  1373. "continue without instance manager");
  1374. $instance_manager->{"executable_setup_failed"}= 1;
  1375. }
  1376. # Look for the udf_example library
  1377. $lib_udf_example=
  1378. mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'),
  1379. "$glob_basedir/sql/.libs/udf_example.so",);
  1380. }
  1381. # Look for mysqltest executable
  1382. if ( $glob_use_embedded_server )
  1383. {
  1384. $exe_mysqltest=
  1385. mtr_exe_exists(vs_config_dirs('libmysqld/examples','mysqltest_embedded'),
  1386. "$glob_basedir/libmysqld/examples/mysqltest_embedded",
  1387. "$path_client_bindir/mysqltest_embedded");
  1388. }
  1389. else
  1390. {
  1391. $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest");
  1392. }
  1393. # Look for mysql_client_test executable which may _not_ exist in
  1394. # some versions, test using it should be skipped
  1395. if ( $glob_use_embedded_server )
  1396. {
  1397. $exe_mysql_client_test=
  1398. mtr_exe_maybe_exists(
  1399. vs_config_dirs('libmysqld/examples', 'mysql_client_test_embedded'),
  1400. "$glob_basedir/libmysqld/examples/mysql_client_test_embedded");
  1401. }
  1402. else
  1403. {
  1404. $exe_mysql_client_test=
  1405. mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
  1406. "$glob_basedir/tests/mysql_client_test",
  1407. "$glob_basedir/bin/mysql_client_test");
  1408. }
  1409. }
  1410. sub generate_cmdline_mysqldump ($) {
  1411. my($mysqld) = @_;
  1412. return
  1413. mtr_native_path($exe_mysqldump) .
  1414. " --no-defaults -uroot " .
  1415. "--port=$mysqld->{'port'} " .
  1416. "--socket=$mysqld->{'path_sock'} --password=";
  1417. }
  1418. ##############################################################################
  1419. #
  1420. # Set environment to be used by childs of this process for
  1421. # things that are constant duting the whole lifetime of mysql-test-run.pl
  1422. #
  1423. ##############################################################################
  1424. sub mysql_client_test_arguments()
  1425. {
  1426. my $exe= $exe_mysql_client_test;
  1427. my $args;
  1428. mtr_init_args(\$args);
  1429. if ( $opt_valgrind_mysqltest )
  1430. {
  1431. valgrind_arguments($args, \$exe);
  1432. }
  1433. mtr_add_arg($args, "--no-defaults");
  1434. mtr_add_arg($args, "--testcase");
  1435. mtr_add_arg($args, "--user=root");
  1436. mtr_add_arg($args, "--port=$master->[0]->{'port'}");
  1437. mtr_add_arg($args, "--socket=$master->[0]->{'path_sock'}");
  1438. if ( $opt_extern || $mysql_version_id >= 50000 )
  1439. {
  1440. mtr_add_arg($args, "--vardir=$opt_vardir")
  1441. }
  1442. if ( $opt_debug )
  1443. {
  1444. mtr_add_arg($args,
  1445. "--debug=d:t:A,$path_vardir_trace/log/mysql_client_test.trace");
  1446. }
  1447. if ( $glob_use_embedded_server )
  1448. {
  1449. mtr_add_arg($args,
  1450. " -A --language=$path_language");
  1451. mtr_add_arg($args,
  1452. " -A --datadir=$slave->[0]->{'path_myddir'}");
  1453. mtr_add_arg($args,
  1454. " -A --character-sets-dir=$path_charsetsdir");
  1455. }
  1456. return join(" ", $exe, @$args);
  1457. }
  1458. sub mysql_upgrade_arguments()
  1459. {
  1460. my $exe= $exe_mysql_upgrade;
  1461. my $args;
  1462. mtr_init_args(\$args);
  1463. # if ( $opt_valgrind_mysql_ugrade )
  1464. # {
  1465. # valgrind_arguments($args, \$exe);
  1466. # }
  1467. mtr_add_arg($args, "--no-defaults");
  1468. mtr_add_arg($args, "--user=root");
  1469. mtr_add_arg($args, "--port=$master->[0]->{'port'}");
  1470. mtr_add_arg($args, "--socket=$master->[0]->{'path_sock'}");
  1471. mtr_add_arg($args, "--datadir=$master->[0]->{'path_myddir'}");
  1472. mtr_add_arg($args, "--basedir=$glob_basedir");
  1473. if ( $opt_debug )
  1474. {
  1475. mtr_add_arg($args,
  1476. "--debug=d:t:A,$path_vardir_trace/log/mysql_upgrade.trace");
  1477. }
  1478. return join(" ", $exe, @$args);
  1479. }
  1480. # Note that some env is setup in spawn/run, in "mtr_process.pl"
  1481. sub environment_setup () {
  1482. umask(022);
  1483. my @ld_library_paths;
  1484. # --------------------------------------------------------------------------
  1485. # Setup LD_LIBRARY_PATH so the libraries from this distro/clone
  1486. # are used in favor of the system installed ones
  1487. # --------------------------------------------------------------------------
  1488. if ( $source_dist )
  1489. {
  1490. push(@ld_library_paths, "$glob_basedir/libmysql/.libs/",
  1491. "$glob_basedir/libmysql_r/.libs/",
  1492. "$glob_basedir/zlib.libs/");
  1493. }
  1494. else
  1495. {
  1496. push(@ld_library_paths, "$glob_basedir/lib");
  1497. }
  1498. # --------------------------------------------------------------------------
  1499. # Add the path where libndbclient can be found
  1500. # --------------------------------------------------------------------------
  1501. if ( $glob_ndbcluster_supported )
  1502. {
  1503. push(@ld_library_paths, "$glob_basedir/storage/ndb/src/.libs");
  1504. }
  1505. # --------------------------------------------------------------------------
  1506. # Add the path where mysqld will find udf_example.so
  1507. # --------------------------------------------------------------------------
  1508. if ( $lib_udf_example )
  1509. {
  1510. push(@ld_library_paths, dirname($lib_udf_example));
  1511. }
  1512. # --------------------------------------------------------------------------
  1513. # Valgrind need to be run with debug libraries otherwise it's almost
  1514. # impossible to add correct supressions, that means if "/usr/lib/debug"
  1515. # is available, it should be added to
  1516. # LD_LIBRARY_PATH
  1517. #
  1518. # But pthread is broken in libc6-dbg on Debian <= 3.1 (see Debian
  1519. # bug 399035, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=399035),
  1520. # so don't change LD_LIBRARY_PATH on that platform.
  1521. # --------------------------------------------------------------------------
  1522. my $debug_libraries_path= "/usr/lib/debug";
  1523. my $deb_version;
  1524. if ( $opt_valgrind and -d $debug_libraries_path and
  1525. (! -e '/etc/debian_version' or
  1526. ($deb_version= mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
  1527. $deb_version > 3.1 ) )
  1528. {
  1529. push(@ld_library_paths, $debug_libraries_path);
  1530. }
  1531. $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  1532. $ENV{'LD_LIBRARY_PATH'} ?
  1533. split(':', $ENV{'LD_LIBRARY_PATH'}) : ());
  1534. mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
  1535. $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  1536. $ENV{'DYLD_LIBRARY_PATH'} ?
  1537. split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
  1538. mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
  1539. # --------------------------------------------------------------------------
  1540. # Also command lines in .opt files may contain env vars
  1541. # --------------------------------------------------------------------------
  1542. $ENV{'CHARSETSDIR'}= $path_charsetsdir;
  1543. $ENV{'UMASK'}= "0660"; # The octal *string*
  1544. $ENV{'UMASK_DIR'}= "0770"; # The octal *string*
  1545. $ENV{'LC_COLLATE'}= "C";
  1546. $ENV{'USE_RUNNING_SERVER'}= $opt_extern;
  1547. $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
  1548. $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
  1549. $ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir;
  1550. $ENV{'MASTER_MYSOCK'}= $master->[0]->{'path_sock'};
  1551. $ENV{'MASTER_MYSOCK1'}= $master->[1]->{'path_sock'};
  1552. $ENV{'MASTER_MYPORT'}= $master->[0]->{'port'};
  1553. $ENV{'MASTER_MYPORT1'}= $master->[1]->{'port'};
  1554. $ENV{'SLAVE_MYSOCK'}= $slave->[0]->{'path_sock'};
  1555. $ENV{'SLAVE_MYPORT'}= $slave->[0]->{'port'};
  1556. $ENV{'SLAVE_MYPORT1'}= $slave->[1]->{'port'};
  1557. $ENV{'SLAVE_MYPORT2'}= $slave->[2]->{'port'};
  1558. $ENV{'MYSQL_TCP_PORT'}= $mysqld_variables{'port'};
  1559. $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'};
  1560. $ENV{'IM_PATH_SOCK'}= $instance_manager->{path_sock};
  1561. $ENV{'IM_USERNAME'}= $instance_manager->{admin_login};
  1562. $ENV{'IM_PASSWORD'}= $instance_manager->{admin_password};
  1563. $ENV{MTR_BUILD_THREAD}= $opt_mtr_build_thread;
  1564. $ENV{'EXE_MYSQL'}= $exe_mysql;
  1565. # ----------------------------------------------------
  1566. # Setup env for NDB
  1567. # ----------------------------------------------------
  1568. if ( ! $opt_skip_ndbcluster )
  1569. {
  1570. $ENV{'NDB_MGM'}= $exe_ndb_mgm;
  1571. $ENV{'NDBCLUSTER_PORT'}= $opt_ndbcluster_port;
  1572. $ENV{'NDBCLUSTER_PORT_SLAVE'}= $opt_ndbcluster_port_slave;
  1573. $ENV{'NDB_EXTRA_TEST'}= $opt_ndb_extra_test;
  1574. $ENV{'NDB_BACKUP_DIR'}= $clusters->[0]->{'data_dir'};
  1575. $ENV{'NDB_DATA_DIR'}= $clusters->[0]->{'data_dir'};
  1576. $ENV{'NDB_TOOLS_DIR'}= $path_ndb_tools_dir;
  1577. $ENV{'NDB_TOOLS_OUTPUT'}= $path_ndb_testrun_log;
  1578. $ENV{'NDB_CONNECTSTRING'}= $opt_ndbconnectstring;
  1579. if ( $mysql_version_id >= 50000 )
  1580. {
  1581. $ENV{'NDB_EXAMPLES_DIR'}= $path_ndb_examples_dir;
  1582. $ENV{'MY_NDB_EXAMPLES_BINARY'}= $exe_ndb_example;
  1583. }
  1584. $ENV{'NDB_EXAMPLES_OUTPUT'}= $path_ndb_testrun_log;
  1585. }
  1586. # ----------------------------------------------------
  1587. # Setup env for IM
  1588. # ----------------------------------------------------
  1589. if ( ! $opt_skip_im )
  1590. {
  1591. $ENV{'IM_EXE'}= $exe_im;
  1592. $ENV{'IM_PATH_PID'}= $instance_manager->{path_pid};
  1593. $ENV{'IM_PATH_ANGEL_PID'}= $instance_manager->{path_angel_pid};
  1594. $ENV{'IM_PORT'}= $instance_manager->{port};
  1595. $ENV{'IM_DEFAULTS_PATH'}= $instance_manager->{defaults_file};
  1596. $ENV{'IM_PASSWORD_PATH'}= $instance_manager->{password_file};
  1597. $ENV{'IM_MYSQLD1_SOCK'}=
  1598. $instance_manager->{instances}->[0]->{path_sock};
  1599. $ENV{'IM_MYSQLD1_PORT'}=
  1600. $instance_manager->{instances}->[0]->{port};
  1601. $ENV{'IM_MYSQLD1_PATH_PID'}=
  1602. $instance_manager->{instances}->[0]->{path_pid};
  1603. $ENV{'IM_MYSQLD2_SOCK'}=
  1604. $instance_manager->{instances}->[1]->{path_sock};
  1605. $ENV{'IM_MYSQLD2_PORT'}=
  1606. $instance_manager->{instances}->[1]->{port};
  1607. $ENV{'IM_MYSQLD2_PATH_PID'}=
  1608. $instance_manager->{instances}->[1]->{path_pid};
  1609. }
  1610. # ----------------------------------------------------
  1611. # Setup env so childs can execute mysqlcheck
  1612. # ----------------------------------------------------
  1613. my $cmdline_mysqlcheck=
  1614. mtr_native_path($exe_mysqlcheck) .
  1615. " --no-defaults -uroot " .
  1616. "--port=$master->[0]->{'port'} " .
  1617. "--socket=$master->[0]->{'path_sock'} --password=";
  1618. if ( $opt_debug )
  1619. {
  1620. $cmdline_mysqlcheck .=
  1621. " --debug=d:t:A,$path_vardir_trace/log/mysqlcheck.trace";
  1622. }
  1623. $ENV{'MYSQL_CHECK'}= $cmdline_mysqlcheck;
  1624. # ----------------------------------------------------
  1625. # Setup env to childs can execute myqldump
  1626. # ----------------------------------------------------
  1627. my $cmdline_mysqldump= generate_cmdline_mysqldump($master->[0]);
  1628. my $cmdline_mysqldumpslave= generate_cmdline_mysqldump($slave->[0]);
  1629. if ( $opt_debug )
  1630. {
  1631. $cmdline_mysqldump .=
  1632. " --debug=d:t:A,$path_vardir_trace/log/mysqldump-master.trace";
  1633. $cmdline_mysqldumpslave .=
  1634. " --debug=d:t:A,$path_vardir_trace/log/mysqldump-slave.trace";
  1635. }
  1636. $ENV{'MYSQL_DUMP'}= $cmdline_mysqldump;
  1637. $ENV{'MYSQL_DUMP_SLAVE'}= $cmdline_mysqldumpslave;
  1638. # ----------------------------------------------------
  1639. # Setup env so childs can execute mysqlslap
  1640. # ----------------------------------------------------
  1641. if ( $exe_mysqlslap )
  1642. {
  1643. my $cmdline_mysqlslap=
  1644. mtr_native_path($exe_mysqlslap) .
  1645. " -uroot " .
  1646. "--port=$master->[0]->{'port'} " .
  1647. "--socket=$master->[0]->{'path_sock'} --password= " .
  1648. "--lock-directory=$opt_tmpdir";
  1649. if ( $opt_debug )
  1650. {
  1651. $cmdline_mysqlslap .=
  1652. " --debug=d:t:A,$path_vardir_trace/log/mysqlslap.trace";
  1653. }
  1654. $ENV{'MYSQL_SLAP'}= $cmdline_mysqlslap;
  1655. }
  1656. # ----------------------------------------------------
  1657. # Setup env so childs can execute mysqlimport
  1658. # ----------------------------------------------------
  1659. my $cmdline_mysqlimport=
  1660. mtr_native_path($exe_mysqlimport) .
  1661. " -uroot " .
  1662. "--port=$master->[0]->{'port'} " .
  1663. "--socket=$master->[0]->{'path_sock'} --password=";
  1664. if ( $opt_debug )
  1665. {
  1666. $cmdline_mysqlimport .=
  1667. " --debug=d:t:A,$path_vardir_trace/log/mysqlimport.trace";
  1668. }
  1669. $ENV{'MYSQL_IMPORT'}= $cmdline_mysqlimport;
  1670. # ----------------------------------------------------
  1671. # Setup env so childs can execute mysqlshow
  1672. # ----------------------------------------------------
  1673. my $cmdline_mysqlshow=
  1674. mtr_native_path($exe_mysqlshow) .
  1675. " -uroot " .
  1676. "--port=$master->[0]->{'port'} " .
  1677. "--socket=$master->[0]->{'path_sock'} --password=";
  1678. if ( $opt_debug )
  1679. {
  1680. $cmdline_mysqlshow .=
  1681. " --debug=d:t:A,$path_vardir_trace/log/mysqlshow.trace";
  1682. }
  1683. $ENV{'MYSQL_SHOW'}= $cmdline_mysqlshow;
  1684. # ----------------------------------------------------
  1685. # Setup env so childs can execute mysqlbinlog
  1686. # ----------------------------------------------------
  1687. my $cmdline_mysqlbinlog=
  1688. mtr_native_path($exe_mysqlbinlog) .
  1689. " --no-defaults";
  1690. if (!$opt_extern && $mysql_version_id >= 50000 )
  1691. {
  1692. $cmdline_mysqlbinlog .=" --character-sets-dir=$path_charsetsdir";
  1693. }
  1694. if ( $opt_debug )
  1695. {
  1696. $cmdline_mysqlbinlog .=
  1697. " --debug=d:t:A,$path_vardir_trace/log/mysqlbinlog.trace";
  1698. }
  1699. $ENV{'MYSQL_BINLOG'}= $cmdline_mysqlbinlog;
  1700. # ----------------------------------------------------
  1701. # Setup env so childs can execute mysql
  1702. # ----------------------------------------------------
  1703. my $cmdline_mysql=
  1704. mtr_native_path($exe_mysql) .
  1705. " --no-defaults --host=localhost --user=root --password= " .
  1706. "--port=$master->[0]->{'port'} " .
  1707. "--socket=$master->[0]->{'path_sock'} ".
  1708. "--character-sets-dir=$path_charsetsdir";
  1709. $ENV{'MYSQL'}= $cmdline_mysql;
  1710. # ----------------------------------------------------
  1711. # Setup env so childs can execute mysql_client_test
  1712. # ----------------------------------------------------
  1713. $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
  1714. # ----------------------------------------------------
  1715. # Setup env so childs can execute mysql_upgrade
  1716. # ----------------------------------------------------
  1717. if ( !$opt_extern && $mysql_version_id >= 50000 )
  1718. {
  1719. $ENV{'MYSQL_UPGRADE'}= mysql_upgrade_arguments();
  1720. }
  1721. # ----------------------------------------------------
  1722. # Setup env so childs can execute mysql_fix_system_tables
  1723. # ----------------------------------------------------
  1724. if ( !$opt_extern && ! $glob_win32 )
  1725. {
  1726. my $cmdline_mysql_fix_system_tables=
  1727. "$exe_mysql_fix_system_tables --no-defaults --host=localhost " .
  1728. "--user=root --password= " .
  1729. "--basedir=$glob_basedir --bindir=$path_client_bindir --verbose " .
  1730. "--port=$master->[0]->{'port'} " .
  1731. "--socket=$master->[0]->{'path_sock'}";
  1732. $ENV{'MYSQL_FIX_SYSTEM_TABLES'}= $cmdline_mysql_fix_system_tables;
  1733. }
  1734. $ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
  1735. # ----------------------------------------------------
  1736. # Setup env so childs can execute my_print_defaults
  1737. # ----------------------------------------------------
  1738. $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= mtr_native_path($exe_my_print_defaults);
  1739. # ----------------------------------------------------
  1740. # Setup env so childs can execute mysqladmin
  1741. # ----------------------------------------------------
  1742. $ENV{'MYSQLADMIN'}= mtr_native_path($exe_mysqladmin);
  1743. # ----------------------------------------------------
  1744. # Setup env so childs can execute perror
  1745. # ----------------------------------------------------
  1746. $ENV{'MY_PERROR'}= mtr_native_path($exe_perror);
  1747. # ----------------------------------------------------
  1748. # Add the path where mysqld will find udf_example.so
  1749. # ----------------------------------------------------
  1750. $ENV{'UDF_EXAMPLE_LIB'}=
  1751. ($lib_udf_example ? basename($lib_udf_example) : "");
  1752. $ENV{'LD_LIBRARY_PATH'}=
  1753. ($lib_udf_example ? dirname($lib_udf_example) : "") .
  1754. ($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : "");
  1755. # ----------------------------------------------------
  1756. # We are nice and report a bit about our settings
  1757. # ----------------------------------------------------
  1758. if (!$opt_extern)
  1759. {
  1760. print "Using MTR_BUILD_THREAD = $ENV{MTR_BUILD_THREAD}\n";
  1761. print "Using MASTER_MYPORT = $ENV{MASTER_MYPORT}\n";
  1762. print "Using MASTER_MYPORT1 = $ENV{MASTER_MYPORT1}\n";
  1763. print "Using SLAVE_MYPORT = $ENV{SLAVE_MYPORT}\n";
  1764. print "Using SLAVE_MYPORT1 = $ENV{SLAVE_MYPORT1}\n";
  1765. print "Using SLAVE_MYPORT2 = $ENV{SLAVE_MYPORT2}\n";
  1766. if ( ! $opt_skip_ndbcluster )
  1767. {
  1768. print "Using NDBCLUSTER_PORT = $ENV{NDBCLUSTER_PORT}\n";
  1769. if ( ! $opt_skip_ndbcluster_slave )
  1770. {
  1771. print "Using NDBCLUSTER_PORT_SLAVE = $ENV{NDBCLUSTER_PORT_SLAVE}\n";
  1772. }
  1773. }
  1774. if ( ! $opt_skip_im )
  1775. {
  1776. print "Using IM_PORT = $ENV{IM_PORT}\n";
  1777. print "Using IM_MYSQLD1_PORT = $ENV{IM_MYSQLD1_PORT}\n";
  1778. print "Using IM_MYSQLD2_PORT = $ENV{IM_MYSQLD2_PORT}\n";
  1779. }
  1780. }
  1781. # Create an environment variable to make it possible
  1782. # to detect that valgrind is being used from test cases
  1783. $ENV{'VALGRIND_TEST'}= $opt_valgrind;
  1784. }
  1785. ##############################################################################
  1786. #
  1787. # If we get a ^C, we try to clean up before termination
  1788. #
  1789. ##############################################################################
  1790. # FIXME check restrictions what to do in a signal handler
  1791. sub signal_setup () {
  1792. $SIG{INT}= \&handle_int_signal;
  1793. }
  1794. sub handle_int_signal () {
  1795. $SIG{INT}= 'DEFAULT'; # If we get a ^C again, we die...
  1796. mtr_warning("got INT signal, cleaning up.....");
  1797. stop_all_servers();
  1798. mtr_error("We die from ^C signal from user");
  1799. }
  1800. ##############################################################################
  1801. #
  1802. # Handle left overs from previous runs
  1803. #
  1804. ##############################################################################
  1805. sub kill_running_servers () {
  1806. if ( $opt_fast or $glob_use_embedded_server )
  1807. {
  1808. # FIXME is embedded server really using PID files?!
  1809. unlink($master->[0]->{'path_pid'});
  1810. unlink($master->[1]->{'path_pid'});
  1811. unlink($slave->[0]->{'path_pid'});
  1812. unlink($slave->[1]->{'path_pid'});
  1813. unlink($slave->[2]->{'path_pid'});
  1814. }
  1815. else
  1816. {
  1817. # Ensure that no old mysqld test servers are running
  1818. # This is different from terminating processes we have
  1819. # started from this run of the script, this is terminating
  1820. # leftovers from previous runs.
  1821. mtr_kill_leftovers();
  1822. }
  1823. }
  1824. #
  1825. # Remove var and any directories in var/ created by previous
  1826. # tests
  1827. #
  1828. sub remove_stale_vardir () {
  1829. mtr_report("Removing Stale Files");
  1830. # Safety!
  1831. mtr_error("No, don't remove the vardir when running with --extern")
  1832. if $opt_extern;
  1833. mtr_verbose("opt_vardir: $opt_vardir");
  1834. if ( $opt_vardir eq $default_vardir )
  1835. {
  1836. #
  1837. # Running with "var" in mysql-test dir
  1838. #
  1839. if ( -l $opt_vardir)
  1840. {
  1841. # var is a symlink
  1842. if ( $opt_mem and readlink($opt_vardir) eq $opt_mem )
  1843. {
  1844. # Remove the directory which the link points at
  1845. mtr_verbose("Removing " . readlink($opt_vardir));
  1846. rmtree(readlink($opt_vardir));
  1847. # Remove the "var" symlink
  1848. mtr_verbose("unlink($opt_vardir)");
  1849. unlink($opt_vardir);
  1850. }
  1851. elsif ( $opt_mem )
  1852. {
  1853. # Just remove the "var" symlink
  1854. mtr_report("WARNING: Removing '$opt_vardir' symlink it's wrong");
  1855. mtr_verbose("unlink($opt_vardir)");
  1856. unlink($opt_vardir);
  1857. }
  1858. else
  1859. {
  1860. # Some users creates a soft link in mysql-test/var to another area
  1861. # - allow it, but remove all files in it
  1862. mtr_report("WARNING: Using the 'mysql-test/var' symlink");
  1863. # Make sure the directory where it points exist
  1864. mtr_error("The destination for symlink $opt_vardir does not exist")
  1865. if ! -d readlink($opt_vardir);
  1866. foreach my $bin ( glob("$opt_vardir/*") )
  1867. {
  1868. mtr_verbose("Removing bin $bin");
  1869. rmtree($bin);
  1870. }
  1871. }
  1872. }
  1873. else
  1874. {
  1875. # Remove the entire "var" dir
  1876. mtr_verbose("Removing $opt_vardir/");
  1877. rmtree("$opt_vardir/");
  1878. }
  1879. if ( $opt_mem )
  1880. {
  1881. # A symlink from var/ to $opt_mem will be set up
  1882. # remove the $opt_mem dir to assure the symlink
  1883. # won't point at an old directory
  1884. mtr_verbose("Removing $opt_mem");
  1885. rmtree($opt_mem);
  1886. }
  1887. }
  1888. else
  1889. {
  1890. #
  1891. # Running with "var" in some other place
  1892. #
  1893. # Remove the var/ dir in mysql-test dir if any
  1894. # this could be an old symlink that shouldn't be there
  1895. mtr_verbose("Removing $default_vardir");
  1896. rmtree($default_vardir);
  1897. # Remove the "var" dir
  1898. mtr_verbose("Removing $opt_vardir/");
  1899. rmtree("$opt_vardir/");
  1900. }
  1901. }
  1902. #
  1903. # Create var and the directories needed in var
  1904. #
  1905. sub setup_vardir() {
  1906. mtr_report("Creating Directories");
  1907. if ( $opt_vardir eq $default_vardir )
  1908. {
  1909. #
  1910. # Running with "var" in mysql-test dir
  1911. #
  1912. if ( -l $opt_vardir )
  1913. {
  1914. # it's a symlink
  1915. # Make sure the directory where it points exist
  1916. mtr_error("The destination for symlink $opt_vardir does not exist")
  1917. if ! -d readlink($opt_vardir);
  1918. }
  1919. elsif ( $opt_mem )
  1920. {
  1921. # Runinng with "var" as a link to some "memory" location, normally tmpfs
  1922. mtr_verbose("Creating $opt_mem");
  1923. mkpath($opt_mem);
  1924. mtr_report("Symlinking 'var' to '$opt_mem'");
  1925. symlink($opt_mem, $opt_vardir);
  1926. }
  1927. }
  1928. if ( ! -d $opt_vardir )
  1929. {
  1930. mtr_verbose("Creating $opt_vardir");
  1931. mkpath($opt_vardir);
  1932. }
  1933. # Ensure a proper error message if vardir couldn't be created
  1934. unless ( -d $opt_vardir and -w $opt_vardir )
  1935. {
  1936. mtr_error("Writable 'var' directory is needed, use the " .
  1937. "'--vardir=<path>' option");
  1938. }
  1939. mkpath("$opt_vardir/log");
  1940. mkpath("$opt_vardir/run");
  1941. mkpath("$opt_vardir/tmp");
  1942. mkpath($opt_tmpdir) if $opt_tmpdir ne "$opt_vardir/tmp";
  1943. # Create new data dirs
  1944. foreach my $data_dir (@data_dir_lst)
  1945. {
  1946. mkpath("$data_dir/mysql");
  1947. mkpath("$data_dir/test");
  1948. }
  1949. # Make a link std_data_ln in var/ that points to std_data
  1950. if ( ! $glob_win32 )
  1951. {
  1952. symlink("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data_ln");
  1953. }
  1954. else
  1955. {
  1956. # on windows, copy all files from std_data into var/std_data_ln
  1957. mkpath("$opt_vardir/std_data_ln");
  1958. opendir(DIR, "$glob_mysql_test_dir/std_data")
  1959. or mtr_error("Can't find the std_data directory: $!");
  1960. for(readdir(DIR)) {
  1961. next if -d "$glob_mysql_test_dir/std_data/$_";
  1962. copy("$glob_mysql_test_dir/std_data/$_", "$opt_vardir/std_data_ln/$_");
  1963. }
  1964. closedir(DIR);
  1965. }
  1966. # Remove old log files
  1967. foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
  1968. {
  1969. unlink($name);
  1970. }
  1971. }
  1972. sub check_running_as_root () {
  1973. # Check if running as root
  1974. # i.e a file can be read regardless what mode we set it to
  1975. my $test_file= "$opt_vardir/test_running_as_root.txt";
  1976. mtr_tofile($test_file, "MySQL");
  1977. chmod(oct("0000"), $test_file);
  1978. my $result="";
  1979. if (open(FILE,"<",$test_file))
  1980. {
  1981. $result= join('', <FILE>);
  1982. close FILE;
  1983. }
  1984. chmod(oct("0755"), $test_file);
  1985. unlink($test_file);
  1986. $ENV{'MYSQL_TEST_ROOT'}= "NO";
  1987. if ($result eq "MySQL")
  1988. {
  1989. mtr_warning("running this script as _root_ will cause some " .
  1990. "tests to be skipped");
  1991. $ENV{'MYSQL_TEST_ROOT'}= "YES";
  1992. }
  1993. }
  1994. sub check_ssl_support ($) {
  1995. my $mysqld_variables= shift;
  1996. if ($opt_skip_ssl || $opt_extern)
  1997. {
  1998. if (!$opt_extern)
  1999. {
  2000. mtr_report("Skipping SSL");
  2001. }
  2002. $opt_ssl_supported= 0;
  2003. $opt_ssl= 0;
  2004. return;
  2005. }
  2006. if ( ! $mysqld_variables->{'ssl'} )
  2007. {
  2008. if ( $opt_ssl)
  2009. {
  2010. mtr_error("Couldn't find support for SSL");
  2011. return;
  2012. }
  2013. mtr_report("Skipping SSL, mysqld not compiled with SSL");
  2014. $opt_ssl_supported= 0;
  2015. $opt_ssl= 0;
  2016. return;
  2017. }
  2018. mtr_report("Setting mysqld to support SSL connections");
  2019. $opt_ssl_supported= 1;
  2020. }
  2021. sub check_debug_support ($) {
  2022. my $mysqld_variables= shift;
  2023. if ( ! $mysqld_variables->{'debug'} )
  2024. {
  2025. #mtr_report("Binaries are not debug compiled");
  2026. $debug_compiled_binaries= 0;
  2027. if ( $opt_debug )
  2028. {
  2029. mtr_error("Can't use --debug, binaries does not support it");
  2030. }
  2031. return;
  2032. }
  2033. mtr_report("Binaries are debug compiled");
  2034. $debug_compiled_binaries= 1;
  2035. }
  2036. ##############################################################################
  2037. #
  2038. # Helper function to handle configuration-based subdirectories which Visual
  2039. # Studio uses for storing binaries. If opt_vs_config is set, this returns
  2040. # a path based on that setting; if not, it returns paths for the default
  2041. # /release/ and /debug/ subdirectories.
  2042. #
  2043. # $exe can be undefined, if the directory itself will be used
  2044. #
  2045. ###############################################################################
  2046. sub vs_config_dirs ($$) {
  2047. my ($path_part, $exe) = @_;
  2048. $exe = "" if not defined $exe;
  2049. if ($opt_vs_config)
  2050. {
  2051. return ("$glob_basedir/$path_part/$opt_vs_config/$exe");
  2052. }
  2053. return ("$glob_basedir/$path_part/release/$exe",
  2054. "$glob_basedir/$path_part/debug/$exe");
  2055. }
  2056. ##############################################################################
  2057. #
  2058. # Start the ndb cluster
  2059. #
  2060. ##############################################################################
  2061. sub check_ndbcluster_support ($) {
  2062. my $mysqld_variables= shift;
  2063. if ($opt_skip_ndbcluster || $opt_extern)
  2064. {
  2065. if (!$opt_extern)
  2066. {
  2067. mtr_report("Skipping ndbcluster");
  2068. }
  2069. $opt_skip_ndbcluster_slave= 1;
  2070. return;
  2071. }
  2072. if ( ! $mysqld_variables->{'ndb-connectstring'} )
  2073. {
  2074. mtr_report("Skipping ndbcluster, mysqld not compiled with ndbcluster");
  2075. $opt_skip_ndbcluster= 1;
  2076. $opt_skip_ndbcluster_slave= 1;
  2077. return;
  2078. }
  2079. $glob_ndbcluster_supported= 1;
  2080. mtr_report("Using ndbcluster when necessary, mysqld supports it");
  2081. if ( $mysql_version_id < 50100 )
  2082. {
  2083. # Slave cluster is not supported until 5.1
  2084. $opt_skip_ndbcluster_slave= 1;
  2085. }
  2086. return;
  2087. }
  2088. sub ndbcluster_start_install ($) {
  2089. my $cluster= shift;
  2090. mtr_report("Installing $cluster->{'name'} Cluster");
  2091. mkdir($cluster->{'data_dir'});
  2092. # Create a config file from template
  2093. my $ndb_no_ord=512;
  2094. my $ndb_no_attr=2048;
  2095. my $ndb_con_op=105000;
  2096. my $ndb_dmem="80M";
  2097. my $ndb_imem="24M";
  2098. my $ndb_pbmem="32M";
  2099. my $nodes= $cluster->{'nodes'};
  2100. my $ndb_host= "localhost";
  2101. my $ndb_diskless= 0;
  2102. if (!$opt_bench)
  2103. {
  2104. # Use a smaller configuration
  2105. if ( $mysql_version_id < 50100 )
  2106. {
  2107. # 4.1 and 5.0 is using a "larger" --small configuration
  2108. $ndb_no_ord=128;
  2109. $ndb_con_op=10000;
  2110. $ndb_dmem="40M";
  2111. $ndb_imem="12M";
  2112. }
  2113. else
  2114. {
  2115. $ndb_no_ord=32;
  2116. $ndb_con_op=5000;
  2117. $ndb_dmem="20M";
  2118. $ndb_imem="1M";
  2119. $ndb_pbmem="4M";
  2120. }
  2121. }
  2122. my $config_file_template= "ndb/ndb_config_${nodes}_node.ini";
  2123. my $config_file= "$cluster->{'data_dir'}/config.ini";
  2124. open(IN, $config_file_template)
  2125. or mtr_error("Can't open $config_file_template: $!");
  2126. open(OUT, ">", $config_file)
  2127. or mtr_error("Can't write to $config_file: $!");
  2128. while (<IN>)
  2129. {
  2130. chomp;
  2131. s/CHOOSE_MaxNoOfAttributes/$ndb_no_attr/;
  2132. s/CHOOSE_MaxNoOfOrderedIndexes/$ndb_no_ord/;
  2133. s/CHOOSE_MaxNoOfConcurrentOperations/$ndb_con_op/;
  2134. s/CHOOSE_DataMemory/$ndb_dmem/;
  2135. s/CHOOSE_IndexMemory/$ndb_imem/;
  2136. s/CHOOSE_Diskless/$ndb_diskless/;
  2137. s/CHOOSE_HOSTNAME_.*/$ndb_host/;
  2138. s/CHOOSE_FILESYSTEM/$cluster->{'data_dir'}/;
  2139. s/CHOOSE_PORT_MGM/$cluster->{'port'}/;
  2140. if ( $mysql_version_id < 50000 )
  2141. {
  2142. my $base_port= $cluster->{'port'} + 1;
  2143. s/CHOOSE_PORT_TRANSPORTER/$base_port/;
  2144. }
  2145. s/CHOOSE_DiskPageBufferMemory/$ndb_pbmem/;
  2146. print OUT "$_ \n";
  2147. }
  2148. close OUT;
  2149. close IN;
  2150. # Start cluster with "--initial"
  2151. ndbcluster_start($cluster, "--initial");
  2152. return 0;
  2153. }
  2154. sub ndbcluster_wait_started($$){
  2155. my $cluster= shift;
  2156. my $ndb_waiter_extra_opt= shift;
  2157. my $path_waiter_log= "$cluster->{'data_dir'}/ndb_waiter.log";
  2158. my $args;
  2159. mtr_init_args(\$args);
  2160. mtr_add_arg($args, "--no-defaults");
  2161. mtr_add_arg($args, "--core");
  2162. mtr_add_arg($args, "--ndb-connectstring=%s", $cluster->{'connect_string'});
  2163. mtr_add_arg($args, "--timeout=60");
  2164. if ($ndb_waiter_extra_opt)
  2165. {
  2166. mtr_add_arg($args, "$ndb_waiter_extra_opt");
  2167. }
  2168. # Start the ndb_waiter which will connect to the ndb_mgmd
  2169. # and poll it for state of the ndbd's, will return when
  2170. # all nodes in the cluster is started
  2171. my $res= mtr_run($exe_ndb_waiter, $args,
  2172. "", $path_waiter_log, $path_waiter_log, "");
  2173. mtr_verbose("ndbcluster_wait_started, returns: $res") if $res;
  2174. return $res;
  2175. }
  2176. sub mysqld_wait_started($){
  2177. my $mysqld= shift;
  2178. my $res= sleep_until_file_created($mysqld->{'path_pid'},
  2179. $mysqld->{'start_timeout'},
  2180. $mysqld->{'pid'});
  2181. return $res == 0;
  2182. }
  2183. sub ndb_mgmd_wait_started($) {
  2184. my ($cluster)= @_;
  2185. my $retries= 100;
  2186. while (ndbcluster_wait_started($cluster, "--no-contact") and
  2187. $retries)
  2188. {
  2189. # Millisceond sleep emulated with select
  2190. select(undef, undef, undef, (0.1));
  2191. $retries--;
  2192. }
  2193. return $retries == 0;
  2194. }
  2195. sub ndb_mgmd_start ($) {
  2196. my $cluster= shift;
  2197. my $args; # Arg vector
  2198. my $pid= -1;
  2199. mtr_init_args(\$args);
  2200. mtr_add_arg($args, "--no-defaults");
  2201. mtr_add_arg($args, "--core");
  2202. mtr_add_arg($args, "--nodaemon");
  2203. mtr_add_arg($args, "--config-file=%s", "$cluster->{'data_dir'}/config.ini");
  2204. my $path_ndb_mgmd_log= "$cluster->{'data_dir'}/\l$cluster->{'name'}_ndb_mgmd.log";
  2205. $pid= mtr_spawn($exe_ndb_mgmd, $args, "",
  2206. $path_ndb_mgmd_log,
  2207. $path_ndb_mgmd_log,
  2208. "",
  2209. { append_log_file => 1 });
  2210. # FIXME Should not be needed
  2211. # Unfortunately the cluster nodes will fail to start
  2212. # if ndb_mgmd has not started properly
  2213. if (ndb_mgmd_wait_started($cluster))
  2214. {
  2215. mtr_error("Failed to wait for start of ndb_mgmd");
  2216. }
  2217. # Remember pid of ndb_mgmd
  2218. $cluster->{'pid'}= $pid;
  2219. mtr_verbose("ndb_mgmd_start, pid: $pid");
  2220. return $pid;
  2221. }
  2222. sub ndbd_start ($$$) {
  2223. my $cluster= shift;
  2224. my $idx= shift;
  2225. my $extra_args= shift;
  2226. my $args; # Arg vector
  2227. my $pid= -1;
  2228. mtr_init_args(\$args);
  2229. mtr_add_arg($args, "--no-defaults");
  2230. mtr_add_arg($args, "--core");
  2231. mtr_add_arg($args, "--ndb-connectstring=%s", "$cluster->{'connect_string'}");
  2232. if ( $mysql_version_id >= 50000)
  2233. {
  2234. mtr_add_arg($args, "--character-sets-dir=%s", "$path_charsetsdir");
  2235. }
  2236. mtr_add_arg($args, "--nodaemon");
  2237. mtr_add_arg($args, "$extra_args");
  2238. my $nodeid= $cluster->{'ndbds'}->[$idx]->{'nodeid'};
  2239. my $path_ndbd_log= "$cluster->{'data_dir'}/ndb_${nodeid}.log";
  2240. $pid= mtr_spawn($exe_ndbd, $args, "",
  2241. $path_ndbd_log,
  2242. $path_ndbd_log,
  2243. "",
  2244. { append_log_file => 1 });
  2245. # Add pid to list of pids for this cluster
  2246. $cluster->{'ndbds'}->[$idx]->{'pid'}= $pid;
  2247. # Rememeber options used when starting
  2248. $cluster->{'ndbds'}->[$idx]->{'start_extra_args'}= $extra_args;
  2249. $cluster->{'ndbds'}->[$idx]->{'idx'}= $idx;
  2250. mtr_verbose("ndbd_start, pid: $pid");
  2251. return $pid;
  2252. }
  2253. sub ndbcluster_start ($$) {
  2254. my $cluster= shift;
  2255. my $extra_args= shift;
  2256. mtr_verbose("ndbcluster_start '$cluster->{'name'}'");
  2257. if ( $glob_use_running_ndbcluster )
  2258. {
  2259. return 0;
  2260. }
  2261. if ( $cluster->{'pid'} )
  2262. {
  2263. mtr_error("Cluster '$cluster->{'name'}' already started");
  2264. }
  2265. ndb_mgmd_start($cluster);
  2266. for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
  2267. {
  2268. ndbd_start($cluster, $idx, $extra_args);
  2269. }
  2270. return 0;
  2271. }
  2272. sub rm_ndbcluster_tables ($) {
  2273. my $dir= shift;
  2274. foreach my $bin ( glob("$dir/mysql/apply_status*"),
  2275. glob("$dir/mysql/schema*"))
  2276. {
  2277. unlink($bin);
  2278. }
  2279. }
  2280. ##############################################################################
  2281. #
  2282. # Run the benchmark suite
  2283. #
  2284. ##############################################################################
  2285. sub run_benchmarks ($) {
  2286. my $benchmark= shift;
  2287. my $args;
  2288. if ( ! $glob_use_embedded_server )
  2289. {
  2290. mysqld_start($master->[0],[],[]);
  2291. if ( ! $master->[0]->{'pid'} )
  2292. {
  2293. mtr_error("Can't start the mysqld server");
  2294. }
  2295. }
  2296. mtr_init_args(\$args);
  2297. mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_sock'});
  2298. mtr_add_arg($args, "--user=%s", $opt_user);
  2299. if ( $opt_small_bench )
  2300. {
  2301. mtr_add_arg($args, "--small-test");
  2302. mtr_add_arg($args, "--small-tables");
  2303. }
  2304. if ( $opt_with_ndbcluster )
  2305. {
  2306. mtr_add_arg($args, "--create-options=TYPE=ndb");
  2307. }
  2308. chdir($glob_mysql_bench_dir)
  2309. or mtr_error("Couldn't chdir to '$glob_mysql_bench_dir': $!");
  2310. if ( ! $benchmark )
  2311. {
  2312. mtr_add_arg($args, "--log");
  2313. mtr_run("$glob_mysql_bench_dir/run-all-tests", $args, "", "", "", "");
  2314. # FIXME check result code?!
  2315. }
  2316. elsif ( -x $benchmark )
  2317. {
  2318. mtr_run("$glob_mysql_bench_dir/$benchmark", $args, "", "", "", "");
  2319. # FIXME check result code?!
  2320. }
  2321. else
  2322. {
  2323. mtr_error("Benchmark $benchmark not found");
  2324. }
  2325. chdir($glob_mysql_test_dir); # Go back
  2326. if ( ! $glob_use_embedded_server )
  2327. {
  2328. stop_masters();
  2329. }
  2330. }
  2331. ##############################################################################
  2332. #
  2333. # Run the test suite
  2334. #
  2335. ##############################################################################
  2336. sub run_suite () {
  2337. my ($suite, $tests)= @_;
  2338. mtr_print_thick_line();
  2339. mtr_timer_start($glob_timers,"suite", 60 * $opt_suite_timeout);
  2340. mtr_report("Starting Tests in the '$suite' suite");
  2341. mtr_report_tests_not_skipped_though_disabled($tests);
  2342. mtr_print_header();
  2343. foreach my $tinfo ( @$tests )
  2344. {
  2345. if (run_testcase_check_skip_test($tinfo))
  2346. {
  2347. next;
  2348. }
  2349. mtr_timer_start($glob_timers,"testcase", 60 * $opt_testcase_timeout);
  2350. run_testcase($tinfo);
  2351. mtr_timer_stop($glob_timers,"testcase");
  2352. }
  2353. mtr_print_line();
  2354. if ( ! $glob_debugger and
  2355. ! $opt_extern and
  2356. ! $glob_use_embedded_server )
  2357. {
  2358. stop_all_servers();
  2359. }
  2360. if ( $opt_gcov )
  2361. {
  2362. gcov_collect(); # collect coverage information
  2363. }
  2364. if ( $opt_gprof )
  2365. {
  2366. gprof_collect(); # collect coverage information
  2367. }
  2368. mtr_report_stats($tests);
  2369. mtr_timer_stop($glob_timers,"suite");
  2370. }
  2371. ##############################################################################
  2372. #
  2373. # Initiate the test databases
  2374. #
  2375. ##############################################################################
  2376. sub initialize_servers () {
  2377. datadir_list_setup();
  2378. if ( $opt_extern )
  2379. {
  2380. # Running against an already started server, if the specified
  2381. # vardir does not already exist it should be created
  2382. if ( ! -d $opt_vardir )
  2383. {
  2384. mtr_report("Creating '$opt_vardir'");
  2385. setup_vardir();
  2386. }
  2387. else
  2388. {
  2389. if ($opt_verbose)
  2390. {
  2391. mtr_report("No need to create '$opt_vardir' it already exists");
  2392. }
  2393. }
  2394. }
  2395. else
  2396. {
  2397. kill_running_servers();
  2398. if ( ! $opt_start_dirty )
  2399. {
  2400. remove_stale_vardir();
  2401. setup_vardir();
  2402. mysql_install_db();
  2403. if ( $opt_force )
  2404. {
  2405. # Save a snapshot of the freshly installed db
  2406. # to make it possible to restore to a known point in time
  2407. save_installed_db();
  2408. }
  2409. }
  2410. }
  2411. check_running_as_root();
  2412. }
  2413. sub mysql_install_db () {
  2414. install_db('master', $master->[0]->{'path_myddir'});
  2415. if ($max_master_num)
  2416. {
  2417. copy_install_db('master', $master->[1]->{'path_myddir'});
  2418. }
  2419. # Install the number of slave databses needed
  2420. for (my $idx= 0; $idx < $max_slave_num; $idx++)
  2421. {
  2422. copy_install_db("slave".($idx+1), $slave->[$idx]->{'path_myddir'});
  2423. }
  2424. if ( ! $opt_skip_im )
  2425. {
  2426. im_prepare_env($instance_manager);
  2427. }
  2428. my $cluster_started_ok= 1; # Assume it can be started
  2429. if ($opt_skip_ndbcluster || $glob_use_running_ndbcluster ||
  2430. $clusters->[0]->{executable_setup_failed})
  2431. {
  2432. # Don't install master cluster
  2433. }
  2434. elsif (ndbcluster_start_install($clusters->[0]))
  2435. {
  2436. mtr_warning("Failed to start install of $clusters->[0]->{name}");
  2437. $cluster_started_ok= 0;
  2438. }
  2439. if ($max_slave_num == 0 ||
  2440. $opt_skip_ndbcluster_slave || $glob_use_running_ndbcluster_slave ||
  2441. $clusters->[1]->{executable_setup_failed})
  2442. {
  2443. # Don't install slave cluster
  2444. }
  2445. elsif (ndbcluster_start_install($clusters->[1]))
  2446. {
  2447. mtr_warning("Failed to start install of $clusters->[1]->{name}");
  2448. $cluster_started_ok= 0;
  2449. }
  2450. foreach my $cluster (@{$clusters})
  2451. {
  2452. next if !$cluster->{'pid'};
  2453. $cluster->{'installed_ok'}= 1; # Assume install suceeds
  2454. if (ndbcluster_wait_started($cluster, ""))
  2455. {
  2456. # failed to install, disable usage and flag that its no ok
  2457. mtr_report("ndbcluster_install of $cluster->{'name'} failed");
  2458. $cluster->{"installed_ok"}= 0;
  2459. $cluster_started_ok= 0;
  2460. }
  2461. }
  2462. if ( ! $cluster_started_ok )
  2463. {
  2464. if ( $opt_force)
  2465. {
  2466. # Continue without cluster
  2467. }
  2468. else
  2469. {
  2470. mtr_error("To continue, re-run with '--force'.");
  2471. }
  2472. }
  2473. return 0;
  2474. }
  2475. sub copy_install_db ($$) {
  2476. my $type= shift;
  2477. my $data_dir= shift;
  2478. mtr_report("Installing \u$type Database");
  2479. # Just copy the installed db from first master
  2480. mtr_copy_dir($master->[0]->{'path_myddir'}, $data_dir);
  2481. }
  2482. sub install_db ($$) {
  2483. my $type= shift;
  2484. my $data_dir= shift;
  2485. mtr_report("Installing \u$type Database");
  2486. my $args;
  2487. mtr_init_args(\$args);
  2488. mtr_add_arg($args, "--no-defaults");
  2489. mtr_add_arg($args, "--bootstrap");
  2490. mtr_add_arg($args, "--basedir=%s", $path_my_basedir);
  2491. mtr_add_arg($args, "--datadir=%s", $data_dir);
  2492. mtr_add_arg($args, "--skip-innodb");
  2493. mtr_add_arg($args, "--skip-ndbcluster");
  2494. mtr_add_arg($args, "--tmpdir=.");
  2495. mtr_add_arg($args, "--core-file");
  2496. if ( $opt_debug )
  2497. {
  2498. mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap_%s.trace",
  2499. $path_vardir_trace, $type);
  2500. }
  2501. if ( ! $glob_netware )
  2502. {
  2503. mtr_add_arg($args, "--language=%s", $path_language);
  2504. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  2505. }
  2506. # If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
  2507. # configure --disable-grant-options), mysqld will not recognize the
  2508. # --bootstrap or --skip-grant-tables options. The user can set
  2509. # MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
  2510. # --bootstrap, to accommodate this.
  2511. my $exe_mysqld_bootstrap = $ENV{'MYSQLD_BOOTSTRAP'} || $exe_mysqld;
  2512. # ----------------------------------------------------------------------
  2513. # export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
  2514. # ----------------------------------------------------------------------
  2515. $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
  2516. # ----------------------------------------------------------------------
  2517. # Create the bootstrap.sql file
  2518. # ----------------------------------------------------------------------
  2519. my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
  2520. # Use the mysql database for system tables
  2521. mtr_tofile($bootstrap_sql_file, "use mysql");
  2522. # Add the offical mysql system tables
  2523. # for a production system
  2524. mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables.sql",
  2525. $bootstrap_sql_file);
  2526. # Add the mysql system tables initial data
  2527. # for a production system
  2528. mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables_data.sql",
  2529. $bootstrap_sql_file);
  2530. # Add test data for timezone - this is just a subset, on a real
  2531. # system these tables will be populated either by mysql_tzinfo_to_sql
  2532. # or by downloading the timezone table package from our website
  2533. mtr_appendfile_to_file("$path_sql_dir/mysql_test_data_timezone.sql",
  2534. $bootstrap_sql_file);
  2535. # Fill help tables, just an empty file when running from bk repo
  2536. # but will be replaced by a real fill_help_tables.sql when
  2537. # building the source dist
  2538. mtr_appendfile_to_file("$path_sql_dir/fill_help_tables.sql",
  2539. $bootstrap_sql_file);
  2540. # Log bootstrap command
  2541. my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
  2542. mtr_tofile($path_bootstrap_log,
  2543. "$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
  2544. if ( mtr_run($exe_mysqld_bootstrap, $args, $bootstrap_sql_file,
  2545. $path_bootstrap_log, $path_bootstrap_log,
  2546. "", { append_log_file => 1 }) != 0 )
  2547. {
  2548. mtr_error("Error executing mysqld --bootstrap\n" .
  2549. "Could not install system database from $bootstrap_sql_file\n" .
  2550. "see $path_bootstrap_log for errors");
  2551. }
  2552. }
  2553. sub im_prepare_env($) {
  2554. my $instance_manager = shift;
  2555. im_create_passwd_file($instance_manager);
  2556. im_prepare_data_dir($instance_manager);
  2557. }
  2558. sub im_create_passwd_file($) {
  2559. my $instance_manager = shift;
  2560. my $pwd_file_path = $instance_manager->{'password_file'};
  2561. mtr_report("Creating IM password file ($pwd_file_path)");
  2562. open(OUT, ">", $pwd_file_path)
  2563. or mtr_error("Can't write to $pwd_file_path: $!");
  2564. print OUT $instance_manager->{'admin_login'}, ":",
  2565. $instance_manager->{'admin_sha1'}, "\n";
  2566. close(OUT);
  2567. }
  2568. sub im_create_defaults_file($) {
  2569. my $instance_manager = shift;
  2570. my $defaults_file = $instance_manager->{'defaults_file'};
  2571. open(OUT, ">", $defaults_file)
  2572. or mtr_error("Can't write to $defaults_file: $!");
  2573. print OUT <<EOF
  2574. [mysql]
  2575. [manager]
  2576. pid-file = $instance_manager->{path_pid}
  2577. angel-pid-file = $instance_manager->{path_angel_pid}
  2578. socket = $instance_manager->{path_sock}
  2579. port = $instance_manager->{port}
  2580. password-file = $instance_manager->{password_file}
  2581. default-mysqld-path = $exe_mysqld
  2582. EOF
  2583. ;
  2584. foreach my $instance (@{$instance_manager->{'instances'}})
  2585. {
  2586. my $server_id = $instance->{'server_id'};
  2587. print OUT <<EOF
  2588. [mysqld$server_id]
  2589. socket = $instance->{path_sock}
  2590. pid-file = $instance->{path_pid}
  2591. port = $instance->{port}
  2592. datadir = $instance->{path_datadir}
  2593. log = $instance->{path_datadir}/mysqld$server_id.log
  2594. log-error = $instance->{path_datadir}/mysqld$server_id.err.log
  2595. log-slow-queries = $instance->{path_datadir}/mysqld$server_id.slow.log
  2596. language = $path_language
  2597. character-sets-dir = $path_charsetsdir
  2598. basedir = $path_my_basedir
  2599. server_id = $server_id
  2600. shutdown-delay = 10
  2601. skip-stack-trace
  2602. skip-innodb
  2603. skip-ndbcluster
  2604. EOF
  2605. ;
  2606. if ( $mysql_version_id < 50100 )
  2607. {
  2608. print OUT "skip-bdb\n";
  2609. }
  2610. print OUT "nonguarded\n" if $instance->{'nonguarded'};
  2611. if ( $mysql_version_id >= 50100 )
  2612. {
  2613. print OUT "log-output=FILE\n" if $instance->{'old_log_format'};
  2614. }
  2615. print OUT "\n";
  2616. }
  2617. close(OUT);
  2618. }
  2619. sub im_prepare_data_dir($) {
  2620. my $instance_manager = shift;
  2621. foreach my $instance (@{$instance_manager->{'instances'}})
  2622. {
  2623. copy_install_db(
  2624. 'im_mysqld_' . $instance->{'server_id'},
  2625. $instance->{'path_datadir'});
  2626. }
  2627. }
  2628. #
  2629. # Restore snapshot of the installed slave databases
  2630. # if the snapshot exists
  2631. #
  2632. sub restore_slave_databases ($) {
  2633. my ($num_slaves)= @_;
  2634. if ( -d $path_snapshot)
  2635. {
  2636. for (my $idx= 0; $idx < $num_slaves; $idx++)
  2637. {
  2638. my $data_dir= $slave->[$idx]->{'path_myddir'};
  2639. my $name= basename($data_dir);
  2640. rmtree($data_dir);
  2641. mtr_copy_dir("$path_snapshot/$name", $data_dir);
  2642. }
  2643. }
  2644. }
  2645. sub run_testcase_check_skip_test($)
  2646. {
  2647. my ($tinfo)= @_;
  2648. # ----------------------------------------------------------------------
  2649. # If marked to skip, just print out and return.
  2650. # Note that a test case not marked as 'skip' can still be
  2651. # skipped later, because of the test case itself in cooperation
  2652. # with the mysqltest program tells us so.
  2653. # ----------------------------------------------------------------------
  2654. if ( $tinfo->{'skip'} )
  2655. {
  2656. mtr_report_test_name($tinfo);
  2657. mtr_report_test_skipped($tinfo);
  2658. return 1;
  2659. }
  2660. if ($tinfo->{'ndb_test'})
  2661. {
  2662. foreach my $cluster (@{$clusters})
  2663. {
  2664. last if ($opt_skip_ndbcluster_slave and
  2665. $cluster->{'name'} eq 'Slave');
  2666. # If test needs this cluster, check binaries was found ok
  2667. if ( $cluster->{'executable_setup_failed'} )
  2668. {
  2669. mtr_report_test_name($tinfo);
  2670. $tinfo->{comment}=
  2671. "Failed to find cluster binaries";
  2672. mtr_report_test_failed($tinfo);
  2673. return 1;
  2674. }
  2675. # If test needs this cluster, check it was installed ok
  2676. if ( !$cluster->{'installed_ok'} )
  2677. {
  2678. mtr_report_test_name($tinfo);
  2679. $tinfo->{comment}=
  2680. "Cluster $cluster->{'name'} was not installed ok";
  2681. mtr_report_test_failed($tinfo);
  2682. return 1;
  2683. }
  2684. }
  2685. }
  2686. if ( $tinfo->{'component_id'} eq 'im' )
  2687. {
  2688. # If test needs im, check binaries was found ok
  2689. if ( $instance_manager->{'executable_setup_failed'} )
  2690. {
  2691. mtr_report_test_name($tinfo);
  2692. $tinfo->{comment}=
  2693. "Failed to find MySQL manager binaries";
  2694. mtr_report_test_failed($tinfo);
  2695. return 1;
  2696. }
  2697. }
  2698. return 0;
  2699. }
  2700. sub do_before_run_mysqltest($)
  2701. {
  2702. my $tinfo= shift;
  2703. my $tname= $tinfo->{'name'};
  2704. # Remove old files produced by mysqltest
  2705. my $result_dir= "r";
  2706. if ( $opt_suite ne "main" )
  2707. {
  2708. $result_dir= "suite/$opt_suite/r";
  2709. }
  2710. unlink("$result_dir/$tname.reject");
  2711. unlink("$result_dir/$tname.progress");
  2712. unlink("$result_dir/$tname.log");
  2713. unlink("$result_dir/$tname.warnings");
  2714. if (!$opt_extern)
  2715. {
  2716. if ( $mysql_version_id < 50000 ) {
  2717. # Set environment variable NDB_STATUS_OK to 1
  2718. # if script decided to run mysqltest cluster _is_ installed ok
  2719. $ENV{'NDB_STATUS_OK'} = "1";
  2720. } elsif ( $mysql_version_id < 50100 ) {
  2721. # Set environment variable NDB_STATUS_OK to YES
  2722. # if script decided to run mysqltest cluster _is_ installed ok
  2723. $ENV{'NDB_STATUS_OK'} = "YES";
  2724. }
  2725. }
  2726. }
  2727. sub do_after_run_mysqltest($)
  2728. {
  2729. my $tinfo= shift;
  2730. my $tname= $tinfo->{'name'};
  2731. # Save info from this testcase run to mysqltest.log
  2732. mtr_appendfile_to_file($path_current_test_log, $path_mysqltest_log)
  2733. if -f $path_current_test_log;
  2734. mtr_appendfile_to_file($path_timefile, $path_mysqltest_log)
  2735. if -f $path_timefile;
  2736. # Remove the file that mysqltest writes info to
  2737. unlink($path_timefile);
  2738. }
  2739. sub run_testcase_mark_logs($)
  2740. {
  2741. my ($log_msg)= @_;
  2742. # Write a marker to all log files
  2743. # The file indicating current test name
  2744. mtr_tonewfile($path_current_test_log, $log_msg);
  2745. # each mysqld's .err file
  2746. foreach my $mysqld (@{$master}, @{$slave})
  2747. {
  2748. mtr_tofile($mysqld->{path_myerr}, $log_msg);
  2749. }
  2750. # ndbcluster log file
  2751. mtr_tofile($path_ndb_testrun_log, $log_msg);
  2752. }
  2753. sub find_testcase_skipped_reason($)
  2754. {
  2755. my ($tinfo)= @_;
  2756. # Open mysqltest-time
  2757. my $F= IO::File->new($path_timefile) or
  2758. mtr_error("can't open file \"$path_timefile\": $!");
  2759. my $reason;
  2760. while ( my $line= <$F> )
  2761. {
  2762. # Look for "reason: <reason for skipping test>"
  2763. if ( $line =~ /reason: (.*)/ )
  2764. {
  2765. $reason= $1;
  2766. }
  2767. }
  2768. if ( ! $reason )
  2769. {
  2770. mtr_warning("Could not find reason for skipping test in $path_timefile");
  2771. $reason= "Detected by testcase(reason unknown) ";
  2772. }
  2773. $tinfo->{'comment'}= $reason;
  2774. }
  2775. sub analyze_testcase_failure_sync_with_master($)
  2776. {
  2777. my ($tinfo)= @_;
  2778. my $args;
  2779. mtr_init_args(\$args);
  2780. mtr_add_arg($args, "--no-defaults");
  2781. mtr_add_arg($args, "--silent");
  2782. mtr_add_arg($args, "--skip-safemalloc");
  2783. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  2784. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  2785. mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_sock'});
  2786. mtr_add_arg($args, "--port=%d", $master->[0]->{'port'});
  2787. mtr_add_arg($args, "--database=test");
  2788. mtr_add_arg($args, "--user=%s", $opt_user);
  2789. mtr_add_arg($args, "--password=");
  2790. # Run the test file and append output to log file
  2791. mtr_run_test($exe_mysqltest,$args,
  2792. "include/analyze_failure_sync_with_master.test",
  2793. "$path_timefile", "$path_timefile","",
  2794. { append_log_file => 1 });
  2795. }
  2796. sub analyze_testcase_failure($)
  2797. {
  2798. my ($tinfo)= @_;
  2799. # Open mysqltest.log
  2800. my $F= IO::File->new($path_timefile) or
  2801. mtr_error("can't open file \"$path_timefile\": $!");
  2802. while ( my $line= <$F> )
  2803. {
  2804. # Look for "mysqltest: At line nnn: <error>
  2805. if ( $line =~ /mysqltest: At line [0-9]*: (.*)/ )
  2806. {
  2807. my $error= $1;
  2808. # Look for "could not sync with master"
  2809. if ( $error =~ /could not sync with master/ )
  2810. {
  2811. analyze_testcase_failure_sync_with_master($tinfo);
  2812. }
  2813. }
  2814. }
  2815. }
  2816. ##############################################################################
  2817. #
  2818. # Run a single test case
  2819. #
  2820. ##############################################################################
  2821. # When we get here, we have already filtered out test cases that doesn't
  2822. # apply to the current setup, for example if we use a running server, test
  2823. # cases that restart the server are dropped. So this function should mostly
  2824. # be about doing things, not a lot of logic.
  2825. # We don't start and kill the servers for each testcase. But some
  2826. # testcases needs a restart, because they specify options to start
  2827. # mysqld with. After that testcase, we need to restart again, to set
  2828. # back the normal options.
  2829. sub run_testcase ($) {
  2830. my $tinfo= shift;
  2831. # -------------------------------------------------------
  2832. # Init variables that can change between each test case
  2833. # -------------------------------------------------------
  2834. $ENV{'TZ'}= $tinfo->{'timezone'};
  2835. mtr_verbose("Setting timezone: $tinfo->{'timezone'}");
  2836. my $master_restart= run_testcase_need_master_restart($tinfo);
  2837. my $slave_restart= run_testcase_need_slave_restart($tinfo);
  2838. if ($master_restart or $slave_restart)
  2839. {
  2840. # Can't restart a running server that may be in use
  2841. if ( $opt_extern )
  2842. {
  2843. mtr_report_test_name($tinfo);
  2844. $tinfo->{comment}= "Can't restart a running server";
  2845. mtr_report_test_skipped($tinfo);
  2846. return;
  2847. }
  2848. run_testcase_stop_servers($tinfo, $master_restart, $slave_restart);
  2849. }
  2850. # Write to all log files to indicate start of testcase
  2851. run_testcase_mark_logs("CURRENT_TEST: $tinfo->{name}\n");
  2852. my $died= mtr_record_dead_children();
  2853. if ($died or $master_restart or $slave_restart)
  2854. {
  2855. if (run_testcase_start_servers($tinfo))
  2856. {
  2857. mtr_report_test_name($tinfo);
  2858. report_failure_and_restart($tinfo);
  2859. return 1;
  2860. }
  2861. }
  2862. # ----------------------------------------------------------------------
  2863. # If --start-and-exit or --start-dirty given, stop here to let user manually
  2864. # run tests
  2865. # ----------------------------------------------------------------------
  2866. if ( $opt_start_and_exit or $opt_start_dirty )
  2867. {
  2868. mtr_timer_stop_all($glob_timers);
  2869. mtr_report("\nServers started, exiting");
  2870. exit(0);
  2871. }
  2872. {
  2873. do_before_run_mysqltest($tinfo);
  2874. my $res= run_mysqltest($tinfo);
  2875. mtr_report_test_name($tinfo);
  2876. if ( $res == 0 )
  2877. {
  2878. mtr_report_test_passed($tinfo);
  2879. }
  2880. elsif ( $res == 62 )
  2881. {
  2882. # Testcase itself tell us to skip this one
  2883. # Try to get reason from mysqltest.log
  2884. find_testcase_skipped_reason($tinfo);
  2885. mtr_report_test_skipped($tinfo);
  2886. }
  2887. elsif ( $res == 63 )
  2888. {
  2889. $tinfo->{'timeout'}= 1; # Mark as timeout
  2890. report_failure_and_restart($tinfo);
  2891. }
  2892. elsif ( $res == 1 )
  2893. {
  2894. if ( $opt_force )
  2895. {
  2896. analyze_testcase_failure($tinfo);
  2897. }
  2898. # Test case failure reported by mysqltest
  2899. report_failure_and_restart($tinfo);
  2900. }
  2901. else
  2902. {
  2903. # mysqltest failed, probably crashed
  2904. $tinfo->{comment}=
  2905. "mysqltest returned unexpected code $res, it has probably crashed";
  2906. report_failure_and_restart($tinfo);
  2907. }
  2908. do_after_run_mysqltest($tinfo);
  2909. }
  2910. # ----------------------------------------------------------------------
  2911. # Stop Instance Manager if we are processing an IM-test case.
  2912. # ----------------------------------------------------------------------
  2913. if ( $tinfo->{'component_id'} eq 'im' and
  2914. !mtr_im_stop($instance_manager, $tinfo->{'name'}) )
  2915. {
  2916. mtr_error("Failed to stop Instance Manager.")
  2917. }
  2918. }
  2919. #
  2920. # Save a snapshot of the installed test db(s)
  2921. # I.e take a snapshot of the var/ dir
  2922. #
  2923. sub save_installed_db () {
  2924. mtr_report("Saving snapshot of installed databases");
  2925. rmtree($path_snapshot);
  2926. foreach my $data_dir (@data_dir_lst)
  2927. {
  2928. my $name= basename($data_dir);
  2929. mtr_copy_dir("$data_dir", "$path_snapshot/$name");
  2930. }
  2931. }
  2932. #
  2933. # Save any interesting files in the data_dir
  2934. # before the data dir is removed.
  2935. #
  2936. sub save_files_before_restore($$) {
  2937. my $test_name= shift;
  2938. my $data_dir= shift;
  2939. my $save_name= "$opt_vardir/log/$test_name";
  2940. # Look for core files
  2941. foreach my $core_file ( glob("$data_dir/core*") )
  2942. {
  2943. last if $opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core;
  2944. my $core_name= basename($core_file);
  2945. mtr_report("Saving $core_name");
  2946. mkdir($save_name) if ! -d $save_name;
  2947. rename("$core_file", "$save_name/$core_name");
  2948. ++$num_saved_cores;
  2949. }
  2950. }
  2951. #
  2952. # Restore snapshot of the installed test db(s)
  2953. # if the snapshot exists
  2954. #
  2955. sub restore_installed_db ($) {
  2956. my $test_name= shift;
  2957. if ( -d $path_snapshot)
  2958. {
  2959. mtr_report("Restoring snapshot of databases");
  2960. foreach my $data_dir (@data_dir_lst)
  2961. {
  2962. my $name= basename($data_dir);
  2963. save_files_before_restore($test_name, $data_dir);
  2964. rmtree("$data_dir");
  2965. mtr_copy_dir("$path_snapshot/$name", "$data_dir");
  2966. }
  2967. # Remove the ndb_*_fs dirs for all ndbd nodes
  2968. # forcing a clean start of ndb
  2969. foreach my $cluster (@{$clusters})
  2970. {
  2971. foreach my $ndbd (@{$cluster->{'ndbds'}})
  2972. {
  2973. rmtree("$ndbd->{'path_fs'}" );
  2974. }
  2975. }
  2976. }
  2977. else
  2978. {
  2979. # No snapshot existed
  2980. mtr_error("No snapshot existed");
  2981. }
  2982. }
  2983. sub report_failure_and_restart ($) {
  2984. my $tinfo= shift;
  2985. mtr_report_test_failed($tinfo);
  2986. mtr_show_failed_diff($tinfo->{'result_file'});
  2987. print "\n";
  2988. if ( $opt_force )
  2989. {
  2990. # Stop all servers that are known to be running
  2991. stop_all_servers();
  2992. # Restore the snapshot of the installed test db
  2993. restore_installed_db($tinfo->{'name'});
  2994. print "Resuming Tests\n\n";
  2995. return;
  2996. }
  2997. my $test_mode= join(" ", @::glob_test_mode) || "default";
  2998. print "Aborting: $tinfo->{'name'} failed in $test_mode mode. ";
  2999. print "To continue, re-run with '--force'.\n";
  3000. if ( ! $glob_debugger and
  3001. ! $opt_extern and
  3002. ! $glob_use_embedded_server )
  3003. {
  3004. stop_all_servers();
  3005. }
  3006. mtr_exit(1);
  3007. }
  3008. ##############################################################################
  3009. #
  3010. # Start and stop servers
  3011. #
  3012. ##############################################################################
  3013. sub do_before_start_master ($) {
  3014. my ($tinfo)= @_;
  3015. my $tname= $tinfo->{'name'};
  3016. my $init_script= $tinfo->{'master_sh'};
  3017. # FIXME what about second master.....
  3018. foreach my $bin ( glob("$opt_vardir/log/master*-bin*") )
  3019. {
  3020. unlink($bin);
  3021. }
  3022. # FIXME only remove the ones that are tied to this master
  3023. # Remove old master.info and relay-log.info files
  3024. unlink("$master->[0]->{'path_myddir'}/master.info");
  3025. unlink("$master->[0]->{'path_myddir'}/relay-log.info");
  3026. unlink("$master->[1]->{'path_myddir'}/master.info");
  3027. unlink("$master->[1]->{'path_myddir'}/relay-log.info");
  3028. # Run master initialization shell script if one exists
  3029. if ( $init_script )
  3030. {
  3031. my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
  3032. if ( $ret != 0 )
  3033. {
  3034. # FIXME rewrite those scripts to return 0 if successful
  3035. # mtr_warning("$init_script exited with code $ret");
  3036. }
  3037. }
  3038. }
  3039. sub do_before_start_slave ($) {
  3040. my ($tinfo)= @_;
  3041. my $tname= $tinfo->{'name'};
  3042. my $init_script= $tinfo->{'master_sh'};
  3043. foreach my $bin ( glob("$opt_vardir/log/slave*-bin*") )
  3044. {
  3045. unlink($bin);
  3046. }
  3047. unlink("$slave->[0]->{'path_myddir'}/master.info");
  3048. unlink("$slave->[0]->{'path_myddir'}/relay-log.info");
  3049. # Run slave initialization shell script if one exists
  3050. if ( $init_script )
  3051. {
  3052. my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
  3053. if ( $ret != 0 )
  3054. {
  3055. # FIXME rewrite those scripts to return 0 if successful
  3056. # mtr_warning("$init_script exited with code $ret");
  3057. }
  3058. }
  3059. foreach my $bin ( glob("$slave->[0]->{'path_myddir'}/log.*") )
  3060. {
  3061. unlink($bin);
  3062. }
  3063. }
  3064. sub mysqld_arguments ($$$$) {
  3065. my $args= shift;
  3066. my $mysqld= shift;
  3067. my $extra_opt= shift;
  3068. my $slave_master_info= shift;
  3069. my $idx= $mysqld->{'idx'};
  3070. my $sidx= ""; # Index as string, 0 is empty string
  3071. if ( $idx> 0 )
  3072. {
  3073. $sidx= $idx;
  3074. }
  3075. my $prefix= ""; # If mysqltest server arg
  3076. if ( $glob_use_embedded_server )
  3077. {
  3078. $prefix= "--server-arg=";
  3079. }
  3080. mtr_add_arg($args, "%s--no-defaults", $prefix);
  3081. mtr_add_arg($args, "%s--console", $prefix);
  3082. mtr_add_arg($args, "%s--basedir=%s", $prefix, $path_my_basedir);
  3083. mtr_add_arg($args, "%s--character-sets-dir=%s", $prefix, $path_charsetsdir);
  3084. if ( $mysql_version_id >= 50036)
  3085. {
  3086. # By default, prevent the started mysqld to access files outside of vardir
  3087. my $secure_file_dir= $opt_vardir;
  3088. if ( $opt_suite ne "main" )
  3089. {
  3090. # When running a suite other than default allow the mysqld
  3091. # access to subdirs of mysql-test/ in order to make it possible
  3092. # to "load data" from the suites data/ directory.
  3093. $secure_file_dir= $glob_mysql_test_dir;
  3094. }
  3095. mtr_add_arg($args, "%s--secure-file-priv=%s", $prefix, $secure_file_dir);
  3096. }
  3097. if ( $mysql_version_id >= 50000 )
  3098. {
  3099. mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix);
  3100. }
  3101. mtr_add_arg($args, "%s--default-character-set=latin1", $prefix);
  3102. mtr_add_arg($args, "%s--language=%s", $prefix, $path_language);
  3103. mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix);
  3104. if ( $opt_valgrind_mysqld )
  3105. {
  3106. mtr_add_arg($args, "%s--skip-safemalloc", $prefix);
  3107. if ( $mysql_version_id < 50100 )
  3108. {
  3109. mtr_add_arg($args, "%s--skip-bdb", $prefix);
  3110. }
  3111. }
  3112. mtr_add_arg($args, "%s--pid-file=%s", $prefix,
  3113. $mysqld->{'path_pid'});
  3114. mtr_add_arg($args, "%s--port=%d", $prefix,
  3115. $mysqld->{'port'});
  3116. mtr_add_arg($args, "%s--socket=%s", $prefix,
  3117. $mysqld->{'path_sock'});
  3118. mtr_add_arg($args, "%s--datadir=%s", $prefix,
  3119. $mysqld->{'path_myddir'});
  3120. if ( $mysql_version_id >= 50106 )
  3121. {
  3122. # Turn on logging to bothe tables and file
  3123. mtr_add_arg($args, "%s--log-output=table,file", $prefix);
  3124. }
  3125. my $log_base_path= "$opt_vardir/log/$mysqld->{'type'}$sidx";
  3126. mtr_add_arg($args, "%s--log=%s.log", $prefix, $log_base_path);
  3127. mtr_add_arg($args,
  3128. "%s--log-slow-queries=%s-slow.log", $prefix, $log_base_path);
  3129. # Check if "extra_opt" contains --skip-log-bin
  3130. my $skip_binlog= grep(/^--skip-log-bin/, @$extra_opt);
  3131. if ( $mysqld->{'type'} eq 'master' )
  3132. {
  3133. if (! ($opt_skip_master_binlog || $skip_binlog) )
  3134. {
  3135. mtr_add_arg($args, "%s--log-bin=%s/log/master-bin%s", $prefix,
  3136. $opt_vardir, $sidx);
  3137. }
  3138. mtr_add_arg($args, "%s--server-id=%d", $prefix,
  3139. $idx > 0 ? $idx + 101 : 1);
  3140. mtr_add_arg($args, "%s--innodb_data_file_path=ibdata1:10M:autoextend",
  3141. $prefix);
  3142. mtr_add_arg($args, "%s--local-infile", $prefix);
  3143. if ( $idx > 0 or !$use_innodb)
  3144. {
  3145. mtr_add_arg($args, "%s--skip-innodb", $prefix);
  3146. }
  3147. my $cluster= $clusters->[$mysqld->{'cluster'}];
  3148. if ( $opt_skip_ndbcluster ||
  3149. !$cluster->{'pid'})
  3150. {
  3151. mtr_add_arg($args, "%s--skip-ndbcluster", $prefix);
  3152. }
  3153. else
  3154. {
  3155. mtr_add_arg($args, "%s--ndbcluster", $prefix);
  3156. mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
  3157. $cluster->{'connect_string'});
  3158. if ( $mysql_version_id >= 50100 )
  3159. {
  3160. mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
  3161. }
  3162. }
  3163. }
  3164. else
  3165. {
  3166. mtr_error("unknown mysqld type")
  3167. unless $mysqld->{'type'} eq 'slave';
  3168. mtr_add_arg($args, "%s--init-rpl-role=slave", $prefix);
  3169. if (! ( $opt_skip_slave_binlog || $skip_binlog ))
  3170. {
  3171. mtr_add_arg($args, "%s--log-bin=%s/log/slave%s-bin", $prefix,
  3172. $opt_vardir, $sidx); # FIXME use own dir for binlogs
  3173. mtr_add_arg($args, "%s--log-slave-updates", $prefix);
  3174. }
  3175. mtr_add_arg($args, "%s--master-retry-count=10", $prefix);
  3176. mtr_add_arg($args, "%s--relay-log=%s/log/slave%s-relay-bin", $prefix,
  3177. $opt_vardir, $sidx);
  3178. mtr_add_arg($args, "%s--report-host=127.0.0.1", $prefix);
  3179. mtr_add_arg($args, "%s--report-port=%d", $prefix,
  3180. $mysqld->{'port'});
  3181. mtr_add_arg($args, "%s--report-user=root", $prefix);
  3182. mtr_add_arg($args, "%s--skip-innodb", $prefix);
  3183. mtr_add_arg($args, "%s--skip-slave-start", $prefix);
  3184. # Directory where slaves find the dumps generated by "load data"
  3185. # on the server. The path need to have constant length otherwise
  3186. # test results will vary, thus a relative path is used.
  3187. my $slave_load_path= "../tmp";
  3188. mtr_add_arg($args, "%s--slave-load-tmpdir=%s", $prefix,
  3189. $slave_load_path);
  3190. mtr_add_arg($args, "%s--set-variable=slave_net_timeout=10", $prefix);
  3191. if ( @$slave_master_info )
  3192. {
  3193. foreach my $arg ( @$slave_master_info )
  3194. {
  3195. mtr_add_arg($args, "%s%s", $prefix, $arg);
  3196. }
  3197. }
  3198. else
  3199. {
  3200. mtr_add_arg($args, "%s--master-user=root", $prefix);
  3201. mtr_add_arg($args, "%s--master-connect-retry=1", $prefix);
  3202. mtr_add_arg($args, "%s--master-host=127.0.0.1", $prefix);
  3203. mtr_add_arg($args, "%s--master-password=", $prefix);
  3204. mtr_add_arg($args, "%s--master-port=%d", $prefix,
  3205. $master->[0]->{'port'}); # First master
  3206. my $slave_server_id= 2 + $idx;
  3207. my $slave_rpl_rank= $slave_server_id;
  3208. mtr_add_arg($args, "%s--server-id=%d", $prefix, $slave_server_id);
  3209. mtr_add_arg($args, "%s--rpl-recovery-rank=%d", $prefix, $slave_rpl_rank);
  3210. }
  3211. if ( $opt_skip_ndbcluster_slave ||
  3212. $mysqld->{'cluster'} == -1 ||
  3213. !$clusters->[$mysqld->{'cluster'}]->{'pid'} )
  3214. {
  3215. mtr_add_arg($args, "%s--skip-ndbcluster", $prefix);
  3216. }
  3217. else
  3218. {
  3219. mtr_add_arg($args, "%s--ndbcluster", $prefix);
  3220. mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
  3221. $clusters->[$mysqld->{'cluster'}]->{'connect_string'});
  3222. if ( $mysql_version_id >= 50100 )
  3223. {
  3224. mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
  3225. }
  3226. }
  3227. } # end slave
  3228. if ( $opt_debug )
  3229. {
  3230. mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/%s%s.trace",
  3231. $prefix, $path_vardir_trace, $mysqld->{'type'}, $sidx);
  3232. }
  3233. mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix);
  3234. mtr_add_arg($args, "%s--sort_buffer=256K", $prefix);
  3235. mtr_add_arg($args, "%s--max_heap_table_size=1M", $prefix);
  3236. if ( $opt_ssl_supported )
  3237. {
  3238. mtr_add_arg($args, "%s--ssl-ca=%s/std_data/cacert.pem", $prefix,
  3239. $glob_mysql_test_dir);
  3240. mtr_add_arg($args, "%s--ssl-cert=%s/std_data/server-cert.pem", $prefix,
  3241. $glob_mysql_test_dir);
  3242. mtr_add_arg($args, "%s--ssl-key=%s/std_data/server-key.pem", $prefix,
  3243. $glob_mysql_test_dir);
  3244. }
  3245. if ( $opt_warnings )
  3246. {
  3247. mtr_add_arg($args, "%s--log-warnings", $prefix);
  3248. }
  3249. # Indicate to "mysqld" it will be debugged in debugger
  3250. if ( $glob_debugger )
  3251. {
  3252. mtr_add_arg($args, "%s--gdb", $prefix);
  3253. }
  3254. my $found_skip_core= 0;
  3255. foreach my $arg ( @opt_extra_mysqld_opt, @$extra_opt )
  3256. {
  3257. # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
  3258. if ($arg eq "--skip-core-file")
  3259. {
  3260. $found_skip_core= 1;
  3261. }
  3262. elsif ($skip_binlog and mtr_match_prefix($arg, "--binlog-format"))
  3263. {
  3264. ; # Dont add --binlog-format when running without binlog
  3265. }
  3266. else
  3267. {
  3268. mtr_add_arg($args, "%s%s", $prefix, $arg);
  3269. }
  3270. }
  3271. if ( !$found_skip_core )
  3272. {
  3273. mtr_add_arg($args, "%s%s", $prefix, "--core-file");
  3274. }
  3275. if ( $opt_bench )
  3276. {
  3277. mtr_add_arg($args, "%s--rpl-recovery-rank=1", $prefix);
  3278. mtr_add_arg($args, "%s--init-rpl-role=master", $prefix);
  3279. }
  3280. elsif ( $mysqld->{'type'} eq 'master' )
  3281. {
  3282. mtr_add_arg($args, "%s--open-files-limit=1024", $prefix);
  3283. }
  3284. return $args;
  3285. }
  3286. ##############################################################################
  3287. #
  3288. # Start mysqld and return the PID
  3289. #
  3290. ##############################################################################
  3291. sub mysqld_start ($$$) {
  3292. my $mysqld= shift;
  3293. my $extra_opt= shift;
  3294. my $slave_master_info= shift;
  3295. my $args; # Arg vector
  3296. my $exe;
  3297. my $pid= -1;
  3298. my $wait_for_pid_file= 1;
  3299. my $type= $mysqld->{'type'};
  3300. my $idx= $mysqld->{'idx'};
  3301. mtr_error("Internal error: mysqld should never be started for embedded")
  3302. if $glob_use_embedded_server;
  3303. if ( $type eq 'master' )
  3304. {
  3305. $exe= $exe_master_mysqld;
  3306. }
  3307. elsif ( $type eq 'slave' )
  3308. {
  3309. $exe= $exe_slave_mysqld;
  3310. }
  3311. else
  3312. {
  3313. mtr_error("Unknown 'type' \"$type\" passed to mysqld_start");
  3314. }
  3315. mtr_init_args(\$args);
  3316. if ( $opt_valgrind_mysqld )
  3317. {
  3318. valgrind_arguments($args, \$exe);
  3319. }
  3320. mysqld_arguments($args,$mysqld,$extra_opt,$slave_master_info);
  3321. if ( $opt_gdb || $opt_manual_gdb)
  3322. {
  3323. gdb_arguments(\$args, \$exe, "$type"."_$idx");
  3324. }
  3325. elsif ( $opt_ddd || $opt_manual_ddd )
  3326. {
  3327. ddd_arguments(\$args, \$exe, "$type"."_$idx");
  3328. }
  3329. elsif ( $opt_debugger )
  3330. {
  3331. debugger_arguments(\$args, \$exe, "$type"."_$idx");
  3332. }
  3333. elsif ( $opt_manual_debug )
  3334. {
  3335. print "\nStart $type in your debugger\n" .
  3336. "dir: $glob_mysql_test_dir\n" .
  3337. "exe: $exe\n" .
  3338. "args: " . join(" ", @$args) . "\n\n" .
  3339. "Waiting ....\n";
  3340. # Indicate the exe should not be started
  3341. $exe= undef;
  3342. }
  3343. else
  3344. {
  3345. # Default to not wait until pid file has been created
  3346. $wait_for_pid_file= 0;
  3347. }
  3348. if ( defined $exe )
  3349. {
  3350. $pid= mtr_spawn($exe, $args, "",
  3351. $mysqld->{'path_myerr'},
  3352. $mysqld->{'path_myerr'},
  3353. "",
  3354. { append_log_file => 1 });
  3355. }
  3356. if ( $wait_for_pid_file && !sleep_until_file_created($mysqld->{'path_pid'},
  3357. $mysqld->{'start_timeout'},
  3358. $pid))
  3359. {
  3360. mtr_error("Failed to start mysqld $mysqld->{'type'}");
  3361. }
  3362. # Remember pid of the started process
  3363. $mysqld->{'pid'}= $pid;
  3364. # Remember options used when starting
  3365. $mysqld->{'start_opts'}= $extra_opt;
  3366. $mysqld->{'start_slave_master_info'}= $slave_master_info;
  3367. mtr_verbose("mysqld pid: $pid");
  3368. return $pid;
  3369. }
  3370. sub stop_all_servers () {
  3371. print "Stopping All Servers\n";
  3372. if ( ! $opt_skip_im )
  3373. {
  3374. print "Shutting-down Instance Manager\n";
  3375. unless (mtr_im_stop($instance_manager, "stop_all_servers"))
  3376. {
  3377. mtr_error("Failed to stop Instance Manager.")
  3378. }
  3379. }
  3380. my %admin_pids; # hash of admin processes that requests shutdown
  3381. my @kill_pids; # list of processes to shutdown/kill
  3382. my $pid;
  3383. # Start shutdown of all started masters
  3384. foreach my $mysqld (@{$master}, @{$slave})
  3385. {
  3386. if ( $mysqld->{'pid'} )
  3387. {
  3388. $pid= mtr_mysqladmin_start($mysqld, "shutdown", 70);
  3389. $admin_pids{$pid}= 1;
  3390. push(@kill_pids,{
  3391. pid => $mysqld->{'pid'},
  3392. pidfile => $mysqld->{'path_pid'},
  3393. sockfile => $mysqld->{'path_sock'},
  3394. port => $mysqld->{'port'},
  3395. });
  3396. $mysqld->{'pid'}= 0; # Assume we are done with it
  3397. }
  3398. }
  3399. # Start shutdown of clusters
  3400. foreach my $cluster (@{$clusters})
  3401. {
  3402. if ( $cluster->{'pid'} )
  3403. {
  3404. $pid= mtr_ndbmgm_start($cluster, "shutdown");
  3405. $admin_pids{$pid}= 1;
  3406. push(@kill_pids,{
  3407. pid => $cluster->{'pid'},
  3408. pidfile => $cluster->{'path_pid'}
  3409. });
  3410. $cluster->{'pid'}= 0; # Assume we are done with it
  3411. foreach my $ndbd (@{$cluster->{'ndbds'}})
  3412. {
  3413. if ( $ndbd->{'pid'} )
  3414. {
  3415. push(@kill_pids,{
  3416. pid => $ndbd->{'pid'},
  3417. pidfile => $ndbd->{'path_pid'},
  3418. });
  3419. $ndbd->{'pid'}= 0;
  3420. }
  3421. }
  3422. }
  3423. }
  3424. # Wait blocking until all shutdown processes has completed
  3425. mtr_wait_blocking(\%admin_pids);
  3426. # Make sure that process has shutdown else try to kill them
  3427. mtr_check_stop_servers(\@kill_pids);
  3428. foreach my $mysqld (@{$master}, @{$slave})
  3429. {
  3430. rm_ndbcluster_tables($mysqld->{'path_myddir'});
  3431. }
  3432. }
  3433. sub run_testcase_need_master_restart($)
  3434. {
  3435. my ($tinfo)= @_;
  3436. # We try to find out if we are to restart the master(s)
  3437. my $do_restart= 0; # Assumes we don't have to
  3438. if ( $glob_use_embedded_server )
  3439. {
  3440. mtr_verbose("Never start or restart for embedded server");
  3441. return $do_restart;
  3442. }
  3443. elsif ( $tinfo->{'master_sh'} )
  3444. {
  3445. $do_restart= 1; # Always restart if script to run
  3446. mtr_verbose("Restart master: Always restart if script to run");
  3447. }
  3448. if ( $tinfo->{'force_restart'} )
  3449. {
  3450. $do_restart= 1; # Always restart if --force-restart in -opt file
  3451. mtr_verbose("Restart master: Restart forced with --force-restart");
  3452. }
  3453. elsif ( ! $opt_skip_ndbcluster and
  3454. !$tinfo->{'ndb_test'} and
  3455. $clusters->[0]->{'pid'} != 0 )
  3456. {
  3457. $do_restart= 1; # Restart without cluster
  3458. mtr_verbose("Restart master: Test does not need cluster");
  3459. }
  3460. elsif ( ! $opt_skip_ndbcluster and
  3461. $tinfo->{'ndb_test'} and
  3462. $clusters->[0]->{'pid'} == 0 )
  3463. {
  3464. $do_restart= 1; # Restart with cluster
  3465. mtr_verbose("Restart master: Test need cluster");
  3466. }
  3467. elsif( $tinfo->{'component_id'} eq 'im' )
  3468. {
  3469. $do_restart= 1;
  3470. mtr_verbose("Restart master: Always restart for im tests");
  3471. }
  3472. elsif ( $master->[0]->{'running_master_options'} and
  3473. $master->[0]->{'running_master_options'}->{'timezone'} ne
  3474. $tinfo->{'timezone'})
  3475. {
  3476. $do_restart= 1;
  3477. mtr_verbose("Restart master: Different timezone");
  3478. }
  3479. # Check that running master was started with same options
  3480. # as the current test requires
  3481. elsif (! mtr_same_opts($master->[0]->{'start_opts'},
  3482. $tinfo->{'master_opt'}) )
  3483. {
  3484. $do_restart= 1;
  3485. mtr_verbose("Restart master: running with different options '" .
  3486. join(" ", @{$tinfo->{'master_opt'}}) . "' != '" .
  3487. join(" ", @{$master->[0]->{'start_opts'}}) . "'" );
  3488. }
  3489. elsif( ! $master->[0]->{'pid'} )
  3490. {
  3491. if ( $opt_extern )
  3492. {
  3493. $do_restart= 0;
  3494. mtr_verbose("No restart: using extern master");
  3495. }
  3496. else
  3497. {
  3498. $do_restart= 1;
  3499. mtr_verbose("Restart master: master is not started");
  3500. }
  3501. }
  3502. return $do_restart;
  3503. }
  3504. sub run_testcase_need_slave_restart($)
  3505. {
  3506. my ($tinfo)= @_;
  3507. # We try to find out if we are to restart the slaves
  3508. my $do_slave_restart= 0; # Assumes we don't have to
  3509. if ( $glob_use_embedded_server )
  3510. {
  3511. mtr_verbose("Never start or restart for embedded server");
  3512. return $do_slave_restart;
  3513. }
  3514. elsif ( $max_slave_num == 0)
  3515. {
  3516. mtr_verbose("Skip slave restart: No testcase use slaves");
  3517. }
  3518. else
  3519. {
  3520. # Check if any slave is currently started
  3521. my $any_slave_started= 0;
  3522. foreach my $mysqld (@{$slave})
  3523. {
  3524. if ( $mysqld->{'pid'} )
  3525. {
  3526. $any_slave_started= 1;
  3527. last;
  3528. }
  3529. }
  3530. if ($any_slave_started)
  3531. {
  3532. mtr_verbose("Restart slave: Slave is started, always restart");
  3533. $do_slave_restart= 1;
  3534. }
  3535. elsif ( $tinfo->{'slave_num'} )
  3536. {
  3537. mtr_verbose("Restart slave: Test need slave");
  3538. $do_slave_restart= 1;
  3539. }
  3540. }
  3541. return $do_slave_restart;
  3542. }
  3543. # ----------------------------------------------------------------------
  3544. # If not using a running servers we may need to stop and restart.
  3545. # We restart in the case we have initiation scripts, server options
  3546. # etc to run. But we also restart again after the test first restart
  3547. # and test is run, to get back to normal server settings.
  3548. #
  3549. # To make the code a bit more clean, we actually only stop servers
  3550. # here, and mark this to be done. Then a generic "start" part will
  3551. # start up the needed servers again.
  3552. # ----------------------------------------------------------------------
  3553. sub run_testcase_stop_servers($$$) {
  3554. my ($tinfo, $do_restart, $do_slave_restart)= @_;
  3555. my $pid;
  3556. my %admin_pids; # hash of admin processes that requests shutdown
  3557. my @kill_pids; # list of processes to shutdown/kill
  3558. # Remember if we restarted for this test case (count restarts)
  3559. $tinfo->{'restarted'}= $do_restart;
  3560. if ( $do_restart )
  3561. {
  3562. delete $master->[0]->{'running_master_options'}; # Forget history
  3563. # Start shutdown of all started masters
  3564. foreach my $mysqld (@{$master})
  3565. {
  3566. if ( $mysqld->{'pid'} )
  3567. {
  3568. $pid= mtr_mysqladmin_start($mysqld, "shutdown", 70);
  3569. $admin_pids{$pid}= 1;
  3570. push(@kill_pids,{
  3571. pid => $mysqld->{'pid'},
  3572. pidfile => $mysqld->{'path_pid'},
  3573. sockfile => $mysqld->{'path_sock'},
  3574. port => $mysqld->{'port'},
  3575. });
  3576. $mysqld->{'pid'}= 0; # Assume we are done with it
  3577. }
  3578. }
  3579. # Start shutdown of master cluster
  3580. my $cluster= $clusters->[0];
  3581. if ( $cluster->{'pid'} )
  3582. {
  3583. $pid= mtr_ndbmgm_start($cluster, "shutdown");
  3584. $admin_pids{$pid}= 1;
  3585. push(@kill_pids,{
  3586. pid => $cluster->{'pid'},
  3587. pidfile => $cluster->{'path_pid'}
  3588. });
  3589. $cluster->{'pid'}= 0; # Assume we are done with it
  3590. foreach my $ndbd (@{$cluster->{'ndbds'}})
  3591. {
  3592. push(@kill_pids,{
  3593. pid => $ndbd->{'pid'},
  3594. pidfile => $ndbd->{'path_pid'},
  3595. });
  3596. $ndbd->{'pid'}= 0; # Assume we are done with it
  3597. }
  3598. }
  3599. }
  3600. if ( $do_restart || $do_slave_restart )
  3601. {
  3602. delete $slave->[0]->{'running_slave_options'}; # Forget history
  3603. # Start shutdown of all started slaves
  3604. foreach my $mysqld (@{$slave})
  3605. {
  3606. if ( $mysqld->{'pid'} )
  3607. {
  3608. $pid= mtr_mysqladmin_start($mysqld, "shutdown", 70);
  3609. $admin_pids{$pid}= 1;
  3610. push(@kill_pids,{
  3611. pid => $mysqld->{'pid'},
  3612. pidfile => $mysqld->{'path_pid'},
  3613. sockfile => $mysqld->{'path_sock'},
  3614. port => $mysqld->{'port'},
  3615. });
  3616. $mysqld->{'pid'}= 0; # Assume we are done with it
  3617. }
  3618. }
  3619. # Start shutdown of slave cluster
  3620. my $cluster= $clusters->[1];
  3621. if ( $cluster->{'pid'} )
  3622. {
  3623. $pid= mtr_ndbmgm_start($cluster, "shutdown");
  3624. $admin_pids{$pid}= 1;
  3625. push(@kill_pids,{
  3626. pid => $cluster->{'pid'},
  3627. pidfile => $cluster->{'path_pid'}
  3628. });
  3629. $cluster->{'pid'}= 0; # Assume we are done with it
  3630. foreach my $ndbd (@{$cluster->{'ndbds'}} )
  3631. {
  3632. push(@kill_pids,{
  3633. pid => $ndbd->{'pid'},
  3634. pidfile => $ndbd->{'path_pid'},
  3635. });
  3636. $ndbd->{'pid'}= 0; # Assume we are done with it
  3637. }
  3638. }
  3639. }
  3640. # ----------------------------------------------------------------------
  3641. # Shutdown has now been started and lists for the shutdown processes
  3642. # and the processes to be killed has been created
  3643. # ----------------------------------------------------------------------
  3644. # Wait blocking until all shutdown processes has completed
  3645. mtr_wait_blocking(\%admin_pids);
  3646. # Make sure that process has shutdown else try to kill them
  3647. mtr_check_stop_servers(\@kill_pids);
  3648. foreach my $mysqld (@{$master}, @{$slave})
  3649. {
  3650. if ( ! $mysqld->{'pid'} )
  3651. {
  3652. # Remove ndbcluster tables if server is stopped
  3653. rm_ndbcluster_tables($mysqld->{'path_myddir'});
  3654. }
  3655. }
  3656. }
  3657. #
  3658. # run_testcase_start_servers
  3659. #
  3660. # Start the servers needed by this test case
  3661. #
  3662. # RETURN
  3663. # 0 OK
  3664. # 1 Start failed
  3665. #
  3666. sub run_testcase_start_servers($) {
  3667. my $tinfo= shift;
  3668. my $tname= $tinfo->{'name'};
  3669. if ( $tinfo->{'component_id'} eq 'mysqld' )
  3670. {
  3671. if ( ! $opt_skip_ndbcluster and
  3672. !$clusters->[0]->{'pid'} and
  3673. $tinfo->{'ndb_test'} )
  3674. {
  3675. # Test need cluster, cluster is not started, start it
  3676. ndbcluster_start($clusters->[0], "");
  3677. }
  3678. if ( !$master->[0]->{'pid'} )
  3679. {
  3680. # Master mysqld is not started
  3681. do_before_start_master($tinfo);
  3682. mysqld_start($master->[0],$tinfo->{'master_opt'},[]);
  3683. }
  3684. if ( $clusters->[0]->{'pid'} and ! $master->[1]->{'pid'} and
  3685. $tinfo->{'master_num'} > 1 )
  3686. {
  3687. # Test needs cluster, start an extra mysqld connected to cluster
  3688. if ( $mysql_version_id >= 50100 )
  3689. {
  3690. # First wait for first mysql server to have created ndb system
  3691. # tables ok FIXME This is a workaround so that only one mysqld
  3692. # create the tables
  3693. if ( ! sleep_until_file_created(
  3694. "$master->[0]->{'path_myddir'}/mysql/apply_status.ndb",
  3695. $master->[0]->{'start_timeout'},
  3696. $master->[0]->{'pid'}))
  3697. {
  3698. $tinfo->{'comment'}= "Failed to create 'mysql/apply_status' table";
  3699. return 1;
  3700. }
  3701. }
  3702. mysqld_start($master->[1],$tinfo->{'master_opt'},[]);
  3703. }
  3704. # Save this test case information, so next can examine it
  3705. $master->[0]->{'running_master_options'}= $tinfo;
  3706. }
  3707. elsif ( ! $opt_skip_im and $tinfo->{'component_id'} eq 'im' )
  3708. {
  3709. # We have to create defaults file every time, in order to ensure that it
  3710. # will be the same for each test. The problem is that test can change the
  3711. # file (by SET/UNSET commands), so w/o recreating the file, execution of
  3712. # one test can affect the other.
  3713. im_create_defaults_file($instance_manager);
  3714. if ( ! mtr_im_start($instance_manager, $tinfo->{im_opts}) )
  3715. {
  3716. $tinfo->{'comment'}= "Failed to start Instance Manager. ";
  3717. return 1;
  3718. }
  3719. }
  3720. # ----------------------------------------------------------------------
  3721. # Start slaves - if needed
  3722. # ----------------------------------------------------------------------
  3723. if ( $tinfo->{'slave_num'} )
  3724. {
  3725. restore_slave_databases($tinfo->{'slave_num'});
  3726. do_before_start_slave($tinfo);
  3727. if ( ! $opt_skip_ndbcluster_slave and
  3728. !$clusters->[1]->{'pid'} and
  3729. $tinfo->{'ndb_test'} )
  3730. {
  3731. # Test need slave cluster, cluster is not started, start it
  3732. ndbcluster_start($clusters->[1], "");
  3733. }
  3734. for ( my $idx= 0; $idx < $tinfo->{'slave_num'}; $idx++ )
  3735. {
  3736. if ( ! $slave->[$idx]->{'pid'} )
  3737. {
  3738. mysqld_start($slave->[$idx],$tinfo->{'slave_opt'},
  3739. $tinfo->{'slave_mi'});
  3740. }
  3741. }
  3742. # Save this test case information, so next can examine it
  3743. $slave->[0]->{'running_slave_options'}= $tinfo;
  3744. }
  3745. # Wait for clusters to start
  3746. foreach my $cluster (@{$clusters})
  3747. {
  3748. next if !$cluster->{'pid'};
  3749. if (ndbcluster_wait_started($cluster, ""))
  3750. {
  3751. # failed to start
  3752. $tinfo->{'comment'}= "Start of $cluster->{'name'} cluster failed";
  3753. return 1;
  3754. }
  3755. }
  3756. # Wait for mysqld's to start
  3757. foreach my $mysqld (@{$master},@{$slave})
  3758. {
  3759. next if !$mysqld->{'pid'};
  3760. if (mysqld_wait_started($mysqld))
  3761. {
  3762. # failed to start
  3763. $tinfo->{'comment'}=
  3764. "Failed to start $mysqld->{'type'} mysqld $mysqld->{'idx'}";
  3765. return 1;
  3766. }
  3767. }
  3768. return 0;
  3769. }
  3770. #
  3771. # Run include/check-testcase.test
  3772. # Before a testcase, run in record mode, save result file to var
  3773. # After testcase, run and compare with the recorded file, they should be equal!
  3774. #
  3775. # RETURN VALUE
  3776. # 0 OK
  3777. # 1 Check failed
  3778. #
  3779. sub run_check_testcase ($$) {
  3780. my $mode= shift;
  3781. my $mysqld= shift;
  3782. my $name= "check-" . $mysqld->{'type'} . $mysqld->{'idx'};
  3783. my $args;
  3784. mtr_init_args(\$args);
  3785. mtr_add_arg($args, "--no-defaults");
  3786. mtr_add_arg($args, "--silent");
  3787. mtr_add_arg($args, "--skip-safemalloc");
  3788. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  3789. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  3790. mtr_add_arg($args, "--socket=%s", $mysqld->{'path_sock'});
  3791. mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
  3792. mtr_add_arg($args, "--database=test");
  3793. mtr_add_arg($args, "--user=%s", $opt_user);
  3794. mtr_add_arg($args, "--password=");
  3795. mtr_add_arg($args, "-R");
  3796. mtr_add_arg($args, "$opt_vardir/tmp/$name.result");
  3797. if ( $mode eq "before" )
  3798. {
  3799. mtr_add_arg($args, "--record");
  3800. }
  3801. my $res = mtr_run_test($exe_mysqltest,$args,
  3802. "include/check-testcase.test", "", "", "");
  3803. if ( $res == 1 and $mode eq "after")
  3804. {
  3805. mtr_run("diff",["-u",
  3806. "$opt_vardir/tmp/$name.result",
  3807. "$opt_vardir/tmp/$name.reject"],
  3808. "", "", "", "");
  3809. }
  3810. elsif ( $res )
  3811. {
  3812. mtr_error("Could not execute 'check-testcase' $mode testcase");
  3813. }
  3814. return $res;
  3815. }
  3816. ##############################################################################
  3817. #
  3818. # Report the features that were compiled in
  3819. #
  3820. ##############################################################################
  3821. sub run_report_features () {
  3822. my $args;
  3823. if ( ! $glob_use_embedded_server )
  3824. {
  3825. mysqld_start($master->[0],[],[]);
  3826. if ( ! $master->[0]->{'pid'} )
  3827. {
  3828. mtr_error("Can't start the mysqld server");
  3829. }
  3830. mysqld_wait_started($master->[0]);
  3831. }
  3832. my $tinfo = {};
  3833. $tinfo->{'name'} = 'report features';
  3834. $tinfo->{'result_file'} = undef;
  3835. $tinfo->{'component_id'} = 'mysqld';
  3836. $tinfo->{'path'} = 'include/report-features.test';
  3837. $tinfo->{'timezone'}= "GMT-3";
  3838. $tinfo->{'slave_num'} = 0;
  3839. $tinfo->{'master_opt'} = [];
  3840. $tinfo->{'slave_opt'} = [];
  3841. $tinfo->{'slave_mi'} = [];
  3842. $tinfo->{'comment'} = 'report server features';
  3843. run_mysqltest($tinfo);
  3844. if ( ! $glob_use_embedded_server )
  3845. {
  3846. stop_all_servers();
  3847. }
  3848. }
  3849. sub run_mysqltest ($) {
  3850. my ($tinfo)= @_;
  3851. my $exe= $exe_mysqltest;
  3852. my $args;
  3853. mtr_init_args(\$args);
  3854. mtr_add_arg($args, "--no-defaults");
  3855. mtr_add_arg($args, "--silent");
  3856. mtr_add_arg($args, "--skip-safemalloc");
  3857. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  3858. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  3859. # Log line number and time for each line in .test file
  3860. mtr_add_arg($args, "--mark-progress")
  3861. if $opt_mark_progress;
  3862. if ($tinfo->{'component_id'} eq 'im')
  3863. {
  3864. mtr_add_arg($args, "--socket=%s", $instance_manager->{'path_sock'});
  3865. mtr_add_arg($args, "--port=%d", $instance_manager->{'port'});
  3866. mtr_add_arg($args, "--user=%s", $instance_manager->{'admin_login'});
  3867. mtr_add_arg($args, "--password=%s", $instance_manager->{'admin_password'});
  3868. }
  3869. else # component_id == mysqld
  3870. {
  3871. mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_sock'});
  3872. mtr_add_arg($args, "--port=%d", $master->[0]->{'port'});
  3873. mtr_add_arg($args, "--database=test");
  3874. mtr_add_arg($args, "--user=%s", $opt_user);
  3875. mtr_add_arg($args, "--password=");
  3876. }
  3877. if ( $opt_ps_protocol )
  3878. {
  3879. mtr_add_arg($args, "--ps-protocol");
  3880. }
  3881. if ( $opt_sp_protocol )
  3882. {
  3883. mtr_add_arg($args, "--sp-protocol");
  3884. }
  3885. if ( $opt_view_protocol )
  3886. {
  3887. mtr_add_arg($args, "--view-protocol");
  3888. }
  3889. if ( $opt_cursor_protocol )
  3890. {
  3891. mtr_add_arg($args, "--cursor-protocol");
  3892. }
  3893. if ( $opt_strace_client )
  3894. {
  3895. $exe= "strace"; # FIXME there are ktrace, ....
  3896. mtr_add_arg($args, "-o");
  3897. mtr_add_arg($args, "%s/log/mysqltest.strace", $opt_vardir);
  3898. mtr_add_arg($args, "$exe_mysqltest");
  3899. }
  3900. if ( $opt_timer )
  3901. {
  3902. mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
  3903. }
  3904. if ( $opt_compress )
  3905. {
  3906. mtr_add_arg($args, "--compress");
  3907. }
  3908. if ( $opt_sleep )
  3909. {
  3910. mtr_add_arg($args, "--sleep=%d", $opt_sleep);
  3911. }
  3912. if ( $opt_debug )
  3913. {
  3914. mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace",
  3915. $path_vardir_trace);
  3916. }
  3917. if ( $opt_ssl_supported )
  3918. {
  3919. mtr_add_arg($args, "--ssl-ca=%s/std_data/cacert.pem",
  3920. $glob_mysql_test_dir);
  3921. mtr_add_arg($args, "--ssl-cert=%s/std_data/client-cert.pem",
  3922. $glob_mysql_test_dir);
  3923. mtr_add_arg($args, "--ssl-key=%s/std_data/client-key.pem",
  3924. $glob_mysql_test_dir);
  3925. }
  3926. if ( $opt_ssl )
  3927. {
  3928. # Turn on SSL for _all_ test cases if option --ssl was used
  3929. mtr_add_arg($args, "--ssl");
  3930. }
  3931. elsif ( $opt_ssl_supported )
  3932. {
  3933. mtr_add_arg($args, "--skip-ssl");
  3934. }
  3935. # ----------------------------------------------------------------------
  3936. # If embedded server, we create server args to give mysqltest to pass on
  3937. # ----------------------------------------------------------------------
  3938. if ( $glob_use_embedded_server )
  3939. {
  3940. mysqld_arguments($args,$master->[0],$tinfo->{'master_opt'},[]);
  3941. }
  3942. # ----------------------------------------------------------------------
  3943. # export MYSQL_TEST variable containing <path>/mysqltest <args>
  3944. # ----------------------------------------------------------------------
  3945. $ENV{'MYSQL_TEST'}=
  3946. mtr_native_path($exe_mysqltest) . " " . join(" ", @$args);
  3947. # ----------------------------------------------------------------------
  3948. # Add arguments that should not go into the MYSQL_TEST env var
  3949. # ----------------------------------------------------------------------
  3950. if ( $opt_valgrind_mysqltest )
  3951. {
  3952. # Prefix the Valgrind options to the argument list.
  3953. # We do this here, since we do not want to Valgrind the nested invocations
  3954. # of mysqltest; that would mess up the stderr output causing test failure.
  3955. my @args_saved = @$args;
  3956. mtr_init_args(\$args);
  3957. valgrind_arguments($args, \$exe);
  3958. mtr_add_arg($args, "%s", $_) for @args_saved;
  3959. }
  3960. mtr_add_arg($args, "--test-file");
  3961. mtr_add_arg($args, $tinfo->{'path'});
  3962. if ( defined $tinfo->{'result_file'} ) {
  3963. mtr_add_arg($args, "--result-file");
  3964. mtr_add_arg($args, $tinfo->{'result_file'});
  3965. }
  3966. if ( $opt_record )
  3967. {
  3968. mtr_add_arg($args, "--record");
  3969. }
  3970. if ( $opt_client_gdb )
  3971. {
  3972. gdb_arguments(\$args, \$exe, "client");
  3973. }
  3974. elsif ( $opt_client_ddd )
  3975. {
  3976. ddd_arguments(\$args, \$exe, "client");
  3977. }
  3978. elsif ( $opt_client_debugger )
  3979. {
  3980. debugger_arguments(\$args, \$exe, "client");
  3981. }
  3982. if ( $opt_check_testcases )
  3983. {
  3984. foreach my $mysqld (@{$master}, @{$slave})
  3985. {
  3986. if ($mysqld->{'pid'})
  3987. {
  3988. run_check_testcase("before", $mysqld);
  3989. }
  3990. }
  3991. }
  3992. my $res = mtr_run_test($exe,$args,"","",$path_timefile,"");
  3993. if ( $opt_check_testcases )
  3994. {
  3995. foreach my $mysqld (@{$master}, @{$slave})
  3996. {
  3997. if ($mysqld->{'pid'})
  3998. {
  3999. if (run_check_testcase("after", $mysqld))
  4000. {
  4001. # Check failed, mark the test case with that info
  4002. $tinfo->{'check_testcase_failed'}= 1;
  4003. }
  4004. }
  4005. }
  4006. }
  4007. return $res;
  4008. }
  4009. #
  4010. # Modify the exe and args so that program is run in gdb in xterm
  4011. #
  4012. sub gdb_arguments {
  4013. my $args= shift;
  4014. my $exe= shift;
  4015. my $type= shift;
  4016. # Write $args to gdb init file
  4017. my $str= join(" ", @$$args);
  4018. my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
  4019. # Remove the old gdbinit file
  4020. unlink($gdb_init_file);
  4021. if ( $type eq "client" )
  4022. {
  4023. # write init file for client
  4024. mtr_tofile($gdb_init_file,
  4025. "set args $str\n" .
  4026. "break main\n");
  4027. }
  4028. else
  4029. {
  4030. # write init file for mysqld
  4031. mtr_tofile($gdb_init_file,
  4032. "set args $str\n" .
  4033. "break mysql_parse\n" .
  4034. "commands 1\n" .
  4035. "disable 1\n" .
  4036. "end\n" .
  4037. "run");
  4038. }
  4039. if ( $opt_manual_gdb )
  4040. {
  4041. print "\nTo start gdb for $type, type in another window:\n";
  4042. print "gdb -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  4043. # Indicate the exe should not be started
  4044. $$exe= undef;
  4045. return;
  4046. }
  4047. $$args= [];
  4048. mtr_add_arg($$args, "-title");
  4049. mtr_add_arg($$args, "$type");
  4050. mtr_add_arg($$args, "-e");
  4051. if ( $exe_libtool )
  4052. {
  4053. mtr_add_arg($$args, $exe_libtool);
  4054. mtr_add_arg($$args, "--mode=execute");
  4055. }
  4056. mtr_add_arg($$args, "gdb");
  4057. mtr_add_arg($$args, "-x");
  4058. mtr_add_arg($$args, "$gdb_init_file");
  4059. mtr_add_arg($$args, "$$exe");
  4060. $$exe= "xterm";
  4061. }
  4062. #
  4063. # Modify the exe and args so that program is run in ddd
  4064. #
  4065. sub ddd_arguments {
  4066. my $args= shift;
  4067. my $exe= shift;
  4068. my $type= shift;
  4069. # Write $args to ddd init file
  4070. my $str= join(" ", @$$args);
  4071. my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
  4072. # Remove the old gdbinit file
  4073. unlink($gdb_init_file);
  4074. if ( $type eq "client" )
  4075. {
  4076. # write init file for client
  4077. mtr_tofile($gdb_init_file,
  4078. "set args $str\n" .
  4079. "break main\n");
  4080. }
  4081. else
  4082. {
  4083. # write init file for mysqld
  4084. mtr_tofile($gdb_init_file,
  4085. "file $$exe\n" .
  4086. "set args $str\n" .
  4087. "break mysql_parse\n" .
  4088. "commands 1\n" .
  4089. "disable 1\n" .
  4090. "end");
  4091. }
  4092. if ( $opt_manual_ddd )
  4093. {
  4094. print "\nTo start ddd for $type, type in another window:\n";
  4095. print "ddd -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  4096. # Indicate the exe should not be started
  4097. $$exe= undef;
  4098. return;
  4099. }
  4100. my $save_exe= $$exe;
  4101. $$args= [];
  4102. if ( $exe_libtool )
  4103. {
  4104. $$exe= $exe_libtool;
  4105. mtr_add_arg($$args, "--mode=execute");
  4106. mtr_add_arg($$args, "ddd");
  4107. }
  4108. else
  4109. {
  4110. $$exe= "ddd";
  4111. }
  4112. mtr_add_arg($$args, "--command=$gdb_init_file");
  4113. mtr_add_arg($$args, "$save_exe");
  4114. }
  4115. #
  4116. # Modify the exe and args so that program is run in the selected debugger
  4117. #
  4118. sub debugger_arguments {
  4119. my $args= shift;
  4120. my $exe= shift;
  4121. my $debugger= $opt_debugger || $opt_client_debugger;
  4122. if ( $debugger =~ /vcexpress|vc|devenv/ )
  4123. {
  4124. # vc[express] /debugexe exe arg1 .. argn
  4125. # Add /debugexe and name of the exe before args
  4126. unshift(@$$args, "/debugexe");
  4127. unshift(@$$args, "$$exe");
  4128. # Set exe to debuggername
  4129. $$exe= $debugger;
  4130. }
  4131. elsif ( $debugger =~ /windbg/ )
  4132. {
  4133. # windbg exe arg1 .. argn
  4134. # Add name of the exe before args
  4135. unshift(@$$args, "$$exe");
  4136. # Set exe to debuggername
  4137. $$exe= $debugger;
  4138. }
  4139. elsif ( $debugger eq "dbx" )
  4140. {
  4141. # xterm -e dbx -r exe arg1 .. argn
  4142. unshift(@$$args, $$exe);
  4143. unshift(@$$args, "-r");
  4144. unshift(@$$args, $debugger);
  4145. unshift(@$$args, "-e");
  4146. $$exe= "xterm";
  4147. }
  4148. else
  4149. {
  4150. mtr_error("Unknown argument \"$debugger\" passed to --debugger");
  4151. }
  4152. }
  4153. #
  4154. # Modify the exe and args so that program is run in valgrind
  4155. #
  4156. sub valgrind_arguments {
  4157. my $args= shift;
  4158. my $exe= shift;
  4159. if ( $opt_callgrind)
  4160. {
  4161. mtr_add_arg($args, "--tool=callgrind");
  4162. mtr_add_arg($args, "--base=$opt_vardir/log");
  4163. }
  4164. else
  4165. {
  4166. mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
  4167. mtr_add_arg($args, "--alignment=8");
  4168. mtr_add_arg($args, "--leak-check=yes");
  4169. mtr_add_arg($args, "--num-callers=16");
  4170. mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
  4171. if -f "$glob_mysql_test_dir/valgrind.supp";
  4172. }
  4173. # Add valgrind options, can be overriden by user
  4174. mtr_add_arg($args, '%s', $_) for (split(' ', $opt_valgrind_options));
  4175. mtr_add_arg($args, $$exe);
  4176. $$exe= $opt_valgrind_path || "valgrind";
  4177. if ($exe_libtool)
  4178. {
  4179. # Add "libtool --mode-execute" before the test to execute
  4180. # if running in valgrind(to avoid valgrinding bash)
  4181. unshift(@$args, "--mode=execute", $$exe);
  4182. $$exe= $exe_libtool;
  4183. }
  4184. }
  4185. ##############################################################################
  4186. #
  4187. # Usage
  4188. #
  4189. ##############################################################################
  4190. sub usage ($) {
  4191. my $message= shift;
  4192. if ( $message )
  4193. {
  4194. print STDERR "$message\n";
  4195. }
  4196. print <<HERE;
  4197. $0 [ OPTIONS ] [ TESTCASE ]
  4198. Options to control what engine/variation to run
  4199. embedded-server Use the embedded server, i.e. no mysqld daemons
  4200. ps-protocol Use the binary protocol between client and server
  4201. cursor-protocol Use the cursor protocol between client and server
  4202. (implies --ps-protocol)
  4203. view-protocol Create a view to execute all non updating queries
  4204. sp-protocol Create a stored procedure to execute all queries
  4205. compress Use the compressed protocol between client and server
  4206. ssl Use ssl protocol between client and server
  4207. skip-ssl Dont start server with support for ssl connections
  4208. bench Run the benchmark suite
  4209. small-bench Run the benchmarks with --small-tests --small-tables
  4210. ndb|with-ndbcluster Use cluster as default table type
  4211. vs-config Visual Studio configuration used to create executables
  4212. (default: MTR_VS_CONFIG environment variable)
  4213. Options to control directories to use
  4214. benchdir=DIR The directory where the benchmark suite is stored
  4215. (default: ../../mysql-bench)
  4216. tmpdir=DIR The directory where temporary files are stored
  4217. (default: ./var/tmp).
  4218. vardir=DIR The directory where files generated from the test run
  4219. is stored (default: ./var). Specifying a ramdisk or
  4220. tmpfs will speed up tests.
  4221. mem Run testsuite in "memory" using tmpfs or ramdisk
  4222. Attempts to find a suitable location
  4223. using a builtin list of standard locations
  4224. for tmpfs (/dev/shm)
  4225. The option can also be set using environment
  4226. variable MTR_MEM=[DIR]
  4227. Options to control what test suites or cases to run
  4228. force Continue to run the suite after failure
  4229. with-ndbcluster-only Run only tests that include "ndb" in the filename
  4230. skip-ndb[cluster] Skip all tests that need cluster
  4231. skip-ndb[cluster]-slave Skip all tests that need a slave cluster
  4232. ndb-extra Run extra tests from ndb directory
  4233. do-test=PREFIX Run test cases which name are prefixed with PREFIX
  4234. start-from=PREFIX Run test cases starting from test prefixed with PREFIX
  4235. suite=NAME Run the test suite named NAME. The default is "main"
  4236. skip-rpl Skip the replication test cases.
  4237. skip-im Don't start IM, and skip the IM test cases
  4238. skip-test=PREFIX Skip test cases which name are prefixed with PREFIX
  4239. big-test Set the environment variable BIG_TEST, which can be
  4240. checked from test cases.
  4241. Options that specify ports
  4242. master_port=PORT Specify the port number used by the first master
  4243. slave_port=PORT Specify the port number used by the first slave
  4244. ndbcluster-port=PORT Specify the port number used by cluster
  4245. ndbcluster-port-slave=PORT Specify the port number used by slave cluster
  4246. mtr-build-thread=# Specify unique collection of ports. Can also be set by
  4247. setting the environment variable MTR_BUILD_THREAD.
  4248. Options for test case authoring
  4249. record TESTNAME (Re)genereate the result file for TESTNAME
  4250. check-testcases Check testcases for sideeffects
  4251. mark-progress Log line number and elapsed time to <testname>.progress
  4252. Options that pass on options
  4253. mysqld=ARGS Specify additional arguments to "mysqld"
  4254. Options to run test on running server
  4255. extern Use running server for tests
  4256. ndb-connectstring=STR Use running cluster, and connect using STR
  4257. ndb-connectstring-slave=STR Use running slave cluster, and connect using STR
  4258. user=USER User for connection to extern server
  4259. socket=PATH Socket for connection to extern server
  4260. Options for debugging the product
  4261. client-ddd Start mysqltest client in ddd
  4262. client-debugger=NAME Start mysqltest in the selected debugger
  4263. client-gdb Start mysqltest client in gdb
  4264. ddd Start mysqld in ddd
  4265. debug Dump trace output for all servers and client programs
  4266. debugger=NAME Start mysqld in the selected debugger
  4267. gdb Start the mysqld(s) in gdb
  4268. manual-debug Let user manually start mysqld in debugger, before
  4269. running test(s)
  4270. manual-gdb Let user manually start mysqld in gdb, before running
  4271. test(s)
  4272. manual-ddd Let user manually start mysqld in ddd, before running
  4273. test(s)
  4274. master-binary=PATH Specify the master "mysqld" to use
  4275. slave-binary=PATH Specify the slave "mysqld" to use
  4276. strace-client Create strace output for mysqltest client
  4277. max-save-core Limit the number of core files saved (to avoid filling
  4278. up disks for heavily crashing server). Defaults to
  4279. $opt_max_save_core, set to 0 for no limit.
  4280. Options for coverage, profiling etc
  4281. gcov FIXME
  4282. gprof FIXME
  4283. valgrind Run the "mysqltest" and "mysqld" executables using
  4284. valgrind with options($default_valgrind_options)
  4285. valgrind-all Synonym for --valgrind
  4286. valgrind-mysqltest Run the "mysqltest" and "mysql_client_test" executable
  4287. with valgrind
  4288. valgrind-mysqld Run the "mysqld" executable with valgrind
  4289. valgrind-options=ARGS Options to give valgrind, replaces default options
  4290. valgrind-path=[EXE] Path to the valgrind executable
  4291. callgrind Instruct valgrind to use callgrind
  4292. Misc options
  4293. comment=STR Write STR to the output
  4294. notimer Don't show test case execution time
  4295. script-debug Debug this script itself
  4296. verbose More verbose output
  4297. start-and-exit Only initialize and start the servers, using the
  4298. startup settings for the specified test case (if any)
  4299. start-dirty Only start the servers (without initialization) for
  4300. the specified test case (if any)
  4301. fast Don't try to clean up from earlier runs
  4302. reorder Reorder tests to get fewer server restarts
  4303. help Get this help text
  4304. unified-diff | udiff When presenting differences, use unified diff
  4305. testcase-timeout=MINUTES Max test case run time (default $default_testcase_timeout)
  4306. suite-timeout=MINUTES Max test suite run time (default $default_suite_timeout)
  4307. warnings | log-warnings Pass --log-warnings to mysqld
  4308. sleep=SECONDS Passed to mysqltest, will be used as fixed sleep time
  4309. Deprecated options
  4310. with-openssl Deprecated option for ssl
  4311. HERE
  4312. mtr_exit(1);
  4313. }