1
# Copyright (c) 2008, 2011 Oracle and/or its affiliates. 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
20
use lib "$ENV{RQG_HOME}/lib";
21
use List::Util 'shuffle';
24
use GenTest::Constants;
28
my ($config_file, $basedir, $vardir, $trials, $duration, $grammar, $gendata,
29
$seed, $testname, $xml_output, $report_xml_tt, $report_xml_tt_type,
30
$report_xml_tt_dest, $force, $no_mask, $exhaustive, $debug);
37
my $opt_result = GetOptions(
38
'config=s' => \$config_file,
39
'basedir=s' => \$basedir,
40
'vardir=s' => \$vardir,
41
'trials=i' => \$trials,
42
'duration=i' => \$duration,
45
'no-mask' => \$no_mask,
46
'grammar=s' => \$grammar,
47
'gendata=s' => \$gendata,
48
'testname=s' => \$testname,
49
'xml-output=s' => \$xml_output,
50
'report-xml-tt' => \$report_xml_tt,
51
'report-xml-tt-type=s' => \$report_xml_tt_type,
52
'report-xml-tt-dest=s' => \$report_xml_tt_dest,
53
'run-all-combinations-once' => \$exhaustive,
58
my $prng = GenTest::Random->new(
59
seed => $seed eq 'time' ? time() : $seed
62
open(CONF, $config_file) or die "unable to open config file '$config_file': $!";
63
read(CONF, my $config_text, -s $config_file);
65
die "Unable to load $config_file: $@" if $@;
68
system("bzr version-info $basedir");
69
system("bzr log --limit=1");
71
my $comb_count = $#$combinations + 1;
75
foreach my $comb_id (0..($comb_count-1)) {
76
$total *= $#{$combinations->[$comb_id]}+1;
78
if (defined $trials) {
79
say("You have specified --run-all-combinations-once, but limited with --trials=$trials");
87
say("[$$] Summary of various interesting strings from the logs:");
88
say(Dumper \%results);
89
foreach my $string ('text=', 'bugcheck', 'Error: assertion', 'mysqld got signal', 'Received signal', 'exception') {
90
system("grep -i '$string' $vardir/trial*log");
93
say("[$$] $0 will exit with exit status $max_result");
96
## ----------------------------------------------------
98
my $trial_counter = 0;
101
my ($level,@idx) = @_;
102
if ($level < $comb_count) {
104
foreach my $i (0..$#{$combinations->[$level]}) {
108
for (my $i= $#alts;$i>=0;$i--) {
109
my $j = $prng->uint16(0, $i);
111
$alts[$i] = $alts[$j];
115
foreach my $alt (@alts) {
118
doExhaustive($level+1,@idx) if $trial_counter < $trials;
120
doExhaustive($level+1,@idx);
127
foreach my $i (0 .. $#idx) {
128
push @comb, $combinations->[$i]->[$idx[$i]];
130
my $comb_str = join(' ', @comb);
131
say("Executing Combination ".$trial_counter."/".$total);
132
doCombination($trial_counter,$comb_str);
136
## ----------------------------------------------------
139
foreach my $trial_id (1..$trials) {
141
foreach my $comb_id (0..($comb_count-1)) {
142
$comb[$comb_id] = $combinations->[$comb_id]->[$prng->uint16(0, $#{$combinations->[$comb_id]})];
144
my $comb_str = join(' ', @comb);
145
doCombination($trial_id,$comb_str);
149
## ----------------------------------------------------
151
my ($trial_id,$comb_str) = @_;
153
my $mask = $prng->uint16(0, 65535);
156
perl ".(defined $ENV{RQG_HOME} ? $ENV{RQG_HOME}."/" : "" )."runall.pl $comb_str
160
$command .= " --mask=$mask" if not defined $no_mask;
161
$command .= " --duration=$duration" if $duration ne '';
162
$command .= " --basedir=$basedir " if $basedir ne '';
163
$command .= " --gendata=$gendata " if $gendata ne '';
164
$command .= " --grammar=$grammar " if $grammar ne '';
165
$command .= " --seed=$seed " if $seed ne '';
166
$command .= " --testname=$testname " if $testname ne '';
167
$command .= " --xml-output=$xml_output " if $xml_output ne '';
168
$command .= " --report-xml-tt" if defined $report_xml_tt;
169
$command .= " --report-xml-tt-type=$report_xml_tt_type " if $report_xml_tt_type ne '';
170
$command .= " --report-xml-tt-dest=$report_xml_tt_dest " if $report_xml_tt_dest ne '';
172
$command .= " --vardir=$vardir/current " if $command !~ m{--mem}sio && $vardir ne '';
173
$command =~ s{[\t\r\n]}{ }sgio;
174
$command .= " 2>&1 | tee $vardir/trial".$trial_id.'.log';
176
$commands[$trial_id] = $command;
178
$command =~ s{"}{\\"}sgio;
179
$command = 'bash -c "set -o pipefail; '.$command.'"';
181
say("[$$] $command");
183
$result = system($command) if not $debug;
185
$result = $result >> 8;
186
say("[$$] runall.pl exited with exit status $result");
187
exit($result) if (($result == STATUS_ENVIRONMENT_FAILURE) || ($result == 255)) && (not defined $force);
190
$max_result = $result >> 8 if ($result >> 8) > $max_result;
191
say("[$$] Copying vardir to $vardir/vardir".$trial_id);
192
if ($command =~ m{--mem}) {
193
system("cp -r /dev/shm/var $vardir/vardir".$trial_id);
195
system("cp -r $vardir/current $vardir/vardir".$trial_id);
197
open(OUT, ">$vardir/vardir".$trial_id."/command");
201
$results{$result >> 8}++;