tests: net: udp: Add tests for SO_PRIORITY and setsockopt

Verify that user is able to set SO_PRIORITY socket option.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2019-05-30 23:38:05 +08:00
parent c3bb0a6af9
commit 194893d52d
3 changed files with 39 additions and 3 deletions

View file

@ -21,3 +21,4 @@ CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_ZTEST=y
CONFIG_NET_CONTEXT_PRIORITY=y

View file

@ -301,6 +301,40 @@ void test_send_recv_2_sock(void)
zassert_equal(rv, 0, "close failed");
}
void test_so_priority(void)
{
struct sockaddr_in bind_addr4;
struct sockaddr_in6 bind_addr6;
int sock1, sock2, rv;
u8_t optval;
prepare_sock_udp_v4(CONFIG_NET_CONFIG_MY_IPV4_ADDR, 55555,
&sock1, &bind_addr4);
prepare_sock_udp_v6(CONFIG_NET_CONFIG_MY_IPV6_ADDR, 55555,
&sock2, &bind_addr6);
rv = bind(sock1, (struct sockaddr *)&bind_addr4, sizeof(bind_addr4));
zassert_equal(rv, 0, "bind failed");
rv = bind(sock2, (struct sockaddr *)&bind_addr6, sizeof(bind_addr6));
zassert_equal(rv, 0, "bind failed");
optval = 2;
rv = setsockopt(sock1, SOL_SOCKET, SO_PRIORITY, &optval,
sizeof(optval));
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
optval = 8;
rv = setsockopt(sock2, SOL_SOCKET, SO_PRIORITY, &optval,
sizeof(optval));
zassert_equal(rv, 0, "setsockopt failed");
rv = close(sock1);
zassert_equal(rv, 0, "close failed");
rv = close(sock2);
zassert_equal(rv, 0, "close failed");
}
void test_main(void)
{
ztest_test_suite(socket_udp,
@ -308,7 +342,9 @@ void test_main(void)
ztest_unit_test(test_v4_sendto_recvfrom),
ztest_unit_test(test_v6_sendto_recvfrom),
ztest_unit_test(test_v4_bind_sendto),
ztest_unit_test(test_v6_bind_sendto));
ztest_unit_test(test_v6_bind_sendto),
ztest_unit_test(test_so_priority)
);
ztest_run_test_suite(socket_udp);
}

View file

@ -1,10 +1,9 @@
common:
depends_on: netif
platform_whitelist: native_posix qemu_x86 qemu_cortex_m3
tags: net socket udp
tests:
net.socket.udp:
extra_configs:
- CONFIG_NET_TEST=y
- CONFIG_NET_LOOPBACK=y
min_ram: 21
tags: net socket