~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/test_tools/randgen/util/simplify-mysqltest.pl

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
18
$| = 1;
 
19
 
 
20
use strict;
 
21
use lib 'lib';
 
22
use lib '../lib';
 
23
use DBI;
 
24
use Carp;
 
25
use File::Compare;
 
26
use File::Copy;
 
27
use Getopt::Long;
 
28
use Time::HiRes;
 
29
 
 
30
use GenTest;
 
31
use GenTest::Properties;
 
32
use GenTest::Constants;
 
33
use GenTest::Simplifier::Mysqltest;
 
34
 
 
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
 
 
40
my $options = {};
 
41
my $o = GetOptions($options, 
 
42
           'config=s',
 
43
           'input_file=s',
 
44
           'basedir=s',
 
45
           'basedir2=s',
 
46
           'expected_mtr_output=s',
 
47
           'verbose!',
 
48
           'mtr_options=s%',
 
49
           'mysqld=s%');
 
50
my $config = GenTest::Properties->new(
 
51
    options => $options,
 
52
    legal => [
 
53
        'config',
 
54
        'input_file',
 
55
        'basedir',
 
56
        'basedir2',
 
57
        'expected_mtr_output',
 
58
        'mtr_options',
 
59
        'verbose',
 
60
        'header',
 
61
        'footer',
 
62
        'filter',
 
63
        'mysqld',
 
64
        'use_connections'
 
65
    ],
 
66
    required => [
 
67
        'basedir',
 
68
        'input_file',
 
69
        'mtr_options']
 
70
    );
 
71
 
 
72
$config->printHelp if not $o;
 
73
$config->printProps;
 
74
 
 
75
my $header = $config->header() || [];
 
76
my $footer = $config->footer() || [];
 
77
 
 
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(
 
86
    filter => $config->filter(),
 
87
    use_connections => $config->use_connections(),
 
88
    oracle => sub {
 
89
        my $oracle_mysqltest = shift;
 
90
        $iteration++;
 
91
        
 
92
        chdir($config->basedir.'/mysql-test'); # assume forward slash works
 
93
 
 
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
 
97
        
 
98
        open (ORACLE_MYSQLTEST, ">t/$testfile") or croak "Unable to open $testfile: $!";
 
99
 
 
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;
 
104
 
 
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);
 
113
        } else {
 
114
            say ("MTR test duration: $mtr_duration; exit_code: $mtr_exit_code");
 
115
        }
 
116
    
 
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");
 
124
        }
 
125
 
 
126
        ########################################################################
 
127
        # Start of comparison mode (two basedirs)
 
128
        ########################################################################
 
129
        
 
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?
 
136
            }
 
137
            
 
138
            #
 
139
            # Run the test against basedir2 and compare results against the previous run.
 
140
            #
 
141
            
 
142
            chdir($config->basedir2.'/mysql-test');
 
143
            
 
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';
 
147
                
 
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';
 
153
            
 
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");
 
156
            
 
157
            my $mysqltest_cmd2 = 
 
158
                "perl mysql-test-run.pl $mysqldopt ". $config->genOpt('--', 'mtr_options').
 
159
                " $testfile2 2>&1";
 
160
 
 
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;
 
165
            
 
166
            
 
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) {
 
173
                # no diff
 
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
 
180
                }
 
181
                return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
 
182
            } elsif ($compare_result > 0) {
 
183
                # diff
 
184
                say("Issue is repeatable (results differ) with test $testfile_base_name");
 
185
                return ORACLE_ISSUE_STILL_REPEATABLE;
 
186
            } else {
 
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;
 
191
                }
 
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");
 
202
                }
 
203
            }
 
204
 
 
205
        ########################################################################
 
206
        # End of comparison mode (two basedirs)
 
207
        ########################################################################
 
208
            
 
209
        } else {
 
210
            # Only one basedir specified - retain old behavior (look for expected output).
 
211
 
 
212
            #
 
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.
 
217
            #
 
218
    
 
219
            my $expected_mtr_output = $config->expected_mtr_output;
 
220
            if (
 
221
                ($mysqltest_output =~ m{$expected_mtr_output}sio) &&
 
222
                ($mysqltest_output !~ m{--die}sio)
 
223
            ) {
 
224
                say("Issue repeatable with $testfile");
 
225
                return ORACLE_ISSUE_STILL_REPEATABLE;
 
226
            } else {
 
227
                say("Issue not repeatable with $testfile.");
 
228
                if (
 
229
                    ($mtr_exit_code == 0) &&
 
230
                    ($iteration > 1)
 
231
                ) {
 
232
                    unlink('t/'.$testfile);
 
233
                    unlink('r/'.$resultfile);
 
234
                }
 
235
 
 
236
                say $mysqltest_output if $iteration > 1 && $mtr_exit_code != 0;
 
237
                return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
 
238
            }
 
239
        }
 
240
    }
 
241
);
 
242
 
 
243
my $simplified_mysqltest;
 
244
 
 
245
## Copy input file
 
246
if (-f $config->input_file){
 
247
    $config->input_file =~ m/\.([a-z]+$)/i;
 
248
    my $extension = $1;
 
249
    my $input_file_copy = $config->basedir."/mysql-test/t/".$run_id."-0.".$extension;
 
250
    system("cp ".$config->input_file." ".$input_file_copy);
 
251
    
 
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);
 
261
    } else {
 
262
        carp "Unknown file type for ".$config->input_file;
 
263
    }
 
264
 
 
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";
 
268
        exit (STATUS_OK);
 
269
    } else {
 
270
        say "Unable to simplify ". $config->input_file.".\n";
 
271
        exit (STATUS_ENVIRONMENT_FAILURE);
 
272
    }
 
273
} else {
 
274
    croak "Can't find ".$config->input_file;
 
275
}
 
276
##
 
277