1
# Copyright (c) 2008, 2010 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
18
package GenTest::XML::BuildInfo;
28
use constant BUILDINFO_DSNS => 0;
29
use constant BUILDINFO_SERVERS => 1;
31
use constant BUILDINFO_SERVER_VERSION => 0;
32
use constant BUILDINFO_SERVER_PACKAGE => 1;
33
use constant BUILDINFO_SERVER_BIT => 2;
34
use constant BUILDINFO_SERVER_PATH => 3;
35
use constant BUILDINFO_SERVER_VARIABLES => 4;
36
use constant BUILDINFO_SERVER_TREE => 5;
37
use constant BUILDINFO_SERVER_REVISION => 6;
42
my $buildinfo = $class->SUPER::new({
43
dsns => BUILDINFO_DSNS
46
$buildinfo->[BUILDINFO_SERVERS] = [];
48
foreach my $id (0..$#{$buildinfo->[BUILDINFO_DSNS]})
50
my $dsn = $buildinfo->[BUILDINFO_DSNS]->[$id];
52
my $dbh = DBI->connect($dsn);
56
# TODO: Add support for non-MySQL dsns.
58
# set this first because it may be used below
59
$server->[BUILDINFO_SERVER_PATH] = $dbh->selectrow_array('SELECT @@basedir');
62
# To align with other test drivers reporting to the same place we
63
# report only the three x.y.z version numbers as "version".
64
# Expecting e.g "5.5.4-m3-log-debug", using only "5.5.4".
65
# The rest (e.g. "log-debug" as well as the version will be prepended
66
# to the value of the "package" tag instead.
67
my $long_version = $dbh->selectrow_array('SELECT @@version');
68
if ($long_version =~ /^(\d+\.\d+\.\d+)/ )
70
# grab version number only to use for version tag.
71
$server->[BUILDINFO_SERVER_VERSION] = $1;
73
# version not of the expected format, so use the whole thing.
74
$server->[BUILDINFO_SERVER_VERSION] = $long_version;
77
$server->[BUILDINFO_SERVER_PACKAGE] = $long_version . ' ' .
78
$dbh->selectrow_array('SELECT @@version_comment');
80
# Source code version-control information (tree, revision):
81
# First we check some environment variables for information:
82
# BRANCH_SOURCE - source URL as understood by the underlying version
84
# BRANCH_NAME - possibly non-unique name of the branch.
85
# PUSH_REVISION - unique ID for the current revision of the branch,
86
# as provided by the underlying version control system.
88
# If those are not present, we try to query bzr itself.
90
# This may take a few seconds due to bzr slowness.
91
my $bzrinfo_server = GenTest::BzrInfo->new(
92
dir => $server->[BUILDINFO_SERVER_PATH]
96
if (defined $ENV{'PUSH_REVISION'}) {
97
$server->[BUILDINFO_SERVER_REVISION] = $ENV{'PUSH_REVISION'};
99
# If this fails, it remains undefined and will not be reported.
100
$server->[BUILDINFO_SERVER_REVISION] = $bzrinfo_server->bzrRevisionId();
104
# Since BRANCH_NAME may not be uniquely identifying a branch, we
105
# instead use the final part of the source URL as tree (branch) name.
106
# E.g. in PB2, we may have both daily-trunk and mysql-trunk referring
107
# to the same branch.
108
if (defined $ENV{'BRANCH_SOURCE'}) {
109
# extract last part of source URL and use as tree name.
111
# http://host.com/bzr/server/mysql-next-mr
112
# becomes "mysql-next-mr".
113
# Need to account for possible ending '/'.
114
if ($ENV{BRANCH_SOURCE} =~ m{([^\\\/]+)[\\\/]?$}) {
115
$server->[BUILDINFO_SERVER_TREE] = $1;
118
if (defined $ENV{'BRANCH_NAME'}) {
119
$server->[BUILDINFO_SERVER_TREE] = $ENV{'BRANCH_NAME'};
121
# Get branch nick from bzr
122
# If this fails, it remains undefined and will not be reported.
123
$server->[BUILDINFO_SERVER_TREE] = $bzrinfo_server->bzrBranchNick();
127
# According to the schema, bit must be "32" or "64".
128
# There is no reliable way to get this on all supported platforms using MySQL queries.
129
#$server->[BUILDINFO_SERVER_BIT] = $dbh->selectrow_array('SELECT @@version_compile_machine');
131
$server->[BUILDINFO_SERVER_VARIABLES] = [];
132
my $sth = $dbh->prepare("SHOW VARIABLES");
134
while (my ($name, $value) = $sth->fetchrow_array()) {
135
push @{$server->[BUILDINFO_SERVER_VARIABLES]}, [ $name , $value ];
141
$buildinfo->[BUILDINFO_SERVERS]->[$id] = $server;
150
my $buildinfo = shift;
153
my $writer = XML::Writer->new(
154
OUTPUT => \$buildinfo_xml,
155
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
156
DATA_INDENT => 2, # number of spaces used for indentation
159
$writer->startTag('product');
160
$writer->dataElement('name','MySQL');
161
$writer->startTag('builds');
163
foreach my $id (0..$#{$buildinfo->[BUILDINFO_DSNS]})
165
my $server = $buildinfo->[BUILDINFO_SERVERS]->[$id];
166
next if not defined $server;
168
# Note that the order of these tags (sequence) is significant.
169
# Commented tags are part of XML spec but not implemented here yet.
171
$writer->startTag('build', id => $id);
172
$writer->dataElement('version', $server->[BUILDINFO_SERVER_VERSION]);
173
$writer->dataElement('tree', $server->[BUILDINFO_SERVER_TREE]) if defined $server->[BUILDINFO_SERVER_TREE];
174
$writer->dataElement('revision', $server->[BUILDINFO_SERVER_REVISION]) if defined $server->[BUILDINFO_SERVER_REVISION];
175
#<xsd:element name="tag" type="xsd:string" minOccurs="0" form="qualified"/>
176
$writer->dataElement('package', $server->[BUILDINFO_SERVER_PACKAGE]);
177
#$writer->dataElement('bit', $server->[BUILDINFO_SERVER_BIT]); # Must be 32 or 64
178
$writer->dataElement('path', $server->[BUILDINFO_SERVER_PATH]);
179
#<xsd:element name="compile_options" type="cassiopeia:Options" minOccurs="0" form="qualified"/>
180
#<xsd:element name="commandline" type="xsd:string" minOccurs="0" form="qualified" />
181
#<xsd:element name="buildscript" minOccurs="0" type="xsd:string" form="qualified" />
182
$writer->endTag('build');
186
$writer->endTag('builds');
188
$writer->startTag('binaries'); # --> <software> = <program>
190
foreach my $id (0..$#{$buildinfo->[BUILDINFO_DSNS]})
192
my $server = $buildinfo->[BUILDINFO_SERVERS]->[$id];
193
next if not defined $server;
195
$writer->startTag('program');
196
$writer->dataElement('name', 'mysqld');
197
$writer->dataElement('type', 'database');
198
$writer->startTag('commandline_options');
200
# TODO: List actual commmand-line options (and config file options /
201
# RQG-defaults?), not all server variables?
202
foreach my $option (@{$server->[BUILDINFO_SERVER_VARIABLES]})
204
$writer->startTag('option');
205
$writer->dataElement('name', $option->[0]);
206
$writer->dataElement('value', $option->[1]);
207
$writer->endTag('option');
210
$writer->endTag('commandline_options');
211
$writer->endTag('program');
214
$writer->endTag('binaries');
215
$writer->endTag('product');
218
return $buildinfo_xml;
1
# Copyright (c) 2008, 2010 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
18
package GenTest::XML::BuildInfo;
28
use constant BUILDINFO_DSNS => 0;
29
use constant BUILDINFO_SERVERS => 1;
31
use constant BUILDINFO_SERVER_VERSION => 0;
32
use constant BUILDINFO_SERVER_PACKAGE => 1;
33
use constant BUILDINFO_SERVER_BIT => 2;
34
use constant BUILDINFO_SERVER_PATH => 3;
35
use constant BUILDINFO_SERVER_VARIABLES => 4;
36
use constant BUILDINFO_SERVER_TREE => 5;
37
use constant BUILDINFO_SERVER_REVISION => 6;
42
my $buildinfo = $class->SUPER::new({
43
dsns => BUILDINFO_DSNS
46
$buildinfo->[BUILDINFO_SERVERS] = [];
48
foreach my $id (0..$#{$buildinfo->[BUILDINFO_DSNS]})
50
my $dsn = $buildinfo->[BUILDINFO_DSNS]->[$id];
52
my $dbh = DBI->connect($dsn);
56
# TODO: Add support for non-MySQL dsns.
58
# set this first because it may be used below
59
$server->[BUILDINFO_SERVER_PATH] = $dbh->selectrow_array('SELECT @@basedir');
62
# To align with other test drivers reporting to the same place we
63
# report only the three x.y.z version numbers as "version".
64
# Expecting e.g "5.5.4-m3-log-debug", using only "5.5.4".
65
# The rest (e.g. "log-debug" as well as the version will be prepended
66
# to the value of the "package" tag instead.
67
my $long_version = $dbh->selectrow_array('SELECT @@version');
68
if ($long_version =~ /^(\d+\.\d+\.\d+)/ )
70
# grab version number only to use for version tag.
71
$server->[BUILDINFO_SERVER_VERSION] = $1;
73
# version not of the expected format, so use the whole thing.
74
$server->[BUILDINFO_SERVER_VERSION] = $long_version;
77
$server->[BUILDINFO_SERVER_PACKAGE] = $long_version . ' ' .
78
$dbh->selectrow_array('SELECT @@version_comment');
80
# Source code version-control information (tree, revision):
81
# First we check some environment variables for information:
82
# BRANCH_SOURCE - source URL as understood by the underlying version
84
# BRANCH_NAME - possibly non-unique name of the branch.
85
# PUSH_REVISION - unique ID for the current revision of the branch,
86
# as provided by the underlying version control system.
88
# If those are not present, we try to query bzr itself.
90
# This may take a few seconds due to bzr slowness.
91
my $bzrinfo_server = GenTest::BzrInfo->new(
92
dir => $server->[BUILDINFO_SERVER_PATH]
96
if (defined $ENV{'PUSH_REVISION'}) {
97
$server->[BUILDINFO_SERVER_REVISION] = $ENV{'PUSH_REVISION'};
99
# If this fails, it remains undefined and will not be reported.
100
$server->[BUILDINFO_SERVER_REVISION] = $bzrinfo_server->bzrRevisionId();
104
# Since BRANCH_NAME may not be uniquely identifying a branch, we
105
# instead use the final part of the source URL as tree (branch) name.
106
# E.g. in PB2, we may have both daily-trunk and mysql-trunk referring
107
# to the same branch.
108
if (defined $ENV{'BRANCH_SOURCE'}) {
109
# extract last part of source URL and use as tree name.
111
# http://host.com/bzr/server/mysql-next-mr
112
# becomes "mysql-next-mr".
113
# Need to account for possible ending '/'.
114
if ($ENV{BRANCH_SOURCE} =~ m{([^\\\/]+)[\\\/]?$}) {
115
$server->[BUILDINFO_SERVER_TREE] = $1;
118
if (defined $ENV{'BRANCH_NAME'}) {
119
$server->[BUILDINFO_SERVER_TREE] = $ENV{'BRANCH_NAME'};
121
# Get branch nick from bzr
122
# If this fails, it remains undefined and will not be reported.
123
$server->[BUILDINFO_SERVER_TREE] = $bzrinfo_server->bzrBranchNick();
127
# According to the schema, bit must be "32" or "64".
128
# There is no reliable way to get this on all supported platforms using MySQL queries.
129
#$server->[BUILDINFO_SERVER_BIT] = $dbh->selectrow_array('SELECT @@version_compile_machine');
131
$server->[BUILDINFO_SERVER_VARIABLES] = [];
132
my $sth = $dbh->prepare("SHOW VARIABLES");
134
while (my ($name, $value) = $sth->fetchrow_array()) {
135
push @{$server->[BUILDINFO_SERVER_VARIABLES]}, [ $name , $value ];
141
$buildinfo->[BUILDINFO_SERVERS]->[$id] = $server;
150
my $buildinfo = shift;
153
my $writer = XML::Writer->new(
154
OUTPUT => \$buildinfo_xml,
155
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
156
DATA_INDENT => 2, # number of spaces used for indentation
159
$writer->startTag('product');
160
$writer->dataElement('name','MySQL');
161
$writer->startTag('builds');
163
foreach my $id (0..$#{$buildinfo->[BUILDINFO_DSNS]})
165
my $server = $buildinfo->[BUILDINFO_SERVERS]->[$id];
166
next if not defined $server;
168
# Note that the order of these tags (sequence) is significant.
169
# Commented tags are part of XML spec but not implemented here yet.
171
$writer->startTag('build', id => $id);
172
$writer->dataElement('version', $server->[BUILDINFO_SERVER_VERSION]);
173
$writer->dataElement('tree', $server->[BUILDINFO_SERVER_TREE]) if defined $server->[BUILDINFO_SERVER_TREE];
174
$writer->dataElement('revision', $server->[BUILDINFO_SERVER_REVISION]) if defined $server->[BUILDINFO_SERVER_REVISION];
175
#<xsd:element name="tag" type="xsd:string" minOccurs="0" form="qualified"/>
176
$writer->dataElement('package', $server->[BUILDINFO_SERVER_PACKAGE]);
177
#$writer->dataElement('bit', $server->[BUILDINFO_SERVER_BIT]); # Must be 32 or 64
178
$writer->dataElement('path', $server->[BUILDINFO_SERVER_PATH]);
179
#<xsd:element name="compile_options" type="cassiopeia:Options" minOccurs="0" form="qualified"/>
180
#<xsd:element name="commandline" type="xsd:string" minOccurs="0" form="qualified" />
181
#<xsd:element name="buildscript" minOccurs="0" type="xsd:string" form="qualified" />
182
$writer->endTag('build');
186
$writer->endTag('builds');
188
$writer->startTag('binaries'); # --> <software> = <program>
190
foreach my $id (0..$#{$buildinfo->[BUILDINFO_DSNS]})
192
my $server = $buildinfo->[BUILDINFO_SERVERS]->[$id];
193
next if not defined $server;
195
$writer->startTag('program');
196
$writer->dataElement('name', 'mysqld');
197
$writer->dataElement('type', 'database');
198
$writer->startTag('commandline_options');
200
# TODO: List actual commmand-line options (and config file options /
201
# RQG-defaults?), not all server variables?
202
foreach my $option (@{$server->[BUILDINFO_SERVER_VARIABLES]})
204
$writer->startTag('option');
205
$writer->dataElement('name', $option->[0]);
206
$writer->dataElement('value', $option->[1]);
207
$writer->endTag('option');
210
$writer->endTag('commandline_options');
211
$writer->endTag('program');
214
$writer->endTag('binaries');
215
$writer->endTag('product');
218
return $buildinfo_xml;