summaryrefslogtreecommitdiff
path: root/src/test/test-path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-path.c')
-rw-r--r--src/test/test-path.c42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 209eb2e366..07a0e413ee 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -12,6 +12,7 @@
#include "macro.h"
#include "manager.h"
#include "mkdir.h"
+#include "path-util.h"
#include "rm-rf.h"
#include "string-util.h"
#include "strv.h"
@@ -32,16 +33,12 @@ static int setup_test(Manager **m) {
assert_se(m);
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice_errno(r, "Skipping test: cgroupfs not available");
- return -EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &tmp);
- if (MANAGER_SKIP_TEST(r)) {
- log_notice_errno(r, "Skipping test: manager_new: %m");
- return -EXIT_TEST_SKIP;
- }
+ if (MANAGER_SKIP_TEST(r))
+ return log_tests_skipped_errno(r, "manager_new");
assert_se(r >= 0);
assert_se(manager_startup(tmp, NULL, NULL) >= 0);
@@ -106,7 +103,7 @@ static void check_stop_unlink(Manager *m, Unit *unit, const char *test_path, con
}
}
- assert_se(UNIT_VTABLE(unit)->stop(unit) >= 0);
+ assert_se(unit_stop(unit) >= 0);
(void) rm_rf(test_path, REMOVE_ROOT|REMOVE_PHYSICAL);
}
@@ -117,7 +114,7 @@ static void test_path_exists(Manager *m) {
assert_se(m);
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(unit_start(unit) >= 0);
assert_se(touch(test_path) >= 0);
@@ -130,7 +127,7 @@ static void test_path_existsglob(Manager *m) {
assert_se(m);
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(unit_start(unit) >= 0);
assert_se(touch(test_path) >= 0);
@@ -147,7 +144,7 @@ static void test_path_changed(Manager *m) {
assert_se(touch(test_path) >= 0);
assert_se(manager_load_startable_unit_or_warn(m, "path-changed.path", NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
+ assert_se(unit_start(unit) >= 0);
f = fopen(test_path, "w");
assert_se(f);
@@ -166,7 +163,7 @@ static void test_path_modified(Manager *m) {
assert_se(touch(test_path) >= 0);
assert_se(manager_load_startable_unit_or_warn(m, "path-modified.path", NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
+ assert_se(unit_start(unit) >= 0);
f = fopen(test_path, "w");
assert_se(f);
@@ -182,7 +179,7 @@ static void test_path_unit(Manager *m) {
assert_se(m);
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(unit_start(unit) >= 0);
assert_se(touch(test_path) >= 0);
@@ -198,7 +195,7 @@ static void test_path_directorynotempty(Manager *m) {
assert_se(access(test_path, F_OK) < 0);
assert_se(manager_load_startable_unit_or_warn(m, "path-directorynotempty.path", NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
+ assert_se(unit_start(unit) >= 0);
/* MakeDirectory default to no */
assert_se(access(test_path, F_OK) < 0);
@@ -219,7 +216,7 @@ static void test_path_makedirectory_directorymode(Manager *m) {
assert_se(access(test_path, F_OK) < 0);
assert_se(manager_load_startable_unit_or_warn(m, "path-makedirectory.path", NULL, &unit) >= 0);
- assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
+ assert_se(unit_start(unit) >= 0);
/* Check if the directory has been created */
assert_se(access(test_path, F_OK) >= 0);
@@ -230,7 +227,7 @@ static void test_path_makedirectory_directorymode(Manager *m) {
assert_se((s.st_mode & S_IRWXG) == 0040);
assert_se((s.st_mode & S_IRWXO) == 0004);
- assert_se(UNIT_VTABLE(unit)->stop(unit) >= 0);
+ assert_se(unit_stop(unit) >= 0);
(void) rm_rf(test_path, REMOVE_ROOT|REMOVE_PHYSICAL);
}
@@ -247,15 +244,16 @@ int main(int argc, char *argv[]) {
};
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
+ _cleanup_free_ char *test_path = NULL;
const test_function_t *test = NULL;
Manager *m = NULL;
umask(022);
- log_parse_environment();
- log_open();
+ test_setup_logging(LOG_INFO);
- assert_se(set_unit_path(get_testdata_dir("/test-path")) >= 0);
+ test_path = path_join(get_testdata_dir(), "test-path");
+ assert_se(set_unit_path(test_path) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
for (test = tests; test && *test; test++) {
@@ -263,8 +261,8 @@ int main(int argc, char *argv[]) {
/* We create a clean environment for each test */
r = setup_test(&m);
- if (r < 0)
- return -r;
+ if (r != 0)
+ return r;
(*test)(m);