35 lines · cpp
1//===-- Unittests for __sched_cpu_count -----------------------------------===//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/sched_getaffinity.h"11#include "src/sched/sched_getcpucount.h"12#include "test/UnitTest/ErrnoCheckingTest.h"13#include "test/UnitTest/ErrnoSetterMatcher.h"14 15#include "hdr/sched_macros.h"16#include "hdr/types/cpu_set_t.h"17#include "hdr/types/pid_t.h"18 19using LlvmLibcSchedCpuCountTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;20 21TEST_F(LlvmLibcSchedCpuCountTest, SmokeTest) {22 cpu_set_t mask;23 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;24 pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);25 ASSERT_GT(tid, pid_t(0));26 ASSERT_THAT(LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), &mask),27 Succeeds(0));28 29 // CPU_COUNT is a macro, but it expands to an LLVM-libc internal function that30 // needs to be in the appropriate namespace for the test.31 int num_cpus = LIBC_NAMESPACE::CPU_COUNT(&mask);32 ASSERT_GT(num_cpus, 0);33 ASSERT_LE(num_cpus, int(sizeof(cpu_set_t) * sizeof(unsigned long)));34}35