diff options
author | Anita Zhang <the.anitazha@gmail.com> | 2019-06-28 17:02:30 -0700 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-17 11:35:02 +0200 |
commit | 31cd5f63ce86a0784c4ef869c4d323a11ff14adc (patch) | |
tree | 4762477054b47738120d76397e38a1703ad449da /src/test/test-execute.c | |
parent | cc2f3f05a77f34f867e2505eae0e67f056d28a15 (diff) | |
download | systemd-31cd5f63ce86a0784c4ef869c4d323a11ff14adc.tar.gz |
core: ExecCondition= for services
Closes #10596
Diffstat (limited to 'src/test/test-execute.c')
-rw-r--r-- | src/test/test-execute.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 5b3e6875d6..e308d75a56 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -39,7 +39,7 @@ static int cld_dumped_to_killed(int code) { return code == CLD_DUMPED ? CLD_KILLED : code; } -static void check(const char *func, Manager *m, Unit *unit, int status_expected, int code_expected) { +static void wait_for_service_finish(Manager *m, Unit *unit) { Service *service = NULL; usec_t ts; usec_t timeout = 2 * USEC_PER_MINUTE; @@ -67,6 +67,17 @@ static void check(const char *func, Manager *m, Unit *unit, int status_expected, exit(EXIT_FAILURE); } } +} + +static void check_main_result(const char *func, Manager *m, Unit *unit, int status_expected, int code_expected) { + Service *service = NULL; + + assert_se(m); + assert_se(unit); + + wait_for_service_finish(m, unit); + + service = SERVICE(unit); exec_status_dump(&service->main_exec_status, stdout, "\t"); if (cld_dumped_to_killed(service->main_exec_status.code) != cld_dumped_to_killed(code_expected)) { @@ -84,6 +95,25 @@ static void check(const char *func, Manager *m, Unit *unit, int status_expected, } } +static void check_service_result(const char *func, Manager *m, Unit *unit, ServiceResult result_expected) { + Service *service = NULL; + + assert_se(m); + assert_se(unit); + + wait_for_service_finish(m, unit); + + service = SERVICE(unit); + + if (service->result != result_expected) { + log_error("%s: %s: service end result %s, expected %s", + func, unit->id, + service_result_to_string(service->result), + service_result_to_string(result_expected)); + abort(); + } +} + static bool check_nobody_user_and_group(void) { static int cache = -1; struct passwd *p; @@ -173,7 +203,17 @@ static void test(const char *func, Manager *m, const char *unit_name, int status assert_se(manager_load_startable_unit_or_warn(m, unit_name, NULL, &unit) >= 0); assert_se(unit_start(unit) >= 0); - check(func, m, unit, status_expected, code_expected); + check_main_result(func, m, unit, status_expected, code_expected); +} + +static void test_service(const char *func, Manager *m, const char *unit_name, ServiceResult result_expected) { + Unit *unit; + + assert_se(unit_name); + + assert_se(manager_load_startable_unit_or_warn(m, unit_name, NULL, &unit) >= 0); + assert_se(unit_start(unit) >= 0); + check_service_result(func, m, unit, result_expected); } static void test_exec_bindpaths(Manager *m) { @@ -718,6 +758,11 @@ static void test_exec_standardoutput_append(Manager *m) { test(__func__, m, "exec-standardoutput-append.service", 0, CLD_EXITED); } +static void test_exec_condition(Manager *m) { + test_service(__func__, m, "exec-condition-failed.service", SERVICE_FAILURE_EXIT_CODE); + test_service(__func__, m, "exec-condition-skip.service", SERVICE_SKIP_CONDITION); +} + typedef struct test_entry { test_function_t f; const char *name; @@ -756,6 +801,7 @@ int main(int argc, char *argv[]) { entry(test_exec_ambientcapabilities), entry(test_exec_bindpaths), entry(test_exec_capabilityboundingset), + entry(test_exec_condition), entry(test_exec_cpuaffinity), entry(test_exec_environment), entry(test_exec_environmentfile), |