From: Yu Watanabe Date: Wed, 27 May 2026 14:29:31 +0000 (+0900) Subject: test-path: drop PATH_TEST() macro X-Git-Tag: v261-rc3~57^2~3 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=bd6b38d74edfae4ecac0ceeca326cdac4a00db27;p=thirdparty%2Fsystemd.git test-path: drop PATH_TEST() macro The macro was introduced by fc7a32df38dd4797ce7266df6ece6bd9b9842783, but unfortunately gcc/gcov/lcov are confused by the macro: ``` lcov: ERROR: lcov: ERROR: (inconsistent) mismatched end line for test_path_exists_body at /home/runner/work/systemd/systemd/src/test/test-path.c:158: 158 -> 185 while capturing from build/mkosi.builddir/arch~rolling~x86-64/test-path.p/src_test_test-path.c.gcno (use "lcov --ignore-errors inconsistent ..." to bypass this error) ``` The macro deos nothing spurious, hence it should be a bug in gcc. But, the macro just reduces the lines for calling setup_test(), and does not simplify test cases so much. Let's call it in each test cases, and stop using the macro. --- diff --git a/src/test/test-path.c b/src/test/test-path.c index 52b9d75f601..69b51db0bfe 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -66,19 +66,6 @@ static Service *service_for_path(Manager *m, Path *path, const char *service_nam 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, @@ -155,16 +142,20 @@ static int _check_states( 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); @@ -184,16 +175,20 @@ PATH_TEST(path_exists) { 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); @@ -213,17 +208,20 @@ PATH_TEST(path_existsglob) { 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); @@ -235,8 +233,7 @@ PATH_TEST(path_changed) { 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); @@ -248,17 +245,20 @@ PATH_TEST(path_changed) { 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); @@ -270,7 +270,7 @@ PATH_TEST(path_modified) { 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); @@ -283,16 +283,20 @@ PATH_TEST(path_modified) { 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); @@ -308,16 +312,20 @@ PATH_TEST(path_unit) { 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)); @@ -344,11 +352,16 @@ PATH_TEST(path_directorynotempty) { 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)); @@ -359,6 +372,7 @@ PATH_TEST(path_makedirectory_directorymode) { 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);