Changeset 8a2944ab in rtems


Ignore:
Timestamp:
Sep 16, 2009, 10:14:11 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
ee3b1c13
Parents:
e0b66438
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/heapwalk.c

    re0b66438 r8a2944ab  
    2929#include <rtems/bspIo.h>
    3030
    31 static void _Heap_Walk_printk( int source, bool dump, bool error, const char *fmt, ... )
    32 {
    33   if ( dump ) {
    34     va_list ap;
    35 
    36     if ( error ) {
    37       printk( "FAIL[%d]: ", source );
    38     } else {
    39       printk( "PASS[%d]: ", source );
    40     }
    41 
    42     va_start( ap, fmt );
    43     vprintk( fmt, ap );
    44     va_end( ap );
    45   }
     31typedef (*Heap_Walk_printer)(int, bool, const char*, ...);
     32
     33static void _Heap_Walk_print_nothing(
     34  int source,
     35  bool error,
     36  const char *fmt,
     37  ...
     38)
     39{
     40  /* Do nothing */
     41}
     42
     43static void _Heap_Walk_print( int source, bool error, const char *fmt, ... )
     44{
     45  va_list ap;
     46
     47  if ( error ) {
     48    printk( "FAIL[%d]: ", source );
     49  } else {
     50    printk( "PASS[%d]: ", source );
     51  }
     52
     53  va_start( ap, fmt );
     54  vprintk( fmt, ap );
     55  va_end( ap );
    4656}
    4757
    4858static bool _Heap_Walk_check_free_list(
    4959  int source,
    50   bool dump,
     60  Heap_Walk_printer printer,
    5161  Heap_Control *heap
    5262)
     
    6070  while ( free_block != free_list_tail ) {
    6171    if ( !_Heap_Is_block_in_heap( heap, free_block ) ) {
    62       _Heap_Walk_printk(
    63         source,
    64         dump,
     72      (*printer)(
     73        source,
    6574        true,
    6675        "free block 0x%08x: not in heap\n",
     
    7483      !_Heap_Is_aligned( _Heap_Alloc_area_of_block( free_block ), page_size )
    7584    ) {
    76       _Heap_Walk_printk(
    77         source,
    78         dump,
     85      (*printer)(
     86        source,
    7987        true,
    8088        "free block 0x%08x: alloc area not page aligned\n",
     
    8694
    8795    if ( _Heap_Is_used( free_block ) ) {
    88       _Heap_Walk_printk(
    89         source,
    90         dump,
     96      (*printer)(
     97        source,
    9198        true,
    9299        "free block 0x%08x: is used\n",
     
    98105
    99106    if ( free_block->prev != prev_block ) {
    100       _Heap_Walk_printk(
    101         source,
    102         dump,
     107      (*printer)(
     108        source,
    103109        true,
    104110        "free block 0x%08x: invalid previous block 0x%08x\n",
     
    137143static bool _Heap_Walk_check_control(
    138144  int source,
    139   bool dump,
     145  Heap_Walk_printer printer,
    140146  Heap_Control *heap
    141147)
     
    148154  Heap_Block *const last_block = heap->last_block;
    149155
    150   _Heap_Walk_printk(
     156  (*printer)(
    151157    source,
    152     dump,
    153158    false,
    154159    "page size %u, min block size %u\n"
     
    163168
    164169  if ( page_size == 0 ) {
    165     _Heap_Walk_printk( source, dump, true, "page size is zero\n" );
     170    (*printer)( source, true, "page size is zero\n" );
    166171
    167172    return false;
     
    169174
    170175  if ( !_Addresses_Is_aligned( (void *) page_size ) ) {
    171     _Heap_Walk_printk(
    172       source,
    173       dump,
     176    (*printer)(
     177      source,
    174178      true,
    175179      "page size %u not CPU aligned\n",
     
    181185
    182186  if ( !_Heap_Is_aligned( min_block_size, page_size ) ) {
    183     _Heap_Walk_printk(
    184       source,
    185       dump,
     187    (*printer)(
     188      source,
    186189      true,
    187190      "min block size %u not page aligned\n",
     
    195198    !_Heap_Is_aligned( _Heap_Alloc_area_of_block( first_block ), page_size )
    196199  ) {
    197     _Heap_Walk_printk(
    198       source,
    199       dump,
     200    (*printer)(
     201      source,
    200202      true,
    201203      "first block 0x%08x: alloc area not page aligned\n",
     
    207209
    208210  if ( !_Heap_Is_prev_used( first_block ) ) {
    209     _Heap_Walk_printk(
    210       source,
    211       dump,
     211    (*printer)(
     212      source,
    212213      true,
    213214      "first block: HEAP_PREV_BLOCK_USED is cleared\n"
     
    218219
    219220  if ( first_block->prev_size != page_size ) {
    220     _Heap_Walk_printk(
    221       source,
    222       dump,
     221    (*printer)(
     222      source,
    223223      true,
    224224      "first block: prev size %u != page size %u\n",
     
    231231
    232232  if ( _Heap_Is_free( last_block ) ) {
    233     _Heap_Walk_printk(
    234       source,
    235       dump,
     233    (*printer)(
     234      source,
    236235      true,
    237236      "last block: is free\n"
     
    241240  }
    242241
    243   return _Heap_Walk_check_free_list( source, dump, heap );
     242  return _Heap_Walk_check_free_list( source, printer, heap );
    244243}
    245244
    246245static bool _Heap_Walk_check_free_block(
    247246  int source,
    248   bool dump,
     247  Heap_Walk_printer printer,
    249248  Heap_Control *heap,
    250249  Heap_Block *block
     
    259258  Heap_Block *const next_block = _Heap_Block_at( block, block_size );
    260259
    261   _Heap_Walk_printk(
     260  (*printer)(
    262261    source,
    263     dump,
    264262    false,
    265263    "block 0x%08x: prev 0x%08x%s, next 0x%08x%s\n",
     
    276274
    277275  if ( block_size != next_block->prev_size ) {
    278     _Heap_Walk_printk(
    279       source,
    280       dump,
     276    (*printer)(
     277      source,
    281278      true,
    282279      "block 0x%08x: size %u != size %u (in next block 0x%08x)\n",
     
    291288
    292289  if ( !prev_used ) {
    293     _Heap_Walk_printk(
    294       source,
    295       dump,
     290    (*printer)(
     291      source,
    296292      true,
    297293      "block 0x%08x: two consecutive blocks are free\n",
     
    303299
    304300  if ( !_Heap_Walk_is_in_free_list( heap, block ) ) {
    305     _Heap_Walk_printk(
    306       source,
    307       dump,
     301    (*printer)(
     302      source,
    308303      true,
    309304      "block 0x%08x: free block not in free list\n",
     
    327322  Heap_Block *const last_block = heap->last_block;
    328323  Heap_Block *block = heap->first_block;
     324  Heap_Walk_printer printer = dump ?
     325    _Heap_Walk_print : _Heap_Walk_print_nothing;
    329326
    330327  if ( !_System_state_Is_up( _System_state_Get() ) ) {
     
    332329  }
    333330
    334   if ( !_Heap_Walk_check_control( source, dump, heap ) ) {
     331  if ( !_Heap_Walk_check_control( source, printer, heap ) ) {
    335332    return false;
    336333  }
     
    344341
    345342    if ( prev_used ) {
    346       _Heap_Walk_printk(
    347         source,
    348         dump,
     343      (*printer)(
     344        source,
    349345        false,
    350346        "block 0x%08x: size %u\n",
     
    353349      );
    354350    } else {
    355       _Heap_Walk_printk(
    356         source,
    357         dump,
     351      (*printer)(
     352        source,
    358353        false,
    359354        "block 0x%08x: size %u, prev_size %u\n",
     
    365360
    366361    if ( !_Heap_Is_block_in_heap( heap, next_block ) ) {
    367       _Heap_Walk_printk(
    368         source,
    369         dump,
     362      (*printer)(
     363        source,
    370364        true,
    371365        "block 0x%08x: next block 0x%08x not in heap\n",
     
    378372
    379373    if ( !_Heap_Is_aligned( block_size, page_size ) ) {
    380       _Heap_Walk_printk(
    381         source,
    382         dump,
     374      (*printer)(
     375        source,
    383376        true,
    384377        "block 0x%08x: block size %u not page aligned\n",
     
    391384
    392385    if ( block_size < min_block_size ) {
    393       _Heap_Walk_printk(
    394         source,
    395         dump,
     386      (*printer)(
     387        source,
    396388        true,
    397389        "block 0x%08x: size %u < min block size %u\n",
     
    405397
    406398    if ( next_block_begin <= block_begin ) {
    407       _Heap_Walk_printk(
    408         source,
    409         dump,
     399      (*printer)(
     400        source,
    410401        true,
    411402        "block 0x%08x: next block 0x%08x is not a successor\n",
     
    418409   
    419410    if ( !_Heap_Is_prev_used( next_block ) ) {
    420       if ( !_Heap_Walk_check_free_block( source, dump, heap, block ) ) {
     411      if ( !_Heap_Walk_check_free_block( source, printer, heap, block ) ) {
    421412        return false;
    422413      }
Note: See TracChangeset for help on using the changeset viewer.