]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-sched-prio.c
core: remove ManagerRunningAs enum
[thirdparty/systemd.git] / src / test / test-sched-prio.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2012 Holger Hans Peter Freyther
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <sched.h>
21
22 #include "macro.h"
23 #include "manager.h"
24 #include "test-helper.h"
25
26 int main(int argc, char *argv[]) {
27 Manager *m = NULL;
28 Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
29 Service *ser;
30 FILE *serial = NULL;
31 FDSet *fdset = NULL;
32 int r;
33
34 /* prepare the test */
35 assert_se(set_unit_path(TEST_DIR) >= 0);
36 r = manager_new(UNIT_FILE_USER, true, &m);
37 if (MANAGER_SKIP_TEST(r)) {
38 printf("Skipping test: manager_new: %s\n", strerror(-r));
39 return EXIT_TEST_SKIP;
40 }
41 assert_se(r >= 0);
42 assert_se(manager_startup(m, serial, fdset) >= 0);
43
44 /* load idle ok */
45 assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0);
46 assert_se(idle_ok->load_state == UNIT_LOADED);
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);
50
51 /*
52 * load idle bad. This should print a warning but we have no way to look at it.
53 */
54 assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0);
55 assert_se(idle_bad->load_state == UNIT_LOADED);
56 ser = SERVICE(idle_ok);
57 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
58 assert_se(ser->exec_context.cpu_sched_priority == 0);
59
60 /*
61 * load rr ok.
62 * Test that the default priority is moving from 0 to 1.
63 */
64 assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0);
65 assert_se(rr_ok->load_state == UNIT_LOADED);
66 ser = SERVICE(rr_ok);
67 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
68 assert_se(ser->exec_context.cpu_sched_priority == 1);
69
70 /*
71 * load rr bad.
72 * Test that the value of 0 and 100 is ignored.
73 */
74 assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0);
75 assert_se(rr_bad->load_state == UNIT_LOADED);
76 ser = SERVICE(rr_bad);
77 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
78 assert_se(ser->exec_context.cpu_sched_priority == 1);
79
80 /*
81 * load rr change.
82 * Test that anything between 1 and 99 can be set.
83 */
84 assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0);
85 assert_se(rr_sched->load_state == UNIT_LOADED);
86 ser = SERVICE(rr_sched);
87 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
88 assert_se(ser->exec_context.cpu_sched_priority == 99);
89
90 manager_free(m);
91
92 return EXIT_SUCCESS;
93 }