|
| 1 | +# -*- cperl -*- |
| 2 | + |
| 3 | +# This is a library file used by the Perl version of mysql-test-run, |
| 4 | +# and is part of the translation of the Bourne shell script with the |
| 5 | +# same name. |
| 6 | + |
| 7 | +use strict; |
| 8 | +use File::Spec; |
| 9 | + |
| 10 | +# These are not to be prefixed with "mtr_" |
| 11 | + |
| 12 | +sub run_stress_test (); |
| 13 | + |
| 14 | +############################################################################## |
| 15 | +# |
| 16 | +# Run tests in the stress mode |
| 17 | +# |
| 18 | +############################################################################## |
| 19 | + |
| 20 | +sub run_stress_test () |
| 21 | +{ |
| 22 | + |
| 23 | + my $args; |
| 24 | + my $stress_basedir; |
| 25 | + my $stress_suitedir; |
| 26 | + |
| 27 | + mtr_report("Starting stress testing\n"); |
| 28 | + |
| 29 | + if ( ! $::glob_use_embedded_server and ! $::opt_local_master ) |
| 30 | + { |
| 31 | + $::master->[0]->{'pid'}= mysqld_start('master',0,[],[]); |
| 32 | + if ( ! $::master->[0]->{'pid'} ) |
| 33 | + { |
| 34 | + mtr_error("Can't start the mysqld server"); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + my $stress_basedir=File::Spec->catdir($::opt_vardir, "stress"); |
| 39 | + |
| 40 | + #Clean up stress dir |
| 41 | + if ( -d $stress_basedir ) |
| 42 | + { |
| 43 | + rmtree($stress_basedir); |
| 44 | + } |
| 45 | + mkpath($stress_basedir); |
| 46 | + |
| 47 | + if ($::opt_stress_suite ne 'main' && $::opt_stress_suite ne 'default' ) |
| 48 | + { |
| 49 | + $stress_suitedir=File::Spec->catdir($::glob_mysql_test_dir, "suite", |
| 50 | + $::opt_stress_suite); |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + $stress_suitedir=$::glob_mysql_test_dir; |
| 55 | + } |
| 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 | + |
| 69 | + if ( @::opt_cases ) |
| 70 | + { |
| 71 | + $::opt_stress_test_file=File::Spec->catfile($stress_basedir, "stress_tests.txt"); |
| 72 | + open(STRESS_FILE, ">$::opt_stress_test_file"); |
| 73 | + print STRESS_FILE join("\n",@::opt_cases),"\n"; |
| 74 | + close(STRESS_FILE); |
| 75 | + } |
| 76 | + elsif ( $::opt_stress_test_file ) |
| 77 | + { |
| 78 | + $::opt_stress_test_file=File::Spec->catfile($stress_suitedir, |
| 79 | + $::opt_stress_test_file); |
| 80 | + if ( ! -f $::opt_stress_test_file ) |
| 81 | + { |
| 82 | + mtr_error("Specified file $::opt_stress_test_file with list of tests does not exist\n", |
| 83 | + "Please ensure that file exists and has proper permissions"); |
| 84 | + } |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + $::opt_stress_test_file=File::Spec->catfile($stress_suitedir, |
| 89 | + "stress_tests.txt"); |
| 90 | + if ( ! -f $::opt_stress_test_file ) |
| 91 | + { |
| 92 | + mtr_error("Default file $::opt_stress_test_file with list of tests does not exist\n", |
| 93 | + "Please use --stress-test-file option to specify custom one or you can\n", |
| 94 | + "just specify name of test for testing as last argument in command line"); |
| 95 | + |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + if ( $::opt_stress_init_file ) |
| 100 | + { |
| 101 | + $::opt_stress_init_file=File::Spec->catfile($stress_suitedir, |
| 102 | + $::opt_stress_init_file); |
| 103 | + if ( ! -f $::opt_stress_init_file ) |
| 104 | + { |
| 105 | + mtr_error("Specified file $::opt_stress_init_file with list of tests does not exist\n", |
| 106 | + "Please ensure that file exists and has proper permissions"); |
| 107 | + } |
| 108 | + } |
| 109 | + else |
| 110 | + { |
| 111 | + $::opt_stress_init_file=File::Spec->catfile($stress_suitedir, |
| 112 | + "stress_init.txt"); |
| 113 | + if ( ! -f $::opt_stress_init_file ) |
| 114 | + { |
| 115 | + $::opt_stress_init_file=''; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + if ( $::opt_stress_mode ne 'random' && $::opt_stress_mode ne 'seq' ) |
| 120 | + { |
| 121 | + mtr_error("You specified wrong mode $::opt_stress_mode for stress test\n", |
| 122 | + "Correct values are 'random' or 'seq'"); |
| 123 | + } |
| 124 | + |
| 125 | + mtr_init_args(\$args); |
| 126 | + |
| 127 | + mtr_add_arg($args, "--server-socket=%s", $::master->[0]->{'path_mysock'}); |
| 128 | + mtr_add_arg($args, "--server-user=%s", $::opt_user); |
| 129 | + mtr_add_arg($args, "--server-database=%s", "test"); |
| 130 | + mtr_add_arg($args, "--stress-suite-basedir=%s", $::glob_mysql_test_dir); |
| 131 | + mtr_add_arg($args, "--suite=%s", $::opt_stress_suite); |
| 132 | + mtr_add_arg($args, "--stress-tests-file=%s", $::opt_stress_test_file); |
| 133 | + mtr_add_arg($args, "--stress-basedir=%s", $stress_basedir); |
| 134 | + mtr_add_arg($args, "--server-logs-dir=%s", $stress_basedir); |
| 135 | + mtr_add_arg($args, "--stress-mode=%s", $::opt_stress_mode); |
| 136 | + mtr_add_arg($args, "--mysqltest=%s", $::exe_mysqltest); |
| 137 | + mtr_add_arg($args, "--threads=%s", $::opt_stress_threads); |
| 138 | + mtr_add_arg($args, "--verbose"); |
| 139 | + mtr_add_arg($args, "--cleanup"); |
| 140 | + mtr_add_arg($args, "--log-error-details"); |
| 141 | + mtr_add_arg($args, "--abort-on-error"); |
| 142 | + |
| 143 | + if ( $::opt_stress_init_file ) |
| 144 | + { |
| 145 | + mtr_add_arg($args, "--stress-init-file=%", $::opt_stress_init_file); |
| 146 | + } |
| 147 | + |
| 148 | + if ( $::opt_stress_loop_count ) |
| 149 | + { |
| 150 | + mtr_add_arg($args, "--loop-count=%s", $::opt_stress_loop_count); |
| 151 | + } |
| 152 | + |
| 153 | + if ( $::opt_stress_test_count ) |
| 154 | + { |
| 155 | + mtr_add_arg($args, "--test-count=%s", $::opt_stress_test_count); |
| 156 | + } |
| 157 | + |
| 158 | + if ( $::opt_stress_test_duration ) |
| 159 | + { |
| 160 | + mtr_add_arg($args, "--test-duration=%s", $::opt_stress_test_duration); |
| 161 | + } |
| 162 | + |
| 163 | + #Run stress test |
| 164 | + mtr_run("$::glob_mysql_test_dir/mysql-stress-test.pl", $args, "", "", "", ""); |
| 165 | + |
| 166 | + if ( ! $::glob_use_embedded_server ) |
| 167 | + { |
| 168 | + stop_masters(); |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +1; |
0 commit comments