~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/XML/Environment.pm

  • Committer: Mark Atwood
  • Date: 2011-10-14 15:59:08 UTC
  • mfrom: (2430.1.12 refactor3a)
  • Revision ID: me@mark.atwood.name-20111014155908-whqmrmaf2grpsg5c
mergeĀ lp:~olafvdspek/drizzle/refactor3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
2
 
# Use is subject to license terms.
3
 
#
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.
7
 
#
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.
12
 
#
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
16
 
# USA
17
 
 
18
 
package GenTest::XML::Environment;
19
 
 
20
 
require Exporter;
21
 
@ISA = qw(GenTest);
22
 
 
23
 
use strict;
24
 
use Carp;
25
 
use Cwd;
26
 
use File::Spec;
27
 
use GenTest;
28
 
use Net::Domain qw(hostfqdn);
29
 
 
30
 
# Global variables keeping environment info
31
 
our $hostname = Net::Domain->hostfqdn();
32
 
our $arch;
33
 
our $kernel;
34
 
our $bit;
35
 
our $cpu;
36
 
our $memory;
37
 
#our $disk;
38
 
our $role = 'server';
39
 
our $locale;
40
 
our $encoding;
41
 
our $timezone;
42
 
our $osType;
43
 
our $osVer;
44
 
our $osRev;
45
 
our $osPatch;
46
 
our $osBit;
47
 
our $harnessVersion;
48
 
our $harnessRevision;
49
 
 
50
 
 
51
 
our $DEBUG=0;
52
 
 
53
 
sub new {
54
 
    my $class = shift;
55
 
 
56
 
    my $environment = $class->SUPER::new({
57
 
    }, @_);
58
 
 
59
 
    return $environment;
60
 
}
61
 
 
62
 
sub xml {
63
 
    require XML::Writer;
64
 
 
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.
68
 
    getInfo();
69
 
 
70
 
    my $environment = shift;
71
 
    my $environment_xml;
72
 
 
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
77
 
    );
78
 
 
79
 
    $writer->startTag('environments');
80
 
    $writer->startTag('environment', 'id' => 0);
81
 
    $writer->startTag('hosts');
82
 
    $writer->startTag('host');
83
 
 
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);
98
 
 
99
 
    #
100
 
    # <software> ...
101
 
    #
102
 
    $writer->startTag('software');
103
 
 
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.
106
 
 
107
 
    # <os>
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');
115
 
 
116
 
    # <program> perl
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');
124
 
 
125
 
    # <program> harness
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');
138
 
    
139
 
    $writer->endTag('software');
140
 
 
141
 
    $writer->endTag('host');
142
 
    $writer->endTag('hosts');
143
 
    $writer->endTag('environment');
144
 
    $writer->endTag('environments');
145
 
 
146
 
    $writer->end();
147
 
 
148
 
    return $environment_xml;
149
 
}
150
 
 
151
 
sub getInfo()
152
 
{
153
 
 
154
 
    # First, OS-independent stuff:
155
 
    
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(
159
 
            dir => cwd()
160
 
    );
161
 
    # Using bzr revno as RQG version until we have something better.
162
 
    #
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.
165
 
    #
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).
169
 
    #
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
174
 
    #         over time).
175
 
    #
176
 
    #$harnessVersion = 'revno'.$bzrinfo_randgen->bzrRevno();
177
 
    #$harnessRevision = $bzrinfo_randgen->bzrRevisionId();
178
 
    $harnessVersion = $bzrinfo_randgen->bzrRevisionId();
179
 
    
180
 
    
181
 
    # lets see what OS type we have
182
 
    if (osLinux())
183
 
    {
184
 
        
185
 
        # Get the CPU info
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";
189
 
 
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";}
195
 
        $osVer=trim($osVer);
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);
201
 
        $osType="Linux";
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;
208
 
        $bit = trim($bit);
209
 
        $osBit = $bit;  # treat $osBit as $bit for now...
