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