aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src/sys/time/getitimer_test.cpp
blob: c1d6f72701627cf52b7dd5bcde7875a1e123e1c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//===-- Unittests for getitimer -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "hdr/types/struct_itimerval.h"
#include "src/sys/time/getitimer.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
using LlvmLibcSysTimeGetitimerTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcSysTimeGetitimerTest, SmokeTest) {
  struct itimerval timer;
  timer.it_value.tv_sec = -1;
  timer.it_value.tv_usec = -1;
  timer.it_interval.tv_sec = -1;
  timer.it_interval.tv_usec = -1;

  ASSERT_THAT(LIBC_NAMESPACE::getitimer(0, &timer),
              returns(EQ(0)).with_errno(EQ(0)));

  ASSERT_TRUE(timer.it_value.tv_sec == 0);
  ASSERT_TRUE(timer.it_value.tv_usec == 0);
  ASSERT_TRUE(timer.it_interval.tv_sec == 0);
  ASSERT_TRUE(timer.it_interval.tv_usec == 0);
}

TEST_F(LlvmLibcSysTimeGetitimerTest, InvalidRetTest) {
  struct itimerval timer;

  // out of range timer type (which)
  ASSERT_THAT(LIBC_NAMESPACE::getitimer(99, &timer),
              returns(NE(0)).with_errno(NE(0)));
}