~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/randgen/pb2combinations.pl

  • Committer: patrick crews
  • Date: 2011-10-05 20:40:33 UTC
  • mfrom: (2337.1.24 dbqp_revamp2)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: gleebix@gmail.com-20111005204033-5m6kvcii1q87yur6
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2009 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
use lib 'lib';
 
19
use lib "$ENV{RQG_HOME}/lib";
 
20
use lib 'randgen/lib';
 
21
 
 
22
use strict;
 
23
use Cwd;
 
24
use File::Basename;
 
25
use GenTest;
 
26
use POSIX;
 
27
use Sys::Hostname;
 
28
 
 
29
my ($basedir, $vardir, $tree, $test) = @ARGV;
 
30
 
 
31
print("==================== Starting $0 ====================\n");
 
32
# Print MTR-style output saying which test suite/mode this is for PB2 reporting.
 
33
# So far we only support running one test at a time.
 
34
print("##############################################################################\n");
 
35
print("# $test\n");
 
36
print("##############################################################################\n");
 
37
 
 
38
# Autoflush output buffers (needed when using POSIX::_exit())
 
39
$| = 1;
 
40
 
 
41
# Working dir.
 
42
chdir('randgen');
 
43
my $cwd = cwd();
 
44
 
 
45
# Location of grammars and other test configuration files.
 
46
# Will use env variable RQG_CONF if set.
 
47
# Default is currently "conf" while using legacy setup.
 
48
# If not absolute path, it is relative to cwd at run time, which is the randgen directory.
 
49
my $conf = $ENV{RQG_CONF};
 
50
$conf = 'conf' if not defined $conf;
 
51
 
 
52
# Find out active user name and mention it in the output to ease debugging.
 
53
my $username;
 
54
if (osLinux() || osSolaris()) {
 
55
    $username = $ENV{'LOGNAME'};
 
56
} else {
 
57
    $username = $ENV{'USERNAME'};
 
58
}
 
59
 
 
60
say("===== Information on the host system: =====\n");
 
61
say(" - Local time  : ".localtime()."\n");
 
62
say(" - Hostname    : ".hostname()."\n");
 
63
say(" - Username    : ".$username."\n");
 
64
say(" - PID         : $$\n");
 
65
say(" - Working dir : ".cwd()."\n");
 
66
say(" - PATH        : ".$ENV{PATH}."\n");
 
67
say(" - Script arguments:\n");
 
68
say("       basedir = $basedir\n");
 
69
say("       vardir  = $vardir\n");
 
70
say("       tree    = $tree\n");
 
71
say("       test    = $test\n");
 
72
say("\n");
 
73
say("===== Information on Random Query Generator version (bzr): =====\n");
 
74
system("bzr info");
 
75
system("bzr version-info");
 
76
say("\n");
 
77
 
 
78
mkdir($vardir);
 
79
 
 
80
my $command;
 
81
 
 
82
# setting number of trials to 1 until we have more stable runs and proper output handling.
 
83
 
 
84
if ($test =~ m{falcon_combinations_simple}io ) {
 
85
        $command = '
 
86
                --grammar='.$conf.'/transactions/combinations.yy
 
87
                --gendata='.$conf.'/transactions/combinations.zz
 
88
                --config='.$conf.'/engines/falcon/falcon_simple.cc
 
89
                --duration=900
 
90
                --trials=1
 
91
                --seed=time
 
92
        ';
 
93
} elsif ($test =~ m{falcon_combinations_transactions}io ) {
 
94
        $command = '
 
95
                --grammar='.$conf.'/transactions/transactions-flat.yy
 
96
                --gendata='.$conf.'/transactions/transactions.zz
 
97
                --config='.$conf.'/engines/falcon/falcon_simple.cc
 
98
                --duration=900
 
99
                --trials=1
 
100
                --seed=time
 
101
        ';
 
102
} elsif ($test =~ m{innodb_combinations_simple}io ) {
 
103
        $command = '
 
104
                --grammar='.$conf.'/transactions/combinations.yy
 
105
                --gendata='.$conf.'/transactions/combinations.zz
 
106
                --config='.$conf.'/engines/innodb/innodb_simple.cc
 
107
                --mysqld=--innodb
 
108
                --duration=1800
 
109
                --trials=1
 
110
                --seed=time
 
111
        ';
 
112
} elsif ($test =~ m{innodb_combinations_stress}io ) {
 
113
        $command = '
 
114
                --grammar='.$conf.'/engines/engine_stress.yy
 
115
                --gendata='.$conf.'/engines/engine_stress.zz
 
116
                --config='.$conf.'/engines/innodb/innodb_simple.cc
 
117
                --mysqld=--innodb
 
118
                --duration=600
 
119
                --trials=1
 
120
                --seed=time
 
121
        ';
 
122
} elsif ($test =~ m{falcon_combinations_varchar}io ) {
 
123
        $command = '
 
124
                --grammar='.$conf.'/engines/varchar.yy
 
125
                --gendata='.$conf.'/engines/varchar.zz
 
126
                --config='.$conf.'/engines/falcon/falcon_varchar.cc
 
127
                --duration=900
 
128
                --trials=1
 
129
                --seed=time
 
130
        ';
 
131
} else {
 
132
        die("unknown combinations test $test");
 
133
}
 