210
 
 
211
 
        $kernel=trim(`uname -r`);
212
 
 
213
 
        #Memory
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";
220
 
 
221
 
        #locale
222
 
        if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
223
 
        {
224
 
            ($locale,$encoding) = split(/\./,$locale);
225
 
            $encoding = trim($encoding);
226
 
        }
227
 
        else
228
 
        {
229
 
            $locale   = "UNKNOWN";
230
 
            $encoding = "UNKNOWN";
231
 
        }
232
 
 
233
 
        #TimeZone
234
 
        $timezone = trim(`date +%Z`);
235
 
    }
236
 
    elsif(osSolaris())
237
 
    {
238
 
        
239
 
        # Get the CPU info
240
 
        my $tmpVar = `/usr/sbin/psrinfo -v | grep -i "operates" | head -1`;
241
 
        ($cpu, my $speed) = split(/processor operates at/,$tmpVar);
242
 
        $cpu =~ s/The//;
243
 
        $speed =~ s/MHz//;
244
 
        $cpu = trim($cpu);
245
 
        $speed = trim($speed);
246
 
        if ($speed => 1000)
247
 
        {
248
 
            $speed = $speed/1000;
249
 
            $speed = "$speed"."GHz";
250
 
        }
251
 
        else
252
 
        {
253
 
            $speed = "$speed"."MHz";
254
 
        }
255
 
 
256
 
        my $numOfP = `/usr/sbin/psrinfo -v | grep -i "operates" |wc -l`;
257
 
        $numOfP = trim($numOfP);
258
 
        $cpu ="$numOfP"."x"."$cpu"."$speed";
259
 
 
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);
270
 
 
271
 
        #Memory
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";
279
 
 
280
 
        #locale
281
 
        if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
282
 
        {
283
 
            ($locale, $encoding) = split(/\./,$locale);
284
 
            $encoding = trim($encoding);
285
 
        }
286
 
        else
287
 
        {
288
 
            $locale   = "UNKNOWN";
289
 
            $encoding = "UNKNOWN";
290
 
        }
291
 
 
292
 
        #TimeZone
293
 
        $timezone = trim(`date +%Z`);
294
 
    }
295
 
    elsif(osWindows())
296
 
    {
297
 
        #$hostName = `hostname`;
298
 
        my @tmpData;
299
 
        if ($^O eq 'cygwin')
300
 
        {
301
 
            # Assuming cygwin on Windows at this point
302
 
            @tmpData = `cmd /c systeminfo 2>&1`;
303
 
        }
304
 
        else
305
 
        {
306
 
            # Assuming Windows at this point
307
 
            @tmpData = `systeminfo 2>&1`;
308
 
        }
309
 
 
310
 
        if ($? != 0)
311
 
        {
312
 
            carp "systeminfo command failed with: $?";
313
 
            $cpu        = "UNKNOWN";
314
 
            $osType     = "UNKNOWN";
315
 
            $osVer      = "UNKNOWN";
316
 
            $arch       = "UNKNOWN";
317
 
            $kernel     = "UNKNOWN";
318
 
            $memory     = "UNKNOWN";
319
 
            $locale     = "UNKNOWN";
320
 
            $timezone   = "UNKNOWN";
321
 
        }
322
 
        else
323
 
        {
324
 
            $kernel = "UNKOWN";
325
 
            my $cpuFlag = 0;
326
 
            # Time to get busy and grab what we need.
327
 
            foreach my $line (@tmpData)
328
 
            {
329
 
                if ($cpuFlag == 1)
330
 
                {
331
 
                    (my $numP, $cpu) = split(/\:/,$line);
332
 
                    $numP = trim($numP);
333
 
                    (my $trash, $numP) = split(/\[/,$numP);
334
 
                    ($numP, $trash) = split(/\]/,$numP);
335
 
                    $cpu = "$numP"."$cpu";
336
 
                    $cpu = trim($cpu);
337
 
                    $cpuFlag=0;
338
 
                }
339
 
                elsif ($line =~ /OS Name:\s+(.*?)\s*$/)
340
 
                {
341
 
                    $osType = $1;
342
 
                }
343
 
                elsif ($line =~ /^OS Version:\s+(.*?)\s*$/)
344
 
                {
345
 
                    $osVer = $1;
346
 
                }
347
 
                elsif ($line =~ /System type:\s/i)
348
 
                {
349
 
                    (my $trash, $arch) = split(/\:/,$line);
350
 
                    ($arch,$trash) = split(/\-/,$arch);
351
 
                    $arch = trim($arch);
352
 
                }
353
 
                elsif ($line =~ /^Processor/)
354
 
                {
355
 
                    $cpuFlag = 1;
356
 
                    next;
357
 
                }
358
 
                elsif ($line =~ /^Total Physical Memory:\s+(.*?)\s*$/)
359
 
                {
360
 
                    $memory = $1;
361
 
                }
362
 
                elsif ($line =~ /Locale:/)
363
 
                {
364
 
                    (my $trash, $locale) = split(/\:/,$line);
365
 
                    ($locale, $trash) = split(/\;/,$locale);
366
 
                    $locale = trim($locale);
367
 
                }
368
 
                elsif ($line =~ /Time Zone:\s+(.*?)\s*$/)
369
 
                {
370
 
                    $timezone = $1;
371
 
                }
372
 
            }
373
 
        }
374
 
    }
