⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 C
📖 第 1 页 / 共 3 页
字号:
  sigset_t     *waitset,  int           sec,  int           expect_signal){  siginfo_t         siginfo;  int               status;  struct timespec   timeout;  int               signo;  siginfo.si_code = -1;  siginfo.si_signo = -1;  siginfo.si_value.sival_int = -1;  timeout.tv_sec = sec;  timeout.tv_nsec = 0;  status = sigemptyset( waitset );  assert( !status );  status = sigaddset( waitset, SIGUSR1 );  assert( !status );  printf( "waiting on any signal for %d seconds.\n", sec );  signo = sigtimedwait( waitset, &siginfo, &timeout );  if (expect_signal) {    fatal_int_service_status( signo, SIGUSR1, "got SISUSR1" );  } else {    fatal_int_service_status( signo, -1, "error return status");    fatal_posix_service_status( errno, EAGAIN, "errno EAGAIN");  }}void verify_notify(){  struct sigevent event;  int             status;  timer_t         timer_id;  sigset_t        set;  Start_Test( "mq_notify"  );  /* timer create */  event.sigev_notify = SIGEV_SIGNAL;  event.sigev_signo  = SIGUSR1;  if (timer_create (CLOCK_REALTIME, &event, &timer_id) == -1)     fatal_posix_service_status( errno, 0,  "errno ETIMEDOUT");  /* block the timer signal */  sigemptyset( &set );  sigaddset( &set, SIGUSR1 );  pthread_sigmask( SIG_BLOCK, &set, NULL );  /*   * EBADF - Not A Valid Message Queue   */  puts( "Init: mq_notify - Unopened message queue (EBADF)" );  status = mq_notify( Test_q[CLOSED].mq, NULL );  fatal_posix_service_status( status, -1, "mq_ error return status");  fatal_posix_service_status( errno, EBADF, "mq_receive errno EBADF");  /*   * Create ...   */  /*   * XXX setup notification    */  printf( "_____mq_notify - notify when %s gets a message\n",RW_NAME);  status = mq_notify( Test_q[RW_QUEUE].mq, &event );  fatal_posix_service_status( status, 0, "mq_notify valid status");  wait_for_signal( &set, 3, 0 );  /*   * Send and verify signal occurs and registration is removed.   */  puts( "Init: Verify Signal when send" );  Show_send_msg_to_que( "Init:", RW_QUEUE, 0 );  wait_for_signal( &set, 3, 1 );  Read_msg_from_que( RW_QUEUE, 0 );  puts( "Init: Verify No Signal when send" );  Show_send_msg_to_que( "Init:", RW_QUEUE, 0 );  wait_for_signal( &set, 3, 0 );  Read_msg_from_que( RW_QUEUE, 0 );  /*   * EBUSY - Already Registered   */  printf( "____mq_notify - notify when %s gets a message\n",RD_NAME);  status = mq_notify( Test_q[RW_QUEUE].mq, &event );  fatal_posix_service_status( status, 0, "mq_notify valid status");  wait_for_signal( &set, 3, 0 );  puts( "Init: mq_notify -  (EBUSY)" );  status = mq_notify( Test_q[RW_QUEUE].mq, &event );  fatal_posix_service_status( status, -1, "mq_notify error return status");  fatal_posix_service_status( errno, EBUSY, "mq_notify errno EBUSY");  /*   * Verify NULL removes registration.   */  puts( "Init: mq_notify - Remove notification with null" );  status = mq_notify( Test_q[RW_QUEUE].mq, NULL );  fatal_posix_service_status( status, 0, "mq_notify valid status");  puts( "Init: Verify No Signal when send" );  Show_send_msg_to_que( "Init:", RW_QUEUE, 0 );  wait_for_signal( &set, 3, 0 );  Read_msg_from_que( RW_QUEUE, 0 );}void verify_with_threads(){  int               status;  pthread_t         id;  Test_Message_t   *ptr;#if 0  unsigned int      priority;  char              message[100];#endif#if 0  /*   * Create a task then block until the task sends the message.   * Task tests set attributes so one queue will have a thread   * blocked while attributes are changed.   */  Start_Test( "multi-thread Task 4 Receive Test"  );  status = pthread_create( &id, NULL, Task_4, NULL );  assert( !status );  puts( "Init: mq_receive - Empty queue changes to non-blocking (EAGAIN)" );  status = mq_receive( Test_q[BLOCKING].mq, message, 100, &priority );  fatal_int_service_status( status, -1, "mq_receive error return status");  fatal_posix_service_status( errno, EAGAIN, "mq_receive errno EAGAIN");  print_current_time( "Init: ", "" );#endif  /*   * Create a task then block until the task sends the message.   * Task tests set attributes so one queue will have a thread   * blocked while attributes are changed.   */  Start_Test( "multi-thread Task 1 Test"  );  status = pthread_create( &id, NULL, Task_1, NULL );  assert( !status );  Read_msg_from_que(  BLOCKING, 0 ); /* Block until init writes */  print_current_time( "Init: ", "" );#if 0   /*   * Fill the queue then create a task then block until the task receives a message.   * Task tests set attributes so one queue will have a thread   * blocked while attributes are changed.   */  Start_Test( "multi-thread Task 4 Send Test"  );  fill_message_queues( "Init:" );  status = pthread_create( &id, NULL, Task_4, NULL );  assert( !status );  puts( "Init: mq_send - Full queue changes to non-blocking (EAGAIN)" );  status = mq_send(Test_q[BLOCKING].mq, message, 0, 0 );  fatal_posix_service_status( status, -1, "mq_send error return status");  fatal_posix_service_status( errno, EAGAIN, "mq_send errno EAGAIN");  verify_queues_full( "Init:" );  empty_message_queues( "Init:" );#endif  /*   * Create a task then block until the task reads a message.   */  Start_Test( "multi-thread Task 2 Test"  );  fill_message_queues( "Init:" );  status = pthread_create( &id, NULL, Task_2, NULL );  assert( !status );  Show_send_msg_to_que( "Init:", BLOCKING, Priority_Order[0] );   print_current_time( "Init: ", "" );  verify_queues_full( "Init:" );  empty_message_queues( "Init:" );  /*   * Create a task then block until it deletes and closes all queues.   *     EBADF - Queue unlinked and closed while blocked   */  Start_Test( "multi-thread Task 3 Test"  );  fill_message_queues( "Init:" );  status = pthread_create( &id, NULL, Task_3, NULL );  assert( !status );  puts( "Init: mq_send - Block while thread deletes queue (EBADF)" );  ptr = &Predefined_Msgs[0];  status = mq_send( Test_q[BLOCKING].mq, ptr->msg, ptr->size , ptr->priority );  fatal_posix_service_status( status, -1, "mq_send error return status");  fatal_posix_service_status( errno, EBADF, "mq_send errno EBADF");}void validate_mq_setattr(){  struct mq_attr  attr;  struct mq_attr  save_attr[ NUMBER_OF_TEST_QUEUES ];  int             status;  int            i;  /*   * EBADF - Get the attributes from a closed queue.   */  puts( "Task1:mq_setattr - unopened queue (EBADF)" );  status = mq_setattr( Test_q[CLOSED].mq, &attr, NULL );  fatal_posix_service_status( status, -1, "mq_setattr error return status");  fatal_posix_service_status( errno, EBADF, "mq_setattr errno EBADF");    /*   * XXX - The following are not listed in the POSIX manual but   *       may occur.   */  /*   * EINVAL - NULL attributes   */  puts( "Task1:mq_setattr - NULL attributes (EINVAL)" );  status = mq_setattr( Test_q[RW_QUEUE].mq, NULL, NULL );  fatal_posix_service_status( status, -1, "mq_setattr error return status");  fatal_posix_service_status( errno, EINVAL, "mq_setattr errno EINVAL");    /*   * Verify change queues to blocking, by verifying all queues block   * for a timed receive.   */  puts( "Init: set_attr all queues to blocking" );  for(i=0; i<CLOSED; i++) {    attr.mq_flags =  Test_q[i].oflag & (~O_NONBLOCK );    status = mq_setattr( Test_q[i].mq, &attr, &save_attr[i] );    fatal_int_service_status( status, 0, "mq_setattr valid return status");    Validate_attributes( Test_q[i].mq, attr.mq_flags, 0 );  }  for( i = RW_QUEUE; i < CLOSED; i++ ) {    verify_timed_receive_queue( "Init:", i, 1 );  }  /*   * Restore restore all queues to their old attribute.   */    for(i=0; i<CLOSED; i++) {    status = mq_setattr( Test_q[i].mq, &save_attr[i], NULL );    fatal_int_service_status( status, 0, "mq_setattr valid return status");    Validate_attributes( Test_q[i].mq, Test_q[i].oflag, 0 );  }}void *POSIX_Init(  void *argument){  puts( "\n\n*** POSIX MESSAGE QUEUE TEST ***" );  validate_mq_open_error_codes( );  open_test_queues();  validate_mq_unlink_error_codes();  validate_mq_close_error_codes();  verify_unlink_functionality();  validate_mq_setattr( );  validate_mq_send_error_codes();  validate_mq_getattr_error_codes();  verify_timed_send();  validate_mq_receive_error_codes();  verify_timed_receive();  verify_open_functionality();  verify_notify();  verify_with_threads();    puts( "*** END OF POSIX MESSAGE QUEUE TEST ***" );  rtems_test_exit( 0 );  return NULL; /* just so the compiler thinks we returned something */}void *Task_1 (  void *argument){  /* Block Waiting for a message */  print_current_time( "Task_1: ", "" );  Show_send_msg_to_que( "Task_1:", BLOCKING, 0 );  puts( "Task_1: pthread_exit" );  pthread_exit( NULL );  /* switch to Init */  assert( 0 );  return NULL; /* just so the compiler thinks we returned something */}void *Task_2(  void *argument){  print_current_time( "Task_2: ", "" );   /* Block waiting to send a message */  verify_queues_full( "Task_2:" );  Read_msg_from_que( BLOCKING, Priority_Order[0] ); /* Cause context switch */  puts( "Task_2: pthread_exit" );  pthread_exit( NULL );     /* switch to Init */  return NULL; /* just so the compiler thinks we returned something */}void *Task_3 (  void *argument){  print_current_time( "Task_3: ", "" );  /*   * close and unlink all queues.   */  verify_close_functionality( "Task_3: " );  puts( "Task_3: pthread_exit" );  pthread_exit( NULL );     /* switch to Init */  return NULL; /* just so the compiler thinks we returned something */}void *Task_4 (  void *argument){  struct mq_attr  attr;  int             status;  int             count;  print_current_time( "Task_4: ", "" );  /*   * Set the count to the number of messages in the queue.   */  status = mq_getattr( Test_q[BLOCKING].mq, &attr );  fatal_posix_service_status( status, 0, "mq_getattr valid return status");  count = attr.mq_curmsgs;  puts("Task_4: Set queue to non-blocking");  attr.mq_flags =  Test_q[BLOCKING].oflag | O_NONBLOCK;  status = mq_setattr( Test_q[BLOCKING].mq, &attr, NULL );  fatal_int_service_status( status, 0, "mq_setattr valid return status");  Validate_attributes( Test_q[BLOCKING].mq, attr.mq_flags, count );  puts("Task_4: Return queue to blocking");  attr.mq_flags =  Test_q[BLOCKING].oflag;  status = mq_setattr( Test_q[BLOCKING].mq, &attr, NULL );  fatal_int_service_status( status, 0, "mq_setattr valid return status");  Validate_attributes( Test_q[BLOCKING].mq, attr.mq_flags, count );  puts( "Task_4: pthread_exit" );  pthread_exit( NULL );     /* switch to Init */  return NULL; /* just so the compiler thinks we returned something */}void *Task_5 (  void *argument){  print_current_time( "Task_5: ", "" );  puts( "Task_5: pthread_exit" );  pthread_exit( NULL );     /* switch to Init */  return NULL; /* just so the compiler thinks we returned something */}void *Task_ (  void *argument){  print_current_time( "Task_: ", "" );  puts( "Task_: pthread_exit" );  pthread_exit( NULL );     /* switch to Init */  return NULL; /* just so the compiler thinks we returned something */} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -