tests: net: tcp: Add new tests for get/set SO_RCVBUF
Test SO_RCVBUF option using getsockopt and setsockopt. Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
This commit is contained in:
parent
5d37de8551
commit
4e7a74c547
2 changed files with 42 additions and 0 deletions
|
@ -35,3 +35,4 @@ CONFIG_ZTEST=y
|
|||
CONFIG_ZTEST_STACK_SIZE=2048
|
||||
|
||||
CONFIG_NET_CONTEXT_RCVTIMEO=y
|
||||
CONFIG_NET_CONTEXT_RCVBUF=y
|
||||
|
|
|
@ -672,6 +672,46 @@ void test_so_protocol(void)
|
|||
k_sleep(TCP_TEARDOWN_TIMEOUT);
|
||||
}
|
||||
|
||||
void test_so_rcvbuf(void)
|
||||
{
|
||||
struct sockaddr_in bind_addr4;
|
||||
struct sockaddr_in6 bind_addr6;
|
||||
int sock1, sock2, rv;
|
||||
int retval;
|
||||
int optval = UINT16_MAX;
|
||||
socklen_t optlen = sizeof(optval);
|
||||
|
||||
prepare_sock_tcp_v4(CONFIG_NET_CONFIG_MY_IPV4_ADDR, ANY_PORT,
|
||||
&sock1, &bind_addr4);
|
||||
prepare_sock_tcp_v6(CONFIG_NET_CONFIG_MY_IPV6_ADDR, ANY_PORT,
|
||||
&sock2, &bind_addr6);
|
||||
|
||||
rv = setsockopt(sock1, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", rv);
|
||||
rv = getsockopt(sock1, SOL_SOCKET, SO_RCVBUF, &retval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", rv);
|
||||
zassert_equal(retval, optval, "getsockopt got invalid rcvbuf");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
rv = setsockopt(sock2, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", rv);
|
||||
rv = getsockopt(sock2, SOL_SOCKET, SO_RCVBUF, &retval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", rv);
|
||||
zassert_equal(retval, optval, "getsockopt got invalid rcvbuf");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
optval = -1;
|
||||
rv = setsockopt(sock2, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
zassert_equal(rv, -1, "setsockopt failed (%d)", rv);
|
||||
|
||||
optval = UINT16_MAX + 1;
|
||||
rv = setsockopt(sock2, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
zassert_equal(rv, -1, "setsockopt failed (%d)", rv);
|
||||
|
||||
test_close(sock1);
|
||||
test_close(sock2);
|
||||
}
|
||||
|
||||
void test_v4_so_rcvtimeo(void)
|
||||
{
|
||||
int c_sock;
|
||||
|
@ -1071,6 +1111,7 @@ void test_main(void)
|
|||
ztest_user_unit_test(test_v4_accept_timeout),
|
||||
ztest_unit_test(test_so_type),
|
||||
ztest_unit_test(test_so_protocol),
|
||||
ztest_unit_test(test_so_rcvbuf),
|
||||
ztest_unit_test(test_v4_so_rcvtimeo),
|
||||
ztest_unit_test(test_v6_so_rcvtimeo),
|
||||
ztest_unit_test(test_v4_msg_waitall),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue