~elenst/randgen/rocksdb

967 by Elena Stepanova
Repeat the same test the given number of times without creating
1
#!/usr/bin/perl
2
3
# Copyright (c) 2008, 2011 Oracle and/or its affiliates. All rights reserved.
4
# Copyright (c) 2014, SkySQL Ab.
5
# Use is subject to license terms.
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; version 2 of the License.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
# USA
20
21
use strict;
22
use lib 'lib';
23
use lib "$ENV{RQG_HOME}/lib";
24
#use List::Util 'shuffle';
25
use Cwd;
26
use File::Path 'remove_tree';
27
use GenTest;
28
use GenTest::Constants;
29
use Getopt::Long;
30
use File::Basename;
31
32
Getopt::Long::Configure("pass_through");
33
34
if (defined $ENV{RQG_HOME}) {
35
	if (osWindows()) {
36
		$ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
37
	} else {
38
		$ENV{RQG_HOME} = $ENV{RQG_HOME}.'/';
39
	}
40
} else {
41
	$ENV{RQG_HOME} = dirname(Cwd::abs_path($0));
42
}
43
44
if ( osWindows() )
45
{
46
	require Win32::API;
47
	my $errfunc = Win32::API->new('kernel32', 'SetErrorMode', 'I', 'I');
48
	my $initial_mode = $errfunc->Call(2);
49
	$errfunc->Call($initial_mode | 2);
50
};
51
52
$| = 1;
53
my $ctrl_c = 0;
54
	
55
$SIG{INT} = sub { $ctrl_c = 1 };
56
$SIG{TERM} = sub { exit(0) };
57
$SIG{CHLD} = "IGNORE" if osWindows();
58
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
59
my ($vardir, $vardir1, $vardir2, $trials, $force, $old, $exit_status, @exit_status);
967 by Elena Stepanova
Repeat the same test the given number of times without creating
60
61
my $max_result = 0;
62
63
my $opt_result = GetOptions(
64
	'vardir=s' => \$vardir,
65
	'vardir1=s' => \$vardir1,
66
	'vardir2=s' => \$vardir2,
67
	'trials=i' => \$trials,
68
	'force' => \$force,
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
69
	'old' => \$old,
70
	'exit_status=s' => \$exit_status,
71
	'exit-status=s' => \$exit_status,
967 by Elena Stepanova
Repeat the same test the given number of times without creating
72
);
73
74
$trials = 1 unless defined $trials;
75
76
push @ARGV, "--vardir=$vardir" if defined $vardir;
77
push @ARGV, "--vardir1=$vardir1" if defined $vardir1;
78
push @ARGV, "--vardir2=$vardir2" if defined $vardir2;
79
80
my $comb_str = join(' ', @ARGV);		
81
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
82
if ($exit_status) {
83
	@exit_status = split(',', $exit_status);
84
}
85
967 by Elena Stepanova
Repeat the same test the given number of times without creating
86
foreach my $trial_id (1..$trials) {
87
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
88
	say("##########################################################");
967 by Elena Stepanova
Repeat the same test the given number of times without creating
89
	say("Running trial ".$trial_id."/".$trials);
90
	my $runall = $old?"runall.pl":"runall-new.pl";
91
92
	my $command = "perl ".
93
		(defined $ENV{RQG_HOME} ? $ENV{RQG_HOME}."/" : "" ).
94
		"$runall $comb_str ";
95
96
	$command =~ s{[\t\r\n]}{ }sgio;
97
	$command =~ s{"}{\\"}sgio;
98
99
	unless (osWindows())
100
	{
101
		$command = 'bash -c "set -o pipefail; '.$command.'"';
102
	}
103
104
	say("$command");
105
106
	my $result = system($command) >> 8;
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
107
	my $result_name = status2text($result);
108
	say("Trial $trial_id ended with exit status $result_name ($result)");
109
	unless (check_for_desired_status($result_name)) {
110
		say("Exit status $result_name is not on the list of desired status codes ($exit_status), it will be ignored");
111
		next;
112
	}
113
	exit($result) if not defined $force;
967 by Elena Stepanova
Repeat the same test the given number of times without creating
114
115
	$max_result = $result if $result > $max_result;
116
117
	if ($result > 0) {
118
		# Storing vardirs for the failure
119
		foreach my $v ($vardir,$vardir1,$vardir2) {
120
			next unless defined $v;
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
121
			# Remove trailing slashes
122
			$v =~ s/[\/\\]+$//;
967 by Elena Stepanova
Repeat the same test the given number of times without creating
123
			my $from = $v;
124
			my $to = $v.'_trial'.$trial_id;
125
			say("Copying $from to $to");
126
			remove_tree($to) if (-e $to);
127
			remove_tree($to.'_slave') if (-e $to.'_slave');
128
			if (osWindows()) {
129
				system("xcopy \"$from\" \"$to\" /E /I /Q");
130
				system("xcopy \"$from"."_slave\" \"$to"."_slave\" /E /I /Q") if -e $from.'_slave';
131
				open(OUT, ">$to/command");
132
				print OUT $command;
133
				close(OUT);
134
			} elsif ($command =~ m{--mem}) {
135
				system("cp -r /dev/shm/var $to");
136
				open(OUT, ">$to/command");
137
				print OUT $command;
138
				close(OUT);
139
			} else {
140
				system("cp -r $from $to");
141
				system("cp -r $from"."_slave $to"."_slave") if -e $from.'_slave';
142
				open(OUT, ">$to/command");
143
				print OUT $command;
144
				close(OUT);
145
			}
146
		}
147
	}
148
}
149
150
say("$0 will exit with exit status ".status2text($max_result)."($max_result)");
151
exit($max_result);
152
1022 by Elena Stepanova
Remove trailing slashes from the vardir, they cause wrong directory names
153
sub check_for_desired_status {
154
	my $resname = shift;
155
	if (!$exit_status) {
156
		# No desired codes, anything except for STATUS_OIK will do
157
		return $resname ne 'STATUS_OK';
158
	}
159
	else {
160
		foreach (@exit_status) {
161
			return 1 if $resname eq $_;
162
		}
163
		return 0;
164
	}
165
}
967 by Elena Stepanova
Repeat the same test the given number of times without creating
166
167