30 lines · cpp
1//===-- Unittests for getcpu ----------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/OSUtil/syscall.h"10#include "src/sched/getcpu.h"11#include "test/UnitTest/ErrnoCheckingTest.h"12#include "test/UnitTest/ErrnoSetterMatcher.h"13 14using LlvmLibcSchedGetCpuTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;15 16TEST_F(LlvmLibcSchedGetCpuTest, SmokeTest) {17 unsigned int current_cpu;18 unsigned int current_node;19 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;20 ASSERT_THAT(LIBC_NAMESPACE::getcpu(¤t_cpu, ¤t_node), Succeeds(0));21}22 23TEST_F(LlvmLibcSchedGetCpuTest, BadPointer) {24 unsigned int current_cpu;25 unsigned int *current_node = reinterpret_cast<unsigned int *>(-1);26 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;27 ASSERT_THAT(LIBC_NAMESPACE::getcpu(¤t_cpu, current_node),28 Fails(EFAULT));29}30