tests: net: socket: offload_dispatcher move to new ztest API
Move offload_dispatcher tests to use new ztest API TEST=twister -T tests/net/socket/offload_dispatcher Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
This commit is contained in:
parent
37c956ffb9
commit
011b1ea8da
|
@ -1,5 +1,6 @@
|
|||
CONFIG_NET_TEST=y
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
CONFIG_ZTEST_STACK_SIZE=2048
|
||||
|
||||
# Networking config
|
||||
|
|
|
@ -436,18 +436,21 @@ static void test_result_reset(void)
|
|||
k_sem_reset(&test_native_send_called);
|
||||
}
|
||||
|
||||
static void test_socket_setup_udp(void)
|
||||
static void test_socket_setup_udp(void *dummy)
|
||||
{
|
||||
ARG_UNUSED(dummy);
|
||||
test_result_reset();
|
||||
|
||||
test_sock = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
zassert_true(test_sock >= 0, "Failed to create socket");
|
||||
zassert_false(test_socket_ctx[OFFLOAD_1].socket_called,
|
||||
"Socket should'nt have been dispatched yet");
|
||||
}
|
||||
|
||||
static void test_socket_setup_tls(void)
|
||||
static void test_socket_setup_tls(void *dummy)
|
||||
{
|
||||
ARG_UNUSED(dummy);
|
||||
test_result_reset();
|
||||
|
||||
test_sock = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);
|
||||
|
@ -456,8 +459,10 @@ static void test_socket_setup_tls(void)
|
|||
"Socket should'nt have been dispatched yet");
|
||||
}
|
||||
|
||||
static void test_socket_teardown(void)
|
||||
static void test_socket_teardown(void *dummy)
|
||||
{
|
||||
ARG_UNUSED(dummy);
|
||||
|
||||
int ret = zsock_close(test_sock);
|
||||
|
||||
test_sock = -1;
|
||||
|
@ -468,7 +473,7 @@ static void test_socket_teardown(void)
|
|||
/* Verify that socket is not dispatched when close() is called immediately after
|
||||
* creating dispatcher socket.
|
||||
*/
|
||||
static void test_close_not_bound(void)
|
||||
ZTEST(net_socket_offload_close, test_close_not_bound)
|
||||
{
|
||||
int ret = zsock_close(test_sock);
|
||||
|
||||
|
@ -484,7 +489,7 @@ static void test_close_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on ioctl() call, if not bound.
|
||||
*/
|
||||
static void test_fcntl_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_fcntl_not_bound)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -499,7 +504,8 @@ static void test_fcntl_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on shutdown() call, if not bound.
|
||||
*/
|
||||
static void test_shutdown_not_bound(void)
|
||||
|
||||
ZTEST(net_socket_offload_udp, test_shutdown_not_bound)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -514,7 +520,7 @@ static void test_shutdown_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on bind() call, if not bound.
|
||||
*/
|
||||
static void test_bind_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_bind_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_in addr = {
|
||||
|
@ -532,7 +538,7 @@ static void test_bind_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on connect() call, if not bound.
|
||||
*/
|
||||
static void test_connect_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_connect_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_in addr = test_peer_addr;
|
||||
|
@ -548,7 +554,7 @@ static void test_connect_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on listen() call, if not bound.
|
||||
*/
|
||||
static void test_listen_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_listen_not_bound)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -563,7 +569,7 @@ static void test_listen_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on accept() call, if not bound.
|
||||
*/
|
||||
static void test_accept_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_accept_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_in addr;
|
||||
|
@ -580,7 +586,7 @@ static void test_accept_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on sendto() call, if not bound.
|
||||
*/
|
||||
static void test_sendto_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_sendto_not_bound)
|
||||
{
|
||||
int ret;
|
||||
uint8_t dummy_data = 0;
|
||||
|
@ -598,7 +604,7 @@ static void test_sendto_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on recvfrom() call, if not bound.
|
||||
*/
|
||||
static void test_recvfrom_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_recvfrom_not_bound)
|
||||
{
|
||||
int ret;
|
||||
uint8_t dummy_data = 0;
|
||||
|
@ -614,7 +620,7 @@ static void test_recvfrom_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on getsockopt() call, if not bound.
|
||||
*/
|
||||
static void test_getsockopt_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_getsockopt_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct timeval optval = { 0 };
|
||||
|
@ -632,7 +638,7 @@ static void test_getsockopt_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on setsockopt() call, if not bound.
|
||||
*/
|
||||
static void test_setsockopt_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_setsockopt_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct timeval optval = { 0 };
|
||||
|
@ -649,7 +655,7 @@ static void test_setsockopt_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on sendmsg() call, if not bound.
|
||||
*/
|
||||
static void test_sendmsg_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_sendmsg_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct msghdr dummy_msg = { 0 };
|
||||
|
@ -665,7 +671,7 @@ static void test_sendmsg_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on getpeername() call, if not bound.
|
||||
*/
|
||||
static void test_getpeername_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_getpeername_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_in addr;
|
||||
|
@ -682,7 +688,7 @@ static void test_getpeername_not_bound(void)
|
|||
/* Verify that socket is automatically dispatched to a default socket
|
||||
* implementation on getsockname() call, if not bound.
|
||||
*/
|
||||
static void test_getsockname_not_bound(void)
|
||||
ZTEST(net_socket_offload_udp, test_getsockname_not_bound)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_in addr;
|
||||
|
@ -699,7 +705,7 @@ static void test_getsockname_not_bound(void)
|
|||
/* Verify that socket is dispatched to a proper offloaded socket implementation
|
||||
* if the socket is bound to an offloaded interface.
|
||||
*/
|
||||
static void test_so_bindtodevice_iface_offloaded(void)
|
||||
ZTEST(net_socket_offload_udp, test_so_bindtodevice_iface_offloaded)
|
||||
{
|
||||
int ret;
|
||||
uint8_t dummy_data = 0;
|
||||
|
@ -730,7 +736,7 @@ static void test_so_bindtodevice_iface_offloaded(void)
|
|||
/* Verify that socket is dispatched to a native socket implementation
|
||||
* if the socket is bound to a native interface.
|
||||
*/
|
||||
static void test_so_bindtodevice_iface_native(void)
|
||||
ZTEST(net_socket_offload_udp, test_so_bindtodevice_iface_native)
|
||||
{
|
||||
int ret;
|
||||
uint8_t dummy_data = 0;
|
||||
|
@ -741,6 +747,7 @@ static void test_so_bindtodevice_iface_native(void)
|
|||
|
||||
ret = zsock_setsockopt(test_sock, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
&ifreq, sizeof(ifreq));
|
||||
|
||||
zassert_equal(0, ret, "setsockopt() failed");
|
||||
zassert_false(test_socket_ctx[OFFLOAD_1].socket_called,
|
||||
"Socket dispatched to wrong iface");
|
||||
|
@ -759,7 +766,7 @@ static void test_so_bindtodevice_iface_native(void)
|
|||
* implementation if native TLS is used and the socket is bound to an offloaded
|
||||
* interface.
|
||||
*/
|
||||
static void test_tls_native_iface_offloaded(void)
|
||||
ZTEST(net_socket_offload_tls, test_tls_native_iface_offloaded)
|
||||
{
|
||||
int ret;
|
||||
const struct fd_op_vtable *vtable;
|
||||
|
@ -802,7 +809,7 @@ static void test_tls_native_iface_offloaded(void)
|
|||
* implementation if native TLS is used and the socket is bound to a native
|
||||
* interface.
|
||||
*/
|
||||
static void test_tls_native_iface_native(void)
|
||||
ZTEST(net_socket_offload_tls, test_tls_native_iface_native)
|
||||
{
|
||||
int ret;
|
||||
const struct fd_op_vtable *vtable;
|
||||
|
@ -842,65 +849,9 @@ static void test_tls_native_iface_native(void)
|
|||
zassert_equal(0, ret, "sendto() should've been dispatched to native iface");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(
|
||||
socket_offload_dispatcher,
|
||||
ztest_unit_test_setup_teardown(test_close_not_bound,
|
||||
test_socket_setup_udp,
|
||||
unit_test_noop),
|
||||
ztest_unit_test_setup_teardown(test_fcntl_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_shutdown_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_bind_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_connect_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_listen_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_accept_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_sendto_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_recvfrom_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_getsockopt_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_setsockopt_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_sendmsg_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_getpeername_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_getsockname_not_bound,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_so_bindtodevice_iface_offloaded,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_so_bindtodevice_iface_native,
|
||||
test_socket_setup_udp,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_tls_native_iface_offloaded,
|
||||
test_socket_setup_tls,
|
||||
test_socket_teardown),
|
||||
ztest_unit_test_setup_teardown(test_tls_native_iface_native,
|
||||
test_socket_setup_tls,
|
||||
test_socket_teardown)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(socket_offload_dispatcher);
|
||||
}
|
||||
ZTEST_SUITE(net_socket_offload_udp, NULL, NULL, test_socket_setup_udp,
|
||||
test_socket_teardown, NULL);
|
||||
ZTEST_SUITE(net_socket_offload_tls, NULL, NULL, test_socket_setup_tls,
|
||||
test_socket_teardown, NULL);
|
||||
ZTEST_SUITE(net_socket_offload_close, NULL, NULL, test_socket_setup_udp,
|
||||
NULL, NULL);
|
||||
|
|
Loading…
Reference in a new issue