{
return _fstat;
}
+
+/**
+ * Not all systems support the same clockid_t's. This call checks
+ * if the CLOCK_MONOTONIC clockid_t is valid. If so, that is returned,
+ * otherwise, CLOCK_REALTIME is returned.
+ *
+ * The clockid_t that was found to work on the first call is
+ * cached for subsequent calls.
+ */
+clockid_t check_get_clockid()
+{
+ static clockid_t clockid = -1;
+
+ if(clockid == -1)
+ {
+ struct timespec ts;
+ if(clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
+ {
+ clockid = CLOCK_MONOTONIC;
+ }
+ else
+ {
+ clockid = CLOCK_REALTIME;
+ }
+ }
+
+ return clockid;
+}
struct timeval inittv;
struct tm now;
gettimeofday(&inittv, NULL);
- clock_gettime(CLOCK_MONOTONIC, &ts_start);
+ clock_gettime(check_get_clockid(), &ts_start);
localtime_r(&(inittv.tv_sec), &now);
strftime(t, sizeof("yyyy-mm-dd hh:mm:ss"), "%Y-%m-%d %H:%M:%S", &now);
}
unsigned int duration;
/* calculate time the test were running */
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
+ clock_gettime(check_get_clockid(), &ts_end);
duration = DIFF_IN_USEC(ts_start, ts_end);
fprintf(file, " <duration>%u.%06u</duration>\n",
duration / 1000000, duration % 1000000);
tr = tcase_run_checked_setup(sr, tc);
if (tr == NULL) {
if ( 0 == setjmp(error_jmp_buffer) ) {
- clock_gettime(CLOCK_MONOTONIC, &ts_start);
+ clock_gettime(check_get_clockid(), &ts_start);
tfun->fn(i);
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
+ clock_gettime(check_get_clockid(), &ts_end);
}
tcase_run_checked_teardown(tc);
return receive_result_info_nofork(tc->name, tfun->name, i,
int status = 0;
struct timespec ts_start = {0}, ts_end = {0};
- int timer_create_result;
timer_t timerid;
struct itimerspec timer_spec;
TestResult * tr;
group_pid = getpgrp();
tr = tcase_run_checked_setup(sr, tc);
free(tr);
- clock_gettime(CLOCK_MONOTONIC, &ts_start);
+ clock_gettime(check_get_clockid(), &ts_start);
tfun->fn(i);
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
+ clock_gettime(check_get_clockid(), &ts_end);
tcase_run_checked_teardown(tc);
send_duration_info(DIFF_IN_USEC(ts_start, ts_end));
exit(EXIT_SUCCESS);
alarm_received = 0;
- timer_create_result = timer_create(CLOCK_MONOTONIC,
- NULL /* fire SIGALRM if timer expires */,
- &timerid);
-
- /*
- * CLOCK_MONOTONIC is not supported on the Cygwin platform
- * (maybe others as well). If the timer creation fails, attempt with
- * CLOCK_REALTIME before bailing out.
- */
- if(timer_create_result != 0)
- {
- timer_create_result = timer_create(CLOCK_REALTIME,
- NULL /* fire SIGALRM if timer expires */,
- &timerid);
- }
-
- if(timer_create_result == 0)
+ if(timer_create(check_get_clockid(),
+ NULL /* fire SIGALRM if timer expires */,
+ &timerid) == 0)
{
/* Set the timer to fire once */
timer_spec.it_value = tc->timeout;