]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-udev-spawn: migrate to use ASSERT_XYZ()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 24 Nov 2024 07:13:04 +0000 (16:13 +0900)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 14 Dec 2024 06:47:14 +0000 (06:47 +0000)
src/udev/test-udev-spawn.c

index a6079e3c613d7ef40bdc82d3de86e2e52d9ff49e..b9674f955313d587ba63d22fe7dbdefb0dfbdff2 100644 (file)
@@ -14,13 +14,13 @@ static void test_event_spawn_core(bool with_pidfd, const char *cmd, char *result
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
         _cleanup_(udev_event_freep) UdevEvent *event = NULL;
 
-        assert_se(setenv("SYSTEMD_PIDFD", yes_no(with_pidfd), 1) >= 0);
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PIDFD", yes_no(with_pidfd), 1));
 
-        assert_se(sd_device_new_from_syspath(&dev, "/sys/class/net/lo") >= 0);
-        assert_se(event = udev_event_new(dev, NULL, EVENT_TEST_SPAWN));
-        assert_se(udev_event_spawn(event, false, cmd, result_buf, buf_size, NULL) == 0);
+        ASSERT_OK(sd_device_new_from_syspath(&dev, "/sys/class/net/lo"));
+        ASSERT_NOT_NULL(event = udev_event_new(dev, NULL, EVENT_TEST_SPAWN));
+        ASSERT_OK_ZERO(udev_event_spawn(event, false, cmd, result_buf, buf_size, NULL));
 
-        assert_se(unsetenv("SYSTEMD_PIDFD") >= 0);
+        ASSERT_OK_ERRNO(unsetenv("SYSTEMD_PIDFD"));
 }
 
 static void test_event_spawn_cat(bool with_pidfd, size_t buf_size) {
@@ -30,18 +30,18 @@ static void test_event_spawn_cat(bool with_pidfd, size_t buf_size) {
 
         log_debug("/* %s(%s) */", __func__, yes_no(with_pidfd));
 
-        assert_se(find_executable("cat", &cmd) >= 0);
-        assert_se(strextend_with_separator(&cmd, " ", "/sys/class/net/lo/uevent"));
+        ASSERT_OK(find_executable("cat", &cmd));
+        ASSERT_NOT_NULL(strextend_with_separator(&cmd, " ", "/sys/class/net/lo/uevent"));
 
         test_event_spawn_core(with_pidfd, cmd, result_buf,
                               buf_size >= BUF_SIZE ? BUF_SIZE : buf_size);
 
-        assert_se(lines = strv_split_newlines(result_buf));
+        ASSERT_NOT_NULL(lines = strv_split_newlines(result_buf));
         strv_print(lines);
 
         if (buf_size >= BUF_SIZE) {
-                assert_se(strv_contains(lines, "INTERFACE=lo"));
-                assert_se(strv_contains(lines, "IFINDEX=1"));
+                ASSERT_TRUE(strv_contains(lines, "INTERFACE=lo"));
+                ASSERT_TRUE(strv_contains(lines, "IFINDEX=1"));
         }
 }
 
@@ -53,15 +53,15 @@ static void test_event_spawn_self(const char *self, const char *arg, bool with_p
         log_debug("/* %s(%s, %s) */", __func__, arg, yes_no(with_pidfd));
 
         /* 'self' may contain spaces, hence needs to be quoted. */
-        assert_se(cmd = strjoin("'", self, "' ", arg));
+        ASSERT_NOT_NULL(cmd = strjoin("'", self, "' ", arg));
 
         test_event_spawn_core(with_pidfd, cmd, result_buf, BUF_SIZE);
 
-        assert_se(lines = strv_split_newlines(result_buf));
+        ASSERT_NOT_NULL(lines = strv_split_newlines(result_buf));
         strv_print(lines);
 
-        assert_se(strv_contains(lines, "aaa"));
-        assert_se(strv_contains(lines, "bbb"));
+        ASSERT_TRUE(strv_contains(lines, "aaa"));
+        ASSERT_TRUE(strv_contains(lines, "bbb"));
 }
 
 static void test1(void) {