Skip to content

Commit

Permalink
fixup! tests: provide gnrc_sock_udp tests
Browse files Browse the repository at this point in the history
Adapt for new timeout behavior (incl. non-blocking)
  • Loading branch information
miri64 committed Oct 25, 2016
1 parent cdf067a commit e0ea6aa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
56 changes: 48 additions & 8 deletions tests/gnrc_sock_udp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,19 @@ static void test_sock_udp_recv__EADDRNOTAVAIL(void)
assert(0 == sock_udp_create(&_sock, NULL, NULL, SOCK_FLAGS_REUSE_EP));

assert(-EADDRNOTAVAIL == sock_udp_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, NULL));
sizeof(_test_buffer),
SOCK_NO_TIMEOUT, NULL));
}

static void test_sock_udp_recv__EAGAIN(void)
{
static const sock_udp_ep_t local = { .family = AF_INET6, .netif = _TEST_NETIF,
.port = _TEST_PORT_LOCAL };

assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));

assert(-EAGAIN == sock_udp_recv(&_sock, _test_buffer, sizeof(_test_buffer),
0, NULL));
}

static void test_sock_udp_recv__ENOBUFS(void)
Expand All @@ -202,7 +214,8 @@ static void test_sock_udp_recv__ENOBUFS(void)
assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));
assert(_inject_packet(&src_addr, &dst_addr, _TEST_PORT_REMOTE,
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"), _TEST_NETIF));
assert(-ENOBUFS == sock_udp_recv(&_sock, _test_buffer, 2, 0, NULL));
assert(-ENOBUFS == sock_udp_recv(&_sock, _test_buffer, 2, SOCK_NO_TIMEOUT,
NULL));
assert(_check_net());
}

Expand All @@ -220,8 +233,8 @@ static void test_sock_udp_recv__EPROTO(void)
assert(_inject_packet(&src_addr, &dst_addr, _TEST_PORT_REMOTE,
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"),
_TEST_NETIF));
assert(-EPROTO == sock_udp_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, NULL));
assert(-EPROTO == sock_udp_recv(&_sock, _test_buffer, sizeof(_test_buffer),
SOCK_NO_TIMEOUT, NULL));
assert(_check_net());
}

Expand Down Expand Up @@ -254,7 +267,8 @@ static void test_sock_udp_recv__socketed(void)
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"),
_TEST_NETIF));
assert(sizeof("ABCD") == sock_udp_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, NULL));
sizeof(_test_buffer),
SOCK_NO_TIMEOUT, NULL));
assert(_check_net());
}

Expand All @@ -274,7 +288,8 @@ static void test_sock_udp_recv__socketed_with_remote(void)
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"),
_TEST_NETIF));
assert(sizeof("ABCD") == sock_udp_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_PORT_REMOTE == result.port);
Expand All @@ -295,7 +310,8 @@ static void test_sock_udp_recv__unsocketed(void)
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"),
_TEST_NETIF));
assert(sizeof("ABCD") == sock_udp_recv(&_sock, _test_buffer,
sizeof(_test_buffer), 0, NULL));
sizeof(_test_buffer),
SOCK_NO_TIMEOUT, NULL));
assert(_check_net());
}

Expand All @@ -312,7 +328,8 @@ static void test_sock_udp_recv__unsocketed_with_remote(void)
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"),
_TEST_NETIF));
assert(sizeof("ABCD") == sock_udp_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_PORT_REMOTE == result.port);
Expand Down Expand Up @@ -342,6 +359,27 @@ static void test_sock_udp_recv__with_timeout(void)
assert(_check_net());
}

static void test_sock_udp_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_udp_ep_t local = { .family = AF_INET6,
.port = _TEST_PORT_LOCAL };
sock_udp_ep_t result;

assert(0 == sock_udp_create(&_sock, &local, NULL, SOCK_FLAGS_REUSE_EP));
assert(_inject_packet(&src_addr, &dst_addr, _TEST_PORT_REMOTE,
_TEST_PORT_LOCAL, "ABCD", sizeof("ABCD"),
_TEST_NETIF));
assert(sizeof("ABCD") == sock_udp_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_PORT_REMOTE == result.port);
assert(_TEST_NETIF == result.netif);
assert(_check_net());
}

static void test_sock_udp_send__EAFNOSUPPORT(void)
{
static const sock_udp_ep_t remote = { .addr = { .ipv6 = _TEST_ADDR_REMOTE },
Expand Down Expand Up @@ -633,6 +671,7 @@ int main(void)
/* sock_udp_get_local() is tested in sock_udp_create() tests */
/* sock_udp_get_remote() is tested in sock_udp_create() tests */
CALL(test_sock_udp_recv__EADDRNOTAVAIL());
CALL(test_sock_udp_recv__EAGAIN());
CALL(test_sock_udp_recv__ENOBUFS());
CALL(test_sock_udp_recv__EPROTO());
CALL(test_sock_udp_recv__ETIMEDOUT());
Expand All @@ -641,6 +680,7 @@ int main(void)
CALL(test_sock_udp_recv__unsocketed());
CALL(test_sock_udp_recv__unsocketed_with_remote());
CALL(test_sock_udp_recv__with_timeout());
CALL(test_sock_udp_recv__non_blocking());
_prepare_send_checks();
CALL(test_sock_udp_send__EAFNOSUPPORT());
CALL(test_sock_udp_send__EINVAL_addr());
Expand Down
2 changes: 2 additions & 0 deletions tests/gnrc_sock_udp/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def testfunc(child):
child.expect_exact(u"Calling test_sock_udp_create__only_remote()")
child.expect_exact(u"Calling test_sock_udp_create__full()")
child.expect_exact(u"Calling test_sock_udp_recv__EADDRNOTAVAIL()")
child.expect_exact(u"Calling test_sock_udp_recv__EAGAIN()")
child.expect_exact(u"Calling test_sock_udp_recv__ENOBUFS()")
child.expect_exact(u"Calling test_sock_udp_recv__EPROTO()")
child.expect_exact(u"Calling test_sock_udp_recv__ETIMEDOUT()")
Expand All @@ -50,6 +51,7 @@ def testfunc(child):
child.expect_exact(u"Calling test_sock_udp_recv__unsocketed()")
child.expect_exact(u"Calling test_sock_udp_recv__unsocketed_with_remote()")
child.expect_exact(u"Calling test_sock_udp_recv__with_timeout()")
child.expect_exact(u"Calling test_sock_udp_recv__non_blocking()")
child.expect_exact(u"Calling test_sock_udp_send__EAFNOSUPPORT()")
child.expect_exact(u"Calling test_sock_udp_send__EINVAL_addr()")
child.expect_exact(u"Calling test_sock_udp_send__EINVAL_netif()")
Expand Down

0 comments on commit e0ea6aa

Please sign in to comment.