mirror of
https://github.com/systemd/systemd.git
synced 2025-03-21 02:50:18 +03:00
tests: use manager_load_startable_unit_or_warn() to load units
Doing manager_load_unit() followed by UNIT_VTABLE(unit)->start(unit) would result in an assertion failure in ->start() if the unit failed to load properly. Something like this is okey-ish is tests, since the test units are not expected to fail to load, but the reason for failure is clearer if we fail immediately.
This commit is contained in:
parent
4109ede778
commit
ba412430a9
@ -66,16 +66,11 @@ static int test_cgroup_mask(void) {
|
||||
assert_se(manager_startup(m, serial, fdset) >= 0);
|
||||
|
||||
/* Load units and verify hierarchy. */
|
||||
assert_se(manager_load_unit(m, "parent.slice", NULL, NULL, &parent) >= 0);
|
||||
assert_se(manager_load_unit(m, "son.service", NULL, NULL, &son) >= 0);
|
||||
assert_se(manager_load_unit(m, "daughter.service", NULL, NULL, &daughter) >= 0);
|
||||
assert_se(manager_load_unit(m, "grandchild.service", NULL, NULL, &grandchild) >= 0);
|
||||
assert_se(manager_load_unit(m, "parent-deep.slice", NULL, NULL, &parent_deep) >= 0);
|
||||
assert_se(parent->load_state == UNIT_LOADED);
|
||||
assert_se(son->load_state == UNIT_LOADED);
|
||||
assert_se(daughter->load_state == UNIT_LOADED);
|
||||
assert_se(grandchild->load_state == UNIT_LOADED);
|
||||
assert_se(parent_deep->load_state == UNIT_LOADED);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "parent.slice", NULL, &parent) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "son.service", NULL, &son) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "daughter.service", NULL, &daughter) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "grandchild.service", NULL, &grandchild) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "parent-deep.slice", NULL, &parent_deep) >= 0);
|
||||
assert_se(UNIT_DEREF(son->slice) == parent);
|
||||
assert_se(UNIT_DEREF(daughter->slice) == parent);
|
||||
assert_se(UNIT_DEREF(parent_deep->slice) == parent);
|
||||
|
@ -56,9 +56,9 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(manager_startup(m, serial, fdset) >= 0);
|
||||
|
||||
printf("Load1:\n");
|
||||
assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0);
|
||||
assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0);
|
||||
assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "a.service", NULL, &a) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "b.service", NULL, &b) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "c.service", NULL, &c) >= 0);
|
||||
manager_dump_units(m, stdout, "\t");
|
||||
|
||||
printf("Test1: (Trivial)\n");
|
||||
@ -70,8 +70,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
printf("Load2:\n");
|
||||
manager_clear_jobs(m);
|
||||
assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0);
|
||||
assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "d.service", NULL, &d) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "e.service", NULL, &e) >= 0);
|
||||
manager_dump_units(m, stdout, "\t");
|
||||
|
||||
printf("Test2: (Cyclic Order, Unfixable)\n");
|
||||
@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
|
||||
manager_dump_jobs(m, stdout, "\t");
|
||||
|
||||
printf("Load3:\n");
|
||||
assert_se(manager_load_unit(m, "g.service", NULL, NULL, &g) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "g.service", NULL, &g) >= 0);
|
||||
manager_dump_units(m, stdout, "\t");
|
||||
|
||||
printf("Test5: (Colliding transaction, fail)\n");
|
||||
@ -109,7 +109,7 @@ int main(int argc, char *argv[]) {
|
||||
manager_dump_jobs(m, stdout, "\t");
|
||||
|
||||
printf("Load4:\n");
|
||||
assert_se(manager_load_unit(m, "h.service", NULL, NULL, &h) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "h.service", NULL, &h) >= 0);
|
||||
manager_dump_units(m, stdout, "\t");
|
||||
|
||||
printf("Test10: (Unmergeable job type of auxiliary job, fail)\n");
|
||||
|
@ -145,7 +145,7 @@ static void test(Manager *m, const char *unit_name, int status_expected, int cod
|
||||
|
||||
assert_se(unit_name);
|
||||
|
||||
assert_se(manager_load_unit(m, unit_name, NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, unit_name, NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
check(m, unit, status_expected, code_expected);
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ static void test_path_exists(Manager *m) {
|
||||
|
||||
assert_se(m);
|
||||
|
||||
assert_se(manager_load_unit(m, "path-exists.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-exists.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
assert_se(touch(test_path) >= 0);
|
||||
@ -147,7 +147,7 @@ static void test_path_existsglob(Manager *m) {
|
||||
Unit *unit = NULL;
|
||||
|
||||
assert_se(m);
|
||||
assert_se(manager_load_unit(m, "path-existsglob.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-existsglob.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
assert_se(touch(test_path) >= 0);
|
||||
@ -164,7 +164,7 @@ static void test_path_changed(Manager *m) {
|
||||
|
||||
assert_se(touch(test_path) >= 0);
|
||||
|
||||
assert_se(manager_load_unit(m, "path-changed.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-changed.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
f = fopen(test_path, "w");
|
||||
@ -183,7 +183,7 @@ static void test_path_modified(Manager *m) {
|
||||
|
||||
assert_se(touch(test_path) >= 0);
|
||||
|
||||
assert_se(manager_load_unit(m, "path-modified.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-modified.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
f = fopen(test_path, "w");
|
||||
@ -199,7 +199,7 @@ static void test_path_unit(Manager *m) {
|
||||
|
||||
assert_se(m);
|
||||
|
||||
assert_se(manager_load_unit(m, "path-unit.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-unit.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
assert_se(touch(test_path) >= 0);
|
||||
@ -215,7 +215,7 @@ static void test_path_directorynotempty(Manager *m) {
|
||||
|
||||
assert_se(access(test_path, F_OK) < 0);
|
||||
|
||||
assert_se(manager_load_unit(m, "path-directorynotempty.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-directorynotempty.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
/* MakeDirectory default to no */
|
||||
@ -236,7 +236,7 @@ static void test_path_makedirectory_directorymode(Manager *m) {
|
||||
|
||||
assert_se(access(test_path, F_OK) < 0);
|
||||
|
||||
assert_se(manager_load_unit(m, "path-makedirectory.path", NULL, NULL, &unit) >= 0);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "path-makedirectory.path", NULL, &unit) >= 0);
|
||||
assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
|
||||
|
||||
/* Check if the directory has been created */
|
||||
|
@ -53,8 +53,7 @@ int main(int argc, char *argv[]) {
|
||||
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);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "sched_idle_ok.service", NULL, &idle_ok) >= 0);
|
||||
ser = SERVICE(idle_ok);
|
||||
assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
|
||||
assert_se(ser->exec_context.cpu_sched_priority == 0);
|
||||
@ -62,8 +61,7 @@ int main(int argc, char *argv[]) {
|
||||
/*
|
||||
* 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);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "sched_idle_bad.service", NULL, &idle_bad) >= 0);
|
||||
ser = SERVICE(idle_ok);
|
||||
assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
|
||||
assert_se(ser->exec_context.cpu_sched_priority == 0);
|
||||
@ -72,8 +70,7 @@ int main(int argc, char *argv[]) {
|
||||
* 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);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_ok.service", NULL, &rr_ok) >= 0);
|
||||
ser = SERVICE(rr_ok);
|
||||
assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
|
||||
assert_se(ser->exec_context.cpu_sched_priority == 1);
|
||||
@ -82,8 +79,7 @@ int main(int argc, char *argv[]) {
|
||||
* 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);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_bad.service", NULL, &rr_bad) >= 0);
|
||||
ser = SERVICE(rr_bad);
|
||||
assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
|
||||
assert_se(ser->exec_context.cpu_sched_priority == 1);
|
||||
@ -92,8 +88,7 @@ int main(int argc, char *argv[]) {
|
||||
* 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);
|
||||
assert_se(manager_load_startable_unit_or_warn(m, "sched_rr_change.service", NULL, &rr_sched) >= 0);
|
||||
ser = SERVICE(rr_sched);
|
||||
assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
|
||||
assert_se(ser->exec_context.cpu_sched_priority == 99);
|
||||
|
Loading…
x
Reference in New Issue
Block a user