committed by
Lennart Poettering
parent
cc2f3f05a7
commit
31cd5f63ce
+48
-2
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user