1 //===-- Unittests for sched_getaffinity and sched_setaffinity -------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/OSUtil/syscall.h"
10 #include "src/errno/libc_errno.h"
11 #include "src/sched/sched_getaffinity.h"
12 #include "src/sched/sched_setaffinity.h"
13 #include "test/UnitTest/ErrnoSetterMatcher.h"
16 #include <sys/syscall.h>
18 TEST(LlvmLibcSchedAffinityTest
, SmokeTest
) {
21 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds
;
22 pid_t tid
= LIBC_NAMESPACE::syscall_impl
<pid_t
>(SYS_gettid
);
23 ASSERT_GT(tid
, pid_t(0));
24 // We just get and set the same mask.
25 ASSERT_THAT(LIBC_NAMESPACE::sched_getaffinity(tid
, sizeof(cpu_set_t
), &mask
),
27 ASSERT_THAT(LIBC_NAMESPACE::sched_setaffinity(tid
, sizeof(cpu_set_t
), &mask
),
31 TEST(LlvmLibcSchedAffinityTest
, BadMask
) {
32 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails
;
33 pid_t tid
= LIBC_NAMESPACE::syscall_impl
<pid_t
>(SYS_gettid
);
37 LIBC_NAMESPACE::sched_getaffinity(tid
, sizeof(cpu_set_t
), nullptr),
42 LIBC_NAMESPACE::sched_setaffinity(tid
, sizeof(cpu_set_t
), nullptr),