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