134
 
 
135
# Assuming Unix for now (using tail).
 
136
 
 
137
$command = "perl combinations.pl --basedir=\"$basedir\" --vardir=\"$vardir\" ".$command;
 
138
 
 
139
### XML reporting setup START
 
140
 
 
141
# Pass test name to RQG, for reporting purposes
 
142
$command = $command." --testname=".$test;
 
143
 
 
144
# Enable XML reporting to TestTool.
 
145
# For now only on given hosts...
 
146
my %report_xml_from_hosts = (
 
147
    'loki06'   => '',
 
148
    'nanna21'  => '',
 
149
    'techra22' => '',
 
150
    'tor06-z1' => '',
 
151
    'tyr41'    => ''
 
152
);
 
153
my $hostname = hostname();
 
154
my $xmlfile;
 
155
my $delete_xmlfile = 0; # boolean indicator whether to delete local XML file.
 
156
if (exists $report_xml_from_hosts{$hostname}) {
 
157
    # We should enable XML reporting on this host...
 
158
    say("XML reporting to TestTool automatically enabled based on hostname.");
 
159
    # We need to write the XML to a file before sending to reporting framework.
 
160
    # This is done by specifying xml-output option.
 
161
    # TMPDIR should be set by Pushbuild to indicate a suitable location for temp files.
 
162
    my $tmpdir = $ENV{'TMPDIR'};
 
163
    if (length($tmpdir) > 1) {
 
164
        $xmlfile = $tmpdir.'/'.$test.'.xml';
 
165
    } else {
 
166
        # TMPDIR not set. Write report to current directory.
 
167
        # This file should be deleted after test end so that disks won't fill up.
 
168
        $delete_xmlfile = 1;
 
169
        $xmlfile = $test.'.xml';
 
170
    }
 
171
    # Enable XML reporting to TT (assuming this is not already enabled):
 
172
    $command = $command.' --xml-output='.$xmlfile.' --report-xml-tt';
 
173
    # Specify XML reporting transport type (not relying on defaults):
 
174
    # We assume SSH keys have been properly set up to enable seamless scp use.
 
175
    $command = $command.' --report-xml-tt-type=scp';
 
176
    # Specify destination for XML reports (not relying on defaults):
 
177
    $command = $command.' --report-xml-tt-dest=regin.norway.sun.com:/raid/xml_results/TestTool/xml/';
 
178
}
 
179
### XML reporting setup END
 
180
 
 
181
# redirect output to log file to avoid sending huge amount of output to PB2
 
182
my $log_file = $vardir.'/pb2comb_'.$test.'.out';
 
183
$command = $command." > $log_file 2>&1";
 
184
$command =~ s{[\r\n\t]}{ }sgio;
 
185
 
 
186
print localtime()." [$$] Executing command: $command\n";
 
187
my $command_result = system($command);
 
188
# shift result code to the right to obtain the code returned from the called script
 
189
my $command_result_shifted = ($command_result >> 8);
 
190
print localtime()." [$$] combinations.pl exited with exit status ".$command_result_shifted."\n";
 
191
 
 
192
 
 
193
# Report test result in an MTR fashion so that PB2 will see it and add to
 
194
# xref database etc.
 
195
# Format: TESTSUITE.TESTCASE 'TESTMODE' [ RESULT ]
 
196
# Example: ndb.ndb_dd_alter 'InnoDB plugin'     [ fail ]
 
