From 0e3e424261fc432a1da730c5ebf5893f5ecc38fb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 15 Mar 2025 06:48:37 +0900 Subject: [PATCH 1/6] test-macro: CONST_MAX() and friends may return (void*)0 when built under coverity See 963c6c90af87fdf8b7dcb942991fb018b87fea07. --- src/test/test-macro.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/test-macro.c b/src/test/test-macro.c index c4c533777d..78422de9ee 100644 --- a/src/test/test-macro.c +++ b/src/test/test-macro.c @@ -80,7 +80,7 @@ TEST(MAX) { /* CONST_MAX returns (void) instead of a value if the passed arguments * are not of the same type or not constant expressions. */ assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 10)), int)); - assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 1U)), void)); + assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 1U)), typeof(VOID_0))); assert_se(val1.a == 100); assert_se(MAX(++d, 0) == 1); @@ -618,8 +618,8 @@ TEST(ALIGN_TO) { assert_cc(CONST_ALIGN_TO(513, 512) == 1024); assert_cc(CONST_ALIGN_TO(sizeof(int), 64) == 64); - assert_cc(__builtin_types_compatible_p(typeof(CONST_ALIGN_TO(4, 3)), void)); - assert_cc(__builtin_types_compatible_p(typeof(CONST_ALIGN_TO(SIZE_MAX, 512)), void)); + assert_cc(__builtin_types_compatible_p(typeof(CONST_ALIGN_TO(4, 3)), typeof(VOID_0))); + assert_cc(__builtin_types_compatible_p(typeof(CONST_ALIGN_TO(SIZE_MAX, 512)), typeof(VOID_0))); } TEST(align_down) { From 83340eb1fae01b411dabc1ba1a30413f02b3d369 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 15 Mar 2025 06:51:18 +0900 Subject: [PATCH 2/6] tests: replace ASSERT_OK() and friends with coverity firendy function We already have done the same for assert_se() since d9fb7afb4890a93db478616e7bfc639b2129b466. Hopefully this makes coverity silent about the false-positive side-effect warnings. --- src/shared/tests.h | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/src/shared/tests.h b/src/shared/tests.h index 07c4eeefbd..f3506a5625 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -221,6 +221,9 @@ static inline int run_test_table(void) { long long: "%lld", \ unsigned long long: "%llu") +#ifdef __COVERITY__ +#define ASSERT_OK(expr) __coverity_check__((expr) >= 0) +#else #define ASSERT_OK(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -230,8 +233,12 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif /* For functions that return a boolean on success and a negative errno on failure. */ +#ifdef __COVERITY__ +#define ASSERT_OK_POSITIVE(expr) __coverity_check__((expr) > 0) +#else #define ASSERT_OK_POSITIVE(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -246,7 +253,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_OK_ZERO(expr) __coverity_check__((expr) == 0) +#else #define ASSERT_OK_ZERO(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -263,7 +274,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_OK_EQ(expr1, expr2) __coverity_check__((expr1) == (expr2)) +#else #define ASSERT_OK_EQ(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -283,7 +298,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_OK_ERRNO(expr) __coverity_check__((expr) >= 0) +#else #define ASSERT_OK_ERRNO(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -293,7 +312,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_OK_ZERO_ERRNO(expr) __coverity_check__((expr) == 0) +#else #define ASSERT_OK_ZERO_ERRNO(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -310,7 +333,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_OK_EQ_ERRNO(expr1, expr2) __coverity_check__((expr1) == (expr2)) +#else #define ASSERT_OK_EQ_ERRNO(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -330,7 +357,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_FAIL(expr) __coverity_check__((expr) < 0) +#else #define ASSERT_FAIL(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -340,7 +371,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_ERROR(expr1, expr2) __coverity_check__((expr1) == -(expr2)) +#else #define ASSERT_ERROR(expr1, expr2) \ ({ \ int _expr1 = (expr1); \ @@ -355,7 +390,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_ERROR_ERRNO(expr1, expr2) __coverity_check__((expr1) < 0 && errno == (expr2)) +#else #define ASSERT_ERROR_ERRNO(expr1, expr2) \ ({ \ int _expr1 = (expr1); \ @@ -370,7 +409,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_TRUE(expr) __coverity_check__(!!(expr)) +#else #define ASSERT_TRUE(expr) \ ({ \ if (!(expr)) { \ @@ -379,7 +422,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_FALSE(expr) __coverity_check__(!(expr)) +#else #define ASSERT_FALSE(expr) \ ({ \ if ((expr)) { \ @@ -388,7 +435,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_NULL(expr) __coverity_check__((expr) == NULL) +#else #define ASSERT_NULL(expr) \ ({ \ typeof(expr) _result = (expr); \ @@ -398,7 +449,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_NOT_NULL(expr) __coverity_check__((expr) != NULL) +#else #define ASSERT_NOT_NULL(expr) \ ({ \ if ((expr) == NULL) { \ @@ -407,7 +462,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_STREQ(expr1, expr2) __coverity_check__(streq_ptr((expr1), (expr2))) +#else #define ASSERT_STREQ(expr1, expr2) \ ({ \ const char *_expr1 = (expr1), *_expr2 = (expr2); \ @@ -417,7 +476,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_PTR_EQ(expr1, expr2) __coverity_check__((expr1) == (expr2)) +#else #define ASSERT_PTR_EQ(expr1, expr2) \ ({ \ const void *_expr1 = (expr1), *_expr2 = (expr2); \ @@ -427,10 +490,14 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif /* DECIMAL_STR_FMT() uses _Generic which cannot be used in string concatenation so we have to format the * input into strings first and then format those into the final assertion message. */ +#ifdef __COVERITY__ +#define ASSERT_EQ(expr1, expr2) __coverity_check__((expr1) == (expr2)) +#else #define ASSERT_EQ(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -445,7 +512,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_GE(expr1, expr2) __coverity_check__((expr1) >= (expr2)) +#else #define ASSERT_GE(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -460,7 +531,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_LE(expr1, expr2) __coverity_check__((expr1) <= (expr2)) +#else #define ASSERT_LE(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -475,7 +550,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_NE(expr1, expr2) __coverity_check__((expr1) != (expr2)) +#else #define ASSERT_NE(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -490,7 +569,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_GT(expr1, expr2) __coverity_check__((expr1) > (expr2)) +#else #define ASSERT_GT(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -505,7 +588,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_LT(expr1, expr2) __coverity_check__((expr1) < (expr2)) +#else #define ASSERT_LT(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -520,7 +607,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_SIGNAL(expr, signal) __coverity_check__(((expr), false)) +#else #define ASSERT_SIGNAL(expr, signal) \ ({ \ ASSERT_TRUE(SIGNAL_VALID(signal)); \ @@ -543,7 +634,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_EQ_ID128(expr1, expr2) __coverity_check__(sd_id128_equal((expr1), (expr2))) +#else #define ASSERT_EQ_ID128(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -556,7 +651,11 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif +#ifdef __COVERITY__ +#define ASSERT_NE_ID128(expr1, expr2) __coverity_check__(!sd_id128_equal((expr1), (expr2))) +#else #define ASSERT_NE_ID128(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -569,12 +668,16 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif #define EFI_GUID_Fmt "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" #define EFI_GUID_Arg(guid) (guid).Data1, (guid).Data2, (guid).Data3, \ (guid).Data4[0], (guid).Data4[1], (guid).Data4[2], (guid).Data4[3], \ (guid).Data4[4], (guid).Data4[5], (guid).Data4[6], (guid).Data4[7] \ +#ifdef __COVERITY__ +#define ASSERT_EQ_EFI_GUID(expr1, expr2) __coverity_check__(efi_guid_equal((expr1), (expr2))) +#else #define ASSERT_EQ_EFI_GUID(expr1, expr2) \ ({ \ typeof(expr1) _expr1 = (expr1); \ @@ -588,3 +691,4 @@ static inline int run_test_table(void) { abort(); \ } \ }) +#endif From 09e0ce8010d5fd10db1c44c493d4700e27b0f8f0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 15 Mar 2025 07:20:45 +0900 Subject: [PATCH 3/6] test: fix wrong use of ASSERT_OK() and friends --- src/libsystemd/sd-device/test-sd-device.c | 2 +- src/test/test-id128.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index b2b04562cd..e9d24570da 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -544,7 +544,7 @@ TEST(sd_device_enumerator_add_all_parents) { log_debug("found %u devices", devices_count_without_parents); /* STEP 2: enumerate again with all_parents() */ - ASSERT_OK(sd_device_enumerator_add_all_parents(e) >= 0); + ASSERT_OK(sd_device_enumerator_add_all_parents(e)); unsigned not_filtered_parent_count = 0; FOREACH_DEVICE(e, dev) { diff --git a/src/test/test-id128.c b/src/test/test-id128.c index 4ff95deaea..48af629b73 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -31,7 +31,7 @@ TEST(id128) { ASSERT_OK(sd_id128_randomize(&id)); printf("random: %s\n", sd_id128_to_string(id, t)); - ASSERT_OK(sd_id128_from_string(t, &id2) == 0); + ASSERT_OK(sd_id128_from_string(t, &id2)); ASSERT_EQ_ID128(id, id2); ASSERT_TRUE(sd_id128_in_set(id, id)); ASSERT_TRUE(sd_id128_in_set(id, id2)); @@ -116,7 +116,7 @@ TEST(id128) { ASSERT_OK(sd_id128_randomize(&id)); ASSERT_OK(id128_write_fd(fd, ID128_FORMAT_PLAIN, id)); - ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET) == 0); + ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET)); ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_UUID, &id2), EUCLEAN); ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET)); From 88f4650f22cbe37ac0d340e431fbe380ed5b0a26 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 15 Mar 2025 07:21:33 +0900 Subject: [PATCH 4/6] meson: handle bool-compare warning as error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Then we can detect the error fixed by the previous commit like the following: ../src/libsystemd/sd-device/test-sd-device.c: In function ‘test_sd_device_enumerator_add_all_parents’: ../src/shared/tests.h:225:51: error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare] 225 | #define ASSERT_OK(expr) __coverity_check__((expr) >= 0) | ^~ ../src/libsystemd/sd-device/test-sd-device.c:547:9: note: in expansion of macro ‘ASSERT_OK’ 547 | ASSERT_OK(sd_device_enumerator_add_all_parents(e) >= 0); | ^~~~~~~~~ --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index d87c651fc6..9cbfffb8c3 100644 --- a/meson.build +++ b/meson.build @@ -379,6 +379,7 @@ possible_common_cc_flags = [ '-Warray-bounds=2', '-Wdate-time', '-Wendif-labels', + '-Werror=bool-compare', '-Werror=discarded-qualifiers', '-Werror=format=2', '-Werror=format-signedness', From d9000d708c7dbf2eaeaa387facd7bef9589f1ba7 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 15 Mar 2025 09:04:25 +0900 Subject: [PATCH 5/6] test: drop redundant parentheses in ASSERT_OK() and friends This reverts 278e3adf50e36518c5a5dd798ca998e7eac5436e, and drop more redundant parentheses, as they unfortunately does not suppress the false-positive warnings by coverity. --- .../sd-device/test-sd-device-monitor.c | 4 +- src/libsystemd/sd-device/test-sd-device.c | 34 ++++++------- src/libsystemd/sd-event/test-event.c | 2 +- .../sd-journal/test-journal-interleaving.c | 2 +- src/libsystemd/sd-netlink/test-netlink.c | 48 +++++++++---------- src/locale/test-localed-util.c | 6 +-- src/test/test-acl-util.c | 4 +- src/test/test-calendarspec.c | 2 +- src/test/test-chase.c | 14 +++--- src/test/test-compress.c | 2 +- src/test/test-condition.c | 2 +- src/test/test-conf-parser.c | 2 +- src/test/test-dev-setup.c | 12 ++--- src/test/test-fs-util.c | 2 +- src/test/test-hostname-setup.c | 6 +-- src/test/test-json.c | 2 +- src/test/test-mount-util.c | 2 +- src/test/test-namespace.c | 4 +- src/test/test-netlink-manual.c | 6 +-- src/test/test-terminal-util.c | 4 +- src/test/test-unit-file.c | 2 +- src/test/test-user-util.c | 2 +- 22 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/libsystemd/sd-device/test-sd-device-monitor.c b/src/libsystemd/sd-device/test-sd-device-monitor.c index 01681792ca..1cdeabbf21 100644 --- a/src/libsystemd/sd-device/test-sd-device-monitor.c +++ b/src/libsystemd/sd-device/test-sd-device-monitor.c @@ -376,13 +376,13 @@ TEST(sd_device_monitor_receive) { ASSERT_OK(device_monitor_send(monitor_server, &sa, device)); - ASSERT_OK((fd = sd_device_monitor_get_fd(monitor_client))); + ASSERT_OK(fd = sd_device_monitor_get_fd(monitor_client)); for (;;) { usec_t timeout; int events; - ASSERT_OK((events = sd_device_monitor_get_events(monitor_client))); + ASSERT_OK(events = sd_device_monitor_get_events(monitor_client)); ASSERT_EQ(events, (int) EPOLLIN); ASSERT_OK(sd_device_monitor_get_timeout(monitor_client, &timeout)); ASSERT_EQ(timeout, USEC_INFINITY); diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index e9d24570da..86926ec484 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -39,12 +39,12 @@ static void test_sd_device_one(sd_device *d) { ASSERT_OK(sd_device_new_from_syspath(&dev, syspath)); ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); ASSERT_OK(sd_device_new_from_path(&dev, syspath)); ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); r = sd_device_get_ifindex(d, &ifindex); if (r < 0) @@ -69,7 +69,7 @@ static void test_sd_device_one(sd_device *d) { } else { ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); } /* This does not require the interface really exists on the network namespace. @@ -77,7 +77,7 @@ static void test_sd_device_one(sd_device *d) { ASSERT_OK(sd_device_new_from_ifname(&dev, sysname)); ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); } r = sd_device_get_subsystem(d, &subsystem); @@ -99,7 +99,7 @@ static void test_sd_device_one(sd_device *d) { else { ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); } /* The device ID depends on subsystem. */ @@ -115,11 +115,11 @@ static void test_sd_device_one(sd_device *d) { } else { ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); } /* These require udev database, and reading database requires device ID. */ - ASSERT_OK((r = sd_device_get_is_initialized(d))); + ASSERT_OK(r = sd_device_get_is_initialized(d)); if (r > 0) { r = sd_device_get_usec_since_initialized(d, &usec); if (r < 0) @@ -145,7 +145,7 @@ static void test_sd_device_one(sd_device *d) { else { ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); } r = sd_device_new_from_path(&dev, devname); @@ -154,7 +154,7 @@ static void test_sd_device_one(sd_device *d) { else { ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); _cleanup_close_ int fd = -EBADF; fd = sd_device_open(d, O_CLOEXEC| O_NONBLOCK | (is_block ? O_RDONLY : O_NOCTTY | O_PATH)); @@ -173,18 +173,18 @@ static void test_sd_device_one(sd_device *d) { ASSERT_OK(sd_device_new_from_devnum(&dev, is_block ? 'b' : 'c', devnum)); ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); ASSERT_OK(asprintf(&p, "/dev/%s/%u:%u", is_block ? "block" : "char", major(devnum), minor(devnum))); ASSERT_OK(sd_device_new_from_devname(&dev, p)); ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); ASSERT_OK(sd_device_new_from_path(&dev, p)); ASSERT_OK(sd_device_get_syspath(dev, &val)); ASSERT_STREQ(syspath, val); - ASSERT_NULL((dev = sd_device_unref(dev))); + ASSERT_NULL(dev = sd_device_unref(dev)); } ASSERT_OK(sd_device_get_devpath(d, &val)); @@ -216,8 +216,8 @@ static void test_sd_device_one(sd_device *d) { ASSERT_TRUE(ERRNO_IS_NEG_PRIVILEGE(r) || IN_SET(r, -ENOENT, -EINVAL)); else { unsigned x; - ASSERT_OK((r = device_get_sysattr_unsigned(d, "nsid", &x))); - ASSERT_EQ((x > 0), (r > 0)); + ASSERT_OK(r = device_get_sysattr_unsigned(d, "nsid", &x)); + ASSERT_EQ(x > 0, r > 0); } } @@ -687,7 +687,7 @@ TEST(sd_device_new_from_path) { ASSERT_OK(sd_device_new_from_path(&d, syspath)); ASSERT_OK(sd_device_get_syspath(d, &s)); ASSERT_STREQ(s, syspath); - ASSERT_NULL((d = sd_device_unref(d))); + ASSERT_NULL(d = sd_device_unref(d)); ASSERT_OK(sd_device_get_devname(dev, &devpath)); r = sd_device_new_from_path(&d, devpath); @@ -696,7 +696,7 @@ TEST(sd_device_new_from_path) { else { ASSERT_OK(sd_device_get_syspath(d, &s)); ASSERT_STREQ(s, syspath); - ASSERT_NULL((d = sd_device_unref(d))); + ASSERT_NULL(d = sd_device_unref(d)); } ASSERT_NOT_NULL((path = path_join(tmpdir, sysname))); @@ -720,7 +720,7 @@ static void test_devname_from_devnum_one(const char *path) { ASSERT_OK(devname_from_devnum(st.st_mode, st.st_rdev, &resolved)); ASSERT_TRUE(path_equal(path, resolved)); - ASSERT_NULL((resolved = mfree(resolved))); + ASSERT_NULL(resolved = mfree(resolved)); ASSERT_OK(devname_from_stat_rdev(&st, &resolved)); ASSERT_TRUE(path_equal(path, resolved)); } diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index 79a3d30356..6394507994 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -572,7 +572,7 @@ TEST(pidfd) { assert_se(pid > 1); - ASSERT_OK((pidfd = pidfd_open(pid, 0))); + ASSERT_OK(pidfd = pidfd_open(pid, 0)); pid2 = fork(); if (pid2 == 0) diff --git a/src/libsystemd/sd-journal/test-journal-interleaving.c b/src/libsystemd/sd-journal/test-journal-interleaving.c index 80bb436ea5..6e9c87c023 100644 --- a/src/libsystemd/sd-journal/test-journal-interleaving.c +++ b/src/libsystemd/sd-journal/test-journal-interleaving.c @@ -236,7 +236,7 @@ static void test_cursor(sd_journal *j) { ASSERT_OK(sd_journal_seek_head(j)); for (;;) { - ASSERT_OK((r = sd_journal_next(j))); + ASSERT_OK(r = sd_journal_next(j)); if (r == 0) break; diff --git a/src/libsystemd/sd-netlink/test-netlink.c b/src/libsystemd/sd-netlink/test-netlink.c index 9862904e30..a68a37e282 100644 --- a/src/libsystemd/sd-netlink/test-netlink.c +++ b/src/libsystemd/sd-netlink/test-netlink.c @@ -100,7 +100,7 @@ TEST(message_address) { ASSERT_OK(sd_rtnl_message_new_addr(rtnl, &message, RTM_GETADDR, ifindex, AF_INET)); ASSERT_OK(sd_netlink_message_set_request_dump(message, true)); - ASSERT_OK((r = sd_netlink_call(rtnl, message, 0, &reply))); + ASSERT_OK(r = sd_netlink_call(rtnl, message, 0, &reply)); /* If the loopback device is down we won't get any results. */ if (r > 0) { @@ -134,7 +134,7 @@ TEST(message_route) { ASSERT_OK(sd_netlink_message_read_u32(req, RTA_OIF, &u32_data)); ASSERT_EQ(u32_data, index); - ASSERT_NULL((req = sd_netlink_message_unref(req))); + ASSERT_NULL(req = sd_netlink_message_unref(req)); } static int link_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { @@ -173,7 +173,7 @@ TEST(netlink_event_loop) { ASSERT_OK(sd_event_run(event, 0)); ASSERT_OK(sd_netlink_detach_event(rtnl)); - ASSERT_NULL((rtnl = sd_netlink_unref(rtnl))); + ASSERT_NULL(rtnl = sd_netlink_unref(rtnl)); } static void test_async_destroy(void *userdata) { @@ -226,7 +226,7 @@ TEST(netlink_call_async) { ASSERT_OK(sd_netlink_wait(rtnl, 0)); ASSERT_OK(sd_netlink_process(rtnl, &reply)); - ASSERT_NULL((rtnl = sd_netlink_unref(rtnl))); + ASSERT_NULL(rtnl = sd_netlink_unref(rtnl)); } struct test_async_object { @@ -307,7 +307,7 @@ TEST(async_destroy_callback) { ASSERT_PTR_EQ(test_async_object_ref(t), t); ASSERT_EQ(t->n_ref, 2U); - ASSERT_NULL((slot = sd_netlink_slot_unref(slot))); + ASSERT_NULL(slot = sd_netlink_slot_unref(slot)); ASSERT_EQ(t->n_ref, 1U); ASSERT_NULL(sd_netlink_message_unref(m)); @@ -320,7 +320,7 @@ TEST(async_destroy_callback) { ASSERT_PTR_EQ(test_async_object_ref(t), t); ASSERT_EQ(t->n_ref, 2U); - ASSERT_NULL((rtnl = sd_netlink_unref(rtnl))); + ASSERT_NULL(rtnl = sd_netlink_unref(rtnl)); ASSERT_EQ(t->n_ref, 1U); } @@ -329,7 +329,7 @@ static int pipe_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) (*counter)--; - ASSERT_OK((r = sd_netlink_message_get_errno(m))); + ASSERT_OK(r = sd_netlink_message_get_errno(m)); log_info_errno(r, "%d left in pipe. got reply: %m", *counter); return 1; } @@ -356,7 +356,7 @@ TEST(pipe) { ASSERT_OK(sd_netlink_process(rtnl, NULL)); } - ASSERT_NULL((rtnl = sd_netlink_unref(rtnl))); + ASSERT_NULL(rtnl = sd_netlink_unref(rtnl)); } TEST(message_container) { @@ -403,10 +403,10 @@ TEST(sd_netlink_add_match) { ASSERT_OK(sd_netlink_add_match(rtnl, &s2, RTM_NEWLINK, link_handler, NULL, NULL, NULL)); ASSERT_OK(sd_netlink_add_match(rtnl, NULL, RTM_NEWLINK, link_handler, NULL, NULL, NULL)); - ASSERT_NULL((s1 = sd_netlink_slot_unref(s1))); - ASSERT_NULL((s2 = sd_netlink_slot_unref(s2))); + ASSERT_NULL(s1 = sd_netlink_slot_unref(s1)); + ASSERT_NULL(s2 = sd_netlink_slot_unref(s2)); - ASSERT_NULL((rtnl = sd_netlink_unref(rtnl))); + ASSERT_NULL(rtnl = sd_netlink_unref(rtnl)); } TEST(dump_addresses) { @@ -578,23 +578,23 @@ TEST(genl) { ASSERT_OK(sd_genl_add_match(genl, NULL, CTRL_GENL_NAME, "notify", 0, genl_ctrl_match_callback, NULL, NULL, "genl-ctrl-notify")); - ASSERT_NULL((m = sd_netlink_message_unref(m))); + ASSERT_NULL(m = sd_netlink_message_unref(m)); ASSERT_FAIL(sd_genl_message_new(genl, "should-not-exist", CTRL_CMD_GETFAMILY, &m)); ASSERT_ERROR(sd_genl_message_new(genl, "should-not-exist", CTRL_CMD_GETFAMILY, &m), EOPNOTSUPP); /* These families may not be supported by kernel. Hence, ignore results. */ (void) sd_genl_message_new(genl, FOU_GENL_NAME, 0, &m); - ASSERT_NULL((m = sd_netlink_message_unref(m))); + ASSERT_NULL(m = sd_netlink_message_unref(m)); (void) sd_genl_message_new(genl, L2TP_GENL_NAME, 0, &m); - ASSERT_NULL((m = sd_netlink_message_unref(m))); + ASSERT_NULL(m = sd_netlink_message_unref(m)); (void) sd_genl_message_new(genl, MACSEC_GENL_NAME, 0, &m); - ASSERT_NULL((m = sd_netlink_message_unref(m))); + ASSERT_NULL(m = sd_netlink_message_unref(m)); (void) sd_genl_message_new(genl, NL80211_GENL_NAME, 0, &m); - ASSERT_NULL((m = sd_netlink_message_unref(m))); + ASSERT_NULL(m = sd_netlink_message_unref(m)); (void) sd_genl_message_new(genl, NETLBL_NLTYPE_UNLABELED_NAME, 0, &m); for (;;) { - ASSERT_OK((r = sd_event_run(event, 500 * USEC_PER_MSEC))); + ASSERT_OK(r = sd_event_run(event, 500 * USEC_PER_MSEC)); if (r == 0) return; } @@ -636,8 +636,8 @@ TEST(rtnl_set_link_name) { return (void) log_tests_skipped("dummy network interface is not supported"); ASSERT_OK(r); - ASSERT_NULL((message = sd_netlink_message_unref(message))); - ASSERT_NULL((reply = sd_netlink_message_unref(reply))); + ASSERT_NULL(message = sd_netlink_message_unref(message)); + ASSERT_NULL(reply = sd_netlink_message_unref(reply)); ASSERT_OK(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, 0)); ASSERT_OK(sd_netlink_message_append_string(message, IFLA_IFNAME, "test-netlink")); @@ -664,7 +664,7 @@ TEST(rtnl_set_link_name) { ASSERT_ERROR(rtnl_set_link_name(&rtnl, ifindex, "testlongalternativename", NULL), EINVAL); ASSERT_OK(rtnl_set_link_name(&rtnl, ifindex, "test-shortname", STRV_MAKE("testlongalternativename", "test-shortname", "test-additional-name"))); - ASSERT_NULL((alternative_names = strv_free(alternative_names))); + ASSERT_NULL(alternative_names = strv_free(alternative_names)); ASSERT_OK(rtnl_get_link_alternative_names(&rtnl, ifindex, &alternative_names)); ASSERT_TRUE(strv_contains(alternative_names, "testlongalternativename")); ASSERT_TRUE(strv_contains(alternative_names, "test-additional-name")); @@ -672,7 +672,7 @@ TEST(rtnl_set_link_name) { ASSERT_OK(rtnl_delete_link_alternative_names(&rtnl, ifindex, STRV_MAKE("testlongalternativename"))); - ASSERT_NULL((alternative_names = strv_free(alternative_names))); + ASSERT_NULL(alternative_names = strv_free(alternative_names)); ASSERT_OK_EQ(rtnl_get_link_alternative_names(&rtnl, ifindex, &alternative_names), ifindex); ASSERT_FALSE(strv_contains(alternative_names, "testlongalternativename")); ASSERT_TRUE(strv_contains(alternative_names, "test-additional-name")); @@ -682,7 +682,7 @@ TEST(rtnl_set_link_name) { ASSERT_OK_EQ(rtnl_resolve_link_alternative_name(&rtnl, "test-additional-name", NULL), ifindex); ASSERT_OK_EQ(rtnl_resolve_link_alternative_name(&rtnl, "test-additional-name", &resolved), ifindex); ASSERT_STREQ(resolved, "test-shortname"); - ASSERT_NULL((resolved = mfree(resolved))); + ASSERT_NULL(resolved = mfree(resolved)); ASSERT_OK(rtnl_rename_link(&rtnl, "test-shortname", "test-shortname")); ASSERT_OK(rtnl_rename_link(&rtnl, "test-shortname", "test-shortname2")); @@ -691,12 +691,12 @@ TEST(rtnl_set_link_name) { ASSERT_OK_EQ(rtnl_resolve_link_alternative_name(&rtnl, "test-additional-name", NULL), ifindex); ASSERT_OK_EQ(rtnl_resolve_link_alternative_name(&rtnl, "test-additional-name", &resolved), ifindex); ASSERT_STREQ(resolved, "test-shortname3"); - ASSERT_NULL((resolved = mfree(resolved))); + ASSERT_NULL(resolved = mfree(resolved)); ASSERT_OK_EQ(rtnl_resolve_link_alternative_name(&rtnl, "test-shortname3", NULL), ifindex); ASSERT_OK_EQ(rtnl_resolve_link_alternative_name(&rtnl, "test-shortname3", &resolved), ifindex); ASSERT_STREQ(resolved, "test-shortname3"); - ASSERT_NULL((resolved = mfree(resolved))); + ASSERT_NULL(resolved = mfree(resolved)); } DEFINE_TEST_MAIN(LOG_DEBUG); diff --git a/src/locale/test-localed-util.c b/src/locale/test-localed-util.c index f700642cc5..d6221edbaf 100644 --- a/src/locale/test-localed-util.c +++ b/src/locale/test-localed-util.c @@ -33,10 +33,10 @@ TEST(find_converted_keymap) { }, &ans)); ASSERT_NULL(ans); - ASSERT_OK((r = find_converted_keymap( + ASSERT_OK(r = find_converted_keymap( &(X11Context) { .layout = (char*) "pl", - }, &ans))); + }, &ans)); if (r == 0) return (void) log_tests_skipped("keymaps are not installed"); @@ -115,7 +115,7 @@ TEST(vconsole_convert_to_x11) { /* "gh" has no mapping in kbd-model-map and kbd provides a converted keymap for this layout. */ log_info("/* test with a converted keymap (gh:) */"); ASSERT_OK(free_and_strdup(&vc.keymap, "gh")); - ASSERT_OK((r = vconsole_convert_to_x11(&vc, x11_context_verify, &xc))); + ASSERT_OK(r = vconsole_convert_to_x11(&vc, x11_context_verify, &xc)); if (r == 0) return (void) log_tests_skipped("keymaps are not installed"); diff --git a/src/test/test-acl-util.c b/src/test/test-acl-util.c index f7e0f5ca4d..bd68f58bae 100644 --- a/src/test/test-acl-util.c +++ b/src/test/test-acl-util.c @@ -29,7 +29,7 @@ TEST_RET(add_acls_for_user) { return log_tests_skipped_errno(r, "Could not find %s binary: %m", s); } - ASSERT_OK((fd = mkostemp_safe(fn))); + ASSERT_OK(fd = mkostemp_safe(fn)); /* Use the mode that user journal files use */ ASSERT_OK_ZERO_ERRNO(fchmod(fd, 0640)); @@ -86,7 +86,7 @@ TEST_RET(fd_acl_make_read_only) { return log_tests_skipped_errno(r, "Could not find %s binary: %m", s); } - ASSERT_OK((fd = mkostemp_safe(fn))); + ASSERT_OK(fd = mkostemp_safe(fn)); /* make it more exciting */ (void) fd_add_uid_acl_permission(fd, 1, ACL_READ|ACL_WRITE|ACL_EXECUTE); diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index 0fc3a43a23..005d9b0771 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -97,7 +97,7 @@ TEST(hourly_bug_4031) { ASSERT_OK(calendar_spec_from_string("hourly", &c)); n = now(CLOCK_REALTIME); - ASSERT_OK((r = calendar_spec_next_usec(c, n, &u))); + ASSERT_OK(r = calendar_spec_next_usec(c, n, &u)); log_info("Now: %s (%"PRIu64")", FORMAT_TIMESTAMP_STYLE(n, TIMESTAMP_US), n); log_info("Next hourly: %s (%"PRIu64")", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US), u); diff --git a/src/test/test-chase.c b/src/test/test-chase.c index 16f470a08e..09baae64fd 100644 --- a/src/test/test-chase.c +++ b/src/test/test-chase.c @@ -468,7 +468,7 @@ TEST(chaseat) { struct stat st; const char *p; - ASSERT_OK((tfd = mkdtemp_open(NULL, 0, &t))); + ASSERT_OK(tfd = mkdtemp_open(NULL, 0, &t)); /* Test that AT_FDCWD with CHASE_AT_RESOLVE_IN_ROOT resolves against / and not the current working * directory. */ @@ -520,7 +520,7 @@ TEST(chaseat) { /* Test that absolute path or not are the same when resolving relative to a directory file * descriptor and that we always get a relative path back. */ - ASSERT_OK((fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700))); + ASSERT_OK(fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700)); fd = safe_close(fd); ASSERT_OK(symlinkat("/def", tfd, "qed")); ASSERT_OK(chaseat(tfd, "qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL)); @@ -536,7 +536,7 @@ TEST(chaseat) { /* Test CHASE_PARENT */ - ASSERT_OK((fd = open_mkdir_at(tfd, "chase", O_CLOEXEC, 0755))); + ASSERT_OK(fd = open_mkdir_at(tfd, "chase", O_CLOEXEC, 0755)); ASSERT_OK(symlinkat("/def", fd, "parent")); fd = safe_close(fd); @@ -668,24 +668,24 @@ TEST(chaseat) { /* Test chase_and_open_parent_at() */ - ASSERT_OK((fd = chase_and_open_parent_at(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_NOFOLLOW, &result))); + ASSERT_OK(fd = chase_and_open_parent_at(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_NOFOLLOW, &result)); ASSERT_OK(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW)); ASSERT_STREQ(result, "parent"); fd = safe_close(fd); result = mfree(result); - ASSERT_OK((fd = chase_and_open_parent_at(tfd, "chase", CHASE_AT_RESOLVE_IN_ROOT, &result))); + ASSERT_OK(fd = chase_and_open_parent_at(tfd, "chase", CHASE_AT_RESOLVE_IN_ROOT, &result)); ASSERT_OK(faccessat(fd, result, F_OK, 0)); ASSERT_STREQ(result, "chase"); fd = safe_close(fd); result = mfree(result); - ASSERT_OK((fd = chase_and_open_parent_at(tfd, "/", CHASE_AT_RESOLVE_IN_ROOT, &result))); + ASSERT_OK(fd = chase_and_open_parent_at(tfd, "/", CHASE_AT_RESOLVE_IN_ROOT, &result)); ASSERT_STREQ(result, "."); fd = safe_close(fd); result = mfree(result); - ASSERT_OK((fd = chase_and_open_parent_at(tfd, ".", CHASE_AT_RESOLVE_IN_ROOT, &result))); + ASSERT_OK(fd = chase_and_open_parent_at(tfd, ".", CHASE_AT_RESOLVE_IN_ROOT, &result)); ASSERT_STREQ(result, "."); fd = safe_close(fd); result = mfree(result); diff --git a/src/test/test-compress.c b/src/test/test-compress.c index 9688e10df4..b9ef3644e1 100644 --- a/src/test/test-compress.c +++ b/src/test/test-compress.c @@ -188,7 +188,7 @@ _unused_ static void test_compress_stream(const char *compression, log_debug("/* create source from %s */", srcfile); - ASSERT_OK((src = open(srcfile, O_RDONLY|O_CLOEXEC))); + ASSERT_OK(src = open(srcfile, O_RDONLY|O_CLOEXEC)); log_debug("/* test compression */"); diff --git a/src/test/test-condition.c b/src/test/test-condition.c index be5fe67879..9334a8ca89 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -250,7 +250,7 @@ TEST(condition_test_architecture) { const char *sa; Architecture a; - ASSERT_OK((a = uname_architecture())); + ASSERT_OK(a = uname_architecture()); ASSERT_NOT_NULL((sa = architecture_to_string(a))); ASSERT_NOT_NULL((condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false))); diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index 233f58b90e..a4309c0134 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -409,7 +409,7 @@ TEST(config_parse_standard_file_with_dropins_full) { _cleanup_close_ int rfd = -EBADF; int r; - ASSERT_OK((rfd = mkdtemp_open("/tmp/test-config-parse-XXXXXX", 0, &root))); + ASSERT_OK(rfd = mkdtemp_open("/tmp/test-config-parse-XXXXXX", 0, &root)); assert_se(mkdir_p_root(root, "/etc/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755)); assert_se(mkdir_p_root(root, "/run/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755)); assert_se(mkdir_p_root(root, "/usr/lib/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755)); diff --git a/src/test/test-dev-setup.c b/src/test/test-dev-setup.c index bdf562584c..dd6b30079a 100644 --- a/src/test/test-dev-setup.c +++ b/src/test/test-dev-setup.c @@ -30,29 +30,29 @@ int main(int argc, char *argv[]) { f = prefix_roota(p, "/run/systemd/inaccessible/reg"); ASSERT_OK_ERRNO(stat(f, &st)); ASSERT_TRUE(S_ISREG(st.st_mode)); - ASSERT_EQ((st.st_mode & 07777), 0000U); + ASSERT_EQ(st.st_mode & 07777, 0000U); f = prefix_roota(p, "/run/systemd/inaccessible/dir"); ASSERT_OK_ERRNO(stat(f, &st)); ASSERT_TRUE(S_ISDIR(st.st_mode)); - ASSERT_EQ((st.st_mode & 07777), 0000U); + ASSERT_EQ(st.st_mode & 07777, 0000U); f = prefix_roota(p, "/run/systemd/inaccessible/fifo"); ASSERT_OK_ERRNO(stat(f, &st)); ASSERT_TRUE(S_ISFIFO(st.st_mode)); - ASSERT_EQ((st.st_mode & 07777), 0000U); + ASSERT_EQ(st.st_mode & 07777, 0000U); f = prefix_roota(p, "/run/systemd/inaccessible/sock"); ASSERT_OK_ERRNO(stat(f, &st)); ASSERT_TRUE(S_ISSOCK(st.st_mode)); - ASSERT_EQ((st.st_mode & 07777), 0000U); + ASSERT_EQ(st.st_mode & 07777, 0000U); f = prefix_roota(p, "/run/systemd/inaccessible/chr"); if (stat(f, &st) < 0) ASSERT_EQ(errno, ENOENT); else { ASSERT_TRUE(S_ISCHR(st.st_mode)); - ASSERT_EQ((st.st_mode & 07777), 0000U); + ASSERT_EQ(st.st_mode & 07777, 0000U); } f = prefix_roota(p, "/run/systemd/inaccessible/blk"); @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) { ASSERT_EQ(errno, ENOENT); else { ASSERT_TRUE(S_ISBLK(st.st_mode)); - ASSERT_EQ((st.st_mode & 07777), 0000U); + ASSERT_EQ(st.st_mode & 07777, 0000U); } return EXIT_SUCCESS; diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 3becf8f9ab..0670bb7f8e 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -610,7 +610,7 @@ TEST(openat_report_new) { _cleanup_close_ int tfd = -EBADF, fd = -EBADF; bool b; - ASSERT_OK((tfd = mkdtemp_open(NULL, 0, &t))); + ASSERT_OK(tfd = mkdtemp_open(NULL, 0, &t)); fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b); ASSERT_OK(fd); diff --git a/src/test/test-hostname-setup.c b/src/test/test-hostname-setup.c index 8243d600e1..9348313984 100644 --- a/src/test/test-hostname-setup.c +++ b/src/test/test-hostname-setup.c @@ -87,19 +87,19 @@ TEST(hostname_substitute_wildcards) { ASSERT_NOT_NULL((buf = strdup(""))); ASSERT_OK(hostname_substitute_wildcards(buf)); ASSERT_STREQ(buf, ""); - ASSERT_NULL((buf = mfree(buf))); + ASSERT_NULL(buf = mfree(buf)); ASSERT_NOT_NULL((buf = strdup("hogehoge"))); ASSERT_OK(hostname_substitute_wildcards(buf)); ASSERT_STREQ(buf, "hogehoge"); - ASSERT_NULL((buf = mfree(buf))); + ASSERT_NULL(buf = mfree(buf)); ASSERT_NOT_NULL((buf = strdup("hoge??hoge??foo?"))); ASSERT_OK(hostname_substitute_wildcards(buf)); log_debug("hostname_substitute_wildcards(\"hoge??hoge??foo?\"): → \"%s\"", buf); ASSERT_EQ(fnmatch("hoge??hoge??foo?", buf, /* flags= */ 0), 0); ASSERT_TRUE(hostname_is_valid(buf, /* flags= */ 0)); - ASSERT_NULL((buf = mfree(buf))); + ASSERT_NULL(buf = mfree(buf)); } TEST(hostname_setup) { diff --git a/src/test/test-json.c b/src/test/test-json.c index 5cbcf9f68f..8dd5746495 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -1366,7 +1366,7 @@ TEST(fd_info) { fd = safe_close(fd); /* regular file */ - ASSERT_OK((fd = open_tmpfile_unlinkable(NULL, O_RDWR))); + ASSERT_OK(fd = open_tmpfile_unlinkable(NULL, O_RDWR)); ASSERT_OK(json_variant_new_fd_info(&v, fd)); ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL)); v = sd_json_variant_unref(v); diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index ccaaacc812..ce6a43101e 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -540,7 +540,7 @@ TEST(path_is_network_fs_harder) { _cleanup_close_ int dir_fd = -EBADF; int r; - ASSERT_OK((dir_fd = open("/", O_PATH | O_CLOEXEC))); + ASSERT_OK(dir_fd = open("/", O_PATH | O_CLOEXEC)); FOREACH_STRING(s, "/", "/dev/", "/proc/", "/run/", "/sys/", "/tmp/", "/usr/", "/var/tmp/", "", ".", "../../../", "/this/path/should/not/exist/for/test-mount-util/") { diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c index 25393baf73..cae65a14b1 100644 --- a/src/test/test-namespace.c +++ b/src/test/test-namespace.c @@ -184,11 +184,11 @@ TEST(fd_is_namespace) { ASSERT_OK_ZERO(fd_is_namespace(fd, NAMESPACE_NET)); fd = safe_close(fd); - ASSERT_OK((fd = namespace_open_by_type(NAMESPACE_IPC))); + ASSERT_OK(fd = namespace_open_by_type(NAMESPACE_IPC)); ASSERT_OK_POSITIVE(fd_is_namespace(fd, NAMESPACE_IPC)); fd = safe_close(fd); - ASSERT_OK((fd = namespace_open_by_type(NAMESPACE_NET))); + ASSERT_OK(fd = namespace_open_by_type(NAMESPACE_NET)); ASSERT_OK_POSITIVE(fd_is_namespace(fd, NAMESPACE_NET)); } diff --git a/src/test/test-netlink-manual.c b/src/test/test-netlink-manual.c index 913998ad50..d12eee42cb 100644 --- a/src/test/test-netlink-manual.c +++ b/src/test/test-netlink-manual.c @@ -84,7 +84,7 @@ static int test_tunnel_configure(sd_netlink *rtnl) { ASSERT_OK_POSITIVE(sd_netlink_call(rtnl, m, -1, NULL)); - ASSERT_NULL((m = sd_netlink_message_unref(m))); + ASSERT_NULL(m = sd_netlink_message_unref(m)); /* sit */ assert_se(sd_rtnl_message_new_link(rtnl, &n, RTM_NEWLINK, 0) >= 0); @@ -110,7 +110,7 @@ static int test_tunnel_configure(sd_netlink *rtnl) { ASSERT_OK_POSITIVE(sd_netlink_call(rtnl, n, -1, NULL)); - ASSERT_NULL((n = sd_netlink_message_unref(n))); + ASSERT_NULL(n = sd_netlink_message_unref(n)); return EXIT_SUCCESS; } @@ -126,7 +126,7 @@ int main(int argc, char *argv[]) { r = test_tunnel_configure(rtnl); - ASSERT_NULL((rtnl = sd_netlink_unref(rtnl))); + ASSERT_NULL(rtnl = sd_netlink_unref(rtnl)); return r; } diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index f454d3ea60..a5616c8121 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -319,8 +319,8 @@ TEST(terminal_new_session) { _cleanup_close_ int pty_fd = -EBADF, peer_fd = -EBADF; int r; - ASSERT_OK((pty_fd = openpt_allocate(O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK, NULL))); - ASSERT_OK((peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC))); + ASSERT_OK(pty_fd = openpt_allocate(O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK, NULL)); + ASSERT_OK(peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC)); r = safe_fork_full("test-term-session", (int[]) { peer_fd, peer_fd, peer_fd }, diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 1561265a3e..c7779237b5 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -122,7 +122,7 @@ static bool test_unit_file_remove_from_name_map_trail(const LookupPaths *lp, siz ASSERT_OK_ERRNO(unlink(path)); - ASSERT_OK((r = unit_file_remove_from_name_map(lp, &cache_timestamp_hash, &unit_ids, &unit_names, &path_cache, path))); + ASSERT_OK(r = unit_file_remove_from_name_map(lp, &cache_timestamp_hash, &unit_ids, &unit_names, &path_cache, path)); if (r > 0) return false; /* someone touches unit files. Retrying. */ diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c index 0255c5775a..bf8dd16d5b 100644 --- a/src/test/test-user-util.c +++ b/src/test/test-user-util.c @@ -444,7 +444,7 @@ TEST(gid_lists_ops) { assert_se(nresult >= 0); assert_se(memcmp_nn(result2, ELEMENTSOF(result2), res4, nresult) == 0); - ASSERT_OK((nresult = getgroups_alloc(&gids))); + ASSERT_OK(nresult = getgroups_alloc(&gids)); assert_se(gids || nresult == 0); } From e92d699dde746355bba893b2375b7937a52d9e05 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 15 Mar 2025 10:46:36 +0900 Subject: [PATCH 6/6] test-cgroup-util: allow ESRCH in cg_pidref_get_path() and friends As the process may be already dead. Follow-ups for ca82f0cbe2db096bc7ff81280b5683ea1beae534. --- src/test/test-cgroup-util.c | 55 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index cdf2ea83d7..18bc998a39 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -216,44 +216,57 @@ TEST(proc, .sd_booted = true) { _cleanup_(pidref_done) PidRef pid = PIDREF_NULL; uid_t uid = UID_INVALID; - r = proc_dir_read_pidref(d, &pid); - assert_se(r >= 0); - + ASSERT_OK(r = proc_dir_read_pidref(d, &pid)); if (r == 0) break; if (pidref_is_kernel_thread(&pid) != 0) continue; - ASSERT_OK_ZERO(cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path)); + r = cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path); + if (r == -ESRCH) + continue; + ASSERT_OK(r); + /* Test may run in a container with supervising/monitor processes that don't belong to our * cgroup tree (slices/leaves) */ if (hidden_cgroup(path)) continue; - ASSERT_OK_ZERO(cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted)); - ASSERT_OK_ZERO(cg_pidref_get_unit(&pid, &unit)); - ASSERT_OK_ZERO(cg_pid_get_slice(pid.pid, &slice)); + + r = cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted); + if (r != -ESRCH) + ASSERT_OK(r); + r = cg_pidref_get_unit(&pid, &unit); + if (r != -ESRCH) + ASSERT_OK(r); + r = cg_pid_get_slice(pid.pid, &slice); + if (r != -ESRCH) + ASSERT_OK(r); /* Not all processes belong to a specific user or a machine */ r = cg_pidref_get_owner_uid(&pid, &uid); - ASSERT_TRUE(r == 0 || r == -ENXIO); + if (!IN_SET(r, -ESRCH, -ENXIO)) + ASSERT_OK(r); r = cg_pidref_get_session(&pid, &session); - ASSERT_TRUE(r == 0 || r == -ENXIO); + if (!IN_SET(r, -ESRCH, -ENXIO)) + ASSERT_OK(r); r = cg_pid_get_user_unit(pid.pid, &user_unit); - ASSERT_TRUE(r == 0 || r == -ENXIO); + if (!IN_SET(r, -ESRCH, -ENXIO)) + ASSERT_OK(r); r = cg_pid_get_machine_name(pid.pid, &machine); - ASSERT_TRUE(r == 0 || r == -ENOENT); + if (!IN_SET(r, -ESRCH, -ENOENT)) + ASSERT_OK(r); - printf(PID_FMT"\t%s\t%s\t"UID_FMT"\t%s\t%s\t%s\t%s\t%s\n", - pid.pid, - path, - path_shifted, - uid, - session, - unit, - user_unit, - machine, - slice); + log_debug(PID_FMT": %s, %s, "UID_FMT", %s, %s, %s, %s, %s", + pid.pid, + path, + strna(path_shifted), + uid, + strna(session), + strna(unit), + strna(user_unit), + strna(machine), + strna(slice)); } }