return SERVICE(service_unit);
}
-/* Define a test that gets a freshly-initialized Manager passed as `m`. The body returns 0 on
- * success or EXIT_TEST_SKIP to skip; the wrapper hands the value back to the test framework. */
-#define PATH_TEST(name) \
- static int test_##name##_body(Manager *m); \
- TEST_RET(name) { \
- _cleanup_(manager_freep) Manager *m = NULL; \
- int r = setup_test(&m); \
- if (r != 0) \
- return r; \
- return test_##name##_body(m); \
- } \
- static int test_##name##_body(Manager *m)
-
static int _check_states(
unsigned line,
Manager *m,
return _r; \
} while (0)
-PATH_TEST(path_exists) {
+TEST_RET(path_exists) {
const char *test_path = "/tmp/test-path_exists";
- Unit *unit = NULL;
- Path *path = NULL;
- Service *service = NULL;
+ int r;
+
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-exists.path", NULL, &unit));
- path = PATH(unit);
- service = service_for_path(m, path, NULL);
+ Path *path = PATH(unit);
+ Service *service = service_for_path(m, path, NULL);
ASSERT_OK(unit_start(unit, NULL));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
return 0;
}
-PATH_TEST(path_existsglob) {
+TEST_RET(path_existsglob) {
const char *test_path = "/tmp/test-path_existsglobFOOBAR";
- Unit *unit = NULL;
- Path *path = NULL;
- Service *service = NULL;
+ int r;
+
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-existsglob.path", NULL, &unit));
- path = PATH(unit);
- service = service_for_path(m, path, NULL);
+ Path *path = PATH(unit);
+ Service *service = service_for_path(m, path, NULL);
ASSERT_OK(unit_start(unit, NULL));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
return 0;
}
-PATH_TEST(path_changed) {
+TEST_RET(path_changed) {
const char *test_path = "/tmp/test-path_changed";
- FILE *f;
- Unit *unit = NULL;
- Path *path = NULL;
- Service *service = NULL;
+ int r;
+
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-changed.path", NULL, &unit));
- path = PATH(unit);
- service = service_for_path(m, path, NULL);
+ Path *path = PATH(unit);
+ Service *service = service_for_path(m, path, NULL);
ASSERT_OK(unit_start(unit, NULL));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
ASSERT_OK(unit_stop(UNIT(service)));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
- f = ASSERT_NOT_NULL(fopen(test_path, "w"));
- fclose(f);
+ fclose(ASSERT_NOT_NULL(fopen(test_path, "w")));
check_states(m, path, service, PATH_RUNNING, SERVICE_RUNNING);
return 0;
}
-PATH_TEST(path_modified) {
- _cleanup_fclose_ FILE *f = NULL;
+TEST_RET(path_modified) {
const char *test_path = "/tmp/test-path_modified";
- Unit *unit = NULL;
- Path *path = NULL;
- Service *service = NULL;
+ int r;
+
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-modified.path", NULL, &unit));
- path = PATH(unit);
- service = service_for_path(m, path, NULL);
+ Path *path = PATH(unit);
+ Service *service = service_for_path(m, path, NULL);
ASSERT_OK(unit_start(unit, NULL));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
ASSERT_OK(unit_stop(UNIT(service)));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
- f = ASSERT_NOT_NULL(fopen(test_path, "w"));
+ _cleanup_fclose_ FILE *f = ASSERT_NOT_NULL(fopen(test_path, "w"));
fputs("test", f);
check_states(m, path, service, PATH_RUNNING, SERVICE_RUNNING);
return 0;
}
-PATH_TEST(path_unit) {
+TEST_RET(path_unit) {
const char *test_path = "/tmp/test-path_unit";
- Unit *unit = NULL;
- Path *path = NULL;
- Service *service = NULL;
+ int r;
+
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-unit.path", NULL, &unit));
- path = PATH(unit);
- service = service_for_path(m, path, "path-mycustomunit.service");
+ Path *path = PATH(unit);
+ Service *service = service_for_path(m, path, "path-mycustomunit.service");
ASSERT_OK(unit_start(unit, NULL));
check_states(m, path, service, PATH_WAITING, SERVICE_DEAD);
return 0;
}
-PATH_TEST(path_directorynotempty) {
+TEST_RET(path_directorynotempty) {
const char *test_file, *test_path = "/tmp/test-path_directorynotempty/";
- Unit *unit = NULL;
- Path *path = NULL;
- Service *service = NULL;
+ int r;
+
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-directorynotempty.path", NULL, &unit));
- path = PATH(unit);
- service = service_for_path(m, path, NULL);
+ Path *path = PATH(unit);
+ Service *service = service_for_path(m, path, NULL);
ASSERT_FAIL(access(test_path, F_OK));
return 0;
}
-PATH_TEST(path_makedirectory_directorymode) {
+TEST_RET(path_makedirectory_directorymode) {
const char *test_path = "/tmp/test-path_makedirectory/";
- Unit *unit = NULL;
- struct stat s;
+ int r;
+ _cleanup_(manager_freep) Manager *m = NULL;
+ r = setup_test(&m);
+ if (r != 0)
+ return r;
+
+ Unit *unit;
ASSERT_OK(manager_load_startable_unit_or_warn(m, "path-makedirectory.path", NULL, &unit));
ASSERT_FAIL(access(test_path, F_OK));
ASSERT_OK_ERRNO(access(test_path, F_OK));
/* Check the mode we specified with DirectoryMode=0744 */
+ struct stat s;
ASSERT_OK_ERRNO(stat(test_path, &s));
ASSERT_EQ((mode_t) (s.st_mode & S_IRWXU), (mode_t) 0700);
ASSERT_EQ((mode_t) (s.st_mode & S_IRWXG), (mode_t) 0040);