1
# Copyright (C) 2008-2009 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
19
use lib "$ENV{RQG_HOME}/lib";
20
use lib 'randgen/lib';
29
my ($basedir, $vardir, $tree, $test) = @ARGV;
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");
36
print("##############################################################################\n");
38
# Autoflush output buffers (needed when using POSIX::_exit())
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;
52
# Find out active user name and mention it in the output to ease debugging.
54
if (osLinux() || osSolaris()) {
55
$username = $ENV{'LOGNAME'};
57
$username = $ENV{'USERNAME'};
60
say("===== Information on the host system: =====\n");
61
say(" - Local time : ".localtime()."\n");
62
say(" - Hostname : ".hostname()."\n");
63
say(" - Username : ".$username."\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");
73
say("===== Information on Random Query Generator version (bzr): =====\n");
75
system("bzr version-info");
82
# setting number of trials to 1 until we have more stable runs and proper output handling.
84
if ($test =~ m{falcon_combinations_simple}io ) {
86
--grammar='.$conf.'/transactions/combinations.yy
87
--gendata='.$conf.'/transactions/combinations.zz
88
--config='.$conf.'/engines/falcon/falcon_simple.cc
93
} elsif ($test =~ m{falcon_combinations_transactions}io ) {
95
--grammar='.$conf.'/transactions/transactions-flat.yy
96
--gendata='.$conf.'/transactions/transactions.zz
97
--config='.$conf.'/engines/falcon/falcon_simple.cc
102
} elsif ($test =~ m{innodb_combinations_simple}io ) {
104
--grammar='.$conf.'/transactions/combinations.yy
105
--gendata='.$conf.'/transactions/combinations.zz
106
--config='.$conf.'/engines/innodb/innodb_simple.cc
112
} elsif ($test =~ m{innodb_combinations_stress}io ) {
114
--grammar='.$conf.'/engines/engine_stress.yy
115
--gendata='.$conf.'/engines/engine_stress.zz
116
--config='.$conf.'/engines/innodb/innodb_simple.cc
122
} elsif ($test =~ m{falcon_combinations_varchar}io ) {
124
--grammar='.$conf.'/engines/varchar.yy
125
--gendata='.$conf.'/engines/varchar.zz
126
--config='.$conf.'/engines/falcon/falcon_varchar.cc
132
die("unknown combinations test $test");
135
# Assuming Unix for now (using tail).
137
$command = "perl combinations.pl --basedir=\"$basedir\" --vardir=\"$vardir\" ".$command;
139
### XML reporting setup START
141
# Pass test name to RQG, for reporting purposes
142
$command = $command." --testname=".$test;
144
# Enable XML reporting to TestTool.
145
# For now only on given hosts...
146
my %report_xml_from_hosts = (
153
my $hostname = hostname();
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';
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.
169
$xmlfile = $test.'.xml';
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/';
179
### XML reporting setup END
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;
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";
193
# Report test result in an MTR fashion so that PB2 will see it and add to
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)
203
$full_test_name = $full_test_name.' ';
206
if ($command_result_shifted > 0) {
208
say("------------------------------------------------------------------------\n");
209
print($full_test_name." [ fail ]\n");
210
say("-----> See below for failure details...\n");
212
print($full_test_name." [ pass ]\n");
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.
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>);
229
} elsif ($log_lines > 200) {
230
# the log has more than 200 lines. Display the first and last 100 lines.
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");
238
# something went wrong. wc did not work?
239
warn("***ERROR during log processing. wc -l did not work? (\$log_lines=$log_lines)\n");
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");
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"); }
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
264
if (system("pgrep mysqld > /dev/null") == 0) {
265
# process is still around...
266
system("pgrep mysqld | xargs kill -9"); # "hard" kill
268
} else { say(" None found.\n"); }
271
print localtime()." [$$] $0 will exit with exit status ".$command_result_shifted."\n";
272
POSIX::_exit ($command_result_shifted);