2009-06-10 Joel Sherrill <joel.sherrill@OARcorp.com>

* heapwalk/init.c: Add test code for first free block pointer not
	aligned.
This commit is contained in:
Joel Sherrill
2009-06-10 15:28:10 +00:00
parent e050d9ae5a
commit 5f6a4a24fa
2 changed files with 47 additions and 16 deletions

View File

@@ -1,3 +1,8 @@
2009-06-10 Joel Sherrill <joel.sherrill@OARcorp.com>
* heapwalk/init.c: Add test code for first free block pointer not
aligned.
2009-06-08 Joel Sherrill <joel.sherrill@OARcorp.com>
* heapwalk/init.c: Add more cases.

View File

@@ -1,7 +1,7 @@
/*
* Test of Heap Walker
*
* COPYRIGHT (c) 1989-2008.
* COPYRIGHT (c) 1989-2009.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -32,12 +32,20 @@ void test_heap_init(void)
_Heap_Initialize( &TestHeap, TestHeapMemory, sizeof(TestHeapMemory), 0 );
}
void test_heap_walk( int source, bool do_dump )
void test_heap_walk_body( int source, bool do_dump );
void test_heap_walk( int source )
{
test_heap_walk_body( source, true );
test_heap_walk_body( source, false );
}
void test_heap_walk_body( int source, bool do_dump )
{
int i, j, original;
_Heap_Walk( &TestHeap, source, do_dump );
/*
* Now corrupt all non-zero values
*/
@@ -47,23 +55,26 @@ void test_heap_walk( int source, bool do_dump )
continue;
/* mark it free -- may or may not have already been */
printf( "%p -- free\n", i );
TestHeapMemory[i] &= ~0x01;
TestHeapMemory[i] &= ~0x01;
_Heap_Walk( &TestHeap, source, do_dump );
/* mark it used -- may or may not have already been */
printf( "%p -- used\n", i );
TestHeapMemory[i] |= 0x01;
TestHeapMemory[i] |= 0x01;
_Heap_Walk( &TestHeap, source, do_dump );
/* try values of 2-7 in the last three bits -- push alignment issues */
for (j=2 ; j<=7 ; j++) {
TestHeapMemory[i] = (TestHeapMemory[i] & ~0x7) | j;
_Heap_Walk( &TestHeap, source, do_dump );
}
/* try 0 and see what that does */
printf( "%p -- 0x00\n", i );
TestHeapMemory[i] = 0x00;
TestHeapMemory[i] = 0x00;
_Heap_Walk( &TestHeap, source, do_dump );
/* try 0xffffffff and see what that does */
printf( "%p -- 0xff\n", i );
TestHeapMemory[i] = 0xffffffff;
TestHeapMemory[i] = 0xffffffff;
_Heap_Walk( &TestHeap, source, do_dump );
TestHeapMemory[i] = original;
@@ -74,7 +85,7 @@ void test_walk_freshly_initialized(void)
{
puts( "Walk freshly initialized heap" );
test_heap_init();
test_heap_walk(1, true);
test_heap_walk(1);
}
void test_negative_source_value(void)
@@ -85,7 +96,7 @@ void test_negative_source_value(void)
*/
puts( "Passing negative value for source" );
test_heap_init();
test_heap_walk( -1, true );
test_heap_walk( -1 );
}
void test_prev_block_flag_check(void)
@@ -95,7 +106,7 @@ void test_prev_block_flag_check(void)
* Actually covers more than that.
*/
puts( "Calling Heap Walk without initialising" );
test_heap_walk( 1, true );
test_heap_walk( 1 );
}
void test_not_aligned(void)
@@ -109,7 +120,21 @@ void test_not_aligned(void)
puts( "Testing case of blocks not on page size" );
test_heap_init();
TestHeap.page_size = 128;
test_heap_walk( -1, true );
test_heap_walk( -1 );
}
void test_first_block_not_aligned(void)
{
/*
* Hack to get to the error case where the blocks are
* not on the page size. We initialize a heap with
* default settings and change the page size to something
* large.
*/
puts( "Testing case of blocks not on page size" );
test_heap_init();
_Heap_Head(&TestHeap)->next = (void *)1;
test_heap_walk( -1 );
}
void test_not_in_free_list(void)
@@ -128,7 +153,7 @@ void test_not_in_free_list(void)
p2 =_Heap_Allocate( &TestHeap, 32 );
p3 =_Heap_Allocate( &TestHeap, 32 );
_Heap_Free( &TestHeap, p2 );
test_heap_walk( -1, true );
test_heap_walk( -1 );
}
rtems_task Init(
@@ -142,6 +167,7 @@ rtems_task Init(
test_negative_source_value();
test_not_aligned();
test_not_in_free_list();
test_first_block_not_aligned();
puts( "*** END OF HEAP WALK TEST ***" );
rtems_test_exit(0);