Test::Without::Shm - simulate shmget() etc not available
# pretend shm not implemented on the system perl -MTest::Without::Shm myprog.pl ... # pretend not enough memory for shm perl -MTest::Without::Shm=-nomem myprog.pl ...
This module overrides the Perl core functions
shmget() shmread() shmwrite() shmctl()
to pretend that their System-V style shared memory is either not implemented or there's not enough memory.
This fakery can be used for testing to check how module code etc might behave on a system without shm or when there's not enough memory. A module might throw an error, use an I/O fallback, etc.
The shm functions are overridden using the
CORE::GLOBAL mechanism (see "OVERRIDING CORE FUNCTIONS" in CORE) so
Test::Without::Shm must be loaded before compiling any code which might call them.
The default import behaviour is to pretend shm is not implemented on the system.
-M can be used on the command line to run a program,
perl -MTest::Without::Shm myprog.pl ...
-nomem option pretends that shm exists, but there's not enough memory,
perl -MTest::Without::Shm=-nomem myprog.pl ...
For the usual
ExtUtils::MakeMaker harness the
-M can be put in the
HARNESS_PERL_SWITCHES environment variable in the usual way,
HARNESS_PERL_SWITCHES="-MTest::Without::Shm" make test
The same effect as the above
-M can be had in a script,
use Test::Without::Shm; # shm not implemented
use Test::Without::Shm '-nomem';
If you want to load the
Test::Without::Shm module but not activate it then give a
() in the usual way to skip its
# setups, but no "without" yet use Test::Without::Shm ();
Don't forget as noted above that this must be done before any code using the
shm...() functions, which probably means somewhere early in the mainline script.
The import options are
Make shm "not implemented", as if the system doesn't have the underlying functions. This makes the Perl functions croak with "shmget not implemented", or "shm I/O not implemented", etc.
shmget() fail with
ENOMEM as if the system says there's not enough memory to make a shm segment. This is arranged even when the system doesn't have shm (ie. when "not implemented" would be the normal state).
$mode = Test::Without::Shm->mode ()
Get or set the shm fakery mode.
$mode is a string
"notimp" "nomem" "normal"
Normal mode means the
shm...() functions are Perl's normal behaviour, whatever that might be. In the current implementation this is done by leaving the
CORE::GLOBAL setups installed but dispatching to the actual
Copyright 2011, 2012 Kevin Ryde
Test-VariousBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Test-VariousBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Test-VariousBits. If not, see <http://www.gnu.org/licenses/>.