From cd34cb93b2e3ea3dc2ce5a35972c3160916c7281 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 12 Oct 2016 19:47:39 +0200 Subject: [PATCH] fixup! tests: provide gnrc_sock_ip tests Adapt for new timeout behavior (incl. non-blocking) --- tests/gnrc_sock_ip/main.c | 54 +++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/tests/gnrc_sock_ip/main.c b/tests/gnrc_sock_ip/main.c index 5142767ab530..7938d5ea1af9 100644 --- a/tests/gnrc_sock_ip/main.c +++ b/tests/gnrc_sock_ip/main.c @@ -166,7 +166,19 @@ static void test_sock_ip_recv__EADDRNOTAVAIL(void) SOCK_FLAGS_REUSE_EP)); assert(-EADDRNOTAVAIL == sock_ip_recv(&_sock, _test_buffer, - sizeof(_test_buffer), 0, NULL)); + sizeof(_test_buffer), SOCK_NO_TIMEOUT, + NULL)); +} + +static void test_sock_ip_recv__EAGAIN(void) +{ + static const sock_ip_ep_t local = { .family = AF_INET6, .netif = _TEST_NETIF }; + + assert(0 == sock_ip_create(&_sock, &local, NULL, _TEST_PROTO, + SOCK_FLAGS_REUSE_EP)); + + assert(-EAGAIN == sock_ip_recv(&_sock, _test_buffer, sizeof(_test_buffer), + 0, NULL)); } static void test_sock_ip_recv__ENOBUFS(void) @@ -179,7 +191,8 @@ static void test_sock_ip_recv__ENOBUFS(void) SOCK_FLAGS_REUSE_EP)); assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", sizeof("ABCD"), _TEST_NETIF)); - assert(-ENOBUFS == sock_ip_recv(&_sock, _test_buffer, 2, 0, NULL)); + assert(-ENOBUFS == sock_ip_recv(&_sock, _test_buffer, 2, SOCK_NO_TIMEOUT, + NULL)); assert(_check_net()); } @@ -195,8 +208,8 @@ static void test_sock_ip_recv__EPROTO(void) SOCK_FLAGS_REUSE_EP)); assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", sizeof("ABCD"), _TEST_NETIF)); - assert(-EPROTO == sock_ip_recv(&_sock, _test_buffer, - sizeof(_test_buffer), 0, NULL)); + assert(-EPROTO == sock_ip_recv(&_sock, _test_buffer, sizeof(_test_buffer), + SOCK_NO_TIMEOUT, NULL)); assert(_check_net()); } @@ -227,7 +240,8 @@ static void test_sock_ip_recv__socketed(void) assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", sizeof("ABCD"), _TEST_NETIF)); assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer, - sizeof(_test_buffer), 0, NULL)); + sizeof(_test_buffer), SOCK_NO_TIMEOUT, + NULL)); assert(_check_net()); } @@ -245,7 +259,8 @@ static void test_sock_ip_recv__socketed_with_remote(void) assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", sizeof("ABCD"), _TEST_NETIF)); assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer, - sizeof(_test_buffer), 0, &result)); + sizeof(_test_buffer), SOCK_NO_TIMEOUT, + &result)); assert(AF_INET6 == result.family); assert(memcmp(&result.addr, &src_addr, sizeof(result.addr)) == 0); assert(_TEST_NETIF == result.netif); @@ -264,7 +279,8 @@ static void test_sock_ip_recv__unsocketed(void) assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", sizeof("ABCD"), _TEST_NETIF)); assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer, - sizeof(_test_buffer), 0, NULL)); + sizeof(_test_buffer), SOCK_NO_TIMEOUT, + NULL)); assert(_check_net()); } @@ -280,7 +296,8 @@ static void test_sock_ip_recv__unsocketed_with_remote(void) assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", sizeof("ABCD"), _TEST_NETIF)); assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer, - sizeof(_test_buffer), 0, &result)); + sizeof(_test_buffer), SOCK_NO_TIMEOUT, + &result)); assert(AF_INET6 == result.family); assert(memcmp(&result.addr, &src_addr, sizeof(result.addr)) == 0); assert(_TEST_NETIF == result.netif); @@ -307,6 +324,25 @@ static void test_sock_ip_recv__with_timeout(void) assert(_check_net()); } +static void test_sock_ip_recv__non_blocking(void) +{ + static const ipv6_addr_t src_addr = { .u8 = _TEST_ADDR_REMOTE }; + static const ipv6_addr_t dst_addr = { .u8 = _TEST_ADDR_LOCAL }; + static const sock_ip_ep_t local = { .family = AF_INET6 }; + sock_ip_ep_t result; + + assert(0 == sock_ip_create(&_sock, &local, NULL, _TEST_PROTO, + SOCK_FLAGS_REUSE_EP)); + assert(_inject_packet(&src_addr, &dst_addr, _TEST_PROTO, "ABCD", + sizeof("ABCD"), _TEST_NETIF)); + assert(sizeof("ABCD") == sock_ip_recv(&_sock, _test_buffer, + sizeof(_test_buffer), 0, &result)); + assert(AF_INET6 == result.family); + assert(memcmp(&result.addr, &src_addr, sizeof(result.addr)) == 0); + assert(_TEST_NETIF == result.netif); + assert(_check_net()); +} + static void test_sock_ip_send__EAFNOSUPPORT(void) { static const sock_ip_ep_t remote = { .addr = { .ipv6 = _TEST_ADDR_REMOTE }, @@ -570,6 +606,7 @@ int main(void) /* sock_ip_get_local() is tested in sock_ip_create() tests */ /* sock_ip_get_remote() is tested in sock_ip_create() tests */ CALL(test_sock_ip_recv__EADDRNOTAVAIL()); + CALL(test_sock_ip_recv__EAGAIN()); CALL(test_sock_ip_recv__ENOBUFS()); CALL(test_sock_ip_recv__EPROTO()); CALL(test_sock_ip_recv__ETIMEDOUT()); @@ -578,6 +615,7 @@ int main(void) CALL(test_sock_ip_recv__unsocketed()); CALL(test_sock_ip_recv__unsocketed_with_remote()); CALL(test_sock_ip_recv__with_timeout()); + CALL(test_sock_ip_recv__non_blocking()); _prepare_send_checks(); CALL(test_sock_ip_send__EAFNOSUPPORT()); CALL(test_sock_ip_send__EINVAL_addr());