]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-sched-prio.c
tests: skip bus test if bus cannot be opened
[thirdparty/systemd.git] / src / test / test-sched-prio.c
CommitLineData
bb112710
HHPF
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2012 Holger Hans Peter Freyther
7
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.
12
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.
17
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/>.
20***/
21
22#include <sched.h>
23
24#include "manager.h"
49e5de64 25#include "macro.h"
bb112710
HHPF
26
27int main(int argc, char *argv[]) {
28 Manager *m;
29 Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
30 Service *ser;
31 FILE *serial = NULL;
32 FDSet *fdset = NULL;
c5e33bf8 33 int r;
bb112710
HHPF
34
35 /* prepare the test */
36 assert_se(set_unit_path(TEST_DIR) >= 0);
c5e33bf8
ZJS
37 r = manager_new(SYSTEMD_USER, &m);
38 if (r == -EPERM) {
39 puts("manager_new: Permission denied. Skipping test.");
49e5de64 40 return EXIT_TEST_SKIP;
c5e33bf8
ZJS
41 }
42 assert(r >= 0);
bb112710
HHPF
43 assert_se(manager_startup(m, serial, fdset) >= 0);
44
45 /* load idle ok */
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);
51
52 /*
53 * load idle bad. This should print a warning but we have no way to look at it.
54 */
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);
60
61 /*
62 * load rr ok.
63 * Test that the default priority is moving from 0 to 1.
64 */
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);
67 ser = SERVICE(rr_ok);
68 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
69 assert_se(ser->exec_context.cpu_sched_priority == 1);
70
71 /*
72 * load rr bad.
73 * Test that the value of 0 and 100 is ignored.
74 */
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);
80
81 /*
82 * load rr change.
83 * Test that anything between 1 and 99 can be set.
84 */
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);
90
c5e33bf8 91 return EXIT_SUCCESS;
bb112710 92}