llvm-project/openmp/runtime/test/api/omp_get_wtime.c
Joachim Protze 7368227965 [OpenMP][Tests] Test omp_get_wtime for invariants
As discussed in D108488, testing for invariants of omp_get_wtime would be more
reliable than testing for duration of sleep, as return from sleep might be
delayed due to system load.

Alternatively/in addition, we could compare the time measured by omp_get_wtime
 to time measured with C++11 chrono (for portability?).

Differential Revision: https://reviews.llvm.org/D112458
2021-10-25 18:20:59 +02:00

31 lines
884 B
C

// RUN: %libomp-compile-and-run
#include <stdio.h>
#include <stdlib.h>
#include "omp_testsuite.h"
#include "omp_my_sleep.h"
#define NTIMES 100
#define ASSERT_CMP(lhs, cmp, rhs) \
if (!((lhs)cmp(rhs))) { \
printf("Expected: (" #lhs ") " #cmp " (" #rhs "), actual: %e vs. %e", lhs, \
rhs); \
return EXIT_FAILURE; \
}
int main() {
int i;
for (i = 0; i < NTIMES; i++) {
double start = omp_get_wtime(), end;
ASSERT_CMP(start, >=, 0.0);
for (end = omp_get_wtime(); end == start; end = omp_get_wtime()) {
ASSERT_CMP(end, >=, 0.0);
}
ASSERT_CMP(end, >=, 0.0);
ASSERT_CMP(end, >, start);
}
return EXIT_SUCCESS;
}