aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src/sched/getcpu_test.cpp
blob: fc4ada8a722f58d46da64db238352daa7afe1ae8 (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
//===-- Unittests for getcpu ----------------------------------------------===//
//
// 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 "src/__support/OSUtil/syscall.h"
#include "src/__support/libc_errno.h"
#include "src/sched/getcpu.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"

using LlvmLibcSchedGetCpuTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcSchedGetCpuTest, SmokeTest) {
  unsigned int current_cpu;
  unsigned int current_node;
  using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
  ASSERT_THAT(LIBC_NAMESPACE::getcpu(&current_cpu, &current_node), Succeeds(0));
}

TEST_F(LlvmLibcSchedGetCpuTest, BadPointer) {
  unsigned int current_cpu;
  unsigned int *current_node = reinterpret_cast<unsigned int *>(-1);
  using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
  ASSERT_THAT(LIBC_NAMESPACE::getcpu(&current_cpu, current_node),
              Fails(EFAULT));
}