tests: net: tcp: Add new tests for get/set SO_SNDBUF

Test SO_SNDBUF option using getsockopt and setsockopt.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
This commit is contained in:
Mohan Kumar Kumar 2022-04-01 12:50:31 -07:00 committed by Carles Cufí
parent f105ea6ef5
commit 2558d277e2
2 changed files with 42 additions and 0 deletions

View file

@ -37,3 +37,4 @@ CONFIG_ZTEST_STACK_SIZE=2048
CONFIG_NET_CONTEXT_RCVTIMEO=y
CONFIG_NET_CONTEXT_RCVBUF=y
CONFIG_NET_CONTEXT_SNDBUF=y

View file

@ -846,6 +846,46 @@ void test_so_rcvbuf(void)
test_close(sock2);
}
void test_so_sndbuf(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_SNDBUF, &optval, sizeof(optval));
zassert_equal(rv, 0, "setsockopt failed (%d)", rv);
rv = getsockopt(sock1, SOL_SOCKET, SO_SNDBUF, &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_SNDBUF, &optval, sizeof(optval));
zassert_equal(rv, 0, "setsockopt failed (%d)", rv);
rv = getsockopt(sock2, SOL_SOCKET, SO_SNDBUF, &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_SNDBUF, &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;
@ -1246,6 +1286,7 @@ void test_main(void)
ztest_unit_test(test_so_type),
ztest_unit_test(test_so_protocol),
ztest_unit_test(test_so_rcvbuf),
ztest_unit_test(test_so_sndbuf),
ztest_unit_test(test_v4_so_rcvtimeo),
ztest_unit_test(test_v6_so_rcvtimeo),
ztest_unit_test(test_v4_msg_waitall),