brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 51159ba Raw
45 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/OSUtil/syscall.h"10#include "src/sched/sched_getaffinity.h"11#include "src/sched/sched_setaffinity.h"12#include "test/UnitTest/ErrnoCheckingTest.h"13#include "test/UnitTest/ErrnoSetterMatcher.h"14 15#include "hdr/types/cpu_set_t.h"16#include "hdr/types/pid_t.h"17#include <sys/syscall.h>18 19using LlvmLibcSchedAffinityTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;20 21TEST_F(LlvmLibcSchedAffinityTest, 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  // We just get and set the same mask.27  ASSERT_THAT(LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), &mask),28              Succeeds(0));29  ASSERT_THAT(LIBC_NAMESPACE::sched_setaffinity(tid, sizeof(cpu_set_t), &mask),30              Succeeds(0));31}32 33TEST_F(LlvmLibcSchedAffinityTest, BadMask) {34  using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;35  pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);36 37  ASSERT_THAT(38      LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr),39      Fails(EFAULT));40 41  ASSERT_THAT(42      LIBC_NAMESPACE::sched_setaffinity(tid, sizeof(cpu_set_t), nullptr),43      Fails(EFAULT));44}45