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::Environment;
28
use Net::Domain qw(hostfqdn);
30
# Global variables keeping environment info
31
our $hostname = Net::Domain->hostfqdn();
56
my $environment = $class->SUPER::new({
65
# Obtain environmental info from host.
66
# In separate function because lots of logic is needed to parse various
67
# information based on the OS.
70
my $environment = shift;
73
my $writer = XML::Writer->new(
74
OUTPUT => \$environment_xml,
75
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
76
DATA_INDENT => 2, # number of spaces used for indentation
79
$writer->startTag('environments');
80
$writer->startTag('environment', 'id' => 0);
81
$writer->startTag('hosts');
82
$writer->startTag('host');
84
# Some elements may be empty either because
85
# a) we don't know that piece of information
86
# b) values are fetched from a database of test hosts
87
$writer->dataElement('name', $hostname);
88
$writer->dataElement('arch', $arch);
89
$writer->dataElement('kernel', $kernel);
90
$writer->dataElement('bit', $bit) if defined $bit;
91
$writer->dataElement('cpu', $cpu);
92
$writer->dataElement('memory', $memory);
93
$writer->dataElement('disk', '');
94
$writer->dataElement('role', $role);
95
$writer->dataElement('locale', $locale);
96
$writer->dataElement('encoding', $encoding);
97
$writer->dataElement('timezone', $timezone);
102
$writer->startTag('software');
104
# Note that the order of the tags under software->program is significant.
105
# Some commented tags are part of XML spec but not implemented here yet.
108
$writer->startTag('program');
109
$writer->dataElement('name', $osType);
110
$writer->dataElement('type', 'os');
111
$writer->dataElement('version', $osVer);
112
#$writer->dataElement('patch', $osPatch); # not in XML schema
113
$writer->dataElement('bit', $osBit) if defined $osBit;
114
$writer->endTag('program');
117
$writer->startTag('program');
118
$writer->dataElement('name', 'perl');
119
$writer->dataElement('type', 'perl');
120
#$writer->dataElement('version', $^V); # Solaris yields: Code point \u0005 is not a valid character in XML at lib/GenTest/XML/Environment.pm line 45
121
$writer->dataElement('version', $]);
122
$writer->dataElement('path', $^X);
123
$writer->endTag('program');
126
$writer->startTag('program');
127
$writer->dataElement('name', 'Random Query Generator');
128
$writer->dataElement('type', 'harness');
129
$writer->dataElement('version', $harnessVersion) if defined $harnessVersion;
130
$writer->dataElement('revision', $harnessRevision) if defined $harnessRevision;
131
#<xsd:element name="patch" type="xsd:string" minOccurs="0" maxOccurs="1" form="qualified"/>
132
my $rqg_path = File::Spec->rel2abs(); # assuming cwd is the randgen dir
133
$writer->dataElement('path', $rqg_path);
134
#<xsd:element name="bit" type="cassiopeia:Bits" minOccurs="0" form="qualified"/>
135
#<xsd:element name="commandline_options" type="cassiopeia:Options" minOccurs="0" form="qualified"/>
136
#<xsd:element name="commandline" minOccurs="0" type="xsd:string" form="qualified" /> # alternative to the above
137
$writer->endTag('program');
139
$writer->endTag('software');
141
$writer->endTag('host');
142
$writer->endTag('hosts');
143
$writer->endTag('environment');
144
$writer->endTag('environments');
148
return $environment_xml;
154
# First, OS-independent stuff:
156
# Grab info from bzr, assuming current dir is randgen dir.
157
# If not a bzr branch, information is undef.
158
my $bzrinfo_randgen = GenTest::BzrInfo->new(
161
# Using bzr revno as RQG version until we have something better.
163
# Update: Temporarily using revid as version (instead of revision) due to
164
# a "bug" in the XML schema where revision can only be an integer.
166
# TODO: Use revid as "revision" and revno as "version" once XML
167
# schema is fixed to accept "revision" tag as string (similar
168
# to build->revision).
170
# If the RQG starts to include a different version number,
171
# independent of the underlying version control system, we may want
172
# to use that as version and instead not report revno (revid is better to
173
# use as revision due to its ability to uniquely identify a revision
176
#$harnessVersion = 'revno'.$bzrinfo_randgen->bzrRevno();
177
#$harnessRevision = $bzrinfo_randgen->bzrRevisionId();
178
$harnessVersion = $bzrinfo_randgen->bzrRevisionId();
181
# lets see what OS type we have
186
$cpu = trim(`cat /proc/cpuinfo | grep -i "model name" | head -n 1 | cut -b 14-`);
187
my $numOfP = trim(`cat /proc/cpuinfo | grep processor |wc -l`);
188
$cpu ="$numOfP"."x"."$cpu";
190
#try to get OS Information
191
if (-e "/etc/SuSE-release"){$osVer=`cat /etc/SuSE-release |head -n 1`;}
192
elsif (-e "/etc/redhat-release"){$osVer=`cat /etc/redhat-release |head -n 1`;}
193
elsif (-e "/etc/debian_version"){$osVer=`cat /etc/debian_version |head -n 1`;}
194
else {$osVer="linux-unknown";}
196
if (-e "/etc/SuSE-release"){$osPatch=`cat /etc/SuSE-release |tail -n 1`;}
197
elsif (-e "/etc/redhat-release"){$osPatch=`cat /etc/redhat-release |tail -n 1`;}
198
elsif (-e "/etc/debian_version"){$osPatch=`cat /etc/debian_version |tail -n 1`;}
199
else {$osPatch="unknown";}
200
(my $trash, $osPatch) = split(/=/,$osPatch);
202
$arch=trim(`uname -m`);
203
# We assume something like "x86_64" from 'uname -m'. Get bit info from that.
204
($trash, $bit) = split(/_/,$arch);
205
# If nothing after '_' (or no '_' at all), assume 32-bit.
206
$bit = "32" if length($bit) < 1;
207
#$bit = undef if length($bit) < 1;
209
$osBit = $bit; # treat $osBit as $bit for now...
211
$kernel=trim(`uname -r`);
214
$memory = trim(`cat /proc/meminfo | grep -i memtotal`);
215
$memory =~ s/MemTotal: //;
216
($memory, $trash) = split(/k/,$memory);
217
$memory = trim(`cat /proc/meminfo |grep -i memtotal`);
218
$memory =~ /MemTotal:\s*(\d+)/;
219
$memory = sprintf("%.2f",($1/1024000))."GB";
222
if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
224
($locale,$encoding) = split(/\./,$locale);
225
$encoding = trim($encoding);
230
$encoding = "UNKNOWN";
234
$timezone = trim(`date +%Z`);
240
my $tmpVar = `/usr/sbin/psrinfo -v | grep -i "operates" | head -1`;
241
($cpu, my $speed) = split(/processor operates at/,$tmpVar);
245
$speed = trim($speed);
248
$speed = $speed/1000;
249
$speed = "$speed"."GHz";
253
$speed = "$speed"."MHz";
256
my $numOfP = `/usr/sbin/psrinfo -v | grep -i "operates" |wc -l`;
257
$numOfP = trim($numOfP);
258
$cpu ="$numOfP"."x"."$cpu"."$speed";
260
#try to get OS Information
261
($osType,$osVer,$arch) = split (/ /, trim(`uname -srp`));
262
# use of uname -m is discouraged (man pages), so use isainfo instead
263
$kernel = trim(`isainfo -k`);
264
$osBit = trim(`isainfo -b`);
265
my $trash; # variable functioning as /dev/null
266
($trash, $trash, my $osPatch1, my $osPatch2, $trash) = split(/ /, trim(`cat /etc/release | head -1`));
267
my $osPatch3 = `uname -v`;
268
$osPatch = $osPatch1.' '.$osPatch2.' '.$osPatch3;
269
$osPatch = trim($osPatch);
272
$memory = `/usr/sbin/prtconf | grep Memory`;
273
$memory =~ s/Memory size://;
274
$memory =~ s/Megabytes//;
275
$memory = trim($memory);
276
$memory = $memory/1024;
277
($memory, my $trash) = split(/\./,$memory);
278
$memory = "$memory"."GB";
281
if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
283
($locale, $encoding) = split(/\./,$locale);
284
$encoding = trim($encoding);
289
$encoding = "UNKNOWN";
293
$timezone = trim(`date +%Z`);
297
#$hostName = `hostname`;
301
# Assuming cygwin on Windows at this point
302
@tmpData = `cmd /c systeminfo 2>&1`;
306
# Assuming Windows at this point
307
@tmpData = `systeminfo 2>&1`;
312
carp "systeminfo command failed with: $?";
320
$timezone = "UNKNOWN";
326
# Time to get busy and grab what we need.
327
foreach my $line (@tmpData)
331
(my $numP, $cpu) = split(/\:/,$line);
333
(my $trash, $numP) = split(/\[/,$numP);
334
($numP, $trash) = split(/\]/,$numP);
335
$cpu = "$numP"."$cpu";
339
elsif ($line =~ /OS Name:\s+(.*?)\s*$/)
343
elsif ($line =~ /^OS Version:\s+(.*?)\s*$/)
347
elsif ($line =~ /System type:\s/i)
349
(my $trash, $arch) = split(/\:/,$line);
350
($arch,$trash) = split(/\-/,$arch);
353
elsif ($line =~ /^Processor/)
358
elsif ($line =~ /^Total Physical Memory:\s+(.*?)\s*$/)
362
elsif ($line =~ /Locale:/)
364
(my $trash, $locale) = split(/\:/,$line);
365
($locale, $trash) = split(/\;/,$locale);
366
$locale = trim($locale);
368
elsif ($line =~ /Time Zone:\s+(.*?)\s*$/)
377
confess "\n\nUnable to figure out OS!!\n\n";
382
print "cpu = $cpu\n";
383
print "os = $osType\n";
384
print "OS ver = $osVer\n";
385
print "Arch = $arch\n";
386
print "Kernel = $kernel\n";
387
print "memory = $memory\n";
388
print "locale = $locale\n";
389
print "Timezone = $timezone\n";
393
# Removes leading and trailing whitespace and trailing newline characters
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::Environment;
28
use Net::Domain qw(hostfqdn);
30
# Global variables keeping environment info
31
our $hostname = Net::Domain->hostfqdn();
56
my $environment = $class->SUPER::new({
65
# Obtain environmental info from host.
66
# In separate function because lots of logic is needed to parse various
67
# information based on the OS.
70
my $environment = shift;
73
my $writer = XML::Writer->new(
74
OUTPUT => \$environment_xml,
75
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
76
DATA_INDENT => 2, # number of spaces used for indentation
79
$writer->startTag('environments');
80
$writer->startTag('environment', 'id' => 0);
81
$writer->startTag('hosts');
82
$writer->startTag('host');
84
# Some elements may be empty either because
85
# a) we don't know that piece of information
86
# b) values are fetched from a database of test hosts
87
$writer->dataElement('name', $hostname);
88
$writer->dataElement('arch', $arch);
89
$writer->dataElement('kernel', $kernel);
90
$writer->dataElement('bit', $bit) if defined $bit;
91
$writer->dataElement('cpu', $cpu);
92
$writer->dataElement('memory', $memory);
93
$writer->dataElement('disk', '');
94
$writer->dataElement('role', $role);
95
$writer->dataElement('locale', $locale);
96
$writer->dataElement('encoding', $encoding);
97
$writer->dataElement('timezone', $timezone);
102
$writer->startTag('software');
104
# Note that the order of the tags under software->program is significant.
105
# Some commented tags are part of XML spec but not implemented here yet.
108
$writer->startTag('program');
109
$writer->dataElement('name', $osType);
110
$writer->dataElement('type', 'os');
111
$writer->dataElement('version', $osVer);
112
#$writer->dataElement('patch', $osPatch); # not in XML schema
113
$writer->dataElement('bit', $osBit) if defined $osBit;
114
$writer->endTag('program');
117
$writer->startTag('program');
118
$writer->dataElement('name', 'perl');
119
$writer->dataElement('type', 'perl');
120
#$writer->dataElement('version', $^V); # Solaris yields: Code point \u0005 is not a valid character in XML at lib/GenTest/XML/Environment.pm line 45
121
$writer->dataElement('version', $]);
122
$writer->dataElement('path', $^X);
123
$writer->endTag('program');
126
$writer->startTag('program');
127
$writer->dataElement('name', 'Random Query Generator');
128
$writer->dataElement('type', 'harness');
129
$writer->dataElement('version', $harnessVersion) if defined $harnessVersion;
130
$writer->dataElement('revision', $harnessRevision) if defined $harnessRevision;
131
#<xsd:element name="patch" type="xsd:string" minOccurs="0" maxOccurs="1" form="qualified"/>
132
my $rqg_path = File::Spec->rel2abs(); # assuming cwd is the randgen dir
133
$writer->dataElement('path', $rqg_path);
134
#<xsd:element name="bit" type="cassiopeia:Bits" minOccurs="0" form="qualified"/>
135
#<xsd:element name="commandline_options" type="cassiopeia:Options" minOccurs="0" form="qualified"/>
136
#<xsd:element name="commandline" minOccurs="0" type="xsd:string" form="qualified" /> # alternative to the above
137
$writer->endTag('program');
139
$writer->endTag('software');
141
$writer->endTag('host');
142
$writer->endTag('hosts');
143
$writer->endTag('environment');
144
$writer->endTag('environments');
148
return $environment_xml;
154
# First, OS-independent stuff:
156
# Grab info from bzr, assuming current dir is randgen dir.
157
# If not a bzr branch, information is undef.
158
my $bzrinfo_randgen = GenTest::BzrInfo->new(
161
# Using bzr revno as RQG version until we have something better.
163
# Update: Temporarily using revid as version (instead of revision) due to
164
# a "bug" in the XML schema where revision can only be an integer.
166
# TODO: Use revid as "revision" and revno as "version" once XML
167
# schema is fixed to accept "revision" tag as string (similar
168
# to build->revision).
170
# If the RQG starts to include a different version number,
171
# independent of the underlying version control system, we may want
172
# to use that as version and instead not report revno (revid is better to
173
# use as revision due to its ability to uniquely identify a revision
176
#$harnessVersion = 'revno'.$bzrinfo_randgen->bzrRevno();
177
#$harnessRevision = $bzrinfo_randgen->bzrRevisionId();
178
$harnessVersion = $bzrinfo_randgen->bzrRevisionId();
181
# lets see what OS type we have
186
$cpu = trim(`cat /proc/cpuinfo | grep -i "model name" | head -n 1 | cut -b 14-`);
187
my $numOfP = trim(`cat /proc/cpuinfo | grep processor |wc -l`);
188
$cpu ="$numOfP"."x"."$cpu";
190
#try to get OS Information
191
if (-e "/etc/SuSE-release"){$osVer=`cat /etc/SuSE-release |head -n 1`;}
192
elsif (-e "/etc/redhat-release"){$osVer=`cat /etc/redhat-release |head -n 1`;}
193
elsif (-e "/etc/debian_version"){$osVer=`cat /etc/debian_version |head -n 1`;}
194
else {$osVer="linux-unknown";}
196
if (-e "/etc/SuSE-release"){$osPatch=`cat /etc/SuSE-release |tail -n 1`;}
197
elsif (-e "/etc/redhat-release"){$osPatch=`cat /etc/redhat-release |tail -n 1`;}
198
elsif (-e "/etc/debian_version"){$osPatch=`cat /etc/debian_version |tail -n 1`;}
199
else {$osPatch="unknown";}
200
(my $trash, $osPatch) = split(/=/,$osPatch);
202
$arch=trim(`uname -m`);
203
# We assume something like "x86_64" from 'uname -m'. Get bit info from that.
204
($trash, $bit) = split(/_/,$arch);
205
# If nothing after '_' (or no '_' at all), assume 32-bit.
206
$bit = "32" if length($bit) < 1;
207
#$bit = undef if length($bit) < 1;
209
$osBit = $bit; # treat $osBit as $bit for now...
211
$kernel=trim(`uname -r`);
214
$memory = trim(`cat /proc/meminfo | grep -i memtotal`);
215
$memory =~ s/MemTotal: //;
216
($memory, $trash) = split(/k/,$memory);
217
$memory = trim(`cat /proc/meminfo |grep -i memtotal`);
218
$memory =~ /MemTotal:\s*(\d+)/;
219
$memory = sprintf("%.2f",($1/1024000))."GB";
222
if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
224
($locale,$encoding) = split(/\./,$locale);
225
$encoding = trim($encoding);
230
$encoding = "UNKNOWN";
234
$timezone = trim(`date +%Z`);
240
my $tmpVar = `/usr/sbin/psrinfo -v | grep -i "operates" | head -1`;
241
($cpu, my $speed) = split(/processor operates at/,$tmpVar);
245
$speed = trim($speed);
248
$speed = $speed/1000;
249
$speed = "$speed"."GHz";
253
$speed = "$speed"."MHz";
256
my $numOfP = `/usr/sbin/psrinfo -v | grep -i "operates" |wc -l`;
257
$numOfP = trim($numOfP);
258
$cpu ="$numOfP"."x"."$cpu"."$speed";
260
#try to get OS Information
261
($osType,$osVer,$arch) = split (/ /, trim(`uname -srp`));
262
# use of uname -m is discouraged (man pages), so use isainfo instead
263
$kernel = trim(`isainfo -k`);
264
$osBit = trim(`isainfo -b`);
265
my $trash; # variable functioning as /dev/null
266
($trash, $trash, my $osPatch1, my $osPatch2, $trash) = split(/ /, trim(`cat /etc/release | head -1`));
267
my $osPatch3 = `uname -v`;
268
$osPatch = $osPatch1.' '.$osPatch2.' '.$osPatch3;
269
$osPatch = trim($osPatch);
272
$memory = `/usr/sbin/prtconf | grep Memory`;
273
$memory =~ s/Memory size://;
274
$memory =~ s/Megabytes//;
275
$memory = trim($memory);
276
$memory = $memory/1024;
277
($memory, my $trash) = split(/\./,$memory);
278
$memory = "$memory"."GB";
281
if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
283
($locale, $encoding) = split(/\./,$locale);
284
$encoding = trim($encoding);
289
$encoding = "UNKNOWN";
293
$timezone = trim(`date +%Z`);
297
#$hostName = `hostname`;
301
# Assuming cygwin on Windows at this point
302
@tmpData = `cmd /c systeminfo 2>&1`;
306
# Assuming Windows at this point
307
@tmpData = `systeminfo 2>&1`;
312
carp "systeminfo command failed with: $?";
320
$timezone = "UNKNOWN";
326
# Time to get busy and grab what we need.
327
foreach my $line (@tmpData)
331
(my $numP, $cpu) = split(/\:/,$line);
333
(my $trash, $numP) = split(/\[/,$numP);
334
($numP, $trash) = split(/\]/,$numP);
335
$cpu = "$numP"."$cpu";
339
elsif ($line =~ /OS Name:\s+(.*?)\s*$/)
343
elsif ($line =~ /^OS Version:\s+(.*?)\s*$/)
347
elsif ($line =~ /System type:\s/i)
349
(my $trash, $arch) = split(/\:/,$line);
350
($arch,$trash) = split(/\-/,$arch);
353
elsif ($line =~ /^Processor/)
358
elsif ($line =~ /^Total Physical Memory:\s+(.*?)\s*$/)
362
elsif ($line =~ /Locale:/)
364
(my $trash, $locale) = split(/\:/,$line);
365
($locale, $trash) = split(/\;/,$locale);
366
$locale = trim($locale);
368
elsif ($line =~ /Time Zone:\s+(.*?)\s*$/)
377
confess "\n\nUnable to figure out OS!!\n\n";
382
print "cpu = $cpu\n";
383
print "os = $osType\n";
384
print "OS ver = $osVer\n";
385
print "Arch = $arch\n";
386
print "Kernel = $kernel\n";
387
print "memory = $memory\n";
388
print "locale = $locale\n";
389
print "Timezone = $timezone\n";
393
# Removes leading and trailing whitespace and trailing newline characters