~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use strict;
use Cwd;
use File::Basename;
use POSIX;
use Sys::Hostname;

my ($basedir, $vardir, $tree, $test) = @ARGV;

print("==================== Starting $0 ====================\n");
# Print MTR-style output saying which test suite/mode this is for PB2 reporting.
# So far we only support running one test at a time.
print("##############################################################################\n");
print("# $test\n");
print("##############################################################################\n");

# Autoflush output buffers (needed when using POSIX::_exit())
$| = 1;

chdir('randgen');

#print localtime()." [$$] Information on Random Query Generator version:\n";
#system("bzr parent");
#system("bzr version-info");

my $cwd = cwd();

# Location of grammars and other test configuration files.
# Will use env variable RQG_CONF is set.
# Default is currently "conf" while using legacy setup.
# If not absolute path, it is relative to cwd at run time, which is the randgen directory.
my $conf = $ENV{RQG_CONF};
$conf = 'conf' if not defined $conf;

print("***** Information on the host system: *****\n");
print(" - Local time  : ".localtime()."\n");
print(" - Hostname    : ".hostname()."\n");
print(" - PID         : $$\n");
print(" - Working dir : ".cwd()."\n");
print(" - PATH        : ".$ENV{PATH}."\n");
print(" - Script arguments:\n");
print("       basedir = $basedir\n");
print("       vardir  = $vardir\n");
print("       tree    = $tree\n");
print("       test    = $test\n");
print("\n");
print("***** Information on Random Query Generator version (bzr): *****\n");
system("bzr info");
system("bzr version-info");
print("\n");

mkdir($vardir);

my $command;

# setting number of trials to 1 until we have more stable runs and proper output handling.

if ($test =~ m{falcon_combinations_simple}io ) {
	$command = '
		--grammar='.$conf.'/combinations.yy
		--gendata='.$conf.'/combinations.zz
		--config='.$conf.'/falcon_simple.cc
		--duration=900
		--trials=1
		--seed=time
	';
} elsif ($test =~ m{falcon_combinations_transactions}io ) {
	$command = '
		--grammar='.$conf.'/transactions-flat.yy
		--gendata='.$conf.'/transactions.zz
		--config='.$conf.'/falcon_simple.cc
		--duration=900
		--trials=1
		--seed=time
	';
} elsif ($test =~ m{innodb_combinations_simple}io ) {
	$command = '
		--grammar='.$conf.'/combinations.yy
		--gendata='.$conf.'/combinations.zz
		--config='.$conf.'/innodb_simple.cc
		--duration=1800
		--trials=1
		--seed=time
	';
} elsif ($test =~ m{innodb_combinations_stress}io ) {
	$command = '
		--grammar='.$conf.'/engine_stress.yy
		--gendata='.$conf.'/engine_stress.zz
		--config='.$conf.'/innodb_simple.cc
		--duration=600
		--trials=1
		--seed=time
	';
} elsif ($test =~ m{falcon_combinations_varchar}io ) {
	$command = '
		--grammar='.$conf.'/varchar.yy
		--gendata='.$conf.'/varchar.zz
		--config='.$conf.'/falcon_varchar.cc
		--duration=900
		--trials=1
		--seed=time
	';
} else {
	die("unknown combinations test $test");
}

# Assuming Unix for now (using tail).

$command = "perl combinations.pl --basedir=\"$basedir\" --vardir=\"$vardir\" ".$command;
# redirect output to log file to avoid sending huge amount of output to PB2
my $log_file = $vardir.'/pb2comb_'.$test.'.out';
$command = $command." > $log_file 2>&1";
$command =~ s{[\r\n\t]}{ }sgio;

print localtime()." [$$] Executing command: $command\n";
my $command_result = system($command);
# shift result code to the right to obtain the code returned from the called script
my $command_result_shifted = ($command_result >> 8);
print localtime()." [$$] combinations.pl exited with exit status ".$command_result_shifted."\n";


# Report test result in an MTR fashion so that PB2 will see it and add to
# xref database etc.
# Format: TESTSUITE.TESTCASE 'TESTMODE' [ RESULT ]
# Example: ndb.ndb_dd_alter 'InnoDB plugin'     [ fail ]
# Not using TESTMODE for now.
my $test_suite_name = 'serverqa';
my $full_test_name = $test_suite_name.'.'.$test;
# keep test statuses more or less vertically aligned (if more than one)
while (length $full_test_name < 40)
{
	$full_test_name = $full_test_name.' ';
}

if ($command_result_shifted > 0) {
	# test failed
	print("------------------------------------------------------------------------\n");
	print($full_test_name." [ fail ]\n");
} else {
	print($full_test_name." [ pass ]\n");
}
# Print only parts of the output if it is "too large" for PB2.
# This is hopefully just a temporary hack solution...
# Caveats: If the file is shorter than 201 lines, all the output will be sent to std out.
#          If the file is longer than 200 lines, only the first and last parts of the output
#          will be sent to std out.
#          Using 'wc', 'head' and 'tail', so probably won't work on windows (unless required gnu utils are installed)
#          Hanged proceses not especially handled.
#          etc.
my $log_lines = `wc -l < $log_file`;	# number of lines in the log file
if ($log_lines <= 200) {
	# log has 200 lines or less. Display the entire log.
	print("----->  See below for failure details...\n");
	print("----->  Test log will now be displayed...\n\n");
	open LOGFILE, $log_file or warn "***Failed to open log file [$log_file]";
	print while(<LOGFILE>);
	close LOGFILE;
} elsif ($log_lines > 200) {
	# the log has more than 200 lines. Display the first and last 100 lines.
	my $lines = 100;
	print("----->  See below for failure details...\n");
	print("----->  Printing first $lines and last $lines lines from test output...\n");
	print('----->  See log file '.basename($log_file)." for full output.\n\n");
	system("head -$lines $log_file");
	print("\n.\n.\n.\n.\n.\n(...)\n.\n.\n.\n.\n.\n\n"); # something to visually separate the head and the tail
	system("tail -$lines $log_file");
} else {
	# something went wrong. wc did not work?
	warn("***ERROR during log processing. wc -l did not work? (\$log_lines=$log_lines)\n");
}
print localtime()." [$$] $0 will exit with exit status ".$command_result_shifted."\n";
POSIX::_exit ($command_result_shifted);