mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
test/gnrc_udp: add test for sock_udp_sendv()
This commit is contained in:
parent
b822e8a5a9
commit
489434b951
@ -629,6 +629,37 @@ static void test_sock_udp_send__socketed(void)
|
||||
expect(_check_net());
|
||||
}
|
||||
|
||||
static void test_sock_udp_sendv__socketed(void)
|
||||
{
|
||||
static const ipv6_addr_t src_addr = { .u8 = _TEST_ADDR_LOCAL };
|
||||
static const ipv6_addr_t dst_addr = { .u8 = _TEST_ADDR_REMOTE };
|
||||
static const sock_udp_ep_t local = { .addr = { .ipv6 = _TEST_ADDR_LOCAL },
|
||||
.family = AF_INET6,
|
||||
.netif = _TEST_NETIF,
|
||||
.port = _TEST_PORT_LOCAL };
|
||||
static const sock_udp_ep_t remote = { .addr = { .ipv6 = _TEST_ADDR_REMOTE },
|
||||
.family = AF_INET6,
|
||||
.port = _TEST_PORT_REMOTE };
|
||||
const iolist_t tail = {
|
||||
.iol_base = "EFGH",
|
||||
.iol_len = sizeof("EFGH"),
|
||||
};
|
||||
|
||||
const iolist_t head = {
|
||||
.iol_next = (void *)&tail,
|
||||
.iol_base = "ABCD",
|
||||
.iol_len = sizeof("ABCD") - 1,
|
||||
};
|
||||
|
||||
expect(0 == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
|
||||
expect(sizeof("ABCDEFGH") == sock_udp_sendv(&_sock, &head, NULL));
|
||||
expect(_check_packet(&src_addr, &dst_addr, _TEST_PORT_LOCAL,
|
||||
_TEST_PORT_REMOTE, "ABCDEFGH", sizeof("ABCDEFGH"),
|
||||
_TEST_NETIF, false));
|
||||
xtimer_usleep(1000); /* let GNRC stack finish */
|
||||
expect(_check_net());
|
||||
}
|
||||
|
||||
static void test_sock_udp_send__socketed_other_remote(void)
|
||||
{
|
||||
static const ipv6_addr_t src_addr = { .u8 = _TEST_ADDR_LOCAL };
|
||||
@ -808,6 +839,7 @@ int main(void)
|
||||
CALL(test_sock_udp_send__socketed_no_netif());
|
||||
CALL(test_sock_udp_send__socketed_no_local());
|
||||
CALL(test_sock_udp_send__socketed());
|
||||
CALL(test_sock_udp_sendv__socketed());
|
||||
CALL(test_sock_udp_send__socketed_other_remote());
|
||||
CALL(test_sock_udp_send__unsocketed_no_local_no_netif());
|
||||
CALL(test_sock_udp_send__unsocketed_no_netif());
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
static msg_t _msg_queue[_MSG_QUEUE_SIZE];
|
||||
static gnrc_netreg_entry_t _udp_handler;
|
||||
static char _rx_buf[32];
|
||||
|
||||
void _net_init(void)
|
||||
{
|
||||
@ -130,9 +131,11 @@ bool _check_packet(const ipv6_addr_t *src, const ipv6_addr_t *dst,
|
||||
void *data, size_t data_len, uint16_t iface,
|
||||
bool random_src_port)
|
||||
{
|
||||
gnrc_pktsnip_t *pkt, *ipv6, *udp;
|
||||
gnrc_pktsnip_t *pkt, *ipv6, *udp, *payload;
|
||||
ipv6_hdr_t *ipv6_hdr;
|
||||
udp_hdr_t *udp_hdr;
|
||||
size_t payload_len;
|
||||
char *payload_buf;
|
||||
msg_t msg;
|
||||
|
||||
msg_receive(&msg);
|
||||
@ -164,12 +167,22 @@ bool _check_packet(const ipv6_addr_t *src, const ipv6_addr_t *dst,
|
||||
return _res(pkt, false);
|
||||
}
|
||||
udp_hdr = udp->data;
|
||||
|
||||
payload = udp->next;
|
||||
payload_buf = _rx_buf;
|
||||
while (payload) {
|
||||
memcpy(payload_buf, payload->data, payload->size);
|
||||
payload_buf += payload->size;
|
||||
payload = payload->next;
|
||||
}
|
||||
payload_len = payload_buf - _rx_buf;
|
||||
|
||||
return _res(pkt, (memcmp(src, &ipv6_hdr->src, sizeof(ipv6_addr_t)) == 0) &&
|
||||
(memcmp(dst, &ipv6_hdr->dst, sizeof(ipv6_addr_t)) == 0) &&
|
||||
(ipv6_hdr->nh == PROTNUM_UDP) &&
|
||||
(random_src_port || (src_port == byteorder_ntohs(udp_hdr->src_port))) &&
|
||||
(dst_port == byteorder_ntohs(udp_hdr->dst_port)) &&
|
||||
(udp->next != NULL) &&
|
||||
(data_len == udp->next->size) &&
|
||||
(memcmp(data, udp->next->data, data_len) == 0));
|
||||
(data_len ==payload_len ) &&
|
||||
(memcmp(data, _rx_buf, data_len) == 0));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user