1
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
31
use GenTest::Properties;
32
use GenTest::Constants;
33
use GenTest::Simplifier::Mysqltest;
36
# NOTE: oracle function behaves differently if basedir2 is specified in addition
37
# to basedir. In this case expected_mtr_output is ignored, and result
38
# comparison between servers is performed instead.
41
my $o = GetOptions($options,
46
'expected_mtr_output=s',
50
my $config = GenTest::Properties->new(
57
'expected_mtr_output',
72
$config->printHelp if not $o;
75
my $header = $config->header() || [];
76
my $footer = $config->footer() || [];
78
# End of user-configurable section
83
say("run_id = $run_id");
85
my $simplifier = GenTest::Simplifier::Mysqltest->new(
86
filter => $config->filter(),
87
use_connections => $config->use_connections(),
89
my $oracle_mysqltest = shift;
92
chdir($config->basedir.'/mysql-test'); # assume forward slash works
94
my $testfile_base_name = $run_id.'-'.$iteration; # we need this for both test- and result file name
95
my $testfile = $testfile_base_name.'.test'; # test file of this iteration
96
my $resultfile = $testfile_base_name.'.result'; # test file of this iteration
98
open (ORACLE_MYSQLTEST, ">t/$testfile") or croak "Unable to open $testfile: $!";
100
print ORACLE_MYSQLTEST join("\n",@{$header})."\n\n";
101
print ORACLE_MYSQLTEST $oracle_mysqltest;
102
print ORACLE_MYSQLTEST "\n\n".join("\n",@{$footer})."\n";
103
close ORACLE_MYSQLTEST;
105
my $mysqldopt = $config->genOpt('--mysqld=--', 'mysqld');
106
my $mtr_start_time = Time::HiRes::time();
107
my $mysqltest_cmd = "perl mysql-test-run.pl $mysqldopt ". $config->genOpt('--', 'mtr_options')." t/$testfile 2>&1";
108
my $mysqltest_output = `$mysqltest_cmd`;
109
my $mtr_exit_code = $? >> 8;
110
my $mtr_duration = Time::HiRes::time() - $mtr_start_time;
111
if ($iteration == 1) {
112
say ($mysqltest_output);
114
say ("MTR test duration: $mtr_duration; exit_code: $mtr_exit_code");
117
system("grep 'Unsafe statement binlogged' ".$config->basedir()."/mysql-test/var/log/mysqld.1.err");
118
my $grep_exit_code = $? >> 8;
119
if ($grep_exit_code == 0) {
120
say("Messages about unsafe replication found in master error log.");
121
return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
122
} elsif ($grep_exit_code > 1) {
123
say("grep on the mysqld.1.err error log failed");
126
########################################################################
127
# Start of comparison mode (two basedirs)
128
########################################################################
130
if (defined $config->basedir2) {
131
if ($iteration == 1) {
132
say ('Two basedirs specified. Will compare outputs instead of looking for expected output.');
133
say ('Server A: '.$config->basedir);
134
say ('Server B: '.$config->basedir2);
135
# NOTE: --record MTR option is required. TODO: Check for this?
139
# Run the test against basedir2 and compare results against the previous run.
142
chdir($config->basedir2.'/mysql-test');
144
# working dir is now for Server B, so we need full path to Server A's files for later
145
my $testfile_full_path = $config->basedir.'/mysql-test/t/'.$testfile;
146
my $resultfile_full_path = $config->basedir.'/mysql-test/r/'.$testfile_base_name.'.result';
148
# tests/results for Server B include "-b" in the filename
149
my $testfile2_base_name = $run_id.'-'.$iteration.'-b';
150
my $testfile2 = $testfile2_base_name.'.test';
151
my $testfile2_full_path = $config->basedir2.'/mysql-test/t/'.$testfile2;
152
my $resultfile2_full_path = $config->basedir2.'/mysql-test/r/'.$testfile2_base_name.'.result';
154
# Copy test file to server B
155
copy($testfile_full_path, $testfile2_full_path) or croak("Unable to copy test file $testfile to $testfile2");
158
"perl mysql-test-run.pl $mysqldopt ". $config->genOpt('--', 'mtr_options').
161
# Run the test against server B
162
# we don't really use this output for anything right now
163
my $mysqltest_output2 = `$mysqltest_cmd2`;
164
#say $mysqltest_output2 if $iteration == 1;
167
# Compare the two results
168
# We declare the tests to have failed properly only if the results
169
# from the two test runs differ.
170
# (We ignore expected_mtr_output in this mode)
171
my $compare_result = compare($resultfile_full_path, $resultfile2_full_path);
172
if ( $compare_result == 0) {
174
say('Issue not repeatable (results were equal) with test '.$testfile_base_name);
175
if ($iteration > 1) {
176
unlink($testfile_full_path); # deletes test for Server A
177
unlink($testfile2_full_path); # deletes test for Server B
178
unlink($resultfile_full_path); # deletes result for Server A
179
unlink($resultfile2_full_path); # deletes result for Server B
181
return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
182
} elsif ($compare_result > 0) {
184
say("Issue is repeatable (results differ) with test $testfile_base_name");
185
return ORACLE_ISSUE_STILL_REPEATABLE;
187
# error ($compare_result < 0)
188
if ( (! -e $resultfile_full_path) && (! -e $resultfile2_full_path) ) {
189
# both servers are lacking result file. Probably due to bad SQL in simplified test.
190
return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
192
if (! -e $resultfile_full_path) {
193
say("Error ($compare_result) comparing result files for test $testfile_base_name");
194
say("Test output was:");
195
say $mysqltest_output;
196
croak("Resultfile $resultfile_full_path not found");
197
} elsif (! -e $resultfile2_full_path) {
198
say("Error ($compare_result) comparing result files for test $testfile_base_name");
199
say("Test output was:");
200
say $mysqltest_output2;
201
croak("Resultfile2 $resultfile2_full_path not found");
205
########################################################################
206
# End of comparison mode (two basedirs)
207
########################################################################
210
# Only one basedir specified - retain old behavior (look for expected output).
213
# We declare the test to have failed properly only if the
214
# desired message is present in the output and it is not a
215
# result of an error that caused part of the test, including
216
# the --croak construct, to be printed to stdout.
219
my $expected_mtr_output = $config->expected_mtr_output;
221
($mysqltest_output =~ m{$expected_mtr_output}sio) &&
222
($mysqltest_output !~ m{--die}sio)
224
say("Issue repeatable with $testfile");
225
return ORACLE_ISSUE_STILL_REPEATABLE;
227
say("Issue not repeatable with $testfile.");
229
($mtr_exit_code == 0) &&
232
unlink('t/'.$testfile);
233
unlink('r/'.$resultfile);
236
say $mysqltest_output if $iteration > 1 && $mtr_exit_code != 0;
237
return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
243
my $simplified_mysqltest;
246
if (-f $config->input_file){
247
$config->input_file =~ m/\.([a-z]+$)/i;
249
my $input_file_copy = $config->basedir."/mysql-test/t/".$run_id."-0.".$extension;
250
system("cp ".$config->input_file." ".$input_file_copy);
252
if (lc($extension) eq 'csv') {
253
say("Treating ".$config->input_file." as a CSV file");
254
$simplified_mysqltest = $simplifier->simplifyFromCSV($input_file_copy);
255
} elsif (lc($extension) eq 'test') {
256
say("Treating ".$config->input_file." as a mysqltest file");
257
open (MYSQLTEST_FILE , $input_file_copy) or croak "Unable to open ".$input_file_copy." as a .test file: $!";
258
read (MYSQLTEST_FILE , my $initial_mysqltest, -s $input_file_copy);
259
close (MYSQLTEST_FILE);
260
$simplified_mysqltest = $simplifier->simplify($initial_mysqltest);
262
carp "Unknown file type for ".$config->input_file;
265
if (defined $simplified_mysqltest) {
266
say "Simplified mysqltest:";
267
print "\n\n".join("\n",@{$header})."\n\n\n".$simplified_mysqltest.join("\n",@{$footer})."\n\n";
270
say "Unable to simplify ". $config->input_file.".\n";
271
exit (STATUS_ENVIRONMENT_FAILURE);
274
croak "Can't find ".$config->input_file;