예제 #1
0
DECLARE_TEST(time, builtin) {
	tick_t tick, newtick, tps;
	deltatime_t dt;

	tps = time_ticks_per_second();
	EXPECT_GT(tps, 0);

	tick = time_current();
	thread_sleep(30);
	newtick = time_current();

	EXPECT_TICKNE(tick, 0);
	EXPECT_TICKGT(newtick, tick);

	EXPECT_TICKGT(time_diff(tick, newtick), 0);
	EXPECT_GT_MSGFORMAT(time_diff(tick, newtick), (tps / 100LL),
	                    "time elapsed not more than 10ms: %" PRId64 " (%" PRId64 ")", time_diff(tick, newtick),
	                    (tps / 100)); //more than 10 ms
	EXPECT_LT_MSGFORMAT(time_diff(tick, newtick), (tps / 20LL),
	                    "time elapsed not less than 50ms: %" PRId64 " (%" PRId64 ")", time_diff(tick, newtick),
	                    (tps / 33)); //less than 30 ms
	EXPECT_REALGT(time_elapsed(tick), 0);
	EXPECT_REALGT(time_elapsed(tick), 0.01f); //more than 10 ms
	EXPECT_TICKGT(time_elapsed_ticks(tick), 0);
	EXPECT_TICKGT(time_elapsed_ticks(tick), (tps / 100)); //more than 10 ms
	EXPECT_TICKLT(time_elapsed_ticks(tick), (tps / 20));  //less than 50 ms

	dt = time_ticks_to_seconds(newtick - tick);
	EXPECT_REALGT(dt, 0);
	EXPECT_GT_MSGFORMAT(dt, 0.01f, "time elapsed in seconds not more than 10ms: %.5f",
	                    dt);   //more than 10 ms
	EXPECT_LT_MSGFORMAT(dt, 0.05f, "time elapsed in seconds not less than 30ms: %.5f",
	                    dt);   //less than 30 ms

	tick = time_startup();
	EXPECT_TICKGT(tick, 0);
	EXPECT_TICKLT(tick, newtick);
	EXPECT_TICKEQ(tick, time_startup());

	tick = time_system();
	thread_sleep(100);
	newtick = time_system();

	EXPECT_TICKGT(tick, 0);
	EXPECT_TICKGT(newtick, 0);
	EXPECT_TICKGT(newtick, tick);
	EXPECT_GT_MSGFORMAT(newtick - tick, 50,
	                    "Elapsed system time less than 50ms, expected 100ms, got %" PRId64 "ms", newtick - tick);
	EXPECT_LT_MSGFORMAT(newtick - tick, 200,
	                    "Elapsed system time more than 200ms, expected 100ms, got %" PRId64 "ms", newtick - tick);

	return 0;
}
예제 #2
0
static log_timestamp_t _log_make_timestamp( void )
{
	tick_t elapsed;
	tick_t ticks_per_sec;
	uint64_t milliseconds;
	uint64_t seconds;
	uint64_t minutes;

	log_timestamp_t timestamp = {0};
	
	ticks_per_sec = time_ticks_per_second();
	if( !ticks_per_sec )
		return timestamp;
	
	elapsed = time_current() - time_startup();
	milliseconds = ( ( elapsed % ticks_per_sec ) * 1000ULL ) / ticks_per_sec;
	seconds = elapsed / ticks_per_sec;
	minutes = seconds / 60ULL;

	timestamp.milliseconds = (unsigned int)( milliseconds % 1000ULL );
	timestamp.seconds = (unsigned int)( seconds % 60ULL );
	timestamp.minutes = (unsigned int)( minutes % 60ULL );
	timestamp.hours = (unsigned int)( minutes / 24ULL );

	return timestamp;
}
예제 #3
0
DECLARE_TEST( time, builtin )
{
	tick_t tick, newtick, tps;
	deltatime_t dt;

	tps = time_ticks_per_second();
	EXPECT_GT( tps, 0 );

	tick = time_current();
	thread_sleep( 20 );
	newtick = time_current();

	EXPECT_NE( tick, 0 );
	EXPECT_GT( newtick, tick );

	EXPECT_GT( time_diff( tick, newtick ), 0 );
	EXPECT_GT_MSGFORMAT( time_diff( tick, newtick ), ( tps / 100LL ), "time elapsed not more than 10ms: %lld (%lld)", time_diff( tick, newtick ), ( tps / 100LL ) ); //more than 10 ms
	EXPECT_LT_MSGFORMAT( time_diff( tick, newtick ), ( tps / 30LL  ), "time elapsed not less than 30ms: %lld (%lld)", time_diff( tick, newtick ), ( tps / 33LL  ) ); //less than 30 ms
	EXPECT_GT( time_elapsed( tick ), 0 );
	EXPECT_GT( time_elapsed( tick ), 0.01f ); //more than 10 ms
	EXPECT_GT( time_elapsed_ticks( tick ), 0 );
	EXPECT_GT( time_elapsed_ticks( tick ), ( tps / 100 ) ); //more than 10 ms

	dt = time_ticks_to_seconds( newtick - tick );
	EXPECT_GT( dt, 0 );
	EXPECT_GT_MSGFORMAT( dt, 0.01f, "time elapsed in seconds not more than 10ms: %.5f", dt ); //more than 10 ms
	EXPECT_LT_MSGFORMAT( dt, 0.03f, "time elapsed in seconds not less than 30ms: %.5f", dt ); //less than 30 ms

	tick = time_startup();
	EXPECT_GT( tick, 0 );
	EXPECT_LT( tick, newtick );
	EXPECT_EQ( tick, time_startup() );

	tick = time_system();
	EXPECT_GT( tick, 0 );

	thread_sleep( 100 );

	newtick = time_system();
	EXPECT_GT( newtick, 0 );
	EXPECT_GT( newtick, tick );
	EXPECT_GT( newtick - tick, 50 ); //more than 50 ms
	EXPECT_LT( newtick - tick, 200 ); //less than 200 ms

	return 0;
}
예제 #4
0
파일: ld-time.c 프로젝트: bminor/glibc
void
time_finish (struct localedef_t *locale, const struct charmap_t *charmap)
{
  struct locale_time_t *time = locale->categories[LC_TIME].time;
  int nothing = 0;

  /* Now resolve copying and also handle completely missing definitions.  */
  if (time == NULL)
    {
      /* First see whether we were supposed to copy.  If yes, find the
	 actual definition.  */
      if (locale->copy_name[LC_TIME] != NULL)
	{
	  /* Find the copying locale.  This has to happen transitively since
	     the locale we are copying from might also copying another one.  */
	  struct localedef_t *from = locale;

	  do
	    from = find_locale (LC_TIME, from->copy_name[LC_TIME],
				from->repertoire_name, charmap);
	  while (from->categories[LC_TIME].time == NULL
		 && from->copy_name[LC_TIME] != NULL);

	  time = locale->categories[LC_TIME].time
	    = from->categories[LC_TIME].time;
	}

      /* If there is still no definition issue an warning and create an
	 empty one.  */
      if (time == NULL)
	{
	  record_warning (_("\
No definition for %s category found"), "LC_TIME");
	  time_startup (NULL, locale, 0);
	  time = locale->categories[LC_TIME].time;
	  nothing = 1;
	}
    }