Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / sched / affinity_test.cpp
blob38433edecbd0c0608f3a2c585d7b130a5ca109ec
1 //===-- Unittests for sched_getaffinity and sched_setaffinity -------------===//
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-exception
6 //
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"
15 #include <sched.h>
16 #include <sys/syscall.h>
18 TEST(LlvmLibcSchedAffinityTest, SmokeTest) {
19 cpu_set_t mask;
20 libc_errno = 0;
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),
26 Succeeds(0));
27 ASSERT_THAT(LIBC_NAMESPACE::sched_setaffinity(tid, sizeof(cpu_set_t), &mask),
28 Succeeds(0));
31 TEST(LlvmLibcSchedAffinityTest, BadMask) {
32 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
33 pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
35 libc_errno = 0;
36 ASSERT_THAT(
37 LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr),
38 Fails(EFAULT));
40 libc_errno = 0;
41 ASSERT_THAT(
42 LIBC_NAMESPACE::sched_setaffinity(tid, sizeof(cpu_set_t), nullptr),
43 Fails(EFAULT));
45 libc_errno = 0;