1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #10107 from miri64/tests/fix/lwip-sock-stack

tests/lwip_sock_*: Stop main thread from overflowing
This commit is contained in:
Koen Zandberg 2018-10-17 20:26:31 +02:00 committed by GitHub
commit 8b2d295ab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 211 additions and 184 deletions

View File

@ -28,10 +28,19 @@ extern "C" {
#define _TEST_PROTO (254) /* https://tools.ietf.org/html/rfc3692#section-2.1 */
#define _TEST_NETIF (1)
#define _TEST_TIMEOUT (1000000U)
#define _TEST_ADDR4_LOCAL (0xc0a84f96U) /* 192.168.79.150 */
#define _TEST_ADDR4_REMOTE (0xc0a84f6bU) /* 192.168.79.107 */
#define _TEST_ADDR4_WRONG (0x254c6b4cU)
#define _TEST_ADDR4_MASK (0xffffff00U) /* 255.255.255.0 */
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define _TEST_ADDR4_LOCAL (0x964fa8c0U) /* 192.168.79.150 */
# define _TEST_ADDR4_REMOTE (0x6b4fa8c0U) /* 192.168.79.107 */
# define _TEST_ADDR4_WRONG (0x4c6b4c25U)
# define _TEST_ADDR4_MASK (0x00ffffffU) /* 255.255.255.0 */
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define _TEST_ADDR4_LOCAL (0xc0a84f96U) /* 192.168.79.150 */
# define _TEST_ADDR4_REMOTE (0xc0a84f6bU) /* 192.168.79.107 */
# define _TEST_ADDR4_WRONG (0x254c6b4cU)
# define _TEST_ADDR4_MASK (0xffffff00U) /* 255.255.255.0 */
#else
# error "Byte order is neither little nor big!"
#endif
#define _TEST_ADDR4_GW (0UL) /* so we can test unreachability */
#define _TEST_ADDR6_LOCAL { 0x2f, 0xc4, 0x11, 0x5a, 0xe6, 0x91, 0x8d, 0x5d, \
0x8c, 0xd1, 0x47, 0x07, 0xb7, 0x6f, 0x9b, 0x48 }

View File

