test cache page allocation failure #442
Labels
good first issue
something that would be simple for a newcomer to stumpless to work on
help wanted
external contributations encouraged
testing
pertains to the test suite
Stumpless uses a simple slab cache implementation in
src/cache.c
to consolidate memory allocations for common structures like entries. Test coverage of this cache is fairly complete, but still has some gaps.One such gap is the failure of a new page allocation when the cache needs one. You will test for this case by causing a memory allocation failure after the cache has been set up and needs to add a new page.
General Approach
There are a few details left out of the following approach, for you to fill in as you encounter them. If you find you need help, please ask here or on the project gitter and someone can help you get past the stumbling block.
First, familiarize yourself with the
cache_alloc
implementation insrc/cache.c
. This function looks for a free slot in the cache, and if one is not found then it allocates a new page to make more space. You don't need to fully understand this function, but it will help to see what logic causes theadd_page
call to happen, which is what you will cause to fail.Next, devise a test that creates a single structure in a cache (entry structures are one such type) to set up the cache, set the memory allocation function to one that will fail, and then create new structures until the cache fills, attempts to allocate a new page, and fails. For an example of a test that creates several new structures look at
TEST( BufferTargetOpenTest, Open100Targets )
intest/function/target/buffer.cpp
, andTEST_F( EntryTest, AddNewParamMallocFailure )
intest/function/entry.cpp
for an example of a memory allocation failure test. If testing entry creation, put your new test intest/function/entry.cpp
.Make sure that you have full coverage on
add_page
insrc/cache.c
after this test. See the test documentation for details on checking coverage.The text was updated successfully, but these errors were encountered: