~drizzle-trunk/drizzle/development

0.67.305 by Bernt M. Johnsen
Copyright headres and license added
1
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
3
#
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.
7
#
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.
12
#
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
16
# USA
17
0.67.348 by Philip Stoev
changes to support large-scale mysqltest simplifications
18
$| = 1;
19
0.67.9 by Philip Stoev
merge from internal tree
20
use strict;
21
use lib 'lib';
22
use lib '../lib';
23
use DBI;
0.82.2 by Bernt M. Johnsen
New config
24
use Carp;
0.67.286 by John H. Embretsen
New feature in simplify-mysqltest.pl utility script: Specify basedir2 in order to simplify a test case based on result differences between two servers.
25
use File::Compare;
26
use File::Copy;
0.82.2 by Bernt M. Johnsen
New config
27
use Getopt::Long;
0.67.298 by Philip Stoev
faster mysqltest simplification
28
use Time::HiRes;
0.67.9 by Philip Stoev
merge from internal tree
29
30
use GenTest;
0.82.2 by Bernt M. Johnsen
New config
31
use GenTest::Properties;
0.67.9 by Philip Stoev
merge from internal tree
32
use GenTest::Constants;
33
use GenTest::Simplifier::Mysqltest;
34
0.67.286 by John H. Embretsen
New feature in simplify-mysqltest.pl utility script: Specify basedir2 in order to simplify a test case based on result differences between two servers.
35
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.
39
0.82.2 by Bernt M. Johnsen
New config
40
my $options = {};
0.67.169 by Bernt M. Johnsen
util/simplify-mysqltest.pl fixes
41
my $o = GetOptions($options, 
0.82.2 by Bernt M. Johnsen
New config
42
           'config=s',
43
           'input_file=s',
44
           'basedir=s',
0.67.286 by John H. Embretsen
New feature in simplify-mysqltest.pl utility script: Specify basedir2 in order to simplify a test case based on result differences between two servers.
45
           'basedir2=s',
0.67.169 by Bernt M. Johnsen
util/simplify-mysqltest.pl fixes
46
           'expected_mtr_output=s',
47
           'verbose!',
0.67.202 by Bernt M. Johnsen
Typo in util/simplify-mysqltest
48
           'mtr_options=s%',
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
49
           'mysqld=s%');
0.82.2 by Bernt M. Johnsen
New config
50
my $config = GenTest::Properties->new(
51
    options => $options,
0.67.169 by Bernt M. Johnsen
util/simplify-mysqltest.pl fixes
52
    legal => [
53
        'config',
54
        'input_file',
55
        'basedir',
0.67.286 by John H. Embretsen
New feature in simplify-mysqltest.pl utility script: Specify basedir2 in order to simplify a test case based on result differences between two servers.
56
        'basedir2',
0.67.169 by Bernt M. Johnsen
util/simplify-mysqltest.pl fixes
57
        'expected_mtr_output',
58
        'mtr_options',
59
        'vebose',
0.67.298 by Philip Stoev
faster mysqltest simplification
60
	'header',
61
	'footer',
62
	'filter',
63
        'mysqld',
64
	'use_connections'
0.67.169 by Bernt M. Johnsen
util/simplify-mysqltest.pl fixes
65
    ],
66
    required => [
67
        'basedir',
0.67.208 by Bernt M. Johnsen
Remove default mtr-options
68
        'input_file',
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
69
        'mtr_options']
0.82.2 by Bernt M. Johnsen
New config
70
    );
