]>
Commit | Line | Data |
---|---|---|
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 | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <sched.h> | |
22 | ||
49e5de64 | 23 | #include "macro.h" |
cf0fbc49 | 24 | #include "manager.h" |
d2120590 | 25 | #include "rm-rf.h" |
8b3aa503 | 26 | #include "test-helper.h" |
d2120590 | 27 | #include "tests.h" |
bb112710 HHPF |
28 | |
29 | int main(int argc, char *argv[]) { | |
f942504e | 30 | _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL; |
c70cac54 | 31 | _cleanup_(manager_freep) Manager *m = NULL; |
bb112710 HHPF |
32 | Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched; |
33 | Service *ser; | |
34 | FILE *serial = NULL; | |
35 | FDSet *fdset = NULL; | |
c5e33bf8 | 36 | int r; |
bb112710 | 37 | |
651d47d1 ZJS |
38 | r = enter_cgroup_subroot(); |
39 | if (r == -ENOMEDIUM) { | |
40 | log_notice_errno(r, "Skipping test: cgroupfs not available"); | |
41 | return EXIT_TEST_SKIP; | |
42 | } | |
8c759b33 | 43 | |
bb112710 | 44 | /* prepare the test */ |
cc100a5a | 45 | assert_se(set_unit_path(get_testdata_dir("")) >= 0); |
3e29e810 | 46 | assert_se(runtime_dir = setup_fake_runtime_dir()); |
e8112e67 | 47 | r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m); |
8b3aa503 | 48 | if (MANAGER_SKIP_TEST(r)) { |
9eec7d12 | 49 | log_notice_errno(r, "Skipping test: manager_new: %m"); |
49e5de64 | 50 | return EXIT_TEST_SKIP; |
c5e33bf8 | 51 | } |
bdf7026e | 52 | assert_se(r >= 0); |
bb112710 HHPF |
53 | assert_se(manager_startup(m, serial, fdset) >= 0); |
54 | ||
55 | /* load idle ok */ | |
56 | assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0); | |
57 | assert_se(idle_ok->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 idle bad. This should print a warning but we have no way to look at it. | |
64 | */ | |
65 | assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0); | |
66 | assert_se(idle_bad->load_state == UNIT_LOADED); | |
67 | ser = SERVICE(idle_ok); | |
68 | assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER); | |
69 | assert_se(ser->exec_context.cpu_sched_priority == 0); | |
70 | ||
71 | /* | |
72 | * load rr ok. | |
73 | * Test that the default priority is moving from 0 to 1. | |
74 | */ | |
75 | assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0); | |
76 | assert_se(rr_ok->load_state == UNIT_LOADED); | |
77 | ser = SERVICE(rr_ok); | |
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 bad. | |
83 | * Test that the value of 0 and 100 is ignored. | |
84 | */ | |
85 | assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0); | |
86 | assert_se(rr_bad->load_state == UNIT_LOADED); | |
87 | ser = SERVICE(rr_bad); | |
88 | assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR); | |
89 | assert_se(ser->exec_context.cpu_sched_priority == 1); | |
90 | ||
91 | /* | |
92 | * load rr change. | |
93 | * Test that anything between 1 and 99 can be set. | |
94 | */ | |
95 | assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0); | |
96 | assert_se(rr_sched->load_state == UNIT_LOADED); | |
97 | ser = SERVICE(rr_sched); | |
98 | assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR); | |
99 | assert_se(ser->exec_context.cpu_sched_priority == 99); | |
100 | ||
c5e33bf8 | 101 | return EXIT_SUCCESS; |
bb112710 | 102 | } |