]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-sched-prio.c
tests: turn check if manager cannot be intialized into macro
[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
49e5de64 24#include "macro.h"
cf0fbc49 25#include "manager.h"
8b3aa503 26#include "test-helper.h"
bb112710
HHPF
27
28int main(int argc, char *argv[]) {
39883f62 29 Manager *m = NULL;
bb112710
HHPF
30 Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
31 Service *ser;
32 FILE *serial = NULL;
33 FDSet *fdset = NULL;
c5e33bf8 34 int r;
bb112710
HHPF
35
36 /* prepare the test */
0d8c31ff 37 assert_se(set_unit_path(TEST_DIR) >= 0);
b2c23da8 38 r = manager_new(MANAGER_USER, true, &m);
8b3aa503 39 if (MANAGER_SKIP_TEST(r)) {
254ed85a 40 printf("Skipping test: manager_new: %s", strerror(-r));
49e5de64 41 return EXIT_TEST_SKIP;
c5e33bf8 42 }
bdf7026e 43 assert_se(r >= 0);
bb112710
HHPF
44 assert_se(manager_startup(m, serial, fdset) >= 0);
45
46 /* load idle ok */
47 assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0);
48 assert_se(idle_ok->load_state == UNIT_LOADED);
49 ser = SERVICE(idle_ok);
50 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
51 assert_se(ser->exec_context.cpu_sched_priority == 0);
52
53 /*
54 * load idle bad. This should print a warning but we have no way to look at it.
55 */
56 assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0);
57 assert_se(idle_bad->load_state == UNIT_LOADED);
58 ser = SERVICE(idle_ok);
59 assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
60 assert_se(ser->exec_context.cpu_sched_priority == 0);
61
62 /*
63 * load rr ok.
64 * Test that the default priority is moving from 0 to 1.
65 */
66 assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0);
67 assert_se(rr_ok->load_state == UNIT_LOADED);
68 ser = SERVICE(rr_ok);
69 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
70 assert_se(ser->exec_context.cpu_sched_priority == 1);
71
72 /*
73 * load rr bad.
74 * Test that the value of 0 and 100 is ignored.
75 */
76 assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0);
77 assert_se(rr_bad->load_state == UNIT_LOADED);
78 ser = SERVICE(rr_bad);
79 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
80 assert_se(ser->exec_context.cpu_sched_priority == 1);
81
82 /*
83 * load rr change.
84 * Test that anything between 1 and 99 can be set.
85 */
86 assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0);
87 assert_se(rr_sched->load_state == UNIT_LOADED);
88 ser = SERVICE(rr_sched);
89 assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
90 assert_se(ser->exec_context.cpu_sched_priority == 99);
91
b463b813
ZJS
92 manager_free(m);
93
c5e33bf8 94 return EXIT_SUCCESS;
bb112710 95}