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