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-1335 USA 17 18# This is a library file used by the Perl version of mysql-test-run, 19# and is part of the translation of the Bourne shell script with the 20# same name. 21 22use strict; 23use File::Spec; 24 25# These are not to be prefixed with "mtr_" 26 27sub run_stress_test (); 28 29############################################################################## 30# 31# Run tests in the stress mode 32# 33############################################################################## 34 35sub run_stress_test () 36{ 37 38 my $args; 39 my $stress_suitedir; 40 41 mtr_report("Starting stress testing\n"); 42 43 if ( ! $::glob_use_embedded_server ) 44 { 45 if ( ! mysqld_start($::master->[0],[],[]) ) 46 { 47 mtr_error("Can't start the mysqld server"); 48 } 49 } 50 51 my $stress_basedir=File::Spec->catdir($::opt_vardir, "stress"); 52 53 #Clean up stress dir 54 if ( -d $stress_basedir ) 55 { 56 rmtree($stress_basedir); 57 } 58 mkpath($stress_basedir); 59 60 if ($::opt_stress_suite ne 'main' && $::opt_stress_suite ne 'default' ) 61 { 62 $stress_suitedir=File::Spec->catdir($::glob_mysql_test_dir, "suite", 63 $::opt_stress_suite); 64 } 65 else 66 { 67 $stress_suitedir=$::glob_mysql_test_dir; 68 } 69 70 if ( -d $stress_suitedir ) 71 { 72 #$stress_suite_t_dir=File::Spec->catdir($stress_suitedir, "t"); 73 #$stress_suite_r_dir=File::Spec->catdir($stress_suitedir, "r"); 74 #FIXME: check dirs above for existence to ensure that test suite 75 # contains tests and results dirs 76 } 77 else 78 { 79 mtr_error("Specified test suite $::opt_stress_suite doesn't exist"); 80 } 81 82 if ( @::opt_cases ) 83 { 84 $::opt_stress_test_file=File::Spec->catfile($stress_basedir, "stress_tests.txt"); 85 open(STRESS_FILE, ">$::opt_stress_test_file"); 86 print STRESS_FILE join("\n",@::opt_cases),"\n"; 87 close(STRESS_FILE); 88 } 89 elsif ( $::opt_stress_test_file ) 90 { 91 $::opt_stress_test_file=File::Spec->catfile($stress_suitedir, 92 $::opt_stress_test_file); 93 if ( ! -f $::opt_stress_test_file ) 94 { 95 mtr_error("Specified file $::opt_stress_test_file with list of tests does not exist\n", 96 "Please ensure that file exists and has proper permissions"); 97 } 98 } 99 else 100 { 101 $::opt_stress_test_file=File::Spec->catfile($stress_suitedir, 102 "stress_tests.txt"); 103 if ( ! -f $::opt_stress_test_file ) 104 { 105 mtr_error("Default file $::opt_stress_test_file with list of tests does not exist\n", 106 "Please use --stress-test-file option to specify custom one or you can\n", 107 "just specify name of test for testing as last argument in command line"); 108 109 } 110 } 111 112 if ( $::opt_stress_init_file ) 113 { 114 $::opt_stress_init_file=File::Spec->catfile($stress_suitedir, 115 $::opt_stress_init_file); 116 if ( ! -f $::opt_stress_init_file ) 117 { 118 mtr_error("Specified file $::opt_stress_init_file with list of tests does not exist\n", 119 "Please ensure that file exists and has proper permissions"); 120 } 121 } 122 else 123 { 124 $::opt_stress_init_file=File::Spec->catfile($stress_suitedir, 125 "stress_init.txt"); 126 if ( ! -f $::opt_stress_init_file ) 127 { 128 $::opt_stress_init_file=''; 129 } 130 } 131 132 if ( $::opt_stress_mode ne 'random' && $::opt_stress_mode ne 'seq' ) 133 { 134 mtr_error("You specified wrong mode $::opt_stress_mode for stress test\n", 135 "Correct values are 'random' or 'seq'"); 136 } 137 138 mtr_init_args(\$args); 139 mtr_add_args($args, "$::glob_mysql_test_dir/mysql-stress-test.pl"); 140 mtr_add_arg($args, "--server-socket=%s", $::master->[0]->{'path_sock'}); 141 mtr_add_arg($args, "--server-user=%s", $::opt_user); 142 mtr_add_arg($args, "--server-database=%s", "test"); 143 mtr_add_arg($args, "--stress-suite-basedir=%s", $::glob_mysql_test_dir); 144 mtr_add_arg($args, "--suite=%s", $::opt_stress_suite); 145 mtr_add_arg($args, "--stress-tests-file=%s", $::opt_stress_test_file); 146 mtr_add_arg($args, "--stress-basedir=%s", $stress_basedir); 147 mtr_add_arg($args, "--server-logs-dir=%s", $stress_basedir); 148 mtr_add_arg($args, "--stress-mode=%s", $::opt_stress_mode); 149 mtr_add_arg($args, "--mysqltest=%s", $::exe_mysqltest); 150 mtr_add_arg($args, "--threads=%s", $::opt_stress_threads); 151 mtr_add_arg($args, "--verbose"); 152 mtr_add_arg($args, "--cleanup"); 153 mtr_add_arg($args, "--log-error-details"); 154 mtr_add_arg($args, "--abort-on-error=1"); 155 156 if ( $::opt_stress_init_file ) 157 { 158 mtr_add_arg($args, "--stress-init-file=%s", $::opt_stress_init_file); 159 } 160 161 if ( !$::opt_stress_loop_count && !$::opt_stress_test_count && 162 !$::opt_stress_test_duration ) 163 { 164 #Limit stress testing with 20 loops in case when any limit parameter 165 #was specified 166 $::opt_stress_test_count=20; 167 } 168 169 if ( $::opt_stress_loop_count ) 170 { 171 mtr_add_arg($args, "--loop-count=%s", $::opt_stress_loop_count); 172 } 173 174 if ( $::opt_stress_test_count ) 175 { 176 mtr_add_arg($args, "--test-count=%s", $::opt_stress_test_count); 177 } 178 179 if ( $::opt_stress_test_duration ) 180 { 181 mtr_add_arg($args, "--test-duration=%s", $::opt_stress_test_duration); 182 } 183 184 #Run stress test 185 My::SafeProcess->run 186 ( 187 name => "stress test", 188 path => $^X, 189 args => \$args, 190 ); 191 192 if ( ! $::glob_use_embedded_server ) 193 { 194 stop_all_servers(); 195 } 196} 197 1981; 199