2012-11-01 18:48:11 +01:00
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2012 Holger Hans Peter Freyther
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <sched.h>
|
|
|
|
|
2013-03-27 02:07:46 +01:00
|
|
|
#include "macro.h"
|
2015-11-16 22:09:36 +01:00
|
|
|
#include "manager.h"
|
2015-12-02 04:35:16 +01:00
|
|
|
#include "test-helper.h"
|
2012-11-01 18:48:11 +01:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2014-02-19 17:47:11 +01:00
|
|
|
Manager *m = NULL;
|
2012-11-01 18:48:11 +01:00
|
|
|
Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
|
|
|
|
Service *ser;
|
|
|
|
FILE *serial = NULL;
|
|
|
|
FDSet *fdset = NULL;
|
2013-02-06 23:35:53 +01:00
|
|
|
int r;
|
2012-11-01 18:48:11 +01:00
|
|
|
|
|
|
|
/* prepare the test */
|
2014-01-07 14:41:24 +01:00
|
|
|
assert_se(set_unit_path(TEST_DIR) >= 0);
|
2016-02-24 21:24:23 +01:00
|
|
|
r = manager_new(UNIT_FILE_USER, true, &m);
|
2015-12-02 04:35:16 +01:00
|
|
|
if (MANAGER_SKIP_TEST(r)) {
|
2015-12-02 05:44:27 +01:00
|
|
|
printf("Skipping test: manager_new: %s\n", strerror(-r));
|
2013-03-27 02:07:46 +01:00
|
|
|
return EXIT_TEST_SKIP;
|
2013-02-06 23:35:53 +01:00
|
|
|
}
|
2014-10-04 23:51:45 +02:00
|
|
|
assert_se(r >= 0);
|
2012-11-01 18:48:11 +01:00
|
|
|
assert_se(manager_startup(m, serial, fdset) >= 0);
|
|
|
|
|
|
|
|
/* load idle ok */
|
|
|
|
assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0);
|
|
|
|
assert_se(idle_ok->load_state == UNIT_LOADED);
|
|
|
|
ser = SERVICE(idle_ok);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_priority == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load idle bad. This should print a warning but we have no way to look at it.
|
|
|
|
*/
|
|
|
|
assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0);
|
|
|
|
assert_se(idle_bad->load_state == UNIT_LOADED);
|
|
|
|
ser = SERVICE(idle_ok);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_priority == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load rr ok.
|
|
|
|
* Test that the default priority is moving from 0 to 1.
|
|
|
|
*/
|
|
|
|
assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0);
|
|
|
|
assert_se(rr_ok->load_state == UNIT_LOADED);
|
|
|
|
ser = SERVICE(rr_ok);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_priority == 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load rr bad.
|
|
|
|
* Test that the value of 0 and 100 is ignored.
|
|
|
|
*/
|
|
|
|
assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0);
|
|
|
|
assert_se(rr_bad->load_state == UNIT_LOADED);
|
|
|
|
ser = SERVICE(rr_bad);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_priority == 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load rr change.
|
|
|
|
* Test that anything between 1 and 99 can be set.
|
|
|
|
*/
|
|
|
|
assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0);
|
|
|
|
assert_se(rr_sched->load_state == UNIT_LOADED);
|
|
|
|
ser = SERVICE(rr_sched);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
|
|
|
|
assert_se(ser->exec_context.cpu_sched_priority == 99);
|
|
|
|
|
2013-07-12 14:04:39 +02:00
|
|
|
manager_free(m);
|
|
|
|
|
2013-02-06 23:35:53 +01:00
|
|
|
return EXIT_SUCCESS;
|
2012-11-01 18:48:11 +01:00
|
|
|
}
|