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.

4465 lines
122 KiB

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