375
 
    else
376
 
    {
377
 
        confess "\n\nUnable to figure out OS!!\n\n";
378
 
    }
379
 
 
380
 
    if ($DEBUG)
381
 
    {
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";
390
 
    }
391
 
}
392
 
 
393
 
# Removes leading and trailing whitespace and trailing newline characters
394
 
sub trim($)
395
 
{
396
 
    my $string = shift;
397
 
    $string =~ s/^\s+//;
398
 
    $string =~ s/\s+$//;
399
 
    chomp($string);
400
 
    return $string;
401
 
}
402
 
 
403
 
1;
 
1
# Copyright (c) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
 
2
# Use is subject to license terms.
 
3
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
# USA
 
17
 
 
18
package GenTest::XML::Environment;
 
19
 
 
20
require Exporter;
 
21
@ISA = qw(GenTest);
 
22
 
 
23
use strict;
 
24
use Carp;
 
25
use Cwd;
 
26
use File::Spec;
 
27
use GenTest;
 
28
use Net::Domain qw(hostfqdn);
 
29
 
 
30
# Global variables keeping environment info
 
31
our $hostname = Net::Domain->hostfqdn();
 
32
our $arch;
 
33
our $kernel;
 
34
our $bit;
 
35
our $cpu;
 
36
our $memory;
 
37
#our $disk;
 
38
our $role = 'server';
 
39
our $locale;
 
40
our $encoding;
 
41
our $timezone;
 
42
our $osType;
 
43
our $osVer;
 
44
our $osRev;
 
45
our $osPatch;
 
46
our $osBit;
 
47
our $harnessVersion;
 
48
our $harnessRevision;
 
49
 
 
50
 
 
51
our $DEBUG=0;
 
52
 
 
53
sub new {
 
54
    my $class = shift;
 
55
 
 
56
    my $environment = $class->SUPER::new({
 
57
    }, @_);
 
58
 
 
59
    return $environment;
 
60
}
 
61
 
 
62
sub xml {
 
63
    require XML::Writer;
 
64
 
 
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.
 
68
    getInfo();
 
69
 
 
70
    my $environment = shift;
 
71
    my $environment_xml;
 
72
 
 
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
 
77
    );
 
78
 
 
79
    $writer->startTag('environments');
 
80
    $writer->startTag('environment', 'id' => 0);
 
81
    $writer->startTag('hosts');
 
82
    $writer->startTag('host');
 
83
 
 
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);
 
