Skip to content

Commit

Permalink
fixup! tests: provide gnrc_sock_ip 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 e0ea6aa commit cd34cb9
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions tests/gnrc_sock_ip/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -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());
}

Expand All @@ -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);
Expand All @@ -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());
}

Expand All @@ -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);
Expand All @@ -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 },
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit cd34cb9

Please sign in to comment.