~drizzle-trunk/drizzle/development

0.67.305 by Bernt M. Johnsen
Copyright headres and license added
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
0.99.26 by John H. Embretsen
Start using GenTest's windows() and solaris() checking subs instead of re-inventing the wheel in each pb2 script.
18
use lib 'lib';
19
use lib "$ENV{RQG_HOME}/lib";
20
use lib 'randgen/lib';
21
0.67.1 by Philip Stoev
initial import from internal tree
22
use strict;
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
23
use Cwd;
24
use File::Basename;
0.99.26 by John H. Embretsen
Start using GenTest's windows() and solaris() checking subs instead of re-inventing the wheel in each pb2 script.
25
use GenTest;
0.67.1 by Philip Stoev
initial import from internal tree
26
use POSIX;
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
27
use Sys::Hostname;
0.67.1 by Philip Stoev
initial import from internal tree
28
29
my ($basedir, $vardir, $tree, $test) = @ARGV;
30
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
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
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
41
# Working dir.
0.67.16 by John H. Embretsen
Update paths in PB2 scripts, having modified PB2 host setup to use the randgen branch on Launchpad.
42
chdir('randgen');
0.67.1 by Philip Stoev
initial import from internal tree
43
my $cwd = cwd();
44
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
45
# Location of grammars and other test configuration files.
0.67.136 by John H. Embretsen
Minor fixes to comments in pb2{gentest,combinations}.pl
46
# Will use env variable RQG_CONF if set.
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
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
0.67.389 by John H. Embretsen
Enable XML reporting in pb2combinations.pl. Also add username to output (aligned with pb2gentest.pl).
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
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
60
say("===== Information on the host system: =====\n");
61
say(" - Local time  : ".localtime()."\n");
62
say(" - Hostname    : ".hostname()."\n");
0.67.389 by John H. Embretsen
Enable XML reporting in pb2combinations.pl. Also add username to output (aligned with pb2gentest.pl).
63
say(" - Username    : ".$username."\n");
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
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");
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
74
system("bzr info");
75
system("bzr version-info");
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
76
say("\n");
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
77
0.67.1 by Philip Stoev
initial import from internal tree
78
mkdir($vardir);
79
80
my $command;
81
0.80.3 by John H. Embretsen
pb2combinations: Set --trials to 1 to see if at least that will run OK in PB2 without causing hangs.
82
# setting number of trials to 1 until we have more stable runs and proper output handling.
0.80.2 by John H. Embretsen
pb2combinations: Make test output handling slightly more 'intelligent' by checking number of lines and displaying head and tail only if there are more than 200 lines.
83
0.67.1 by Philip Stoev
initial import from internal tree
84
if ($test =~ m{falcon_combinations_simple}io ) {
85
	$command = '
0.99.3 by John H. Embretsen
Categorized configuration files by moving them into subdirectories with descriptive names.
86
		--grammar='.$conf.'/transactions/combinations.yy
87
		--gendata='.$conf.'/transactions/combinations.zz
88
		--config='.$conf.'/engines/falcon/falcon_simple.cc
0.67.1 by Philip Stoev
initial import from internal tree
89
		--duration=900
0.80.3 by John H. Embretsen
pb2combinations: Set --trials to 1 to see if at least that will run OK in PB2 without causing hangs.
90
		--trials=1
0.67.1 by Philip Stoev
initial import from internal tree
91
		--seed=time
92
	';
93
} elsif ($test =~ m{falcon_combinations_transactions}io ) {
94
	$command = '
0.99.3 by John H. Embretsen
Categorized configuration files by moving them into subdirectories with descriptive names.
95
		--grammar='.$conf.'/transactions/transactions-flat.yy
96
		--gendata='.$conf.'/transactions/transactions.zz
97
		--config='.$conf.'/engines/falcon/falcon_simple.cc
0.67.1 by Philip Stoev
initial import from internal tree
98
		--duration=900
0.80.3 by John H. Embretsen
pb2combinations: Set --trials to 1 to see if at least that will run OK in PB2 without causing hangs.
99
		--trials=1
0.67.1 by Philip Stoev
initial import from internal tree
100
		--seed=time
101
	';
102
} elsif ($test =~ m{innodb_combinations_simple}io ) {
103
	$command = '
0.99.3 by John H. Embretsen
Categorized configuration files by moving them into subdirectories with descriptive names.
104
		--grammar='.$conf.'/transactions/combinations.yy
105
		--gendata='.$conf.'/transactions/combinations.zz
106
		--config='.$conf.'/engines/innodb/innodb_simple.cc
0.67.142 by John H. Embretsen
pb2gentest: Set option --mysqld=--innodb for tests that always use innodb.
107
		--mysqld=--innodb
0.67.1 by Philip Stoev
initial import from internal tree
108
		--duration=1800
0.80.3 by John H. Embretsen
pb2combinations: Set --trials to 1 to see if at least that will run OK in PB2 without causing hangs.
109
		--trials=1
0.67.1 by Philip Stoev
initial import from internal tree
110
		--seed=time
111
	';
0.67.9 by Philip Stoev
merge from internal tree
112
} elsif ($test =~ m{innodb_combinations_stress}io ) {
113
	$command = '
0.99.3 by John H. Embretsen
Categorized configuration files by moving them into subdirectories with descriptive names.
114
		--grammar='.$conf.'/engines/engine_stress.yy
115
		--gendata='.$conf.'/engines/engine_stress.zz
116
		--config='.$conf.'/engines/innodb/innodb_simple.cc
0.67.142 by John H. Embretsen
pb2gentest: Set option --mysqld=--innodb for tests that always use innodb.
117
		--mysqld=--innodb
0.67.9 by Philip Stoev
merge from internal tree
118
		--duration=600
0.80.3 by John H. Embretsen
pb2combinations: Set --trials to 1 to see if at least that will run OK in PB2 without causing hangs.
119
		--trials=1
0.67.9 by Philip Stoev
merge from internal tree
120
		--seed=time
121
	';
0.67.1 by Philip Stoev
initial import from internal tree
122
} elsif ($test =~ m{falcon_combinations_varchar}io ) {
123
	$command = '
0.99.3 by John H. Embretsen
Categorized configuration files by moving them into subdirectories with descriptive names.
124
		--grammar='.$conf.'/engines/varchar.yy
125
		--gendata='.$conf.'/engines/varchar.zz
126
		--config='.$conf.'/engines/falcon/falcon_varchar.cc
0.67.1 by Philip Stoev
initial import from internal tree
127
		--duration=900
0.80.3 by John H. Embretsen
pb2combinations: Set --trials to 1 to see if at least that will run OK in PB2 without causing hangs.
128
		--trials=1
0.67.1 by Philip Stoev
initial import from internal tree
129
		--seed=time
130
	';
131
} else {
132
	die("unknown combinations test $test");
133
}
134
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
135
# Assuming Unix for now (using tail).
136
0.67.1 by Philip Stoev
initial import from internal tree
137
$command = "perl combinations.pl --basedir=\"$basedir\" --vardir=\"$vardir\" ".$command;
0.67.389 by John H. Embretsen
Enable XML reporting in pb2combinations.pl. Also add username to output (aligned with pb2gentest.pl).
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
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
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";
0.67.1 by Philip Stoev
initial import from internal tree
184
$command =~ s{[\r\n\t]}{ }sgio;
185
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
186
print localtime()." [$$] Executing command: $command\n";
0.67.1 by Philip Stoev
initial import from internal tree
187
my $command_result = system($command);
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
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
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
208
	say("------------------------------------------------------------------------\n");
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
209
	print($full_test_name." [ fail ]\n");
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
210
	say("----->  See below for failure details...\n");
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
211
} else {
212
	print($full_test_name." [ pass ]\n");
213
}
0.80.2 by John H. Embretsen
pb2combinations: Make test output handling slightly more 'intelligent' by checking number of lines and displaying head and tail only if there are more than 200 lines.
214
# Print only parts of the output if it is "too large" for PB2.
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
215
# This is hopefully just a temporary hack solution...
0.80.2 by John H. Embretsen
pb2combinations: Make test output handling slightly more 'intelligent' by checking number of lines and displaying head and tail only if there are more than 200 lines.
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)
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
220
#          Hanged proceses not especially handled.
221
#          etc.
0.80.2 by John H. Embretsen
pb2combinations: Make test output handling slightly more 'intelligent' by checking number of lines and displaying head and tail only if there are more than 200 lines.
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.
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
225
	say("----->  Test log will now be displayed...\n\n");
