rtems_task Init(
    rtems_task_argument argument
)
{
    void                   *p1;
    bool                    retbool;
    Heap_Information_block  info;

    puts( "\n\n*** TEST WORKSPACE CLASSIC API ***" );

    puts( "rtems_workspace_get_information - null pointer" );
    retbool = rtems_workspace_get_information( NULL );
    rtems_test_assert( retbool == false );

    puts( "rtems_workspace_get_information - OK" );
    retbool = rtems_workspace_get_information( &info );
    rtems_test_assert( retbool == true );

    puts( "rtems_workspace_allocate - null pointer" );
    retbool = rtems_workspace_allocate( 42, NULL );
    rtems_test_assert( retbool == false );

    puts( "rtems_workspace_allocate - 0 bytes" );
    retbool = rtems_workspace_allocate( 0, &p1 );
    rtems_test_assert( retbool == false );

    puts( "rtems_workspace_allocate - too many bytes" );
    retbool = rtems_workspace_allocate( info.Free.largest * 2, &p1 );
    rtems_test_assert( retbool == false );

    puts( "rtems_workspace_allocate - 42 bytes" );
    retbool = rtems_workspace_allocate( 42, &p1 );
    rtems_test_assert( retbool == true );
    rtems_test_assert( p1 != NULL );

    puts( "rtems_workspace_free - NULL" );
    retbool = rtems_workspace_free( NULL );
    rtems_test_assert( retbool == false );

    puts( "rtems_workspace_free - previous pointer to 42 bytes" );
    retbool = rtems_workspace_free( p1 );
    rtems_test_assert( retbool == true );

    puts( "*** END OF TEST WORKSPACE CLASSIC API ***" );
    rtems_test_exit( 0 );
}
void Allocate_majority_of_workspace( int smallest )
{
  bool                   result;
  Heap_Information_block info;
  void                   *temp;

  puts("Allocate_majority_of_workspace: ");
  result = rtems_workspace_get_information( &info );
  if ( result != TRUE )
    perror("==> Error Getting workspace information");

  do {
    result = rtems_workspace_allocate(
      info.Free.largest-16,
      &temp
    );
    if ((!result) || (!temp))
      perror("Unable to allocate from workspace");
    result = rtems_workspace_get_information( &info );
  } while ( info.Free.largest >= smallest );

}
示例#3
0
void *POSIX_Init(
  void *ignored
)
{
  pthread_key_t           key;
  int                     sc;
  bool                    sb;
  Heap_Information_block  start;
  Heap_Information_block  info;
  size_t                  to_alloc;
  void                   *alloced;

  puts( "\n\n*** TEST KEY 02 ***" );

  puts( "Init - rtems_workspace_get_information - OK" );
  sb = rtems_workspace_get_information( &start );
  rtems_test_assert( sb );

  #if 0
    printf( "Init - workspace free = %d\n", start.Free.largest );
    printf( "Init - workspace free blocks = %d\n", start.Free.number );
  #endif
  rtems_test_assert( start.Free.number == 1 );
  to_alloc = start.Free.largest;

  /* find the largest we can actually allocate */
  while ( 1 ) {
    sb = rtems_workspace_allocate( to_alloc, &alloced );
    if ( sb )
      break;
    to_alloc -= 4;
  }

  rtems_workspace_free( alloced );

  #if 0
    printf( "Init - start with to_alloc of = %d\n", to_alloc );
  #endif

  /*
   * Verify heap is still in same shape if we couldn't allocate a task
   */
  sb = rtems_workspace_get_information( &info );
  rtems_test_assert( sb );
  rtems_test_assert( info.Free.largest == start.Free.largest );
  rtems_test_assert( info.Free.number  == start.Free.number  );

  puts( "Init - pthread_key_create - ENOMEM" );
  while (1) {

    sb = rtems_workspace_allocate( to_alloc, &alloced );
    rtems_test_assert( sb );

    sc = pthread_key_create( &key, NULL );

    /* free the memory we snagged, then check the status */
    rtems_workspace_free( alloced );

    if ( !sc )
      break;

    if ( sc != ENOMEM ) {
      printf( "key create returned %s\n", strerror(sc) );
      rtems_test_exit(0);
    }

    /*
     * Verify heap is still in same shape if we couldn't allocate a task
     */
    sb = rtems_workspace_get_information( &info );
    #if 0
      printf( "Init - workspace free/blocks = %d/%d\n",
        info.Free.largest, info.Free.number );
    #endif
    rtems_test_assert( sb );
    rtems_test_assert( info.Free.largest == start.Free.largest );
    rtems_test_assert( info.Free.number  == start.Free.number  );

    to_alloc -= 8;
    if ( to_alloc == 0 )
     break;
  }

  if ( sc )
    rtems_test_exit(0);

  /*
   * Verify heap is still in same shape after we free the task
   */
  puts( "Init - pthread_key_delete - OK" );
  sc = pthread_key_delete( key );
  rtems_test_assert( sc == 0 );

  puts( "Init - verify workspace has same memory" );
  sb = rtems_workspace_get_information( &info );
  #if 0
    printf( "Init - workspace free/blocks = %d/%d\n",
      info.Free.largest, info.Free.number );
  #endif
  rtems_test_assert( sb );
  rtems_test_assert( info.Free.largest == start.Free.largest );
  rtems_test_assert( info.Free.number  == start.Free.number  );

  puts( "*** END OF TEST KEY 02 ***" );
  rtems_test_exit(0);
}
示例#4
0
rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_id                region1;
  rtems_id                region2;
  rtems_status_code       sc;
  bool                    sb;
  Heap_Information_block  start;
  Heap_Information_block  info;
  size_t                  to_alloc;
  void                   *alloced;

  puts( "\n\n*** TEST 64 ***" );

  puts( "Allocate one region -- so second auto extends" );
  sc = rtems_region_create(
    rtems_build_name( 'R', 'N', '1', ' ' ),
    Area1,
    sizeof(Area1),
    8,
    RTEMS_DEFAULT_ATTRIBUTES,
    &region1
  );
  directive_failed( sc, "rtems_region_create of RN1" );

  puts( "Init - rtems_workspace_get_information - OK" );
  sb = rtems_workspace_get_information( &start );
  rtems_test_assert( sb );

  #if 0
    printf( "Init - workspace free = %d\n", start.Free.largest );
    printf( "Init - workspace free blocks = %d\n", start.Free.number );
  #endif
  rtems_test_assert( start.Free.number == 1 );
  to_alloc = start.Free.largest;

  /* find the largest we can actually allocate */
  while ( 1 ) {
    sb = rtems_workspace_allocate( to_alloc, &alloced );
    if ( sb )
      break;
    to_alloc -= 4;
  }

  rtems_workspace_free( alloced );

  #if 0
    printf( "Init - start with to_alloc of = %d\n", to_alloc );
  #endif

  /*
   * Verify heap is still in same shape if we couldn't allocate a region
   */
  sb = rtems_workspace_get_information( &info );
  rtems_test_assert( sb );
  rtems_test_assert( info.Free.largest == start.Free.largest );
  rtems_test_assert( info.Free.number  == start.Free.number  );

  puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" );
  while (1) {

    sb = rtems_workspace_allocate( to_alloc, &alloced );
    rtems_test_assert( sb );

    sc = rtems_region_create(
      rtems_build_name( 'R', 'N', '2', ' ' ),
      Area2,
      sizeof(Area2),
      8,
      RTEMS_DEFAULT_ATTRIBUTES,
      &region2
    );

    /* free the memory we snagged, then check the status */
    rtems_workspace_free( alloced );

    if ( sc == RTEMS_SUCCESSFUL )
      break;

    if ( sc != RTEMS_TOO_MANY ) {
      printf( "region create returned %d or %s\n", sc, rtems_status_text(sc) );
      rtems_test_exit(0);
    }

    /*
     * Verify heap is still in same shape if we couldn't allocate a region
     */
    sb = rtems_workspace_get_information( &info );
    #if 0
      printf( "Init - workspace free/blocks = %d/%d\n",
        info.Free.largest, info.Free.number );
    #endif
    rtems_test_assert( sb );
    rtems_test_assert( info.Free.largest == start.Free.largest );
    rtems_test_assert( info.Free.number  == start.Free.number  );

    to_alloc -= 8;
    if ( to_alloc == 0 )
     break;
  }

  if ( sc )
    rtems_test_exit(0);

  /*
   * Verify heap is still in same shape after we free the region
   */
  puts( "Init - rtems_region_delete - OK" );
  sc = rtems_region_delete( region2 );
  rtems_test_assert( sc == 0 );

  /*
   *  Although it is intuitive that after deleting the region the
   *  object space would shrink and go back to its original shape,
   *  we could end up with fragmentation which prevents a simple
   *  check from verifying this.
   */
  #if 0
    puts( "Init - verify workspace has same memory" );
    sb = rtems_workspace_get_information( &info );
    #if 0
        printf( "Init - workspace free/blocks = %d/%d\n",
      info.Free.largest, info.Free.number );
    #endif
    rtems_test_assert( sb );
    rtems_test_assert( info.Free.largest == start.Free.largest );
    rtems_test_assert( info.Free.number  == start.Free.number  );
  #endif

  puts( "*** END OF TEST 64 ***" );
  rtems_test_exit(0);
}
示例#5
0
void *POSIX_Init(
  void *argument
)
{
  struct mq_attr          attr;
  mqd_t                   Queue, second_Queue;
  int                     sc;
  Heap_Information_block  start;
  Heap_Information_block  info;
  size_t                  to_alloc;
  void                   *alloced;
  bool                    sb;
  const char             *name;

  puts( "\n\n*** POSIX MESSAGE QUEUE TEST 4 ***" );

  attr.mq_maxmsg = 1;
  attr.mq_msgsize = sizeof(int);

  puts( "Init - Open message queue instance 1" );
  Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr );
  if ( Queue == (-1) )
    perror( "mq_open failed" );
  rtems_test_assert( Queue != (-1) );

  puts( "Init - Open message queue instance 2 - FAIL - ENFILE " );
  second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr );
  if ( second_Queue != (-1) )
    puts( "mq_open did not failed" );
  rtems_test_assert( second_Queue == (-1) );
  rtems_test_assert( errno == ENFILE );

  puts( "Init - Unlink message queue instance 1" );
  sc = mq_unlink( "Queue" );
  if ( sc != 0 )
    perror( "mq_unlink failed" );
  rtems_test_assert( sc == 0 );

  puts( "Init - Close message queue instance 1" );
  sc = mq_close( Queue );
  if ( sc != 0 )
    perror( "mq_close failed" );
  rtems_test_assert( sc == 0 );

  sb = rtems_workspace_get_information( &start );
  rtems_test_assert( start.Free.number == 1 );
  to_alloc = start.Free.largest;

  /* find the largest we can actually allocate */
  while ( 1 ) {
    sb = rtems_workspace_allocate( to_alloc, &alloced );
    if ( sb )
      break;
    to_alloc -= 4;
  }

  rtems_workspace_free( alloced );

  /*
   * Now do the test
   */
  puts( "Init - Memory allocation error test" );

  sb = rtems_workspace_get_information( &info );

  attr.mq_maxmsg = 1;
  attr.mq_msgsize = 200;

  name = Get_Longest_Name();
  while ( attr.mq_msgsize > 0 ) {
    sb = rtems_workspace_allocate( to_alloc, &alloced );
    rtems_test_assert( sb );

    second_Queue = mq_open(name,O_CREAT | O_RDWR, 0x777, &attr );

    /* free the memory we snagged, then check the status */
    rtems_workspace_free( alloced );

    if ( second_Queue != (-1) )
      break;

    /* attr.mq_msgsize -= 48; */
    to_alloc -= 4;
  }

  if ( second_Queue == -1 )
    rtems_test_exit(0);

  puts( "Init - Message Queue created" );

  puts( "Init - Unlink message queue" );
    sc = mq_unlink( name );
    if ( sc != 0 )
      perror( "mq_unlink failed" );
    rtems_test_assert( sc == 0 );

  puts( "Init - Close message queue" );
    sc = mq_close( second_Queue );
    if ( sc != 0 )
      perror( "mq_close failed" );
    rtems_test_assert( sc == 0 );

  puts( "*** END OF POSIX MESSAGE QUEUE TEST 4 ***" );
  rtems_test_exit( 0 );

  return NULL; /* just so the compiler thinks we returned something */
}
示例#6
0
rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_id                task_id;
  rtems_status_code       sc;
  bool                    sb;
  Heap_Information_block  start;
  Heap_Information_block  info;
  size_t                  stack_size;

  puts( "\n\n*** TEST 18 ***" );

  puts( "Init - rtems_workspace_get_information - OK" );
  sb = rtems_workspace_get_information( &start );
  rtems_test_assert( sb );

  #if 0
    printf( "Init - workspace free = %d\n", start.Free.largest );
    printf( "Init - workspace free blocks = %d\n", start.Free.number );
  #endif
  rtems_test_assert( start.Free.number == 1 );
  stack_size = start.Free.largest;

  #if 0
    printf( "Init - start with stack size of = %d\n", stack_size );
  #endif

  puts( "Init - rtems_task_create - Unsatisfied on Extensions" );
  while (1) {

    sc = rtems_task_create(
      rtems_build_name( 'T', 'E', 'S', 'T' ),
      1,
      stack_size,
      RTEMS_DEFAULT_MODES,
      RTEMS_FLOATING_POINT,
      &task_id
    );

    if ( sc == RTEMS_SUCCESSFUL )
      break;

    fatal_directive_status( sc, RTEMS_UNSATISFIED, "rtems_task_create" );

    /*
     * Verify heap is still in same shape if we couldn't allocate a task
     */
    sb = rtems_workspace_get_information( &info );
    rtems_test_assert( sb );
    rtems_test_assert( info.Free.largest == start.Free.largest );
    rtems_test_assert( info.Free.number  == start.Free.number  );

    stack_size -= 8;
    if ( stack_size <= RTEMS_MINIMUM_STACK_SIZE )
     break;
  }

  if ( sc != RTEMS_SUCCESSFUL )
    rtems_test_exit(0);

  /*
   * Verify heap is still in same shape after we free the task
   */
  puts( "Init - rtems_task_delete - OK" );
  sc = rtems_task_delete( task_id );
  directive_failed( sc, "rtems_task_delete" );

  puts( "Init - verify workspace has same memory" );
  sb = rtems_workspace_get_information( &info );
  rtems_test_assert( sb );
  rtems_test_assert( info.Free.largest == start.Free.largest );
  rtems_test_assert( info.Free.number  == start.Free.number  );

  puts( "*** END OF TEST 18 ***" );
  rtems_test_exit(0);
}