]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-sched-prio.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
12 #include "test-helper.h"
15 int main(int argc
, char *argv
[]) {
16 _cleanup_(rm_rf_physical_and_freep
) char *runtime_dir
= NULL
;
17 _cleanup_(manager_freep
) Manager
*m
= NULL
;
18 Unit
*idle_ok
, *idle_bad
, *rr_ok
, *rr_bad
, *rr_sched
;
22 test_setup_logging(LOG_INFO
);
24 r
= enter_cgroup_subroot();
26 return log_tests_skipped("cgroupfs not available");
28 /* prepare the test */
29 assert_se(set_unit_path(get_testdata_dir()) >= 0);
30 assert_se(runtime_dir
= setup_fake_runtime_dir());
31 r
= manager_new(UNIT_FILE_USER
, MANAGER_TEST_RUN_BASIC
, &m
);
32 if (MANAGER_SKIP_TEST(r
))
33 return log_tests_skipped_errno(r
, "manager_new");
35 assert_se(manager_startup(m
, NULL
, NULL
) >= 0);
38 assert_se(manager_load_startable_unit_or_warn(m
, "sched_idle_ok.service", NULL
, &idle_ok
) >= 0);
39 ser
= SERVICE(idle_ok
);
40 assert_se(ser
->exec_context
.cpu_sched_policy
== SCHED_OTHER
);
41 assert_se(ser
->exec_context
.cpu_sched_priority
== 0);
44 * load idle bad. This should print a warning but we have no way to look at it.
46 assert_se(manager_load_startable_unit_or_warn(m
, "sched_idle_bad.service", NULL
, &idle_bad
) >= 0);
47 ser
= SERVICE(idle_ok
);
48 assert_se(ser
->exec_context
.cpu_sched_policy
== SCHED_OTHER
);
49 assert_se(ser
->exec_context
.cpu_sched_priority
== 0);
53 * Test that the default priority is moving from 0 to 1.
55 assert_se(manager_load_startable_unit_or_warn(m
, "sched_rr_ok.service", NULL
, &rr_ok
) >= 0);
57 assert_se(ser
->exec_context
.cpu_sched_policy
== SCHED_RR
);
58 assert_se(ser
->exec_context
.cpu_sched_priority
== 1);
62 * Test that the value of 0 and 100 is ignored.
64 assert_se(manager_load_startable_unit_or_warn(m
, "sched_rr_bad.service", NULL
, &rr_bad
) >= 0);
65 ser
= SERVICE(rr_bad
);
66 assert_se(ser
->exec_context
.cpu_sched_policy
== SCHED_RR
);
67 assert_se(ser
->exec_context
.cpu_sched_priority
== 1);
71 * Test that anything between 1 and 99 can be set.
73 assert_se(manager_load_startable_unit_or_warn(m
, "sched_rr_change.service", NULL
, &rr_sched
) >= 0);
74 ser
= SERVICE(rr_sched
);
75 assert_se(ser
->exec_context
.cpu_sched_policy
== SCHED_RR
);
76 assert_se(ser
->exec_context
.cpu_sched_priority
== 99);