71
0.67.170 by Bernt M. Johnsen
Fixed help problem
72
$config->printHelp if not $o;
0.82.2 by Bernt M. Johnsen
New config
73
$config->printProps;
0.67.9 by Philip Stoev
merge from internal tree
74
0.67.298 by Philip Stoev
faster mysqltest simplification
75
my $header = $config->header() || [];
76
my $footer = $config->footer() || [];
77
0.67.9 by Philip Stoev
merge from internal tree
78
# End of user-configurable section
79
80
my $iteration = 0;
81
my $run_id = time();
82
83
say("run_id = $run_id");
84
85
my $simplifier = GenTest::Simplifier::Mysqltest->new(
0.67.298 by Philip Stoev
faster mysqltest simplification
86
    filter => $config->filter(),
87
    use_connections => $config->use_connections(),
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
88
    oracle => sub {
89
        my $oracle_mysqltest = shift;
90
        $iteration++;
91
        
92
        chdir($config->basedir.'/mysql-test'); # assume forward slash works
93
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
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
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
97
        
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
98
        open (ORACLE_MYSQLTEST, ">t/$testfile") or croak "Unable to open $testfile: $!";
0.67.298 by Philip Stoev
faster mysqltest simplification
99
100
	print ORACLE_MYSQLTEST join("\n",@{$header})."\n\n";
0.67.348 by Philip Stoev
changes to support large-scale mysqltest simplifications
101
        print ORACLE_MYSQLTEST $oracle_mysqltest;
102
	print ORACLE_MYSQLTEST "\n\n".join("\n",@{$footer})."\n";
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
103
        close ORACLE_MYSQLTEST;
104
105
        my $mysqldopt = $config->genOpt('--mysqld=--', 'mysqld');
106
0.67.298 by Philip Stoev
faster mysqltest simplification
107
	my $mtr_start_time = Time::HiRes::time();
108
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
109
        my $mysqltest_cmd = "perl mysql-test-run.pl $mysqldopt ". $config->genOpt('--', 'mtr_options')." t/$testfile 2>&1";
0.67.9 by Philip Stoev
merge from internal tree
110
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
111
        my $mysqltest_output = `$mysqltest_cmd`;
0.67.298 by Philip Stoev
faster mysqltest simplification
112
	my $mtr_exit_code = $? >> 8;
113
	my $mtr_duration = Time::HiRes::time() - $mtr_start_time;
114
	if ($iteration == 1) {
115
		say ($mysqltest_output);
116
	} else {
117
		say ("MTR test duration: $mtr_duration; exit_code: $mtr_exit_code");
118
	}
119
0.67.341 by Matthias Leich
One simplification attempt for a server crash did not
120
	system("grep 'Unsafe statement binlogged' ".$config->basedir()."/mysql-test/var/log/mysqld.1.err");
0.67.298 by Philip Stoev
faster mysqltest simplification
121
	my $grep_exit_code = $? >> 8;
122
	if ($grep_exit_code == 0) {
123
		say("Messages about unsafe replication found in master error log.");
124
		return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
125
	} elsif ($grep_exit_code > 1) {
0.67.348 by Philip Stoev
changes to support large-scale mysqltest simplifications
126
		say("grep on the mysqld.1.err error log failed");
0.67.298 by Philip Stoev
faster mysqltest simplification
127
	}
128
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
129
        ########################################################################
130
        # Start of comparison mode (two basedirs)
131
        ########################################################################
132
        
133
        if (defined $config->basedir2) {
134
            if ($iteration == 1) {
135
                say ('Two basedirs specified. Will compare outputs instead of looking for expected output.');
136
                say ('Server A: '.$config->basedir);
137
                say ('Server B: '.$config->basedir2);
138
                # NOTE: --record MTR option is required. TODO: Check for this?
139
            }
140
            
141
            #
142
            # Run the test against basedir2 and compare results against the previous run.
143
            #
144
            
145
            chdir($config->basedir2.'/mysql-test');
146
            
147
            # working dir is now for Server B, so we need full path to Server A's files for later
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
148
            my $testfile_full_path = $config->basedir.'/mysql-test/t/'.$testfile;
149
            my $resultfile_full_path = $config->basedir.'/mysql-test/r/'.$testfile_base_name.'.result';
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
150
                
151
            # tests/results for Server B include "-b" in the filename
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
152
            my $testfile2_base_name = $run_id.'-'.$iteration.'-b';
153
            my $testfile2 = $testfile2_base_name.'.test';
154
            my $testfile2_full_path = $config->basedir2.'/mysql-test/t/'.$testfile2;
155
            my $resultfile2_full_path = $config->basedir2.'/mysql-test/r/'.$testfile2_base_name.'.result';
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
156
            
157
            # Copy test file to server B
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
158
            copy($testfile_full_path, $testfile2_full_path) or croak("Unable to copy test file $testfile to $testfile2");
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
159
            
160
            my $mysqltest_cmd2 = 
161
                "perl mysql-test-run.pl $mysqldopt ". $config->genOpt('--', 'mtr_options').
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
162
                " $testfile2 2>&1";
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
163
164
            # Run the test against server B
165
            # we don't really use this output for anything right now
166
            my $mysqltest_output2 = `$mysqltest_cmd2`;
167
            #say $mysqltest_output2 if $iteration == 1;
168
            
169
            
170
            # Compare the two results
171
            # We declare the tests to have failed properly only if the results
172
            # from the two test runs differ.
173
            # (We ignore expected_mtr_output in this mode)
174
            my $compare_result = compare($resultfile_full_path, $resultfile2_full_path);
175
            if ( $compare_result == 0) {
176
                # no diff
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
177
                say('Issue not repeatable (results were equal) with test '.$testfile_base_name);
178
179
		if ($iteration > 1) {
180
	                unlink($testfile_full_path); # deletes test for Server A
181
	                unlink($testfile2_full_path); # deletes test for Server B
182
	                unlink($resultfile_full_path); # deletes result for Server A
183
        	        unlink($resultfile2_full_path); # deletes result for Server B
184
		}
185
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
186
                return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
187
            } elsif ($compare_result > 0) {
188
                # diff
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
189
                say("Issue is repeatable (results differ) with test $testfile_base_name");
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
190
                return ORACLE_ISSUE_STILL_REPEATABLE;
191
            } else {
192
                # error ($compare_result < 0)
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
193
                say("\nError ($compare_result) comparing result files for test $testfile_base_name");
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
194
                if (! -e $resultfile_full_path) {
195
                    say("Test output was:");
196
                    say $mysqltest_output;
197
                    # TODO: No result file may mean that we tried an invalid query
198
                    #       Try comparing .reject files in this case?
199
                    croak("Resultfile  $resultfile_full_path not found");
200
                } elsif (! -e $resultfile_full_path) {
201
                    say("Test output was:");
202
                    say $mysqltest_output2;
203
                    croak("Resultfile2 $resultfile2_full_path not found");
204
                }
205
            }
206
207
        ########################################################################
208
        # End of comparison mode (two basedirs)
209
        ########################################################################
210
            
211
        } else {
212
            # Only one basedir specified - retain old behavior (look for expected output).
213
214
            #
215
            # We declare the test to have failed properly only if the
216
            # desired message is present in the output and it is not a
217
            # result of an error that caused part of the test, including
218
            # the --croak construct, to be printed to stdout.
219
            #
220
    
221
            my $expected_mtr_output = $config->expected_mtr_output;
222
            if (
223
                ($mysqltest_output =~ m{$expected_mtr_output}sio) &&
224
                ($mysqltest_output !~ m{--die}sio)
225
            ) {
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
226
                say("Issue repeatable with $testfile");
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
227
                return ORACLE_ISSUE_STILL_REPEATABLE;
228
            } else {
0.67.307 by Philip Stoev
further fixes to mysqltest simplification
229
                say("Issue not repeatable with $testfile.");
230
231
		if (
232
			($mtr_exit_code == 0) &&
233
			($iteration > 1)
234
		) {
235
	                unlink('t/'.$testfile);
236
	                unlink('r/'.$resultfile);
237
		}
238
0.67.298 by Philip Stoev
faster mysqltest simplification
239
		say $mysqltest_output if $iteration > 1 && $mtr_exit_code != 0;
240
		
0.67.287 by John H. Embretsen
simplify_mysqltest.pl: Convert tabs to spaces. This was inconsistent prior to this change. Spaces only is easier to work with across editors and systems.
241
                return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
242
            }
243
        }
244
    }
0.67.9 by Philip Stoev
merge from internal tree
245
);
246
247
my $simplified_mysqltest;
248
0.67.172 by Bernt M. Johnsen
Always copy input file
249
## Copy input file
250
if (-f $config->input_file){
251
    $config->input_file =~ m/\.([a-z]+$)/i;
252
    my $extension = $1;
253
    my $input_file_copy = $config->basedir."/mysql-test/t/".$run_id."-0.".$extension;
254
    system("cp ".$config->input_file." ".$input_file_copy);
255
    
256
    if (lc($extension) eq 'csv') {
257
        say("Treating ".$config->input_file." as a CSV file");
258
        $simplified_mysqltest = $simplifier->simplifyFromCSV($input_file_copy);
259
    } elsif (lc($extension) eq 'test') {
260
        say("Treating ".$config->input_file." as a mysqltest file");
261
        open (MYSQLTEST_FILE , $input_file_copy) or croak "Unable to open ".$input_file_copy." as a .test file: $!";
262
        read (MYSQLTEST_FILE , my $initial_mysqltest, -s $input_file_copy);
263
        close (MYSQLTEST_FILE);
264
        $simplified_mysqltest = $simplifier->simplify($initial_mysqltest);
265
    } else {
266
        carp "Unknown file type for ".$config->input_file;
267
    }
0.67.9 by Philip Stoev
merge from internal tree
268
0.67.172 by Bernt M. Johnsen
Always copy input file
269
    if (defined $simplified_mysqltest) {
0.67.298 by Philip Stoev
faster mysqltest simplification
270
        say "Simplified mysqltest:";
271
	print "\n\n".join("\n",@{$header})."\n\n\n".$simplified_mysqltest.join("\n",@{$footer})."\n\n";
0.67.172 by Bernt M. Johnsen
Always copy input file
272
        exit (STATUS_OK);
273
    } else {
274
        say "Unable to simplify ". $config->input_file.".\n";
275
        exit (STATUS_ENVIRONMENT_FAILURE);
276
    }
0.67.9 by Philip Stoev
merge from internal tree
277
} else {
0.67.172 by Bernt M. Johnsen
Always copy input file
278
    croak "Can't find ".$config->input_file;
0.67.9 by Philip Stoev
merge from internal tree
279
}
0.67.172 by Bernt M. Johnsen
Always copy input file
280
##
281