mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / lib / mtr_stress.pl
blob6ab607e643958aeffc87c333fe1b56b5c8e602cd
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.
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
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.
22 use strict;
23 use File::Spec;
25 # These are not to be prefixed with "mtr_"
27 sub run_stress_test ();
29 ##############################################################################
31 # Run tests in the stress mode
33 ##############################################################################
35 sub run_stress_test ()
38 my $args;
39 my $stress_suitedir;
41 mtr_report("Starting stress testing\n");
43 if ( ! $::glob_use_embedded_server )
45 if ( ! mysqld_start($::master->[0],[],[]) )
47 mtr_error("Can't start the mysqld server");
51 my $stress_basedir=File::Spec->catdir($::opt_vardir, "stress");
53 #Clean up stress dir
54 if ( -d $stress_basedir )
56 rmtree($stress_basedir);
58 mkpath($stress_basedir);
60 if ($::opt_stress_suite ne 'main' && $::opt_stress_suite ne 'default' )
62 $stress_suitedir=File::Spec->catdir($::glob_mysql_test_dir, "suite",
63 $::opt_stress_suite);
65 else
67 $stress_suitedir=$::glob_mysql_test_dir;
70 if ( -d $stress_suitedir )
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
77 else
79 mtr_error("Specified test suite $::opt_stress_suite doesn't exist");
82 if ( @::opt_cases )
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);
89 elsif ( $::opt_stress_test_file )
91 $::opt_stress_test_file=File::Spec->catfile($stress_suitedir,
92 $::opt_stress_test_file);
93 if ( ! -f $::opt_stress_test_file )
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");
99 else
101 $::opt_stress_test_file=File::Spec->catfile($stress_suitedir,
102 "stress_tests.txt");
103 if ( ! -f $::opt_stress_test_file )
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");
112 if ( $::opt_stress_init_file )
114 $::opt_stress_init_file=File::Spec->catfile($stress_suitedir,
115 $::opt_stress_init_file);
116 if ( ! -f $::opt_stress_init_file )
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");
122 else
124 $::opt_stress_init_file=File::Spec->catfile($stress_suitedir,
125 "stress_init.txt");
126 if ( ! -f $::opt_stress_init_file )
128 $::opt_stress_init_file='';
132 if ( $::opt_stress_mode ne 'random' && $::opt_stress_mode ne 'seq' )
134 mtr_error("You specified wrong mode $::opt_stress_mode for stress test\n",
135 "Correct values are 'random' or 'seq'");
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");
156 if ( $::opt_stress_init_file )
158 mtr_add_arg($args, "--stress-init-file=%s", $::opt_stress_init_file);
161 if ( !$::opt_stress_loop_count && !$::opt_stress_test_count &&
162 !$::opt_stress_test_duration )
164 #Limit stress testing with 20 loops in case when any limit parameter
165 #was specified
166 $::opt_stress_test_count=20;
169 if ( $::opt_stress_loop_count )
171 mtr_add_arg($args, "--loop-count=%s", $::opt_stress_loop_count);
174 if ( $::opt_stress_test_count )
176 mtr_add_arg($args, "--test-count=%s", $::opt_stress_test_count);
179 if ( $::opt_stress_test_duration )
181 mtr_add_arg($args, "--test-duration=%s", $::opt_stress_test_duration);
184 #Run stress test
185 My::SafeProcess->run
187 name => "stress test",
188 path => $^X,
189 args => \$args,
192 if ( ! $::glob_use_embedded_server )
194 stop_all_servers();