summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-dhcp/test-dhcp-client.c140
-rw-r--r--src/libsystemd-dhcp/test-dhcp-option.c64
-rw-r--r--src/libsystemd/sd-rtnl/test-rtnl.c286
-rw-r--r--src/network/test-network.c28
4 files changed, 259 insertions, 259 deletions
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c
index 005d6c2a4c..8061e5fa83 100644
--- a/src/libsystemd-dhcp/test-dhcp-client.c
+++ b/src/libsystemd-dhcp/test-dhcp-client.c
@@ -56,50 +56,50 @@ static void test_request_basic(sd_event *e)
r = sd_dhcp_client_new(&client);
- assert(r >= 0);
- assert(client);
+ assert_se(r >= 0);
+ assert_se(client);
r = sd_dhcp_client_attach_event(client, e, 0);
- assert(r >= 0);
+ assert_se(r >= 0);
- assert(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
- assert(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
- assert(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
+ assert_se(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
+ assert_se(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
+ assert_se(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
- assert(sd_dhcp_client_set_index(client, 15) == 0);
- assert(sd_dhcp_client_set_index(client, -42) == -EINVAL);
- assert(sd_dhcp_client_set_index(client, -1) == 0);
+ assert_se(sd_dhcp_client_set_index(client, 15) == 0);
+ assert_se(sd_dhcp_client_set_index(client, -42) == -EINVAL);
+ assert_se(sd_dhcp_client_set_index(client, -1) == 0);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_SUBNET_MASK) == -EEXIST);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_ROUTER) == -EEXIST);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_HOST_NAME) == -EEXIST);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_DOMAIN_NAME) == -EEXIST);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_DOMAIN_NAME_SERVER)
== -EEXIST);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_NTP_SERVER) == -EEXIST);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_PAD) == -EINVAL);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_END) == -EINVAL);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_MESSAGE_TYPE) == -EINVAL);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_OVERLOAD) == -EINVAL);
- assert(sd_dhcp_client_set_request_option(client,
+ assert_se(sd_dhcp_client_set_request_option(client,
DHCP_OPTION_PARAMETER_REQUEST_LIST)
== -EINVAL);
- assert(sd_dhcp_client_set_request_option(client, 33) == 0);
- assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
- assert(sd_dhcp_client_set_request_option(client, 44) == 0);
- assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
+ assert_se(sd_dhcp_client_set_request_option(client, 33) == 0);
+ assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
+ assert_se(sd_dhcp_client_set_request_option(client, 44) == 0);
+ assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
}
static uint16_t client_checksum(void *buf, int len)
@@ -137,7 +137,7 @@ static void test_checksum(void)
if (verbose)
printf("* %s\n", __FUNCTION__);
- assert(client_checksum(&buf, 20) == be16toh(0x78ae));
+ assert_se(client_checksum(&buf, 20) == be16toh(0x78ae));
}
static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
@@ -153,20 +153,20 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
_cleanup_free_ DHCPPacket *discover;
uint16_t ip_check, udp_check;
- assert(s >= 0);
- assert(packet);
+ assert_se(s >= 0);
+ assert_se(packet);
size = sizeof(DHCPPacket) + 4;
- assert(len > size);
+ assert_se(len > size);
discover = memdup(packet, len);
- assert(discover->ip.ttl == IPDEFTTL);
- assert(discover->ip.protocol == IPPROTO_UDP);
- assert(discover->ip.saddr == INADDR_ANY);
- assert(discover->ip.daddr == INADDR_BROADCAST);
- assert(discover->udp.source == be16toh(DHCP_PORT_CLIENT));
- assert(discover->udp.dest == be16toh(DHCP_PORT_SERVER));
+ assert_se(discover->ip.ttl == IPDEFTTL);
+ assert_se(discover->ip.protocol == IPPROTO_UDP);
+ assert_se(discover->ip.saddr == INADDR_ANY);
+ assert_se(discover->ip.daddr == INADDR_BROADCAST);
+ assert_se(discover->udp.source == be16toh(DHCP_PORT_CLIENT));
+ assert_se(discover->udp.dest == be16toh(DHCP_PORT_SERVER));
ip_check = discover->ip.check;
@@ -174,21 +174,21 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
discover->ip.check = discover->udp.len;
udp_check = ~client_checksum(&discover->ip.ttl, len - 8);
- assert(udp_check == 0xffff);
+ assert_se(udp_check == 0xffff);
discover->ip.ttl = IPDEFTTL;
discover->ip.check = ip_check;
ip_check = ~client_checksum(&discover->ip, sizeof(discover->ip));
- assert(ip_check == 0xffff);
+ assert_se(ip_check == 0xffff);
- assert(discover->dhcp.xid);
- assert(memcmp(discover->dhcp.chaddr,
+ assert_se(discover->dhcp.xid);
+ assert_se(memcmp(discover->dhcp.chaddr,
&mac_addr.ether_addr_octet, 6) == 0);
size = len - sizeof(struct iphdr) - sizeof(struct udphdr);
- assert(callback_recv);
+ assert_se(callback_recv);
callback_recv(size, &discover->dhcp);
return 575;
@@ -218,7 +218,7 @@ static int test_discover_message_verify(size_t size, struct DHCPMessage *dhcp)
int res;
res = dhcp_option_parse(dhcp, size, check_options, NULL);
- assert(res == DHCP_DISCOVER);
+ assert_se(res == DHCP_DISCOVER);
if (verbose)
printf(" recv DHCP Discover 0x%08x\n", be32toh(dhcp->xid));
@@ -235,22 +235,22 @@ static void test_discover_message(sd_event *e)
printf("* %s\n", __FUNCTION__);
r = sd_dhcp_client_new(&client);
- assert(r >= 0);
- assert(client);
+ assert_se(r >= 0);
+ assert_se(client);
r = sd_dhcp_client_attach_event(client, e, 0);
- assert(r >= 0);
+ assert_se(r >= 0);
- assert(sd_dhcp_client_set_index(client, 42) >= 0);
- assert(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
+ assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
+ assert_se(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
- assert(sd_dhcp_client_set_request_option(client, 248) >= 0);
+ assert_se(sd_dhcp_client_set_request_option(client, 248) >= 0);
callback_recv = test_discover_message_verify;
res = sd_dhcp_client_start(client);
- assert(res == 0 || res == -EINPROGRESS);
+ assert_se(res == 0 || res == -EINPROGRESS);
sd_event_run(e, (uint64_t) -1);
@@ -358,22 +358,22 @@ static void test_addr_acq_acquired(sd_dhcp_client *client, int event,
sd_dhcp_lease *lease;
struct in_addr addr;
- assert(client);
- assert(event == DHCP_EVENT_IP_ACQUIRE);
+ assert_se(client);
+ assert_se(event == DHCP_EVENT_IP_ACQUIRE);
- assert(sd_dhcp_client_get_lease(client, &lease) >= 0);
- assert(lease);
+ assert_se(sd_dhcp_client_get_lease(client, &lease) >= 0);
+ assert_se(lease);
- assert(sd_dhcp_lease_get_address(lease, &addr) >= 0);
- assert(memcmp(&addr.s_addr, &test_addr_acq_ack[44],
+ assert_se(sd_dhcp_lease_get_address(lease, &addr) >= 0);
+ assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[44],
sizeof(addr.s_addr)) == 0);
- assert(sd_dhcp_lease_get_netmask(lease, &addr) >= 0);
- assert(memcmp(&addr.s_addr, &test_addr_acq_ack[285],
+ assert_se(sd_dhcp_lease_get_netmask(lease, &addr) >= 0);
+ assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[285],
sizeof(addr.s_addr)) == 0);
- assert(sd_dhcp_lease_get_router(lease, &addr) >= 0);
- assert(memcmp(&addr.s_addr, &test_addr_acq_ack[308],
+ assert_se(sd_dhcp_lease_get_router(lease, &addr) >= 0);
+ assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[308],
sizeof(addr.s_addr)) == 0);
if (verbose)
@@ -388,8 +388,8 @@ static int test_addr_acq_recv_request(size_t size, DHCPMessage *request)
int res;
res = dhcp_option_parse(request, size, check_options, NULL);
- assert(res == DHCP_REQUEST);
- assert(xid == request->xid);
+ assert_se(res == DHCP_REQUEST);
+ assert_se(xid == request->xid);
if (verbose)
printf(" recv DHCP Request 0x%08x\n", be32toh(xid));
@@ -403,7 +403,7 @@ static int test_addr_acq_recv_request(size_t size, DHCPMessage *request)
res = write(test_fd[1], test_addr_acq_ack,
sizeof(test_addr_acq_ack));
- assert(res == sizeof(test_addr_acq_ack));
+ assert_se(res == sizeof(test_addr_acq_ack));
if (verbose)
printf(" send DHCP Ack\n");
@@ -417,7 +417,7 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover)
int res;
res = dhcp_option_parse(discover, size, check_options, NULL);
- assert(res == DHCP_DISCOVER);
+ assert_se(res == DHCP_DISCOVER);
xid = discover->xid;
@@ -433,7 +433,7 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover)
res = write(test_fd[1], test_addr_acq_offer,
sizeof(test_addr_acq_offer));
- assert(res == sizeof(test_addr_acq_offer));
+ assert_se(res == sizeof(test_addr_acq_offer));
if (verbose)
printf(" send DHCP Offer\n");
@@ -450,22 +450,22 @@ static void test_addr_acq(sd_event *e)
printf("* %s\n", __FUNCTION__);
r = sd_dhcp_client_new(&client);
- assert(r >= 0);
- assert(client);
+ assert_se(r >= 0);
+ assert_se(client);
r = sd_dhcp_client_attach_event(client, e, 0);
- assert(r >= 0);
+ assert_se(r >= 0);
- assert(sd_dhcp_client_set_index(client, 42) >= 0);
- assert(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
+ assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
+ assert_se(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
- assert(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e)
+ assert_se(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e)
>= 0);
callback_recv = test_addr_acq_recv_discover;
res = sd_dhcp_client_start(client);
- assert(res == 0 || res == -EINPROGRESS);
+ assert_se(res == 0 || res == -EINPROGRESS);
sd_event_loop(e);
@@ -484,7 +484,7 @@ int main(int argc, char *argv[])
{
sd_event *e;
- assert(sd_event_new(&e) >= 0);
+ assert_se(sd_event_new(&e) >= 0);
test_request_basic(e);
test_checksum();
diff --git a/src/libsystemd-dhcp/test-dhcp-option.c b/src/libsystemd-dhcp/test-dhcp-option.c
index ac0b0a435a..8659fd5025 100644
--- a/src/libsystemd-dhcp/test-dhcp-option.c
+++ b/src/libsystemd-dhcp/test-dhcp-option.c
@@ -77,8 +77,8 @@ static void test_invalid_buffer_length(void)
{
DHCPMessage message;
- assert(dhcp_option_parse(&message, 0, NULL, NULL) == -EINVAL);
- assert(dhcp_option_parse(&message, sizeof(DHCPMessage), NULL, NULL)
+ assert_se(dhcp_option_parse(&message, 0, NULL, NULL) == -EINVAL);
+ assert_se(dhcp_option_parse(&message, sizeof(DHCPMessage), NULL, NULL)
== -EINVAL);
}
@@ -93,14 +93,14 @@ static void test_cookie(void)
opt = (uint8_t *)(message + 1);
opt[0] = 0xff;
- assert(dhcp_option_parse(message, len, NULL, NULL) == -EINVAL);
+ assert_se(dhcp_option_parse(message, len, NULL, NULL) == -EINVAL);
opt[0] = 99;
opt[1] = 130;
opt[2] = 83;
opt[3] = 99;
- assert(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
+ assert_se(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
}
static DHCPMessage *create_message(uint8_t *options, uint16_t optlen,
@@ -160,15 +160,15 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
uint8_t optlen = 0;
uint8_t i;
- assert((!desc && !code && !len) || desc);
+ assert_se((!desc && !code && !len) || desc);
if (!desc)
return -EINVAL;
- assert(code != DHCP_OPTION_PAD);
- assert(code != DHCP_OPTION_END);
- assert(code != DHCP_OPTION_MESSAGE_TYPE);
- assert(code != DHCP_OPTION_OVERLOAD);
+ assert_se(code != DHCP_OPTION_PAD);
+ assert_se(code != DHCP_OPTION_END);
+ assert_se(code != DHCP_OPTION_MESSAGE_TYPE);
+ assert_se(code != DHCP_OPTION_OVERLOAD);
while (desc->pos >= 0 || desc->filepos >= 0 || desc->snamepos >= 0) {
@@ -186,7 +186,7 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
descpos = &desc->snamepos;
}
- assert(descoption && desclen && descpos);
+ assert_se(descoption && desclen && descpos);
if (*desclen)
test_ignore_opts(descoption, descpos, desclen);
@@ -198,8 +198,8 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
*descpos = -1;
}
- assert(descpos);
- assert(*descpos != -1);
+ assert_se(descpos);
+ assert_se(*descpos != -1);
optcode = descoption[*descpos];
optlen = descoption[*descpos + 1];
@@ -208,8 +208,8 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
printf("DHCP code %2d(%2d) len %2d(%2d) ", code, optcode,
len, optlen);
- assert(code == optcode);
- assert(len == optlen);
+ assert_se(code == optcode);
+ assert_se(len == optlen);
for (i = 0; i < len; i++) {
@@ -217,7 +217,7 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
printf("0x%02x(0x%02x) ", option[i],
descoption[*descpos + 2 + i]);
- assert(option[i] == descoption[*descpos + 2 + i]);
+ assert_se(option[i] == descoption[*descpos + 2 + i]);
}
if (verbose)
@@ -272,17 +272,17 @@ static void test_options(struct option_desc *desc)
buflen = sizeof(DHCPMessage) + 4 + optlen;
if (!desc) {
- assert((res = dhcp_option_parse(message, buflen,
+ assert_se((res = dhcp_option_parse(message, buflen,
test_options_cb,
NULL)) == -ENOMSG);
} else if (desc->success) {
- assert((res = dhcp_option_parse(message, buflen,
+ assert_se((res = dhcp_option_parse(message, buflen,
test_options_cb,
desc)) >= 0);
- assert(desc->pos == -1 && desc->filepos == -1 &&
+ assert_se(desc->pos == -1 && desc->filepos == -1 &&
desc->snamepos == -1);
} else
- assert((res = dhcp_option_parse(message, buflen,
+ assert_se((res = dhcp_option_parse(message, buflen,
test_options_cb,
desc)) < 0);
@@ -311,22 +311,22 @@ static void test_option_set(void)
int pos, i;
uint8_t *opt;
- assert(dhcp_option_append(NULL, NULL, 0, 0, NULL) == -EINVAL);
+ assert_se(dhcp_option_append(NULL, NULL, 0, 0, NULL) == -EINVAL);
len = 0;
opt = &result[0];
- assert(dhcp_option_append(&opt, NULL, 0, 0, NULL) == -EINVAL);
- assert(opt == &result[0] && len == 0);
+ assert_se(dhcp_option_append(&opt, NULL, 0, 0, NULL) == -EINVAL);
+ assert_se(opt == &result[0] && len == 0);
- assert(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
+ assert_se(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
0, NULL) == -ENOBUFS);
- assert(opt == &result[0] && len == 0);
+ assert_se(opt == &result[0] && len == 0);
opt = &result[4];
len = 1;
- assert(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
+ assert_se(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
0, NULL) >= 0);
- assert(opt == &result[5] && len == 0);
+ assert_se(opt == &result[5] && len == 0);
pos = 4;
len = 60;
@@ -334,17 +334,17 @@ static void test_option_set(void)
opt = &result[pos];
oldlen = len;
- assert(dhcp_option_append(&opt, &len, options[pos],
+ assert_se(dhcp_option_append(&opt, &len, options[pos],
options[pos + 1],
&options[pos + 2]) >= 0);
if (options[pos] == DHCP_OPTION_PAD) {
- assert(opt == &result[pos + 1]);
- assert(len == oldlen - 1);
+ assert_se(opt == &result[pos + 1]);
+ assert_se(len == oldlen - 1);
pos++;
} else {
- assert(opt == &result[pos + 2 + options[pos + 1]]);
- assert(len == oldlen - 2 - options[pos + 1]);
+ assert_se(opt == &result[pos + 2 + options[pos + 1]]);
+ assert_se(len == oldlen - 2 - options[pos + 1]);
pos += 2 + options[pos + 1];
}
}
@@ -353,7 +353,7 @@ static void test_option_set(void)
if (verbose)
printf("%2d: 0x%02x(0x%02x)\n", i, result[i],
options[i]);
- assert(result[i] == options[i]);
+ assert_se(result[i] == options[i]);
}
if (verbose)
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index 497cefd4f9..dd74e76ed4 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -37,24 +37,24 @@ static void test_link_configure(sd_rtnl *rtnl, int ifindex) {
void *data;
/* we'd really like to test NEWLINK, but let's not mess with the running kernel */
- assert(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
- assert(sd_rtnl_message_append_string(message, IFLA_IFNAME, name) >= 0);
- assert(sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
- assert(sd_rtnl_message_append_u32(message, IFLA_MTU, mtu) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_rtnl_message_append_string(message, IFLA_IFNAME, name) >= 0);
+ assert_se(sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
+ assert_se(sd_rtnl_message_append_u32(message, IFLA_MTU, mtu) >= 0);
- assert(sd_rtnl_call(rtnl, message, 0, NULL) == 1);
+ assert_se(sd_rtnl_call(rtnl, message, 0, NULL) == 1);
- assert(sd_rtnl_message_read(message, &type, &data) > 0);
- assert(type == IFLA_IFNAME);
- assert(streq(name, (char *) data));
+ assert_se(sd_rtnl_message_read(message, &type, &data) > 0);
+ assert_se(type == IFLA_IFNAME);
+ assert_se(streq(name, (char *) data));
- assert(sd_rtnl_message_read(message, &type, &data) > 0);
- assert(type == IFLA_ADDRESS);
- assert(streq(mac, ether_ntoa(data)));
+ assert_se(sd_rtnl_message_read(message, &type, &data) > 0);
+ assert_se(type == IFLA_ADDRESS);
+ assert_se(streq(mac, ether_ntoa(data)));
- assert(sd_rtnl_message_read(message, &type, &data) > 0);
- assert(type == IFLA_MTU);
- assert(mtu == *(unsigned int *) data);
+ assert_se(sd_rtnl_message_read(message, &type, &data) > 0);
+ assert_se(type == IFLA_MTU);
+ assert_se(mtu == *(unsigned int *) data);
}
static void test_link_get(sd_rtnl *rtnl, int ifindex) {
@@ -65,66 +65,66 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) {
void *data;
uint16_t type;
- assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
- assert(m);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+ assert_se(m);
/* u8 test cases */
- assert(sd_rtnl_message_append_u8(m, IFLA_CARRIER, 0) >= 0);
- assert(sd_rtnl_message_append_u8(m, IFLA_OPERSTATE, 0) >= 0);
- assert(sd_rtnl_message_append_u8(m, IFLA_LINKMODE, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u8(m, IFLA_CARRIER, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u8(m, IFLA_OPERSTATE, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u8(m, IFLA_LINKMODE, 0) >= 0);
/* u32 test cases */
- assert(sd_rtnl_message_append_u32(m, IFLA_MTU, mtu) >= 0);
- assert(sd_rtnl_message_append_u32(m, IFLA_GROUP, 0) >= 0);
- assert(sd_rtnl_message_append_u32(m, IFLA_TXQLEN, 0) >= 0);
- assert(sd_rtnl_message_append_u32(m, IFLA_NUM_TX_QUEUES, 0) >= 0);
- assert(sd_rtnl_message_append_u32(m, IFLA_NUM_RX_QUEUES, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u32(m, IFLA_MTU, mtu) >= 0);
+ assert_se(sd_rtnl_message_append_u32(m, IFLA_GROUP, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u32(m, IFLA_TXQLEN, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u32(m, IFLA_NUM_TX_QUEUES, 0) >= 0);
+ assert_se(sd_rtnl_message_append_u32(m, IFLA_NUM_RX_QUEUES, 0) >= 0);
- assert(sd_rtnl_call(rtnl, m, -1, &r) == 1);
+ assert_se(sd_rtnl_call(rtnl, m, -1, &r) == 1);
/* u8 read back */
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_CARRIER);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_CARRIER);
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_OPERSTATE);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_OPERSTATE);
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_LINKMODE);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_LINKMODE);
/* u32 read back */
- assert(sd_rtnl_message_read(m, &type, (void **) &mtu_reply) == 1);
- assert(type == IFLA_MTU);
- assert(*mtu_reply == mtu);
+ assert_se(sd_rtnl_message_read(m, &type, (void **) &mtu_reply) == 1);
+ assert_se(type == IFLA_MTU);
+ assert_se(*mtu_reply == mtu);
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_GROUP);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_GROUP);
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_TXQLEN);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_TXQLEN);
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_NUM_TX_QUEUES);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_NUM_TX_QUEUES);
- assert(sd_rtnl_message_read(m, &type, &data) == 1);
- assert(type == IFLA_NUM_RX_QUEUES);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+ assert_se(type == IFLA_NUM_RX_QUEUES);
while (sd_rtnl_message_read(r, &type, &data) > 0) {
switch (type) {
// case IFLA_MTU:
-// assert(*(unsigned int *) data == 65536);
+// assert_se(*(unsigned int *) data == 65536);
// break;
// case IFLA_QDISC:
-// assert(streq((char *) data, "noqueue"));
+// assert_se(streq((char *) data, "noqueue"));
// break;
case IFLA_IFNAME:
- assert(streq((char *) data, "lo"));
+ assert_se(streq((char *) data, "lo"));
break;
}
}
- assert(sd_rtnl_flush(rtnl) >= 0);
- assert((m = sd_rtnl_message_unref(m)) == NULL);
+ assert_se(sd_rtnl_flush(rtnl) >= 0);
+ assert_se((m = sd_rtnl_message_unref(m)) == NULL);
}
@@ -156,22 +156,22 @@ static void test_route(void) {
return;
}
- assert(rtnl_message_seal(NULL, req) >= 0);
+ assert_se(rtnl_message_seal(NULL, req) >= 0);
- assert(sd_rtnl_message_read(req, &type, &data) > 0);
- assert(type == RTA_GATEWAY);
- assert(((struct in_addr *)data)->s_addr == addr.s_addr);
+ assert_se(sd_rtnl_message_read(req, &type, &data) > 0);
+ assert_se(type == RTA_GATEWAY);
+ assert_se(((struct in_addr *)data)->s_addr == addr.s_addr);
- assert(sd_rtnl_message_read(req, &type, &data) > 0);
- assert(type == RTA_OIF);
- assert(*(uint32_t *) data == index);
+ assert_se(sd_rtnl_message_read(req, &type, &data) > 0);
+ assert_se(type == RTA_OIF);
+ assert_se(*(uint32_t *) data == index);
}
static void test_multiple(void) {
sd_rtnl *rtnl1, *rtnl2;
- assert(sd_rtnl_open(&rtnl1, 0) >= 0);
- assert(sd_rtnl_open(&rtnl2, 0) >= 0);
+ assert_se(sd_rtnl_open(&rtnl1, 0) >= 0);
+ assert_se(sd_rtnl_open(&rtnl2, 0) >= 0);
rtnl1 = sd_rtnl_unref(rtnl1);
rtnl2 = sd_rtnl_unref(rtnl2);
@@ -182,8 +182,8 @@ static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
uint16_t type;
char *ifname = userdata;
- assert(rtnl);
- assert(m);
+ assert_se(rtnl);
+ assert_se(m);
log_info("got link info about %s", ifname);
free(ifname);
@@ -191,13 +191,13 @@ static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
while (sd_rtnl_message_read(m, &type, &data) > 0) {
switch (type) {
// case IFLA_MTU:
-// assert(*(unsigned int *) data == 65536);
+// assert_se(*(unsigned int *) data == 65536);
// break;
// case IFLA_QDISC:
-// assert(streq((char *) data, "noqueue"));
+// assert_se(streq((char *) data, "noqueue"));
// break;
case IFLA_IFNAME:
- assert(streq((char *) data, "lo"));
+ assert_se(streq((char *) data, "lo"));
break;
}
}
@@ -212,20 +212,20 @@ static void test_event_loop(int ifindex) {
char *ifname;
ifname = strdup("lo2");
- assert(ifname);
+ assert_se(ifname);
- assert(sd_rtnl_open(&rtnl, 0) >= 0);
- assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
- assert(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
+ assert_se(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
- assert(sd_event_default(&event) >= 0);
+ assert_se(sd_event_default(&event) >= 0);
- assert(sd_rtnl_attach_event(rtnl, event, 0) >= 0);
+ assert_se(sd_rtnl_attach_event(rtnl, event, 0) >= 0);
- assert(sd_event_run(event, 0) >= 0);
+ assert_se(sd_event_run(event, 0) >= 0);
- assert(sd_rtnl_detach_event(rtnl) >= 0);
+ assert_se(sd_rtnl_detach_event(rtnl) >= 0);
}
static int pipe_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
@@ -245,16 +245,16 @@ static void test_async(int ifindex) {
char *ifname;
ifname = strdup("lo");
- assert(ifname);
+ assert_se(ifname);
- assert(sd_rtnl_open(&rtnl, 0) >= 0);
+ assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
- assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
- assert(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
+ assert_se(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
- assert(sd_rtnl_wait(rtnl, 0) >= 0);
- assert(sd_rtnl_process(rtnl, &r) >= 0);
+ assert_se(sd_rtnl_wait(rtnl, 0) >= 0);
+ assert_se(sd_rtnl_process(rtnl, &r) >= 0);
}
static void test_pipe(int ifindex) {
@@ -262,20 +262,20 @@ static void test_pipe(int ifindex) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *m1 = NULL, *m2 = NULL;
int counter = 0;
- assert(sd_rtnl_open(&rtnl, 0) >= 0);
+ assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
- assert(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
- assert(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0);
counter ++;
- assert(sd_rtnl_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
+ assert_se(sd_rtnl_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
counter ++;
- assert(sd_rtnl_call_async(rtnl, m2, &pipe_handler, &counter, 0, NULL) >= 0);
+ assert_se(sd_rtnl_call_async(rtnl, m2, &pipe_handler, &counter, 0, NULL) >= 0);
while (counter > 0) {
- assert(sd_rtnl_wait(rtnl, 0) >= 0);
- assert(sd_rtnl_process(rtnl, NULL) >= 0);
+ assert_se(sd_rtnl_wait(rtnl, 0) >= 0);
+ assert_se(sd_rtnl_process(rtnl, NULL) >= 0);
}
}
@@ -284,54 +284,54 @@ static void test_container(void) {
uint16_t type;
void *data;
- assert(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
-
- assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
- assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
- assert(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
- assert(sd_rtnl_message_close_container(m) >= 0);
- assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
- assert(sd_rtnl_message_close_container(m) >= 0);
- assert(sd_rtnl_message_close_container(m) == -EINVAL);
-
- assert(rtnl_message_seal(NULL, m) >= 0);
-
- assert(sd_rtnl_message_read(m, &type, &data) >= 0);
- assert(type == IFLA_LINKINFO);
- assert(data == NULL);
- assert(sd_rtnl_message_read(m, &type, &data) >= 0);
- assert(type == IFLA_INFO_KIND);
- assert(streq("kind", (char *)data));
- assert(sd_rtnl_message_read(m, &type, &data) >= 0);
- assert(type == IFLA_INFO_DATA);
- assert(data == NULL);
- assert(sd_rtnl_message_read(m, &type, &data) >= 0);
- assert(type == IFLA_VLAN_ID);
- assert(*(uint16_t *)data == 100);
- assert(sd_rtnl_message_read(m, &type, &data) == 0);
- assert(sd_rtnl_message_exit_container(m) >= 0);
- assert(sd_rtnl_message_read(m, &type, &data) >= 0);
- assert(type == IFLA_INFO_KIND);
- assert(streq("kind", (char *)data));
- assert(sd_rtnl_message_read(m, &type, &data) == 0);
- assert(sd_rtnl_message_exit_container(m) >= 0);
- assert(sd_rtnl_message_exit_container(m) == -EINVAL);
+ assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
+
+ assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
+ assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
+ assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
+ assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
+ assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
+ assert_se(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
+ assert_se(sd_rtnl_message_close_container(m) >= 0);
+ assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
+ assert_se(sd_rtnl_message_close_container(m) >= 0);
+ assert_se(sd_rtnl_message_close_container(m) == -EINVAL);
+
+ assert_se(rtnl_message_seal(NULL, m) >= 0);
+
+ assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+ assert_se(type == IFLA_LINKINFO);
+ assert_se(data == NULL);
+ assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+ assert_se(type == IFLA_INFO_KIND);
+ assert_se(streq("kind", (char *)data));
+ assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+ assert_se(type == IFLA_INFO_DATA);
+ assert_se(data == NULL);
+ assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+ assert_se(type == IFLA_VLAN_ID);
+ assert_se(*(uint16_t *)data == 100);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
+ assert_se(sd_rtnl_message_exit_container(m) >= 0);
+ assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+ assert_se(type == IFLA_INFO_KIND);
+ assert_se(streq("kind", (char *)data));
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
+ assert_se(sd_rtnl_message_exit_container(m) >= 0);
+ assert_se(sd_rtnl_message_exit_container(m) == -EINVAL);
}
static void test_match(void) {
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
- assert(sd_rtnl_open(&rtnl, 0) >= 0);
+ assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
- assert(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
- assert(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+ assert_se(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+ assert_se(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
- assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
- assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
- assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
+ assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+ assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+ assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
}
int main(void) {
@@ -350,11 +350,11 @@ int main(void) {
test_container();
- assert(sd_rtnl_open(&rtnl, 0) >= 0);
- assert(rtnl);
+ assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
+ assert_se(rtnl);
if_loopback = (int) if_nametoindex("lo");
- assert(if_loopback > 0);
+ assert_se(if_loopback > 0);
test_async(if_loopback);
@@ -364,31 +364,31 @@ int main(void) {
test_link_configure(rtnl, if_loopback);
- assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0);
- assert(m);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0);
+ assert_se(m);
- assert(sd_rtnl_message_get_type(m, &type) >= 0);
- assert(type == RTM_GETLINK);
+ assert_se(sd_rtnl_message_get_type(m, &type) >= 0);
+ assert_se(type == RTM_GETLINK);
- assert(sd_rtnl_message_read(m, &type, &data) == -EPERM);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == -EPERM);
- assert(sd_rtnl_call(rtnl, m, 0, &r) == 1);
- assert(sd_rtnl_message_get_type(r, &type) >= 0);
- assert(type == RTM_NEWLINK);
+ assert_se(sd_rtnl_call(rtnl, m, 0, &r) == 1);
+ assert_se(sd_rtnl_message_get_type(r, &type) >= 0);
+ assert_se(type == RTM_NEWLINK);
- assert(sd_rtnl_message_read(m, &type, &data) == 0);
- assert((r = sd_rtnl_message_unref(r)) == NULL);
+ assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
+ assert_se((r = sd_rtnl_message_unref(r)) == NULL);
- assert(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM);
- assert((m = sd_rtnl_message_unref(m)) == NULL);
- assert((r = sd_rtnl_message_unref(r)) == NULL);
+ assert_se(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM);
+ assert_se((m = sd_rtnl_message_unref(m)) == NULL);
+ assert_se((r = sd_rtnl_message_unref(r)) == NULL);
test_link_get(rtnl, if_loopback);
- assert(sd_rtnl_flush(rtnl) >= 0);
- assert((m = sd_rtnl_message_unref(m)) == NULL);
- assert((r = sd_rtnl_message_unref(r)) == NULL);
- assert((rtnl = sd_rtnl_unref(rtnl)) == NULL);
+ assert_se(sd_rtnl_flush(rtnl) >= 0);
+ assert_se((m = sd_rtnl_message_unref(m)) == NULL);
+ assert_se((r = sd_rtnl_message_unref(r)) == NULL);
+ assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
return EXIT_SUCCESS;
}
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 5e279974cb..46afeec926 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -27,8 +27,8 @@ static void test_link(struct udev_device *loopback) {
manager_new(&manager);
- assert(link_new(manager, loopback, &link) >= 0);
- assert(link);
+ assert_se(link_new(manager, loopback, &link) >= 0);
+ assert_se(link);
}
static void test_load_config(Manager *manager) {
@@ -36,10 +36,10 @@ static void test_load_config(Manager *manager) {
* so we can't do this test here, move it to a test for paths_check_timestamps
* directly
*
- * assert(network_should_reload(manager) == true);
+ * assert_se(network_should_reload(manager) == true);
*/
- assert(manager_load_config(manager) >= 0);
- assert(manager_should_reload(manager) == false);
+ assert_se(manager_load_config(manager) >= 0);
+ assert_se(manager_should_reload(manager) == false);
}
static void test_network_get(Manager *manager, struct udev_device *loopback) {
@@ -47,8 +47,8 @@ static void test_network_get(Manager *manager, struct udev_device *loopback) {
/* let's assume that the test machine does not have a .network file
that applies to the loopback device... */
- assert(network_get(manager, loopback, &network) == -ENOENT);
- assert(!network);
+ assert_se(network_get(manager, loopback, &network) == -ENOENT);
+ assert_se(!network);
}
int main(void) {
@@ -56,24 +56,24 @@ int main(void) {
struct udev *udev;
struct udev_device *loopback;
- assert(manager_new(&manager) >= 0);
+ assert_se(manager_new(&manager) >= 0);
test_load_config(manager);
udev = udev_new();
- assert(udev);
+ assert_se(udev);
loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
- assert(loopback);
- assert(udev_device_get_ifindex(loopback) == 1);
+ assert_se(loopback);
+ assert_se(udev_device_get_ifindex(loopback) == 1);
test_network_get(manager, loopback);
test_link(loopback);
- assert(manager_udev_listen(manager) >= 0);
- assert(manager_udev_enumerate_links(manager) >= 0);
- assert(manager_rtnl_listen(manager) >= 0);
+ assert_se(manager_udev_listen(manager) >= 0);
+ assert_se(manager_udev_enumerate_links(manager) >= 0);
+ assert_se(manager_rtnl_listen(manager) >= 0);
udev_device_unref(loopback);
udev_unref(udev);