197
# Not using TESTMODE for now.
 
198
my $test_suite_name = 'serverqa';
 
199
my $full_test_name = $test_suite_name.'.'.$test;
 
200
# keep test statuses more or less vertically aligned (if more than one)
 
201
while (length $full_test_name < 40)
 
202
{
 
203
        $full_test_name = $full_test_name.' ';
 
204
}
 
205
 
 
206
if ($command_result_shifted > 0) {
 
207
        # test failed
 
208
        say("------------------------------------------------------------------------\n");
 
209
        print($full_test_name." [ fail ]\n");
 
210
        say("----->  See below for failure details...\n");
 
211
} else {
 
212
        print($full_test_name." [ pass ]\n");
 
213
}
 
214
# Print only parts of the output if it is "too large" for PB2.
 
215
# This is hopefully just a temporary hack solution...
 
216
# Caveats: If the file is shorter than 201 lines, all the output will be sent to std out.
 
217
#          If the file is longer than 200 lines, only the first and last parts of the output
 
218
#          will be sent to std out.
 
219
#          Using 'wc', 'head' and 'tail', so probably won't work on windows (unless required gnu utils are installed)
 
220
#          Hanged proceses not especially handled.
 
221
#          etc.
 
222
my $log_lines = `wc -l < $log_file`;    # number of lines in the log file
 
223
if ($log_lines <= 200) {
 
224
        # log has 200 lines or less. Display the entire log.
 
225
        say("----->  Test log will now be displayed...\n\n");
 
226
        open LOGFILE, $log_file or warn "***Failed to open log file [$log_file]";
 
227
        print while(<LOGFILE>);
 
228
        close LOGFILE;
 
229
} elsif ($log_lines > 200) {
 
230
        # the log has more than 200 lines. Display the first and last 100 lines.
 
231
        my $lines = 100;
 
232
        say("----->  Printing first $lines and last $lines lines from test output of $log_lines lines...\n");
 
233
        say('----->  See log file '.basename($log_file)." for full output.\n\n");
 
234
        system("head -$lines $log_file");
 
235
        print("\n.\n.\n.\n.\n.\n(...)\n.\n.\n.\n.\n.\n\n"); # something to visually separate the head and the tail
 
236
        system("tail -$lines $log_file");
 
237
} else {
 
238
        # something went wrong. wc did not work?
 
239
        warn("***ERROR during log processing. wc -l did not work? (\$log_lines=$log_lines)\n");
 
240
}
 
241
 
 
242
# Kill remaining mysqld processes.
 
243
# Assuming only one test run going on at the same time, and that all mysqld
 
244
# processes are ours.
 
245
say("Checking for remaining mysqld processes...\n");
 
246
if (osWindows()) {
 
247
        # assumes MS Sysinternals PsTools is installed in C:\bin
 
248
        # If you need to run pslist or pskill as non-Admin user, some permission
 
249
        # adjustments may be needed. See:
 
250
        #   http://blogs.technet.com/markrussinovich/archive/2007/07/09/1449341.aspx
 
251
        if (system('C:\bin\pslist mysqld') == 0) {
 
252
                say(" ^--- Found running mysqld process(es), to be killed if possible.\n");
 
253
                system('C:\bin\pskill mysqld > '.$vardir.'/pskill_mysqld.out 2>&1');
 
254
                system('C:\bin\pskill mysqld-nt > '.$vardir.'/pskill_mysqld-nt.out 2>&1');
 
255
        } else { say("  None found.\n"); }
 
256
 
 
257
} else {
 
258
        # Unix/Linux.
 
259
        # Avoid "bad argument count" messages from kill by checking if process exists first.
 
260
        if (system("pgrep mysqld") == 0) {
 
261
                say(" ^--- Found running mysqld process(es), to be killed if possible.\n");
 
262
                system("pgrep mysqld | xargs kill -15"); # "soft" kill
 
263
                sleep(5);
 
264
                if (system("pgrep mysqld > /dev/null") == 0) {
 
265
                        # process is still around...
 
266
                        system("pgrep mysqld | xargs kill -9"); # "hard" kill
 
267
                }
 
268
        } else { say("  None found.\n"); }
 
269
}
 
270
 
 
271
print localtime()." [$$] $0 will exit with exit status ".$command_result_shifted."\n";
 
272
POSIX::_exit ($command_result_shifted);