Changeset 85387db in rtems


Ignore:
Timestamp:
May 3, 2013, 3:28:48 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
57c05b54
Parents:
77ebea3
git-author:
Sebastian Huber <sebastian.huber@…> (05/03/13 15:28:48)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/03/13 15:30:53)
Message:

libtests/malloc04: Adjust for new sbrk() support

Location:
testsuites/libtests/malloc04
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • testsuites/libtests/malloc04/init.c

    r77ebea3 r85387db  
    4141#endif
    4242
    43 char Malloc_Heap[ 128 ] CPU_STRUCTURE_ALIGNMENT;
     43char Malloc_Heap[ 256 ] CPU_STRUCTURE_ALIGNMENT;
    4444int sbrk_count;
    4545Heap_Control TempHeap;
     
    5353  printf( "sbrk(%td)\n", incr );
    5454  if ( sbrk_count == -1 ) {
    55     p = (void *) (NULL - 2);
    56   } else if ( offset + incr < sizeof(Malloc_Heap) ) {
    57      p = &Malloc_Heap[ offset ];
    58      offset += incr;
    59   } else {
    60     if ( sbrk_count == 0 )
    61       p = (void *) rtems_task_create;
    62     sbrk_count++;
     55    p = (void *) -2;
     56    sbrk_count = 0;
     57  } else if ( offset + incr <= sizeof(Malloc_Heap) ) {
     58    p = &Malloc_Heap[ offset ];
     59    offset += incr;
    6360  }
    6461
    65   sbrk_count++;
     62  ++sbrk_count;
     63
    6664  return p;
    6765}
    68 
    69 void *p1, *p2, *p3, *p4;
    7066
    7167rtems_task Init(
     
    7571  Heap_Control *real_heap;
    7672  Heap_Area area;
    77 
    78   sbrk_count = 0;
    79   offset     = 0;
     73  void *p;
    8074
    8175  puts( "\n\n*** TEST MALLOC 04 ***" );
     
    8579  malloc_set_heap_pointer( &TempHeap );
    8680
     81  rtems_heap_set_sbrk_amount( 0 );
     82
     83  puts( "No sbrk() amount" );
     84
     85  sbrk_count = 0;
     86  offset     = 64;
     87  area.begin = &Malloc_Heap [0];
     88  area.size  = offset;
     89  RTEMS_Malloc_Initialize( &area, 1, NULL );
     90
     91  errno = 0;
     92  p = malloc(64);
     93  rtems_test_assert( p == NULL );
     94  rtems_test_assert( errno == ENOMEM );
     95  rtems_test_assert( sbrk_count == 0 );
     96
    8797  rtems_heap_set_sbrk_amount( 64 );
    8898
    89   puts( "Initialize heap with some memory" );
     99  puts( "Misaligned extend" );
     100
     101  sbrk_count = 0;
    90102  offset     = 64;
     103  area.begin = &Malloc_Heap [0];
     104  area.size  = offset;
     105  RTEMS_Malloc_Initialize( &area, 1, NULL );
     106
     107  p = malloc(1);
     108  rtems_test_assert( p != NULL );
     109  rtems_test_assert( sbrk_count == 0 );
     110
     111  p = malloc(65);
     112  rtems_test_assert( p != NULL );
     113  rtems_test_assert( sbrk_count == 1 );
     114
     115  puts( "Not enough sbrk() space" );
     116
    91117  sbrk_count = 0;
     118  offset     = 64;
    92119  area.begin = &Malloc_Heap [0];
    93   area.size = 64;
     120  area.size  = offset;
    94121  RTEMS_Malloc_Initialize( &area, 1, NULL );
    95   p1 = malloc(64);
    96   p2 = malloc(64);
    97   p3 = malloc(48);
    98   p4 = malloc(48);
    99  
    100   puts( "Initialize heap with some memory - return address out of heap" );
    101   area.begin = &Malloc_Heap [1];
    102   area.size = 64;
     122
     123  errno = 0;
     124  p = malloc( sizeof( Malloc_Heap ) );
     125  rtems_test_assert( p == NULL );
     126  rtems_test_assert( errno == ENOMEM );
     127  rtems_test_assert( sbrk_count == 1 );
     128
     129  puts( "Valid heap extend" );
     130
     131  sbrk_count = 0;
     132  offset     = 64;
     133  area.begin = &Malloc_Heap [0];
     134  area.size  = offset;
    103135  RTEMS_Malloc_Initialize( &area, 1, NULL );
     136
     137  p = malloc(32);
     138  rtems_test_assert( p != NULL );
     139  rtems_test_assert( sbrk_count == 0 );
     140
     141  p = malloc(32);
     142  rtems_test_assert( p != NULL );
     143  rtems_test_assert( sbrk_count == 1 );
     144
     145  puts( "Invalid heap extend" );
     146
     147  sbrk_count = -1;
    104148  offset     = 64;
    105   sbrk_count = -1;
    106   p1 = malloc( 127 );
    107   rtems_test_assert( p1 == (void *) NULL );
     149  area.begin = &Malloc_Heap [0];
     150  area.size  = offset;
     151  RTEMS_Malloc_Initialize( &area, 1, NULL );
     152
     153  errno = 0;
     154  p = malloc( 64 );
     155  rtems_test_assert( p == NULL );
    108156  rtems_test_assert( errno == ENOMEM );
    109  
    110 
    111   area.begin = &Malloc_Heap [0];
    112   area.size = 64;
    113   RTEMS_Malloc_Initialize( &area, 1, NULL );
    114   puts( "Initialize heap with some unaligned memory" );
    115   offset     = 65;
    116   sbrk_count = 0;
    117   area.begin = &Malloc_Heap [1];
    118   area.size = 64;
    119   RTEMS_Malloc_Initialize( &area, 1, NULL );
    120   p1 = malloc(64);
    121   p2 = malloc(64);
    122   p3 = malloc(48);
     157  rtems_test_assert( sbrk_count == 2 );
    123158
    124159  /* Restore information on real heap */
  • testsuites/libtests/malloc04/malloc04.scn

    r77ebea3 r85387db  
    11*** TEST MALLOC 04 ***
    2 Initialize heap with some memory
     2No sbrk() amount
     3Misaligned extend
    34sbrk(128)
    4 sbrk(128)
     5Not enough sbrk() space
     6sbrk(256)
     7Valid heap extend
    58sbrk(64)
    6 Initialize heap with some memory - return address out of heap
    7 sbrk(128)
    8 sbrk(-128)
    9 Initialize heap with some unaligned memory
    10 sbrk(128)
    11 sbrk(128)
     9Invalid heap extend
    1210sbrk(64)
     11sbrk(-64)
    1312*** END OF TEST MALLOC 04 ***
Note: See TracChangeset for help on using the changeset viewer.