brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 9758501 Raw
50 lines · cpp
1//===-- Unittests for timespec_get ----------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "hdr/time_macros.h"10#include "hdr/types/struct_timespec.h"11#include "src/__support/macros/properties/architectures.h"12#include "src/time/timespec_get.h"13#include "test/UnitTest/Test.h"14 15TEST(LlvmLibcTimespecGet, Utc) {16  timespec ts;17  int result;18  result = LIBC_NAMESPACE::timespec_get(&ts, TIME_UTC);19#ifdef LIBC_TARGET_ARCH_IS_GPU20  ASSERT_EQ(result, 0);21#else22  ASSERT_EQ(result, TIME_UTC);23  ASSERT_GT(ts.tv_sec, time_t(0));24#endif25}26 27// Baremetal implementation currently only supports TIME_UTC28#ifndef LIBC_TARGET_OS_IS_BAREMETAL29TEST(LlvmLibcTimespecGet, Monotonic) {30  timespec ts1, ts2;31  int result;32  result = LIBC_NAMESPACE::timespec_get(&ts1, TIME_MONOTONIC);33  ASSERT_EQ(result, TIME_MONOTONIC);34  ASSERT_GT(ts1.tv_sec, time_t(0));35  result = LIBC_NAMESPACE::timespec_get(&ts2, TIME_MONOTONIC);36  ASSERT_EQ(result, TIME_MONOTONIC);37  ASSERT_GE(ts2.tv_sec, ts1.tv_sec); // The monotonic time should increase.38  if (ts2.tv_sec == ts1.tv_sec) {39    ASSERT_GE(ts2.tv_nsec, ts1.tv_nsec);40  }41}42#endif43 44TEST(LlvmLibcTimespecGet, Unknown) {45  timespec ts;46  int result;47  result = LIBC_NAMESPACE::timespec_get(&ts, 0);48  ASSERT_EQ(result, 0);49}50