1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

test-udev-spawn: migrate to use ASSERT_XYZ()

This commit is contained in:
Yu Watanabe 2024-11-24 16:13:04 +09:00 committed by Daan De Meyer
parent 130698dc20
commit 7edb1b42fc

View 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) {