Beispiel #1
0
void basic_init()
{
	signal_handler_init();

	// Force '.' as decimal point
	std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
	setlocale(LC_NUMERIC, "C");

	log_set_max_level(LOG_VERBOSE);

	guard_init();
}
static int create_test()
{
   int passed = 1;
   VCOS_SEMAPHORE_T semas[MAX_TESTED];
   GUARD_T guard;
   int i;

   for(i=0; i<MAX_TESTED; i++)
   {
      if(vcos_semaphore_create(semas+i, "sem", i) != VCOS_SUCCESS)
      {
         vcos_assert(0);
         passed = 0;
      }
   }

   for(i=0; i<MAX_TESTED; i+=2)
      vcos_semaphore_delete(semas+i);

   for(i=0; i<MAX_TESTED; i+=2)
      if(vcos_semaphore_create(semas+i, "sem2", i) != VCOS_SUCCESS)
         passed = 0;

   if(passed)
   {
      if(guard_init(&guard) < 0)
         passed = 0;
      else
      {
         /* see if the values appear to be independent */
         for(i=0; i<MAX_TESTED && passed; i++)
         {
            int j;

            guard.wait[0] = 10;
            guard.post[0] = 1;
            guard.wait[1] = 10;
            guard.post[1] = 100;
            guard.guard = semas+i;

            vcos_semaphore_post(&guard.go);

            /* wait for one more than we set, the first wait by the guard
             * should timeout, and it will post one more time.  We should
             * then wake up here, and set the event, so the second wait
             * shouldn't timeout.
             */

            for(j=0; j<i+1; j++)
               vcos_semaphore_wait(semas+i);

            vcos_event_flags_set(&guard.event, 1, VCOS_OR);

            vcos_semaphore_wait(&guard.done);
            if(!guard.timeout[0] || guard.timeout[1])
               passed = 0;
         }

         guard_deinit(&guard, &passed);
      }

      for(i=0; i<MAX_TESTED; i++)
         vcos_semaphore_delete(semas+i);
   }
   return passed;
}