aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/nice_ut.cpp
blob: 5a49c0355a2599185cc59344bf959ae1def64572 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "nice.h"

#include "platform.h"

#include <library/cpp/testing/unittest/registar.h> 

#ifdef _unix_
    #include <sys/resource.h>

static int GetPriority() {
    return getpriority(PRIO_PROCESS, 0);
}
#endif

Y_UNIT_TEST_SUITE(NiceTest) {
    Y_UNIT_TEST(TestNiceZero) {
        UNIT_ASSERT(Nice(0));
        UNIT_ASSERT(Nice(0));
    }
#ifdef _unix_
    Y_UNIT_TEST(TestNice) {
        int prio = GetPriority();

        if (prio >= 10) {
            return;
        }

        if (Nice(-2)) {
            UNIT_ASSERT_VALUES_EQUAL(GetPriority(), prio - 2);
            prio -= 2;
        } else {
            UNIT_ASSERT_VALUES_EQUAL(GetPriority(), prio);
        }
        UNIT_ASSERT(Nice(1));
        UNIT_ASSERT_VALUES_EQUAL(GetPriority(), prio + 1);
        UNIT_ASSERT(Nice(0));
        UNIT_ASSERT_VALUES_EQUAL(GetPriority(), prio + 1);
        UNIT_ASSERT(Nice(2));
        UNIT_ASSERT_VALUES_EQUAL(GetPriority(), prio + 3);
    }
#endif
}