Info/Linux.pm

filter: Statementstmt 86.1% 192 / 223 Branchbran 68.3% 97 / 142 Conditioncond 63.9% 55 / 86 MC/DCmcdc 43.1% 22 / 51 Subroutinesub 94.1% 16 / 17 Podpod 100% 11 / 11 totaltotal 74.1% 393 / 530 CC 110 SCAR 37.3
CC
110
Cov
76%
prepare_os
67.9
_lsb_release
63.6
linux_generic
30.0
CRAP 41.5
« Info/HPUX.pm ↑ Summary Info/AIX.pm »
1 package System::Info::Linux;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base "System::Info::Base";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = "0.055";
9  
10 =head1 NAME
11  
12 System::Info::Linux - Object for specific Linux info.
13  
14 =head1 DESCRIPTION
15  
16 =head2 $si->prepare_sysinfo
17  
18 Use os-specific tools to find out more about the system.
19  
20 =cut
21  
22 137 ▶sub prepare_sysinfo {
Subroutine prepare_sysinfo: called CC=8 SCAR=21.5
Pod documented
23 137 my $self = shift;
24 137 $self->SUPER::prepare_sysinfo;
25 137 $self->prepare_os;
26 137 ▶ $self->prepare_proc_cpuinfo or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->prepare_proc_cpuinfo or return 137 0 137
27  
28 137 for ($self->get_cpu_type) {
29 137 ▶ m/arm/ and do { $self->linux_arm; last };
Branch: 1 branch
BranchTrueFalseTotal
/arm/ and do { $self->linux_arm; last } 3 134 137
30 0 ▶ m/aarch64/ and do { $self->linux_arm; last };
Branch: 1 branch
BranchTrueFalseTotal
/aarch64/ and do { $self->linux_arm; last } 0 134 134
31 134 ▶ m/ppc/ and do { $self->linux_ppc; last };
Branch: 1 branch
BranchTrueFalseTotal
/ppc/ and do { $self->linux_ppc; last } 1 133 134
32 0 ▶ m/sparc/ and do { $self->linux_sparc; last };
Branch: 1 branch
BranchTrueFalseTotal
/sparc/ and do { $self->linux_sparc; last } 0 133 133
33 133 ▶ m/s390x/ and do { $self->linux_s390x; last };
Branch: 1 branch
BranchTrueFalseTotal
/s390x/ and do { $self->linux_s390x; last } 2 131 133
34 # default
35 131 $self->linux_generic;
36 }
37 137 return $self;
38 } # prepare_sysinfo
39  
40 =head2 $si->prepare_os
41  
42 Use os-specific tools to find out more about the operating system.
43  
44 =cut
45  
46 551 ▶sub _file_info {
Subroutine _file_info: called CC=11 SCAR=24.0
47 551 my ($file, $os) = @_;
48 551 ▶ open my $fh, "<", $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return 551 0 551
49 551 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 2477 551 3028
50 2477 ▶ m/^\s*[;#]/ and next;
Branch: 1 branch
BranchTrueFalseTotal
/^\s*[;#]/ and next 12 2465 2477
51 2465 chomp;
52 2465 ▶ m/\S/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/\S/ or next 2277 188 2465
53 2277 s/^\s+//;
54 2277 s/\s+$//;
55 2277 ▶ if (my ($k, $v) = (m/^\s*(.*\S)\s*=\s*(\S.*?)\s*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = /^\s*(.*\S)\s*=\s*(\S.*?)\s*$/) 1779 498 2277
56 # Having a value prevails over being defined
57 1779 ▶ defined $os->{$k} and next;
Branch: 1 branch
BranchTrueFalseTotal
defined $os->{$k} and next 12 1767 1779
58 1767 $v =~ s/^"\s*(.*?)\s*"$/$1/;
59 1767 $v =~ s/^'\s*(.*?)\s*'$/$1/;
60 1767 ▶ $v =~ m{^["(]?undef(?:ined)?[")]$}i and $v = "undefined";
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /^["(]?undef(?:ined)?[")]$/i and $v = "undefined" 39 1728 1767
61 1767 $os->{$k} = $v;
62 1767 next;
63 }
64 498 ▶ m/^[12][0-9]{3}(?:,\s*[12][0-9]{3})*(?:\s*,\s*)*$/ and next; # Copyright years
Branch: 1 branch
BranchTrueFalseTotal
/^[12][0-9]{3}(?:,\s*[12][0-9]{3})*(?:\s*,\s*)*$/ and next 3 495 498
65 495 ▶ m/^[12][0-9]{3}(?:,\s*[12][0-9]{3})*.*All rights reserved/i and next; # Copyright years
Branch: 1 branch
BranchTrueFalseTotal
/^[12][0-9]{3}(?:,\s*[12][0-9]{3})*.*All rights reserved/i and next 1 494 495
66 494 ▶ exists $os->{$_} or $os->{$_} = undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $os->{$_} or $os->{$_} = undef 100 394 494
67 }
68 551 close $fh;
69 } # _file_info
70  
71 137 ▶sub _lsb_release {
Subroutine _lsb_release: called CC=11 SCAR=41.5
72 137 my $os = shift;
73  
74 137 ▶ $ENV{SMOKE_USE_ETC} and return;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SMOKE_USE_ETC"} and return 121 16 137
75  
76 $os->{DISTRIB_ID} || $os->{DISTRIB_RELEASE} || $os->{DISTRIB_CODENAME}
77 16 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
$os->{"DISTRIB_ID"} || $os->{"DISTRIB_RELEASE"} || $os->{"DISTRIB_CODENAME"} and return 16 0 16
Condition33%2/6
$os->{"DISTRIB_ID"} or $os->{"DISTRIB_RELEASE"} or $os->{"DISTRIB_CODENAME"}
l!l&&r!l&&!r
1600
$os->{"DISTRIB_ID"} or $os->{"DISTRIB_RELEASE"}
l!l&&r!l&&!r
1600
MC/DC0%0/3
$os->{"DISTRIB_ID"} or $os->{"DISTRIB_RELEASE"} or $os->{"DISTRIB_CODENAME"}
$os->{"DISTRIB_ID"} $os->{"DISTRIB_RELEASE"} $os->{"DISTRIB_CODENAME"}
Truth table25%1/4
A or B or C
A= $os->{"DISTRIB_ID"}B= $os->{"DISTRIB_RELEASE"}C= $os->{"DISTRIB_CODENAME"}
ABCresult
1XX1
01X1
0011
0000
78  
79 0 ▶ open my $ch, "lsb_release -a 2>&1 |" or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $ch, "lsb_release -a 2>&1 |" or return 0 0 0
80 0 my %map = (
81 "LSB Version" => "don't care",
82 "Distributor ID" => "DISTRIB_ID",
83 "Description" => "DISTRIB_DESCRIPTION",
84 "Release" => "DISTRIB_RELEASE",
85 "Code" => "DISTRIB_CODENAME",
86 );
87 0 ▶ while (<$ch>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $ch)) 0 0 0
88 0 chomp;
89 0 ▶ m/^\s*(\S.*?)\s*:\s*(.*?)\s*$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\s*(\S.*?)\s*:\s*(.*?)\s*$/ or next 0 0 0
90 0 ▶ $os->{$map{$1} || $1} ||= $2 unless $2 eq "n/a";
Branch: 1 branch
BranchTrueFalseTotal
unless $2 eq "n/a" 0 0 0
Condition0%0/6
$$os{$map{$1} or $1} ||= $2
l!l&&r!l&&!r
000
$map{$1} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$$os{$map{$1} or $1} ||= $2
$$os{$map{$1} or $1} $2
MC/DC0%0/2
$map{$1} || $1
$map{$1} $1
Truth table0%0/3
A ||= B
A= $$os{$map{$1} or $1}B= $2
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $map{$1}B= $1
ABresult
1X1
011
000
91 }
92 } # _lsb_release
93  
94 137 ▶sub prepare_os {
Subroutine prepare_os: called CC=55 SCAR=42.2
Pod documented
95 137 my $self = shift;
96  
97 137 ▶ my $etc = $ENV{SMOKE_USE_ETC} || "/etc";
Condition100%2/2
$ENV{'SMOKE_USE_ETC'} || '/etc'
l!l
12116
MC/DC100%1/1
$ENV{'SMOKE_USE_ETC'} || '/etc'
$ENV{'SMOKE_USE_ETC'}
Truth table100%2/2
A
A= $ENV{'SMOKE_USE_ETC'}
Aresult
11
00
98 1142 ▶ my @dist_file = grep { -f $_ && -s _ } map {
Condition100%3/3
-f $_ && -s _
!ll&&!rl&&r
414177551
MC/DC100%2/2
-f $_ && -s _
-f $_ -s _
Truth table100%3/3
A && B
A= -f $_B= -s _
ABresult
0X0
100
111
99 3 ▶ -d $_ ? glob ("$_/*") : ($_)
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
-d $_ ? : 22 969 991
100 } glob ("$etc/*[-_][rRvV][eE][lLrR]*"), "$etc/issue",
101 "$etc.defaults/VERSION", "$etc/VERSION", "$etc/release";
102  
103 137 my $os = $self->_os;
104 137 my %os;
105 my $distro;
106 137 foreach my $df (@dist_file) {
107 # use "debian" out of /etc/debian-release
108 551 ▶ unless (defined $distro or $df =~ m/\blsb-/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $distro or $df =~ /\blsb-/) 137 414 551
Condition100%3/3
defined $distro or $df =~ /\blsb-/
l!l&&r!l&&!r
39519137
MC/DC100%2/2
defined $distro or $df =~ /\blsb-/
defined $distro $df =~ /\blsb-/
Truth table100%3/3
A or B
A= defined $distroB= $df =~ /\blsb-/
ABresult
1X1
011
000
109 137 ($distro = $df) =~ s{^$etc(?:\.defaults)?/}{}i;
110 137 $distro =~ s{[-_]?(?:release|version)\b}{}i;
111 }
112 551 _file_info ($df, \%os);
113 }
114 137 _lsb_release (\%os);
115  
116 137 ▶ keys %os or return;
Branch: 1 branch
BranchTrueFalseTotal
keys %os or return 137 0 137
117  
118 137 foreach my $key (keys %os) {
119 2161 my $KEY = uc $key;
120 2161 ▶ defined $os{$key} or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $os{$key} or next 1767 394 2161
121 1767 ▶ exists $os{$KEY} or $os{$KEY} = $os{$key};
Branch: 1 branch
BranchTrueFalseTotal
exists $os{$KEY} or $os{$KEY} = $os{$key} 1668 99 1767
122 }
123  
124 137 ▶ if ($os{DISTRIB_DESCRIPTION}) {
Branch: 7 branches
BranchTrueFalseTotal
if ($os{'DISTRIB_DESCRIPTION'}) { } 29 108 137
elsif ($os{'DISTRIBVER'} and defined $os{'NETBSD_OFFICIAL_RELEASE'}) { } 1 107 108
elsif ($os{'PRETTY_NAME'}) { } 76 31 107
elsif ($os{'VERSION'} and $os{'NAME'}) { } 0 31 31
elsif ($os{'VERSION'} and $os{'CODENAME'}) { } 1 30 31
elsif ($os{'MAJORVERSION'} and defined $os{'MINORVERSION'}) { } 11 19 30
elsif ($os{'DISTRIBVER'} and exists $os{'NETBSDSRCDIR'}) { } 2 17 19
125 29 $distro = $os{DISTRIB_DESCRIPTION};
126 29 ▶ $os{DISTRIB_CODENAME} && $distro !~ m{\b$os{DISTRIB_CODENAME}\b}i and
Branch: 1 branch
BranchTrueFalseTotal
$os{"DISTRIB_CODENAME"} and not $distro =~ /\b$os{"DISTRIB_CODENAME"}\b/i and $distro .= qq[ ($os{"DISTRIB_CODENAME"})] 25 4 29
Condition100%3/3
$os{"DISTRIB_CODENAME"} and not $distro =~ /\b$os{"DISTRIB_CODENAME"}\b/i
!ll&&!rl&&r
1325
MC/DC100%2/2
$os{"DISTRIB_CODENAME"} and not $distro =~ /\b$os{"DISTRIB_CODENAME"}\b/i
$os{"DISTRIB_CODENAME"} not $distro =~ /\b$os{"DISTRIB_CODENAME"}\b/i
Truth table100%3/3
A and not(B)
A= $os{"DISTRIB_CODENAME"}B= not $distro =~ /\b$os{"DISTRIB_CODENAME"}\b/i
ABresult
0X0
100
111
127 $distro .= " ($os{DISTRIB_CODENAME})";
128 29 ▶ if ($os{VERSION_ID} && $distro !~ m{\b$os{VERSION_ID}\b}i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($os{'VERSION_ID'} and not $distro =~ /\b$os{'VERSION_ID'}\b/i) { } 1 28 29
elsif ($os{'DISTRIB_RELEASE'} and not $distro =~ /\b$os{'DISTRIB_RELEASE'}\b/i) { } 0 28 28
Condition100%3/3
$os{"VERSION_ID"} and not $distro =~ /\b$os{"VERSION_ID"}\b/i
!ll&&!rl&&r
3251
MC/DC100%2/2
$os{"VERSION_ID"} and not $distro =~ /\b$os{"VERSION_ID"}\b/i
$os{"VERSION_ID"} not $distro =~ /\b$os{"VERSION_ID"}\b/i
Truth table100%3/3
A and not(B)
A= $os{"VERSION_ID"}B= not $distro =~ /\b$os{"VERSION_ID"}\b/i
ABresult
0X0
100
111
129 1 $distro .= " $os{VERSION_ID}";
130 }
131 ▶ elsif ($os{DISTRIB_RELEASE} && $distro !~ m{\b$os{DISTRIB_RELEASE}\b}i) {
Condition33%1/3
$os{"DISTRIB_RELEASE"} and not $distro =~ /\b$os{"DISTRIB_RELEASE"}\b/i
!ll&&!rl&&r
0280
MC/DC0%0/2
$os{"DISTRIB_RELEASE"} and not $distro =~ /\b$os{"DISTRIB_RELEASE"}\b/i
$os{"DISTRIB_RELEASE"} not $distro =~ /\b$os{"DISTRIB_RELEASE"}\b/i
Truth table33%1/3
A and not(B)
A= $os{"DISTRIB_RELEASE"}B= not $distro =~ /\b$os{"DISTRIB_RELEASE"}\b/i
ABresult
0X0
100
111
132 0 $distro .= " $os{DISTRIB_RELEASE}";
133 }
134 }
135 ▶ elsif ($os{DISTRIBVER} && defined $os{NETBSD_OFFICIAL_RELEASE}) { # NetBSD 9
Condition100%3/3
$os{"DISTRIBVER"} and defined $os{"NETBSD_OFFICIAL_RELEASE"}
!ll&&!rl&&r
10521
MC/DC100%2/2
$os{"DISTRIBVER"} and defined $os{"NETBSD_OFFICIAL_RELEASE"}
$os{"DISTRIBVER"} defined $os{"NETBSD_OFFICIAL_RELEASE"}
Truth table100%3/3
A and B
A= $os{"DISTRIBVER"}B= defined $os{"NETBSD_OFFICIAL_RELEASE"}
ABresult
0X0
100
111
136 1 my @k = grep m/^netbsd\s+\d/i => keys %os;
137 1 ▶ ($distro = @k == 1 ? $k[0] : "NetBSD $os{DISTRIBVER}") =~ s{/.*}{};
Branch: 1 branch
BranchTrueFalseTotal
@k == 1 ? : 1 0 1
138 }
139 elsif ($os{PRETTY_NAME}) {
140 76 $distro = $os{PRETTY_NAME}; # "openSUSE 12.1 (Asparagus) (x86_64)"
141 76 ▶ if (my $vid = $os{VERSION_ID}) { # wheezy 7 => 7.2
Branch: 1 branch
BranchTrueFalseTotal
if (my $vid = $os{"VERSION_ID"}) 75 1 76
142 75 my @rv;
143 75 ▶ if (@rv = grep m{^$vid\.} => sort keys %os) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rv = grep(/^$vid\./, sort(keys %os))) 14 61 75
144 # from /etc/debian_version
145 14 ▶ $rv[0] =~ m/^[0-9]+\.\w+$/ and
Branch: 1 branch
BranchTrueFalseTotal
$rv[0] =~ /^[0-9]+\.\w+$/ and $distro =~ s/\b$vid\b/$rv[0]/ 14 0 14
146 $distro =~ s/\b$vid\b/$rv[0]/;
147 }
148 75 ▶ if (!@rv && defined $os{NAME} and # CentOS Linux 7 = CentOS Linux 7.1.1503
Branch: 1 branch
BranchTrueFalseTotal
if (not @rv and defined $os{"NAME"} and @rv = grep(/^$os{"NAME"} (?:(?:release|version)\s+)?$vid\./, sort(keys %os))) 13 62 75
Condition83%5/6
not @rv and defined $os{"NAME"} and @rv = grep(/^$os{"NAME"} (?:(?:release|version)\s+)?$vid\./, sort(keys %os))
!ll&&!rl&&r
144813
not @rv and defined $os{"NAME"}
!ll&&!rl&&r
14061
MC/DC66%2/3
not @rv and defined $os{"NAME"} and @rv = grep(/^$os{"NAME"} (?:(?:release|version)\s+)?$vid\./, sort(keys %os))
not @rv defined $os{"NAME"} @rv = grep(/^$os{"NAME"} (?:(?:release|version)\s+)?$vid\./, sort(keys %os))
Truth table75%3/4
not(A) and B and C
A= not @rvB= defined $os{"NAME"}C= @rv = grep(/^$os{"NAME"} (?:(?:release|version)\s+)?$vid\./, sort(keys %os))
ABCresult
0XX0
10X0
1100
1111
149 @rv = grep m{^$os{NAME} (?:(?:release|version)\s+)?$vid\.} => sort keys %os) {
150 13 ▶ if ($rv[0] =~ m/\s($vid\.[-.\w]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv[0] =~ /\s($vid\.[-.\w]+)/) 13 0 13
151 13 my $vr = $1;
152 13 $distro =~ s/\s$vid\b/ $vr/;
153 }
154 }
155 }
156 76 $distro =~ s{\s*[-:/,]\s*Version\s*:?\s*}{ };
157 76 $distro =~ s/\)\s+\(\w+\)\s*$/)/; # remove architectural part
158 76 $distro =~ s/\s+\(?(?:i\d86|x86_64)\)?\s*$//; # i386 i486 i586 x86_64
159 76 ▶ $os{VERSION_ID} && $distro !~ m{\b$os{VERSION_ID}\b}i and
Branch: 1 branch
BranchTrueFalseTotal
$os{"VERSION_ID"} and not $distro =~ /\b$os{"VERSION_ID"}\b/i and $distro .= qq[ $os{"VERSION_ID"}] 4 72 76
Condition100%3/3
$os{"VERSION_ID"} and not $distro =~ /\b$os{"VERSION_ID"}\b/i
!ll&&!rl&&r
1714
MC/DC100%2/2
$os{"VERSION_ID"} and not $distro =~ /\b$os{"VERSION_ID"}\b/i
$os{"VERSION_ID"} not $distro =~ /\b$os{"VERSION_ID"}\b/i
Truth table100%3/3
A and not(B)
A= $os{"VERSION_ID"}B= not $distro =~ /\b$os{"VERSION_ID"}\b/i
ABresult
0X0
100
111
160 $distro .= " $os{VERSION_ID}";
161 }
162 ▶ elsif ($os{VERSION} && $os{NAME}) {
Condition66%2/3
$os{"VERSION"} and $os{"NAME"}
!ll&&!rl&&r
2740
MC/DC0%0/2
$os{"VERSION"} and $os{"NAME"}
$os{"VERSION"} $os{"NAME"}
Truth table66%2/3
A and B
A= $os{"VERSION"}B= $os{"NAME"}
ABresult
0X0
100
111
163 0 $distro = qq{$os{NAME} $os{VERSION}};
164 }
165 ▶ elsif ($os{VERSION} && $os{CODENAME}) {
Condition100%3/3
$os{"VERSION"} and $os{"CODENAME"}
!ll&&!rl&&r
2731
MC/DC100%2/2
$os{"VERSION"} and $os{"CODENAME"}
$os{"VERSION"} $os{"CODENAME"}
Truth table100%3/3
A and B
A= $os{"VERSION"}B= $os{"CODENAME"}
ABresult
0X0
100
111
166 1 ▶ if (my @welcome = grep s{^\s*Welcome\s+to\s+(\S*$distro\S*)\b.*}{$1}i => keys %os) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@welcome) = grep(s/^\s*Welcome\s+to\s+(\S*$distro\S*)\b.*/$1/i, keys %os)) 1 0 1
167 1 $distro = $welcome[0];
168 }
169 1 $distro .= qq{ $os{VERSION}};
170 1 ▶ $distro =~ m/\b$os{CODENAME}\b/ or
Branch: 1 branch
BranchTrueFalseTotal
$distro =~ /\b$os{"CODENAME"}\b/ or $distro .= qq[ ($os{"CODENAME"})] 0 1 1
171 $distro .= qq{ ($os{CODENAME})};
172 }
173 ▶ elsif ($os{MAJORVERSION} && defined $os{MINORVERSION}) {
Condition66%2/3
$os{"MAJORVERSION"} and defined $os{"MINORVERSION"}
!ll&&!rl&&r
19011
MC/DC50%1/2
$os{"MAJORVERSION"} and defined $os{"MINORVERSION"}
$os{"MAJORVERSION"} defined $os{"MINORVERSION"}
Truth table66%2/3
A and B
A= $os{"MAJORVERSION"}B= defined $os{"MINORVERSION"}
ABresult
0X0
100
111
174 11 ▶ -d "/usr/syno" || "@dist_file" =~ m{^\S*/VERSION$} and $distro .= "DSM";
Branch: 1 branch
BranchTrueFalseTotal
-d "/usr/syno" || join($", @dist_file) =~ m[^\S*/VERSION$] and $distro .= 'DSM' 11 0 11
Condition33%1/3
-d "/usr/syno" or join($", @dist_file) =~ m[^\S*/VERSION$]
l!l&&r!l&&!r
0110
MC/DC0%0/2
-d "/usr/syno" or join($", @dist_file) =~ m[^\S*/VERSION$]
-d "/usr/syno" join($", @dist_file) =~ m[^\S*/VERSION$]
Truth table33%1/3
A or B
A= -d "/usr/syno"B= join($", @dist_file) =~ m[^\S*/VERSION$]
ABresult
1X1
011
000
175 11 $distro .= qq{ $os{MAJORVERSION}.$os{MINORVERSION}};
176 11 ▶ $os{BUILDNUMBER} and $distro .= qq{-$os{BUILDNUMBER}};
Branch: 1 branch
BranchTrueFalseTotal
$os{"BUILDNUMBER"} and $distro .= qq[-$os{"BUILDNUMBER"}] 11 0 11
177 11 ▶ $os{SMALLFIXNUMBER} and $distro .= qq{-$os{SMALLFIXNUMBER}};
Branch: 1 branch
BranchTrueFalseTotal
$os{"SMALLFIXNUMBER"} and $distro .= qq[-$os{"SMALLFIXNUMBER"}] 7 4 11
178 }
179 ▶ elsif ($os{DISTRIBVER} && exists $os{NETBSDSRCDIR}) {
Condition66%2/3
$os{"DISTRIBVER"} and exists $os{"NETBSDSRCDIR"}
!ll&&!rl&&r
1702
MC/DC50%1/2
$os{"DISTRIBVER"} and exists $os{"NETBSDSRCDIR"}
$os{"DISTRIBVER"} exists $os{"NETBSDSRCDIR"}
Truth table66%2/3
A and B
A= $os{"DISTRIBVER"}B= exists $os{"NETBSDSRCDIR"}
ABresult
0X0
100
111
180 2 (my $dv = $os{DISTRIBVER}) =~ tr{ ''"";}{}d;
181 2 $distro .= qq{ NetBSD $dv};
182 }
183 else {
184 # /etc/issue:
185 # Welcome to SUSE LINUX 10.0 "Prague" (i586) - Kernel \r (\l).
186 # Welcome to openSUSE 10.1 "Agama Lizard" (i586) - Kernel \r (\l).
187 # Welcome to openSUSE 10.2 (i586) - Kernel \r (\l).
188 # Welcome to openSUSE 10.2 "Basilisk Lizard" (X86-64) - Kernel \r (\l).
189 # Welcome to openSUSE 10.3 (i586) - Kernel \r (\l).
190 # Welcome to openSUSE 10.3 (X86-64) - Kernel \r (\l).
191 # Welcome to openSUSE 11.1 - Kernel \r (\l).
192 # Welcome to openSUSE 11.2 "Emerald" - Kernel \r (\l).
193 # Welcome to openSUSE 11.3 "Teal" - Kernel \r (\l).
194 # Welcome to openSUSE 11.4 "Celadon" - Kernel \r (\l).
195 # Welcome to openSUSE 12.1 "Asparagus" - Kernel \r (\l).
196 # Welcome to openSUSE 12.2 "Mantis" - Kernel \r (\l).
197 # Welcome to openSUSE 12.3 "Dartmouth" - Kernel \r (\l).
198 # Welcome to openSUSE 13.1 "Bottle" - Kernel \r (\l).
199 # Welcome to openSUSE 13.2 "Harlequin" - Kernel \r (\l).
200 # Welcome to openSUSE Leap 42.1 - Kernel \r (\l).
201 # Welcome to openSUSE 20151218 "Tumbleweed" - Kernel \r (\l).
202 # Welcome to SUSE Linux Enterprise Server 11 SP1 for VMware (x86_64) - Kernel \r (\l).
203 # Ubuntu 10.04.4 LTS \n \l
204 # Debian GNU/Linux wheezy/sid \n \l
205 # Debian GNU/Linux 6.0 \n \l
206 # CentOS release 6.4 (Final)
207 # /etc/redhat-release:
208 # CentOS release 5.7 (Final)
209 # CentOS release 6.4 (Final)
210 # Red Hat Enterprise Linux ES release 4 (Nahant Update 2)
211 # /etc/debian_version:
212 # 6.0.4
213 # wheezy/sid
214 # squeeze/sid
215  
216 17 my @key = sort keys %os;
217 17 s/\s*\\[rln].*// for @key;
218  
219 17 my @vsn = grep m/^[0-9.]+$/ => @key;
220 #$self->{__X__} = { os => \%os, key => \@key, vsn => \@vsn };
221  
222 17 ▶ if (my @welcome = grep s{^\s*Welcome\s+to\s+}{}i => @key) {
Branch: 4 branches
BranchTrueFalseTotal
if (my(@welcome) = grep(s/^\s*Welcome\s+to\s+//i, @key)) { } 3 14 17
elsif (my(@rel) = grep(/\brelease\b/i, @key)) { } 12 2 14
elsif (my(@lnx) = grep(/\bLinux\b/i, @key)) { } 2 0 2
elsif ($distro and @vsn) { } 0 0 0
223 3 ($distro = $welcome[0]) =~ s/"([^"]+)"/($1)/;
224 }
225 elsif (my @rel = grep m{\brelease\b}i => @key) {
226 12 ▶ @rel > 1 && $rel[0] =~ m/^Enterprise Linux Enterprise/
Branch: 1 branch
BranchTrueFalseTotal
@rel > 1 and $rel[0] =~ /^Enterprise Linux Enterprise/ and $rel[1] =~ /^Oracle Linux/ and shift @rel 1 11 12
Condition66%4/6
@rel > 1 and $rel[0] =~ /^Enterprise Linux Enterprise/ and $rel[1] =~ /^Oracle Linux/
!ll&&!rl&&r
1101
@rel > 1 and $rel[0] =~ /^Enterprise Linux Enterprise/
!ll&&!rl&&r
1101
MC/DC33%1/3
@rel > 1 and $rel[0] =~ /^Enterprise Linux Enterprise/ and $rel[1] =~ /^Oracle Linux/
@rel > 1 $rel[0] =~ /^Enterprise Linux Enterprise/ $rel[1] =~ /^Oracle Linux/
Truth table50%2/4
A and B and C
A= @rel > 1B= $rel[0] =~ /^Enterprise Linux Enterprise/C= $rel[1] =~ /^Oracle Linux/
ABCresult
0XX0
10X0
1100
1111
227 && $rel[1] =~ m/^Oracle Linux/ and shift @rel;
228 12 $distro = $rel[0];
229 12 $distro =~ s/ *release//;
230 12 $distro =~ s/Red Hat Enterprise Linux/RHEL/; # Too long for subject
231 # RHEL ES 4 (Nahant Update 2) => RHEL Server 4.2 (Nahant)
232 12 $distro =~ s/^RHEL ES (\d+)\s+(.*)\s+Update\s+(\d+)/RHEL Server $1.$3 $2/;
233 }
234 elsif ( my @lnx = grep m{\bLinux\b}i => @key ) {
235 2 $distro = $lnx[0];
236 }
237 ▶ elsif ( $distro && @vsn ) {
Condition0%0/3
$distro and @vsn
!ll&&!rl&&r
000
MC/DC0%0/2
$distro and @vsn
$distro @vsn
Truth table0%0/3
A and B
A= $distroB= @vsn
ABresult
0X0
100
111
238 0 $distro .= "-$vsn[0]";
239 }
240 else {
241 0 $distro = $key[0];
242 }
243 17 $distro =~ s/\s+-\s+Kernel.*//i;
244 }
245 137 ▶ if ($distro =~ s/^\s*(.*\S)\s*$/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distro =~ s/^\s*(.*\S)\s*$/$1/) 137 0 137
246 137 $self->{__distro} = $distro;
247 137 $os .= " [$distro]";
248 }
249 137 $self->{__release_info} = \%os;
250 137 $self->{__os} = $os;
251 } # prepare_os
252  
253 =head2 $si->linux_generic
254  
255 Check C</proc/cpuinfo> for these keys:
256  
257 =over
258  
259 =item "processor" (count occurrence for __cpu_count)
260  
261 =item "model name" (part of __cpu)
262  
263 =item "vendor_id" (part of __cpu)
264  
265 =item "cpu mhz" (part of __cpu)
266  
267 =item "cpu cores" (add values to add to __cpu_count)
268  
269 =back
270  
271 =cut
272  
273 131 ▶sub linux_generic {
Subroutine linux_generic: called CC=18 SCAR=34.0
Pod documented
274 131 my $self = shift;
275  
276 131 ▶ my $n_phys_id = $self->count_unique_in_cpuinfo (qr/^physical id\s+:/) || 0;
Condition100%2/2
$self->count_unique_in_cpuinfo(qr/^physical id\s+:/) || 0
l!l
1301
MC/DC100%1/1
$self->count_unique_in_cpuinfo(qr/^physical id\s+:/) || 0
$self->count_unique_in_cpuinfo(qr/^physical id\s+:/)
Truth table100%2/2
A
A= $self->count_unique_in_cpuinfo(qr/^physical id\s+:/)
Aresult
11
00
277 131 ▶ my $n_core_id = $self->count_unique_in_cpuinfo (qr/^core id\s+:/) || 0;
Condition100%2/2
$self->count_unique_in_cpuinfo(qr/^core id\s+:/) || 0
l!l
1301
MC/DC100%1/1
$self->count_unique_in_cpuinfo(qr/^core id\s+:/) || 0
$self->count_unique_in_cpuinfo(qr/^core id\s+:/)
Truth table100%2/2
A
A= $self->count_unique_in_cpuinfo(qr/^core id\s+:/)
Aresult
11
00
278 131 ▶ my $n_processor = $self->count_unique_in_cpuinfo (qr/^processor\s+:/) || 0;
Condition50%1/2
$self->count_unique_in_cpuinfo(qr/^processor\s+:/) || 0
l!l
1310
MC/DC0%0/1
$self->count_unique_in_cpuinfo(qr/^processor\s+:/) || 0
$self->count_unique_in_cpuinfo(qr/^processor\s+:/)
Truth table50%1/2
A
A= $self->count_unique_in_cpuinfo(qr/^processor\s+:/)
Aresult
11
00
279 131 ▶ my $n_cpu = $n_phys_id || $n_core_id || $n_processor;
Condition66%4/6
$n_phys_id || $n_core_id || $n_processor
l!l&&r!l&&!r
13010
$n_phys_id or $n_core_id
l!l&&r!l&&!r
13001
MC/DC0%0/3
$n_phys_id || $n_core_id || $n_processor
$n_phys_id $n_core_id $n_processor
Truth table50%2/4
A or B || C
A= $n_phys_idB= $n_core_idC= $n_processor
ABCresult
1XX1
01X1
0011
0000
280  
281 # ::diag"Np: $n_phys_id, NC: $n_core_id, NP: $n_processor, NC: $n_cpu";
282 131 $self->{__cpu_count} = $n_cpu;
283  
284 131 { my @tags = ("model name", "vendor_id", "cpu mhz");
285 131 my %info = map { ($_ => $self->from_cpuinfo ($_)) } @tags;
286 131 ▶ unless (defined $info{$tags[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info{$tags[0]}) 0 131 131
287 # riscv64 -> rv64imafdc
288 0 $info{$tags[0]} = $self->from_cpuinfo ("isa");
289 }
290 131 ▶ $info{$tags[2]} and $info{$tags[2]} = sprintf "%.0fMHz", $info{$tags[2]};
Branch: 1 branch
BranchTrueFalseTotal
$info{$tags[2]} and $info{$tags[2]} = sprintf("%.0fMHz", $info{$tags[2]}) 131 0 131
291 131 my @cpui;
292 131 ▶ if ($info{$tags[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info{$tags[0]}) { } 131 0 131
293 131 push @cpui => $info{shift @tags};
294 131 push @cpui => "(".(join " " => grep { length } @info{@tags}).")";
295 }
296 else {
297 0 push @cpui => grep { length } @info{@tags};
298 }
299 131 $self->{__cpu} = join " " => @cpui;
300 }
301  
302 131 ▶ if ($n_phys_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_phys_id) 130 1 131
303 $n_processor > $n_phys_id and
304 130 ▶ $self->{__cpu_count} .= " [$n_processor cores]";
Branch: 1 branch
BranchTrueFalseTotal
$n_processor > $n_phys_id and $self->{"__cpu_count"} .= " [$n_processor cores]" 4 126 130
305 130 return;
306 }
307 1 ▶ if ($n_core_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_core_id) 0 1 1
308 $n_processor > $n_core_id and
309 0 ▶ $self->{__cpu_count} .= " [$n_processor cores]";
Branch: 1 branch
BranchTrueFalseTotal
$n_processor > $n_core_id and $self->{"__cpu_count"} .= " [$n_processor cores]" 0 0 0
310 0 return;
311 }
312  
313 1 my $n_cores = 0;
314 1 my $core_id = 0;
315 1 my %cores;
316 1 for my $cores (grep m/(cpu cores|core id)\s*:\s*\d+/ => $self->_proc_cpuinfo) {
317 0 ▶ my ($tag, $count) = $cores =~ m/^(.*\S)\s*:\s*(\d+)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $cores =~ /^(.*\S)\s*:\s*(\d+)/ or next 0 0 0
318 0 ▶ if ($tag eq "core id") {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'core id') { } 0 0 0
319 0 $core_id = $count;
320 }
321 else {
322 0 $cores{$core_id} = $count;
323 }
324 }
325 1 $n_cores += $cores{$_} for keys %cores;
326  
327 1 ▶ $n_cores > $n_cpu and $self->{__cpu_count} .= " [$n_cores cores]";
Branch: 1 branch
BranchTrueFalseTotal
$n_cores > $n_cpu and $self->{"__cpu_count"} .= " [$n_cores cores]" 0 1 1
328 } # _linux_generic
329  
330 =head2 $si->linux_arm
331  
332 Check C</proc/cpuinfo> for these keys:
333  
334 =over
335  
336 =item "processor" (count occurrence for __cpu_count)
337  
338 =item "Processor" (part of __cpu)
339  
340 =item "BogoMIPS" (part of __cpu)
341  
342 =back
343  
344 =cut
345  
346 3 ▶sub linux_arm {
Subroutine linux_arm: called CC=3 SCAR=11.1
Pod documented
347 3 my $self = shift;
348  
349 3 $self->{__cpu_count} = $self->count_in_cpuinfo (qr/^processor\s+:\s+/i);
350  
351 3 ▶ my $cpu = $self->from_cpuinfo ("Processor") ||
Condition66%2/3
$self->from_cpuinfo('Processor') || $self->from_cpuinfo('Model[_ ]name')
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->from_cpuinfo('Processor') || $self->from_cpuinfo('Model[_ ]name')
$self->from_cpuinfo('Processor') $self->from_cpuinfo('Model[_ ]name')
Truth table66%2/3
A || B
A= $self->from_cpuinfo('Processor')B= $self->from_cpuinfo('Model[_ ]name')
ABresult
1X1
011
000
352 $self->from_cpuinfo ("Model[_ ]name");
353 3 my $bogo = $self->from_cpuinfo ("BogoMIPS");
354 3 my $mhz = 100 * int (($bogo + 50) / 100);
355 3 $cpu =~ s/\s+/ /g;
356 3 ▶ $mhz and $cpu .= " ($mhz MHz)";
Branch: 1 branch
BranchTrueFalseTotal
$mhz and $cpu .= " ($mhz MHz)" 3 0 3
357 3 $self->{__cpu} = $cpu;
358 } # _linux_arm
359  
360 =head2 $si->linux_ppc
361  
362 Check C</proc/cpuinfo> for these keys:
363  
364 =over
365  
366 =item "processor" (count occurrence for __cpu_count)
367  
368 =item "cpu" (part of __cpu)
369  
370 =item "machine" (part of __cpu)
371  
372 =item "clock" (part of __cpu)
373  
374 =item "detected" (alters machine if present)
375  
376 =back
377  
378 =cut
379  
380 1 ▶sub linux_ppc {
Subroutine linux_ppc: called CC=2 SCAR=6.9
Pod documented
381 1 my $self = shift;
382  
383 1 $self->{__cpu_count} = $self->count_in_cpuinfo (qr/^processor\s+:\s+/);
384  
385 1 my @tags = qw( cpu machine clock );
386 1 my %info = map { ($_ => $self->from_cpuinfo ($_)) } @tags;
387 1 ▶ if ($info{detected} = $self->from_cpuinfo ("detected as")){
Branch: 1 branch
BranchTrueFalseTotal
if ($info{"detected"} = $self->from_cpuinfo("detected as")) 1 0 1
388 1 $info{detected} =~ s/.*(\b.+Mac G\d).*/$1/;
389 1 $info{machine} = $info{detected};
390 }
391  
392 1 $self->{__cpu} = sprintf "%s %s (%s)", map { $info{$_} } @tags;
393 } # linux_ppc
394  
395 =head2 $si->linux_sparc
396  
397 Check C</proc/cpuinfo> for these keys:
398  
399 =over
400  
401 =item "processor" (count occurrence for __cpu_count)
402  
403 =item "cpu" (part of __cpu)
404  
405 =item "Cpu0ClkTck" (part of __cpu)
406  
407 =back
408  
409 =cut
410  
411 0 ▶sub linux_sparc {
Subroutine linux_sparc: not called CC=2 SCAR=17.9
Pod documented
412 0 my $self = shift;
413  
414 0 $self->{__cpu_count} = $self->from_cpuinfo ("ncpus active");
415  
416 0 my @tags = qw( cpu Cpu0ClkTck );
417 0 my %info = map { ($_ => $self->from_cpuinfo ($_)) } @tags;
418 0 my $cpu = $info{cpu};
419 $info{Cpu0ClkTck} and
420 0 ▶ $cpu .= sprintf " (%.0fMHz)", hex ($info{Cpu0ClkTck}) / 1_000_000;
Branch: 1 branch
BranchTrueFalseTotal
$info{"Cpu0ClkTck"} and $cpu .= sprintf(" (%.0fMHz)", hex($info{"Cpu0ClkTck"}) / 1000000) 0 0 0
421 0 $self->{__cpu} = $cpu;
422 } # linux_sparc
423  
424 =head2 $si->linux_s390x
425  
426 Check C</proc/cpuinfo> for these keys:
427  
428 =over
429  
430 =item "processor" (count occurrence for __cpu_count)
431  
432 =item "Processor" (part of __cpu)
433  
434 =item "BogoMIPS" (part of __cpu)
435  
436 =back
437  
438 =cut
439  
440 2 ▶sub linux_s390x {
Subroutine linux_s390x: called CC=4 SCAR=15.0
Pod documented
441 2 my $self = shift;
442  
443 2 $self->{__cpu_count} = $self->count_in_cpuinfo (qr/^processor\s+\d+:\s+/i);
444  
445 2 ▶ my $cpu = $self->from_cpuinfo ("vendor_id") ||
Condition33%2/6
$self->from_cpuinfo('vendor_id') || $self->from_cpuinfo('Processor') || $self->from_cpuinfo('Model[_ ]name')
l!l&&r!l&&!r
200
$self->from_cpuinfo("vendor_id") or $self->from_cpuinfo("Processor")
l!l&&r!l&&!r
200
MC/DC0%0/3
$self->from_cpuinfo('vendor_id') || $self->from_cpuinfo('Processor') || $self->from_cpuinfo('Model[_ ]name')
$self->from_cpuinfo("vendor_id") $self->from_cpuinfo("Processor") $self->from_cpuinfo('Model[_ ]name')
Truth table25%1/4
A or B || C
A= $self->from_cpuinfo("vendor_id")B= $self->from_cpuinfo("Processor")C= $self->from_cpuinfo('Model[_ ]name')
ABCresult
1XX1
01X1
0011
0000
446 $self->from_cpuinfo ("Processor") ||
447 $self->from_cpuinfo ("Model[_ ]name");
448 2 my $bogo = $self->from_cpuinfo (qr{BogoMIPS(?:\s*per[ _]CPU)?}i);
449 2 my $mhz = 100 * int (($bogo + 50) / 100);
450 2 $cpu =~ s/\s+/ /g;
451 2 ▶ $mhz and $cpu .= " ($mhz MHz)";
Branch: 1 branch
BranchTrueFalseTotal
$mhz and $cpu .= " ($mhz MHz)" 2 0 2
452 2 $self->{__cpu} = $cpu;
453 } # _linux_s390x
454  
455 =head2 $si->prepare_proc_cpuinfo
456  
457 Read the complete C<< /proc/cpuinfo >>.
458  
459 =cut
460  
461 137 ▶sub prepare_proc_cpuinfo {
Subroutine prepare_proc_cpuinfo: called CC=4 SCAR=13.9
Pod documented
462 137 my $self = shift;
463  
464 137 ▶ if (open my $pci, "<", "/proc/cpuinfo") {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $pci, "<", "/proc/cpuinfo") 137 0 137
465 137 chomp (my @pci = <$pci>);
466 137 s/[\s\xa0]+/ /g for @pci;
467 137 s/ $// for @pci;
468 137 $self->{__proc_cpuinfo} = \@pci;
469 137 close $pci;
470 137 return 1;
471 }
472 } # prepare_proc_cpuinfo
473  
474 =head2 $si->count_in_cpuinfo ($regex)
475  
476 Returns the number of lines $regex matches for.
477  
478 =cut
479  
480 6 ▶sub count_in_cpuinfo {
Subroutine count_in_cpuinfo: called CC=1 SCAR=0.0
Pod documented
481 6 my ($self, $regex) = @_;
482  
483 6 return scalar grep /$regex/, $self->_proc_cpuinfo;
484 } # count_in_cpuinfo
485  
486 =head2 $si->count_unique_in_cpuinfo ($regex)
487  
488 Returns the number of lines $regex matches for.
489  
490 =cut
491  
492 393 ▶sub count_unique_in_cpuinfo {
Subroutine count_unique_in_cpuinfo: called CC=1 SCAR=0.0
Pod documented
493 393 my ($self, $regex) = @_;
494  
495 393 my %match = map { $_ => 1 } grep /$regex/ => $self->_proc_cpuinfo;
496 393 return scalar keys %match;
497 } # count_unique_in_cpuinfo
498  
499 =head2 $si->from_cpuinfo ($key)
500  
501 Returns the first value of that key in C<< /proc/cpuinfo >>.
502  
503 =cut
504  
505 408 ▶sub from_cpuinfo {
Subroutine from_cpuinfo: called CC=2 SCAR=7.0
Pod documented
506 408 my ($self, $key) = @_;
507  
508 408 my ($first) = grep m/^\s*$key\s*[:=]\s*/i => $self->_proc_cpuinfo;
509 408 ▶ defined $first or $first = "";
Branch: 1 branch
BranchTrueFalseTotal
defined $first or $first = "" 408 0 408
510 408 $first =~ s/^\s*$key\s*[:=]\s*//i;
511 408 return $first;
512 } # from_cpuinfo
513  
514 3 1;
515  
516 __END__
« Info/HPUX.pm ↑ Summary Info/AIX.pm »