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