Example #1
0
rtems_task Init(
  rtems_task_argument ignored
)
{
  int fd[2] = {0,0};
  int dummy_fd[2] = {0,0};
  int status = 0;
  void *opaque = NULL;

  TEST_BEGIN();

  puts( "Init - attempt to create pipe -- expect EFAULT" );
  status = pipe( NULL );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EFAULT );

  puts( "Init - create pipe -- OK" );
  status = pipe( fd );
  rtems_test_assert( status == 0 );

  status = close( fd[0] );
  status |= close( fd[1] );
  rtems_test_assert( status == 0 );

  puts( "Init - create pipe -- OK" );
  status = pipe( fd );
  rtems_test_assert( status == 0 );

  status = close( fd[0] );
  status |= close( fd[1] );
  rtems_test_assert( status == 0 );

  opaque = rtems_heap_greedy_allocate( NULL, 0 );

  /* case where mkfifo fails */
  puts( "Init - attempt to create pipe -- expect ENOMEM" );
  status = pipe( fd );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  rtems_heap_greedy_free( opaque );
  
  dummy_fd[0] = open( "/file01", O_RDONLY | O_CREAT, S_IRWXU );
  rtems_test_assert( dummy_fd[0] != -1 );
  dummy_fd[1] = open( "/file02", O_RDONLY | O_CREAT, S_IRWXU );
  rtems_test_assert( dummy_fd[1] != -1 );

  /* case where fifo_open for read => open fails */
  puts( "Init - create pipe -- expect ENFILE" );
  status = pipe( fd );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENFILE );

  status = close( dummy_fd[1] );
  status |= unlink( "/file02" );
  rtems_test_assert( status == 0 );

  /* case where fifo_open for write => open fails */
  puts( "Init - create pipe -- expect ENFILE" );
  status = pipe( fd );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENFILE );

  status = close( dummy_fd[0] );
  status |= unlink( "/file01" );
  rtems_test_assert( status == 0 );

  TEST_END();
  rtems_test_exit( 0 );
}
Example #2
0
File: test.c Project: Fyleo/rtems
int main(
  int    argc,
  char **argv
)
#endif
{
  pthread_rwlock_t     rwlock;
  pthread_rwlockattr_t attr;
  int                  status;
  int                  p;
  int                  i;
  struct timespec      abstime;

  TEST_BEGIN();

  /*************** NULL POINTER CHECKS *****************/
  puts( "pthread_rwlockattr_init( NULL ) -- EINVAL" );
  status = pthread_rwlockattr_init( NULL );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlockattr_setpshared( NULL, private ) -- EINVAL" );
  status = pthread_rwlockattr_setpshared( NULL, PTHREAD_PROCESS_PRIVATE );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlockattr_setpshared( NULL, shared ) -- EINVAL" );
  status = pthread_rwlockattr_setpshared( NULL, PTHREAD_PROCESS_SHARED );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlockattr_getpshared( NULL, &p ) -- EINVAL" );
  status = pthread_rwlockattr_getpshared( NULL, &p );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlockattr_destroy( NULL ) -- EINVAL" );
  status = pthread_rwlockattr_destroy( NULL );
  rtems_test_assert( status == EINVAL );

  /*************** NOT INITIALIZED CHECKS *****************/
  /* cheat visibility */
  attr.is_initialized = 0;
  puts( "pthread_rwlockattr_setpshared( &attr, shared ) -- EINVAL" );
  status = pthread_rwlockattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlockattr_getpshared( &attr, NULL ) -- EINVAL" );
  status = pthread_rwlockattr_getpshared( &attr, NULL );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlockattr_destroy( &attr ) -- EINVAL" );
  status = pthread_rwlockattr_destroy( &attr );
  rtems_test_assert( status == EINVAL );

  /*************** BAD PSHARED CHECK *****************/
  puts( "pthread_rwlockattr_setpshared( &attr, private ) -- EINVAL" );
  status = pthread_rwlockattr_setpshared( &attr, ~PTHREAD_PROCESS_PRIVATE );
  rtems_test_assert( status == EINVAL );

  /*************** ACTUALLY WORK THIS TIME *****************/
  puts( "pthread_rwlockattr_init( &attr ) -- OK" );
  status = pthread_rwlockattr_init( &attr );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlockattr_setpshared( &attr, private ) -- OK" );
  status = pthread_rwlockattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlockattr_getpshared( &attr, &p ) -- OK" );
  status = pthread_rwlockattr_getpshared( &attr, &p );
  rtems_test_assert( status == 0 );
  rtems_test_assert( p == PTHREAD_PROCESS_PRIVATE );

  puts( "pthread_rwlockattr_setpshared( &attr, shared ) -- OK" );
  status = pthread_rwlockattr_setpshared( &attr, PTHREAD_PROCESS_SHARED );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlockattr_getpshared( &attr, &p ) -- OK" );
  status = pthread_rwlockattr_getpshared( &attr, &p );
  rtems_test_assert( status == 0 );
  rtems_test_assert( p == PTHREAD_PROCESS_SHARED );

  /*************** DESTROY/REUSE CHECK *****************/
  puts( "pthread_rwlockattr_destroy( &attr ) -- OK" );
  status = pthread_rwlockattr_destroy( &attr );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlockattr_getpshared( &attr, &p ) destroyed -- EINVAL" );
  status = pthread_rwlockattr_getpshared( &attr, &p );
  rtems_test_assert( status == EINVAL );

  /*************** NULL ARGUMENT CHECKS *****************/
  abstime.tv_sec = 0;
  abstime.tv_nsec = 0;

  puts( "pthread_rwlock_init(NULL, &attr) -- EINVAL" );
  status = pthread_rwlock_init(NULL, &attr);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_destroy(NULL) -- EINVAL" );
  status = pthread_rwlock_destroy(NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_rdlock(NULL) -- EINVAL" );
  status = pthread_rwlock_rdlock(NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_timedrdlock( NULL, &abstime) -- EINVAL" );
  status = pthread_rwlock_timedrdlock( NULL, &abstime);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_timedrdlock( &rwlock, NULL) -- EINVAL" );
  status = pthread_rwlock_timedrdlock( &rwlock, NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_tryrdlock(NULL) -- EINVAL" );
  status = pthread_rwlock_tryrdlock(NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_wrlock(NULL) -- EINVAL" );
  status = pthread_rwlock_wrlock(NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_timedwrlock( NULL, &abstime) -- EINVAL" );
  status = pthread_rwlock_timedwrlock( NULL, &abstime );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_timedwrlock( &rwlock, NULL) -- EINVAL" );
  status = pthread_rwlock_timedwrlock( &rwlock, NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_trywrlock(NULL) -- EINVAL" );
  status = pthread_rwlock_trywrlock(NULL);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_unlock(NULL) -- EINVAL" );
  status = pthread_rwlock_unlock(NULL);
  rtems_test_assert( status == EINVAL );

  /*************** BAD ID CHECK *****************/
  rwlock = 1;
  /* make a valid abstime */
  puts( "clock_gettime(CLOCK_REALTIME, &abstime) -- OK" );
  status = clock_gettime( CLOCK_REALTIME, &abstime );
  rtems_test_assert( !status );
  abstime.tv_sec += 5;

  puts( "pthread_rwlock_destroy(BadId) -- EINVAL" );
  status = pthread_rwlock_destroy(&rwlock);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_rdlock(BadId) -- EINVAL" );
  status = pthread_rwlock_rdlock(&rwlock);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_timedrdlock(BadId, &abstime) -- EINVAL" );
  status = pthread_rwlock_timedrdlock( &rwlock, &abstime);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_tryrdlock(BadId) -- EINVAL" );
  status = pthread_rwlock_tryrdlock(&rwlock);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_wrlock(BadId) -- EINVAL" );
  status = pthread_rwlock_wrlock(&rwlock);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_timedwrlock(BadId, &abstime) -- EINVAL" );
  status = pthread_rwlock_timedwrlock( &rwlock, &abstime );
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_trywrlock(BadId) -- EINVAL" );
  status = pthread_rwlock_trywrlock(&rwlock);
  rtems_test_assert( status == EINVAL );

  puts( "pthread_rwlock_unlock(BadId) -- EINVAL" );
  status = pthread_rwlock_unlock(&rwlock);
  rtems_test_assert( status == EINVAL );

  /*************** BAD ABSTIME CHECK *****************/

  /* in the past */
  abstime.tv_sec = 0;
  abstime.tv_nsec = 0;

  /* invalid tv_nsec */
  abstime.tv_sec = 0;
  abstime.tv_nsec = 0x7fffffffL;

  /* XXX do we need bad time check? */

  /*************** ACTUALLY CREATE ONE CHECK *****************/
  puts( "pthread_rwlockattr_init( &attr ) -- OK" );
  status = pthread_rwlockattr_init( &attr );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlock_init( &rwlock, &attr ) -- OK" );
  status = pthread_rwlock_init( &rwlock, &attr );
  rtems_test_assert( status == 0 );
  rtems_test_assert( rwlock != 0 );

  puts( "pthread_rwlock_init( &rwlock, &attr ) -- EAGAIN" );
  status = pthread_rwlock_init( &rwlock, &attr );
  rtems_test_assert( status == EAGAIN );

  puts( "pthread_rwlock_destroy( &rwlock ) -- OK" );
  status = pthread_rwlock_destroy( &rwlock );
  rtems_test_assert( status == 0 );

  /********* CREATE RWLOCK WITH DEFAULT ATTRIBUTES AND DESTROY IT *********/
  puts( "pthread_rwlock_init( &rwlock, NULL ) -- OK" );
  status = pthread_rwlock_init( &rwlock, NULL );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlock_destroy( &rwlock ) -- OK" );
  status = pthread_rwlock_destroy( &rwlock );
  rtems_test_assert( status == 0 );

  /*************** CREATE THREADS AND LET THEM OBTAIN READLOCK ***************/
  puts( "pthread_rwlock_init( &RWLock, &attr ) -- OK" );
  status = pthread_rwlock_init( &RWLock, &attr );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlock_tryrdlock(RWLock) -- OK" );
  status = pthread_rwlock_tryrdlock(&RWLock);
  rtems_test_assert( !status );

  for (i=0 ; i<NUMBER_THREADS ; i++ ) {
    printf( "Init: pthread_create - thread %d OK\n", i+1 );
    status = pthread_create(&ThreadIds[i], NULL, ReadLockThread, &ThreadIds[i]);
    rtems_test_assert( !status );

    sleep(1);
  }

  puts( "pthread_rwlock_unlock(RWLock) -- OK" );
  status = pthread_rwlock_unlock(&RWLock);
  rtems_test_assert( !status );

  sleep(1);

  /*************** CREATE THREADS AND LET THEM OBTAIN READLOCK ***************/
  puts( "pthread_rwlock_trywrlock(RWLock) -- OK" );
  status = pthread_rwlock_trywrlock(&RWLock);
  rtems_test_assert( !status );

  puts( "pthread_rwlock_tryrdlock(&RWLock) -- EBUSY" );
  status = pthread_rwlock_tryrdlock(&RWLock);
  rtems_test_assert( status == EBUSY );

  for (i=0 ; i<NUMBER_THREADS ; i++ ) {
    printf( "Init: pthread_create - thread %d OK\n", i+1 );
    status = pthread_create(&ThreadIds[i], NULL, ReadLockThread, &ThreadIds[i]);
    rtems_test_assert( !status );

    sleep(1);
  }

  /* Attempt delete while threads are blocked */
  puts( "pthread_rwlock_destroy( &RWLock ) -- EBUSY" );
  status = pthread_rwlock_destroy( &RWLock );
  rtems_test_assert( status == EBUSY );

  /* now unlock it so the threads can continue */
  puts( "pthread_rwlock_unlock(RWLock) -- OK" );
  status = pthread_rwlock_unlock(&RWLock);
  rtems_test_assert( !status );

  sleep(2);

  /*************** CREATE THREADS AND LET THEM OBTAIN WRITE LOCK *************/
  puts( "\npthread_rwlock_trywrlock(RWLock) -- OK" );
  status = pthread_rwlock_trywrlock(&RWLock);
  rtems_test_assert( !status );

  puts( "pthread_rwlock_trywrlock(&RWLock) -- EBUSY" );
  status = pthread_rwlock_trywrlock(&RWLock);
  rtems_test_assert( status == EBUSY );

  for (i=0 ; i<NUMBER_THREADS ; i++ ) {
    printf( "Init: pthread_create - thread %d OK\n", i+1 );
    status =
      pthread_create(&ThreadIds[i], NULL, WriteLockThread, &ThreadIds[i]);
    rtems_test_assert( !status );

    sleep(2);
  }

  puts( "pthread_rwlock_unlock(RWLock) -- OK" );
  status = pthread_rwlock_unlock(&RWLock);
  rtems_test_assert( !status );

  sleep(6);

  /*************** CREATE THREADS AND LET THEM OBTAIN WRITE LOCK *************/
  /***************    THEN ATTEMPT TO OBTAIN A READLOCK          *************/
 
  puts( "\npthread_rwlock_tryrdlock(&RWLock) -- OK" );
  status = pthread_rwlock_tryrdlock(&RWLock);
  rtems_test_assert( !status );

  printf( "Init: pthread_create - thread reader & writer OK\n" );
  status = pthread_create(&ThreadIds[0], NULL, WriteLockThread, &ThreadIds[0]);
  rtems_test_assert( !status );

  sleep(1);
  status = pthread_create(&ThreadIds[1], NULL, ReadLockThread, &ThreadIds[1]);
  rtems_test_assert( !status );

  sleep(1);

  puts( "pthread_rwlock_tryrdlock(&RWLock) -- EBUSY" );
  status = pthread_rwlock_tryrdlock(&RWLock);
  rtems_test_assert( status == EBUSY );

  puts( "pthread_rwlock_trywrlock(&RWLock) -- EBUSY" );
  status = pthread_rwlock_trywrlock(&RWLock);
  rtems_test_assert( status == EBUSY );

  sleep( 5 );

  puts( "pthread_rwlock_unlock(&RWLock) -- OK" );
  status = pthread_rwlock_unlock(&RWLock);
  rtems_test_assert( !status );

  sleep( 5 );

  /*************** TIMEOUT ON RWLOCK ***************/
  puts( "clock_gettime(CLOCK_REALTIME, &abstime) -- OK" );
  status = clock_gettime( CLOCK_REALTIME, &abstime );
  rtems_test_assert( !status );

  abstime.tv_sec += 1;
  puts( "pthread_rwlock_timedwrlock( &RWLock, &abstime) -- OK" );
  status = pthread_rwlock_timedwrlock( &RWLock, &abstime );
  rtems_test_assert( status == 0 );

  abstime.tv_sec += 1;
  puts( "pthread_rwlock_timedrdlock( &RWLock, &abstime) -- ETIMEDOUT" );
  status = pthread_rwlock_timedrdlock( &RWLock, &abstime );
  rtems_test_assert( status == ETIMEDOUT );

  abstime.tv_sec -= 1;
  puts( "pthread_rwlock_timedrdlock( &RWLock, &abstime) -- ETIMEDOUT" );
  status = pthread_rwlock_timedrdlock( &RWLock, &abstime );
  rtems_test_assert( status == ETIMEDOUT );

  abstime.tv_sec -= 1;
  puts( "pthread_rwlock_timedwrlock( &RWLock, &abstime) -- ETIMEDOUT" );
  status = pthread_rwlock_timedwrlock( &RWLock, &abstime );
  rtems_test_assert( status == ETIMEDOUT );

  /*************** OBTAIN RWLOCK WITH ABSTIME IN PAST ***************/
  status = pthread_rwlock_unlock(&RWLock);
  rtems_test_assert( !status );

  abstime.tv_sec -= 1;
  puts( "pthread_rwlock_timedrdlock( &RWLock, &abstime) -- in past -- OK" );
  status = pthread_rwlock_timedrdlock( &RWLock, &abstime );
  rtems_test_assert( status == 0 );

  /*************** OBTAIN RWLOCK FOR WRITE WITH ABSTIME IN PAST ***************/
  status = pthread_rwlock_unlock(&RWLock);
  rtems_test_assert( !status );

  abstime.tv_sec -= 1;
  puts( "pthread_rwlock_timedwrlock( &RWLock, &abstime) -- in past -- OK" );
  status = pthread_rwlock_timedwrlock( &RWLock, &abstime );
  rtems_test_assert( status == 0 );

  /*************** DESTROY RWLOCK ***************/
  puts( "pthread_rwlock_destroy( &RWLock ) -- OK" );
  status = pthread_rwlock_destroy( &RWLock );
  rtems_test_assert( status == 0 );

  /*************** OBTAIN A LOCK AND THEN RELEASE IT TWICE ***************/

  puts( "pthread_rwlock_init( &rwlock, NULL ) -- OK" );
  status = pthread_rwlock_init( &rwlock, NULL );
  rtems_test_assert( status == 0 );
  rtems_test_assert( rwlock != 0 );

  puts( "pthread_rwlock_unlock ( &rwlock ) -- OK" );
  status = pthread_rwlock_unlock( &rwlock );
  rtems_test_assert( status == 0 );

  puts( "pthread_rwlock_unlock ( &rwlock ) -- OK" );
  status = pthread_rwlock_unlock( &rwlock );
  rtems_test_assert( status == 0 );

  /*************** END OF TEST *****************/
  TEST_END();
  exit(0);
}
Example #3
0
static void test_task_get_set_scheduler(void)
{
  rtems_status_code sc;
  rtems_id self_id = rtems_task_self();
  rtems_name name = BLUE;
  rtems_id scheduler_id;
  rtems_id scheduler_by_name;
  rtems_id task_id;
  rtems_id mtx_id;

  sc = rtems_scheduler_ident(name, &scheduler_by_name);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_get_scheduler(RTEMS_SELF, NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);

  sc = rtems_task_get_scheduler(invalid_id, &scheduler_id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  scheduler_id = 0;
  sc = rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(scheduler_id == scheduler_by_name);

  scheduler_id = 0;
  sc = rtems_task_get_scheduler(self_id, &scheduler_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(scheduler_id == scheduler_by_name);

  sc = rtems_task_set_scheduler(invalid_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  sc = rtems_task_set_scheduler(self_id, invalid_id, 1);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, UINT32_C(0x80000000));
  rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_create(
    rtems_build_name(' ', 'M', 'T', 'X'),
    0,
    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
    0,
    &mtx_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_release(mtx_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(set_prio(self_id, RTEMS_CURRENT_PRIORITY) == 1);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 2);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(set_prio(self_id, RTEMS_CURRENT_PRIORITY) == 2);

  sc = rtems_task_set_scheduler(self_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(set_prio(self_id, RTEMS_CURRENT_PRIORITY) == 1);

  sc = rtems_semaphore_delete(mtx_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    2,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  scheduler_id = 0;
  sc = rtems_task_get_scheduler(task_id, &scheduler_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(scheduler_id == scheduler_by_name);

  sc = rtems_task_set_scheduler(task_id, scheduler_id, 2);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(task_id, forbidden_task, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_scheduler(task_id, scheduler_id, 2);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    2,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(task_id, restart_task, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_suspend(self_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_create(
    rtems_build_name('S', 'E', 'M', 'A'),
    0,
    RTEMS_COUNTING_SEMAPHORE,
    0,
    &sema_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    1,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(task_id, sema_task, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_scheduler(task_id, scheduler_id, 1);
  rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE);

  sc = rtems_semaphore_delete(sema_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Example #4
0
File: init.c Project: medivhc/rtems
static void test_blkdev_imfs_errors(void)
{
  rtems_status_code sc;
  int rv;
  ramdisk *rd;
  void *opaque;

  rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);
  rtems_test_assert(rd != NULL);

  ramdisk_enable_free_at_delete_request(rd);

  sc = rtems_blkdev_create(
    rda,
    0,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    0,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  opaque = rtems_heap_greedy_allocate(0);
  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_NO_MEMORY);
  rtems_heap_greedy_free(opaque);

  opaque = rtems_heap_greedy_allocate(sizeof(rtems_disk_device) + sizeof(int));
  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_UNSATISFIED);
  rtems_heap_greedy_free(opaque);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  ASSERT_SC(sc);

  sc = rtems_blkdev_create_partition(
    rda1,
    not_exist,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  rv = mknod(not_blkdev, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
  rtems_test_assert(rv == 0);

  sc = rtems_blkdev_create_partition(
    rda1,
    not_blkdev,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_NODE);

  rv = mknod(invalid_blkdev, S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO, 0);
  rtems_test_assert(rv == 0);

  sc = rtems_blkdev_create_partition(
    rda1,
    invalid_blkdev,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    0
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    BLOCK_COUNT,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT + 1
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  opaque = rtems_heap_greedy_allocate(0);
  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_NO_MEMORY);
  rtems_heap_greedy_free(opaque);

  opaque = rtems_heap_greedy_allocate(sizeof(rtems_disk_device) + sizeof(int));
  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_UNSATISFIED);
  rtems_heap_greedy_free(opaque);

  rv = unlink(rda);
  rtems_test_assert(rv == 0);
}
Example #5
0
rtems_task Init(
  rtems_task_argument argument
)
{
  clock_t    start;
  clock_t    end;
  clock_t    now;
  clock_t    sc;
  clock_t    difference;
  struct tms start_tm;
  struct tms end_tm;

  puts( "\n\n*** TEST TIMES 01 ***" );

  puts( "times( NULL ) -- EFAULT" );
  sc = times( NULL );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EFAULT );

  puts( "_times_r( NULL, NULL ) -- EFAULT" );
  start = _times_r( NULL, NULL );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EFAULT );

  while ( rtems_clock_get_ticks_since_boot() == 0 )
    ;

  puts( "_times( &start_tm ) -- OK" );
  now = _times( &start_tm );
  rtems_test_assert( start != 0 );
  rtems_test_assert( now != 0 );
  
  rtems_test_spin_for_ticks(5);

  puts( "_times( &end_tm ) -- OK" );
  end = _times( &end_tm );
  rtems_test_assert( end != 0 );
  
  puts( "Check various values" );
  difference = end - start;
  rtems_test_assert( difference >= 5 );

  rtems_test_assert( end_tm.tms_utime >= start_tm.tms_utime );
  rtems_test_assert( end_tm.tms_stime >= start_tm.tms_stime );
  rtems_test_assert( end_tm.tms_cutime == 0 );
  rtems_test_assert( end_tm.tms_cstime == 0 );
  
  puts( "*** END OF TEST TIMES 01 ***" );

  rtems_test_exit(0);
}
Example #6
0
static void test_chain_with_notification(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_chain_control chain;
  rtems_chain_node a;
  rtems_chain_node b;
  rtems_chain_node *p = (rtems_chain_node *) 1;
  rtems_event_set out = 0;

  puts( "INIT - Verify rtems_chain_append_with_notification" );
  rtems_chain_initialize_empty( &chain );
  sc = rtems_chain_append_with_notification(
    &chain,
    &a,
    rtems_task_self(),
    EVENT
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( p == &a );

  rtems_chain_initialize_empty( &chain );

  rtems_chain_append( &chain, &b );
  sc = rtems_chain_append_with_notification(
    &chain,
    &a,
    rtems_task_self(),
    EVENT
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( p == &a );

  puts( "INIT - Verify rtems_chain_prepend_with_notification" );
  rtems_chain_initialize_empty( &chain );
  sc = rtems_chain_prepend_with_notification(
    &chain,
    &a,
    rtems_task_self(),
    EVENT
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( p == &a );

  rtems_chain_prepend( &chain, &b );
  sc = rtems_chain_prepend_with_notification(
    &chain,
    &a,
    rtems_task_self(),
    EVENT
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( p == &a );

  puts( "INIT - Verify rtems_chain_prepend_with_notification" );
  puts( "INIT - Verify rtems_chain_get_with_notification" );
  rtems_chain_initialize_empty( &chain );

  rtems_chain_append( &chain, &b );
  rtems_chain_append( &chain, &a );

  sc = rtems_chain_get_with_notification(&chain, rtems_task_self(), EVENT, &p);
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( p == &b );

  sc = rtems_chain_get_with_notification(&chain, rtems_task_self(), EVENT, &p);
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( p == &a );
  sc = rtems_event_receive(
    EVENT,
    RTEMS_EVENT_ALL | RTEMS_WAIT,
    TIMEOUT,
    &out
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( out == EVENT );
}
Example #7
0
File: init.c Project: medivhc/rtems
static void area_compare(const long *area_a, const long *area_b, bool equal)
{
  bool actual_equal = memcmp(area_a, area_b, AREA_SIZE) == 0;
  rtems_test_assert(actual_equal == equal);
}
Example #8
0
static void test(void)
{
  rtems_status_code   sc;
  uint32_t            cpu_count;
  int                 cpu;
  int                 i;
  cpu_set_t           cpuset;

  /* Get the number of processors that we are using. */
  cpu_count = rtems_get_processor_count();
  if (cpu_count < 2) {
    printf("Error: Test requires at least 2 cpus\n");
    return;
  }

  printf("Create Semaphore\n");
  sc = rtems_semaphore_create(  
    rtems_build_name('S', 'E', 'M', '0'),
    1,                                               /* initial count = 1 */
    RTEMS_LOCAL                   |
    RTEMS_SIMPLE_BINARY_SEMAPHORE |
    RTEMS_NO_INHERIT_PRIORITY     |
    RTEMS_NO_PRIORITY_CEILING     |
    RTEMS_FIFO,
    0,
    &task_sem
  );  
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  /*
   * Create and start TA1 at a higher priority
   * than the init task. 
   */
  sc = rtems_task_create(
    rtems_build_name('T', 'A', '0', '1'),
    4,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_data.id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  printf("Start TA1\n");
  sc = rtems_task_start( task_data.id, task, 0 );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  /* 
   * Verify the Init task is running on the max core.
   */ 
  printf("Verify Init task is on cpu %ld\n",cpu_count-1);
  cpu = rtems_get_current_processor();
  rtems_test_assert(cpu == (cpu_count-1));

  /* Walk TA1 across all of the cores */
  for(i=0; i < cpu_count; i++) {
    /* Set the Affinity to core i */
    CPU_ZERO(&cpuset);
    CPU_SET(i, &cpuset);
    printf("Set Affinity TA1 to cpu %d\n", i);
    sc = rtems_task_set_affinity( task_data.id, sizeof(cpuset), &cpuset );
    rtems_test_assert(sc == RTEMS_SUCCESSFUL);

    /* Wait a bit to be sure it has switched cores then clear the task data */
    test_delay(50);
    while( rtems_semaphore_obtain (task_sem, RTEMS_NO_WAIT, 0) != RTEMS_SUCCESSFUL );
    task_data.ran = false;
    task_data.expected_cpu = i;
    rtems_semaphore_release(task_sem);
    test_delay(50);

    /* Verify the task ran on core i */
    while( rtems_semaphore_obtain (task_sem, RTEMS_NO_WAIT, 0) != RTEMS_SUCCESSFUL );
    if (task_data.ran != true)
      printf("Error: TA01 never ran.\n");
    else
      printf(
        "TA1 expected cpu: %d actual cpu %d\n", 
        task_data.expected_cpu,
        task_data.actual_cpu
      );
    rtems_test_assert(task_data.ran == true);
    rtems_test_assert(task_data.expected_cpu == task_data.actual_cpu);
    rtems_semaphore_release(task_sem);
  }
}
Example #9
0
void *POSIX_Init(
  void *argument
)
{
  int                 sc;
  pthread_t           id;
  struct sigaction    act;
  bool                trueArg = true;
  bool                falseArg = false;
  struct timespec     delay_request;

  puts( "\n\n*** POSIX TEST SIGNAL " TEST_NAME " ***" );
  puts( "Init - Variation is: " TEST_STRING );

  Signal_occurred = false;

  act.sa_handler = NULL;
  act.sa_sigaction = Signal_handler;
  act.sa_flags   = SA_SIGINFO;
  sigaction( SIGNAL_ONE, &act, NULL );
  sigaction( SIGNAL_TWO, &act, NULL );

  /* create threads */
  sc = pthread_create( &id, NULL, Test_Thread, &falseArg );
  rtems_test_assert(  !sc );

  sc = pthread_create( &id, NULL, Test_Thread, &trueArg );
  rtems_test_assert(  !sc );

  puts( "Init - sleep - let threads settle - OK" );
  delay_request.tv_sec = 0;
  delay_request.tv_nsec = 5 * 100000000;
  sc = nanosleep( &delay_request, NULL );
  rtems_test_assert(  !sc );

  puts( "Init - sleep - SignalBlocked thread settle - OK" );
  sc = nanosleep( &delay_request, NULL );
  rtems_test_assert(  !sc );

  printf( "Init - sending %s - deliver to one thread\n",
          signal_name(SIGNAL_TWO));
  sc =  SEND_SIGNAL( SIGNAL_TWO );
  rtems_test_assert(  !sc );

  printf( "Init - sending %s - deliver to other thread\n",
          signal_name(SIGNAL_TWO));
  sc =  SEND_SIGNAL( SIGNAL_TWO );
  rtems_test_assert(  !sc );

  #if defined(TO_PROCESS)
    printf( "Init - sending %s - expect EAGAIN\n", signal_name(SIGNAL_TWO) );
    sc =  SEND_SIGNAL( SIGNAL_TWO );
    rtems_test_assert(  sc == -1 );
    rtems_test_assert(  errno == EAGAIN );
  #endif

  puts( "Init - sleep - let thread report if it unblocked - OK" );
  usleep(500000);

  /* we are just sigwait'ing the signal, not delivering it */
  rtems_test_assert(  Signal_occurred == true );

  puts( "*** END OF POSIX TEST SIGNAL " TEST_NAME " ***" );
  rtems_test_exit(0);

  return NULL; /* just so the compiler thinks we returned something */
}
Example #10
0
int main(){
  struct sigaction act;
  pthread_t        newThread;
  pthread_t        mainThread;
  int              status;
  int              i;

  status = sem_init(&GC_suspend_ack_sem, 0, 0);
  rtems_test_assert( status == 0 );

  status = sigemptyset(&act.sa_mask);
  rtems_test_assert( status == 0 );

  status = sigaddset(&act.sa_mask,SIG_SUSPEND);
  rtems_test_assert( status == 0 );

  status = sigaddset(&act.sa_mask,SIG_THR_RESTART);
  rtems_test_assert( status == 0 );

  status = pthread_sigmask(SIG_UNBLOCK,&act.sa_mask,NULL);
  rtems_test_assert( status == 0 );

  act.sa_handler=GC_suspend_handler;

  status = sigaction(SIG_SUSPEND,&act,NULL);
  rtems_test_assert( status == 0 );

  act.sa_handler=GC_restart_handler;

  status = sigaction(SIG_THR_RESTART,&act,NULL);
  rtems_test_assert( status == 0 );

  status = sigfillset(&suspend_handler_mask);
  rtems_test_assert( status == 0 );

  status = sigdelset(&suspend_handler_mask, SIG_THR_RESTART);
  rtems_test_assert( status == 0 );

  mainThread = pthread_self();
  status = pthread_create(&newThread,NULL,thread1,NULL);
  rtems_test_assert( status == 0 );

  GC_threads[0] = mainThread;
  GC_threads[1] = newThread;

  for(i=0; i<5; i++){
    printf("%d\n",i);
    status = sleep(1);
    printf("sleep returned %d/%s\n", status, strerror(errno) );
  }

  status = pthread_join( newThread, NULL );
  if(status) printf("MainThread pthread_join return %d\n", status);
  rtems_test_assert( status == 0 );

  printf( "Back from MainThread pthread_join times: %d\n", times );
  puts( "*** END OF TEST ***" );
  return 0;
}
Example #11
0
void test_gid(void)
{
  gid_t gid;
  int sc;

  gid = getegid();
  rtems_test_assert( gid == 0 );
  printf( "getegid = %d\n", gid );

  gid = getgid();
  rtems_test_assert( gid == 0 );
  printf( "getgid = %d\n", gid );

  puts( "setgid(5)" );
  sc = setgid(5);
  rtems_test_assert( sc == 0 );

  gid = getegid();
  rtems_test_assert( gid == 0 );
  printf( "getegid = %d\n", gid );

  gid = getgid();
  rtems_test_assert( gid == 5 );
  printf( "getgid = %d\n", gid );

  puts( "setegid(5)" );
  sc = setegid(5);
  rtems_test_assert( sc == 0 );

  gid = getegid();
  rtems_test_assert( gid == 5 );
  printf( "getegid = %d\n", gid );

  gid = getgid();
  rtems_test_assert( gid == 5 );
  printf( "getgid = %d\n", gid );

  puts( "setgid(0)" );
  sc = setgid(0);
  rtems_test_assert( sc == 0 );

  puts( "setegid(0)" );
  sc = setegid(0);
  rtems_test_assert( sc == 0 );

  errno = 0;
  puts( "setpgid(getpid(), 10) - ENOSYS" );
  sc = setpgid( getpid(), 10 );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == ENOSYS );
}
Example #12
0
static void validate_task(rtems_task_argument arg)
{
  _CPU_Context_validate(arg);
  rtems_test_assert(0);
}
Example #13
0
rtems_task Init(rtems_task_argument arg)
{
  rtems_status_code  status;
  int                sc;
  uintptr_t          max_free_size = 13 * RTEMS_MINIMUM_STACK_SIZE;
  void              *greedy;

  all_thread_created = 0;

  TEST_BEGIN();

  puts( "Init - Semaphore 1 create - OK" );
  name1 = rtems_build_name('S', 'E', 'M', '1');
  sc = rtems_semaphore_create(
    name1, 0,
    RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO,
    0,
    &sema1
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  puts( "Init - Semaphore 2 create - OK" );
  name2 = rtems_build_name('S', 'E', 'M', '2');
  sc = rtems_semaphore_create(
    name2,
    0,
    RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO,
    0,
    &sema2
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  puts( "Init - pthread Key create - OK" );
  sc = pthread_key_create( &Key, NULL );
  rtems_test_assert( !sc );

  /* Reduce workspace size if necessary to shorten test time */
  greedy = rtems_workspace_greedy_allocate( &max_free_size, 1 );

  for ( ; ; ) {
    rtems_id task_id;

    sc = rtems_task_create(
      rtems_build_name('T','A',created_task_count, ' '),
      1,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &task_id
    );
    rtems_test_assert(
      (sc == RTEMS_UNSATISFIED) ||
      (sc == RTEMS_TOO_MANY) ||
      (sc == RTEMS_SUCCESSFUL)
    );

    /**
     * when return is RTEMS_TOO_MANY or RTEMS_UNSATISFIED, there is not
     * enough source to create task.
     */
    if ( (sc == RTEMS_TOO_MANY) || (sc == RTEMS_UNSATISFIED) ) {
      break;
    }
    ++created_task_count;

    sc = rtems_task_start( task_id,  test_task, 0 );
    rtems_test_assert( sc == RTEMS_SUCCESSFUL );

    sc = rtems_semaphore_obtain( sema1, RTEMS_WAIT, 0 );
    rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  }

  rtems_workspace_greedy_free( greedy );

  printf(
    "Init - %d tasks have been created - OK\n"
    "Init - %d tasks have been setted key data - OK\n",
    setted_task_count,
    created_task_count
  );
  rtems_test_assert( created_task_count == setted_task_count );

  /* unblock all created tasks to let them set key data.*/
  puts( "Init - flush semaphore 2 - OK" );
  sc = rtems_semaphore_flush( sema2 );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  puts( "Init - sleep to yield processor - OK" );
  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
  directive_failed( status, "rtems_task_wake_after" );

  printf( "Init - %d Tasks have been got key data - OK\n", got_task_count );
  rtems_test_assert( created_task_count == got_task_count );
  puts( "Init - pthread Key delete - OK" );
  sc = pthread_key_delete( Key );
  rtems_test_assert( sc == 0 );

  puts( "Init - semaphore 1 delete - OK" );
  sc = rtems_semaphore_delete( sema1 );
  rtems_test_assert( !sc );

  puts( "Init - semaphore 2 delete - OK" );
  sc = rtems_semaphore_delete( sema2 );
  rtems_test_assert( !sc );

  TEST_END();
  exit(0);
}
Example #14
0
File: init.c Project: gedare/rtems
static void mmap_bad_arguments( void )
{
  int devfd, pagesize, shmfd, zerofd;
  void* p;

  rtems_test_assert((pagesize = getpagesize()) > 0);
  rtems_test_assert((devfd = open(&test_driver_name[0], O_RDONLY)) >= 0);
  rtems_test_assert((shmfd = shm_open("/shm", O_CREAT | O_RDWR, 0644)) >= 0);
  rtems_test_assert(ftruncate(shmfd, pagesize) == 0);
  rtems_test_assert((zerofd = open("/dev/zero", O_RDONLY)) >= 0);

  /*
   * These should normally work on FREEBSD. Test cases below that fail are
   * due to unsupported features in RTEMS.
   */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_ANON, -1, 0,
      "simple MAP_ANON");
  checked_mmap(PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0,
      "simple shm fd shared");
  checked_mmap(PROT_READ | PROT_WRITE, MAP_PRIVATE, shmfd, 0,
      "simple shm fd private");
  /* RTEMS cannot protect against writes so this will fail */
  checked_mmap(PROT_READ, MAP_SHARED, zerofd, ENOTSUP,
      "simple /dev/zero shared");
   /*
    * Repeat with no write protection. Will fail because of unimplemented
    * mmap handler in /dev/zero.
    */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_SHARED, zerofd, ENOTSUP,
      "simple /dev/zero shared");
  /* RTEMS /dev/zero is a character device so this will fail */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_PRIVATE, zerofd, EINVAL,
      "simple /dev/zero private");
  /* RTEMS cannot protect against writes so this will fail */
  checked_mmap(PROT_READ, MAP_SHARED, devfd, ENOTSUP,
      "simple test driver shared");
   /*
    * Repeat with no write protection. Should fail because of unimplemented
    * mmap handler in /dev/null.
    */
  p = checked_mmap(PROT_READ | PROT_WRITE, MAP_SHARED, devfd, 0,
      "simple test driver shared");
  rtems_test_assert(p == &test_data[0]);

  /* Extra PROT flags. */
  checked_mmap(PROT_READ | PROT_WRITE | 0x100000, MAP_ANON, -1, EINVAL,
      "MAP_ANON with extra PROT flags");
  checked_mmap(0xffff, MAP_SHARED, shmfd, EINVAL,
      "shm fd with garbage PROT");

  /* Undefined flag. */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_ANON | MAP_RESERVED0080, -1,
      EINVAL, "Undefined flag");

  /* Both MAP_SHARED and MAP_PRIVATE */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE |
      MAP_SHARED, -1, EINVAL, "MAP_ANON with both SHARED and PRIVATE");
  checked_mmap(PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_SHARED, shmfd,
      EINVAL, "shm fd with both SHARED and PRIVATE");

  /* At least one of MAP_SHARED or MAP_PRIVATE without ANON */
  checked_mmap(PROT_READ | PROT_WRITE, 0, shmfd, EINVAL,
      "shm fd without sharing flag");

  /* MAP_ANON with sharing flag. Will fail on RTEMS*/
  checked_mmap(PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, EINVAL,
      "shared MAP_ANON");
  /* MAP_ANON with private flag*/
  checked_mmap(PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0,
      "private MAP_ANON");

  /* MAP_ANON should require an fd of -1. */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, EINVAL,
      "MAP_ANON with fd != -1");

  /*
   * Writable MAP_SHARED should fail on read-only descriptors. Will fail
   * on RTEMS because of unimplemented mmap handler in /dev/null and the fact
   * that there is no read only protection.
   */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_SHARED, zerofd, ENOTSUP,
      "MAP_SHARED of read-only /dev/zero");

  /*
   * Character devices other than /dev/zero do not support private
   * mappings. RTEMS cannot protect against writes so this will fail with
   * ENOTSUP
   */
  checked_mmap(PROT_READ, MAP_PRIVATE, devfd, ENOTSUP,
      "MAP_PRIVATE of test driver");

   /*
    * Repeat with no write protection.
    */
  checked_mmap(PROT_READ | PROT_WRITE, MAP_PRIVATE, devfd, EINVAL,
      "MAP_PRIVATE of test driver");

  close(devfd);
  close(shmfd);
  close(zerofd);
}
Example #15
0
rtems_task Init(
  rtems_task_argument argument
)
{
  struct timespec tv;
  struct timespec tr;
  int             sc;
  time_t          seconds;
  time_t          seconds1;
  unsigned int    remaining;
  struct tm       tm;
  struct timespec delay_request;

  puts( "\n\n*** POSIX CLOCK TEST ***" );

  tm_build_time( &tm, TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );

  /* error cases in clock_gettime and clock_settime */

  puts( "Init: clock_gettime - EINVAL (NULL timespec)" );
  sc = clock_gettime( CLOCK_REALTIME, NULL );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  puts( "Init: clock_gettime - EINVAL (invalid clockid)" );
  sc = clock_gettime( (clockid_t)-1, &tv );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  puts( "Init: clock_settime - EINVAL (invalid clockid)" );
  sc = clock_settime( (clockid_t)-1, &tv );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  /* way back near the dawn of time :D */
  tv.tv_sec = 1;
  tv.tv_nsec = 0;
  printf( ctime( &tv.tv_sec ) );
  puts( "Init: clock_settime - before 1988 EINVAL" );
  sc = clock_settime( CLOCK_REALTIME, &tv );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  /* exercise clock_getres */

  puts( "Init: clock_getres - EINVAL (invalid clockid)" );
  sc = clock_getres( (clockid_t) -1, &tv );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  puts( "Init: clock_getres - EINVAL (NULL resolution)" );
  sc = clock_getres( CLOCK_REALTIME, NULL );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  puts( "Init: clock_getres - SUCCESSFUL" );
  sc = clock_getres( CLOCK_REALTIME, &tv );
  printf( "Init: resolution = sec (%" PRIdtime_t "), nsec (%ld)\n", tv.tv_sec, tv.tv_nsec );
  rtems_test_assert( !sc );

  /* set the time of day, and print our buffer in multiple ways */

  tv.tv_sec = mktime( &tm );
  rtems_test_assert( tv.tv_sec != -1 );

  tv.tv_nsec = 0;

  /* now set the time of day */

  empty_line();

  printf( asctime( &tm ) );
  puts( "Init: clock_settime - SUCCESSFUL" );
  sc = clock_settime( CLOCK_REALTIME, &tv );
  rtems_test_assert( !sc );

  printf( asctime( &tm ) );
  printf( ctime( &tv.tv_sec ) );

  /* use sleep to delay */

  remaining = sleep( 3 );
  rtems_test_assert( !remaining );

  /* print new times to make sure it has changed and we can get the realtime */
  sc = clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &tv );
  rtems_test_assert( !sc );
  printf("Time since boot: (%" PRIdtime_t ", %ld)\n", tv.tv_sec,tv.tv_nsec );

  sc = clock_gettime( CLOCK_REALTIME, &tv );
  rtems_test_assert( !sc );

  printf( ctime( &tv.tv_sec ) );

  seconds = time( NULL );
  printf( ctime( &seconds ) );

  /*  just to have the value copied out through the parameter */

  seconds = time( &seconds1 );
  rtems_test_assert( seconds == seconds1 );

  /* check the time remaining */

  printf( "Init: seconds remaining (%d)\n", (int)remaining );
  rtems_test_assert( !remaining );

  /* error cases in nanosleep */

  empty_line();
  puts( "Init: nanosleep - EINVAL (NULL time)" );
  sc = nanosleep ( NULL, &tr );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  tv.tv_sec = 0;
  tv.tv_nsec = TOD_NANOSECONDS_PER_SECOND * 2;
  puts( "Init: nanosleep - EINVAL (too many nanoseconds)" );
  sc = nanosleep ( &tv, &tr );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  /* this is an error */
  tv.tv_sec = -1;
  tv.tv_nsec = 0;
  puts( "Init: nanosleep - negative seconds - EINVAL" );
  sc = nanosleep ( &tv, &tr );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  /* this is also an error */
  tv.tv_sec = 0;
  tv.tv_nsec = -1;
  puts( "Init: nanosleep - negative nanoseconds - EINVAL" );
  sc = nanosleep ( &tv, &tr );
  rtems_test_assert( sc == -1 );
  rtems_test_assert( errno == EINVAL );

  /* this is actually a small delay */
  tv.tv_sec = 0;
  tv.tv_nsec = 1;
  puts( "Init: nanosleep - delay so small results in one tick" );
  sc = nanosleep ( &tv, &tr );
  rtems_test_assert( !sc );
  rtems_test_assert( !tr.tv_sec );
  rtems_test_assert( !tr.tv_nsec );

  /* use nanosleep to yield */

  tv.tv_sec = 0;
  tv.tv_nsec = 0;

  puts( "Init: nanosleep - yield with remaining" );
  sc = nanosleep ( &tv, &tr );
  rtems_test_assert( !sc );
  rtems_test_assert( !tr.tv_sec );
  rtems_test_assert( !tr.tv_nsec );

  puts( "Init: nanosleep - yield with NULL time remaining" );
  sc = nanosleep ( &tv, NULL );
  rtems_test_assert( !sc );
  rtems_test_assert( !tr.tv_sec );
  rtems_test_assert( !tr.tv_nsec );

  /* use nanosleep to delay */

  tv.tv_sec = 3;
  tv.tv_nsec = 500000;

  puts( "Init: nanosleep - 1.05 seconds" );
  sc = nanosleep ( &tv, &tr );
  rtems_test_assert( !sc );

  /* print the current real time again */
  sc = clock_gettime( CLOCK_REALTIME, &tv );
  rtems_test_assert( !sc );
  printf( ctime( &tv.tv_sec ) );

  /* check the time remaining */

  printf( "Init: sec (%" PRIdtime_t "), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec );
  rtems_test_assert( !tr.tv_sec && !tr.tv_nsec );

  puts( "Init: nanosleep - 1.35 seconds" );
  delay_request.tv_sec = 1;
  delay_request.tv_nsec = 35000000;
  sc = nanosleep( &delay_request, NULL );
  rtems_test_assert( !sc );

  /* print the current real time again */
  sc = clock_gettime( CLOCK_REALTIME, &tv );
  rtems_test_assert( !sc );
  printf( ctime( &tv.tv_sec ) );

  empty_line();
  puts( "clock_gettime - CLOCK_THREAD_CPUTIME_ID -- ENOSYS" );
  #if defined(_POSIX_THREAD_CPUTIME)
    {
      struct timespec tp;
      sc = clock_gettime( CLOCK_THREAD_CPUTIME_ID, &tp );
      check_enosys( sc );
    }
  #endif

  puts( "clock_settime - CLOCK_PROCESS_CPUTIME_ID -- ENOSYS" );
  #if defined(_POSIX_CPUTIME)
    {
      struct timespec tp;
      sc = clock_settime( CLOCK_PROCESS_CPUTIME_ID, &tp );
      check_enosys( sc );
    }
  #endif

  puts( "clock_settime - CLOCK_THREAD_CPUTIME_ID -- ENOSYS" );
  #if defined(_POSIX_THREAD_CPUTIME)
    {
      struct timespec tp;
      sc = clock_settime( CLOCK_THREAD_CPUTIME_ID, &tp );
      check_enosys( sc );
    }
  #endif

  puts( "*** END OF POSIX CLOCK TEST ***" );
  rtems_test_exit(0);
}
Example #16
0
static void suspend(size_t i)
{
  rtems_status_code sc = rtems_task_suspend(task_ids[i]);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Example #17
0
static void test_chain_control_initializer(void)
{
  rtems_chain_control chain = RTEMS_CHAIN_INITIALIZER_EMPTY( chain );
  puts( "INIT - Verify rtems_chain_control initializer" );
  rtems_test_assert( rtems_chain_is_empty( &chain ) );
}
Example #18
0
static void resume(size_t i)
{
  rtems_status_code sc = rtems_task_resume(task_ids[i]);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Example #19
0
static void test(void)
{
  test_context *ctx = &ctx_instance;
  rtems_status_code sc;
  rtems_task_argument runner_index;
  rtems_id stopper_id;
  uint32_t expected_tokens;
  uint32_t total_delta;

  sc = rtems_task_create(
    rtems_build_name('S', 'T', 'O', 'P'),
    PRIO_STOP,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &stopper_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  for (runner_index = 0; runner_index < RUNNER_COUNT; ++runner_index) {
    sc = rtems_task_create(
      rtems_build_name('R', 'U', 'N', (char) ('0' + runner_index)),
      PRIO_HIGH + runner_index,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &ctx->runner_ids[runner_index]
    );
    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
  }

  for (runner_index = 0; runner_index < RUNNER_COUNT; ++runner_index) {
    sc = rtems_task_start(ctx->runner_ids[runner_index], runner, runner_index);
    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
  }

  sc = rtems_task_wake_after(10 * rtems_clock_get_ticks_per_second());
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_start(stopper_id, stopper, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  for (runner_index = 0; runner_index < RUNNER_COUNT; ++runner_index) {
    test_counters *counters = &ctx->counters[runner_index];
    size_t cpu;

    printf("runner %" PRIuPTR "\n", runner_index);

    for (cpu = 0; cpu < CPU_COUNT; ++cpu) {
      printf(
        "\tcpu %zu tokens %" PRIu32 "\n"
        "\tcpu %zu cycles %" PRIu32 "\n",
        cpu,
        counters->tokens_per_cpu[cpu].counter,
        cpu,
        counters->cycles_per_cpu[cpu].counter
      );
    }
  }

  expected_tokens = ctx->counters[0].tokens_per_cpu[0].counter;
  total_delta = 0;
  for (runner_index = 0; runner_index < RUNNER_COUNT; ++runner_index) {
    test_counters *counters = &ctx->counters[runner_index];
    size_t cpu;

    for (cpu = 0; cpu < CPU_COUNT; ++cpu) {
      uint32_t tokens = counters->tokens_per_cpu[cpu].counter;
      uint32_t delta = tokens > expected_tokens ?
        tokens - expected_tokens : expected_tokens - tokens;

      rtems_test_assert(delta <= 1);

      total_delta += delta;
    }
  }

  rtems_test_assert(total_delta <= (RUNNER_COUNT * CPU_COUNT - 1));
}
Example #20
0
void *POSIX_Init(
  void *argument
)
{
  unsigned int      remaining;
  int               status;
  struct sigaction  act;
  sigset_t          mask;
  sigset_t          pending_set;
  sigset_t          oset;
  struct timespec   timeout;
  siginfo_t         info;

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

  /* set the time of day, and print our buffer in multiple ways */

  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );

  /* get id of this thread */

  Init_id = pthread_self();
  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );

  /* generate some easy error cases */

  status = sigwait( NULL, NULL );
  if ( status != EINVAL )
    printf( "status = %d (%s)\n", status, strerror(status) );
  rtems_test_assert( status == EINVAL );
  puts( "Init: sigwait - EINVAL (NULL set)" );

  status = sigtimedwait( NULL, NULL, NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigwait - EINVAL (NULL set)" );

/* install a signal handler for SIGUSR1 */

  status = sigemptyset( &act.sa_mask );
  rtems_test_assert( !status );
  printf( "Init: sigemptyset -  set= 0x%08x\n", (unsigned int) act.sa_mask );

  /* test sigfillset following the above sigemptyset */

  status = sigfillset( &act.sa_mask );
  rtems_test_assert( !status );
  printf( "Init: sigfillset -  set= 0x%08x\n", (unsigned int) act.sa_mask );

  /* test sigdelset */

  status = sigdelset( &act.sa_mask, SIGUSR1 );
  rtems_test_assert( !status );
  printf( "Init: sigdelset - delete SIGUSR1 set= 0x%08x\n",
      (unsigned int) act.sa_mask );

  /* test sigismember - FALSE */

  status = sigismember( &act.sa_mask, SIGUSR1 );
  rtems_test_assert( !status );
  puts( "Init: sigismember - FALSE since SIGUSR1 is not a member" );

  /* test sigismember - TRUE */

  status = sigismember( &act.sa_mask, SIGUSR2 );
  rtems_test_assert( status );
  puts( "Init: sigismember - TRUE since SIGUSR2 is a member" );

  /* return the set to empty */

  act.sa_handler = Signal_handler;
  act.sa_flags   = 0;

  sigaction( SIGUSR1, &act, NULL );

  /* simple signal to process */

  Signal_count = 0;
  Signal_occurred = 0;

  puts( "Init: send SIGUSR1 to process" );
  status = kill( getpid(), SIGUSR1 );
  rtems_test_assert( !status );

/* end of install a signal handler for SIGUSR1 */

  Signal_occurred = 0;

  /* now block the signal, send it, see if it is pending, and unblock it */

  empty_line();

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR1 );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR1" );
  act.sa_handler = Signal_handler;
  act.sa_flags   = 0;

  sigaction( SIGUSR1, &act, NULL );

  /* simple signal to process */

  Signal_count = 0;
  Signal_occurred = 0;

  puts( "Init: send SIGUSR1 to process" );
  status = kill( getpid(), SIGUSR1 );
  rtems_test_assert( !status );

  Signal_occurred = 0;

  /* now block the signal, send it, see if it is pending, and unblock it */

  empty_line();

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR1 );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR1" );
  status = sigprocmask( SIG_BLOCK, &mask, NULL );
  rtems_test_assert( !status );

  status = sigpending( &pending_set );
  rtems_test_assert( !status );
  printf( "Init: Signals pending 0x%08x\n", (unsigned int) pending_set );

  puts( "Init: send SIGUSR1 to process" );
  status = kill( getpid(), SIGUSR1 );
  rtems_test_assert( !status );

  status = sigpending( &pending_set );
  rtems_test_assert( !status );
  printf( "Init: Signals pending 0x%08x\n", (unsigned int) pending_set );

  puts( "Init: Unblock SIGUSR1" );
  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
  rtems_test_assert( !status );

  /* now let another task get interrupted by a signal */

  empty_line();

  puts( "Init: create a thread interested in SIGUSR1" );
  status = pthread_create( &Task1_id, NULL, Task_1, NULL );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR1" );
  status = sigprocmask( SIG_BLOCK, &mask, NULL );
  rtems_test_assert( !status );

  status = sigpending( &pending_set );
  rtems_test_assert( !status );
  printf( "Init: Signals pending 0x%08x\n", (unsigned int) pending_set );

  puts( "Init: sleep so the other task can block" );
  remaining = sleep( 1 );
  rtems_test_assert( !status );

     /* switch to task 1 */

  puts( "Init: send SIGUSR1 to process" );
  status = kill( getpid(), SIGUSR1 );
  rtems_test_assert( !status );

  status = sigpending( &pending_set );
  rtems_test_assert( !status );
  printf( "Init: Signals pending 0x%08x\n", (unsigned int) pending_set );

  puts( "Init: sleep so the other task can catch signal" );
  remaining = sleep( 1 );
  rtems_test_assert( !status );

     /* switch to task 1 */

  /* test alarm */

  empty_line();

  /* install a signal handler for SIGALRM and unblock it */

  status = sigemptyset( &act.sa_mask );
  rtems_test_assert( !status );

  act.sa_handler = Signal_handler;
  act.sa_flags   = 0;

  sigaction( SIGALRM, &act, NULL );

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGALRM );
  rtems_test_assert( !status );

  puts( "Init: Unblock SIGALRM" );
  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
  rtems_test_assert( !status );

  /* schedule the alarm */

  puts( "Init: Firing alarm in 5 seconds" );
  remaining = alarm( 5 );
  printf( "Init: %d seconds left on previous alarm\n", status );
  rtems_test_assert( !status );

  puts( "Init: Firing alarm in 2 seconds" );
  remaining = alarm( 2 );
  printf( "Init: %d seconds left on previous alarm\n", remaining );
  rtems_test_assert( remaining == 5 );

  puts( "Init: Wait 4 seconds for alarm" );
  remaining = sleep( 4 );
  printf( "Init: %d seconds left in sleep\n", remaining );
  rtems_test_assert( remaining == 2 );

  /* test SIG_SETMASK case and returning oset of pthread_sigmask */

  empty_line();

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR1 );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR2 );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR1 and SIGUSR2 only" );
  status = pthread_sigmask( SIG_SETMASK, &mask, &oset );
  printf( "Init: Previous blocked set was 0x%08x\n", (unsigned int) oset );
  rtems_test_assert( !status );

  /* test inquiry about current blocked set with pthread_sigmask */

  status = pthread_sigmask( 0, NULL, &oset );
  printf( "Init: Current blocked set is 0x%08x\n", (unsigned int) oset );
  rtems_test_assert( !status );

  /* return blocked mask to no signals blocked */

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  puts( "Init: Unblock all signals" );
  status = pthread_sigmask( SIG_SETMASK, &mask, &oset );
  printf( "Init: Previous blocked set was 0x%08x\n", (unsigned int) oset );
  rtems_test_assert( !status );

  /* test sigsuspend */

  empty_line();

  puts( "Init: create a thread to send Init SIGUSR1" );
  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
  rtems_test_assert( !status );

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  puts( "Init: sigsuspend for any signal" );
  status = sigsuspend( &mask );
  rtems_test_assert( status );
  printf( "Init: awakended from sigsuspend status=%08d \n", status );

  /* test a SIGINFO case, these are signals sent to a process only */

  empty_line();

  puts( "Init: create a thread to sent Process SIGUSR1 with SA_SIGINFO" );
  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
  rtems_test_assert( !status );

  /* set action on SIGUSR1 to an info case */
  act.sa_handler   = Signal_handler;
  act.sa_flags     = SA_SIGINFO;
  act.sa_sigaction = Signal_info_handler;

  sigaction( SIGUSR1, &act, NULL );

  puts( "Init: sleep so the Task_3 can sigqueue SIGUSR1" );
  remaining = sleep( 1 );
  rtems_test_assert( !status );

     /* switch to task 1 */

  puts( "Init: sigqueue occurred" );

  /* Send SIGUSR1, Task_3 has issued a sigwaitinfo */

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR1 );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR1" );
  status = sigprocmask( SIG_BLOCK, &mask, NULL );
  rtems_test_assert( !status );

  puts( "Init: send SIGUSR1 to process" );
  status = kill( getpid(), SIGUSR1 );
  rtems_test_assert( !status );

  puts( "Init: sleep so the Task_3 can receive SIGUSR1" );
  remaining = sleep( 1 );
  rtems_test_assert( !status );

  /* Send SIGUSR1, Task_3 has issued a sigwait */

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR1 );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR1" );
  status = sigprocmask( SIG_BLOCK, &mask, NULL );
  rtems_test_assert( !status );

  puts( "Init: send SIGUSR1 to process" );
  status = kill( getpid(), SIGUSR1 );
  rtems_test_assert( !status );

  puts( "Init: sleep so the Task_3 can receive SIGUSR1" );
  remaining = sleep( 1 );
  rtems_test_assert( !status );

  /* Send SIGUSR1, Task_3 has issued a sigwaitinfo */

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  status = sigaddset( &mask, SIGUSR2 );
  rtems_test_assert( !status );

  puts( "Init: Block SIGUSR2" );
  status = sigprocmask( SIG_BLOCK, &mask, NULL );
  rtems_test_assert( !status );

  puts( "Init: send SIGUSR2 to process" );
  status = kill( getpid(), SIGUSR2 );
  rtems_test_assert( !status );

  puts( "Init: sleep so the Task_3 can receive SIGUSR2" );
  remaining = sleep( 1 );
  rtems_test_assert( !status );

  /* Suspend for signal that has already be sent */

  status = sigemptyset( &mask );
  rtems_test_assert( !status );

  puts( "Init: sigsuspend for any signal" );
  status = sigsuspend( &mask );
  rtems_test_assert( status );
  printf( "Init: awakended from sigsuspend status=%d \n", status );

  /* generate error cases for psignal */

  empty_line();

  status = sigemptyset( NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigemptyset - EINVAL (set invalid)" );

  status = sigfillset( NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigfillset - EINVAL (set invalid)" );

  status = sigaddset( NULL, SIGUSR1 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigaddset - EINVAL (set invalid)" );

  status = sigaddset( &mask, 0 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigaddset - EINVAL (signal = 0)" );

  status = sigaddset( &mask, 999 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigaddset - EINVAL (set invalid)" );

  status = sigdelset( NULL, SIGUSR1 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigdelset - EINVAL (set invalid)" );

  status = sigdelset( &mask, 0 );
  rtems_test_assert( !status );
  puts( "Init: sigdelset - SUCCESSFUL (signal = 0)" );

  status = sigdelset( &mask, 999 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigdelset - EINVAL (set invalid)" );

  status = sigismember( NULL, SIGUSR1 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigismember - EINVAL (set invalid)" );

  status = sigismember( &mask, 0 );
  rtems_test_assert( !status );
  puts( "Init: sigismember - SUCCESSFUL (signal = 0)" );

  status = sigismember( &mask, 999 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigismember - EINVAL (signal invalid)" );

  status = sigaction( 0, &act, 0 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigaction - EINVAL (signal = 0)" );

  status = sigaction( 999, &act, NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigaction - EINVAL (signal invalid)" );

  status = sigaction( SIGKILL, &act, NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigaction - EINVAL (SIGKILL)" );

  status = pthread_sigmask( SIG_BLOCK, NULL, NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: pthread_sigmask - EINVAL (set and oset invalid)" );

  status = pthread_sigmask( 999, &pending_set, NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: pthread_sigmask - EINVAL (how invalid)" );

  status = sigpending( NULL );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: sigpending - EINVAL (set invalid)" );

  timeout.tv_nsec = -1;
  status = sigtimedwait( &mask, &info, &timeout );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: pthread_sigmask - EINVAL (timout->nsec invalid < 0)" );

  timeout.tv_nsec = 0x7fffffff;
  status = sigtimedwait( &mask, &info, &timeout );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: pthread_sigmask - EINVAL (timout->nsec invalid to large)" );

  status = pthread_kill( Init_id, 999 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: pthread_kill - EINVAL (sig invalid)" );

  status = pthread_kill( Init_id, 0 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: pthread_kill - EINVAL (signal = 0)" );

  act.sa_handler = SIG_IGN;
  act.sa_flags = 0;
  sigaction( SIGUSR2, &act, NULL );
  status = pthread_kill( Init_id, SIGUSR2 );
  rtems_test_assert( !status );
  puts( "Init: pthread_kill - SUCCESSFUL (signal = SIG_IGN)" );

  status = kill( INT_MAX, SIGUSR1 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == ESRCH );
  puts( "Init: kill - ESRCH (pid invalid)" );

  status = kill( getpid(), 0 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: kill - EINVAL (signal = 0)" );

  status = kill( getpid(), 999 );
  if ( status != -1 )
    printf( "status = %d\n", status );
  rtems_test_assert( errno == EINVAL );
  puts( "Init: kill - EINVAL (sig invalid)" );

  /* exit this thread */

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

  return NULL; /* just so the compiler thinks we returned something */
}
Example #21
0
File: init.c Project: medivhc/rtems
static void test_blkdev_imfs_parameters(void)
{
  rtems_status_code sc;
  int rv;
  ramdisk *rd;
  int fd;
  const rtems_disk_device *dd;
  struct stat st;

  rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);
  rtems_test_assert(rd != NULL);

  ramdisk_enable_free_at_delete_request(rd);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  ASSERT_SC(sc);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    1,
    BLOCK_COUNT - 1
  );
  ASSERT_SC(sc);

  fd = open(rda, O_RDWR);
  rtems_test_assert(fd >= 0);

  rv = fstat(fd, &st);
  rtems_test_assert(rv == 0);

  rv = rtems_disk_fd_get_disk_device(fd, &dd);
  rtems_test_assert(rv == 0);

  rtems_test_assert(rtems_disk_get_driver_data(dd) == rd);
  rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev);
  rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_begin(dd) == 0);
  rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT);

  rv = close(fd);
  rtems_test_assert(rv == 0);

  fd = open(rda1, O_RDWR);
  rtems_test_assert(fd >= 0);

  rv = fstat(fd, &st);
  rtems_test_assert(rv == 0);

  rv = rtems_disk_fd_get_disk_device(fd, &dd);
  rtems_test_assert(rv == 0);

  rtems_test_assert(rtems_disk_get_driver_data(dd) == rd);
  rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev);
  rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_begin(dd) == 1);
  rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT - 1);

  rv = close(fd);
  rtems_test_assert(rv == 0);

  rv = unlink(rda1);
  rtems_test_assert(rv == 0);

  rv = unlink(rda);
  rtems_test_assert(rv == 0);
}
int main(
  int argc,
  char **argv
)
#endif
{
  int i;
  int fd;
  int status;
  struct stat statbuf;
  static char mount_point_string[25] = { "/c/z/my_mount_point" };


  printf( "\n\n*** MOUNT/UNMOUNT TEST ***\n" );

  /*
   * Change directory to the root and create files under
   * the base file system.
   */

  printf( "\nchdir to the root directory\n" );
  status = chdir( "/" );
  printf( "chdir() status : %d\n\n", status );

  printf( "\nCreating a series of directories under /\n" );
  i=0;
  while ( strcmp(dnames[i], "END") != 0 )
  {
     status = mkdir( dnames[i], 0777 );
     printf("Creating : %25s  %d %d   ", dnames[i], status, errno );
     if ( status == 0 )
        printf(" Success\n");
     else
        printf(" Failure\n");

     i++;
  }

  /*
   * Create a Files with all rwx for others group and user.  Verify
   * the created file.
   */

  printf("create /b/my_file\n");
  fd = open ("/b/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
  rtems_test_assert(  fd != 0 );
  close (fd);

  printf("Verify /b/my_file\n");
  fd = open("/b/my_file", S_IRWXU|S_IRWXG|S_IRWXO);
  rtems_test_assert(  fd != 0 );
  close( fd );


  printf("create c/y/my_mount_point/my_dir/d\n");
  fd = open ("c/y/my_mount_point/my_dir/d", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
  rtems_test_assert(  fd != 0 );
  close (fd);

  printf("Verify c/y/my_mount_point/my_dir/d\n");
  fd = open("c/y/my_mount_point/my_dir/d", S_IRWXU|S_IRWXG|S_IRWXO);
  rtems_test_assert(  fd != 0 );
  close( fd );

  /*
   *  Mount an the IMFS file system on the base file system.
   */

  printf("Attempting to mount IMFS file system at /c/z/my_mount_point \n");
  status = mount(
    "null",
    mount_point_string,
    "imfs",
    RTEMS_FILESYSTEM_READ_WRITE,
    NULL );
  rtems_test_assert(  status == 0 );
  printf("2nd file system successfully mounted at /c/z/my_mount_point \n");

  /*
   * Change directory to the mount point and create a group of files under
   * the mounted file system.
   */

  printf( "\nchdir to /c/z/my_mount_point.\n" );
  status = chdir( "/c/z/my_mount_point" );
  printf( "chdir() status : %d\n\n", status );

  printf( "\nCreating a series of directories under /c/z/my_mount_point\n" );
  i=0;
  while ( strcmp(fnames[i], "END") != 0 )
  {
     status = mkdir( fnames[i], 0777 );
     printf("Creating: %46s   %d %d   ", fnames[i], status, errno );
     if ( status == 0 )
        printf(" Success\n");
     else {
        printf(" Failure\n");
        perror("errno");
     }

     status = stat( fnames[i], &statbuf );
     if ( status == -1 )
       printf( ": %s\n", strerror( errno ) );

     i++;
  }

  printf( "\nchdir to /\n" );
  status = chdir( "/" );
  printf( "chdir() status : %d\n\n", status );

  /*
   * Unmount the first file system we mounted
   */

  printf( "Unmount status:");
  status = unmount( "/c/z/my_mount_point" );
  printf( " %d\n", status );


  /*
   * Mount a NULL filesystem and verify it fails.
   */

  printf("Mount a NULL file system and verify EINVAL\n");
  status = mount(
    "null",
    mount_point_string,
    "nofound",
    RTEMS_FILESYSTEM_READ_WRITE,
    NULL );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EINVAL );

  /*
   * Verify mount with option of -62 fails with EINVAL
   */

  printf("mount with option of -62 should fail with EINVAL\n");
  status = mount(
    "null",
    "/c/y/my_mount_point",
    "imfs",
    -62,
    NULL );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EINVAL );

  /*
   * Mount a Read Only File system.
   */

  printf("Mount a Read Only filesystem at /c/y/my_mount_point \n");
  status = mount(
    "null",
    "/c/y/my_mount_point",
    "imfs",
    RTEMS_FILESYSTEM_READ_ONLY,
    NULL );
  rtems_test_assert(  status == 0 );
  printf("Read only file system successfully mounted at /c/y/my_mount_point \n");

  /*
   * Create a directory that passes through the read only file system.
   */

  printf("create c/y/my_mount_point/../../y/my_mount_point/new_dir\n");
  status = mkdir("c/y/my_mount_point/../../y/my_mount_point/new_dir",S_IRWXU );
  rtems_test_assert(  status == 0 );
  status = stat("c/y/my_mount_point/../../y/my_mount_point/new_dir",&statbuf );
  rtems_test_assert(  status == 0 );
  status = stat("c/y/my_mount_point/new_dir/..", &statbuf );
  rtems_test_assert(  status == 0 );

  /*
   * Attempt to mount a second file system at a used mount point.
   */

  printf("Verify a mount point returns EBUSY for another mount\n");
  status = mount(
    "null",
    "/c/y/my_mount_point",
    "imfs",
     RTEMS_FILESYSTEM_READ_ONLY,
     NULL );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EBUSY);

  /*
   * Attempt to mount at a file.
   */

  printf("Mount on a file should fail with ENOTDIR\n");
  status = mount(
    "null",
    "/b/my_file",
    "imfs",
    RTEMS_FILESYSTEM_READ_ONLY,
    NULL );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == ENOTDIR );


  /*
   * Verify we cannot unmount a file system while we are in it.
   */

  printf("Create and chdir to /c/y/my_mount_point/mydir\n");
  status = mkdir( "/c/y/my_mount_point/mydir", 0777);
  rtems_test_assert(  status == 0 );

  status = chdir( "/c/y/my_mount_point/mydir" );
  rtems_test_assert(  status == 0 );

  printf("unmount of /c/y/my_mount_point should fail with EBUSY\n");
  status = unmount( "/c/y/my_mount_point" );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EBUSY );

  /*
   * Chdir to root and verify we can unmount the file system now.
   */

  printf("chdir to / and verify we can unmount /c/y/my_mount_point\n");
  status = chdir( "/" );
  rtems_test_assert(  status == 0 );

  printf("unmount /c/y/my_mount_point \n");
  status = unmount( "/c/y/my_mount_point" );
  rtems_test_assert(  status == 0 );

  /*
   * Attempt to unmount a directory that does not exist.
   */

  printf("unmount /b/mount_point should fail with EINVAL\n");
  status = unmount( "/b/mount_point" );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == ENOENT );

  /*
   * Remount the filesystem.
   */

  printf("Mount /c/y/my_mount_point\n");
  status = mount(
    "null",
    "/c/y/my_mount_point",
    "imfs",
    RTEMS_FILESYSTEM_READ_ONLY,
    NULL );
  rtems_test_assert(  status == 0 );

  /*
   * Create a file and directory then open the directory.
   * Verify unmount will return EBUSY while directory is open.
   */

  printf("Create and open /c/y/my_mount_point/my_file\n");
  fd = open( "/c/y/my_mount_point/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
  rtems_test_assert(  fd != -1 );
  status = close( fd );
  rtems_test_assert(  status == 0 );

  printf("\nmkdir /c/y/my_mount_point/my_dir\n");
  status = mkdir( "/c/y/my_mount_point/my_dir", 0x1c0 );
  printf("Open /c/y/my_mount_point/my_dir\n");
  directory = opendir( "/c/y/my_mount_point/my_dir" );
  rtems_test_assert(  directory );

  printf("Unmount /c/y/my_mount_point should fail with EBUSY\n");
  status = unmount( "/c/y/my_mount_point" );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EBUSY );

  printf("Close /c/y/my_mount_point/my_dir\n");
  status = closedir( directory );
  rtems_test_assert(  status == 0 );

  /*
   * Attempt to unmount a directory that is not a mount point.
   */

  printf("Unmount /c/y/my_mount_point/my_dir should fail with EACCES\n");
  status = unmount( "/c/y/my_mount_point/my_dir" );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EACCES );

  /*
   * Verify a file system can not be unmounted with a mounted file system
   * in it.
   */

  printf("Mount a file system at /c/y/my_mount_point/my_dir\n");
  status = mount(
     "null",
     "/c/y/my_mount_point/my_dir",
     "imfs",
     RTEMS_FILESYSTEM_READ_WRITE,
     NULL );
  rtems_test_assert(  status == 0 );

  printf("unmount /c/y/my_mount_point should fail with EBUSY\n");
  status = unmount( "/c/y/my_mount_point" );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EBUSY );

  /*
   * Verify you cannot create a hard link across mounted file systems.
   */

  printf("Verify a hard link across filesystems fails with EXDEV\n");
  status = mkdir( "/c/y/my_mount_point/my_dir2", S_IRWXU  );
  rtems_test_assert(  status == 0 );

  status = link( "/c/y/my_mount_point/my_dir2", "/c/y/my_mount_point/my_dir/my_link" );
  rtems_test_assert(  status == -1 );
  rtems_test_assert(  errno == EXDEV );

  /*
   * Create a symbolic link across mountpoints.
   */

  printf("Verify a symbolic link across file systems works\n");
  status = symlink( "/c/y/my_mount_point/my_dir2", "/c/y/my_mount_point/my_dir/my_link" );
  rtems_test_assert(  status == 0 );
  status = stat( "/c/y/my_mount_point/my_dir/my_link", &statbuf );
  rtems_test_assert(  status == 0 );

  printf("unmount /c/y/my_mount_point/my_dir\n");
  status = unmount( "/c/y/my_mount_point/my_dir" );
  rtems_test_assert(  status == 0 );

  /*
   * Verify symblic link no longer works.
   */

  printf("Verify the symbolic link now fails\n");
  status = stat( "/c/y/my_mount_point/my_dir/my_link", &statbuf );
  rtems_test_assert(  status != 0 );

  printf("unmount /c/y/my_mount_point\n");
  status = unmount( "/c/y/my_mount_point" );
  rtems_test_assert(  status == 0 );

  printf( "\n\n*** END OF MOUNT/UNMOUNT TEST ***\n" );
  rtems_test_exit(0);
}
Example #23
0
File: init.c Project: Fyleo/rtems
void Validate_affinity(void )
{
  pthread_attr_t       attr;
  cpu_set_t            cpuset0;
  cpu_set_t            cpuset1;
  cpu_set_t            cpuset2;
  uint32_t             i;
  int                  sc;
  int                  cpu_count;
  struct sched_param   param;


  puts( "Init - Set Init priority to high");
  sc = pthread_getattr_np( Init_id, &attr );
  rtems_test_assert( sc == 0 );
  sc = pthread_attr_getschedparam( &attr, &param );
  rtems_test_assert( sc == 0 );
  param.sched_priority = sched_get_priority_max( SCHED_FIFO );
  sc = pthread_setschedparam( Init_id, SCHED_FIFO, &param );
  rtems_test_assert( !sc );

  sc = pthread_getaffinity_np( Init_id, sizeof(cpu_set_t), &cpuset0 );
  rtems_test_assert( !sc );

  /* Get the number of processors that we are using. */
  cpu_count = rtems_get_processor_count();

  /* Fill the remaining cpus with med priority tasks */
  puts( "Init - Create Medium priority tasks");
  for (i=0; i<(cpu_count-1); i++){
    sc = pthread_create( &Med_id[i], &attr, Thread_1, NULL );
    rtems_test_assert( !sc );
  }

  puts( "Init - Verify Medium priority tasks");
  for (i=0; i<(cpu_count-1); i++){
    sc = pthread_getaffinity_np( Med_id[i], sizeof(cpu_set_t), &cpuset2 );
    rtems_test_assert( !sc );
    rtems_test_assert( CPU_EQUAL(&cpuset0, &cpuset2) );
  }

  /*
   * Create low priority thread for each remaining cpu with the affinity
   * set to only run on one cpu.
   */
  puts( "Init - Create  Low priority tasks");
  for (i=0; i<cpu_count; i++){
    CPU_ZERO(&cpuset1);
    CPU_SET(i, &cpuset1);

    sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t), &cpuset1 );
    rtems_test_assert( !sc );

    sc = pthread_create( &Low_id[i], &attr, Thread_1, NULL );
    rtems_test_assert( !sc );
  }

  /* Verify affinity on low priority tasks */
  puts( "Init - Verify Low priority tasks");
  for (i=0; i<(cpu_count-1); i++){
    CPU_ZERO(&cpuset1);
    CPU_SET(i, &cpuset1);

    sc = pthread_getaffinity_np( Low_id[i], sizeof(cpu_set_t), &cpuset2 );
    rtems_test_assert( !sc );
    rtems_test_assert( CPU_EQUAL(&cpuset1, &cpuset2) );
  }

  /* Change the affinity for each low priority task */
  puts("Init - Change affinity on Low priority tasks");
  CPU_COPY(&cpuset1, &cpuset0);
  for (i=0; i<cpu_count; i++){

    CPU_CLR(i, &cpuset1);
    sc = pthread_setaffinity_np( Low_id[i], sizeof(cpu_set_t), &cpuset1 );

    /* Verify no cpu's are now set in the cpuset */
    if (i== (cpu_count-1)) {
      rtems_test_assert( sc == EINVAL );
      sc = pthread_setaffinity_np( Low_id[i], sizeof(cpu_set_t), &cpuset0 );
    }
    rtems_test_assert( !sc );
  }

  puts("Init - Validate affinity on Low priority tasks");
  CPU_COPY(&cpuset1, &cpuset0);
  for (i=0; i<cpu_count; i++){
    CPU_CLR(i, &cpuset1);

    sc = pthread_getaffinity_np( Low_id[i], sizeof(cpu_set_t), &cpuset2 );
    rtems_test_assert( !sc );
    if (i== (cpu_count-1))
      rtems_test_assert( CPU_EQUAL(&cpuset0, &cpuset2) );
    else
      rtems_test_assert( CPU_EQUAL(&cpuset1, &cpuset2) );
  }
}
Example #24
0
rtems_task Init(
  rtems_task_argument argument
)
{
  int status;
  int fdr = 0, fdw = 0;
  char buf[10];

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

  puts( "Init - attempt to open the /dev/test WR mode -- OK" );
  fdw = open( "/dev/test", O_WRONLY );
  rtems_test_assert( fdw != -1 );
  
  puts( "Init - attempt to write to /dev/test -- OK" );
  status = write( fdw, "data", 5 );
  rtems_test_assert( status == 5 );

  puts( "Init - attempt to write to /dev/test - expect ENOSYS" );
  status = write( fdw, "data", 10 );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOSYS );

  puts( "Init - attempt to open the /dev/test RD mode -- OK" );
  fdr = open( "/dev/test", O_RDONLY );
  rtems_test_assert( fdr != -1 );

  puts( "Init - attempt to read from /dev/test -- OK" );
  status = read( fdr, buf, 5 );
  rtems_test_assert( status == 0 );

  puts( "Init - attempt to read from /dev/test - expect ENOSYS" );
  status = read( fdr, buf, 10 );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOSYS );

  puts( "Init - attempt ioctl on the device - expect ENOSYS" );
  status = ioctl( fdr, -1 );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOSYS );

  puts( "Init - mknod(/dev/null)-- OK" );
  status = mknod( "/dev/null", 0777 | S_IFCHR, 0LL );
  rtems_test_assert( status == 0 );

  puts( "*** END OF TEST DEVFS04 ***" );
  rtems_test_exit(0);
}
Example #25
0
void *POSIX_Init(
  void *argument
)
{
  int              status;
  struct itimerval itimer;
  struct itimerval otimer;

  puts( "\n\n*** POSIX TEST ITIMER ***" );

  /* test getitimer stub */
  puts( "getitimer -- bad which - EINVAL " );
  status = getitimer( 1234, &itimer );
  rtems_test_assert(  status == -1 && errno == EINVAL );

  puts( "getitimer -- NULL pointer - EFAULT " );
  status = getitimer( ITIMER_REAL, NULL );
  rtems_test_assert(  status == -1 && errno == EFAULT );

  puts( "getitimer -- ITIMER_REAL - ENOSYS " );
  status = getitimer( ITIMER_REAL, &itimer );
  rtems_test_assert(  status == -1 && errno == ENOSYS );

  puts( "getitimer -- ITIMER_VIRTUAL - ENOSYS " );
  status = getitimer( ITIMER_VIRTUAL, &itimer );
  rtems_test_assert(  status == -1 && errno == ENOSYS );

  puts( "getitimer -- ITIMER_PROF - ENOSYS " );
  status = getitimer( ITIMER_PROF, &itimer );
  rtems_test_assert(  status == -1 && errno == ENOSYS );

  /* test setitimer stub */
  puts( "setitimer -- bad which - EINVAL " );
  status = setitimer( 1234, &itimer, &otimer );
  rtems_test_assert(  status == -1 && errno == EINVAL );

  puts( "setitimer -- NULL value pointer - EFAULT " );
  status = setitimer( ITIMER_REAL, NULL, &otimer );
  rtems_test_assert(  status == -1 && errno == EFAULT );

  puts( "setitimer -- NULL value pointer - EFAULT " );
  status = setitimer( ITIMER_REAL, &itimer, NULL );
  rtems_test_assert(  status == -1 && errno == EFAULT );

  puts( "setitimer -- ITIMER_REAL - ENOSYS " );
  status = setitimer( ITIMER_REAL, &itimer, &otimer );
  rtems_test_assert(  status == -1 && errno == ENOSYS );

  puts( "setitimer -- ITIMER_VIRTUAL - ENOSYS " );
  status = setitimer( ITIMER_VIRTUAL, &itimer, &otimer );
  rtems_test_assert(  status == -1 && errno == ENOSYS );

  puts( "setitimer -- ITIMER_PROF - ENOSYS " );
  status = setitimer( ITIMER_PROF, &itimer, &otimer );
  rtems_test_assert(  status == -1 && errno == ENOSYS );

  puts( "*** END OF POSIX TEST ITIMER ***" );
  rtems_test_exit(0);
}
Example #26
0
static void test_cache_message( void *arg )
{
  rtems_test_assert(arg == &ctx);

  ctx.count[rtems_get_current_processor()]++;
}
Example #27
0
static void forbidden_task(rtems_task_argument arg)
{
  (void) arg;

  rtems_test_assert(0);
}
int main(
  int argc,
  char **argv
)
#endif
{
  int fd;
  int i;
  int status;
  off_t off;
  struct dirent *d_not;
  struct dirent **namelist;
  struct stat s;


  printf( "\n\n*** READDIR TEST ***\n" );

  printf( "\nchdir to the root directory\n" );
  status = chdir( "/" );
  printf( "chdir() status : %d\n\n", status );

  printf( "\nCreating a series of directories under /\n" );
  i=0;
  while ( strcmp(dnames[i], "END") != 0 )
  {
     status = mkdir( dnames[i], 0x1c0 );
     printf("Creating directory: %s      %d %d   ", dnames[i], status, errno );
     if ( errno == 0 )
        printf(" Success\n");
     else
        printf(" Failure\n");

     i++;
  }

  /*
   * Create files under many and open the directory.
   */

  printf("Create a lot of files\n");
  status = mkdir( "/many", 0x1c0 );
  status = chdir( "/many" );
  for (i = 0; i<44; i++) {
    printf("Create %s\n", many_files[i]);
    fd = open (many_files[i], O_CREAT, S_IRWXU);
    close (fd);
  }
  printf("Open /many and print the directory\n");
  directory_not = opendir( "/many" );
  printdir ( directory_not );
  d_not = readdir( directory_not );

  printf("open /b/myfile\n");
  fd = open ("/b/my_file", O_CREAT, S_IRWXU);
  rtems_test_assert( fd != -1 );
  close (fd);

  printf("scandir a file status: ");
  status = scandir(
     "/b/my_file",
     &namelist,
     select1,
     NULL
  );
  printf("%d\n", status);

  printf("Open /b/new_file\n");
  fd  = open( "/b/new_file", O_CREAT, S_IRWXU );
  rtems_test_assert( fd != -1 );

  printf("fcntl F_SETFD should return 0\n");
  status = fcntl( fd, F_SETFD, 1 );
  rtems_test_assert( status == 0 );

  printf("fcntl F_SETFD should return 1\n");
  status = fcntl( fd, F_GETFD, 1 );
  rtems_test_assert( status == 1 );

#if 0
  printf("fcntl F_DUPFD should return 0\n");
  status = fcntl( fd, F_DUPFD, 0 );
  rtems_test_assert ( status == 0 );
#else
  printf("fcntl F_DUPFD should return 0 -- skip until implemented\n");
#endif

  printf("fcntl F_GETFL returns current flags\n");
  status = fcntl( fd, F_GETFL, 1 );
  printf("fcntl F_GETFL returned 0x%x\n", status );
  rtems_test_assert( status != -1 );

  printf("fcntl F_SETFL to add O_APPEND and O_NONBLOCK\n");
  status = fcntl( fd, F_SETFL, O_APPEND|O_NONBLOCK );
  rtems_test_assert ( status != -1 );

  printf("fcntl F_GETFL return current flags to see changes\n");
  status = fcntl( fd, F_GETFL, 1 );
  printf("fcntl F_GETFL returned 0x%x\n", status );
  rtems_test_assert( status != -1 );

  printf("fcntl F_GETLK should return -1\n");
  status = fcntl( fd, F_GETLK, 1 );
  rtems_test_assert ( status == -1 );

  printf("fcntl F_SETLK should return -1\n");
  status = fcntl( fd, F_SETLK, 1 );
  rtems_test_assert ( status == -1 );

  printf("fcntl F_SETLKW should return -1\n");
  status = fcntl( fd, F_SETLKW, 1 );
  rtems_test_assert ( status == -1 );

  printf("fcntl F_SETOWN should return -1\n");
  status = fcntl( fd, F_SETOWN, 1 );
  rtems_test_assert ( status == -1 );

  printf("fcntl F_GETOWN should return -1\n");
  status = fcntl( fd, F_GETOWN, 1 );
  rtems_test_assert ( status == -1 );

  printf("fcntl invalid argument should return -1\n");
  status = fcntl( fd, 0xb, 1 );
  printf("Status %d\n",status);
  rtems_test_assert( status == -1 );

  printf("opendir and readdir /b/myfile\n");
  directory_not = opendir ("/b/my_file");
  d_not = readdir(directory_not);

  printf("opendir and readdir\n");
  directory_not = opendir ("/a");
  d_not = readdir (directory_not);

  printf("chdir to /b/myfile\n");
  status = chdir ("/b/my_file");
  rtems_test_assert (status == -1);

  printf( "\nPerforming stat of directory /\n");
  status = stat( "/", &s );
  printf("status for stat : %d, size of directory: %" PRIdoff_t "\n\n", status, s.st_size);

  puts( "\nOpen and print directory /" );
  directory = opendir("/");
  rtems_test_assert( directory );
  printdir(directory);

  printf("\nmkdir /d/my_dir\n");
  status = mkdir( "/d/my_dir", 0x1c0 );
  printf("Open /d/my_dir\n");
  directory_not = opendir( "/d/my_dir" );
  rtems_test_assert( directory_not );

  printf( "remove /d/my_dir.\n" );
  status = rmdir( "/d/my_dir" );
  rtems_test_assert( status == 0 );

  printf( "close /d/my_dir.\n" );
  closedir( directory_not );

  printf( "\nOpening directory /c\n" );
  directory2 = opendir("/c");

  rtems_test_assert( directory2 );

  printdir(directory2);
  status = closedir( directory2 );

  printf( "\nOpening directory /c/y\n" );
  directory3 = opendir("/c/y");
  rtems_test_assert( directory3 );
  printdir(directory3);
  status = closedir( directory3 );

  printf( "\nLSEEK to the start of the open directory\n" );
  lseek( directory->dd_fd, 0, SEEK_SET );
  printdir(directory);

  lseek( directory->dd_fd, 0, SEEK_CUR );

  lseek( directory->dd_fd, 0, SEEK_END );

  lseek( directory->dd_fd, 0, -99 );

  printf( "\nRewinding directory\n" );
  rewinddir( directory );
  printdir(directory);

#if 0
  /* Newlib's implementation does not check for NULL */
  printf( "Send rewinddir a NULL pointer\n");
  rewinddir( NULL );
#endif

  printf( "\nSeek directory\n" );
  printf( "telldir() should report only sizeof(struct dirent) increments \n" );
  printf( "in position. Sizeof(struct dirent): %ld\n",
                          (unsigned long) sizeof(struct dirent) );
  rewinddir( directory );
  for( off=0 ; off<=200 ; off=off + sizeof(struct dirent) / 4 ) {
    seekdir( directory, off );
    printf(
       "seeked to %2d -- currently at %2d\n",
       (int)off,
       (int)telldir(directory)
    );
  }

  printf( "Send seekdir a NULL pointer\n");
  seekdir( NULL, off );

  printf( "\nClosing directory\n" );
  status = closedir( directory );

  printf( "\nSCANDIR TEST\n");
  printf( "\nselection rule 1\n");
  printf( "scanning for any entry under directory /c\n\n");
  status = scandir(
     "/c",
     &namelist,
     select1,
     NULL
  );
  printf("\nscandir status: %d\n", status );
  for ( i=0; i<status; i++)
  {
     printf("Selected Node Name: %s\n", namelist[i]->d_name );
  }

  printf( "\nselection rule 2\n");
  printf( "scanning for any entry under directory /c whose name = y\n\n");
  status = scandir(
     "/c",
     &namelist,
     select2,
     NULL
  );
  printf("\nscandir status: %d\n", status );
  for ( i=0; i<status; i++)
  {
     printf("Selected Node Name: %s\n", namelist[i]->d_name );
  }

  printf( "\nSCANDIR with sorting\n" );
  printf( "\nselection rule 1\n");
  printf( "scanning for any entry under directory /c\n");
  printf( "sort in ascending order\n\n");
  status = scandir(
     "/c",
     &namelist,
     select1,
     compare_ascending
  );
  printf("\nscandir status: %d\n", status );
  for ( i=0; i<status; i++)
  {
     printf("Selected and Sorted Node Name: %s\n", namelist[i]->d_name );
  }


  printf( "\nSCANDIR with sorting\n" );
  printf( "\nselection rule 1\n");
  printf( "scanning for any entry under directory /c\n");
  printf( "sort in descending order\n\n");
  status = scandir(
     "/c",
     &namelist,
     select1,
     compare_descending
  );
  printf("scandir status: %d\n", status );
  for ( i=0; i<status; i++)
  {
     printf("Selected and Sorted Node Name: %s\n", namelist[i]->d_name );
  }

  test_across_mount();
  printf( "\n\n*** END OF READDIR TEST ***\n" );
  rtems_test_exit(0);
}
Example #29
0
static void test_task_get_set_affinity(void)
{
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
  rtems_id self_id = rtems_task_self();
  rtems_id task_id;
  rtems_status_code sc;
  cpu_set_t cpusetone;
  cpu_set_t cpuset;
  size_t big = 2 * CHAR_BIT * sizeof(cpu_set_t);
  size_t cpusetbigsize = CPU_ALLOC_SIZE(big);
  cpu_set_t *cpusetbigone;
  cpu_set_t *cpusetbig;

  CPU_ZERO(&cpusetone);
  CPU_SET(0, &cpusetone);

  sc = rtems_task_create(
    rtems_build_name('T', 'A', 'S', 'K'),
    2,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_get_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);

  sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);

  sc = rtems_task_get_affinity(RTEMS_SELF, 0, &cpuset);
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_task_set_affinity(RTEMS_SELF, 0, &cpuset);
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_task_get_affinity(invalid_id, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  sc = rtems_task_set_affinity(invalid_id, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  sc = rtems_task_get_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));

  sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_affinity(self_id, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_affinity(task_id, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_get_affinity(task_id, sizeof(cpuset), &cpuset);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));

  cpusetbigone = CPU_ALLOC(big);
  rtems_test_assert(cpusetbigone != NULL);

  cpusetbig = CPU_ALLOC(big);
  rtems_test_assert(cpusetbig != NULL);

  CPU_ZERO_S(cpusetbigsize, cpusetbigone);
  CPU_SET_S(0, cpusetbigsize, cpusetbigone);

  sc = rtems_task_get_affinity(task_id, cpusetbigsize, cpusetbig);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(CPU_EQUAL_S(cpusetbigsize, cpusetbig, cpusetbigone));

  sc = rtems_task_set_affinity(task_id, cpusetbigsize, cpusetbig);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_delete(task_id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  CPU_FREE(cpusetbig);
  CPU_FREE(cpusetbigone);
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
}
Example #30
0
/*
 * The test sequence
 */
static
void test( void )
{
  rtems_status_code sc;
  int               rv;
  char              device_name[] = "/dev/sda1";
  uint32_t          block_size;
  rtems_blkdev_bnum block_number;
  rtems_blkdev_bnum blocks_allocated;
  int               file_descriptor;
  uint8_t           fill_pattern = 0;


  sc = rtems_disk_io_initialize();
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  block_size       = 512;
  block_number     = 4 * 2 * 1024;
  blocks_allocated = 8;
  sc               = rtems_sparse_disk_create_and_register(
    "/dev/sda1",
    block_size,
    blocks_allocated,
    block_number,
    fill_pattern
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Test reading and writing with sector size 512 and 8 such sectors
   * allocated. Block size will default to 512 */
  test_device_io(
    device_name,
    block_size,
    block_size,
    block_number,
    blocks_allocated,
    fill_pattern
    );

  file_descriptor = open( device_name, O_RDWR );
  rtems_test_assert( 0 <= file_descriptor );

  rv = rtems_disk_fd_set_block_size( file_descriptor,
                                     blocks_allocated * block_size );
  rtems_test_assert( 0 == rv );

  rv = close( file_descriptor );
  rtems_test_assert( 0 == rv );

  /* Block size was increased to 4k. Thus all to allocated disk space
   * corresponds to one block. Repeat the read write tests */
  test_device_io(
    device_name,
    block_size * blocks_allocated,
    block_size,
    block_number,
    1,
    fill_pattern
    );

  rv = unlink( device_name );
  rtems_test_assert( 0 == rv );

  /* Do testing with a statically allocated disk. This permits white box
   * testing */
  test_with_whitebox( device_name );
}