1 Star 0 Fork 49

问书/systemd_bak

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0709-test-add-a-test-for-sd_netlink_message_-append-read-.patch 2.57 KB
一键复制 编辑 原始数据 按行查看 历史
geliwei 提交于 2022-04-13 15:44 . update to systemd-239-58.el8.src.rpm
From 58d0d77ddda4c02943d1f03e4c142aec9c4930f5 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sun, 15 Dec 2019 21:48:12 +0900
Subject: [PATCH] test: add a test for sd_netlink_message_{append,read}_strv()
(cherry picked from commit d08d92d5ee508a80e35d6b95b962bd09527fb5f2)
Related: #2005008
---
src/libsystemd/sd-netlink/test-netlink.c | 33 ++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/libsystemd/sd-netlink/test-netlink.c b/src/libsystemd/sd-netlink/test-netlink.c
index 03773fb936..8ee6551385 100644
--- a/src/libsystemd/sd-netlink/test-netlink.c
+++ b/src/libsystemd/sd-netlink/test-netlink.c
@@ -10,7 +10,9 @@
#include "missing.h"
#include "netlink-util.h"
#include "socket-util.h"
+#include "stdio-util.h"
#include "string-util.h"
+#include "strv.h"
#include "util.h"
static void test_message_link_bridge(sd_netlink *rtnl) {
@@ -357,6 +359,36 @@ static void test_message(sd_netlink *rtnl) {
assert_se(sd_netlink_message_get_errno(m) == -ETIMEDOUT);
}
+static void test_strv(sd_netlink *rtnl) {
+ _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
+ _cleanup_strv_free_ char **names_in = NULL, **names_out;
+ const char *p;
+
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_NEWLINKPROP, 1) >= 0);
+
+ for (unsigned i = 0; i < 10; i++) {
+ char name[STRLEN("hoge") + DECIMAL_STR_MAX(uint32_t)];
+
+ xsprintf(name, "hoge%" PRIu32, i + 1000);
+ assert_se(strv_extend(&names_in, name) >= 0);
+ }
+
+ assert_se(sd_netlink_message_open_container(m, IFLA_PROP_LIST) >= 0);
+ assert_se(sd_netlink_message_append_strv(m, IFLA_ALT_IFNAME, names_in) >= 0);
+ assert_se(sd_netlink_message_close_container(m) >= 0);
+
+ rtnl_message_seal(m);
+ assert_se(sd_netlink_message_rewind(m) >= 0);
+
+ assert_se(sd_netlink_message_read_strv(m, IFLA_PROP_LIST, IFLA_ALT_IFNAME, &names_out) >= 0);
+ assert_se(strv_equal(names_in, names_out));
+
+ assert_se(sd_netlink_message_enter_container(m, IFLA_PROP_LIST) >= 0);
+ assert_se(sd_netlink_message_read_string(m, IFLA_ALT_IFNAME, &p) >= 0);
+ assert_se(streq(p, "hoge1009"));
+ assert_se(sd_netlink_message_exit_container(m) >= 0);
+}
+
int main(void) {
sd_netlink *rtnl;
sd_netlink_message *m;
@@ -377,6 +409,7 @@ int main(void) {
test_message(rtnl);
test_container(rtnl);
+ test_strv(rtnl);
if_loopback = (int) if_nametoindex("lo");
assert_se(if_loopback > 0);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Weisson/systemd_bak.git
git@gitee.com:Weisson/systemd_bak.git
Weisson
systemd_bak
systemd_bak
a8

搜索帮助

0d507c66 1850385 C8b1a773 1850385