Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / sched / get_priority_test.cpp
blob3a79a67802cf3e9c3dd2aec65270a11bfbaa9b53
1 //===-- Unittests for sched_get_priority_{min,max} ------------------------===//
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/errno/libc_errno.h"
10 #include "src/sched/sched_get_priority_max.h"
11 #include "src/sched/sched_get_priority_min.h"
12 #include "test/UnitTest/Test.h"
14 #include <sched.h>
16 TEST(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
18 // Test arbitrary values for which there is no policy.
20 int policy = -1;
21 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
22 ASSERT_EQ(max_priority, -1);
23 ASSERT_EQ(libc_errno, EINVAL);
24 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
25 ASSERT_EQ(min_priority, -1);
26 ASSERT_EQ(libc_errno, EINVAL);
30 int policy = 30;
31 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
32 ASSERT_EQ(max_priority, -1);
33 ASSERT_EQ(libc_errno, EINVAL);
34 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
35 ASSERT_EQ(min_priority, -1);
36 ASSERT_EQ(libc_errno, EINVAL);
40 int policy = 80;
41 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
42 ASSERT_EQ(max_priority, -1);
43 ASSERT_EQ(libc_errno, EINVAL);
44 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
45 ASSERT_EQ(min_priority, -1);
46 ASSERT_EQ(libc_errno, EINVAL);
50 int policy = 110;
51 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
52 ASSERT_EQ(max_priority, -1);
53 ASSERT_EQ(libc_errno, EINVAL);
54 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
55 ASSERT_EQ(min_priority, -1);
56 ASSERT_EQ(libc_errno, EINVAL);
60 TEST(LlvmLibcSchedGetPriorityTest, SmokeTest) {
61 libc_errno = 0;
63 // We Test:
64 // SCHED_OTHER, SCHED_FIFO, SCHED_RR
65 // Linux specific test could also include:
66 // SCHED_BATCH, SCHED_ISO, SCHED_IDLE, SCHED_DEADLINE
68 int policy = SCHED_OTHER;
69 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
70 ASSERT_GE(max_priority, 0);
71 ASSERT_EQ(libc_errno, 0);
72 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
73 ASSERT_GE(min_priority, 0);
74 ASSERT_EQ(libc_errno, 0);
76 ASSERT_LE(max_priority, 99);
77 ASSERT_GE(min_priority, 0);
78 ASSERT_GE(max_priority, min_priority);
82 int policy = SCHED_FIFO;
83 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
84 ASSERT_GE(max_priority, 0);
85 ASSERT_EQ(libc_errno, 0);
86 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
87 ASSERT_GE(min_priority, 0);
88 ASSERT_EQ(libc_errno, 0);
90 ASSERT_LE(max_priority, 99);
91 ASSERT_GE(min_priority, 0);
92 ASSERT_GT(max_priority, min_priority);
96 int policy = SCHED_RR;
97 int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
98 ASSERT_GE(max_priority, 0);
99 ASSERT_EQ(libc_errno, 0);
100 int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
101 ASSERT_GE(min_priority, 0);
102 ASSERT_EQ(libc_errno, 0);
104 ASSERT_LE(max_priority, 99);
105 ASSERT_GE(min_priority, 0);
106 ASSERT_GT(max_priority, min_priority);