98
 
 
99
    #
 
100
    # <software> ...
 
101
    #
 
102
    $writer->startTag('software');
 
103
 
 
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.
 
106
 
 
107
    # <os>
 
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');
 
115
 
 
116
    # <program> perl
 
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');
 
124
 
 
125
    # <program> harness
 
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');
 
138
    
 
139
    $writer->endTag('software');
 
140
 
 
141
    $writer->endTag('host');
 
142
    $writer->endTag('hosts');
 
143
    $writer->endTag('environment');
 
144
    $writer->endTag('environments');
 
145
 
 
146
    $writer->end();
 
147
 
 
148
    return $environment_xml;
 
149
}
 
150
 
 
151
sub getInfo()
 
152
{
 
153
 
 
154
    # First, OS-independent stuff:
 
155
    
 
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(
 
159
            dir => cwd()
 
160
    );
 
161
    # Using bzr revno as RQG version until we have something better.
 
162
    #
 
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.
 
165
    #
 
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).
 
169
    #
 
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
 
174
    #         over time).
 
175
    #
 
176
    #$harnessVersion = 'revno'.$bzrinfo_randgen->bzrRevno();
 
177
    #$harnessRevision = $bzrinfo_randgen->bzrRevisionId();
 
178
    $harnessVersion = $bzrinfo_randgen->bzrRevisionId();
 
179
    
 
180
    
 
181
    # lets see what OS type we have
 
182
    if (osLinux())
 
183
    {
 
184
        
 
185
        # Get the CPU info
 
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";
 
189
 
 
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";}
 
195
        $osVer=trim($osVer);
 
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);
 
201
        $osType="Linux";
 
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;
 
208
        $bit = trim($bit);
 
209
        $osBit = $bit;  # treat $osBit as $bit for now...
 
210
 
 
211
        $kernel=trim(`uname -r`);
 
212
 
 
213
        #Memory
 
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";
 
220
 
 
221
        #locale
 
222
        if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
 
223
        {
 
224
            ($locale,$encoding) = split(/\./,$locale);
 
225
            $encoding = trim($encoding);
 
226
        }
 
227
        else
 
228
        {
 
229
            $locale   = "UNKNOWN";
 
230
            $encoding = "UNKNOWN";
 
231
        }
 
232
 
 
233
        #TimeZone
 
234
        $timezone = trim(`date +%Z`);
 
235
    }
 
236
    elsif(osSolaris())
 
237
    {
 
238
        
 
239
        # Get the CPU info
 
240
        my $tmpVar = `/usr/sbin/psrinfo -v | grep -i "operates" | head -1`;
 
241
        ($cpu, my $speed) = split(/processor operates at/,$tmpVar);
 
242
        $cpu =~ s/The//;
 
243
        $speed =~ s/MHz//;
 
244
        $cpu = trim($cpu);
 
245
        $speed = trim($speed);
 
246
        if ($speed => 1000)
 
247
        {
 
248
            $speed = $speed/1000;
 
249
            $speed = "$speed"."GHz";
 
250
        }
 
251
        else
 
252
        {
 
253
            $speed = "$speed"."MHz";
 
254
        }
 
255
 
 
256
        my $numOfP = `/usr/sbin/psrinfo -v | grep -i "operates" |wc -l`;
 
257
        $numOfP = trim($numOfP);
 
258
        $cpu ="$numOfP"."x"."$cpu"."$speed";
 
259
 
 
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);
 
270
 
 
271
        #Memory
 
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";
 
279
 
 
280
        #locale
 
281
        if (defined ($locale=`locale |grep LC_CTYPE| cut -b 10-`))
 
282
        {
 
283
            ($locale, $encoding) = split(/\./,$locale);
 
284
            $encoding = trim($encoding);
 
285
        }
 
286
        else
 
287
        {
 
288
            $locale   = "UNKNOWN";
 
289
            $encoding = "UNKNOWN";
 
290
        }
 
