source: rtems/testsuites/libtests/heapwalk/init.c @ f4812a03

4.104.11
Last change on this file since f4812a03 was f4812a03, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 6, 2009 at 6:52:54 PM

2009-06-06 Joel Sherrill <joel.sherrill@…>

  • heapwalk/init.c: Add more automated corruption capability.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  Test of Heap Walker
3 *
4 *  COPYRIGHT (c) 1989-2008.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
15#define CONFIGURE_INIT
16#include "system.h"
17
18#include <stdlib.h>
19#include <inttypes.h>
20#include <errno.h>
21#include <string.h>
22#include <rtems/score/heap.h>
23
24#define TEST_HEAP_SIZE 1024
25uint32_t TestHeapMemory[TEST_HEAP_SIZE];
26Heap_Control TestHeap;
27
28void test_heap_init(void)
29{
30  memset( TestHeapMemory, '\0', sizeof(TestHeapMemory) );
31  _Heap_Initialize( &TestHeap, TestHeapMemory, sizeof(TestHeapMemory), 0 );
32}
33
34void test_heap_walk( int source, bool do_dump )
35{
36  int i, j, original;
37
38  _Heap_Walk( &TestHeap, source, do_dump );
39 
40  /*
41   *  Now corrupt all non-zero values
42   */
43  for (i=0 ; i<TEST_HEAP_SIZE ; i++) {
44    original = TestHeapMemory[i];
45    if ( original == 0 )
46      continue;
47
48    /* mark it free -- may or may not have already been */
49    TestHeapMemory[i] &= ~0x01;   
50    _Heap_Walk( &TestHeap, source, do_dump );
51
52    /* mark it used -- may or may not have already been */
53    TestHeapMemory[i] |= 0x01;   
54    _Heap_Walk( &TestHeap, source, do_dump );
55
56    /* try 0 and see what that does */
57    TestHeapMemory[i] = 0x00;   
58    _Heap_Walk( &TestHeap, source, do_dump );
59
60    /* try 0xffffffff and see what that does */
61    TestHeapMemory[i] = 0xffffffff;   
62    _Heap_Walk( &TestHeap, source, do_dump );
63
64    TestHeapMemory[i] = original;
65  }
66}
67
68void test_walk_freshly_initialized(void)
69{
70  puts( "Walk freshly initialized heap" );
71  test_heap_init();
72  test_heap_walk(1, true);
73}
74
75void test_negative_source_value(void)
76{
77  test_heap_init();
78  /*
79   * Passing a negative value for source so that
80   * the control enters the if block on line 67
81   */
82  puts( "Passing negative value for source" );
83  test_heap_walk( -1, true );
84}
85
86void test_prev_block_flag_check(void)
87{
88  /* Calling heapwalk without initialising the heap.
89   * Covers line 80 and 85 on heapwalk.
90   * Actually covers more than that.
91   */
92  puts( "Calling Heap Walk without initialising" );
93  _Heap_Walk( &TestHeap, 0x01, true );
94}
95
96rtems_task Init(
97  rtems_task_argument argument
98)
99{
100  puts( "\n\n*** HEAP WALK TEST ***" );
101
102  test_prev_block_flag_check();
103  test_walk_freshly_initialized();
104  test_negative_source_value();
105
106  puts( "*** END OF HEAP WALK TEST ***" );
107  rtems_test_exit(0);
108}
Note: See TracBrowser for help on using the repository browser.