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.

198 lines
6.1 KiB

  1. # -*- cperl -*-
  2. # Copyright (c) 2004-2007 MySQL AB, 2009 Sun Microsystems, Inc.
  3. # Use is subject to license terms.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; version 2 of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. # This is a library file used by the Perl version of mysql-test-run,
  18. # and is part of the translation of the Bourne shell script with the
  19. # same name.
  20. use strict;
  21. use File::Spec;
  22. # These are not to be prefixed with "mtr_"
  23. sub run_stress_test ();
  24. ##############################################################################
  25. #
  26. # Run tests in the stress mode
  27. #
  28. ##############################################################################
  29. sub run_stress_test ()
  30. {
  31. my $args;
  32. my $stress_suitedir;
  33. mtr_report("Starting stress testing\n");
  34. if ( ! $::glob_use_embedded_server )
  35. {
  36. if ( ! mysqld_start($::master->[0],[],[]) )
  37. {
  38. mtr_error("Can't start the mysqld server");
  39. }
  40. }
  41. my $stress_basedir=File::Spec->catdir($::opt_vardir, "stress");
  42. #Clean up stress dir
  43. if ( -d $stress_basedir )
  44. {
  45. rmtree($stress_basedir);
  46. }
  47. mkpath($stress_basedir);
  48. if ($::opt_stress_suite ne 'main' && $::opt_stress_suite ne 'default' )
  49. {
  50. $stress_suitedir=File::Spec->catdir($::glob_mysql_test_dir, "suite",
  51. $::opt_stress_suite);
  52. }
  53. else
  54. {
  55. $stress_suitedir=$::glob_mysql_test_dir;
  56. }
  57. if ( -d $stress_suitedir )
  58. {
  59. #$stress_suite_t_dir=File::Spec->catdir($stress_suitedir, "t");
  60. #$stress_suite_r_dir=File::Spec->catdir($stress_suitedir, "r");
  61. #FIXME: check dirs above for existence to ensure that test suite
  62. # contains tests and results dirs
  63. }
  64. else
  65. {
  66. mtr_error("Specified test suite $::opt_stress_suite doesn't exist");
  67. }
  68. if ( @::opt_cases )
  69. {
  70. $::opt_stress_test_file=File::Spec->catfile($stress_basedir, "stress_tests.txt");
  71. open(STRESS_FILE, ">$::opt_stress_test_file");
  72. print STRESS_FILE join("\n",@::opt_cases),"\n";
  73. close(STRESS_FILE);
  74. }
  75. elsif ( $::opt_stress_test_file )
  76. {
  77. $::opt_stress_test_file=File::Spec->catfile($stress_suitedir,
  78. $::opt_stress_test_file);
  79. if ( ! -f $::opt_stress_test_file )
  80. {
  81. mtr_error("Specified file $::opt_stress_test_file with list of tests does not exist\n",
  82. "Please ensure that file exists and has proper permissions");
  83. }
  84. }
  85. else
  86. {
  87. $::opt_stress_test_file=File::Spec->catfile($stress_suitedir,
  88. "stress_tests.txt");
  89. if ( ! -f $::opt_stress_test_file )
  90. {
  91. mtr_error("Default file $::opt_stress_test_file with list of tests does not exist\n",
  92. "Please use --stress-test-file option to specify custom one or you can\n",
  93. "just specify name of test for testing as last argument in command line");
  94. }
  95. }
  96. if ( $::opt_stress_init_file )
  97. {
  98. $::opt_stress_init_file=File::Spec->catfile($stress_suitedir,
  99. $::opt_stress_init_file);
  100. if ( ! -f $::opt_stress_init_file )
  101. {
  102. mtr_error("Specified file $::opt_stress_init_file with list of tests does not exist\n",
  103. "Please ensure that file exists and has proper permissions");
  104. }
  105. }
  106. else
  107. {
  108. $::opt_stress_init_file=File::Spec->catfile($stress_suitedir,
  109. "stress_init.txt");
  110. if ( ! -f $::opt_stress_init_file )
  111. {
  112. $::opt_stress_init_file='';
  113. }
  114. }
  115. if ( $::opt_stress_mode ne 'random' && $::opt_stress_mode ne 'seq' )
  116. {
  117. mtr_error("You specified wrong mode $::opt_stress_mode for stress test\n",
  118. "Correct values are 'random' or 'seq'");
  119. }
  120. mtr_init_args(\$args);
  121. mtr_add_args($args, "$::glob_mysql_test_dir/mysql-stress-test.pl");
  122. mtr_add_arg($args, "--server-socket=%s", $::master->[0]->{'path_sock'});
  123. mtr_add_arg($args, "--server-user=%s", $::opt_user);
  124. mtr_add_arg($args, "--server-database=%s", "test");
  125. mtr_add_arg($args, "--stress-suite-basedir=%s", $::glob_mysql_test_dir);
  126. mtr_add_arg($args, "--suite=%s", $::opt_stress_suite);
  127. mtr_add_arg($args, "--stress-tests-file=%s", $::opt_stress_test_file);
  128. mtr_add_arg($args, "--stress-basedir=%s", $stress_basedir);
  129. mtr_add_arg($args, "--server-logs-dir=%s", $stress_basedir);
  130. mtr_add_arg($args, "--stress-mode=%s", $::opt_stress_mode);
  131. mtr_add_arg($args, "--mysqltest=%s", $::exe_mysqltest);
  132. mtr_add_arg($args, "--threads=%s", $::opt_stress_threads);
  133. mtr_add_arg($args, "--verbose");
  134. mtr_add_arg($args, "--cleanup");
  135. mtr_add_arg($args, "--log-error-details");
  136. mtr_add_arg($args, "--abort-on-error=1");
  137. if ( $::opt_stress_init_file )
  138. {
  139. mtr_add_arg($args, "--stress-init-file=%s", $::opt_stress_init_file);
  140. }
  141. if ( !$::opt_stress_loop_count && !$::opt_stress_test_count &&
  142. !$::opt_stress_test_duration )
  143. {
  144. #Limit stress testing with 20 loops in case when any limit parameter
  145. #was specified
  146. $::opt_stress_test_count=20;
  147. }
  148. if ( $::opt_stress_loop_count )
  149. {
  150. mtr_add_arg($args, "--loop-count=%s", $::opt_stress_loop_count);
  151. }
  152. if ( $::opt_stress_test_count )
  153. {
  154. mtr_add_arg($args, "--test-count=%s", $::opt_stress_test_count);
  155. }
  156. if ( $::opt_stress_test_duration )
  157. {
  158. mtr_add_arg($args, "--test-duration=%s", $::opt_stress_test_duration);
  159. }
  160. #Run stress test
  161. My::SafeProcess->run
  162. (
  163. name => "stress test",
  164. path => $^X,
  165. args => \$args,
  166. );
  167. if ( ! $::glob_use_embedded_server )
  168. {
  169. stop_all_servers();
  170. }
  171. }
  172. 1;