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