mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 01:10:42 +00:00
Tests: Add pthread scheduler priority tests
This commit is contained in:
parent
6dded99777
commit
2477409680
Notes:
sideshowbarker
2024-07-17 05:04:13 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/2477409680 Pull-request: https://github.com/SerenityOS/serenity/pull/14672 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/timschumi
2 changed files with 69 additions and 0 deletions
|
@ -17,6 +17,7 @@ set(TEST_SOURCES
|
|||
TestMkDir.cpp
|
||||
TestPthreadCancel.cpp
|
||||
TestPthreadCleanup.cpp
|
||||
TestPThreadPriority.cpp
|
||||
TestPthreadSpinLocks.cpp
|
||||
TestPthreadRWLocks.cpp
|
||||
TestQsort.cpp
|
||||
|
|
68
Tests/LibC/TestPThreadPriority.cpp
Normal file
68
Tests/LibC/TestPThreadPriority.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define TEST_CASE_IN_PTHREAD(x) \
|
||||
static void* __TESTCASE_FUNC(x##__inner)(void*); \
|
||||
TEST_CASE(x) \
|
||||
{ \
|
||||
pthread_t thread; \
|
||||
pthread_create(&thread, nullptr, __TESTCASE_FUNC(x##__inner), nullptr); \
|
||||
pthread_join(thread, nullptr); \
|
||||
} \
|
||||
static void* __TESTCASE_FUNC(x##__inner)(void*)
|
||||
|
||||
TEST_CASE_IN_PTHREAD(basic_priority)
|
||||
{
|
||||
auto min_priority = sched_get_priority_min(0);
|
||||
auto max_priority = sched_get_priority_max(0);
|
||||
sched_param const min_priority_parameter { .sched_priority = min_priority };
|
||||
sched_param const max_priority_parameter { .sched_priority = max_priority };
|
||||
|
||||
auto rc = pthread_setschedparam(0, 0, &min_priority_parameter);
|
||||
EXPECT_EQ(rc, 0);
|
||||
sched_param output_parameter;
|
||||
rc = pthread_getschedparam(0, 0, &output_parameter);
|
||||
EXPECT_EQ(rc, 0);
|
||||
EXPECT_EQ(output_parameter.sched_priority, min_priority);
|
||||
|
||||
rc = pthread_setschedparam(0, 0, &max_priority_parameter);
|
||||
EXPECT_EQ(rc, 0);
|
||||
rc = pthread_getschedparam(0, 0, &output_parameter);
|
||||
EXPECT_EQ(rc, 0);
|
||||
EXPECT_EQ(output_parameter.sched_priority, max_priority);
|
||||
|
||||
rc = pthread_setschedparam(0, 0, &max_priority_parameter);
|
||||
EXPECT_EQ(rc, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST_CASE_IN_PTHREAD(invalid_arguments)
|
||||
{
|
||||
auto min_priority = sched_get_priority_min(0);
|
||||
auto max_priority = sched_get_priority_max(0);
|
||||
sched_param const under_priority_parameter { .sched_priority = min_priority - 1 };
|
||||
sched_param const over_priority_parameter { .sched_priority = max_priority + 1 };
|
||||
sched_param const min_priority_parameter { .sched_priority = min_priority };
|
||||
|
||||
// Set too high or too low priorities.
|
||||
auto rc = pthread_setschedparam(0, 0, &over_priority_parameter);
|
||||
EXPECT_EQ(rc, EINVAL);
|
||||
rc = pthread_setschedparam(0, 0, &under_priority_parameter);
|
||||
EXPECT_EQ(rc, EINVAL);
|
||||
|
||||
// Get and set a thread that doesn't exist.
|
||||
rc = pthread_setschedparam(-42069, 0, &min_priority_parameter);
|
||||
EXPECT_EQ(rc, ESRCH);
|
||||
sched_param output_parameter;
|
||||
rc = pthread_getschedparam(-42069, 0, &output_parameter);
|
||||
EXPECT_EQ(rc, ESRCH);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue