Kevin Ryde


Test::Without::Shm - simulate shmget() etc not available


 # pretend shm not implemented on the system
 perl -MTest::Without::Shm ...

 # pretend not enough memory for shm
 perl -MTest::Without::Shm=-nomem ...


This module overrides the Perl core functions


to pretend that their System-V style shared memory is either not implemented or there's not enough memory.

This fakery can be used during 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 when running a program,

    perl -MTest::Without::Shm ...

The -nomem option pretends that shm exists but there's not enough memory,

    perl -MTest::Without::Shm=-nomem ...

For the usual ExtUtils::MakeMaker test 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

or for -nomem

    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 import() action,

    # setups, but no "without" yet
    use Test::Without::Shm ();

Don't forget 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.


Make 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 ()
Test::Without::Shm->mode ($mode)

Get or set the shm fakery mode. $mode is a string


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 CORE::shm...() routines.


"shmget" in perlfunc, CORE, shmget(2), IPC::SysV

Perl sources doio.c Perl_do_ipcget(), Perl_do_shmio() and Perl_do_ipcctl()



Copyright 2011, 2012, 2013, 2015 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