Test/Without/Shm.pm

filter: Statementstmt 61.5% 32 / 52 Branchbran 31.8% 7 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 20.0% 1 / 5 totaltotal 51.6% 46 / 89 CC 13 SCAR 21.7
CC
13
Cov
53%
import
22.1
Test_Without_Shm_shmread
6.0
Test_Without_Shm_shmwrite
6.0
CRAP 8.7
↑ Summary Test/Weaken/ExtraBits.pm »
1 # Copyright 2011, 2012, 2013, 2015, 2017 Kevin Ryde
2  
3 # This file is part of Test-VariousBits.
4 #
5 # Test-VariousBits is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Test-VariousBits is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Test-VariousBits. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 # cf doio.c
20 # Perl_do_ipcget() for shmget
21 # Perl_do_shmio() for shmread,shmwrite
22 # Perl_do_ipcctl() for shmget
23 #
24  
25 package Test::Without::Shm;
26 3 require 5;
27 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 $VERSION = 8;
31  
32 # uncomment this to run the ### lines
33 #use Devel::Comments;
34  
35 ### Test-Without-Shm loads ...
36  
37 3 my %modes = (notimp => 1,
38 nomem => 1,
39 normal => 1);
40 3 my $current_mode = 'normal'; # default
41  
42 1 ▶sub _croak {
Subroutine _croak: called CC=1 SCAR=0.0
43 1 require Carp;
44 1 Carp::croak(@_);
45 }
46  
47 8 ▶sub mode {
Subroutine mode: called CC=3 SCAR=11.0
Pod documented
48 8 my ($class, $mode) = @_;
49 ### Test-Without-Shm mode(): @_
50  
51 8 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 4 4 8
52 4 ▶ $modes{$mode} or _croak "No such $class mode: ",$mode;
Branch: 1 branch
BranchTrueFalseTotal
$modes{$mode} or _croak("No such $class mode: ", $mode) 4 0 4
53 4 $current_mode = $mode;
54 }
55 8 return $current_mode;
56 }
57  
58 2 ▶sub import {
Subroutine import: called CC=6 SCAR=31.0
59 2 my $class = shift;
60 ### Test-Without-Shm import(): @_
61  
62 2 ▶ if (! @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @_) { } 2 0 2
63 # default
64 2 $current_mode = 'notimp';
65 } else {
66 0 foreach (@_) {
67 0 ▶ if ($_ eq '-notimp') {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ eq '-notimp') { } 0 0 0
elsif ($_ eq '-nomem') { } 0 0 0
elsif ($_ eq '-normal') { } 0 0 0
68 0 $current_mode = 'notimp';
69 } elsif ($_ eq '-nomem') {
70 0 $current_mode = 'nomem';
71 } elsif ($_ eq '-normal') {
72 0 $current_mode = 'normal';
73 } else {
74 0 _croak 'Test::Without::Shm unrecognised import option: ',$_;
75 }
76 }
77 }
78 }
79  
80 0 ▶sub unimport {
Subroutine unimport: not called CC=1 SCAR=6.9
81 0 $current_mode = 'normal';
82 }
83  
84  
85 3 *CORE::GLOBAL::shmget = \&Test_Without_Shm_shmget;
86 2 ▶sub Test_Without_Shm_shmget ($$$) {
Subroutine Test_Without_Shm_shmget: called CC=3 SCAR=11.1
Pod undocumented
87 2 my ($key, $size, $flags) = @_;
88 ### Test-Without-Shm shmget() ...
89  
90 2 ▶ if ($current_mode eq 'notimp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq "notimp") 1 1 2
91 # this message string per doio.c Perl_do_ipcget()
92 1 _croak "shmget not implemented";
93 }
94 1 ▶ if ($current_mode eq 'nomem') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq "nomem") 1 0 1
95 1 require POSIX;
96 1 $! = POSIX::ENOMEM();
97 1 return undef;
98 }
99 0 return CORE::shmget ($key, $size, $flags);
100 }
101  
102 3 *CORE::GLOBAL::shmread = \&Test_Without_Shm_shmread;
103 0 ▶sub Test_Without_Shm_shmread ($$$$) {
Subroutine Test_Without_Shm_shmread: not called CC=2 SCAR=17.9
Pod undocumented
104 0 my ($id,$var,$pos,$size) = @_;
105 0 ▶ if ($current_mode eq 'notimp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq "notimp") 0 0 0
106 # this message string per doio.c Perl_do_shmio()
107 0 _croak "shm I/O not implemented";
108 }
109 0 return CORE::shmread($id,$var,$pos,$size);
110 }
111  
112 3 *CORE::GLOBAL::shmwrite = \&Test_Without_Shm_shmwrite;
113 0 ▶sub Test_Without_Shm_shmwrite ($$$$) {
Subroutine Test_Without_Shm_shmwrite: not called CC=2 SCAR=17.9
Pod undocumented
114 0 my ($id,$str,$pos,$size) = @_;
115 0 ▶ if ($current_mode eq 'notimp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq "notimp") 0 0 0
116 # this message per doio.c Perl_do_shmio()
117 0 _croak "shm I/O not implemented";
118 }
119 0 return CORE::shmwrite($id,$str,$pos,$size);
120 }
121  
122 3 *CORE::GLOBAL::shmctl = \&Test_Without_Shm_shmctl;
123 0 ▶sub Test_Without_Shm_shmctl ($$$) {
Subroutine Test_Without_Shm_shmctl: not called CC=2 SCAR=17.9
Pod undocumented
124 0 my ($id,$cmd,$arg) = @_;
125 0 ▶ if ($current_mode eq 'notimp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq "notimp") 0 0 0
126 # this message string per doio.c Perl_do_ipcctl()
127 0 _croak "shmctl not implemented";
128 }
129 0 return CORE::shmctl($id,$cmd,$arg);
130 }
131  
132 3 1;
133 __END__
↑ Summary Test/Weaken/ExtraBits.pm »