1//===-- Unittests for nanosleep -------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
9#include <time.h>
10
11#include "src/errno/libc_errno.h"
12#include "src/time/nanosleep.h"
13#include "test/UnitTest/ErrnoSetterMatcher.h"
14#include "test/UnitTest/Test.h"
15
16namespace cpp = LIBC_NAMESPACE::cpp;
17
18TEST(LlvmLibcNanosleep, SmokeTest) {
19 // TODO: When we have the code to read clocks, test that time has passed.
20 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
21 LIBC_NAMESPACE::libc_errno = 0;
22
23 struct timespec tim = {.tv_sec: 1, .tv_nsec: 500};
24 struct timespec tim2 = {.tv_sec: 0, .tv_nsec: 0};
25 int ret = LIBC_NAMESPACE::nanosleep(req: &tim, rem: &tim2);
26 ASSERT_ERRNO_SUCCESS();
27 ASSERT_EQ(ret, 0);
28}
29

source code of libc/test/src/time/nanosleep_test.cpp