291
 
 
292
        #TimeZone
 
293
        $timezone = trim(`date +%Z`);
 
294
    }
 
295
    elsif(osWindows())
 
296
    {
 
297
        #$hostName = `hostname`;
 
298
        my @tmpData;
 
299
        if ($^O eq 'cygwin')
 
300
        {
 
301
            # Assuming cygwin on Windows at this point
 
302
            @tmpData = `cmd /c systeminfo 2>&1`;
 
303
        }
 
304
        else
 
305
        {
 
306
            # Assuming Windows at this point
 
307
            @tmpData = `systeminfo 2>&1`;
 
308
        }
 
309
 
 
310
        if ($? != 0)
 
311
        {
 
312
            carp "systeminfo command failed with: $?";
 
313
            $cpu        = "UNKNOWN";
 
314
            $osType     = "UNKNOWN";
 
315
            $osVer      = "UNKNOWN";
 
316
            $arch       = "UNKNOWN";
 
317
            $kernel     = "UNKNOWN";
 
318
            $memory     = "UNKNOWN";
 
319
            $locale     = "UNKNOWN";
 
320
            $timezone   = "UNKNOWN";
 
321
        }
 
322
        else
 
323
        {
 
324
            $kernel = "UNKOWN";
 
325
            my $cpuFlag = 0;
 
326
            # Time to get busy and grab what we need.
 
327
            foreach my $line (@tmpData)
 
328
            {
 
329
                if ($cpuFlag == 1)
 
330
                {
 
331
                    (my $numP, $cpu) = split(/\:/,$line);
 
332
                    $numP = trim($numP);
 
333
                    (my $trash, $numP) = split(/\[/,$numP);
 
334
                    ($numP, $trash) = split(/\]/,$numP);
 
335
                    $cpu = "$numP"."$cpu";
 
336
                    $cpu = trim($cpu);
 
337
                    $cpuFlag=0;
 
338
                }
 
339
                elsif ($line =~ /OS Name:\s+(.*?)\s*$/)
 
340
                {
 
341
                    $osType = $1;
 
342
                }
 
343
                elsif ($line =~ /^OS Version:\s+(.*?)\s*$/)
 
344
                {
 
345
                    $osVer = $1;
 
346
                }
 
347
                elsif ($line =~ /System type:\s/i)
 
348
                {
 
349
                    (my $trash, $arch) = split(/\:/,$line);
 
350
                    ($arch,$trash) = split(/\-/,$arch);
 
351
                    $arch = trim($arch);
 
352
                }
 
353
                elsif ($line =~ /^Processor/)
 
354
                {
 
355
                    $cpuFlag = 1;
 
356
                    next;
 
357
                }
 
358
                elsif ($line =~ /^Total Physical Memory:\s+(.*?)\s*$/)
 
359
                {
 
360
                    $memory = $1;
 
361
                }
 
362
                elsif ($line =~ /Locale:/)
 
363
                {
 
364
                    (my $trash, $locale) = split(/\:/,$line);
 
365
                    ($locale, $trash) = split(/\;/,$locale);
 
366
                    $locale = trim($locale);
 
367
                }
 
368
                elsif ($line =~ /Time Zone:\s+(.*?)\s*$/)
 
369
                {
 
370
                    $timezone = $1;
 
371
                }
 
372
            }
 
373
        }
 
374
    }
 
375
    else
 
376
    {
 
377
        confess "\n\nUnable to figure out OS!!\n\n";
 
378
    }
 
379
 
 
380
    if ($DEBUG)
 
381
    {
 
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";
 
390
    }
 
391
}
 
392
 
 
393
# Removes leading and trailing whitespace and trailing newline characters
 
394
sub trim($)
 
395
{
 
396
    my $string = shift;
 
397
    $string =~ s/^\s+//;
 
398
    $string =~ s/\s+$//;
 
399
    chomp($string);
 
400
    return $string;
 
401
}
 
402
 
 
403
1;