[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / time / clock_gettime_test.cpp
blob6bea4ab539af167249230d496f826b53b36552c4
1 //===-- Unittests for clock_gettime ---------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/time/clock_gettime.h"
10 #include "test/UnitTest/Test.h"
12 #include <time.h>
14 TEST(LlvmLibcClockGetTime, RealTime) {
15 struct timespec tp;
16 int result;
17 result = clock_gettime(CLOCK_REALTIME, &tp);
18 ASSERT_EQ(result, 0);
19 ASSERT_GT(tp.tv_sec, time_t(0));
22 #ifdef CLOCK_MONOTONIC
23 TEST(LlvmLibcClockGetTime, MonotonicTime) {
24 struct timespec tp1, tp2;
25 int result;
26 result = clock_gettime(CLOCK_MONOTONIC, &tp1);
27 ASSERT_EQ(result, 0);
28 ASSERT_GT(tp1.tv_sec, time_t(0));
29 result = clock_gettime(CLOCK_MONOTONIC, &tp2);
30 ASSERT_EQ(result, 0);
31 ASSERT_GE(tp2.tv_sec, tp1.tv_sec); // The monotonic clock should increase.
32 if (tp2.tv_sec == tp1.tv_sec) {
33 ASSERT_GE(tp2.tv_nsec, tp1.tv_nsec);
36 #endif // CLOCK_MONOTONIC