static void test_ClockAccumMs_validate(long sec, long nsec, int ms) { struct timespec ts; ts.tv_sec = sec; ts.tv_nsec = nsec; long long reference_nsec = (sec * NSEC_PER_SEC) + nsec + (ms * NSEC_PER_MSEC); /* ts will contain ts+ms */ ClockAccumMs(&ts, ms); long long total_result_nsec = (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec; g_assert(total_result_nsec == reference_nsec); }
static Activity * _activity_new(const char *activity_id, int duration_ms) { if (duration_ms >= ACTIVITY_MAX_DURATION_MS) { duration_ms = ACTIVITY_MAX_DURATION_MS; } Activity *activity = g_new0(Activity, 1); activity->activity_id = g_strdup(activity_id); activity->duration_ms = duration_ms; // end += duration ClockGetTime(&activity->start_time); activity->end_time.tv_sec = activity->start_time.tv_sec; activity->end_time.tv_nsec = activity->start_time.tv_nsec; ClockAccumMs(&activity->end_time, activity->duration_ms); return activity; }