Пример #1
0
THREAD_PROTO(cleanupTask,arg)
{
   msocket_server_t *self = (msocket_server_t *) arg;
   if(self != 0)
   {
      if (self->pDestructor == 0)
      {
         THREAD_RETURN(0);
      }
      while(1)
      {
         int8_t rc;
         uint8_t stopThread;
         SLEEP(200); //sleep 200ms
         rc = _sem_test(&self->sem);
         if(rc < 0)
         {
            //failure
            printf("Error in cleanupTask, errno=%d\n",errno);
            break; //break while-loop
         }
         else if(rc > 0)
         {
            //successfully decreased semaphore, this means that there must be something in the array
            void *item;
            MUTEX_LOCK(self->mutex);
            assert(adt_ary_length(&self->cleanupItems)>0);
            item = adt_ary_shift(&self->cleanupItems);
            self->pDestructor(item);
            MUTEX_UNLOCK(self->mutex);
         }
         else
         {
            //failed to decrease semaphore, check if time to close
            MUTEX_LOCK(self->mutex);
            stopThread = self->cleanupStop;
            MUTEX_UNLOCK(self->mutex);
            if(stopThread)
            {
               break; //break while-loop
            }
         }
      }
   }
   THREAD_RETURN(0);
}
Пример #2
0
void background_test_task
   (
      uint_32  parameter
   )
{
   _partition_id  partition;
   _lwmem_pool_id lwmem_pool_id;
   pointer        error_ptr;
   pointer        error2_ptr;
   _mqx_uint      error;
   _mqx_uint      result;

   while (TRUE) {
      result = _event_test(&error_ptr);
      if (result != MQX_OK){
         printf("\nFailed _event_test: 0x%X.", result);
         _task_block();
      } 
      result = _log_test(&error);
      if (result != MQX_OK){
         printf("\nFailed _log_test: 0x%X.", result);
         _task_block();
      }
      result = _lwevent_test(&error_ptr, &error2_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwevent_test: 0x%X.", result);
         _task_block();
      }
      result = _lwlog_test(&error);
      if (result != MQX_OK){
         printf("\nFailed _lwlog_test: 0x%X.", result);
         _task_block();
      }
      result = _lwsem_test(&error_ptr, &error2_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwsem_test: 0x%X.", result);
         _task_block();
      }
      result = _lwmem_test(&lwmem_pool_id, &error_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwmem_test: 0x%X.", result);
         _task_block();
      }
      result = _lwtimer_test(&error_ptr, &error2_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwtimer_test: 0x%X.", result);
         _task_block();
      }
      
#if ! MQX_USE_LWMEM_ALLOCATOR      
      result = _mem_test_all(&error_ptr);
      if (result != MQX_OK){
         printf("\nFailed _mem_test_all,");
         printf("\nError = 0x%X, pool = 0x%X.", result,
            (_mqx_uint)error_ptr);
         _task_block();
      }
#endif
      
      /*
      ** Create the message component.
      ** Verify the integrity of message pools and message queues.
      */
      if (_msg_create_component() != MQX_OK){
         printf("\nError creating the message component.");
         _task_block();
      }
      if (_msgpool_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _msgpool_test.");
         _task_block();
      }
      if (_msgq_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _msgq_test.");
         _task_block();
      }
      if (_mutex_test(&error_ptr) != MQX_OK){
         printf("\nFailed _mutex_test.");
         _task_block();
      }
      if (_name_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _name_test.");
         _task_block();
      }
      if (_partition_test(&partition, &error_ptr, &error2_ptr) 
         != MQX_OK)
      {
         printf("\nFailed _partition_test.");
         _task_block();
      }
      if (_sem_test(&error_ptr) != MQX_OK){
         printf("\nFailed _sem_test.");
         _task_block();
      }
      if (_taskq_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _takq_test.");
         _task_block();
      }
      if (_timer_test(&error_ptr) != MQX_OK){
         printf("\nFailed _timer_test.");
         _task_block();
      }
      if (_watchdog_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _watchlog_test.");
         _task_block();
      }
      printf("All tests passed.");
      _task_block();
   }

}
Пример #3
0
void background_test_task
   (
      uint32_t  parameter
   )
{
   _partition_id  partition;
#if MQXCFG_ALLOCATOR == MQX_ALLOCATOR_LWMEM
   _lwmem_pool_id lwmem_pool_id;
#endif
   void          *error_ptr;
   void          *error2_ptr;
   _mqx_uint      error;
   _mqx_uint      result;

   printf("\nTesting component:");
   while (TRUE) {
      printf("\nevent");
      result = _event_test(&error_ptr);
      if (result != MQX_OK){
         printf("\nFailed _event_test: 0x%X.", result);
         _task_block();
      }
      printf("\nlog");
      result = _log_test(&error);
      if (result != MQX_OK){
         printf("\nFailed _log_test: 0x%X.", result);
         _task_block();
      }
      printf("\nlwevent");
      result = _lwevent_test(&error_ptr, &error2_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwevent_test: 0x%X.", result);
         _task_block();
      }
      printf("\nlwlog");
      result = _lwlog_test(&error);
      if (result != MQX_OK){
         printf("\nFailed _lwlog_test: 0x%X.", result);
         _task_block();
      }
      printf("\nlwsem");
      result = _lwsem_test(&error_ptr, &error2_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwsem_test: 0x%X.", result);
         _task_block();
      }

#if MQXCFG_ALLOCATOR == MQX_ALLOCATOR_LWMEM
      printf("\nlwmem");
      result = _lwmem_test(&lwmem_pool_id, &error_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwmem_test: 0x%X.", result);
         _task_block();
      }
#endif

      printf("\nlwtimer");
      result = _lwtimer_test(&error_ptr, &error2_ptr);
      if (result != MQX_OK){
         printf("\nFailed _lwtimer_test: 0x%X.", result);
         _task_block();
      }

#if ! MQXCFG_ALLOCATOR == MQX_ALLOCATOR_LWMEM
      printf("\nmem");
      result = _mem_test_all(&error_ptr);
      if (result != MQX_OK){
         printf("\nFailed _mem_test_all,");
         printf("\nError = 0x%X, pool = 0x%X.", result,
            (_mqx_uint)error_ptr);
         _task_block();
      }
#endif /* MQXCFG_ALLOCATOR */

      /*
      ** Create the message component.
      ** Verify the integrity of message pools and message queues.
      */
      printf("\nmsg");
      if (_msg_create_component() != MQX_OK){
         printf("\nError creating the message component.");
         _task_block();
      }
      printf("\nmsgpool");
      if (_msgpool_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _msgpool_test.");
         _task_block();
      }
      printf("\nmsgq");
      if (_msgq_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _msgq_test.");
         _task_block();
      }
      printf("\nmutex");
      if (_mutex_test(&error_ptr) != MQX_OK){
         printf("\nFailed _mutex_test.");
         _task_block();
      }
      printf("\nname");
      if (_name_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _name_test.");
         _task_block();
      }
      printf("\npartition");
      if (_partition_test(&partition, &error_ptr, &error2_ptr)
         != MQX_OK)
      {
         printf("\nFailed _partition_test.");
         _task_block();
      }
      printf("\nsem");
      if (_sem_test(&error_ptr) != MQX_OK){
         printf("\nFailed _sem_test.");
         _task_block();
      }
      printf("\ntaskq");
      if (_taskq_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _takq_test.");
         _task_block();
      }
      printf("\ntimer");
      if (_timer_test(&error_ptr) != MQX_OK){
         printf("\nFailed _timer_test.");
         _task_block();
      }
      printf("\nwatchdog");
      if (_watchdog_test(&error_ptr, &error2_ptr) != MQX_OK){
         printf("\nFailed _watchlog_test.");
         _task_block();
      }
      printf("\nAll tests passed.");
      _task_block();
   }

}