0.80.2 by John H. Embretsen
pb2combinations: Make test output handling slightly more 'intelligent' by checking number of lines and displaying head and tail only if there are more than 200 lines.
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;
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
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");
0.80.2 by John H. Embretsen
pb2combinations: Make test output handling slightly more 'intelligent' by checking number of lines and displaying head and tail only if there are more than 200 lines.
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
}
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
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.
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
245
say("Checking for remaining mysqld processes...\n");
0.67.381 by Bernt M. Johnsen
Adjustments after merge
246
if (osWindows()) {
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
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) {
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
252
		say(" ^--- Found running mysqld process(es), to be killed if possible.\n");
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
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');
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
255
	} else { say("  None found.\n"); }
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
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) {
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
261
		say(" ^--- Found running mysqld process(es), to be killed if possible.\n");
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
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
		}
0.99.27 by John H. Embretsen
Use say() instead of print() where we can, to get a uniform prefix for all chatter (PB2 scripts). Almost all remaining prints are nedded to conform with current external (PB2) log parsers.
268
	} else { say("  None found.\n"); }
0.67.137 by John H. Embretsen
pb2combinations: Look for and kill remaining mysqld processes after a test run, similar to pb2gentest.
269
}
270
0.80.1 by John H. Embretsen
pb2combinations: Adding some changes that have already been applied to pb2gentest. Also redirecting output to log file.
271
print localtime()." [$$] $0 will exit with exit status ".$command_result_shifted."\n";
272
POSIX::_exit ($command_result_shifted);