-
Notifications
You must be signed in to change notification settings - Fork 36
/
dbdpg_test_postgres_versions.pl
executable file
·240 lines (197 loc) · 7.22 KB
/
dbdpg_test_postgres_versions.pl
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env perl
## Test combinations of Postgres for DBD::Pg
## Usage: $0 <postgresdir> [-t specific_test_file] [-c compile_version] [-r run_version] [--setup versions]
## Usage:
## Create Postgres 11,12,13,14, and 15 directories in $ENV{HOME}/pg/:
## perl dbdpg_test_postgres_versions.pl --setup 11,12,13,14,15
## Test all combinations of the same:
## perl dbdpg_test_postgres_versions.pl
## Only run for versions 12 and up:
## perl dbdpg_test_postgres_versions.pl --minversion 11
## Same, but do not run head
## perl dbdpg_test_postgres_versions.pl --minversion 11 --nohead
## Add in the current HEAD branch, recreating if already there:
## perl dbdpg_test_postgres_versions.pl --setup head --force
## Test DBD::Pg compiled against head and run against Postgres 11:
## perl dbdpg_test_postgres_versions.pl -c head -r 11
use 5.008001;
use strict;
use warnings;
use autodie;
use Cwd;
use File::Spec::Functions;
use Getopt::Long qw/ GetOptions /;
use Data::Dumper; $Data::Dumper::Sortkeys = 1;
use Time::HiRes qw/ gettimeofday tv_interval /;
use List::Util qw/ shuffle /;
our $VERSION = 1.5;
my %arg = (
quiet => 0,
minversion => '',
nohead => 0,
);
GetOptions
(
\%arg,
'verbose',
'quiet',
'testfile=s',
'compileversion=s',
'runversion=s',
'wipe',
'setup=s',
'minversion=s',
'nohead',
);
my $testfile = $arg{testfile} || $ENV{DBDPG_TEST_FILE} || '';
my $compileversion = $arg{compileversion} || $ENV{DBDPG_COMPILE_VERSION} || '';
my $runversion = $arg{runversion} || $ENV{DBDPG_RUN_VERSION} || '';
my $basedir = shift || "$ENV{HOME}/pg";
setup_postgres_dirs() if $arg{setup};
my $dh;
opendir $dh, $basedir;
my @versions = grep { /^[1-9][0-9]$/ or /^head$/i } readdir $dh;
closedir $dh;
if ($arg{minversion} =~ /^[0-9]+$/) {
@versions = grep { ! /^[0-9]+$/ or $_ >= $arg{minversion} } @versions;
}
if ($arg{nohead}) {
@versions = grep { ! /head/ } @versions;
}
## Sanity check:
for my $lver (@versions) {
my $libdir = "$basedir/$lver/lib";
-d $libdir or die qq{Could not find directory: $libdir\n};
}
if ($arg{wipe}) {
opendir $dh, 'tmp';
for my $file (grep { /^alltest\.dbdpg.+\.log$/ } readdir $dh) {
unlink "tmp/$file";
}
}
my $summaryfile = 'tmp/summary.testallversions.log';
open my $sfh, ($arg{wipe} ? '>' : '>>'), $summaryfile;
printf {$sfh} "\nSTARTED $0 at %s\n\n", scalar localtime;
sub note {
my $message = shift or die;
chomp $message;
$arg{quiet} or print "$message\n";
print {$sfh} "$message\n";
return;
}
my $debug_loop = 0;
for my $lib_version (shuffle @versions) {
next if $compileversion and $compileversion !~ /\b$lib_version\b/;
my $lib_dir = "$basedir/$lib_version";
for my $target_version (shuffle @versions) {
next if $runversion and $runversion !~ /\b$target_version\b/;
my $target_dir = "$basedir/$target_version";
my $readme = 'README.testdatabase';
unlink $readme if -e $readme;
my $testdbdir = 'dbdpg_test_database';
if (-d $testdbdir) {
system("/bin/rm -fr $testdbdir");
}
my $outfile = "tmp/alltest.dbdpg.$lib_version.vs.$target_version.log";
note "Testing compile $lib_version against target $target_version: results stored in $outfile";
open my $fh, '>', $outfile;
printf {$fh} "STARTED $lib_version vs $target_version: %s\n\n", scalar localtime;
my $start_time = [gettimeofday];
system "perl t/99cleanup.t >> $outfile";
my $COM = "LD_LIBRARY_PATH=$lib_dir/lib POSTGRES_LIB= POSTGRES_INCLUDE= POSTGRES_HOME=$lib_dir perl Makefile.PL 2>&1 >> $outfile";
note "--> $COM";
print {$fh} "***\nRUN: $COM\n***\n\n\n";
print {$fh} qx{$COM};
$COM = "LD_LIBRARY_PATH=$lib_dir/lib DBDPG_TEST_ALWAYS_ENV=0 AUTHOR_TESTING=0 TEST_SIGNATURE=0 DBDPG_INITDB=$target_dir/bin/initdb make test TEST_VERBOSE=1 2>&1 >> $outfile";
$testfile and $COM =~ s/make test/make test TEST_FILES=$testfile/;
note "--> $COM";
print {$fh} "***\nRUN: $COM\n***\n\n\n";
print {$fh} qx{$COM};
my $final_time = sprintf '%d seconds', tv_interval($start_time);
print {$fh} "\nTIME: $final_time\n";
close $fh;
my $final_line = qx{tail -1 $outfile};
chomp $final_line;
my $date = scalar localtime;
if ($final_line !~ /Result/) {
$final_line = "Result: FAIL $final_line";
}
note "--> $final_line $lib_version vs $target_version ($date) ($final_time)\n\n";
if ($debug_loop++ > 300) {
die "Leaving at loop $debug_loop\n";
}
## Just in case we want to catch something
if ($final_line =~ /FAIL/) {
warn "Got a failure. Hit Enter to continue, or break out to examine it\n";
<STDIN>;
}
sleep 1;
}
}
close $sfh;
exit;
sub setup_postgres_dirs {
## Create Postgres directories for one or more versions
my $versions = $arg{setup};
warn "Setup for version: $versions on dir $basedir\n";
## Must have a head
my $giturl = 'https://github.com/postgres/postgres.git';
my $dir = catfile($basedir, 'pg_github');
if (-e $dir) {
chdir $dir;
system 'git checkout --quiet master';
system "git pull --quiet -X theirs origin master";
}
else {
system "git clone $giturl $dir";
}
## Grab a list of all tags
my $old_dir = getcwd();
chdir($dir);
my @taglist = qx{git tag -l};
my %maxversion = (head => ['master','master']);
for my $entry (@taglist) {
chomp $entry;
if ($entry =~ /^REL_?(\d_\d)_(\d+)$/ or $entry =~ /^REL_?(\d\d)_(\d+)$/) {
my ($major,$revision) = ($1,$2);
$major =~ y/_/./;
$maxversion{$major} = [$entry,$revision] if ! exists $maxversion{$major}
or $maxversion{$major}->[1] < $revision;
}
}
for my $version (split /\s*,\s*/ => lc $arg{setup}) {
exists $maxversion{$version} or die "Cannot find a tag for Postgres version $version\n";
my $newdir = catfile($basedir, $version);
my $install = 0;
if (-e $newdir) {
print "Directory already exists: $newdir\n";
## However, there may be a newer version!
my ($existing_revision) = qx{$newdir/bin/psql --version} =~ /\.(\d+)$/;
if ($existing_revision < $maxversion{$version}->[1]) {
printf "For version %s, have revision %d but need %s\n",
$version, $existing_revision, $maxversion{$version}->[1];
$install = 1;
}
else {
print "We appear to have the latest revision: $existing_revision\n";
}
}
else {
$install = 1;
}
if ($install) {
chdir($dir);
my $tag = $maxversion{$version}->[0];
system "git checkout $tag";
system 'git clean -fdx';
my $COM = "./configure --prefix=$newdir --quiet";
if ($version =~ /^\d/ and $version <= 9.0) {
$COM .= ' CFLAGS="-Wno-aggressive-loop-optimizations -O0"';
}
print "Running: $COM\n";
system $COM;
system 'make install';
}
}
exit;
} ## end of setup_postgres_dirs