1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Holger Hans Peter Freyther
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 int main(int argc, char *argv[]) {
29 Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
35 /* prepare the test */
36 assert_se(set_unit_path(TEST_DIR) >= 0);
37 r = manager_new(SYSTEMD_USER, true, &m);
38 if (r == -EPERM || r == -EACCES || r == -EADDRINUSE || r == -EHOSTDOWN) {
39 printf("Skipping test: manager_new: %s", strerror(-r));
40 return EXIT_TEST_SKIP;
43 assert_se(manager_startup(m, serial, fdset) >= 0);
46 assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0);
47 assert_se(idle_ok->load_state == UNIT_LOADED);
48 ser = SERVICE(idle_ok);
49 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
50 assert_se(ser->exec_context.cpu_sched_priority == 0);
53 * load idle bad. This should print a warning but we have no way to look at it.
55 assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0);
56 assert_se(idle_bad->load_state == UNIT_LOADED);
57 ser = SERVICE(idle_ok);
58 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
59 assert_se(ser->exec_context.cpu_sched_priority == 0);
63 * Test that the default priority is moving from 0 to 1.
65 assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0);
66 assert_se(rr_ok->load_state == UNIT_LOADED);
68 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
69 assert_se(ser->exec_context.cpu_sched_priority == 1);
73 * Test that the value of 0 and 100 is ignored.
75 assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0);
76 assert_se(rr_bad->load_state == UNIT_LOADED);
77 ser = SERVICE(rr_bad);
78 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
79 assert_se(ser->exec_context.cpu_sched_priority == 1);
83 * Test that anything between 1 and 99 can be set.
85 assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0);
86 assert_se(rr_sched->load_state == UNIT_LOADED);
87 ser = SERVICE(rr_sched);
88 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
89 assert_se(ser->exec_context.cpu_sched_priority == 99);