Test-MemoryManager

Offers interface for allocating & freeing blocks of memory.  This is a test memory manager which checks for writing beyond the allocated memory block.  It is used during the execution of unit tests.

Summary
Test-MemoryManagerOffers interface for allocating & freeing blocks of memory.
CopyrightThis program is free software.
Files
C-kern/api/test/mm/testmm.hHeader file Test-MemoryManager.
C-kern/test/mm/testmm.cImplementation file Test-MemoryManager impl.
Types
struct testmm_tExports testmm_t.
Functions
test
unittest_test_mm_testmm
testmm_tTest memory manager for allocating/freeing blocks of memory.
context
isinstalled_testmmReturns true if test memory manager is installed.
mmcontext_testmmReturns the installed testmm_t memory manager or 0.
switchon_testmmStores current memory manager of threadcontext_t and installs testmm_t.
switchoff_testmmRestores memory manager of threadcontext_t.
lifetime
testmm_FREEStatic initializer.
init_testmmInitializes a new test memory manager.
free_testmmFrees all memory managed by this manager.
initasmm_testmmCalls init_testmm and wraps object into interface object mm_t.
freeasmm_testmmCalls free_testmm with object pointer from mm_t.
query
sizeallocated_testmmReturns the size in bytes of all allocated memory blocks.
allocate
malloc_testmmAllocates a new memory block.
mresize_testmmAllocates new or resizes already allocated memory block.
mfree_testmmFrees the memory of an allocated memory block.
inline implementation
Macros
isinstalled_testmmImplements testmm_t.isinstalled_testmm.

Copyright

This program 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 2 of the License, or (at your option) any later version.

This program 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.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/test/mm/testmm.h

Header file Test-MemoryManager.

C-kern/test/mm/testmm.c

Implementation file Test-MemoryManager impl.

Types

struct testmm_t

typedef struct testmm_t testmm_t

Exports testmm_t.

test

unittest_test_mm_testmm

int unittest_test_mm_testmm(void)
Test <testmm_t>memory manager for tests.

testmm_t

struct testmm_t

Test memory manager for allocating/freeing blocks of memory.

Summary
context
isinstalled_testmmReturns true if test memory manager is installed.
mmcontext_testmmReturns the installed testmm_t memory manager or 0.
switchon_testmmStores current memory manager of threadcontext_t and installs testmm_t.
switchoff_testmmRestores memory manager of threadcontext_t.
lifetime
testmm_FREEStatic initializer.
init_testmmInitializes a new test memory manager.
free_testmmFrees all memory managed by this manager.
initasmm_testmmCalls init_testmm and wraps object into interface object mm_t.
freeasmm_testmmCalls free_testmm with object pointer from mm_t.
query
sizeallocated_testmmReturns the size in bytes of all allocated memory blocks.
allocate
malloc_testmmAllocates a new memory block.
mresize_testmmAllocates new or resizes already allocated memory block.
mfree_testmmFrees the memory of an allocated memory block.

context

isinstalled_testmm

bool isinstalled_testmm(void)

Returns true if test memory manager is installed.

mmcontext_testmm

testmm_t * mmcontext_testmm(void)

Returns the installed testmm_t memory manager or 0.  If no memory manager of type testmm_t was installed with a previous call to switchon_testmm the value 0 is returned.

switchon_testmm

int switchon_testmm(void)

Stores current memory manager of threadcontext_t and installs testmm_t.

switchoff_testmm

int switchoff_testmm(void)

Restores memory manager of threadcontext_t.  The test memory manager in use (testmm_t) is freed and the memory manager in threadcontext_t is restored to one which was in used before switchon_testmm was called.

lifetime

testmm_FREE

#define testmm_FREE { 0, 0 }

Static initializer.

init_testmm

int init_testmm(/*out*/testmm_t *mman)

Initializes a new test memory manager.

free_testmm

int free_testmm(testmm_t *mman)

Frees all memory managed by this manager.  Before freeing it make sure that every object allocated on this memory heap is no more reachable or already freed.

initasmm_testmm

int initasmm_testmm(/*out*/struct mm_t *testmm)

Calls init_testmm and wraps object into interface object mm_t.  This function is called from switchon_testmm.

freeasmm_testmm

int freeasmm_testmm(struct mm_t *testmm)

Calls free_testmm with object pointer from mm_t.  This function is called from switchoff_testmm.

query

sizeallocated_testmm

size_t sizeallocated_testmm(testmm_t *mman)

Returns the size in bytes of all allocated memory blocks.  If this value is 0 no memory is allocated on this heap.

allocate

malloc_testmm

int malloc_testmm(testmm_t *mman,
size_t size,
/*out*/struct memblock_t *memblock)

Allocates a new memory block.  Test implementation replacement of <malloc_mmimpl>.

mresize_testmm

int mresize_testmm(testmm_t *mman,
size_t newsize,
struct memblock_t *memblock)

Allocates new or resizes already allocated memory block.  Test implementation replacement of <mresize_mmimpl>.

mfree_testmm

int mfree_testmm(testmm_t *mman,
struct memblock_t *memblock)

Frees the memory of an allocated memory block.  Test implementation replacement of <mfree_mmimpl>.

inline implementation

Macros

isinstalled_testmm

#define isinstalled_testmm() (0 != mmcontext_testmm())

Implements testmm_t.isinstalled_testmm.

Offers interface for allocating & freeing blocks of memory.
Implements TestMemoryManager.
typedef struct testmm_t testmm_t
Exports testmm_t.
struct testmm_t
Test memory manager for allocating/freeing blocks of memory.
int unittest_test_mm_testmm(void)
bool isinstalled_testmm(void)
Returns true if test memory manager is installed.
testmm_t * mmcontext_testmm(void)
Returns the installed testmm_t memory manager or 0.
int switchon_testmm(void)
Stores current memory manager of threadcontext_t and installs testmm_t.
int switchoff_testmm(void)
Restores memory manager of threadcontext_t.
#define testmm_FREE { 0, 0 }
Static initializer.
int init_testmm(/*out*/testmm_t *mman)
Initializes a new test memory manager.
int free_testmm(testmm_t *mman)
Frees all memory managed by this manager.
int initasmm_testmm(/*out*/struct mm_t *testmm)
Calls init_testmm and wraps object into interface object mm_t.
iobj_DECLARE(mm_t,
mm)
Uses iobj_DECLARE to declare interfaceable object.
int freeasmm_testmm(struct mm_t *testmm)
Calls free_testmm with object pointer from mm_t.
size_t sizeallocated_testmm(testmm_t *mman)
Returns the size in bytes of all allocated memory blocks.
int malloc_testmm(testmm_t *mman,
size_t size,
/*out*/struct memblock_t *memblock)
Allocates a new memory block.
int mresize_testmm(testmm_t *mman,
size_t newsize,
struct memblock_t *memblock)
Allocates new or resizes already allocated memory block.
int mfree_testmm(testmm_t *mman,
struct memblock_t *memblock)
Frees the memory of an allocated memory block.
#define isinstalled_testmm() (0 != mmcontext_testmm())
Implements testmm_t.isinstalled_testmm.
Close