xref: /aosp_15_r20/external/llvm-libc/test/src/time/nanosleep_test.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
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 
16 namespace cpp = LIBC_NAMESPACE::cpp;
17 
TEST(LlvmLibcNanosleep,SmokeTest)18 TEST(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 = {1, 500};
24   struct timespec tim2 = {0, 0};
25   int ret = LIBC_NAMESPACE::nanosleep(&tim, &tim2);
26   ASSERT_ERRNO_SUCCESS();
27   ASSERT_EQ(ret, 0);
28 }
29