[libc-commits] [libc] [libc] Temporarily disable SCHED_FIFO and SCHED_RR tests (PR #95562)
via libc-commits
libc-commits at lists.llvm.org
Mon Jun 17 08:16:33 PDT 2024
https://github.com/overmighty updated https://github.com/llvm/llvm-project/pull/95562
>From 382105209bb3ef5d3c3d7608e88682152c8b585a Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Fri, 14 Jun 2024 18:31:49 +0200
Subject: [PATCH 1/3] [libc] Temporarily disable SCHED_FIFO and SCHED_RR tests
These tests fail on Arch Linux, where setting these scheduling policies
succeeds even when not running as root.
---
libc/test/src/sched/param_and_scheduler_test.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/sched/param_and_scheduler_test.cpp b/libc/test/src/sched/param_and_scheduler_test.cpp
index 8e81f2ed1517f..7cf553f1af525 100644
--- a/libc/test/src/sched/param_and_scheduler_test.cpp
+++ b/libc/test/src/sched/param_and_scheduler_test.cpp
@@ -145,9 +145,11 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
using LlvmLibcSchedTest = SchedTest; \
TEST_F(LlvmLibcSchedTest, Sched_##policy) { testSched(policy, can_set); }
-// Root is required to set these policies.
-LIST_SCHED_TESTS(SCHED_FIFO, LIBC_NAMESPACE::getuid() == 0)
-LIST_SCHED_TESTS(SCHED_RR, LIBC_NAMESPACE::getuid() == 0)
+// Temporarily disabled as these tests are failing on Arch Linux where
+// scheduling policy setting succeeds without running as root.
+// // Root is required to set these policies.
+// LIST_SCHED_TESTS(SCHED_FIFO, LIBC_NAMESPACE::getuid() == 0)
+// LIST_SCHED_TESTS(SCHED_RR, LIBC_NAMESPACE::getuid() == 0)
// No root is required to set these policies.
LIST_SCHED_TESTS(SCHED_OTHER, true)
>From fdd0136907ad486ae3c70a747c5d34ed1dda82f6 Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Fri, 14 Jun 2024 20:54:49 +0200
Subject: [PATCH 2/3] Revert "[libc] Temporarily disable SCHED_FIFO and
SCHED_RR tests"
This reverts commit 382105209bb3ef5d3c3d7608e88682152c8b585a.
---
libc/test/src/sched/param_and_scheduler_test.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/libc/test/src/sched/param_and_scheduler_test.cpp b/libc/test/src/sched/param_and_scheduler_test.cpp
index 7cf553f1af525..8e81f2ed1517f 100644
--- a/libc/test/src/sched/param_and_scheduler_test.cpp
+++ b/libc/test/src/sched/param_and_scheduler_test.cpp
@@ -145,11 +145,9 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
using LlvmLibcSchedTest = SchedTest; \
TEST_F(LlvmLibcSchedTest, Sched_##policy) { testSched(policy, can_set); }
-// Temporarily disabled as these tests are failing on Arch Linux where
-// scheduling policy setting succeeds without running as root.
-// // Root is required to set these policies.
-// LIST_SCHED_TESTS(SCHED_FIFO, LIBC_NAMESPACE::getuid() == 0)
-// LIST_SCHED_TESTS(SCHED_RR, LIBC_NAMESPACE::getuid() == 0)
+// Root is required to set these policies.
+LIST_SCHED_TESTS(SCHED_FIFO, LIBC_NAMESPACE::getuid() == 0)
+LIST_SCHED_TESTS(SCHED_RR, LIBC_NAMESPACE::getuid() == 0)
// No root is required to set these policies.
LIST_SCHED_TESTS(SCHED_OTHER, true)
>From 80f13a2efa3ef627cdcad6ef76672cdf94c9e7f9 Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Mon, 17 Jun 2024 17:12:48 +0200
Subject: [PATCH 3/3] [libc] Fix scheduler test incorrectly guessing user
privileges
Non-root users may be able to set real-time scheduling policies. Don't
expect failure to set real-time scheduling policies based on UID.
Instead, check that if it fails, it is either due to missing privileges,
or unsupported parameters if the scheduling policy is not mandated by
POSIX.
---
.../src/sched/param_and_scheduler_test.cpp | 48 +++++++++++--------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/libc/test/src/sched/param_and_scheduler_test.cpp b/libc/test/src/sched/param_and_scheduler_test.cpp
index 8e81f2ed1517f..747c7e3409e41 100644
--- a/libc/test/src/sched/param_and_scheduler_test.cpp
+++ b/libc/test/src/sched/param_and_scheduler_test.cpp
@@ -36,7 +36,7 @@
class SchedTest : public LIBC_NAMESPACE::testing::Test {
public:
- void testSched(int policy, bool can_set) {
+ void testSched(int policy, bool is_mandatory) {
LIBC_NAMESPACE::libc_errno = 0;
int init_policy = LIBC_NAMESPACE::sched_getscheduler(0);
@@ -74,24 +74,26 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
param.sched_priority = max_priority + 1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m), -1);
- // A bit hard to test as depending if we are root or not we can run into
+ // A bit hard to test as depending on user privileges we can run into
// different issues.
ASSERT_TRUE(LIBC_NAMESPACE::libc_errno == EINVAL ||
LIBC_NAMESPACE::libc_errno == EPERM);
LIBC_NAMESPACE::libc_errno = 0;
- // Some sched policies require permissions, so skip
param.sched_priority = min_priority;
- // Success / missing permissions.
- ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m),
- can_set ? 0 : -1);
- ASSERT_TRUE(can_set ? (LIBC_NAMESPACE::libc_errno == 0)
- : (LIBC_NAMESPACE::libc_errno == EINVAL ||
- LIBC_NAMESPACE::libc_errno == EPERM));
+ // Success/unsupported policy/missing permissions.
+ int setscheduler_result =
+ LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m);
+ ASSERT_TRUE(setscheduler_result == 0 || setscheduler_result == -1);
+ ASSERT_TRUE(
+ setscheduler_result != -1
+ ? (LIBC_NAMESPACE::libc_errno == 0)
+ : ((!is_mandatory && LIBC_NAMESPACE::libc_errno == EINVAL) ||
+ LIBC_NAMESPACE::libc_errno == EPERM));
LIBC_NAMESPACE::libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getscheduler(0),
- can_set ? policy : init_policy);
+ setscheduler_result != -1 ? policy : init_policy);
ASSERT_ERRNO_SUCCESS();
// Out of bounds priority
@@ -121,17 +123,21 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
ASSERT_ERRNO_EQ(EINVAL);
LIBC_NAMESPACE::libc_errno = 0;
- // Success / missing permissions
- ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, ¶m), can_set ? 0 : -1);
- ASSERT_TRUE(can_set ? (LIBC_NAMESPACE::libc_errno == 0)
- : (LIBC_NAMESPACE::libc_errno == EINVAL ||
- LIBC_NAMESPACE::libc_errno == EPERM));
+ // Success/unsupported policy/missing permissions
+ int setparam_result = LIBC_NAMESPACE::sched_setparam(0, ¶m);
+ ASSERT_TRUE(setparam_result == 0 || setparam_result == -1);
+ ASSERT_TRUE(setparam_result != -1
+ ? (LIBC_NAMESPACE::libc_errno == 0)
+ : ((setscheduler_result == -1 &&
+ LIBC_NAMESPACE::libc_errno == EINVAL) ||
+ LIBC_NAMESPACE::libc_errno == EPERM));
LIBC_NAMESPACE::libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(0, ¶m), 0);
ASSERT_ERRNO_SUCCESS();
- ASSERT_EQ(param.sched_priority, can_set ? priority : init_priority);
+ ASSERT_EQ(param.sched_priority,
+ setparam_result != -1 ? priority : init_priority);
}
// Null test
@@ -145,12 +151,12 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
using LlvmLibcSchedTest = SchedTest; \
TEST_F(LlvmLibcSchedTest, Sched_##policy) { testSched(policy, can_set); }
-// Root is required to set these policies.
-LIST_SCHED_TESTS(SCHED_FIFO, LIBC_NAMESPACE::getuid() == 0)
-LIST_SCHED_TESTS(SCHED_RR, LIBC_NAMESPACE::getuid() == 0)
-
-// No root is required to set these policies.
+// Mandated by POSIX.
LIST_SCHED_TESTS(SCHED_OTHER, true)
+LIST_SCHED_TESTS(SCHED_FIFO, true)
+LIST_SCHED_TESTS(SCHED_RR, true)
+
+// Linux extensions.
LIST_SCHED_TESTS(SCHED_BATCH, true)
LIST_SCHED_TESTS(SCHED_IDLE, true)
More information about the libc-commits
mailing list