1//===-- Unittests for getitimer -------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#include "hdr/types/struct_itimerval.h"
11#include "src/sys/time/getitimer.h"
12#include "test/UnitTest/ErrnoCheckingTest.h"
13#include "test/UnitTest/ErrnoSetterMatcher.h"
14#include "test/UnitTest/Test.h"
15
16using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
17using LlvmLibcSysTimeGetitimerTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
18
19TEST_F(LlvmLibcSysTimeGetitimerTest, SmokeTest) {
20 struct itimerval timer;
21 timer.it_value.tv_sec = -1;
22 timer.it_value.tv_usec = -1;
23 timer.it_interval.tv_sec = -1;
24 timer.it_interval.tv_usec = -1;
25
26 ASSERT_THAT(LIBC_NAMESPACE::getitimer(0, &timer),
27 returns(EQ(0)).with_errno(EQ(0)));
28
29 ASSERT_TRUE(timer.it_value.tv_sec == 0);
30 ASSERT_TRUE(timer.it_value.tv_usec == 0);
31 ASSERT_TRUE(timer.it_interval.tv_sec == 0);
32 ASSERT_TRUE(timer.it_interval.tv_usec == 0);
33}
34
35TEST_F(LlvmLibcSysTimeGetitimerTest, InvalidRetTest) {
36 struct itimerval timer;
37
38 // out of range timer type (which)
39 ASSERT_THAT(LIBC_NAMESPACE::getitimer(99, &timer),
40 returns(NE(0)).with_errno(NE(0)));
41}
42

source code of libc/test/src/sys/time/getitimer_test.cpp