@ -66,9 +66,9 @@ static void test_sock_ip_create4__EINVAL_addr(void)
static void test_sock_ip_create4__EINVAL_netif(void)
{
static const sock_ip_ep_t local = { .family = AF_INET, .netif = _TEST_NETIF };
const sock_ip_ep_t remote = { .family = AF_INET,
static const sock_ip_ep_t remote = { .family = AF_INET,
.netif = (_TEST_NETIF + 1),
.addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } };
.addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } };
assert(-EINVAL == sock_ip_create(&_sock, &local, &remote, _TEST_PROTO,
SOCK_FLAGS_REUSE_EP));
@ -122,8 +122,8 @@ static void test_sock_ip_create4__only_local_reuse_ep(void)
static void test_sock_ip_create4__only_remote(void)
{
const sock_ip_ep_t remote = { .family = AF_INET,
.addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } };
static const sock_ip_ep_t remote = { .family = AF_INET,
.addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } };
sock_ip_ep_t ep;
assert(0 == sock_ip_create(&_sock, NULL, &remote, _TEST_PROTO,
@ -132,15 +132,15 @@ static void test_sock_ip_create4__only_remote(void)
assert(0 == sock_ip_get_local(&_sock, &ep));
assert(0 == sock_ip_get_remote(&_sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
}
static void test_sock_ip_create4__full(void)
{
static const sock_ip_ep_t local = { .family = AF_INET, .netif = _TEST_NETIF };
const sock_ip_ep_t remote = { .family = AF_INET,
.addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } };
static const sock_ip_ep_t remote = { .family = AF_INET,
.addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } };
sock_ip_ep_t ep;
assert(0 == sock_ip_create(&_sock, &local, &remote, _TEST_PROTO,
@ -152,7 +152,7 @@ static void test_sock_ip_create4__full(void)
assert(_TEST_NETIF == ep.netif);
assert(0 == sock_ip_get_remote(&_sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
}
@ -205,7 +205,7 @@ static void test_sock_ip_recv4__ETIMEDOUT(void)
static void test_sock_ip_recv4__socketed(void)
{
static const sock_ip_ep_t local = { .family = AF_INET };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, &remote, _TEST_PROTO,
@ -220,7 +220,7 @@ static void test_sock_ip_recv4__socketed(void)
static void test_sock_ip_recv4__socketed_with_remote(void)
{
static const sock_ip_ep_t local = { .family = AF_INET };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
sock_ip_ep_t result;
@ -231,14 +231,14 @@ static void test_sock_ip_recv4__socketed_with_remote(void)
assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, &result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_NETIF == result.netif);
assert(_check_net());
}
static void test_sock_ip_recv4__unsocketed(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, NULL, _TEST_PROTO,
@ -262,7 +262,7 @@ static void test_sock_ip_recv4__unsocketed_with_remote(void)
assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, &result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_NETIF == result.netif);
assert(_check_net());
}
@ -280,7 +280,7 @@ static void test_sock_ip_recv4__with_timeout(void)
sizeof(_test_buffer), _TEST_TIMEOUT,
&result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_NETIF == result.netif);
assert(_check_net());
}
@ -297,14 +297,14 @@ static void test_sock_ip_recv4__non_blocking(void)
assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, &result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_NETIF == result.netif);
assert(_check_net());
}
static void test_sock_ip_send4__EAFNOSUPPORT(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_UNSPEC };
assert(-EAFNOSUPPORT == sock_ip_send(NULL, "ABCD", sizeof("ABCD"),
@ -314,7 +314,7 @@ static void test_sock_ip_send4__EAFNOSUPPORT(void)
static void test_sock_ip_send4__EINVAL_addr(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF };
static const sock_ip_ep_t remote = { .family = AF_INET,
@ -329,10 +329,10 @@ static void test_sock_ip_send4__EINVAL_addr(void)
static void test_sock_ip_send4__EINVAL_netif(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF + 1 };
@ -345,7 +345,7 @@ static void test_sock_ip_send4__EINVAL_netif(void)
static void test_sock_ip_send4__EHOSTUNREACH(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_WRONG) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_WRONG },
.family = AF_INET };
assert(-EHOSTUNREACH == sock_ip_send(NULL, "ABCD", sizeof("ABCD"), _TEST_PROTO,
@ -363,7 +363,7 @@ static void test_sock_ip_send4__ENOTCONN(void)
static void test_sock_ip_send4__socketed_no_local_no_netif(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, NULL, &remote, _TEST_PROTO,
@ -378,9 +378,9 @@ static void test_sock_ip_send4__socketed_no_local_no_netif(void)
static void test_sock_ip_send4__socketed_no_netif(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, &remote, _TEST_PROTO,
@ -395,7 +395,7 @@ static void test_sock_ip_send4__socketed_no_netif(void)
static void test_sock_ip_send4__socketed_no_local(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF };
@ -411,10 +411,10 @@ static void test_sock_ip_send4__socketed_no_local(void)
static void test_sock_ip_send4__socketed(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, &remote, _TEST_PROTO,
@ -429,12 +429,12 @@ static void test_sock_ip_send4__socketed(void)
static void test_sock_ip_send4__socketed_other_remote(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF };
const sock_ip_ep_t sock_remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_WRONG) },
static const sock_ip_ep_t sock_remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_WRONG },
.family = AF_INET };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, &sock_remote, _TEST_PROTO,
@ -449,7 +449,7 @@ static void test_sock_ip_send4__socketed_other_remote(void)
static void test_sock_ip_send4__unsocketed_no_local_no_netif(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, NULL, NULL, _TEST_PROTO,
@ -464,9 +464,9 @@ static void test_sock_ip_send4__unsocketed_no_local_no_netif(void)
static void test_sock_ip_send4__unsocketed_no_netif(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, NULL, _TEST_PROTO,
@ -481,7 +481,7 @@ static void test_sock_ip_send4__unsocketed_no_netif(void)
static void test_sock_ip_send4__unsocketed_no_local(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF };
@ -497,10 +497,10 @@ static void test_sock_ip_send4__unsocketed_no_local(void)
static void test_sock_ip_send4__unsocketed(void)
{
const sock_ip_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF };
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(0 == sock_ip_create(&_sock, &local, NULL, _TEST_PROTO,
@ -515,7 +515,7 @@ static void test_sock_ip_send4__unsocketed(void)
static void test_sock_ip_send4__no_sock_no_netif(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(sizeof("ABCD") == sock_ip_send(NULL, "ABCD", sizeof("ABCD"),
@ -528,7 +528,7 @@ static void test_sock_ip_send4__no_sock_no_netif(void)
static void test_sock_ip_send4__no_sock(void)
{
const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF };

View File

@ -189,9 +189,9 @@ void _net_init(void)
assert(netdev.netdev.driver);
#if LWIP_IPV4
ip4_addr_t local4, mask4, gw4;
local4.addr = htonl(_TEST_ADDR4_LOCAL);
mask4.addr = htonl(_TEST_ADDR4_MASK);
gw4.addr = htonl(_TEST_ADDR4_GW);
local4.addr = _TEST_ADDR4_LOCAL;
mask4.addr = _TEST_ADDR4_MASK;
gw4.addr = _TEST_ADDR4_GW;
netif_add(&netif, &local4, &mask4, &gw4, &netdev, lwip_netdev_init, tcpip_input);
#else
netif_add(&netif, &netdev, lwip_netdev_init, tcpip_input);
@ -222,7 +222,7 @@ void _prepare_send_checks(void)
netdev_test_set_send_cb(&netdev, _netdev_send);
#if LWIP_ARP
const ip4_addr_t remote4 = { .addr = htonl(_TEST_ADDR4_REMOTE) };
const ip4_addr_t remote4 = { .addr = _TEST_ADDR4_REMOTE };
assert(ERR_OK == etharp_add_static_entry(&remote4, (struct eth_addr *)mac));
#endif
#if LWIP_IPV6
@ -263,8 +263,8 @@ bool _inject_4packet(uint32_t src, uint32_t dst, uint8_t proto, void *data,
IPH_LEN_SET(ip_hdr, htons(sizeof(struct ip_hdr) + data_len));
IPH_TTL_SET(ip_hdr, 64);
IPH_PROTO_SET(ip_hdr, proto);
ip_hdr->src.addr = htonl(src);
ip_hdr->dest.addr = htonl(dst);
ip_hdr->src.addr = src;
ip_hdr->dest.addr = dst;
IPH_CHKSUM_SET(ip_hdr, 0);
IPH_CHKSUM_SET(ip_hdr, inet_chksum(ip_hdr, sizeof(struct ip_hdr)));

View File

@ -29,10 +29,19 @@ extern "C" {
#define _TEST_PORT_REMOTE (0xa615)
#define _TEST_NETIF (1)
#define _TEST_TIMEOUT (1000000U)
#define _TEST_ADDR4_LOCAL (0xc0a84f96U) /* 192.168.79.150 */
#define _TEST_ADDR4_REMOTE (0x7f000001U) /* 127.0.0.1 */
#define _TEST_ADDR4_WRONG (0x254c6b4cU)
#define _TEST_ADDR4_MASK (0xffffff00U) /* 255.255.255.0 */
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define _TEST_ADDR4_LOCAL (0x964fa8c0U) /* 192.168.79.150 */
# define _TEST_ADDR4_REMOTE (0x0100007fU) /* 127.0.0.1 */
# define _TEST_ADDR4_WRONG (0x4c6b4c25U)
# define _TEST_ADDR4_MASK (0x00ffffffU) /* 255.255.255.0 */
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define _TEST_ADDR4_LOCAL (0xc0a84f96U) /* 192.168.79.150 */
# define _TEST_ADDR4_REMOTE (0x7f000001U) /* 127.0.0.1 */
# define _TEST_ADDR4_WRONG (0x254c6b4cU)
# define _TEST_ADDR4_MASK (0xffffff00U) /* 255.255.255.0 */
#else
# error "Byte order is neither little nor big!"
#endif
#define _TEST_ADDR4_GW (0UL) /* so we can test unreachability */
#define _TEST_ADDR6_LOCAL { 0x2f, 0xc4, 0x11, 0x5a, 0xe6, 0x91, 0x8d, 0x5d, \
0x8c, 0xd1, 0x47, 0x07, 0xb7, 0x6f, 0x9b, 0x48 }

View File

@ -88,7 +88,7 @@ static void tear_down(void)
#ifdef SO_REUSE
static void test_tcp_connect4__EADDRINUSE(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -107,7 +107,7 @@ static void test_tcp_connect4__EADDRINUSE(void)
static void test_tcp_connect4__EAFNOSUPPORT(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -129,7 +129,7 @@ static void test_tcp_connect4__EINVAL_addr(void)
static void test_tcp_connect4__EINVAL_netif(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = (_TEST_NETIF + 1) };
@ -142,7 +142,7 @@ static void test_tcp_connect4__EINVAL_netif(void)
static void test_tcp_connect4__success_without_port(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF };
@ -158,13 +158,13 @@ static void test_tcp_connect4__success_without_port(void)
assert(0 == sock_tcp_connect(&_sock, &remote, 0, SOCK_FLAGS_REUSE_EP));
assert(0 == sock_tcp_get_remote(&_sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
assert(_TEST_PORT_REMOTE == ep.port);
}
static void test_tcp_connect4__success_local_port(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -184,7 +184,7 @@ static void test_tcp_connect4__success_local_port(void)
assert(_TEST_PORT_LOCAL == ep.port);
assert(0 == sock_tcp_get_remote(&_sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
assert(_TEST_PORT_REMOTE == ep.port);
}
@ -192,7 +192,7 @@ static void test_tcp_connect4__success_local_port(void)
#ifdef SO_REUSE
static void test_tcp_listen4__EADDRINUSE(void)
{
const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_LOCAL,
.netif = SOCK_ADDR_ANY_NETIF };
@ -211,7 +211,7 @@ static void test_tcp_listen4__EADDRINUSE(void)
static void test_tcp_listen4__EAFNOSUPPORT(void)
{
const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.port = _TEST_PORT_LOCAL,
.netif = SOCK_ADDR_ANY_NETIF };
@ -221,7 +221,7 @@ static void test_tcp_listen4__EAFNOSUPPORT(void)
static void test_tcp_listen4__EINVAL(void)
{
const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_LOCAL,
.netif = (_TEST_NETIF + 1) };
@ -232,7 +232,7 @@ static void test_tcp_listen4__EINVAL(void)
static void test_tcp_listen4__success_any_netif(void)
{
const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
static const sock_tcp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_LOCAL,
.netif = SOCK_ADDR_ANY_NETIF };
@ -242,7 +242,7 @@ static void test_tcp_listen4__success_any_netif(void)
_QUEUE_SIZE, 0));
assert(0 == sock_tcp_queue_get_local(&_queue, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_LOCAL) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_LOCAL == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
assert(_TEST_PORT_LOCAL == ep.port);
}
@ -304,7 +304,7 @@ static void test_tcp_accept4__success(void)
sock_tcp_ep_t ep;
sock_tcp_t *sock;
_server_addr.addr.ipv4_u32 = htonl(_TEST_ADDR4_REMOTE); /* loopback */
_server_addr.addr.ipv4_u32 = _TEST_ADDR4_REMOTE; /* loopback */
_server_addr.family = AF_INET;
_server_addr.port = _TEST_PORT_LOCAL;
_server_addr.netif = SOCK_ADDR_ANY_NETIF;
@ -319,7 +319,7 @@ static void test_tcp_accept4__success(void)
assert(_TEST_PORT_LOCAL == ep.port);
assert(0 == sock_tcp_get_remote(sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
assert(_TEST_PORT_REMOTE == ep.port);
}
@ -328,7 +328,7 @@ static void test_tcp_accept4__success(void)
static void test_tcp_read4__EAGAIN(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -348,7 +348,7 @@ static void test_tcp_read4__EAGAIN(void)
static void test_tcp_read4__ECONNRESET(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -378,7 +378,7 @@ static void test_tcp_read4__ENOTCONN(void)
static void test_tcp_read4__ETIMEDOUT(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -401,7 +401,7 @@ static void test_tcp_read4__ETIMEDOUT(void)
static void test_tcp_read4__success(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -429,7 +429,7 @@ static void test_tcp_read4__success(void)
static void test_tcp_read4__success_with_timeout(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -457,7 +457,7 @@ static void test_tcp_read4__success_with_timeout(void)
static void test_tcp_read4__success_non_blocking(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };
@ -492,7 +492,7 @@ static void test_tcp_write4__ENOTCONN(void)
static void test_tcp_write4__success(void)
{
const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
static const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = SOCK_ADDR_ANY_NETIF };

View File

@ -29,10 +29,19 @@ extern "C" {
#define _TEST_PORT_REMOTE (0xa615)
#define _TEST_NETIF (1)
#define _TEST_TIMEOUT (1000000U)
#define _TEST_ADDR4_LOCAL (0xc0a84f96U) /* 192.168.79.150 */
#define _TEST_ADDR4_REMOTE (0xc0a84f6bU) /* 192.168.79.107 */
#define _TEST_ADDR4_WRONG (0x254c6b4cU)
#define _TEST_ADDR4_MASK (0xffffff00U) /* 255.255.255.0 */
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define _TEST_ADDR4_LOCAL (0x964fa8c0U) /* 192.168.79.150 */
# define _TEST_ADDR4_REMOTE (0x6b4fa8c0U) /* 192.168.79.107 */
# define _TEST_ADDR4_WRONG (0x4c6b4c25U)
# define _TEST_ADDR4_MASK (0x00ffffffU) /* 255.255.255.0 */
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define _TEST_ADDR4_LOCAL (0xc0a84f96U) /* 192.168.79.150 */
# define _TEST_ADDR4_REMOTE (0xc0a84f6bU) /* 192.168.79.107 */
# define _TEST_ADDR4_WRONG (0x254c6b4cU)
# define _TEST_ADDR4_MASK (0xffffff00U) /* 255.255.255.0 */
#else
# error "Byte order is neither little nor big!"
#endif
#define _TEST_ADDR4_GW (0UL) /* so we can test unreachability */
#define _TEST_ADDR6_LOCAL { 0x2f, 0xc4, 0x11, 0x5a, 0xe6, 0x91, 0x8d, 0x5d, \
0x8c, 0xd1, 0x47, 0x07, 0xb7, 0x6f, 0x9b, 0x48 }

View File

@ -85,10 +85,10 @@ static void test_sock_udp_create4__EINVAL_netif(void)
static const sock_udp_ep_t local = { .family = AF_INET, .netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
/* port may not be NULL according to doc */
const sock_udp_ep_t remote = { .family = AF_INET,
.netif = (_TEST_NETIF + 1),
.port = _TEST_PORT_REMOTE,
.addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } };
static const sock_udp_ep_t remote = { .family = AF_INET,
.netif = (_TEST_NETIF + 1),
.port = _TEST_PORT_REMOTE,
.addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } };
assert(-EINVAL == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
}
@ -157,9 +157,9 @@ static void test_sock_udp_create4__only_local_reuse_ep(void)
static void test_sock_udp_create4__only_remote(void)
{
const sock_udp_ep_t remote = { .family = AF_INET,
.port = _TEST_PORT_REMOTE,
.addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } };
static const sock_udp_ep_t remote = { .family = AF_INET,
.port = _TEST_PORT_REMOTE,
.addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } };
sock_udp_ep_t ep;
assert(0 == sock_udp_create(&_sock, NULL, &remote, SOCK_FLAGS_REUSE_EP));
@ -167,7 +167,7 @@ static void test_sock_udp_create4__only_remote(void)
assert(0 == sock_udp_get_local(&_sock, &ep));
assert(0 == sock_udp_get_remote(&_sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
assert(_TEST_PORT_REMOTE == ep.port);
}
@ -176,9 +176,9 @@ static void test_sock_udp_create4__full(void)
{
static const sock_udp_ep_t local = { .family = AF_INET, .netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .family = AF_INET,
.port = _TEST_PORT_REMOTE,
.addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } };
static const sock_udp_ep_t remote = { .family = AF_INET,
.port = _TEST_PORT_REMOTE,
.addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } };
sock_udp_ep_t ep;
assert(0 == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
@ -190,7 +190,7 @@ static void test_sock_udp_create4__full(void)
assert(_TEST_PORT_LOCAL == ep.port);
assert(0 == sock_udp_get_remote(&_sock, &ep));
assert(AF_INET == ep.family);
assert(htonl(_TEST_ADDR4_REMOTE) == ep.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == ep.addr.ipv4_u32);
assert(SOCK_ADDR_ANY_NETIF == ep.netif);
assert(_TEST_PORT_REMOTE == ep.port);
}
@ -246,9 +246,9 @@ static void test_sock_udp_recv4__socketed(void)
{
static const sock_udp_ep_t local = { .family = AF_INET,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
assert(_inject_4packet(_TEST_ADDR4_REMOTE, _TEST_ADDR4_LOCAL, _TEST_PORT_REMOTE,
@ -264,9 +264,9 @@ static void test_sock_udp_recv4__socketed_with_remote(void)
{
static const sock_udp_ep_t local = { .family = AF_INET,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
sock_udp_ep_t result;
assert(0 == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
@ -277,7 +277,7 @@ static void test_sock_udp_recv4__socketed_with_remote(void)
sizeof(_test_buffer),
SOCK_NO_TIMEOUT, &result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_PORT_REMOTE == result.port);
#if LWIP_NETBUF_RECVINFO
assert(_TEST_NETIF == result.netif);
@ -287,9 +287,9 @@ static void test_sock_udp_recv4__socketed_with_remote(void)
static void test_sock_udp_recv4__unsocketed(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.port = _TEST_PORT_LOCAL };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_LOCAL };
assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));
assert(_inject_4packet(_TEST_ADDR4_REMOTE, _TEST_ADDR4_LOCAL, _TEST_PORT_REMOTE,
@ -315,7 +315,7 @@ static void test_sock_udp_recv4__unsocketed_with_remote(void)
sizeof(_test_buffer),
SOCK_NO_TIMEOUT, &result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_PORT_REMOTE == result.port);
#if LWIP_NETBUF_RECVINFO
assert(_TEST_NETIF == result.netif);
@ -337,7 +337,7 @@ static void test_sock_udp_recv4__with_timeout(void)
sizeof(_test_buffer), _TEST_TIMEOUT,
&result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_PORT_REMOTE == result.port);
#if LWIP_NETBUF_RECVINFO
assert(_TEST_NETIF == result.netif);
@ -358,7 +358,7 @@ static void test_sock_udp_recv4__non_blocking(void)
assert(sizeof("ABCD") == sock_udp_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, &result));
assert(AF_INET == result.family);
assert(htonl(_TEST_ADDR4_REMOTE) == result.addr.ipv4_u32);
assert(_TEST_ADDR4_REMOTE == result.addr.ipv4_u32);
assert(_TEST_PORT_REMOTE == result.port);
#if LWIP_NETBUF_RECVINFO
assert(_TEST_NETIF == result.netif);
@ -368,9 +368,9 @@ static void test_sock_udp_recv4__non_blocking(void)
static void test_sock_udp_send4__EAFNOSUPPORT(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_UNSPEC,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_UNSPEC,
.port = _TEST_PORT_REMOTE };
assert(-EAFNOSUPPORT == sock_udp_send(NULL, "ABCD", sizeof("ABCD"),
&remote));
@ -379,10 +379,10 @@ static void test_sock_udp_send4__EAFNOSUPPORT(void)
static void test_sock_udp_send4__EINVAL_addr(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF };
static const sock_udp_ep_t remote = { .family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF };
@ -394,14 +394,14 @@ static void test_sock_udp_send4__EINVAL_addr(void)
static void test_sock_udp_send4__EINVAL_netif(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF + 1 };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE,
.netif = _TEST_NETIF + 1 };
assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));
assert(-EINVAL == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"), &remote));
@ -410,9 +410,9 @@ static void test_sock_udp_send4__EINVAL_netif(void)
static void test_sock_udp_send4__EHOSTUNREACH(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_WRONG) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_WRONG },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(-EHOSTUNREACH == sock_udp_send(NULL, "ABCD", sizeof("ABCD"),
&remote));
@ -420,8 +420,8 @@ static void test_sock_udp_send4__EHOSTUNREACH(void)
static void test_sock_udp_send4__EINVAL_port(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET };
assert(-EINVAL == sock_udp_send(NULL, "ABCD", sizeof("ABCD"), &remote));
assert(_check_net());
@ -436,9 +436,9 @@ static void test_sock_udp_send4__ENOTCONN(void)
static void test_sock_udp_send4__socketed_no_local_no_netif(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, NULL, &remote, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -451,12 +451,12 @@ static void test_sock_udp_send4__socketed_no_local_no_netif(void)
static void test_sock_udp_send4__socketed_no_netif(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_LOCAL };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -470,10 +470,10 @@ static void test_sock_udp_send4__socketed_no_netif(void)
static void test_sock_udp_send4__socketed_no_local(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, NULL, &remote, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -487,13 +487,13 @@ static void test_sock_udp_send4__socketed_no_local(void)
static void test_sock_udp_send4__socketed(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -507,16 +507,16 @@ static void test_sock_udp_send4__socketed(void)
static void test_sock_udp_send4__socketed_other_remote(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t sock_remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_WRONG) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE + _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
static const sock_udp_ep_t sock_remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_WRONG },
.family = AF_INET,
.port = _TEST_PORT_REMOTE + _TEST_PORT_LOCAL };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, &local, &sock_remote, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -530,9 +530,9 @@ static void test_sock_udp_send4__socketed_other_remote(void)
static void test_sock_udp_send4__unsocketed_no_local_no_netif(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, NULL, NULL, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -546,12 +546,12 @@ static void test_sock_udp_send4__unsocketed_no_local_no_netif(void)
static void test_sock_udp_send4__unsocketed_no_netif(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.port = _TEST_PORT_LOCAL };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -565,10 +565,10 @@ static void test_sock_udp_send4__unsocketed_no_netif(void)
static void test_sock_udp_send4__unsocketed_no_local(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, NULL, NULL, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -582,13 +582,13 @@ static void test_sock_udp_send4__unsocketed_no_local(void)
static void test_sock_udp_send4__unsocketed(void)
{
const sock_udp_ep_t local = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_LOCAL) },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));
assert(sizeof("ABCD") == sock_udp_send(&_sock, "ABCD", sizeof("ABCD"),
@ -602,9 +602,9 @@ static void test_sock_udp_send4__unsocketed(void)
static void test_sock_udp_send4__no_sock_no_netif(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.port = _TEST_PORT_REMOTE };
assert(sizeof("ABCD") == sock_udp_send(NULL, "ABCD", sizeof("ABCD"),
&remote));
@ -617,10 +617,10 @@ static void test_sock_udp_send4__no_sock_no_netif(void)
static void test_sock_udp_send4__no_sock(void)
{
const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_REMOTE };
static const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE },
.family = AF_INET,
.netif = _TEST_NETIF,
.port = _TEST_PORT_REMOTE };
assert(sizeof("ABCD") == sock_udp_send(NULL, "ABCD", sizeof("ABCD"),
&remote));

View File

@ -191,9 +191,9 @@ void _net_init(void)
assert(netdev.netdev.driver);
#if LWIP_IPV4
ip4_addr_t local4, mask4, gw4;
local4.addr = htonl(_TEST_ADDR4_LOCAL);
mask4.addr = htonl(_TEST_ADDR4_MASK);
gw4.addr = htonl(_TEST_ADDR4_GW);
local4.addr = _TEST_ADDR4_LOCAL;
mask4.addr = _TEST_ADDR4_MASK;
gw4.addr = _TEST_ADDR4_GW;
netif_add(&netif, &local4, &mask4, &gw4, &netdev, lwip_netdev_init, tcpip_input);
#else
netif_add(&netif, &netdev, lwip_netdev_init, tcpip_input);
@ -224,7 +224,7 @@ void _prepare_send_checks(void)
netdev_test_set_send_cb(&netdev, _netdev_send);
#if LWIP_ARP
const ip4_addr_t remote4 = { .addr = htonl(_TEST_ADDR4_REMOTE) };
const ip4_addr_t remote4 = { .addr = _TEST_ADDR4_REMOTE };
assert(ERR_OK == etharp_add_static_entry(&remote4, (struct eth_addr *)mac));
#endif
#if LWIP_IPV6
@ -268,8 +268,8 @@ bool _inject_4packet(uint32_t src, uint32_t dst, uint16_t src_port,
IPH_LEN_SET(ip_hdr, htons(sizeof(struct ip_hdr) + udp_len));
IPH_TTL_SET(ip_hdr, 64);
IPH_PROTO_SET(ip_hdr, PROTNUM_UDP);
ip_hdr->src.addr = htonl(src);
ip_hdr->dest.addr = htonl(dst);
ip_hdr->src.addr = src;
ip_hdr->dest.addr = dst;
IPH_CHKSUM_SET(ip_hdr, 0);
IPH_CHKSUM_SET(ip_hdr, inet_chksum(ip_hdr, sizeof(struct ip_hdr)));