From a5370ff6df0958f88a2c66ed627fead0575bbeb0 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 3 Oct 2018 14:26:26 +0200 Subject: [PATCH 1/6] tests/lwip_sock_udp: make IPv4 address byteorder static --- tests/lwip_sock_udp/constants.h | 17 ++++++-- tests/lwip_sock_udp/main.c | 70 ++++++++++++++++----------------- tests/lwip_sock_udp/stack.c | 12 +++--- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/tests/lwip_sock_udp/constants.h b/tests/lwip_sock_udp/constants.h index 4a15841a44..a2e9540e94 100644 --- a/tests/lwip_sock_udp/constants.h +++ b/tests/lwip_sock_udp/constants.h @@ -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 } diff --git a/tests/lwip_sock_udp/main.c b/tests/lwip_sock_udp/main.c index 202b23627b..3c77e160c9 100644 --- a/tests/lwip_sock_udp/main.c +++ b/tests/lwip_sock_udp/main.c @@ -88,7 +88,7 @@ static void test_sock_udp_create4__EINVAL_netif(void) const sock_udp_ep_t remote = { .family = AF_INET, .netif = (_TEST_NETIF + 1), .port = _TEST_PORT_REMOTE, - .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) } }; + .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } }; assert(-EINVAL == sock_udp_create(&_sock, &local, &remote, SOCK_FLAGS_REUSE_EP)); } @@ -159,7 +159,7 @@ 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) } }; + .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); } @@ -178,7 +178,7 @@ static void test_sock_udp_create4__full(void) .port = _TEST_PORT_LOCAL }; const sock_udp_ep_t remote = { .family = AF_INET, .port = _TEST_PORT_REMOTE, - .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_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,7 +246,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -264,7 +264,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; sock_udp_ep_t result; @@ -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,7 +287,7 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL }, .family = AF_INET, .port = _TEST_PORT_LOCAL }; @@ -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,7 +368,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_UNSPEC, .port = _TEST_PORT_REMOTE }; @@ -379,7 +379,7 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL }, .family = AF_INET, .port = _TEST_PORT_REMOTE, .netif = _TEST_NETIF }; @@ -394,11 +394,11 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE, .netif = _TEST_NETIF + 1 }; @@ -410,7 +410,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_WRONG }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -420,7 +420,7 @@ 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) }, + 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)); @@ -436,7 +436,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -451,10 +451,10 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL }, .family = AF_INET, .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -470,7 +470,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .netif = _TEST_NETIF, .port = _TEST_PORT_REMOTE }; @@ -487,11 +487,11 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -507,14 +507,14 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _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) }, + const sock_udp_ep_t sock_remote = { .addr = { .ipv4_u32 = _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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -530,7 +530,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -546,10 +546,10 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _TEST_ADDR4_LOCAL }, .family = AF_INET, .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = htonl(_TEST_ADDR4_REMOTE) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -565,7 +565,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .netif = _TEST_NETIF, .port = _TEST_PORT_REMOTE }; @@ -582,11 +582,11 @@ 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) }, + const sock_udp_ep_t local = { .addr = { .ipv4_u32 = _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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -602,7 +602,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE }; @@ -617,7 +617,7 @@ 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) }, + const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .netif = _TEST_NETIF, .port = _TEST_PORT_REMOTE }; diff --git a/tests/lwip_sock_udp/stack.c b/tests/lwip_sock_udp/stack.c index d4a08c43af..1440e08734 100644 --- a/tests/lwip_sock_udp/stack.c +++ b/tests/lwip_sock_udp/stack.c @@ -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))); From 6789a0b2460e2884e79a1dc16a5b50aab1027d93 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 3 Oct 2018 14:47:42 +0200 Subject: [PATCH 2/6] tests/lwip_sock_udp: make non-static consts static --- tests/lwip_sock_udp/main.c | 192 ++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/tests/lwip_sock_udp/main.c b/tests/lwip_sock_udp/main.c index 3c77e160c9..3db379c3f7 100644 --- a/tests/lwip_sock_udp/main.c +++ b/tests/lwip_sock_udp/main.c @@ -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 = _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 = _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)); @@ -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 = _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)); @@ -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 = _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 = _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)); @@ -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 = _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, @@ -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 = _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 = _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 = _TEST_ADDR4_LOCAL }, - .family = AF_INET, - .port = _TEST_PORT_REMOTE, - .netif = _TEST_NETIF }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _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 = _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 = _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 = _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 = _TEST_ADDR4_LOCAL }, - .family = AF_INET, - .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _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 = _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 = _TEST_ADDR4_LOCAL }, - .family = AF_INET, - .netif = _TEST_NETIF, - .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _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 = _TEST_ADDR4_LOCAL }, - .family = AF_INET, - .netif = _TEST_NETIF, - .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t sock_remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_WRONG }, - .family = AF_INET, - .port = _TEST_PORT_REMOTE + _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _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 = _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 = _TEST_ADDR4_LOCAL }, - .family = AF_INET, - .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _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 = _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 = _TEST_ADDR4_LOCAL }, - .family = AF_INET, - .netif = _TEST_NETIF, - .port = _TEST_PORT_LOCAL }; - const sock_udp_ep_t remote = { .addr = { .ipv4_u32 = _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 = _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 = _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)); From 73ec2ac65206f1a23bbc3a5c82e4f01b187cd560 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 3 Oct 2018 14:33:11 +0200 Subject: [PATCH 3/6] tests/lwip_sock_ip: make IPv4 address byteorder static --- tests/lwip_sock_ip/constants.h | 17 +++++++-- tests/lwip_sock_ip/main.c | 68 +++++++++++++++++----------------- tests/lwip_sock_ip/stack.c | 12 +++--- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/tests/lwip_sock_ip/constants.h b/tests/lwip_sock_ip/constants.h index b6a6565414..352a0edd94 100644 --- a/tests/lwip_sock_ip/constants.h +++ b/tests/lwip_sock_ip/constants.h @@ -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 } diff --git a/tests/lwip_sock_ip/main.c b/tests/lwip_sock_ip/main.c index c0e95dc9bb..db6dc1eb71 100644 --- a/tests/lwip_sock_ip/main.c +++ b/tests/lwip_sock_ip/main.c @@ -68,7 +68,7 @@ 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, .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)); @@ -123,7 +123,7 @@ 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) } }; + .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } }; sock_ip_ep_t ep; assert(0 == sock_ip_create(&_sock, NULL, &remote, _TEST_PROTO, @@ -132,7 +132,7 @@ 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); } @@ -140,7 +140,7 @@ 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) } }; + .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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .netif = _TEST_NETIF }; diff --git a/tests/lwip_sock_ip/stack.c b/tests/lwip_sock_ip/stack.c index 7dfd18879e..0cbe29ec44 100644 --- a/tests/lwip_sock_ip/stack.c +++ b/tests/lwip_sock_ip/stack.c @@ -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))); From 4934df3112c19a51ee65353b16ff7c452e6ffa55 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 3 Oct 2018 15:03:53 +0200 Subject: [PATCH 4/6] tests/lwip_sock_ip: make non-static consts static --- tests/lwip_sock_ip/main.c | 56 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/lwip_sock_ip/main.c b/tests/lwip_sock_ip/main.c index db6dc1eb71..638ca9057b 100644 --- a/tests/lwip_sock_ip/main.c +++ b/tests/lwip_sock_ip/main.c @@ -66,7 +66,7 @@ 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 = _TEST_ADDR4_REMOTE } }; @@ -122,7 +122,7 @@ 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, + static const sock_ip_ep_t remote = { .family = AF_INET, .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } }; sock_ip_ep_t ep; @@ -139,7 +139,7 @@ static void test_sock_ip_create4__only_remote(void) 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, + static const sock_ip_ep_t remote = { .family = AF_INET, .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE } }; sock_ip_ep_t ep; @@ -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 = _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 = _TEST_ADDR4_REMOTE }, + static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET }; sock_ip_ep_t result; @@ -238,7 +238,7 @@ static void test_sock_ip_recv4__socketed_with_remote(void) static void test_sock_ip_recv4__unsocketed(void) { - const sock_ip_ep_t local = { .addr = { .ipv4_u32 = _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, @@ -304,7 +304,7 @@ static void test_sock_ip_recv4__non_blocking(void) static void test_sock_ip_send4__EAFNOSUPPORT(void) { - const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 = _TEST_ADDR4_REMOTE }, + static const sock_ip_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .netif = _TEST_NETIF }; From f6964c1065a1681ac22ce3cde9ac9e2f86a99aef Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 3 Oct 2018 14:39:35 +0200 Subject: [PATCH 5/6] tests/lwip_sock_tcp: make IPv4 address byteorder static --- tests/lwip_sock_tcp/constants.h | 17 +++++++++---- tests/lwip_sock_tcp/main.c | 42 ++++++++++++++++----------------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/tests/lwip_sock_tcp/constants.h b/tests/lwip_sock_tcp/constants.h index 1b99b16950..168bc0e398 100644 --- a/tests/lwip_sock_tcp/constants.h +++ b/tests/lwip_sock_tcp/constants.h @@ -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 } diff --git a/tests/lwip_sock_tcp/main.c b/tests/lwip_sock_tcp/main.c index 5903fe6a40..f4fa462fa5 100644 --- a/tests/lwip_sock_tcp/main.c +++ b/tests/lwip_sock_tcp/main.c @@ -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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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) }, + const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _TEST_ADDR4_REMOTE }, .family = AF_INET, .port = _TEST_PORT_REMOTE, .netif = SOCK_ADDR_ANY_NETIF }; From a291facbd77350d38268f3b46f5ccd14ee4008db Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 3 Oct 2018 15:06:49 +0200 Subject: [PATCH 6/6] tests/lwip_sock_tcp: make non-static end-point consts static --- tests/lwip_sock_tcp/main.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/lwip_sock_tcp/main.c b/tests/lwip_sock_tcp/main.c index f4fa462fa5..5b98ce2142 100644 --- a/tests/lwip_sock_tcp/main.c +++ b/tests/lwip_sock_tcp/main.c @@ -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 = _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 = _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 = _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 = _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 }; @@ -164,7 +164,7 @@ static void test_tcp_connect4__success_without_port(void) } static void test_tcp_connect4__success_local_port(void) { - const sock_tcp_ep_t remote = { .addr = { .ipv4_u32 = _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 }; @@ -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 = _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 = _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 = _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 = _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 }; @@ -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 = _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 = _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 = _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 = _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 = _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 = _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 = _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 };