]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-sched-prio.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / test / test-sched-prio.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2012 Holger Hans Peter Freyther
4 ***/
5
6 #include <sched.h>
7
8 #include "all-units.h"
9 #include "macro.h"
10 #include "manager.h"
11 #include "rm-rf.h"
12 #include "test-helper.h"
13 #include "tests.h"
14
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;
19 Service *ser;
20 FILE *serial = NULL;
21 FDSet *fdset = NULL;
22 int r;
23
24 r = enter_cgroup_subroot();
25 if (r == -ENOMEDIUM) {
26 log_notice_errno(r, "Skipping test: cgroupfs not available");
27 return EXIT_TEST_SKIP;
28 }
29
30 /* prepare the test */
31 assert_se(set_unit_path(get_testdata_dir("")) >= 0);
32 assert_se(runtime_dir = setup_fake_runtime_dir());
33 r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
34 if (MANAGER_SKIP_TEST(r)) {
35 log_notice_errno(r, "Skipping test: manager_new: %m");
36 return EXIT_TEST_SKIP;
37 }
38 assert_se(r >= 0);
39 assert_se(manager_startup(m, serial, fdset) >= 0);
40
41 /* load idle ok */
42 assert_se(manager_load_startable_unit_or_warn(m, "sched_idle_ok.service", NULL, &idle_ok) >= 0);
43 ser = SERVICE(idle_ok);
44 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
45 assert_se(ser->exec_context.cpu_sched_priority == 0);
46
47 /*
48 * load idle bad. This should print a warning but we have no way to look at it.
49 */
50 assert_se(manager_load_startable_unit_or_warn(m, "sched_idle_bad.service", NULL, &idle_bad) >= 0);
51 ser = SERVICE(idle_ok);
52 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
53 assert_se(ser->exec_context.cpu_sched_priority == 0);
54
55 /*
56 * load rr ok.
57 * Test that the default priority is moving from 0 to 1.
58 */
59 assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_ok.service", NULL, &rr_ok) >= 0);
60 ser = SERVICE(rr_ok);
61 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
62 assert_se(ser->exec_context.cpu_sched_priority == 1);
63
64 /*
65 * load rr bad.
66 * Test that the value of 0 and 100 is ignored.
67 */
68 assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_bad.service", NULL, &rr_bad) >= 0);
69 ser = SERVICE(rr_bad);
70 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
71 assert_se(ser->exec_context.cpu_sched_priority == 1);
72
73 /*
74 * load rr change.
75 * Test that anything between 1 and 99 can be set.
76 */
77 assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_change.service", NULL, &rr_sched) >= 0);
78 ser = SERVICE(rr_sched);
79 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
80 assert_se(ser->exec_context.cpu_sched_priority == 99);
81
82 return EXIT_SUCCESS;
83 }