brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · ccbad9e Raw
55 lines · cpp
1//===-- Unittests for clock_settime ---------------------------------------===//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/time/clock_settime.h"12#include "test/UnitTest/ErrnoCheckingTest.h"13#include "test/UnitTest/Test.h"14 15using LlvmLibcClockSetTime = LIBC_NAMESPACE::testing::ErrnoCheckingTest;16 17#ifdef CLOCK_MONOTONIC18TEST_F(LlvmLibcClockSetTime, MonotonicIsNotSettable) {19  timespec ts = {0, 0};20  int result = LIBC_NAMESPACE::clock_settime(CLOCK_MONOTONIC, &ts);21  ASSERT_EQ(result, -1);22  ASSERT_ERRNO_EQ(EINVAL);23}24#endif // CLOCK_MONOTONIC25 26TEST_F(LlvmLibcClockSetTime, InvalidClockId) {27  timespec ts = {0, 0};28  int result = LIBC_NAMESPACE::clock_settime(static_cast<clockid_t>(-1), &ts);29  ASSERT_EQ(result, -1);30  ASSERT_ERRNO_EQ(EINVAL);31}32 33TEST_F(LlvmLibcClockSetTime, InvalidTimespecNsec) {34  timespec ts = {0, 1000000000L};35  int result = LIBC_NAMESPACE::clock_settime(CLOCK_REALTIME, &ts);36  ASSERT_EQ(result, -1);37  ASSERT_ERRNO_EQ(EINVAL);38}39 40TEST_F(LlvmLibcClockSetTime, NullPointerIsEFAULT) {41  int result = LIBC_NAMESPACE::clock_settime(CLOCK_REALTIME, nullptr);42  ASSERT_EQ(result, -1);43  ASSERT_ERRNO_EQ(EFAULT);44}45 46TEST_F(LlvmLibcClockSetTime, ClockIsSet) {47  timespec ts = {0, 0};48  int result = LIBC_NAMESPACE::clock_settime(CLOCK_REALTIME, &ts);49  if (result == 0) {50    ASSERT_ERRNO_SUCCESS();51  } else {52    ASSERT_ERRNO_EQ(EPERM);53  }54}55