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.

3714 lines
100 KiB

18 years ago
20 years ago
18 years ago
18 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
18 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
18 years ago
18 years ago
20 years ago
20 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
  1. #!/usr/bin/perl
  2. # -*- cperl -*-
  3. #
  4. ##############################################################################
  5. #
  6. # mysql-test-run.pl
  7. #
  8. # Tool used for executing a suite of .test files
  9. #
  10. # See the "MySQL Test framework manual" for more information
  11. # http://dev.mysql.com/doc/mysqltest/en/index.html
  12. #
  13. # Please keep the test framework tools identical in all versions!
  14. #
  15. ##############################################################################
  16. use strict;
  17. use warnings;
  18. BEGIN {
  19. # Check that mysql-test-run.pl is started from mysql-test/
  20. unless ( -f "mysql-test-run.pl" )
  21. {
  22. print "**** ERROR **** ",
  23. "You must start mysql-test-run from the mysql-test/ directory\n";
  24. exit(1);
  25. }
  26. # Check that lib exist
  27. unless ( -d "lib/" )
  28. {
  29. print "**** ERROR **** ",
  30. "Could not find the lib/ directory \n";
  31. exit(1);
  32. }
  33. }
  34. use lib "lib";
  35. use Cwd;
  36. use Getopt::Long;
  37. use My::File::Path; # Patched version of File::Path
  38. use File::Basename;
  39. use File::Copy;
  40. use File::Temp qw / tempdir /;
  41. use My::Platform;
  42. use My::SafeProcess;
  43. use My::ConfigFactory;
  44. use My::Options;
  45. use mtr_cases;
  46. use mtr_report;
  47. require "lib/mtr_process.pl";
  48. require "lib/mtr_io.pl";
  49. require "lib/mtr_gcov.pl";
  50. require "lib/mtr_match.pl";
  51. require "lib/mtr_misc.pl";
  52. require "lib/mtr_unique.pl";
  53. $SIG{INT}= sub { mtr_error("Got ^C signal"); };
  54. our $mysql_version_id;
  55. our $glob_mysql_test_dir;
  56. our $basedir;
  57. our $path_charsetsdir;
  58. our $path_client_bindir;
  59. our $path_language;
  60. our $path_current_testlog;
  61. our $path_testlog;
  62. our $default_vardir;
  63. our $opt_vardir; # Path to use for var/ dir
  64. my $path_vardir_trace; # unix formatted opt_vardir for trace files
  65. my $opt_tmpdir; # Path to use for tmp/ dir
  66. my $path_config_file; # The generated config file, var/my.cnf
  67. # Visual Studio produces executables in different sub-directories based on the
  68. # configuration used to build them. To make life easier, an environment
  69. # variable or command-line option may be specified to control which set of
  70. # executables will be used by the test suite.
  71. our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
  72. my $DEFAULT_SUITES= "main,binlog,federated,rpl,rpl_ndb,ndb";
  73. our $opt_suites= $DEFAULT_SUITES;
  74. our $opt_verbose= 0; # Verbose output, enable with --verbose
  75. our $opt_verbose_restart= 0; # Verbose output for restarts
  76. my $exe_mysqld;
  77. our $exe_mysql;
  78. our $exe_mysqladmin;
  79. our $exe_mysqltest;
  80. our $exe_ndbd;
  81. our $exe_ndb_mgmd= "";
  82. our $exe_libtool;
  83. my $opt_big_test= 0;
  84. our @opt_combinations;
  85. our @opt_extra_mysqld_opt;
  86. our $opt_compress;
  87. our $opt_ssl;
  88. our $opt_skip_ssl;
  89. our $opt_ssl_supported;
  90. our $opt_ps_protocol;
  91. our $opt_sp_protocol;
  92. our $opt_cursor_protocol;
  93. our $opt_view_protocol;
  94. our $opt_debug;
  95. our @opt_cases; # The test cases names in argv
  96. our $opt_embedded_server;
  97. # Options used when connecting to an already running server
  98. my %opts_extern;
  99. sub using_extern { return (keys %opts_extern > 0);};
  100. our $opt_fast= 0;
  101. our $opt_force;
  102. our $opt_mem= $ENV{'MTR_MEM'};
  103. our $opt_gcov;
  104. our $opt_gcov_err;
  105. our $opt_gcov_msg;
  106. our $glob_debugger= 0;
  107. our $opt_gdb;
  108. our $opt_client_gdb;
  109. our $opt_ddd;
  110. our $opt_client_ddd;
  111. our $opt_manual_gdb;
  112. our $opt_manual_ddd;
  113. our $opt_manual_debug;
  114. our $opt_debugger;
  115. our $opt_client_debugger;
  116. my $config; # The currently running config
  117. my $current_config_name; # The currently running config file template
  118. my $opt_baseport;
  119. my $opt_mtr_build_thread= $ENV{'MTR_BUILD_THREAD'} || "auto";
  120. my $opt_record;
  121. my $opt_report_features;
  122. our $opt_check_testcases;
  123. my $opt_mark_progress;
  124. my $opt_sleep;
  125. my $opt_testcase_timeout= 15; # 15 minutes
  126. my $opt_suite_timeout = 180; # 3 hours
  127. my $opt_shutdown_timeout= 10; # 10 seconds
  128. my $opt_start_timeout = 30; # 30 seconds
  129. my $opt_start;
  130. my $opt_start_dirty;
  131. my $opt_repeat= 1;
  132. my $opt_retry= 1;
  133. my $opt_retry_failure= 2;
  134. my $opt_strace_client;
  135. our $opt_timer= 1;
  136. our $opt_user;
  137. my $opt_valgrind= 0;
  138. my $opt_valgrind_mysqld= 0;
  139. my $opt_valgrind_mysqltest= 0;
  140. my @default_valgrind_args= ("--show-reachable=yes");
  141. my @valgrind_args;
  142. my $opt_valgrind_path;
  143. my $opt_callgrind;
  144. our $opt_warnings= 1;
  145. our $opt_skip_ndbcluster= 0;
  146. our $opt_skip_ndbcluster_slave= 0;
  147. our $opt_with_ndbcluster= 0;
  148. our $glob_ndbcluster_supported= 0;
  149. our $opt_ndb_extra_test= 0;
  150. our $exe_ndb_mgm="";
  151. our $exe_ndb_waiter;
  152. our $path_ndb_tools_dir= "";
  153. our $path_ndb_examples_dir= "";
  154. our $exe_ndb_example= "";
  155. our $path_ndb_testrun_log;
  156. our $path_sql_dir;
  157. our $debug_compiled_binaries;
  158. our %mysqld_variables;
  159. my $source_dist= 0;
  160. our $opt_max_save_core= 5;
  161. my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
  162. select(STDOUT);
  163. $| = 1; # Automatically flush STDOUT
  164. main();
  165. sub main {
  166. command_line_setup();
  167. mtr_report("Checking supported features...");
  168. check_ndbcluster_support(\%mysqld_variables);
  169. check_ssl_support(\%mysqld_variables);
  170. check_debug_support(\%mysqld_variables);
  171. executable_setup();
  172. environment_setup();
  173. if ( $opt_gcov )
  174. {
  175. gcov_prepare();
  176. }
  177. # Figure out which tests we are going to run
  178. mtr_report("Collecting tests...");
  179. my $tests= collect_test_cases($opt_suites, \@opt_cases);
  180. initialize_servers();
  181. if ( $opt_report_features ) {
  182. # Put "report features" as the first test to run
  183. my $tinfo = {};
  184. $tinfo->{'name'} = 'report_features';
  185. $tinfo->{'result_file'} = undef; # Prints result
  186. $tinfo->{'path'} = 'include/report-features.test';
  187. $tinfo->{'master_opt'} = [];
  188. $tinfo->{'slave_opt'} = [];
  189. unshift(@$tests, $tinfo);
  190. }
  191. if ( using_extern() ) {
  192. create_config_file_for_extern(%opts_extern);
  193. }
  194. run_tests($tests);
  195. exit(0);
  196. }
  197. sub ignore_option {
  198. my ($opt, $value)= @_;
  199. print "Ignoring option '$opt'\n";
  200. }
  201. sub command_line_setup {
  202. my $opt_comment;
  203. my $opt_usage;
  204. # This is needed for test log evaluation in "gen-build-status-page"
  205. # in all cases where the calling tool does not log the commands
  206. # directly before it executes them, like "make test-force-pl" in RPM builds.
  207. mtr_report("Logging: $0 ", join(" ", @ARGV));
  208. # Read the command line options
  209. # Note: Keep list, and the order, in sync with usage at end of this file
  210. Getopt::Long::Configure("pass_through");
  211. GetOptions(
  212. # Control what engine/variation to run
  213. 'embedded-server' => \$opt_embedded_server,
  214. 'ps-protocol' => \$opt_ps_protocol,
  215. 'sp-protocol' => \$opt_sp_protocol,
  216. 'view-protocol' => \$opt_view_protocol,
  217. 'cursor-protocol' => \$opt_cursor_protocol,
  218. 'ssl|with-openssl' => \$opt_ssl,
  219. 'skip-ssl' => \$opt_skip_ssl,
  220. 'compress' => \$opt_compress,
  221. 'with-ndbcluster|ndb' => \$opt_with_ndbcluster,
  222. 'vs-config' => \$opt_vs_config,
  223. # Config file to use as template for all tests
  224. 'defaults-file=s' => \&collect_option,
  225. # Extra config file to append to all generated configs
  226. 'defaults-extra-file=s' => \&collect_option,
  227. # Control what test suites or cases to run
  228. 'force' => \$opt_force,
  229. 'with-ndbcluster-only' => \&collect_option,
  230. 'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
  231. 'skip-ndbcluster-slave|skip-ndb-slave'
  232. => \$opt_skip_ndbcluster_slave,
  233. 'ndb-extra-test' => \$opt_ndb_extra_test,
  234. 'suite|suites=s' => \$opt_suites,
  235. 'skip-rpl' => \&collect_option,
  236. 'skip-test=s' => \&collect_option,
  237. 'do-test=s' => \&collect_option,
  238. 'start-from=s' => \&collect_option,
  239. 'big-test' => \$opt_big_test,
  240. 'combination=s' => \@opt_combinations,
  241. 'skip-combination' => \&collect_option,
  242. 'skip-im' => \&ignore_option,
  243. # Specify ports
  244. 'build-thread|mtr-build-thread=i' => \$opt_mtr_build_thread,
  245. # Test case authoring
  246. 'record' => \$opt_record,
  247. 'check-testcases' => \$opt_check_testcases,
  248. 'mark-progress' => \$opt_mark_progress,
  249. # Extra options used when starting mysqld
  250. 'mysqld=s' => \@opt_extra_mysqld_opt,
  251. # Run test on running server
  252. 'extern=s' => \%opts_extern, # Append to hash
  253. # Debugging
  254. 'debug' => \$opt_debug,
  255. 'gdb' => \$opt_gdb,
  256. 'client-gdb' => \$opt_client_gdb,
  257. 'manual-gdb' => \$opt_manual_gdb,
  258. 'manual-debug' => \$opt_manual_debug,
  259. 'ddd' => \$opt_ddd,
  260. 'client-ddd' => \$opt_client_ddd,
  261. 'manual-ddd' => \$opt_manual_ddd,
  262. 'debugger=s' => \$opt_debugger,
  263. 'client-debugger=s' => \$opt_client_debugger,
  264. 'strace-client:s' => \$opt_strace_client,
  265. 'max-save-core=i' => \$opt_max_save_core,
  266. # Coverage, profiling etc
  267. 'gcov' => \$opt_gcov,
  268. 'valgrind|valgrind-all' => \$opt_valgrind,
  269. 'valgrind-mysqltest' => \$opt_valgrind_mysqltest,
  270. 'valgrind-mysqld' => \$opt_valgrind_mysqld,
  271. 'valgrind-options=s' => sub {
  272. my ($opt, $value)= @_;
  273. # Deprecated option unless it's what we know pushbuild uses
  274. if ($value eq "--gen-suppressions=all --show-reachable=yes") {
  275. push(@valgrind_args, $_) for (split(' ', $value));
  276. return;
  277. }
  278. die("--valgrind-options=s is deprecated. Use ",
  279. "--valgrind-option=s, to be specified several",
  280. " times if necessary");
  281. },
  282. 'valgrind-option=s' => \@valgrind_args,
  283. 'valgrind-path=s' => \$opt_valgrind_path,
  284. 'callgrind' => \$opt_callgrind,
  285. # Directories
  286. 'tmpdir=s' => \$opt_tmpdir,
  287. 'vardir=s' => \$opt_vardir,
  288. 'mem' => \$opt_mem,
  289. # Misc
  290. 'report-features' => \$opt_report_features,
  291. 'comment=s' => \$opt_comment,
  292. 'fast' => \$opt_fast,
  293. 'reorder' => \&collect_option,
  294. 'enable-disabled' => \&collect_option,
  295. 'verbose+' => \$opt_verbose,
  296. 'verbose-restart' => \$opt_verbose_restart,
  297. 'sleep=i' => \$opt_sleep,
  298. 'start-dirty' => \$opt_start_dirty,
  299. 'start' => \$opt_start,
  300. 'print-testcases' => \&collect_option,
  301. 'repeat=i' => \$opt_repeat,
  302. 'retry=i' => \$opt_retry,
  303. 'retry-failure=i' => \$opt_retry_failure,
  304. 'timer!' => \$opt_timer,
  305. 'user=s' => \$opt_user,
  306. 'testcase-timeout=i' => \$opt_testcase_timeout,
  307. 'suite-timeout=i' => \$opt_suite_timeout,
  308. 'shutdown-timeout=i' => \$opt_shutdown_timeout,
  309. 'warnings!' => \$opt_warnings,
  310. 'timestamp' => \&report_option,
  311. 'help|h' => \$opt_usage,
  312. ) or usage("Can't read options");
  313. usage("") if $opt_usage;
  314. # --------------------------------------------------------------------------
  315. # Check mtr_build_thread and calculate baseport
  316. # --------------------------------------------------------------------------
  317. set_mtr_build_thread_ports($opt_mtr_build_thread);
  318. if ( -d "../sql" )
  319. {
  320. $source_dist= 1;
  321. }
  322. # Find the absolute path to the test directory
  323. $glob_mysql_test_dir= cwd();
  324. if (IS_CYGWIN)
  325. {
  326. # Use mixed path format i.e c:/path/to/
  327. $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
  328. }
  329. # In most cases, the base directory we find everything relative to,
  330. # is the parent directory of the "mysql-test" directory. For source
  331. # distributions, TAR binary distributions and some other packages.
  332. $basedir= dirname($glob_mysql_test_dir);
  333. # In the RPM case, binaries and libraries are installed in the
  334. # default system locations, instead of having our own private base
  335. # directory. And we install "/usr/share/mysql-test". Moving up one
  336. # more directory relative to "mysql-test" gives us a usable base
  337. # directory for RPM installs.
  338. if ( ! $source_dist and ! -d "$basedir/bin" )
  339. {
  340. $basedir= dirname($basedir);
  341. }
  342. #
  343. # Find the mysqld executable to be able to find the mysqld version
  344. # number as early as possible
  345. #
  346. # Look for the client binaries directory
  347. $path_client_bindir= mtr_path_exists("$basedir/client_release",
  348. "$basedir/client_debug",
  349. vs_config_dirs('client', ''),
  350. "$basedir/client",
  351. "$basedir/bin");
  352. # Look for language files and charsetsdir, use same share
  353. my $path_share= mtr_path_exists("$basedir/share/mysql",
  354. "$basedir/sql/share",
  355. "$basedir/share");
  356. $path_language= mtr_path_exists("$path_share/english");
  357. $path_charsetsdir= mtr_path_exists("$path_share/charsets");
  358. # Look for SQL scripts directory
  359. if ( mtr_file_exists("$path_share/mysql_system_tables.sql") ne "")
  360. {
  361. # The SQL scripts are in path_share
  362. $path_sql_dir= $path_share;
  363. }
  364. else
  365. {
  366. $path_sql_dir= mtr_path_exists("$basedir/share",
  367. "$basedir/scripts");
  368. }
  369. $exe_mysqld= mtr_exe_exists (vs_config_dirs('sql', 'mysqld'),
  370. vs_config_dirs('sql', 'mysqld-debug'),
  371. "$basedir/sql/mysqld",
  372. "$path_client_bindir/mysqld-max-nt",
  373. "$path_client_bindir/mysqld-max",
  374. "$path_client_bindir/mysqld-nt",
  375. "$path_client_bindir/mysqld",
  376. "$path_client_bindir/mysqld-debug",
  377. "$path_client_bindir/mysqld-max",
  378. "$basedir/libexec/mysqld",
  379. "$basedir/bin/mysqld",
  380. "$basedir/sbin/mysqld");
  381. # Use the mysqld found above to find out what features are available
  382. collect_mysqld_features();
  383. if ( $opt_comment )
  384. {
  385. mtr_report();
  386. mtr_print_thick_line('#');
  387. mtr_report("# $opt_comment");
  388. mtr_print_thick_line('#');
  389. }
  390. foreach my $arg ( @ARGV )
  391. {
  392. if ( $arg =~ /^--skip-/ )
  393. {
  394. push(@opt_extra_mysqld_opt, $arg);
  395. }
  396. elsif ( $arg =~ /^--$/ )
  397. {
  398. # It is an effect of setting 'pass_through' in option processing
  399. # that the lone '--' separating options from arguments survives,
  400. # simply ignore it.
  401. }
  402. elsif ( $arg =~ /^-/ )
  403. {
  404. usage("Invalid option \"$arg\"");
  405. }
  406. else
  407. {
  408. push(@opt_cases, $arg);
  409. }
  410. }
  411. # --------------------------------------------------------------------------
  412. # Find out type of logging that are being used
  413. # --------------------------------------------------------------------------
  414. foreach my $arg ( @opt_extra_mysqld_opt )
  415. {
  416. if ( $arg =~ /binlog[-_]format=(\S+)/ )
  417. {
  418. # Save this for collect phase
  419. collect_option('binlog-format', $1);
  420. mtr_report("Using binlog format '$1'");
  421. }
  422. }
  423. # --------------------------------------------------------------------------
  424. # Find out default storage engine being used(if any)
  425. # --------------------------------------------------------------------------
  426. foreach my $arg ( @opt_extra_mysqld_opt )
  427. {
  428. if ( $arg =~ /default-storage-engine=(\S+)/ )
  429. {
  430. # Save this for collect phase
  431. collect_option('default-storage-engine', $1);
  432. mtr_report("Using default engine '$1'")
  433. }
  434. }
  435. # --------------------------------------------------------------------------
  436. # Check if we should speed up tests by trying to run on tmpfs
  437. # --------------------------------------------------------------------------
  438. if ( defined $opt_mem )
  439. {
  440. mtr_error("Can't use --mem and --vardir at the same time ")
  441. if $opt_vardir;
  442. mtr_error("Can't use --mem and --tmpdir at the same time ")
  443. if $opt_tmpdir;
  444. # Search through list of locations that are known
  445. # to be "fast disks" to find a suitable location
  446. # Use --mem=<dir> as first location to look.
  447. my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
  448. foreach my $fs (@tmpfs_locations)
  449. {
  450. if ( -d $fs )
  451. {
  452. my $template= "var_${opt_mtr_build_thread}_XXXX";
  453. $opt_mem= tempdir( $template, DIR => $fs, CLEANUP => 0);
  454. last;
  455. }
  456. }
  457. }
  458. # --------------------------------------------------------------------------
  459. # Set the "var/" directory, as it is the base for everything else
  460. # --------------------------------------------------------------------------
  461. $default_vardir= "$glob_mysql_test_dir/var";
  462. if ( ! $opt_vardir )
  463. {
  464. $opt_vardir= $default_vardir;
  465. }
  466. elsif ( $mysql_version_id < 50000 and
  467. $opt_vardir ne $default_vardir)
  468. {
  469. # Version 4.1 and --vardir was specified
  470. # Only supported as a symlink from var/
  471. # by setting up $opt_mem that symlink will be created
  472. if ( ! IS_WINDOWS )
  473. {
  474. # Only platforms that have native symlinks can use the vardir trick
  475. $opt_mem= $opt_vardir;
  476. mtr_report("Using 4.1 vardir trick");
  477. }
  478. $opt_vardir= $default_vardir;
  479. }
  480. $path_vardir_trace= $opt_vardir;
  481. # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
  482. $path_vardir_trace=~ s/^\w://;
  483. # We make the path absolute, as the server will do a chdir() before usage
  484. unless ( $opt_vardir =~ m,^/, or
  485. (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) )
  486. {
  487. # Make absolute path, relative test dir
  488. $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
  489. }
  490. # Location of my.cnf that all clients use
  491. $path_config_file= "$opt_vardir/my.cnf";
  492. # --------------------------------------------------------------------------
  493. # Set tmpdir
  494. # --------------------------------------------------------------------------
  495. $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
  496. $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
  497. # --------------------------------------------------------------------------
  498. # fast option
  499. # --------------------------------------------------------------------------
  500. if ($opt_fast){
  501. $opt_shutdown_timeout= 0; # Kill processes instead of nice shutdown
  502. }
  503. # --------------------------------------------------------------------------
  504. # Record flag
  505. # --------------------------------------------------------------------------
  506. if ( $opt_record and ! @opt_cases )
  507. {
  508. mtr_error("Will not run in record mode without a specific test case");
  509. }
  510. # --------------------------------------------------------------------------
  511. # Embedded server flag
  512. # --------------------------------------------------------------------------
  513. if ( $opt_embedded_server )
  514. {
  515. if ( IS_WINDOWS )
  516. {
  517. # Add the location for libmysqld.dll to the path.
  518. my $separator= ";";
  519. my $lib_mysqld=
  520. mtr_path_exists(vs_config_dirs('libmysqld',''));
  521. if ( IS_CYGWIN )
  522. {
  523. $lib_mysqld= posix_path($lib_mysqld);
  524. $separator= ":";
  525. }
  526. $ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld;
  527. }
  528. $opt_skip_ndbcluster= 1; # Turn off use of NDB cluster
  529. $opt_skip_ssl= 1; # Turn off use of SSL
  530. # Turn off use of bin log
  531. push(@opt_extra_mysqld_opt, "--skip-log-bin");
  532. if ( using_extern() )
  533. {
  534. mtr_error("Can't use --extern with --embedded-server");
  535. }
  536. }
  537. # --------------------------------------------------------------------------
  538. # Big test flags
  539. # --------------------------------------------------------------------------
  540. if ( $opt_big_test )
  541. {
  542. $ENV{'BIG_TEST'}= 1;
  543. }
  544. # --------------------------------------------------------------------------
  545. # Gcov flag
  546. # --------------------------------------------------------------------------
  547. if ( $opt_gcov and ! $source_dist )
  548. {
  549. mtr_error("Coverage test needs the source - please use source dist");
  550. }
  551. # --------------------------------------------------------------------------
  552. # Check debug related options
  553. # --------------------------------------------------------------------------
  554. if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd ||
  555. $opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug ||
  556. $opt_debugger || $opt_client_debugger )
  557. {
  558. # Indicate that we are using debugger
  559. $glob_debugger= 1;
  560. if ( using_extern() )
  561. {
  562. mtr_error("Can't use --extern when using debugger");
  563. }
  564. }
  565. # --------------------------------------------------------------------------
  566. # Check valgrind arguments
  567. # --------------------------------------------------------------------------
  568. if ( $opt_valgrind or $opt_valgrind_path or @valgrind_args)
  569. {
  570. mtr_report("Turning on valgrind for all executables");
  571. $opt_valgrind= 1;
  572. $opt_valgrind_mysqld= 1;
  573. $opt_valgrind_mysqltest= 1;
  574. # Increase the timeouts when running with valgrind
  575. $opt_testcase_timeout*= 10;
  576. $opt_suite_timeout*= 6;
  577. $opt_start_timeout*= 10;
  578. }
  579. elsif ( $opt_valgrind_mysqld )
  580. {
  581. mtr_report("Turning on valgrind for mysqld(s) only");
  582. $opt_valgrind= 1;
  583. }
  584. elsif ( $opt_valgrind_mysqltest )
  585. {
  586. mtr_report("Turning on valgrind for mysqltest and mysql_client_test only");
  587. $opt_valgrind= 1;
  588. }
  589. if ( $opt_callgrind )
  590. {
  591. mtr_report("Turning on valgrind with callgrind for mysqld(s)");
  592. $opt_valgrind= 1;
  593. $opt_valgrind_mysqld= 1;
  594. # Set special valgrind options unless options passed on command line
  595. push(@valgrind_args, "--trace-children=yes")
  596. unless @valgrind_args;
  597. }
  598. if ( $opt_valgrind )
  599. {
  600. # Set valgrind_options to default unless already defined
  601. push(@valgrind_args, @default_valgrind_args)
  602. unless @valgrind_args;
  603. mtr_report("Running valgrind with options \"",
  604. join(" ", @valgrind_args), "\"");
  605. }
  606. if ( ! $opt_user )
  607. {
  608. $opt_user= "root"; # We want to do FLUSH xxx commands
  609. }
  610. # On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be
  611. # considered different, so avoid the extra slash (/) in the socket
  612. # paths.
  613. my $sockdir = $opt_tmpdir;
  614. $sockdir =~ s|/+$||;
  615. # On some operating systems, there is a limit to the length of a
  616. # UNIX domain socket's path far below PATH_MAX, so try to avoid long
  617. # socket path names.
  618. $sockdir = tempdir(CLEANUP => 0) if ( length($sockdir) >= 70 );
  619. $path_testlog= "$opt_vardir/log/mysqltest.log";
  620. $path_current_testlog= "$opt_vardir/log/current_test";
  621. $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
  622. }
  623. #
  624. # To make it easier for different devs to work on the same host,
  625. # an environment variable can be used to control all ports. A small
  626. # number is to be used, 0 - 16 or similar.
  627. #
  628. # Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
  629. # versions of this script, else a 4.0 test run might conflict with a
  630. # 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
  631. # all port numbers might not be used in this version of the script.
  632. #
  633. # Also note the limitation of ports we are allowed to hand out. This
  634. # differs between operating systems and configuration, see
  635. # http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
  636. # But a fairly safe range seems to be 5001 - 32767
  637. #
  638. sub set_mtr_build_thread_ports($) {
  639. my $mtr_build_thread= shift || 0;
  640. if ( lc($mtr_build_thread) eq 'auto' ) {
  641. print "Requesting build thread... ";
  642. $mtr_build_thread=
  643. mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
  644. print "got ".$mtr_build_thread."\n";
  645. }
  646. $ENV{MTR_BUILD_THREAD}= $mtr_build_thread;
  647. # Calculate baseport
  648. $opt_baseport= $mtr_build_thread * 10 + 10000;
  649. if ( $opt_baseport < 5001 or $opt_baseport + 9 >= 32767 )
  650. {
  651. mtr_error("MTR_BUILD_THREAD number results in a port",
  652. "outside 5001 - 32767",
  653. "($opt_baseport - $opt_baseport + 9)");
  654. }
  655. mtr_report("Using MR_BUILD_THREAD $mtr_build_thread,",
  656. "with reserved ports $opt_baseport..".($opt_baseport+9));
  657. }
  658. sub collect_mysqld_features {
  659. my $found_variable_list_start= 0;
  660. my $tmpdir= tempdir(CLEANUP => 0); # Directory removed by this function
  661. #
  662. # Execute "mysqld --no-defaults --help --verbose" to get a
  663. # list of all features and settings
  664. #
  665. # --no-defaults and --skip-grant-tables are to avoid loading
  666. # system-wide configs and plugins
  667. #
  668. # --datadir must exist, mysqld will chdir into it
  669. #
  670. my $args;
  671. mtr_init_args(\$args);
  672. mtr_add_arg($args, "--no-defaults");
  673. mtr_add_arg($args, "--datadir=%s", mixed_path($tmpdir));
  674. mtr_add_arg($args, "--language=%s", $path_language);
  675. mtr_add_arg($args, "--skip-grant-tables");
  676. mtr_add_arg($args, "--verbose");
  677. mtr_add_arg($args, "--help");
  678. my $cmd= join(" ", $exe_mysqld, @$args);
  679. my $list= `$cmd`;
  680. foreach my $line (split('\n', $list))
  681. {
  682. # First look for version
  683. if ( !$mysql_version_id )
  684. {
  685. # Look for version
  686. my $exe_name= basename($exe_mysqld);
  687. mtr_verbose("exe_name: $exe_name");
  688. if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)/ )
  689. {
  690. #print "Major: $1 Minor: $2 Build: $3\n";
  691. $mysql_version_id= $1*10000 + $2*100 + $3;
  692. #print "mysql_version_id: $mysql_version_id\n";
  693. mtr_report("MySQL Version $1.$2.$3");
  694. }
  695. }
  696. else
  697. {
  698. if (!$found_variable_list_start)
  699. {
  700. # Look for start of variables list
  701. if ( $line =~ /[\-]+\s[\-]+/ )
  702. {
  703. $found_variable_list_start= 1;
  704. }
  705. }
  706. else
  707. {
  708. # Put variables into hash
  709. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  710. {
  711. # print "$1=\"$2\"\n";
  712. $mysqld_variables{$1}= $2;
  713. }
  714. else
  715. {
  716. # The variable list is ended with a blank line
  717. if ( $line =~ /^[\s]*$/ )
  718. {
  719. last;
  720. }
  721. else
  722. {
  723. # Send out a warning, we should fix the variables that has no
  724. # space between variable name and it's value
  725. # or should it be fixed width column parsing? It does not
  726. # look like that in function my_print_variables in my_getopt.c
  727. mtr_warning("Could not parse variable list line : $line");
  728. }
  729. }
  730. }
  731. }
  732. }
  733. rmtree($tmpdir);
  734. mtr_error("Could not find version of MySQL") unless $mysql_version_id;
  735. mtr_error("Could not find variabes list") unless $found_variable_list_start;
  736. }
  737. sub executable_setup_ndb () {
  738. # Look for ndb tols and binaries
  739. my $ndb_path= mtr_file_exists("$basedir/ndb",
  740. "$basedir/storage/ndb",
  741. "$basedir/bin");
  742. $exe_ndbd=
  743. mtr_exe_maybe_exists("$ndb_path/src/kernel/ndbd",
  744. "$ndb_path/ndbd");
  745. $exe_ndb_mgm=
  746. mtr_exe_maybe_exists("$ndb_path/src/mgmclient/ndb_mgm",
  747. "$ndb_path/ndb_mgm");
  748. $exe_ndb_mgmd=
  749. mtr_exe_maybe_exists("$ndb_path/src/mgmsrv/ndb_mgmd",
  750. "$ndb_path/ndb_mgmd");
  751. $exe_ndb_waiter=
  752. mtr_exe_maybe_exists("$ndb_path/tools/ndb_waiter",
  753. "$ndb_path/ndb_waiter");
  754. # May not exist
  755. $path_ndb_tools_dir= mtr_file_exists("$ndb_path/tools",
  756. "$ndb_path");
  757. # May not exist
  758. $path_ndb_examples_dir=
  759. mtr_file_exists("$ndb_path/ndbapi-examples",
  760. "$ndb_path/examples");
  761. # May not exist
  762. $exe_ndb_example=
  763. mtr_file_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple");
  764. return ( $exe_ndbd eq "" or
  765. $exe_ndb_mgm eq "" or
  766. $exe_ndb_mgmd eq "" or
  767. $exe_ndb_waiter eq "");
  768. }
  769. sub executable_setup () {
  770. #
  771. # Check if libtool is available in this distribution/clone
  772. # we need it when valgrinding or debugging non installed binary
  773. # Otherwise valgrind will valgrind the libtool wrapper or bash
  774. # and gdb will not find the real executable to debug
  775. #
  776. if ( -x "../libtool")
  777. {
  778. $exe_libtool= "../libtool";
  779. if ($opt_valgrind or $glob_debugger)
  780. {
  781. mtr_report("Using \"$exe_libtool\" when running valgrind or debugger");
  782. }
  783. }
  784. # Look for the client binaries
  785. $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin");
  786. $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql");
  787. if ( ! $opt_skip_ndbcluster and executable_setup_ndb()) {
  788. mtr_warning("Could not find all required ndb binaries, " .
  789. "all ndb tests will fail, use --skip-ndbcluster to " .
  790. "skip testing it.");
  791. foreach my $cluster ( clusters()) {
  792. $cluster->{"executable_setup_failed"}= 1;
  793. }
  794. }
  795. # Look for mysqltest executable
  796. if ( $opt_embedded_server )
  797. {
  798. $exe_mysqltest=
  799. mtr_exe_exists(vs_config_dirs('libmysqld/examples','mysqltest_embedded'),
  800. "$basedir/libmysqld/examples/mysqltest_embedded",
  801. "$path_client_bindir/mysqltest_embedded");
  802. }
  803. else
  804. {
  805. $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest");
  806. }
  807. }
  808. sub client_debug_arg($$) {
  809. my ($args, $client_name)= @_;
  810. if ( $opt_debug ) {
  811. mtr_add_arg($args,
  812. "--debug=d:t:A,%s/log/%s.trace",
  813. $path_vardir_trace, $client_name)
  814. }
  815. }
  816. sub mysql_fix_arguments () {
  817. return "" if ( IS_WINDOWS );
  818. my $exe=
  819. mtr_script_exists("$basedir/scripts/mysql_fix_privilege_tables",
  820. "$path_client_bindir/mysql_fix_privilege_tables");
  821. my $args;
  822. mtr_init_args(\$args);
  823. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  824. mtr_add_arg($args, "--basedir=", $basedir);
  825. mtr_add_arg($args, "--bindir=", $path_client_bindir);
  826. mtr_add_arg($args, "--verbose");
  827. return mtr_args2str($exe, @$args);
  828. }
  829. sub client_arguments ($) {
  830. my $client_name= shift;
  831. my $client_exe= mtr_exe_exists("$path_client_bindir/$client_name");
  832. my $args;
  833. mtr_init_args(\$args);
  834. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  835. client_debug_arg($args, $client_name);
  836. return mtr_args2str($client_exe, @$args);
  837. }
  838. sub mysqlslap_arguments () {
  839. my $exe= mtr_exe_maybe_exists("$path_client_bindir/mysqlslap");
  840. if ( $exe eq "" ) {
  841. # mysqlap was not found
  842. if (defined $mysql_version_id and $mysql_version_id >= 50100 ) {
  843. mtr_error("Could not find the mysqlslap binary");
  844. }
  845. return ""; # Don't care about mysqlslap
  846. }
  847. my $args;
  848. mtr_init_args(\$args);
  849. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  850. client_debug_arg($args, "mysqlslap");
  851. return mtr_args2str($exe, @$args);
  852. }
  853. sub mysqldump_arguments ($) {
  854. my($group_suffix) = @_;
  855. my $exe= mtr_exe_exists("$path_client_bindir/mysqldump");
  856. my $args;
  857. mtr_init_args(\$args);
  858. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  859. mtr_add_arg($args, "--defaults-group-suffix=_%s", $group_suffix);
  860. client_debug_arg($args, "mysqldump-$group_suffix");
  861. return mtr_args2str($exe, @$args);
  862. }
  863. sub mysql_client_test_arguments(){
  864. my $exe;
  865. # mysql_client_test executable may _not_ exist
  866. if ( $opt_embedded_server ) {
  867. $exe= mtr_exe_maybe_exists(
  868. vs_config_dirs('libmysqld/examples','mysql_client_test_embedded'),
  869. "$basedir/libmysqld/examples/mysql_client_test_embedded");
  870. } else {
  871. $exe= mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
  872. "$basedir/tests/mysql_client_test",
  873. "$basedir/bin/mysql_client_test");
  874. }
  875. my $args;
  876. mtr_init_args(\$args);
  877. if ( $opt_valgrind_mysqltest ) {
  878. valgrind_arguments($args, \$exe);
  879. }
  880. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  881. mtr_add_arg($args, "--testcase");
  882. mtr_add_arg($args, "--vardir=$opt_vardir");
  883. client_debug_arg($args,"mysql_client_test");
  884. return mtr_args2str($exe, @$args);
  885. }
  886. #
  887. # Set environment to be used by childs of this process for
  888. # things that are constant during the whole lifetime of mysql-test-run
  889. #
  890. sub environment_setup {
  891. umask(022);
  892. my @ld_library_paths;
  893. # --------------------------------------------------------------------------
  894. # Setup LD_LIBRARY_PATH so the libraries from this distro/clone
  895. # are used in favor of the system installed ones
  896. # --------------------------------------------------------------------------
  897. if ( $source_dist )
  898. {
  899. push(@ld_library_paths, "$basedir/libmysql/.libs/",
  900. "$basedir/libmysql_r/.libs/",
  901. "$basedir/zlib.libs/");
  902. }
  903. else
  904. {
  905. push(@ld_library_paths, "$basedir/lib");
  906. }
  907. # --------------------------------------------------------------------------
  908. # Add the path where libndbclient can be found
  909. # --------------------------------------------------------------------------
  910. if ( $glob_ndbcluster_supported )
  911. {
  912. push(@ld_library_paths, "$basedir/storage/ndb/src/.libs");
  913. }
  914. # --------------------------------------------------------------------------
  915. # Add the path where mysqld will find udf_example.so
  916. # --------------------------------------------------------------------------
  917. my $lib_udf_example=
  918. mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'),
  919. "$basedir/sql/.libs/udf_example.so",);
  920. if ( $lib_udf_example )
  921. {
  922. push(@ld_library_paths, dirname($lib_udf_example));
  923. }
  924. $ENV{'UDF_EXAMPLE_LIB'}=
  925. ($lib_udf_example ? basename($lib_udf_example) : "");
  926. $ENV{'UDF_EXAMPLE_LIB_OPT'}=
  927. ($lib_udf_example ? "--plugin_dir=" . dirname($lib_udf_example) : "");
  928. # --------------------------------------------------------------------------
  929. # Add the path where mysqld will find ha_example.so
  930. # --------------------------------------------------------------------------
  931. if ($mysql_version_id >= 50100) {
  932. my $lib_example_plugin=
  933. mtr_file_exists(vs_config_dirs('storage/example', 'ha_example.dll'),
  934. "$basedir/storage/example/.libs/ha_example.so",);
  935. $ENV{'EXAMPLE_PLUGIN'}=
  936. ($lib_example_plugin ? basename($lib_example_plugin) : "");
  937. $ENV{'EXAMPLE_PLUGIN_OPT'}=
  938. ($lib_example_plugin ?
  939. "--plugin_dir=" . dirname($lib_example_plugin) : "");
  940. }
  941. # --------------------------------------------------------------------------
  942. # Valgrind need to be run with debug libraries otherwise it's almost
  943. # impossible to add correct supressions, that means if "/usr/lib/debug"
  944. # is available, it should be added to
  945. # LD_LIBRARY_PATH
  946. #
  947. # But pthread is broken in libc6-dbg on Debian <= 3.1 (see Debian
  948. # bug 399035, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=399035),
  949. # so don't change LD_LIBRARY_PATH on that platform.
  950. # --------------------------------------------------------------------------
  951. my $debug_libraries_path= "/usr/lib/debug";
  952. my $deb_version;
  953. if ( $opt_valgrind and -d $debug_libraries_path and
  954. (! -e '/etc/debian_version' or
  955. ($deb_version=
  956. mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
  957. $deb_version > 3.1 ) )
  958. {
  959. push(@ld_library_paths, $debug_libraries_path);
  960. }
  961. $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  962. $ENV{'LD_LIBRARY_PATH'} ?
  963. split(':', $ENV{'LD_LIBRARY_PATH'}) : ());
  964. mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
  965. $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  966. $ENV{'DYLD_LIBRARY_PATH'} ?
  967. split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
  968. mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
  969. # The environment variable used for shared libs on AIX
  970. $ENV{'SHLIB_PATH'}= join(":", @ld_library_paths,
  971. $ENV{'SHLIB_PATH'} ?
  972. split(':', $ENV{'SHLIB_PATH'}) : ());
  973. mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}");
  974. # The environment variable used for shared libs on hp-ux
  975. $ENV{'LIBPATH'}= join(":", @ld_library_paths,
  976. $ENV{'LIBPATH'} ?
  977. split(':', $ENV{'LIBPATH'}) : ());
  978. mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
  979. $ENV{'CHARSETSDIR'}= $path_charsetsdir;
  980. $ENV{'UMASK'}= "0660"; # The octal *string*
  981. $ENV{'UMASK_DIR'}= "0770"; # The octal *string*
  982. #
  983. # MySQL tests can produce output in various character sets
  984. # (especially, ctype_xxx.test). To avoid confusing Perl
  985. # with output which is incompatible with the current locale
  986. # settings, we reset the current values of LC_ALL and LC_CTYPE to "C".
  987. # For details, please see
  988. # Bug#27636 tests fails if LC_* variables set to *_*.UTF-8
  989. #
  990. $ENV{'LC_ALL'}= "C";
  991. $ENV{'LC_CTYPE'}= "C";
  992. $ENV{'LC_COLLATE'}= "C";
  993. $ENV{'USE_RUNNING_SERVER'}= using_extern();
  994. $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
  995. $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
  996. $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'} || 3306;
  997. # ----------------------------------------------------
  998. # Setup env for NDB
  999. # ----------------------------------------------------
  1000. $ENV{'NDB_MGM'}= $exe_ndb_mgm;
  1001. $ENV{'NDB_EXTRA_TEST'}= $opt_ndb_extra_test;
  1002. $ENV{'NDB_TOOLS_DIR'}= $path_ndb_tools_dir;
  1003. $ENV{'NDB_TOOLS_OUTPUT'}= $path_ndb_testrun_log;
  1004. $ENV{'NDB_EXAMPLES_DIR'}= $path_ndb_examples_dir;
  1005. $ENV{'NDB_EXAMPLES_BINARY'}= $exe_ndb_example;
  1006. $ENV{'NDB_EXAMPLES_OUTPUT'}= $path_ndb_testrun_log;
  1007. # ----------------------------------------------------
  1008. # mysql clients
  1009. # ----------------------------------------------------
  1010. $ENV{'MYSQL_CHECK'}= client_arguments("mysqlcheck");
  1011. $ENV{'MYSQL_DUMP'}= mysqldump_arguments(".1");
  1012. $ENV{'MYSQL_DUMP_SLAVE'}= mysqldump_arguments(".2");
  1013. $ENV{'MYSQL_SLAP'}= mysqlslap_arguments();
  1014. $ENV{'MYSQL_IMPORT'}= client_arguments("mysqlimport");
  1015. $ENV{'MYSQL_SHOW'}= client_arguments("mysqlshow");
  1016. $ENV{'MYSQL_BINLOG'}= client_arguments("mysqlbinlog");
  1017. $ENV{'MYSQL'}= client_arguments("mysql");
  1018. $ENV{'MYSQL_UPGRADE'}= client_arguments("mysql_upgrade");
  1019. $ENV{'MYSQLADMIN'}= native_path($exe_mysqladmin);
  1020. $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
  1021. $ENV{'MYSQL_FIX_SYSTEM_TABLES'}= mysql_fix_arguments();
  1022. $ENV{'EXE_MYSQL'}= $exe_mysql;
  1023. # ----------------------------------------------------
  1024. # bug25714 executable may _not_ exist in
  1025. # some versions, test using it should be skipped
  1026. # ----------------------------------------------------
  1027. my $exe_bug25714=
  1028. mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
  1029. "$basedir/tests/bug25714");
  1030. $ENV{'MYSQL_BUG25714'}= native_path($exe_bug25714);
  1031. # ----------------------------------------------------
  1032. # mysql_fix_privilege_tables.sql
  1033. # ----------------------------------------------------
  1034. my $file_mysql_fix_privilege_tables=
  1035. mtr_file_exists("$basedir/scripts/mysql_fix_privilege_tables.sql",
  1036. "$basedir/share/mysql_fix_privilege_tables.sql");
  1037. $ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
  1038. # ----------------------------------------------------
  1039. # my_print_defaults
  1040. # ----------------------------------------------------
  1041. my $exe_my_print_defaults=
  1042. mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
  1043. "$path_client_bindir/my_print_defaults",
  1044. "$basedir/extra/my_print_defaults");
  1045. $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= native_path($exe_my_print_defaults);
  1046. # ----------------------------------------------------
  1047. # perror
  1048. # ----------------------------------------------------
  1049. my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
  1050. "$basedir/extra/perror",
  1051. "$path_client_bindir/perror");
  1052. $ENV{'MY_PERROR'}= native_path($exe_perror);
  1053. # Create an environment variable to make it possible
  1054. # to detect that valgrind is being used from test cases
  1055. $ENV{'VALGRIND_TEST'}= $opt_valgrind;
  1056. }
  1057. #
  1058. # Remove var and any directories in var/ created by previous
  1059. # tests
  1060. #
  1061. sub remove_stale_vardir () {
  1062. mtr_report("Removing old var directory...");
  1063. # Safety!
  1064. mtr_error("No, don't remove the vardir when running with --extern")
  1065. if using_extern();
  1066. mtr_verbose("opt_vardir: $opt_vardir");
  1067. if ( $opt_vardir eq $default_vardir )
  1068. {
  1069. #
  1070. # Running with "var" in mysql-test dir
  1071. #
  1072. if ( -l $opt_vardir)
  1073. {
  1074. # var is a symlink
  1075. if ( $opt_mem )
  1076. {
  1077. # Remove the directory which the link points at
  1078. mtr_verbose("Removing " . readlink($opt_vardir));
  1079. rmtree(readlink($opt_vardir));
  1080. # Remove the "var" symlink
  1081. mtr_verbose("unlink($opt_vardir)");
  1082. unlink($opt_vardir);
  1083. }
  1084. else
  1085. {
  1086. # Some users creates a soft link in mysql-test/var to another area
  1087. # - allow it, but remove all files in it
  1088. mtr_report(" - WARNING: Using the 'mysql-test/var' symlink");
  1089. # Make sure the directory where it points exist
  1090. mtr_error("The destination for symlink $opt_vardir does not exist")
  1091. if ! -d readlink($opt_vardir);
  1092. foreach my $bin ( glob("$opt_vardir/*") )
  1093. {
  1094. mtr_verbose("Removing bin $bin");
  1095. rmtree($bin);
  1096. }
  1097. }
  1098. }
  1099. else
  1100. {
  1101. # Remove the entire "var" dir
  1102. mtr_verbose("Removing $opt_vardir/");
  1103. rmtree("$opt_vardir/");
  1104. }
  1105. if ( $opt_mem )
  1106. {
  1107. # A symlink from var/ to $opt_mem will be set up
  1108. # remove the $opt_mem dir to assure the symlink
  1109. # won't point at an old directory
  1110. mtr_verbose("Removing $opt_mem");
  1111. rmtree($opt_mem);
  1112. }
  1113. }
  1114. else
  1115. {
  1116. #
  1117. # Running with "var" in some other place
  1118. #
  1119. # Remove the var/ dir in mysql-test dir if any
  1120. # this could be an old symlink that shouldn't be there
  1121. mtr_verbose("Removing $default_vardir");
  1122. rmtree($default_vardir);
  1123. # Remove the "var" dir
  1124. mtr_verbose("Removing $opt_vardir/");
  1125. rmtree("$opt_vardir/");
  1126. }
  1127. }
  1128. #
  1129. # Create var and the directories needed in var
  1130. #
  1131. sub setup_vardir() {
  1132. mtr_report("Creating var directory...");
  1133. if ( $opt_vardir eq $default_vardir )
  1134. {
  1135. #
  1136. # Running with "var" in mysql-test dir
  1137. #
  1138. if ( -l $opt_vardir )
  1139. {
  1140. # it's a symlink
  1141. # Make sure the directory where it points exist
  1142. mtr_error("The destination for symlink $opt_vardir does not exist")
  1143. if ! -d readlink($opt_vardir);
  1144. }
  1145. elsif ( $opt_mem )
  1146. {
  1147. # Runinng with "var" as a link to some "memory" location, normally tmpfs
  1148. mtr_verbose("Creating $opt_mem");
  1149. mkpath($opt_mem);
  1150. mtr_report(" - symlinking 'var' to '$opt_mem'");
  1151. symlink($opt_mem, $opt_vardir);
  1152. }
  1153. }
  1154. if ( ! -d $opt_vardir )
  1155. {
  1156. mtr_verbose("Creating $opt_vardir");
  1157. mkpath($opt_vardir);
  1158. }
  1159. # Ensure a proper error message if vardir couldn't be created
  1160. unless ( -d $opt_vardir and -w $opt_vardir )
  1161. {
  1162. mtr_error("Writable 'var' directory is needed, use the " .
  1163. "'--vardir=<path>' option");
  1164. }
  1165. mkpath("$opt_vardir/log");
  1166. mkpath("$opt_vardir/run");
  1167. mkpath("$opt_vardir/tmp");
  1168. mkpath($opt_tmpdir) if $opt_tmpdir ne "$opt_vardir/tmp";
  1169. # copy all files from std_data into var/std_data
  1170. # and make them writable
  1171. copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data");
  1172. # Remove old log files
  1173. foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
  1174. {
  1175. unlink($name);
  1176. }
  1177. }
  1178. #
  1179. # Check if running as root
  1180. # i.e a file can be read regardless what mode we set it to
  1181. #
  1182. sub check_running_as_root () {
  1183. my $test_file= "$opt_vardir/test_running_as_root.txt";
  1184. mtr_tofile($test_file, "MySQL");
  1185. chmod(oct("0000"), $test_file);
  1186. my $result="";
  1187. if (open(FILE,"<",$test_file))
  1188. {
  1189. $result= join('', <FILE>);
  1190. close FILE;
  1191. }
  1192. # Some filesystems( for example CIFS) allows reading a file
  1193. # although mode was set to 0000, but in that case a stat on
  1194. # the file will not return 0000
  1195. my $file_mode= (stat($test_file))[2] & 07777;
  1196. $ENV{'MYSQL_TEST_ROOT'}= "NO";
  1197. mtr_verbose("result: $result, file_mode: $file_mode");
  1198. if ($result eq "MySQL" && $file_mode == 0)
  1199. {
  1200. mtr_warning("running this script as _root_ will cause some " .
  1201. "tests to be skipped");
  1202. $ENV{'MYSQL_TEST_ROOT'}= "YES";
  1203. }
  1204. chmod(oct("0755"), $test_file);
  1205. unlink($test_file);
  1206. }
  1207. sub check_ssl_support ($) {
  1208. my $mysqld_variables= shift;
  1209. if ($opt_skip_ssl)
  1210. {
  1211. mtr_report(" - skipping SSL");
  1212. $opt_ssl_supported= 0;
  1213. $opt_ssl= 0;
  1214. return;
  1215. }
  1216. if ( ! $mysqld_variables->{'ssl'} )
  1217. {
  1218. if ( $opt_ssl)
  1219. {
  1220. mtr_error("Couldn't find support for SSL");
  1221. return;
  1222. }
  1223. mtr_report(" - skipping SSL, mysqld not compiled with SSL");
  1224. $opt_ssl_supported= 0;
  1225. $opt_ssl= 0;
  1226. return;
  1227. }
  1228. mtr_report(" - SSL connections supported");
  1229. $opt_ssl_supported= 1;
  1230. }
  1231. sub check_debug_support ($) {
  1232. my $mysqld_variables= shift;
  1233. if ( ! $mysqld_variables->{'debug'} )
  1234. {
  1235. #mtr_report(" - binaries are not debug compiled");
  1236. $debug_compiled_binaries= 0;
  1237. if ( $opt_debug )
  1238. {
  1239. mtr_error("Can't use --debug, binaries does not support it");
  1240. }
  1241. return;
  1242. }
  1243. mtr_report(" - binaries are debug compiled");
  1244. $debug_compiled_binaries= 1;
  1245. }
  1246. #
  1247. # Helper function to handle configuration-based subdirectories which Visual
  1248. # Studio uses for storing binaries. If opt_vs_config is set, this returns
  1249. # a path based on that setting; if not, it returns paths for the default
  1250. # /release/ and /debug/ subdirectories.
  1251. #
  1252. # $exe can be undefined, if the directory itself will be used
  1253. #
  1254. sub vs_config_dirs ($$) {
  1255. my ($path_part, $exe) = @_;
  1256. $exe = "" if not defined $exe;
  1257. # Don't look in these dirs when not on windows
  1258. return () unless IS_WINDOWS;
  1259. if ($opt_vs_config)
  1260. {
  1261. return ("$basedir/$path_part/$opt_vs_config/$exe");
  1262. }
  1263. return ("$basedir/$path_part/release/$exe",
  1264. "$basedir/$path_part/relwithdebinfo/$exe",
  1265. "$basedir/$path_part/debug/$exe");
  1266. }
  1267. sub check_ndbcluster_support ($) {
  1268. my $mysqld_variables= shift;
  1269. if ($opt_skip_ndbcluster)
  1270. {
  1271. mtr_report(" - skipping ndbcluster");
  1272. $opt_skip_ndbcluster_slave= 1;
  1273. return;
  1274. }
  1275. if ( ! $mysqld_variables{'ndb-connectstring'} )
  1276. {
  1277. mtr_report(" - skipping ndbcluster, mysqld not compiled with ndbcluster");
  1278. $opt_skip_ndbcluster= 1;
  1279. $opt_skip_ndbcluster_slave= 1;
  1280. return;
  1281. }
  1282. $glob_ndbcluster_supported= 1;
  1283. mtr_report(" - using ndbcluster when necessary, mysqld supports it");
  1284. if ( $mysql_version_id < 50100 )
  1285. {
  1286. # Slave cluster is not supported until 5.1
  1287. $opt_skip_ndbcluster_slave= 1;
  1288. }
  1289. return;
  1290. }
  1291. sub ndbcluster_wait_started($$){
  1292. my $cluster= shift;
  1293. my $ndb_waiter_extra_opt= shift;
  1294. my $path_waitlog= join('/', $opt_vardir, $cluster->name(), "ndb_waiter.log");
  1295. my $args;
  1296. mtr_init_args(\$args);
  1297. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1298. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  1299. mtr_add_arg($args, "--timeout=60");
  1300. if ($ndb_waiter_extra_opt)
  1301. {
  1302. mtr_add_arg($args, "$ndb_waiter_extra_opt");
  1303. }
  1304. # Start the ndb_waiter which will connect to the ndb_mgmd
  1305. # and poll it for state of the ndbd's, will return when
  1306. # all nodes in the cluster is started
  1307. my $res= My::SafeProcess->run
  1308. (
  1309. name => "ndb_waiter ".$cluster->name(),
  1310. path => $exe_ndb_waiter,
  1311. args => \$args,
  1312. output => $path_waitlog,
  1313. error => $path_waitlog,
  1314. append => 1,
  1315. );
  1316. # Check that ndb_mgmd(s) are still alive
  1317. foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
  1318. {
  1319. my $proc= $ndb_mgmd->{proc};
  1320. if ( ! $proc->wait_one(0) )
  1321. {
  1322. mtr_warning("$proc died");
  1323. return 2;
  1324. }
  1325. }
  1326. # Check that all started ndbd(s) are still alive
  1327. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  1328. {
  1329. my $proc= $ndbd->{proc};
  1330. next unless defined $proc;
  1331. if ( ! $proc->wait_one(0) )
  1332. {
  1333. mtr_warning("$proc died");
  1334. return 3;
  1335. }
  1336. }
  1337. if ($res)
  1338. {
  1339. mtr_verbose("ndbcluster_wait_started failed");
  1340. return 1;
  1341. }
  1342. return 0;
  1343. }
  1344. sub ndb_mgmd_wait_started($) {
  1345. my ($cluster)= @_;
  1346. my $retries= 100;
  1347. while ($retries)
  1348. {
  1349. my $result= ndbcluster_wait_started($cluster, "--no-contact");
  1350. if ($result == 0)
  1351. {
  1352. # ndb_mgmd is started
  1353. mtr_verbose("ndb_mgmd is started");
  1354. return 0;
  1355. }
  1356. elsif ($result > 1)
  1357. {
  1358. mtr_warning("Cluster process failed while waiting for start");
  1359. return $result;
  1360. }
  1361. mtr_milli_sleep(100);
  1362. $retries--;
  1363. }
  1364. return 1;
  1365. }
  1366. sub ndb_mgmd_start ($$) {
  1367. my ($cluster, $ndb_mgmd)= @_;
  1368. mtr_verbose("ndb_mgmd_start");
  1369. my $dir= $ndb_mgmd->value("DataDir");
  1370. mkpath($dir) unless -d $dir;
  1371. my $args;
  1372. mtr_init_args(\$args);
  1373. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1374. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  1375. mtr_add_arg($args, "--mycnf");
  1376. mtr_add_arg($args, "--nodaemon");
  1377. my $path_ndb_mgmd_log= "$dir/ndb_mgmd.log";
  1378. $ndb_mgmd->{'proc'}= My::SafeProcess->new
  1379. (
  1380. name => $ndb_mgmd->after('cluster_config.'),
  1381. path => $exe_ndb_mgmd,
  1382. args => \$args,
  1383. output => $path_ndb_mgmd_log,
  1384. error => $path_ndb_mgmd_log,
  1385. append => 1,
  1386. verbose => $opt_verbose,
  1387. );
  1388. mtr_verbose("Started $ndb_mgmd->{proc}");
  1389. # FIXME Should not be needed
  1390. # Unfortunately the cluster nodes will fail to start
  1391. # if ndb_mgmd has not started properly
  1392. if (ndb_mgmd_wait_started($cluster))
  1393. {
  1394. mtr_warning("Failed to wait for start of ndb_mgmd");
  1395. return 1;
  1396. }
  1397. return 0;
  1398. }
  1399. sub ndbd_start {
  1400. my ($cluster, $ndbd)= @_;
  1401. mtr_verbose("ndbd_start");
  1402. my $dir= $ndbd->value("DataDir");
  1403. mkpath($dir) unless -d $dir;
  1404. my $args;
  1405. mtr_init_args(\$args);
  1406. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1407. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  1408. mtr_add_arg($args, "--nodaemon");
  1409. # > 5.0 { 'character-sets-dir' => \&fix_charset_dir },
  1410. my $path_ndbd_log= "$dir/ndbd.log";
  1411. my $proc= My::SafeProcess->new
  1412. (
  1413. name => $ndbd->after('cluster_config.'),
  1414. path => $exe_ndbd,
  1415. args => \$args,
  1416. output => $path_ndbd_log,
  1417. error => $path_ndbd_log,
  1418. append => 1,
  1419. verbose => $opt_verbose,
  1420. );
  1421. mtr_verbose("Started $proc");
  1422. $ndbd->{proc}= $proc;
  1423. return;
  1424. }
  1425. sub ndbcluster_start ($) {
  1426. my $cluster= shift;
  1427. mtr_verbose("ndbcluster_start '".$cluster->name()."'");
  1428. foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
  1429. {
  1430. next if started($ndb_mgmd);
  1431. ndb_mgmd_start($cluster, $ndb_mgmd);
  1432. }
  1433. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  1434. {
  1435. next if started($ndbd);
  1436. ndbd_start($cluster, $ndbd);
  1437. }
  1438. return 0;
  1439. }
  1440. #
  1441. # Run the collected tests
  1442. #
  1443. my $suite_timeout_proc;
  1444. sub run_tests {
  1445. my ($tests)= @_;
  1446. mtr_report();
  1447. mtr_print_thick_line();
  1448. mtr_print_header();
  1449. $suite_timeout_proc= My::SafeProcess->timer($opt_suite_timeout* 60);
  1450. foreach my $tinfo ( @$tests )
  1451. {
  1452. if (run_testcase_check_skip_test($tinfo))
  1453. {
  1454. next;
  1455. }
  1456. for my $repeat (1..$opt_repeat){
  1457. if (run_testcase($tinfo))
  1458. {
  1459. # Testcase failed, enter retry mode
  1460. my $retries= 1;
  1461. while ($retries < $opt_retry){
  1462. mtr_report("\nRetrying, attempt($retries/$opt_retry)...\n");
  1463. if (run_testcase($tinfo) <= 0)
  1464. {
  1465. # Testcase suceeded
  1466. my $test_has_failed= $tinfo->{failures} || 0;
  1467. if (!$test_has_failed){
  1468. last;
  1469. }
  1470. }
  1471. else
  1472. {
  1473. # Testcase failed
  1474. # Limit number of test failures
  1475. my $failures= $tinfo->{failures};
  1476. if ($opt_retry > 1 and $failures >= $opt_retry_failure){
  1477. mtr_report("Test has failed $failures times, no more retries!\n");
  1478. last;
  1479. }
  1480. }
  1481. $retries++;
  1482. }
  1483. }
  1484. }
  1485. }
  1486. # Kill the test suite timer
  1487. $suite_timeout_proc->kill();
  1488. mtr_print_line();
  1489. stop_all_servers();
  1490. if ( $opt_gcov )
  1491. {
  1492. gcov_collect(); # collect coverage information
  1493. }
  1494. mtr_report_stats($tests);
  1495. }
  1496. sub create_config_file_for_extern {
  1497. my %opts=
  1498. (
  1499. socket => '/tmp/mysqld.sock',
  1500. port => 3306,
  1501. user => 'test',
  1502. password => '',
  1503. @_
  1504. );
  1505. mtr_report("Creating my.cnf file for extern server...");
  1506. my $F= IO::File->new($path_config_file, "w")
  1507. or mtr_error("Can't write to $path_config_file: $!");
  1508. print $F "[client]\n";
  1509. while (my ($option, $value)= each( %opts )) {
  1510. print $F "$option= $value\n";
  1511. mtr_report(" $option= $value");
  1512. }
  1513. print $F <<EOF
  1514. # binlog reads from [client] and [mysqlbinlog]
  1515. [mysqlbinlog]
  1516. character-sets-dir= $path_charsetsdir
  1517. # mysql_fix_privilege_tables.sh don't read from [client]
  1518. [mysql_fix_privilege_tables]
  1519. socket = $opts{'socket'}
  1520. port = $opts{'port'}
  1521. user = $opts{'user'}
  1522. password = $opts{'password'}
  1523. EOF
  1524. ;
  1525. $F= undef; # Close file
  1526. }
  1527. #
  1528. # Kill processes left from previous runs, normally
  1529. # there should be none so make sure to warn
  1530. # if there is one
  1531. #
  1532. sub kill_leftovers ($) {
  1533. my $rundir= shift;
  1534. return unless ( -d $rundir );
  1535. mtr_report("Checking leftover processes...");
  1536. # Scan the "run" directory for process id's to kill
  1537. opendir(RUNDIR, $rundir)
  1538. or mtr_error("kill_leftovers, can't open dir \"$rundir\": $!");
  1539. while ( my $elem= readdir(RUNDIR) )
  1540. {
  1541. # Only read pid from files that end with .pid
  1542. if ( $elem =~ /.*[.]pid$/ )
  1543. {
  1544. my $pidfile= "$rundir/$elem";
  1545. next unless -f $pidfile;
  1546. my $pid= mtr_fromfile($pidfile);
  1547. unlink($pidfile);
  1548. unless ($pid=~ /^(\d+)/){
  1549. # The pid was not a valid number
  1550. mtr_warning("Got invalid pid '$pid' from '$elem'");
  1551. next;
  1552. }
  1553. mtr_report(" - found old pid $pid in '$elem', killing it...");
  1554. my $ret= kill(9, $pid);
  1555. if ($ret == 0) {
  1556. mtr_report(" process did not exist!");
  1557. next;
  1558. }
  1559. my $check_counter= 100;
  1560. while ($ret > 0 and $check_counter--) {
  1561. mtr_milli_sleep(100);
  1562. $ret= kill(0, $pid);
  1563. }
  1564. mtr_report($check_counter ? " ok!" : " failed!");
  1565. }
  1566. else
  1567. {
  1568. mtr_warning("Found non pid file '$elem' in '$rundir'")
  1569. if -f "$rundir/$elem";
  1570. }
  1571. }
  1572. closedir(RUNDIR);
  1573. }
  1574. #
  1575. # Check that all the ports that are going to
  1576. # be used are free
  1577. #
  1578. sub check_ports_free
  1579. {
  1580. my @ports_to_check;
  1581. for ($opt_baseport..$opt_baseport+9){
  1582. push(@ports_to_check, $_);
  1583. }
  1584. mtr_report("Checking ports...");
  1585. # print "@ports_to_check\n";
  1586. foreach my $port (@ports_to_check){
  1587. if (mtr_ping_port($port)){
  1588. mtr_report(" - 'localhost:$port' was not free");
  1589. return 1; # One port was not free
  1590. }
  1591. }
  1592. return 0; # All ports free
  1593. }
  1594. sub initialize_servers {
  1595. if ( using_extern() )
  1596. {
  1597. # Running against an already started server, if the specified
  1598. # vardir does not already exist it should be created
  1599. if ( ! -d $opt_vardir )
  1600. {
  1601. setup_vardir();
  1602. }
  1603. else
  1604. {
  1605. mtr_verbose("No need to create '$opt_vardir' it already exists");
  1606. }
  1607. }
  1608. else
  1609. {
  1610. # Kill leftovers from previous run
  1611. # using any pidfiles found in var/run
  1612. kill_leftovers("$opt_vardir/run");
  1613. if (check_ports_free()){
  1614. # Some port was not free(which one has already been printed)
  1615. mtr_error("Some port(s) was not free")
  1616. }
  1617. if ( ! $opt_start_dirty )
  1618. {
  1619. remove_stale_vardir();
  1620. setup_vardir();
  1621. mysql_install_db();
  1622. }
  1623. }
  1624. check_running_as_root();
  1625. }
  1626. #
  1627. # Copy the reference database into selected datadir
  1628. #
  1629. sub copy_install_db ($) {
  1630. my $path_data_dir= shift;
  1631. # Don't install over another db
  1632. mtr_error("There is already an installed db in '$path_data_dir'")
  1633. if -d $path_data_dir;
  1634. # copy the installed db into place
  1635. copytree("$opt_vardir/install.db", $path_data_dir);
  1636. }
  1637. sub mysql_install_db {
  1638. my $data_dir= "$opt_vardir/install.db";
  1639. mtr_report("Installing system database...");
  1640. my $args;
  1641. mtr_init_args(\$args);
  1642. mtr_add_arg($args, "--no-defaults");
  1643. mtr_add_arg($args, "--bootstrap");
  1644. mtr_add_arg($args, "--basedir=%s", $basedir);
  1645. mtr_add_arg($args, "--datadir=%s", $data_dir);
  1646. mtr_add_arg($args, "--loose-skip-innodb");
  1647. mtr_add_arg($args, "--loose-skip-ndbcluster");
  1648. mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/");
  1649. mtr_add_arg($args, "--core-file");
  1650. if ( $opt_debug )
  1651. {
  1652. mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap.trace",
  1653. $path_vardir_trace);
  1654. }
  1655. mtr_add_arg($args, "--language=%s", $path_language);
  1656. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  1657. # If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
  1658. # configure --disable-grant-options), mysqld will not recognize the
  1659. # --bootstrap or --skip-grant-tables options. The user can set
  1660. # MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
  1661. # --bootstrap, to accommodate this.
  1662. my $exe_mysqld_bootstrap = $ENV{'MYSQLD_BOOTSTRAP'} || $exe_mysqld;
  1663. # ----------------------------------------------------------------------
  1664. # export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
  1665. # ----------------------------------------------------------------------
  1666. $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
  1667. # ----------------------------------------------------------------------
  1668. # Create the bootstrap.sql file
  1669. # ----------------------------------------------------------------------
  1670. my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
  1671. # Use the mysql database for system tables
  1672. mtr_tofile($bootstrap_sql_file, "use mysql");
  1673. # Add the offical mysql system tables
  1674. # for a production system
  1675. mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables.sql",
  1676. $bootstrap_sql_file);
  1677. # Add the mysql system tables initial data
  1678. # for a production system
  1679. mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables_data.sql",
  1680. $bootstrap_sql_file);
  1681. # Add test data for timezone - this is just a subset, on a real
  1682. # system these tables will be populated either by mysql_tzinfo_to_sql
  1683. # or by downloading the timezone table package from our website
  1684. mtr_appendfile_to_file("$path_sql_dir/mysql_test_data_timezone.sql",
  1685. $bootstrap_sql_file);
  1686. # Fill help tables, just an empty file when running from bk repo
  1687. # but will be replaced by a real fill_help_tables.sql when
  1688. # building the source dist
  1689. mtr_appendfile_to_file("$path_sql_dir/fill_help_tables.sql",
  1690. $bootstrap_sql_file);
  1691. # Remove anonymous users
  1692. mtr_tofile($bootstrap_sql_file,
  1693. "DELETE FROM mysql.user where user= '';");
  1694. # Log bootstrap command
  1695. my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
  1696. mtr_tofile($path_bootstrap_log,
  1697. "$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
  1698. # Create directories mysql and test
  1699. mkpath("$data_dir/mysql");
  1700. mkpath("$data_dir/test");
  1701. if ( My::SafeProcess->run
  1702. (
  1703. name => "bootstrap",
  1704. path => $exe_mysqld_bootstrap,
  1705. args => \$args,
  1706. input => $bootstrap_sql_file,
  1707. output => $path_bootstrap_log,
  1708. error => $path_bootstrap_log,
  1709. append => 1,
  1710. verbose => $opt_verbose,
  1711. ) != 0)
  1712. {
  1713. mtr_error("Error executing mysqld --bootstrap\n" .
  1714. "Could not install system database from $bootstrap_sql_file\n" .
  1715. "see $path_bootstrap_log for errors");
  1716. }
  1717. }
  1718. sub run_testcase_check_skip_test($)
  1719. {
  1720. my ($tinfo)= @_;
  1721. # ----------------------------------------------------------------------
  1722. # If marked to skip, just print out and return.
  1723. # Note that a test case not marked as 'skip' can still be
  1724. # skipped later, because of the test case itself in cooperation
  1725. # with the mysqltest program tells us so.
  1726. # ----------------------------------------------------------------------
  1727. if ( $tinfo->{'skip'} )
  1728. {
  1729. mtr_report_test_skipped($tinfo);
  1730. return 1;
  1731. }
  1732. if ($tinfo->{'ndb_test'})
  1733. {
  1734. foreach my $cluster ( clusters() )
  1735. {
  1736. # If test needs this cluster, check binaries was found ok
  1737. if ( $cluster->{'executable_setup_failed'} )
  1738. {
  1739. $tinfo->{comment}=
  1740. "Failed to find cluster binaries";
  1741. mtr_report_test_failed($tinfo, undef);
  1742. return 1;
  1743. }
  1744. }
  1745. }
  1746. return 0;
  1747. }
  1748. sub run_query {
  1749. my ($tinfo, $mysqld, $query)= @_;
  1750. my $args;
  1751. mtr_init_args(\$args);
  1752. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1753. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  1754. mtr_add_arg($args, "-e %s", $query);
  1755. my $res= My::SafeProcess->run
  1756. (
  1757. name => "run_query -> ".$mysqld->name(),
  1758. path => $exe_mysql,
  1759. args => \$args,
  1760. output => '/dev/null',
  1761. error => '/dev/null'
  1762. );
  1763. return $res
  1764. }
  1765. sub do_before_run_mysqltest($)
  1766. {
  1767. my $tinfo= shift;
  1768. # Remove old files produced by mysqltest
  1769. my $base_file= mtr_match_extension($tinfo->{'result_file'},
  1770. "result"); # Trim extension
  1771. unlink("$base_file.reject");
  1772. unlink("$base_file.progress");
  1773. unlink("$base_file.log");
  1774. unlink("$base_file.warnings");
  1775. if ( $mysql_version_id < 50000 ) {
  1776. # Set environment variable NDB_STATUS_OK to 1
  1777. # if script decided to run mysqltest cluster _is_ installed ok
  1778. $ENV{'NDB_STATUS_OK'} = "1";
  1779. } elsif ( $mysql_version_id < 50100 ) {
  1780. # Set environment variable NDB_STATUS_OK to YES
  1781. # if script decided to run mysqltest cluster _is_ installed ok
  1782. $ENV{'NDB_STATUS_OK'} = "YES";
  1783. }
  1784. }
  1785. sub run_check_testcase_all($$)
  1786. {
  1787. my ($tinfo, $mode)= @_;
  1788. my $result;
  1789. foreach my $mysqld ( mysqlds() )
  1790. {
  1791. if ( defined $mysqld->{'proc'} )
  1792. {
  1793. if (run_check_testcase($tinfo, $mode, $mysqld))
  1794. {
  1795. # Check failed, mark the test case with that info
  1796. $tinfo->{'check_testcase_failed'}= 1;
  1797. $result= 1;
  1798. }
  1799. }
  1800. }
  1801. return $result;
  1802. }
  1803. sub mark_log {
  1804. my ($log, $tinfo)= @_;
  1805. my $log_msg= "CURRENT_TEST: $tinfo->{name}\n";
  1806. mtr_tofile($log, $log_msg);
  1807. }
  1808. sub find_testcase_skipped_reason($)
  1809. {
  1810. my ($tinfo)= @_;
  1811. # Set default message
  1812. $tinfo->{'comment'}= "Detected by testcase(no log file)";
  1813. # Open the test log file
  1814. my $F= IO::File->new($path_current_testlog)
  1815. or return;
  1816. my $reason;
  1817. while ( my $line= <$F> )
  1818. {
  1819. # Look for "reason: <reason for skipping test>"
  1820. if ( $line =~ /reason: (.*)/ )
  1821. {
  1822. $reason= $1;
  1823. }
  1824. }
  1825. if ( ! $reason )
  1826. {
  1827. mtr_warning("Could not find reason for skipping test in $path_current_testlog");
  1828. $reason= "Detected by testcase(reason unknown) ";
  1829. }
  1830. $tinfo->{'comment'}= $reason;
  1831. }
  1832. # Return timezone value of tinfo or default value
  1833. sub timezone {
  1834. my ($tinfo)= @_;
  1835. return $tinfo->{timezone} || "GMT-3";
  1836. }
  1837. # Storage for changed environment variables
  1838. my %old_env;
  1839. #
  1840. # Run a single test case
  1841. #
  1842. # RETURN VALUE
  1843. # 0 OK
  1844. # > 0 failure
  1845. #
  1846. sub run_testcase ($) {
  1847. my $tinfo= shift;
  1848. mtr_verbose("Running test:", $tinfo->{name});
  1849. # -------------------------------------------------------
  1850. # Init variables that can change between each test case
  1851. # -------------------------------------------------------
  1852. my $timezone= timezone($tinfo);
  1853. $ENV{'TZ'}= $timezone;
  1854. mtr_verbose("Setting timezone: $timezone");
  1855. if ( ! using_extern() )
  1856. {
  1857. my @restart= servers_need_restart($tinfo);
  1858. if ( @restart != 0) {
  1859. stop_servers($tinfo, @restart );
  1860. }
  1861. if ( started(all_servers()) == 0 )
  1862. {
  1863. # Restore old ENV
  1864. while (my ($option, $value)= each( %old_env )) {
  1865. if (defined $value){
  1866. mtr_verbose("Restoring $option to $value");
  1867. $ENV{$option}= $value;
  1868. } else {
  1869. mtr_verbose("Removing $option");
  1870. delete($ENV{$option});
  1871. }
  1872. }
  1873. %old_env= ();
  1874. mtr_verbose("Generating my.cnf from '$tinfo->{template_path}'");
  1875. # Generate new config file from template
  1876. $config= My::ConfigFactory->new_config
  1877. ( {
  1878. basedir => $basedir,
  1879. template_path => $tinfo->{template_path},
  1880. extra_template_path => $tinfo->{extra_template_path},
  1881. vardir => $opt_vardir,
  1882. tmpdir => $opt_tmpdir,
  1883. baseport => $opt_baseport,
  1884. #hosts => [ 'host1', 'host2' ],
  1885. user => $opt_user,
  1886. password => '',
  1887. ssl => $opt_ssl_supported,
  1888. embedded => $opt_embedded_server,
  1889. }
  1890. );
  1891. # Write the new my.cnf
  1892. $config->save($path_config_file);
  1893. # Remember current config so a restart can occur when a test need
  1894. # to use a different one
  1895. $current_config_name= $tinfo->{template_path};
  1896. #
  1897. # Set variables in the ENV section
  1898. #
  1899. foreach my $option ($config->options_in_group("ENV"))
  1900. {
  1901. # Save old value to restore it before next time
  1902. $old_env{$option->name()}= $ENV{$option->name()};
  1903. mtr_verbose($option->name(), "=",$option->value());
  1904. $ENV{$option->name()}= $option->value();
  1905. }
  1906. }
  1907. # Write start of testcase to log
  1908. mark_log($path_current_testlog, $tinfo);
  1909. if (start_servers($tinfo))
  1910. {
  1911. report_failure_and_restart($tinfo);
  1912. return 1;
  1913. }
  1914. }
  1915. # --------------------------------------------------------------------
  1916. # If --start or --start-dirty given, stop here to let user manually
  1917. # run tests
  1918. # ----------------------------------------------------------------------
  1919. if ( $opt_start or $opt_start_dirty )
  1920. {
  1921. mtr_report("\nServers started, sleeping");
  1922. sleep(1) while (1);
  1923. exit(0);
  1924. }
  1925. my $test_timeout_proc= My::SafeProcess->timer($opt_testcase_timeout * 60);
  1926. do_before_run_mysqltest($tinfo);
  1927. if ( $opt_check_testcases )
  1928. {
  1929. run_check_testcase_all($tinfo, "before")
  1930. }
  1931. my $test= start_mysqltest($tinfo);
  1932. while (1)
  1933. {
  1934. my $proc= My::SafeProcess->wait_any();
  1935. unless ( defined $proc )
  1936. {
  1937. mtr_error("wait_any failed");
  1938. }
  1939. mtr_verbose("Got $proc");
  1940. # ----------------------------------------------------
  1941. # Stop the test case timer
  1942. # ----------------------------------------------------
  1943. $test_timeout_proc->kill();
  1944. # ----------------------------------------------------
  1945. # Was it the test program that exited
  1946. # ----------------------------------------------------
  1947. if ($proc eq $test)
  1948. {
  1949. my $res= $test->exit_status();
  1950. if ( $res == 0 )
  1951. {
  1952. mtr_report_test_passed($tinfo, $opt_timer);
  1953. if ( $opt_check_testcases )
  1954. {
  1955. if (run_check_testcase_all($tinfo, "after"))
  1956. {
  1957. # Stop all servers that are known to be running
  1958. stop_all_servers();
  1959. after_test_failure($tinfo->{'name'});
  1960. mtr_report("Resuming tests...\n");
  1961. }
  1962. }
  1963. }
  1964. elsif ( $res == 62 )
  1965. {
  1966. # Testcase itself tell us to skip this one
  1967. $tinfo->{skip_detected_by_test}= 1;
  1968. # Try to get reason from test log file
  1969. find_testcase_skipped_reason($tinfo);
  1970. mtr_report_test_skipped($tinfo);
  1971. }
  1972. elsif ( $res == 65 )
  1973. {
  1974. # Testprogram killed by signal
  1975. $tinfo->{comment}=
  1976. "testprogram crashed(returned code $res)";
  1977. report_failure_and_restart($tinfo);
  1978. }
  1979. elsif ( $res == 1 )
  1980. {
  1981. # Test case failure reported by mysqltest
  1982. report_failure_and_restart($tinfo);
  1983. }
  1984. else
  1985. {
  1986. # mysqltest failed, probably crashed
  1987. $tinfo->{comment}=
  1988. "mysqltest failed with unexpected return code $res";
  1989. report_failure_and_restart($tinfo);
  1990. }
  1991. # Save info from this testcase run to mysqltest.log
  1992. if( -f $path_current_testlog)
  1993. {
  1994. mtr_appendfile_to_file($path_current_testlog, $path_testlog);
  1995. unlink($path_current_testlog);
  1996. }
  1997. return ($res == 62) ? 0 : $res;
  1998. }
  1999. # ----------------------------------------------------
  2000. # Check if it was an expected crash
  2001. # ----------------------------------------------------
  2002. if ( check_expected_crash_and_restart($proc) )
  2003. {
  2004. next;
  2005. }
  2006. # ----------------------------------------------------
  2007. # It's not mysqltest that has exited, kill it
  2008. # ----------------------------------------------------
  2009. $test->kill();
  2010. # ----------------------------------------------------
  2011. # Check if it was a server that died
  2012. # ----------------------------------------------------
  2013. if ( grep($proc eq $_, started(all_servers())) )
  2014. {
  2015. # Server failed, probably crashed
  2016. $tinfo->{comment}=
  2017. "Server failed during test run";
  2018. report_failure_and_restart($tinfo);
  2019. return 1;
  2020. }
  2021. # ----------------------------------------------------
  2022. # Check if testcase timer expired
  2023. # ----------------------------------------------------
  2024. if ( $proc eq $test_timeout_proc )
  2025. {
  2026. mtr_report("Test case timeout!");
  2027. $tinfo->{'timeout'}= 1; # Mark as timeout
  2028. report_failure_and_restart($tinfo);
  2029. return 1;
  2030. }
  2031. # ----------------------------------------------------
  2032. # Check if test suite timer expired
  2033. # ----------------------------------------------------
  2034. if ( $proc eq $suite_timeout_proc )
  2035. {
  2036. mtr_report("Test suite timeout! Terminating...");
  2037. exit(1);
  2038. }
  2039. mtr_error("Unhandled process $proc exited");
  2040. }
  2041. mtr_error("Should never come here");
  2042. }
  2043. #
  2044. # Loop through our list of processes and look for and entry
  2045. # with the provided pid, if found check for the file indicating
  2046. # expected crash and restart it.
  2047. #
  2048. sub check_expected_crash_and_restart {
  2049. my ($proc)= @_;
  2050. foreach my $mysqld ( mysqlds() )
  2051. {
  2052. next unless ( $mysqld->{proc} eq $proc );
  2053. # Check if crash expected by looking at the .expect file
  2054. # in var/tmp
  2055. my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
  2056. if ( -f $expect_file )
  2057. {
  2058. mtr_verbose("Crash was expected, file $expect_file exists");
  2059. # Start server with same settings as last time
  2060. mysqld_start($mysqld, $mysqld->{'started_opts'});
  2061. unlink($expect_file);
  2062. }
  2063. return 1;
  2064. }
  2065. # Not an expected crash
  2066. return 0;
  2067. }
  2068. #
  2069. # Save any interesting files in the data_dir
  2070. # before the data dir is removed.
  2071. #
  2072. sub save_files_after_test_failure($$) {
  2073. my $test_name= shift;
  2074. my $data_dir= shift;
  2075. my $save_name= "$opt_vardir/log/$test_name";
  2076. # Look for core files
  2077. foreach my $core_file ( glob("$data_dir/core*") )
  2078. {
  2079. last if $opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core;
  2080. my $core_name= basename($core_file);
  2081. mtr_report(" - saving '$core_name'");
  2082. mkpath($save_name) if ! -d $save_name;
  2083. rename("$core_file", "$save_name/$core_name");
  2084. ++$num_saved_cores;
  2085. }
  2086. }
  2087. sub after_test_failure ($) {
  2088. my $test_name= shift;
  2089. mtr_report("Cleaning datadirs...");
  2090. foreach my $mysqld ( mysqlds() )
  2091. {
  2092. my $data_dir= $mysqld->value('datadir');
  2093. my $name= basename($data_dir);
  2094. save_files_after_test_failure($test_name, $data_dir);
  2095. mtr_debug("Removing '$data_dir'");
  2096. rmtree($data_dir);
  2097. }
  2098. # Remove the ndb_*_fs dirs for all ndbd nodes
  2099. # forcing a clean start of ndb next time
  2100. foreach my $cluster ( clusters() )
  2101. {
  2102. foreach my $ndbd ( ndbds($cluster) )
  2103. {
  2104. my $datadir= $ndbd->value('DataDir');
  2105. foreach my $fs_dir ( glob("$datadir/ndb_*_fs") ) {
  2106. if (-d $fs_dir) {
  2107. rmtree($fs_dir);
  2108. mtr_debug("Removing '$fs_dir'");
  2109. }
  2110. }
  2111. }
  2112. }
  2113. }
  2114. sub report_failure_and_restart ($) {
  2115. my $tinfo= shift;
  2116. mtr_report_test_failed($tinfo, $path_current_testlog);
  2117. print "\n";
  2118. if ( $opt_force )
  2119. {
  2120. # Stop all servers that are known to be running
  2121. stop_all_servers();
  2122. after_test_failure($tinfo->{'name'});
  2123. mtr_report("Resuming tests...\n");
  2124. return;
  2125. }
  2126. mtr_error("Test '$tinfo->{'name'}' failed.",
  2127. "To continue, re-run with '--force'");
  2128. }
  2129. sub run_sh_script {
  2130. my ($script)= @_;
  2131. return 0 unless defined $script;
  2132. mtr_verbose("Running '$script'");
  2133. my $ret= system("/bin/sh $script") >> 8;
  2134. return $ret;
  2135. }
  2136. sub mysqld_stop {
  2137. my $mysqld= shift or die "usage: mysqld_stop(<mysqld>)";
  2138. my $args;
  2139. mtr_init_args(\$args);
  2140. mtr_add_arg($args, "--no-defaults");
  2141. mtr_add_arg($args, "--user=%s", $opt_user);
  2142. mtr_add_arg($args, "--password=");
  2143. mtr_add_arg($args, "--port=%d", $mysqld->value('port'));
  2144. mtr_add_arg($args, "--host=%s", $mysqld->value('#host'));
  2145. mtr_add_arg($args, "--connect_timeout=20");
  2146. mtr_add_arg($args, "--protocol=tcp");
  2147. mtr_add_arg($args, "shutdown");
  2148. My::SafeProcess->run
  2149. (
  2150. name => "mysqladmin shutdown ".$mysqld->name(),
  2151. path => $exe_mysqladmin,
  2152. args => \$args,
  2153. error => "/dev/null",
  2154. );
  2155. }
  2156. sub mysqld_arguments ($$$) {
  2157. my $args= shift;
  2158. my $mysqld= shift;
  2159. my $extra_opts= shift;
  2160. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2161. # When mysqld is run by a root user(euid is 0), it will fail
  2162. # to start unless we specify what user to run as, see BUG#30630
  2163. my $euid= $>;
  2164. if (!IS_WINDOWS and $euid == 0 and
  2165. (grep(/^--user/, @$extra_opts)) == 0) {
  2166. mtr_add_arg($args, "--user=root");
  2167. }
  2168. if ( $opt_valgrind_mysqld )
  2169. {
  2170. mtr_add_arg($args, "--skip-safemalloc");
  2171. if ( $mysql_version_id < 50100 )
  2172. {
  2173. mtr_add_arg($args, "--skip-bdb");
  2174. }
  2175. }
  2176. if ( $mysql_version_id >= 50106 )
  2177. {
  2178. # Turn on logging to both tables and file
  2179. mtr_add_arg($args, "--log-output=table,file");
  2180. }
  2181. # Check if "extra_opt" contains skip-log-bin
  2182. my $skip_binlog= grep(/^(--|--loose-)skip-log-bin/, @$extra_opts);
  2183. # Indicate to mysqld it will be debugged in debugger
  2184. if ( $glob_debugger )
  2185. {
  2186. mtr_add_arg($args, "--gdb");
  2187. }
  2188. my $found_skip_core= 0;
  2189. foreach my $arg ( @$extra_opts )
  2190. {
  2191. # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
  2192. if ($arg eq "--skip-core-file")
  2193. {
  2194. $found_skip_core= 1;
  2195. }
  2196. elsif ($skip_binlog and mtr_match_prefix($arg, "--binlog-format"))
  2197. {
  2198. ; # Dont add --binlog-format when running without binlog
  2199. }
  2200. else
  2201. {
  2202. mtr_add_arg($args, "%s", $arg);
  2203. }
  2204. }
  2205. if ( !$found_skip_core )
  2206. {
  2207. mtr_add_arg($args, "%s", "--core-file");
  2208. }
  2209. return $args;
  2210. }
  2211. sub mysqld_start ($$) {
  2212. my $mysqld= shift;
  2213. my $extra_opts= shift;
  2214. mtr_verbose(My::Options::toStr("mysqld_start", @$extra_opts));
  2215. my $exe= $exe_mysqld;
  2216. my $wait_for_pid_file= 1;
  2217. mtr_error("Internal error: mysqld should never be started for embedded")
  2218. if $opt_embedded_server;
  2219. my $args;
  2220. mtr_init_args(\$args);
  2221. if ( $opt_valgrind_mysqld )
  2222. {
  2223. valgrind_arguments($args, \$exe);
  2224. }
  2225. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  2226. mysqld_arguments($args,$mysqld,$extra_opts);
  2227. if ( $opt_debug )
  2228. {
  2229. mtr_add_arg($args, "--debug=d:t:i:A,%s/log/%s.trace",
  2230. $path_vardir_trace, $mysqld->name());
  2231. }
  2232. if ( $opt_gdb || $opt_manual_gdb )
  2233. {
  2234. gdb_arguments(\$args, \$exe, $mysqld->name());
  2235. }
  2236. elsif ( $opt_ddd || $opt_manual_ddd )
  2237. {
  2238. ddd_arguments(\$args, \$exe, $mysqld->name());
  2239. }
  2240. elsif ( $opt_debugger )
  2241. {
  2242. debugger_arguments(\$args, \$exe, $mysqld->name());
  2243. }
  2244. elsif ( $opt_manual_debug )
  2245. {
  2246. print "\nStart $mysqld->name() in your debugger\n" .
  2247. "dir: $glob_mysql_test_dir\n" .
  2248. "exe: $exe\n" .
  2249. "args: " . join(" ", @$args) . "\n\n" .
  2250. "Waiting ....\n";
  2251. # Indicate the exe should not be started
  2252. $exe= undef;
  2253. }
  2254. else
  2255. {
  2256. # Default to not wait until pid file has been created
  2257. $wait_for_pid_file= 0;
  2258. }
  2259. # Remove the old pidfile if any
  2260. unlink($mysqld->value('pid-file'));
  2261. my $output= $mysqld->value('log-error');
  2262. if ( $opt_valgrind and $opt_debug )
  2263. {
  2264. # When both --valgrind and --debug is selected, send
  2265. # all output to the trace file, making it possible to
  2266. # see the exact location where valgrind complains
  2267. $output= "$opt_vardir/log/".$mysqld->name().".trace";
  2268. }
  2269. if ( defined $exe )
  2270. {
  2271. $mysqld->{'proc'}= My::SafeProcess->new
  2272. (
  2273. name => $mysqld->name(),
  2274. path => $exe,
  2275. args => \$args,
  2276. output => $output,
  2277. error => $output,
  2278. append => 1,
  2279. verbose => $opt_verbose,
  2280. host => undef,
  2281. shutdown => sub { mysqld_stop($mysqld) },
  2282. );
  2283. mtr_verbose("Started $mysqld->{proc}");
  2284. }
  2285. if ( $wait_for_pid_file &&
  2286. !sleep_until_file_created($mysqld->value('pid-file'),
  2287. $opt_start_timeout,
  2288. $mysqld->{'proc'}))
  2289. {
  2290. mtr_error("Failed to start mysqld $mysqld->name()");
  2291. }
  2292. # Remember options used when starting
  2293. $mysqld->{'started_opts'}= $extra_opts;
  2294. return;
  2295. }
  2296. sub stop_all_servers () {
  2297. mtr_report("Stopping all servers...");
  2298. # Kill all started servers
  2299. My::SafeProcess::shutdown(0, # shutdown timeout 0 => kill
  2300. started(all_servers()));
  2301. # Remove pidfiles
  2302. foreach my $server ( all_servers() )
  2303. {
  2304. my $pid_file= $server->if_exist('pid-file');
  2305. unlink($pid_file) if defined $pid_file;
  2306. }
  2307. # Mark servers as stopped
  2308. map($_->{proc}= undef, all_servers());
  2309. }
  2310. # Find out if server should be restarted for this test
  2311. sub server_need_restart {
  2312. my ($tinfo, $server)= @_;
  2313. if ( using_extern() )
  2314. {
  2315. mtr_verbose_restart($server, "no restart for --extern server");
  2316. return 0;
  2317. }
  2318. if ( $opt_embedded_server )
  2319. {
  2320. mtr_verbose_restart($server, "no start or restart for embedded server");
  2321. return 0;
  2322. }
  2323. if ( $tinfo->{'force_restart'} ) {
  2324. mtr_verbose_restart($server, "forced in .opt file");
  2325. return 1;
  2326. }
  2327. if ( $tinfo->{template_path} ne $current_config_name)
  2328. {
  2329. mtr_verbose_restart($server, "using different config file");
  2330. return 1;
  2331. }
  2332. if ( $tinfo->{'master_sh'} || $tinfo->{'slave_sh'} )
  2333. {
  2334. mtr_verbose_restart($server, "sh script to run");
  2335. return 1;
  2336. }
  2337. if ( ! started($server) )
  2338. {
  2339. mtr_verbose_restart($server, "not started");
  2340. return 1;
  2341. }
  2342. my $started_tinfo= $server->{'started_tinfo'};
  2343. if ( defined $started_tinfo )
  2344. {
  2345. # Check if timezone of test that server was started
  2346. # with differs from timezone of next test
  2347. if ( timezone($started_tinfo) ne timezone($tinfo) )
  2348. {
  2349. mtr_verbose_restart($server, "different timezone");
  2350. return 1;
  2351. }
  2352. }
  2353. my $is_mysqld= grep ($server eq $_, mysqlds());
  2354. if ($is_mysqld)
  2355. {
  2356. # Check that running process was started with same options
  2357. # as the current test requires
  2358. my $extra_opts= get_extra_opts($server, $tinfo);
  2359. my $started_opts= $server->{'started_opts'};
  2360. if (!My::Options::same($started_opts, $extra_opts) )
  2361. {
  2362. my $use_dynamic_option_switch= 0;
  2363. if (!$use_dynamic_option_switch)
  2364. {
  2365. mtr_verbose_restart($server, "running with different options '" .
  2366. join(" ", @{$extra_opts}) . "' != '" .
  2367. join(" ", @{$started_opts}) . "'" );
  2368. return 1;
  2369. }
  2370. mtr_verbose(My::Options::toStr("started_opts", @$started_opts));
  2371. mtr_verbose(My::Options::toStr("extra_opts", @$extra_opts));
  2372. # Get diff and check if dynamic switch is possible
  2373. my @diff_opts= My::Options::diff($started_opts, $extra_opts);
  2374. mtr_verbose(My::Options::toStr("diff_opts", @diff_opts));
  2375. my $query= My::Options::toSQL(@diff_opts);
  2376. mtr_verbose("Attempting dynamic switch '$query'");
  2377. if (run_query($tinfo, $server, $query)){
  2378. mtr_verbose("Restart: running with different options '" .
  2379. join(" ", @{$extra_opts}) . "' != '" .
  2380. join(" ", @{$started_opts}) . "'" );
  2381. return 1;
  2382. }
  2383. # Remember the dynamically set options
  2384. $server->{'started_opts'}= $extra_opts;
  2385. }
  2386. }
  2387. # Default, no restart
  2388. return 0;
  2389. }
  2390. sub servers_need_restart($) {
  2391. my ($tinfo)= @_;
  2392. return grep { server_need_restart($tinfo, $_); } all_servers();
  2393. }
  2394. #
  2395. # Return list of specific servers
  2396. # - there is no servers in an empty config
  2397. #
  2398. sub _like { return $config ? $config->like($_[0]) : (); }
  2399. sub mysqlds { return _like('mysqld.'); }
  2400. sub ndbds { return _like('cluster_config.ndbd.');}
  2401. sub ndb_mgmds { return _like('cluster_config.ndb_mgmd.'); }
  2402. sub clusters { return _like('mysql_cluster.'); }
  2403. sub all_servers { return ( mysqlds(), ndb_mgmds(), ndbds() ); }
  2404. #
  2405. # Filter a list of servers and return only those that are part
  2406. # of the specified cluster
  2407. #
  2408. sub in_cluster {
  2409. my ($cluster)= shift;
  2410. # Return only processes for a specific cluster
  2411. return grep { $_->suffix() eq $cluster->suffix() } @_;
  2412. }
  2413. #
  2414. # Filter a list of servers and return the SafeProcess
  2415. # for only those that are started or stopped
  2416. #
  2417. sub started { return grep(defined $_, map($_->{proc}, @_)); }
  2418. sub stopped { return grep(!defined $_, map($_->{proc}, @_)); }
  2419. sub get_extra_opts {
  2420. my ($mysqld, $tinfo)= @_;
  2421. return
  2422. $mysqld->option("#!use-slave-opt") ?
  2423. $tinfo->{slave_opt} : $tinfo->{master_opt};
  2424. }
  2425. sub stop_servers($$) {
  2426. my ($tinfo, @servers)= @_;
  2427. # Remember if we restarted for this test case (count restarts)
  2428. $tinfo->{'restarted'}= 1;
  2429. if ( join('|', @servers) eq join('|', all_servers()) )
  2430. {
  2431. # All servers are going down, use some kind of order to
  2432. # avoid too many warnings in the log files
  2433. mtr_report("Restarting all servers");
  2434. # mysqld processes
  2435. My::SafeProcess::shutdown( $opt_shutdown_timeout, started(mysqlds()) );
  2436. # cluster processes
  2437. My::SafeProcess::shutdown( $opt_shutdown_timeout,
  2438. started(ndbds(), ndb_mgmds()) );
  2439. }
  2440. else
  2441. {
  2442. mtr_report("Restarting ", started(@servers));
  2443. # Stop only some servers
  2444. My::SafeProcess::shutdown( $opt_shutdown_timeout,
  2445. started(@servers) );
  2446. }
  2447. foreach my $server (@servers)
  2448. {
  2449. # Remove datadir
  2450. if ( $server->option('#!remove-datadir') )
  2451. {
  2452. my $datadir= $server->value('datadir');
  2453. mtr_debug("Removing '$datadir'");
  2454. rmtree($datadir);
  2455. }
  2456. # Mark server as stopped
  2457. $server->{proc}= undef;
  2458. # Forget history
  2459. delete $server->{'started_tinfo'};
  2460. delete $server->{'started_opts'};
  2461. delete $server->{'started_cnf'};
  2462. }
  2463. }
  2464. #
  2465. # start_servers
  2466. #
  2467. # Start servers not already started
  2468. #
  2469. # RETURN
  2470. # 0 OK
  2471. # 1 Start failed
  2472. #
  2473. sub start_servers($) {
  2474. my ($tinfo)= @_;
  2475. # Start clusters
  2476. foreach my $cluster ( clusters() )
  2477. {
  2478. ndbcluster_start($cluster);
  2479. }
  2480. # Start mysqlds
  2481. foreach my $mysqld ( mysqlds() )
  2482. {
  2483. if ( $mysqld->{proc} )
  2484. {
  2485. # Already started
  2486. # Write start of testcase to log file
  2487. mark_log($mysqld->value('log-error'), $tinfo);
  2488. next;
  2489. }
  2490. my $datadir= $mysqld->value('datadir');
  2491. # Don't delete anything if starting dirty
  2492. if (!$opt_start_dirty)
  2493. {
  2494. my @options= ('log-bin', 'relay-log');
  2495. foreach my $option_name ( @options ) {
  2496. next unless $mysqld->option($option_name);
  2497. my $value= $mysqld->value($option_name);
  2498. foreach my $file ( glob("$datadir/$value*") )
  2499. {
  2500. #print "removing: $file\n";
  2501. mtr_debug("Removing '$file'");
  2502. unlink($file);
  2503. }
  2504. }
  2505. # Remove old master.info and relay-log.info files
  2506. # from the servers datadir
  2507. unlink("$datadir/master.info");
  2508. unlink("$datadir/relay-log.info");
  2509. }
  2510. # Copy datadir from installed system db
  2511. copy_install_db($datadir) unless -d $datadir;
  2512. # Write start of testcase to log file
  2513. mark_log($mysqld->value('log-error'), $tinfo);
  2514. # Run <tname>-master.sh
  2515. if ($mysqld->option('#!run-master-sh') and
  2516. run_sh_script($tinfo->{master_sh}) )
  2517. {
  2518. $tinfo->{'comment'}= "Failed to execute '$tinfo->{master_sh}'";
  2519. return 1;
  2520. }
  2521. # Run <tname>-slave.sh
  2522. if ($mysqld->option('#!run-slave-sh') and
  2523. run_sh_script($tinfo->{slave_sh}))
  2524. {
  2525. $tinfo->{'comment'}= "Failed to execute '$tinfo->{slave_sh}'";
  2526. return 1;
  2527. }
  2528. if (!$opt_embedded_server)
  2529. {
  2530. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  2531. mysqld_start($mysqld,$extra_opts);
  2532. # Save this test case information, so next can examine it
  2533. $mysqld->{'started_tinfo'}= $tinfo;
  2534. }
  2535. }
  2536. # Wait for clusters to start
  2537. foreach my $cluster ( clusters() )
  2538. {
  2539. if (ndbcluster_wait_started($cluster, ""))
  2540. {
  2541. # failed to start
  2542. $tinfo->{'comment'}= "Start of '".$cluster->name()."' cluster failed";
  2543. return 1;
  2544. }
  2545. }
  2546. # Wait for mysqlds to start
  2547. foreach my $mysqld ( mysqlds() )
  2548. {
  2549. next if !started($mysqld);
  2550. if (sleep_until_file_created($mysqld->value('pid-file'),
  2551. $opt_start_timeout,
  2552. $mysqld->{'proc'}) == 0) {
  2553. $tinfo->{comment}=
  2554. "Failed to start ".$mysqld->name();
  2555. return 1;
  2556. }
  2557. }
  2558. return 0;
  2559. }
  2560. #
  2561. # Run include/check-testcase.test
  2562. # Before a testcase, run in record mode and save result file to var/tmp
  2563. # After testcase, run and compare with the recorded file, they should be equal!
  2564. #
  2565. # RETURN VALUE
  2566. # 0 OK
  2567. # 1 Check failed
  2568. #
  2569. sub run_check_testcase ($$$) {
  2570. my $tinfo= shift;
  2571. my $mode= shift;
  2572. my $mysqld= shift;
  2573. my $name= "check-".$mysqld->name();
  2574. my $tname= $tinfo->{name};
  2575. my $args;
  2576. mtr_init_args(\$args);
  2577. mtr_add_arg($args, "--no-defaults");
  2578. mtr_add_arg($args, "--silent");
  2579. mtr_add_arg($args, "--skip-safemalloc");
  2580. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  2581. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  2582. mtr_add_arg($args, "--socket=%s", $mysqld->value('socket'));
  2583. mtr_add_arg($args, "--port=%d", $mysqld->value('port'));
  2584. mtr_add_arg($args, "--database=test");
  2585. mtr_add_arg($args, "--user=%s", $opt_user);
  2586. mtr_add_arg($args, "--password=");
  2587. mtr_add_arg($args, "--result-file=%s", "$opt_vardir/tmp/$name.result");
  2588. mtr_add_arg($args, "--test-file=%s", "include/check-testcase.test");
  2589. if ( $mode eq "before" )
  2590. {
  2591. mtr_add_arg($args, "--record");
  2592. }
  2593. my $errfile= "$opt_vardir/tmp/$name.err";
  2594. my $res= My::SafeProcess->run
  2595. (
  2596. name => $name,
  2597. path => $exe_mysqltest,
  2598. error => $errfile,
  2599. args => \$args,
  2600. );
  2601. if ( $mode eq "after" and $res == 1 )
  2602. {
  2603. mtr_report("\nThe check of testcase '$tname' failed, this is the\n",
  2604. "diff between before and after:\n");
  2605. # Test failed, display the report mysqltest has created
  2606. mtr_printfile("$opt_vardir/tmp/$name.err");
  2607. }
  2608. elsif ( $res )
  2609. {
  2610. mtr_report("\nCould not execute 'check-testcase' $mode testcase '$tname':");
  2611. mtr_printfile("$opt_vardir/tmp/$name.err");
  2612. mtr_report();
  2613. }
  2614. return $res;
  2615. }
  2616. sub run_mysqltest ($) {
  2617. my $proc= start_mysqltest(@_);
  2618. $proc->wait();
  2619. }
  2620. sub start_mysqltest ($) {
  2621. my ($tinfo)= @_;
  2622. my $exe= $exe_mysqltest;
  2623. my $args;
  2624. mtr_init_args(\$args);
  2625. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2626. mtr_add_arg($args, "--silent");
  2627. mtr_add_arg($args, "--skip-safemalloc");
  2628. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  2629. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  2630. mtr_add_arg($args, "--logdir=%s/log", $opt_vardir);
  2631. # Log line number and time for each line in .test file
  2632. mtr_add_arg($args, "--mark-progress")
  2633. if $opt_mark_progress;
  2634. mtr_add_arg($args, "--database=test");
  2635. if ( $opt_ps_protocol )
  2636. {
  2637. mtr_add_arg($args, "--ps-protocol");
  2638. }
  2639. if ( $opt_sp_protocol )
  2640. {
  2641. mtr_add_arg($args, "--sp-protocol");
  2642. }
  2643. if ( $opt_view_protocol )
  2644. {
  2645. mtr_add_arg($args, "--view-protocol");
  2646. }
  2647. if ( $opt_cursor_protocol )
  2648. {
  2649. mtr_add_arg($args, "--cursor-protocol");
  2650. }
  2651. if ( $opt_strace_client )
  2652. {
  2653. $exe= $opt_strace_client || "strace";
  2654. mtr_add_arg($args, "-o");
  2655. mtr_add_arg($args, "%s/log/mysqltest.strace", $opt_vardir);
  2656. mtr_add_arg($args, "$exe_mysqltest");
  2657. }
  2658. if ( $opt_timer )
  2659. {
  2660. mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
  2661. }
  2662. if ( $opt_compress )
  2663. {
  2664. mtr_add_arg($args, "--compress");
  2665. }
  2666. if ( $opt_sleep )
  2667. {
  2668. mtr_add_arg($args, "--sleep=%d", $opt_sleep);
  2669. }
  2670. client_debug_arg($args, "mysqltest");
  2671. if ( $opt_ssl )
  2672. {
  2673. # Turn on SSL for _all_ test cases if option --ssl was used
  2674. mtr_add_arg($args, "--ssl");
  2675. }
  2676. elsif ( $opt_ssl_supported )
  2677. {
  2678. mtr_add_arg($args, "--skip-ssl");
  2679. }
  2680. if ( $opt_embedded_server )
  2681. {
  2682. # Get the args needed for the embedded server
  2683. # and append them to args prefixed
  2684. # with --sever-arg=
  2685. my $mysqld= $config->group('embedded')
  2686. or mtr_error("Could not get [embedded] section");
  2687. my $mysqld_args;
  2688. mtr_init_args(\$mysqld_args);
  2689. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  2690. mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
  2691. mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
  2692. }
  2693. # ----------------------------------------------------------------------
  2694. # export MYSQL_TEST variable containing <path>/mysqltest <args>
  2695. # ----------------------------------------------------------------------
  2696. $ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
  2697. # ----------------------------------------------------------------------
  2698. # Add arguments that should not go into the MYSQL_TEST env var
  2699. # ----------------------------------------------------------------------
  2700. if ( $opt_valgrind_mysqltest )
  2701. {
  2702. # Prefix the Valgrind options to the argument list.
  2703. # We do this here, since we do not want to Valgrind the nested invocations
  2704. # of mysqltest; that would mess up the stderr output causing test failure.
  2705. my @args_saved = @$args;
  2706. mtr_init_args(\$args);
  2707. valgrind_arguments($args, \$exe);
  2708. mtr_add_arg($args, "%s", $_) for @args_saved;
  2709. }
  2710. mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'});
  2711. # Number of lines of resut to include in failure report
  2712. mtr_add_arg($args, "--tail-lines=20");
  2713. if ( defined $tinfo->{'result_file'} ) {
  2714. mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
  2715. }
  2716. if ( $opt_record )
  2717. {
  2718. mtr_add_arg($args, "--record");
  2719. }
  2720. if ( $opt_client_gdb )
  2721. {
  2722. gdb_arguments(\$args, \$exe, "client");
  2723. }
  2724. elsif ( $opt_client_ddd )
  2725. {
  2726. ddd_arguments(\$args, \$exe, "client");
  2727. }
  2728. elsif ( $opt_client_debugger )
  2729. {
  2730. debugger_arguments(\$args, \$exe, "client");
  2731. }
  2732. my $proc= My::SafeProcess->new
  2733. (
  2734. name => "mysqltest",
  2735. path => $exe,
  2736. args => \$args,
  2737. append => 1,
  2738. error => $path_current_testlog,
  2739. verbose => $opt_verbose,
  2740. );
  2741. mtr_verbose("Started $proc");
  2742. return $proc;
  2743. }
  2744. #
  2745. # Modify the exe and args so that program is run in gdb in xterm
  2746. #
  2747. sub gdb_arguments {
  2748. my $args= shift;
  2749. my $exe= shift;
  2750. my $type= shift;
  2751. # Write $args to gdb init file
  2752. my $str= join(" ", @$$args);
  2753. my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
  2754. # Remove the old gdbinit file
  2755. unlink($gdb_init_file);
  2756. if ( $type eq "client" )
  2757. {
  2758. # write init file for client
  2759. mtr_tofile($gdb_init_file,
  2760. "set args $str\n" .
  2761. "break main\n");
  2762. }
  2763. else
  2764. {
  2765. # write init file for mysqld
  2766. mtr_tofile($gdb_init_file,
  2767. "set args $str\n" .
  2768. "break mysql_parse\n" .
  2769. "commands 1\n" .
  2770. "disable 1\n" .
  2771. "end\n" .
  2772. "run");
  2773. }
  2774. if ( $opt_manual_gdb )
  2775. {
  2776. print "\nTo start gdb for $type, type in another window:\n";
  2777. print "gdb -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  2778. # Indicate the exe should not be started
  2779. $$exe= undef;
  2780. return;
  2781. }
  2782. $$args= [];
  2783. mtr_add_arg($$args, "-title");
  2784. mtr_add_arg($$args, "$type");
  2785. mtr_add_arg($$args, "-e");
  2786. if ( $exe_libtool )
  2787. {
  2788. mtr_add_arg($$args, $exe_libtool);
  2789. mtr_add_arg($$args, "--mode=execute");
  2790. }
  2791. mtr_add_arg($$args, "gdb");
  2792. mtr_add_arg($$args, "-x");
  2793. mtr_add_arg($$args, "$gdb_init_file");
  2794. mtr_add_arg($$args, "$$exe");
  2795. $$exe= "xterm";
  2796. }
  2797. #
  2798. # Modify the exe and args so that program is run in ddd
  2799. #
  2800. sub ddd_arguments {
  2801. my $args= shift;
  2802. my $exe= shift;
  2803. my $type= shift;
  2804. # Write $args to ddd init file
  2805. my $str= join(" ", @$$args);
  2806. my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
  2807. # Remove the old gdbinit file
  2808. unlink($gdb_init_file);
  2809. if ( $type eq "client" )
  2810. {
  2811. # write init file for client
  2812. mtr_tofile($gdb_init_file,
  2813. "set args $str\n" .
  2814. "break main\n");
  2815. }
  2816. else
  2817. {
  2818. # write init file for mysqld
  2819. mtr_tofile($gdb_init_file,
  2820. "file $$exe\n" .
  2821. "set args $str\n" .
  2822. "break mysql_parse\n" .
  2823. "commands 1\n" .
  2824. "disable 1\n" .
  2825. "end");
  2826. }
  2827. if ( $opt_manual_ddd )
  2828. {
  2829. print "\nTo start ddd for $type, type in another window:\n";
  2830. print "ddd -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  2831. # Indicate the exe should not be started
  2832. $$exe= undef;
  2833. return;
  2834. }
  2835. my $save_exe= $$exe;
  2836. $$args= [];
  2837. if ( $exe_libtool )
  2838. {
  2839. $$exe= $exe_libtool;
  2840. mtr_add_arg($$args, "--mode=execute");
  2841. mtr_add_arg($$args, "ddd");
  2842. }
  2843. else
  2844. {
  2845. $$exe= "ddd";
  2846. }
  2847. mtr_add_arg($$args, "--command=$gdb_init_file");
  2848. mtr_add_arg($$args, "$save_exe");
  2849. }
  2850. #
  2851. # Modify the exe and args so that program is run in the selected debugger
  2852. #
  2853. sub debugger_arguments {
  2854. my $args= shift;
  2855. my $exe= shift;
  2856. my $debugger= $opt_debugger || $opt_client_debugger;
  2857. if ( $debugger =~ /vcexpress|vc|devenv/ )
  2858. {
  2859. # vc[express] /debugexe exe arg1 .. argn
  2860. # Add /debugexe and name of the exe before args
  2861. unshift(@$$args, "/debugexe");
  2862. unshift(@$$args, "$$exe");
  2863. # Set exe to debuggername
  2864. $$exe= $debugger;
  2865. }
  2866. elsif ( $debugger =~ /windbg/ )
  2867. {
  2868. # windbg exe arg1 .. argn
  2869. # Add name of the exe before args
  2870. unshift(@$$args, "$$exe");
  2871. # Set exe to debuggername
  2872. $$exe= $debugger;
  2873. }
  2874. elsif ( $debugger eq "dbx" )
  2875. {
  2876. # xterm -e dbx -r exe arg1 .. argn
  2877. unshift(@$$args, $$exe);
  2878. unshift(@$$args, "-r");
  2879. unshift(@$$args, $debugger);
  2880. unshift(@$$args, "-e");
  2881. $$exe= "xterm";
  2882. }
  2883. else
  2884. {
  2885. mtr_error("Unknown argument \"$debugger\" passed to --debugger");
  2886. }
  2887. }
  2888. #
  2889. # Modify the exe and args so that program is run in valgrind
  2890. #
  2891. sub valgrind_arguments {
  2892. my $args= shift;
  2893. my $exe= shift;
  2894. if ( $opt_callgrind)
  2895. {
  2896. mtr_add_arg($args, "--tool=callgrind");
  2897. mtr_add_arg($args, "--base=$opt_vardir/log");
  2898. }
  2899. else
  2900. {
  2901. mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
  2902. mtr_add_arg($args, "--alignment=8");
  2903. mtr_add_arg($args, "--leak-check=yes");
  2904. mtr_add_arg($args, "--num-callers=16");
  2905. mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
  2906. if -f "$glob_mysql_test_dir/valgrind.supp";
  2907. }
  2908. # Add valgrind options, can be overriden by user
  2909. mtr_add_arg($args, '%s', $_) for (@valgrind_args);
  2910. mtr_add_arg($args, $$exe);
  2911. $$exe= $opt_valgrind_path || "valgrind";
  2912. if ($exe_libtool)
  2913. {
  2914. # Add "libtool --mode-execute" before the test to execute
  2915. # if running in valgrind(to avoid valgrinding bash)
  2916. unshift(@$args, "--mode=execute", $$exe);
  2917. $$exe= $exe_libtool;
  2918. }
  2919. }
  2920. #
  2921. # Usage
  2922. #
  2923. sub usage ($) {
  2924. my $message= shift;
  2925. if ( $message )
  2926. {
  2927. print STDERR "$message\n";
  2928. }
  2929. print <<HERE;
  2930. $0 [ OPTIONS ] [ TESTCASE ]
  2931. Options to control what engine/variation to run
  2932. embedded-server Use the embedded server, i.e. no mysqld daemons
  2933. ps-protocol Use the binary protocol between client and server
  2934. cursor-protocol Use the cursor protocol between client and server
  2935. (implies --ps-protocol)
  2936. view-protocol Create a view to execute all non updating queries
  2937. sp-protocol Create a stored procedure to execute all queries
  2938. compress Use the compressed protocol between client and server
  2939. ssl Use ssl protocol between client and server
  2940. skip-ssl Dont start server with support for ssl connections
  2941. ndb|with-ndbcluster Use cluster as default table type
  2942. vs-config Visual Studio configuration used to create executables
  2943. (default: MTR_VS_CONFIG environment variable)
  2944. config|defaults-file=<config template> Use fixed config template for all
  2945. tests
  2946. extra_defaults_file=<config template> Extra config template to add to
  2947. all generated configs
  2948. Options to control directories to use
  2949. tmpdir=DIR The directory where temporary files are stored
  2950. (default: ./var/tmp).
  2951. vardir=DIR The directory where files generated from the test run
  2952. is stored (default: ./var). Specifying a ramdisk or
  2953. tmpfs will speed up tests.
  2954. mem Run testsuite in "memory" using tmpfs or ramdisk
  2955. Attempts to find a suitable location
  2956. using a builtin list of standard locations
  2957. for tmpfs (/dev/shm)
  2958. The option can also be set using environment
  2959. variable MTR_MEM=[DIR]
  2960. Options to control what test suites or cases to run
  2961. force Continue to run the suite after failure
  2962. with-ndbcluster-only Run only tests that include "ndb" in the filename
  2963. skip-ndb[cluster] Skip all tests that need cluster
  2964. skip-ndb[cluster]-slave Skip all tests that need a slave cluster
  2965. ndb-extra Run extra tests from ndb directory
  2966. do-test=PREFIX or REGEX
  2967. Run test cases which name are prefixed with PREFIX
  2968. or fulfills REGEX
  2969. skip-test=PREFIX or REGEX
  2970. Skip test cases which name are prefixed with PREFIX
  2971. or fulfills REGEX
  2972. start-from=PREFIX Run test cases starting test prefixed with PREFIX where
  2973. prefix may be suite.testname or just testname
  2974. suite[s]=NAME1,..,NAMEN
  2975. Collect tests in suites from the comma separated
  2976. list of suite names.
  2977. The default is: "$opt_suites"
  2978. skip-rpl Skip the replication test cases.
  2979. big-test Set the environment variable BIG_TEST, which can be
  2980. checked from test cases.
  2981. Options that specify ports
  2982. mtr-build-thread=# Specify unique number to calculate port number(s) from.
  2983. build-thread=# Can be set in environment variable MTR_BUILD_THREAD.
  2984. Set MTR_BUILD_THREAD="auto" to automatically aquire
  2985. a build thread id that is unique to current host
  2986. Options for test case authoring
  2987. record TESTNAME (Re)genereate the result file for TESTNAME
  2988. check-testcases Check testcases for sideeffects
  2989. mark-progress Log line number and elapsed time to <testname>.progress
  2990. Options that pass on options
  2991. mysqld=ARGS Specify additional arguments to "mysqld"
  2992. Options to run test on running server
  2993. extern option=value Run only the tests against an already started server
  2994. the options to use for connection to the extern server
  2995. must be specified using name-value pair notation
  2996. For example:
  2997. ./$0 --extern socket=/tmp/mysqld.sock
  2998. user=USER User for connection to extern server
  2999. socket=PATH Socket for connection to extern server
  3000. Options for debugging the product
  3001. client-ddd Start mysqltest client in ddd
  3002. client-debugger=NAME Start mysqltest in the selected debugger
  3003. client-gdb Start mysqltest client in gdb
  3004. ddd Start mysqld in ddd
  3005. debug Dump trace output for all servers and client programs
  3006. debugger=NAME Start mysqld in the selected debugger
  3007. gdb Start the mysqld(s) in gdb
  3008. manual-debug Let user manually start mysqld in debugger, before
  3009. running test(s)
  3010. manual-gdb Let user manually start mysqld in gdb, before running
  3011. test(s)
  3012. manual-ddd Let user manually start mysqld in ddd, before running
  3013. test(s)
  3014. strace-client=[path] Create strace output for mysqltest client, optionally
  3015. specifying name and path to the trace program to use.
  3016. Example: $0 --strace-client=ktrace
  3017. max-save-core Limit the number of core files saved (to avoid filling
  3018. up disks for heavily crashing server). Defaults to
  3019. $opt_max_save_core, set to 0 for no limit.
  3020. Options for valgrind
  3021. valgrind Run the "mysqltest" and "mysqld" executables using
  3022. valgrind with default options
  3023. valgrind-all Synonym for --valgrind
  3024. valgrind-mysqltest Run the "mysqltest" and "mysql_client_test" executable
  3025. with valgrind
  3026. valgrind-mysqld Run the "mysqld" executable with valgrind
  3027. valgrind-options=ARGS Deprecated, use --valgrind-option
  3028. valgrind-option=ARGS Option to give valgrind, replaces default option(s),
  3029. can be specified more then once
  3030. valgrind-path=[EXE] Path to the valgrind executable
  3031. callgrind Instruct valgrind to use callgrind
  3032. Misc options
  3033. comment=STR Write STR to the output
  3034. notimer Don't show test case execution time
  3035. verbose More verbose output(use multiple times for even more)
  3036. start Only initialize and start the servers, using the
  3037. startup settings for the first specified test case
  3038. Example:
  3039. $0 --start alias &
  3040. start-dirty Only start the servers (without initialization) for
  3041. the first specified test case
  3042. fast Run as fast as possible, dont't wait for servers
  3043. to shutdown etc.
  3044. repeat=N Run each test N number of times
  3045. retry=N Retry tests that fail N times, limit number of failures
  3046. to $opt_retry_failure
  3047. retry-failure=N Limit number of retries for a failed test
  3048. reorder Reorder tests to get fewer server restarts
  3049. help Get this help text
  3050. testcase-timeout=MINUTES Max test case run time (default $opt_testcase_timeout)
  3051. suite-timeout=MINUTES Max test suite run time (default $opt_suite_timeout)
  3052. shutdown-timeout=SECONDS Max number of seconds to wait for server shutdown
  3053. before killing servers (default $opt_shutdown_timeout)
  3054. warnings Scan the log files for warnings. Use --nowarnings
  3055. to turn off.
  3056. sleep=SECONDS Passed to mysqltest, will be used as fixed sleep time
  3057. HERE
  3058. exit(1);
  3059. }