Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : : /*** 3 : : Copyright © 2012 Holger Hans Peter Freyther 4 : : ***/ 5 : : 6 : : #include <sched.h> 7 : : 8 : : #include "all-units.h" 9 : : #include "macro.h" 10 : : #include "manager.h" 11 : : #include "rm-rf.h" 12 : : #include "test-helper.h" 13 : : #include "tests.h" 14 : : 15 : 4 : int main(int argc, char *argv[]) { 16 : 4 : _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL; 17 : 4 : _cleanup_(manager_freep) Manager *m = NULL; 18 : : Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched; 19 : : Service *ser; 20 : : int r; 21 : : 22 : 4 : test_setup_logging(LOG_INFO); 23 : : 24 : 4 : r = enter_cgroup_subroot(); 25 [ - + ]: 4 : if (r == -ENOMEDIUM) 26 : 0 : return log_tests_skipped("cgroupfs not available"); 27 : : 28 : : /* prepare the test */ 29 [ - + ]: 4 : assert_se(set_unit_path(get_testdata_dir()) >= 0); 30 [ - + ]: 4 : assert_se(runtime_dir = setup_fake_runtime_dir()); 31 : 4 : r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m); 32 [ - + - + ]: 4 : if (MANAGER_SKIP_TEST(r)) 33 : 0 : return log_tests_skipped_errno(r, "manager_new"); 34 [ - + ]: 4 : assert_se(r >= 0); 35 [ - + ]: 4 : assert_se(manager_startup(m, NULL, NULL) >= 0); 36 : : 37 : : /* load idle ok */ 38 [ - + ]: 4 : assert_se(manager_load_startable_unit_or_warn(m, "sched_idle_ok.service", NULL, &idle_ok) >= 0); 39 : 4 : ser = SERVICE(idle_ok); 40 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER); 41 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_priority == 0); 42 : : 43 : : /* 44 : : * load idle bad. This should print a warning but we have no way to look at it. 45 : : */ 46 [ - + ]: 4 : assert_se(manager_load_startable_unit_or_warn(m, "sched_idle_bad.service", NULL, &idle_bad) >= 0); 47 : 4 : ser = SERVICE(idle_ok); 48 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER); 49 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_priority == 0); 50 : : 51 : : /* 52 : : * load rr ok. 53 : : * Test that the default priority is moving from 0 to 1. 54 : : */ 55 [ - + ]: 4 : assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_ok.service", NULL, &rr_ok) >= 0); 56 : 4 : ser = SERVICE(rr_ok); 57 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR); 58 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_priority == 1); 59 : : 60 : : /* 61 : : * load rr bad. 62 : : * Test that the value of 0 and 100 is ignored. 63 : : */ 64 [ - + ]: 4 : assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_bad.service", NULL, &rr_bad) >= 0); 65 : 4 : ser = SERVICE(rr_bad); 66 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR); 67 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_priority == 1); 68 : : 69 : : /* 70 : : * load rr change. 71 : : * Test that anything between 1 and 99 can be set. 72 : : */ 73 [ - + ]: 4 : assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_change.service", NULL, &rr_sched) >= 0); 74 : 4 : ser = SERVICE(rr_sched); 75 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR); 76 [ - + ]: 4 : assert_se(ser->exec_context.cpu_sched_priority == 99); 77 : : 78 : 4 : return EXIT_SUCCESS; 79 : : }