My C application uses 3rd libraries, which do their own memory management. In order to be robust, my application has code to deal with failures of library functions due to lack of free memory.
I would like to test this code, and for this, I need to simulate failures due to lack of memory.
What tool/s are recommended for this? My environment is Linux/gcc.
A memory allocation (malloc) failure occurs when the active controller does not have enough memory to run a stack unit. This failure may occur if you configure a large number of VLANs (for example, 4000) or STP instances (for example, 255) in the router image.
Symptoms. Applications that frequently allocate memory may experience random "out-of-memory" errors. Such errors can result in other errors or unexpected behavior in affected applications.
Allocation Error Panel (ISRUADCS) The term inconsistent attributes refers to incompatible values that have been specified for one or more of these items: Space units; Primary or Secondary quantity; Directory blocks; Record format; Record length; Block size.
The problem with dynamic memory allocation is that it is not deallocated itself, developer responsibility to deallocate the allocated memory explicitly. If we cannot release the allocated memory, it can because of memory leak and make your machine slow.
You can use ulimit
to limit the amount of resources a user can use, including memory. So you create a test user, limit their memory use to something just enough to launch your program, and watch it die :)
Example:
ulimit -m 64
Sets a memory limit of 64kb.
Create your own malloc wrapper which will randomly return null instead of a valid pointer. Well, or which fails consistently if you want to unit test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With