1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

test: add usual log messages in test-netlink

This commit is contained in:
Yu Watanabe 2021-06-29 15:33:58 +09:00
parent 9d7fbec1e5
commit 0c45a60f8e

View File

@ -14,12 +14,14 @@
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
#include "tests.h"
static void test_message_link_bridge(sd_netlink *rtnl) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
uint32_t cost;
log_debug("/* %s */", __func__);
assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_NEWLINK, 1) >= 0);
assert_se(sd_rtnl_message_link_set_family(message, AF_BRIDGE) >= 0);
assert_se(sd_netlink_message_open_container(message, IFLA_PROTINFO) >= 0);
@ -40,6 +42,8 @@ static void test_link_configure(sd_netlink *rtnl, int ifindex) {
const char *name_out;
struct ether_addr mac_out;
log_debug("/* %s */", __func__);
/* we'd really like to test NEWLINK, but let's not mess with the running kernel */
assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
@ -57,6 +61,8 @@ static void test_link_get(sd_netlink *rtnl, int ifindex) {
uint32_t u32_data;
struct ether_addr eth_data;
log_debug("/* %s */", __func__);
assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
assert_se(m);
@ -83,6 +89,8 @@ static void test_address_get(sd_netlink *rtnl, int ifindex) {
struct ifa_cacheinfo cache;
const char *label;
log_debug("/* %s */", __func__);
assert_se(sd_rtnl_message_new_addr(rtnl, &m, RTM_GETADDR, ifindex, AF_INET) >= 0);
assert_se(m);
assert_se(sd_netlink_message_request_dump(m, true) >= 0);
@ -100,6 +108,8 @@ static void test_route(sd_netlink *rtnl) {
uint32_t index = 2, u32_data;
int r;
log_debug("/* %s */", __func__);
r = sd_rtnl_message_new_route(rtnl, &req, RTM_NEWROUTE, AF_INET, RTPROT_STATIC);
if (r < 0) {
log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
@ -134,6 +144,8 @@ static void test_route(sd_netlink *rtnl) {
static void test_multiple(void) {
sd_netlink *rtnl1, *rtnl2;
log_debug("/* %s */", __func__);
assert_se(sd_netlink_open(&rtnl1) >= 0);
assert_se(sd_netlink_open(&rtnl2) >= 0);
@ -164,6 +176,8 @@ static void test_event_loop(int ifindex) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
char *ifname;
log_debug("/* %s */", __func__);
ifname = strdup("lo2");
assert_se(ifname);
@ -194,6 +208,8 @@ static void test_async(int ifindex) {
const char *description;
char *ifname;
log_debug("/* %s */", __func__);
ifname = strdup("lo");
assert_se(ifname);
@ -225,6 +241,8 @@ static void test_slot_set(int ifindex) {
const char *description;
char *ifname;
log_debug("/* %s */", __func__);
ifname = strdup("lo");
assert_se(ifname);
@ -303,6 +321,8 @@ static void test_async_destroy_callback(int ifindex) {
_cleanup_(sd_netlink_slot_unrefp) sd_netlink_slot *slot = NULL;
char *ifname;
log_debug("/* %s */", __func__);
assert_se(t = new(struct test_async_object, 1));
assert_se(ifname = strdup("lo"));
*t = (struct test_async_object) {
@ -371,6 +391,8 @@ static void test_pipe(int ifindex) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m1 = NULL, *m2 = NULL;
int counter = 0;
log_debug("/* %s */", __func__);
assert_se(sd_netlink_open(&rtnl) >= 0);
assert_se(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
@ -396,6 +418,8 @@ static void test_container(sd_netlink *rtnl) {
uint32_t u32_data;
const char *string_data;
log_debug("/* %s */", __func__);
assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_NEWLINK, 0) >= 0);
assert_se(sd_netlink_message_open_container(m, IFLA_LINKINFO) >= 0);
@ -429,6 +453,8 @@ static void test_match(void) {
_cleanup_(sd_netlink_slot_unrefp) sd_netlink_slot *s1 = NULL, *s2 = NULL;
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
log_debug("/* %s */", __func__);
assert_se(sd_netlink_open(&rtnl) >= 0);
assert_se(sd_netlink_add_match(rtnl, &s1, RTM_NEWLINK, link_handler, NULL, NULL, NULL) >= 0);
@ -445,6 +471,8 @@ static void test_get_addresses(sd_netlink *rtnl) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
sd_netlink_message *m;
log_debug("/* %s */", __func__);
assert_se(sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC) >= 0);
assert_se(sd_netlink_message_request_dump(req, true) >= 0);
assert_se(sd_netlink_call(rtnl, req, 0, &reply) >= 0);
@ -472,6 +500,8 @@ static void test_get_addresses(sd_netlink *rtnl) {
static void test_message(sd_netlink *rtnl) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
log_debug("/* %s */", __func__);
assert_se(rtnl_message_new_synthetic_error(rtnl, -ETIMEDOUT, 1, &m) >= 0);
assert_se(sd_netlink_message_get_errno(m) == -ETIMEDOUT);
}
@ -480,6 +510,8 @@ static void test_array(void) {
_cleanup_(sd_netlink_unrefp) sd_netlink *genl = NULL;
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
log_debug("/* %s */", __func__);
assert_se(sd_genl_socket_open(&genl) >= 0);
assert_se(sd_genl_message_new(genl, SD_GENL_ID_CTRL, CTRL_CMD_GETFAMILY, &m) >= 0);
@ -522,6 +554,8 @@ static void test_strv(sd_netlink *rtnl) {
_cleanup_strv_free_ char **names_in = NULL, **names_out;
const char *p;
log_debug("/* %s */", __func__);
assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_NEWLINKPROP, 1) >= 0);
for (unsigned i = 0; i < 10; i++) {
@ -555,6 +589,8 @@ int main(void) {
int if_loopback;
uint16_t type;
test_setup_logging(LOG_DEBUG);
test_match();
test_multiple();