]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/darwintests/xnu_quick_test_getsetpriority.c
xnu-4570.51.1.tar.gz
[apple/xnu.git] / tools / tests / darwintests / xnu_quick_test_getsetpriority.c
CommitLineData
a39ff7e2
A
1#include <darwintest.h>
2
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/stat.h>
6#include <sys/wait.h>
7
8T_GLOBAL_META(T_META_NAMESPACE("xnu.quicktest"), T_META_CHECK_LEAKS(false));
9
10T_DECL(getpriority_setpriority, "Tests getpriority and setpriority system calls", T_META_ASROOT(true))
11{
12 int my_priority;
13 int my_new_priority;
14
15 /* getpriority returns scheduling priority so -1 is a valid value */
16 errno = 0;
17 my_priority = getpriority(PRIO_PROCESS, 0);
18
19 T_WITH_ERRNO;
20 T_ASSERT_FALSE(my_priority == -1 && errno != 0, "Verify getpriority is successful", NULL);
21
22 /* change scheduling priority*/
23 my_new_priority = (my_priority == PRIO_MIN) ? (my_priority + 10) : (PRIO_MIN);
24
25 T_WITH_ERRNO;
26 T_ASSERT_POSIX_SUCCESS(setpriority(PRIO_PROCESS, 0, my_new_priority), "Change scheduling priority", NULL);
27
28 /* verify change */
29 errno = 0;
30 my_priority = getpriority(PRIO_PROCESS, 0);
31 T_WITH_ERRNO;
32 T_ASSERT_FALSE(my_priority == -1 && errno != 0, "Verify getpriority change is successful", NULL);
33
34 T_WITH_ERRNO;
35 T_ASSERT_EQ(my_priority, my_new_priority, "Verify setpriority correctly set scheduling priority", NULL);
36
37 /* reset scheduling priority */
38 T_WITH_ERRNO;
39 T_ASSERT_POSIX_SUCCESS(setpriority(PRIO_PROCESS, 0, 0), "Reset scheduling priority", NULL);
40}