tests: net: sockets: Remove use of NET_SOCKETS_POSIX_NAMES
The setting is deprecated so change the code to either use the native zsock_* API or enable POSIX_API to use the BSD socket API. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
d67fb8321c
commit
0512e7ffae
|
@ -7,10 +7,11 @@ CONFIG_NET_TCP=y
|
|||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS_POLL_MAX=4
|
||||
CONFIG_NET_CONNECTION_MANAGER=y
|
||||
|
||||
CONFIG_POSIX_API=y
|
||||
|
||||
# Kernel options
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_ENTROPY_GENERATOR=y
|
||||
|
|
|
@ -9,6 +9,7 @@ CONFIG_TEST_RANDOM_GENERATOR=y
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=4
|
||||
CONFIG_MAX_THREAD_BYTES=4
|
||||
CONFIG_POSIX_API=y
|
||||
|
||||
# TLS configuration
|
||||
CONFIG_MBEDTLS=y
|
||||
|
@ -362,7 +363,6 @@ CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
|
|||
CONFIG_NET_SOCKETS_OFFLOAD=y
|
||||
CONFIG_NET_SOCKETS_PACKET=y
|
||||
CONFIG_NET_SOCKETS_POLL_MAX=50
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
|
||||
CONFIG_NET_SOCKETS_TLS_MAX_CIPHERSUITES=10
|
||||
|
|
|
@ -405,18 +405,18 @@ static int set_up_recv_socket(enum net_sock_type socket_type)
|
|||
};
|
||||
int fd;
|
||||
|
||||
fd = socket(AF_PACKET, socket_type, ETH_P_IEEE802154);
|
||||
fd = zsock_socket(AF_PACKET, socket_type, ETH_P_IEEE802154);
|
||||
if (fd < 0) {
|
||||
NET_ERR("*** Failed to create recv socket : %d", errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
if (bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
if (zsock_bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
NET_ERR("*** Failed to bind packet socket : %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval, sizeof(timeo_optval))) {
|
||||
if (zsock_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval, sizeof(timeo_optval))) {
|
||||
NET_ERR("*** Failed to set reception timeout on packet socket : %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ static int set_up_recv_socket(enum net_sock_type socket_type)
|
|||
return fd;
|
||||
|
||||
release_fd:
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
return -EFAULT;
|
||||
}
|
||||
#endif /* CONFIG_NET_SOCKETS */
|
||||
|
@ -697,7 +697,7 @@ static bool test_dgram_packet_sending(void *dst_sll, uint8_t dst_sll_halen, uint
|
|||
}
|
||||
|
||||
NET_INFO("- Sending DGRAM packet via AF_PACKET socket");
|
||||
fd = socket(AF_PACKET, SOCK_DGRAM, ETH_P_IEEE802154);
|
||||
fd = zsock_socket(AF_PACKET, SOCK_DGRAM, ETH_P_IEEE802154);
|
||||
if (fd < 0) {
|
||||
NET_ERR("*** Failed to create DGRAM socket : %d", errno);
|
||||
goto reset_security;
|
||||
|
@ -715,13 +715,13 @@ static bool test_dgram_packet_sending(void *dst_sll, uint8_t dst_sll_halen, uint
|
|||
goto release_fd;
|
||||
}
|
||||
|
||||
if (bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
if (zsock_bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
NET_ERR("*** Failed to bind packet socket : %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
||||
if (sendto(fd, payload, sizeof(payload), 0, (const struct sockaddr *)&pkt_dst_sll,
|
||||
sizeof(struct sockaddr_ll)) != sizeof(payload)) {
|
||||
if (zsock_sendto(fd, payload, sizeof(payload), 0, (const struct sockaddr *)&pkt_dst_sll,
|
||||
sizeof(struct sockaddr_ll)) != sizeof(payload)) {
|
||||
NET_ERR("*** Failed to send, errno %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ release_frag:
|
|||
current_pkt->frags = NULL;
|
||||
release_fd:
|
||||
tear_down_short_addr(net_iface, ctx);
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
reset_security:
|
||||
tear_down_security();
|
||||
out:
|
||||
|
@ -877,8 +877,8 @@ static bool test_dgram_packet_reception(void *src_ll_addr, uint8_t src_ll_addr_l
|
|||
}
|
||||
|
||||
recv_src_sll_len = sizeof(recv_src_sll);
|
||||
received_len = recvfrom(fd, received_payload, sizeof(received_payload), 0,
|
||||
(struct sockaddr *)&recv_src_sll, &recv_src_sll_len);
|
||||
received_len = zsock_recvfrom(fd, received_payload, sizeof(received_payload), 0,
|
||||
(struct sockaddr *)&recv_src_sll, &recv_src_sll_len);
|
||||
if (received_len < 0) {
|
||||
NET_ERR("*** Failed to receive packet, errno %d", errno);
|
||||
goto release_pkt;
|
||||
|
@ -905,7 +905,7 @@ static bool test_dgram_packet_reception(void *src_ll_addr, uint8_t src_ll_addr_l
|
|||
release_pkt:
|
||||
net_pkt_unref(pkt);
|
||||
release_fd:
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
reset_security:
|
||||
tear_down_security();
|
||||
out:
|
||||
|
@ -924,7 +924,7 @@ static bool test_raw_packet_sending(void)
|
|||
|
||||
NET_INFO("- Sending RAW packet via AF_PACKET socket");
|
||||
|
||||
fd = socket(AF_PACKET, SOCK_RAW, ETH_P_IEEE802154);
|
||||
fd = zsock_socket(AF_PACKET, SOCK_RAW, ETH_P_IEEE802154);
|
||||
if (fd < 0) {
|
||||
NET_ERR("*** Failed to create RAW socket : %d", errno);
|
||||
goto out;
|
||||
|
@ -934,7 +934,7 @@ static bool test_raw_packet_sending(void)
|
|||
socket_sll.sll_family = AF_PACKET;
|
||||
socket_sll.sll_protocol = ETH_P_IEEE802154;
|
||||
|
||||
if (bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
if (zsock_bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
NET_ERR("*** Failed to bind packet socket : %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
@ -944,7 +944,7 @@ static bool test_raw_packet_sending(void)
|
|||
msg.msg_iov = &io_vector;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
if (sendmsg(fd, &msg, 0) != sizeof(raw_payload)) {
|
||||
if (zsock_sendmsg(fd, &msg, 0) != sizeof(raw_payload)) {
|
||||
NET_ERR("*** Failed to send, errno %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
@ -977,7 +977,7 @@ release_frag:
|
|||
net_pkt_frag_unref(current_pkt->frags);
|
||||
current_pkt->frags = NULL;
|
||||
release_fd:
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
@ -1031,7 +1031,7 @@ static bool test_raw_packet_reception(void)
|
|||
* extracted. We'll only be able to do so when Zephyr provides hooks to
|
||||
* call out to L2 from raw socket contexts.
|
||||
*/
|
||||
received_len = recv(fd, received_payload, sizeof(received_payload), 0);
|
||||
received_len = zsock_recv(fd, received_payload, sizeof(received_payload), 0);
|
||||
if (received_len < 0) {
|
||||
NET_ERR("*** Failed to receive packet, errno %d", errno);
|
||||
goto release_pkt;
|
||||
|
@ -1058,7 +1058,7 @@ static bool test_raw_packet_reception(void)
|
|||
release_pkt:
|
||||
net_pkt_unref(pkt);
|
||||
release_fd:
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
@ -1108,18 +1108,18 @@ static bool test_recv_and_send_ack_reply(struct ieee802154_pkt_test *t)
|
|||
|
||||
NET_INFO("- Sending ACK reply to a data packet");
|
||||
|
||||
fd = socket(AF_PACKET, SOCK_DGRAM, ETH_P_IEEE802154);
|
||||
fd = zsock_socket(AF_PACKET, SOCK_DGRAM, ETH_P_IEEE802154);
|
||||
if (fd < 0) {
|
||||
NET_ERR("*** Failed to create DGRAM socket : %d", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
if (zsock_bind(fd, (const struct sockaddr *)&socket_sll, sizeof(struct sockaddr_ll))) {
|
||||
NET_ERR("*** Failed to bind packet socket : %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval, sizeof(timeo_optval))) {
|
||||
if (zsock_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval, sizeof(timeo_optval))) {
|
||||
NET_ERR("*** Failed to set reception timeout on packet socket : %d", errno);
|
||||
goto release_fd;
|
||||
}
|
||||
|
@ -1139,8 +1139,8 @@ static bool test_recv_and_send_ack_reply(struct ieee802154_pkt_test *t)
|
|||
}
|
||||
|
||||
recv_src_sll_len = sizeof(recv_src_sll);
|
||||
received_len = recvfrom(fd, received_payload, sizeof(received_payload), 0,
|
||||
(struct sockaddr *)&recv_src_sll, &recv_src_sll_len);
|
||||
received_len = zsock_recvfrom(fd, received_payload, sizeof(received_payload), 0,
|
||||
(struct sockaddr *)&recv_src_sll, &recv_src_sll_len);
|
||||
if (received_len < 0) {
|
||||
NET_ERR("*** Failed to receive packet, errno %d", errno);
|
||||
goto release_rx_pkt;
|
||||
|
@ -1202,7 +1202,7 @@ release_rx_pkt:
|
|||
reset_short_addr:
|
||||
tear_down_short_addr(net_iface, ctx);
|
||||
release_fd:
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ CONFIG_NET_L2_ETHERNET=n
|
|||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_POSIX_MAX_FDS=2
|
||||
CONFIG_ZTEST_STACK_SIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
|
|
|
@ -128,16 +128,16 @@ ZTEST(test_net_pm_test_suite, test_pm)
|
|||
|
||||
addr4.sin_family = AF_INET;
|
||||
addr4.sin_port = htons(12345);
|
||||
inet_pton(AF_INET, "192.168.0.1", &addr4.sin_addr);
|
||||
zsock_inet_pton(AF_INET, "192.168.0.1", &addr4.sin_addr);
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock >= 0, "Could not open socket");
|
||||
|
||||
zassert_false(net_if_is_suspended(iface), "net iface is not suspended");
|
||||
|
||||
/* Let's send some data, it should go through */
|
||||
ret = sendto(sock, data, ARRAY_SIZE(data), 0,
|
||||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
ret = zsock_sendto(sock, data, ARRAY_SIZE(data), 0,
|
||||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
zassert_true(ret > 0, "Could not send data");
|
||||
|
||||
/* Let's make sure net stack's thread gets ran, or setting PM state
|
||||
|
@ -157,8 +157,8 @@ ZTEST(test_net_pm_test_suite, test_pm)
|
|||
zassert_true(net_if_is_suspended(iface), "net iface is not suspended");
|
||||
|
||||
/* Let's send some data, it should fail relevantly */
|
||||
ret = sendto(sock, data, ARRAY_SIZE(data), 0,
|
||||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
ret = zsock_sendto(sock, data, ARRAY_SIZE(data), 0,
|
||||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
zassert_true(ret < 0, "Could send data");
|
||||
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);
|
||||
|
@ -170,11 +170,11 @@ ZTEST(test_net_pm_test_suite, test_pm)
|
|||
zassert_true(ret == -EALREADY, "Could change state");
|
||||
|
||||
/* Let's send some data, it should go through */
|
||||
ret = sendto(sock, data, ARRAY_SIZE(data), 0,
|
||||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
ret = zsock_sendto(sock, data, ARRAY_SIZE(data), 0,
|
||||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
zassert_true(ret > 0, "Could not send data");
|
||||
|
||||
close(sock);
|
||||
zsock_close(sock);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(test_net_pm_test_suite, NULL, test_setup, NULL, NULL, NULL);
|
||||
|
|
|
@ -5,7 +5,6 @@ CONFIG_NET_IPV6=n
|
|||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS_PACKET=y
|
||||
CONFIG_POSIX_MAX_FDS=8
|
||||
CONFIG_NET_IPV6_DAD=n
|
||||
|
|
|
@ -11,7 +11,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
|
|||
#include <zephyr/sys/mutex.h>
|
||||
#include <zephyr/ztest_assert.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <zephyr/posix/fcntl.h>
|
||||
#include <zephyr/net/socket.h>
|
||||
#include <zephyr/net/ethernet.h>
|
||||
|
||||
|
@ -107,7 +107,7 @@ static int setup_socket(struct net_if *iface, int type, int proto)
|
|||
{
|
||||
int sock;
|
||||
|
||||
sock = socket(AF_PACKET, type, proto);
|
||||
sock = zsock_socket(AF_PACKET, type, proto);
|
||||
zassert_true(sock >= 0, "Cannot create packet socket (%d)", -errno);
|
||||
|
||||
return sock;
|
||||
|
@ -122,7 +122,7 @@ static int bind_socket(int sock, struct net_if *iface)
|
|||
addr.sll_ifindex = net_if_get_by_iface(iface);
|
||||
addr.sll_family = AF_PACKET;
|
||||
|
||||
return bind(sock, (struct sockaddr *)&addr, sizeof(addr));
|
||||
return zsock_bind(sock, (struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
|
||||
struct user_data {
|
||||
|
@ -157,7 +157,7 @@ static void setblocking(int fd, bool val)
|
|||
{
|
||||
int fl, res;
|
||||
|
||||
fl = fcntl(fd, F_GETFL, 0);
|
||||
fl = zsock_fcntl(fd, F_GETFL, 0);
|
||||
zassert_not_equal(fl, -1, "Fail to set fcntl");
|
||||
|
||||
if (val) {
|
||||
|
@ -166,7 +166,7 @@ static void setblocking(int fd, bool val)
|
|||
fl |= O_NONBLOCK;
|
||||
}
|
||||
|
||||
res = fcntl(fd, F_SETFL, fl);
|
||||
res = zsock_fcntl(fd, F_SETFL, fl);
|
||||
zassert_not_equal(res, -1, "Fail to set fcntl");
|
||||
}
|
||||
|
||||
|
@ -176,16 +176,16 @@ static int prepare_udp_socket(struct sockaddr_in *sockaddr, uint16_t local_port)
|
|||
{
|
||||
int sock, ret;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock >= 0, "Cannot create DGRAM (UDP) socket (%d)", sock);
|
||||
|
||||
sockaddr->sin_family = AF_INET;
|
||||
sockaddr->sin_port = htons(local_port);
|
||||
ret = inet_pton(AF_INET, IPV4_ADDR, &sockaddr->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, IPV4_ADDR, &sockaddr->sin_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
/* Bind UDP socket to local port */
|
||||
ret = bind(sock, (struct sockaddr *) sockaddr, sizeof(*sockaddr));
|
||||
ret = zsock_bind(sock, (struct sockaddr *) sockaddr, sizeof(*sockaddr));
|
||||
zassert_equal(ret, 0, "Cannot bind DGRAM (UDP) socket (%d)", -errno);
|
||||
|
||||
return sock;
|
||||
|
@ -241,8 +241,8 @@ ZTEST(socket_packet, test_raw_packet_sockets)
|
|||
* Send UDP datagram to us - as check_ip_addr() in net_send_data()
|
||||
* returns 1 - the packet is processed immediately in the net stack
|
||||
*/
|
||||
sent = sendto(sock4, data_to_send, sizeof(data_to_send),
|
||||
0, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
||||
sent = zsock_sendto(sock4, data_to_send, sizeof(data_to_send),
|
||||
0, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
||||
zassert_equal(sent, sizeof(data_to_send), "sendto failed");
|
||||
|
||||
k_msleep(10); /* Let the packet enter the system */
|
||||
|
@ -253,8 +253,8 @@ ZTEST(socket_packet, test_raw_packet_sockets)
|
|||
|
||||
/* Check if UDP packets can be read after being sent */
|
||||
addrlen = sizeof(sockaddr);
|
||||
ret = recvfrom(sock3, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&sockaddr, &addrlen);
|
||||
ret = zsock_recvfrom(sock3, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&sockaddr, &addrlen);
|
||||
zassert_equal(ret, sizeof(data_to_send), "Cannot receive all data (%d)",
|
||||
-errno);
|
||||
zassert_mem_equal(data_to_receive, data_to_send, sizeof(data_to_send),
|
||||
|
@ -271,8 +271,8 @@ ZTEST(socket_packet, test_raw_packet_sockets)
|
|||
* IP (20B) and UDP (8) headers. After those we can expect payload,
|
||||
* which have been sent.
|
||||
*/
|
||||
ret = recvfrom(sock1, data_to_receive, sizeof(data_to_receive), 0,
|
||||
(struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock1, data_to_receive, sizeof(data_to_receive), 0,
|
||||
(struct sockaddr *)&src, &addrlen);
|
||||
zassert_equal(ret, sizeof(data_to_send) + HDR_SIZE,
|
||||
"Cannot receive all data (%d vs %zd) (%d)",
|
||||
ret, sizeof(data_to_send), -errno);
|
||||
|
@ -280,10 +280,10 @@ ZTEST(socket_packet, test_raw_packet_sockets)
|
|||
sizeof(data_to_send),
|
||||
"Sent and received buffers do not match");
|
||||
|
||||
close(sock1);
|
||||
close(sock2);
|
||||
close(sock3);
|
||||
close(sock4);
|
||||
zsock_close(sock1);
|
||||
zsock_close(sock2);
|
||||
zsock_close(sock3);
|
||||
zsock_close(sock4);
|
||||
}
|
||||
|
||||
ZTEST(socket_packet, test_packet_sockets)
|
||||
|
@ -292,8 +292,8 @@ ZTEST(socket_packet, test_packet_sockets)
|
|||
|
||||
__test_packet_sockets(&sock1, &sock2);
|
||||
|
||||
close(sock1);
|
||||
close(sock2);
|
||||
zsock_close(sock1);
|
||||
zsock_close(sock2);
|
||||
}
|
||||
|
||||
ZTEST(socket_packet, test_packet_sockets_dgram)
|
||||
|
@ -331,8 +331,8 @@ ZTEST(socket_packet, test_packet_sockets_dgram)
|
|||
dst.sll_protocol = htons(ETH_P_IP);
|
||||
memcpy(dst.sll_addr, lladdr1, sizeof(lladdr1));
|
||||
|
||||
ret = sendto(sock2, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
ret = zsock_sendto(sock2, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_equal(ret, sizeof(data_to_send), "Cannot send all data (%d)",
|
||||
-errno);
|
||||
|
||||
|
@ -342,8 +342,8 @@ ZTEST(socket_packet, test_packet_sockets_dgram)
|
|||
errno = 0;
|
||||
iter = 0;
|
||||
do {
|
||||
ret = recvfrom(sock1, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock1, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
k_msleep(10);
|
||||
iter++;
|
||||
} while (ret < 0 && errno == EAGAIN && iter < max_iter);
|
||||
|
@ -360,16 +360,16 @@ ZTEST(socket_packet, test_packet_sockets_dgram)
|
|||
/* Send to socket 2 but read from socket 1. There should not be any
|
||||
* data in socket 1
|
||||
*/
|
||||
ret = sendto(sock2, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
ret = zsock_sendto(sock2, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_equal(ret, sizeof(data_to_send), "Cannot send all data (%d)",
|
||||
-errno);
|
||||
|
||||
k_msleep(10);
|
||||
memset(&src, 0, sizeof(src));
|
||||
|
||||
ret = recvfrom(sock1, data_to_receive, sizeof(data_to_receive), 0,
|
||||
(struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock1, data_to_receive, sizeof(data_to_receive), 0,
|
||||
(struct sockaddr *)&src, &addrlen);
|
||||
zassert_equal(ret, -1, "Received something (%d)", ret);
|
||||
zassert_equal(errno, EAGAIN, "Wrong errno (%d)", errno);
|
||||
|
||||
|
@ -378,8 +378,8 @@ ZTEST(socket_packet, test_packet_sockets_dgram)
|
|||
errno = 0;
|
||||
iter = 0;
|
||||
do {
|
||||
ret = recvfrom(sock2, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock2, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
k_msleep(10);
|
||||
iter++;
|
||||
} while (ret < 0 && errno == EAGAIN && iter < max_iter);
|
||||
|
@ -389,8 +389,8 @@ ZTEST(socket_packet, test_packet_sockets_dgram)
|
|||
zassert_mem_equal(data_to_send, data_to_receive, sizeof(data_to_send),
|
||||
"Data mismatch");
|
||||
|
||||
close(sock1);
|
||||
close(sock2);
|
||||
zsock_close(sock1);
|
||||
zsock_close(sock2);
|
||||
}
|
||||
|
||||
ZTEST(socket_packet, test_raw_and_dgram_socket_exchange)
|
||||
|
@ -443,8 +443,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_exchange)
|
|||
|
||||
/* SOCK_DGRAM to SOCK_RAW */
|
||||
|
||||
ret = sendto(sock1, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
ret = zsock_sendto(sock1, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_equal(ret, sizeof(data_to_send), "Cannot send all data (%d)",
|
||||
-errno);
|
||||
|
||||
|
@ -454,8 +454,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_exchange)
|
|||
errno = 0;
|
||||
iter = 0;
|
||||
do {
|
||||
ret = recvfrom(sock2, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock2, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
k_msleep(10);
|
||||
iter++;
|
||||
} while (ret < 0 && errno == EAGAIN && iter < max_iter);
|
||||
|
@ -473,8 +473,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_exchange)
|
|||
|
||||
/* SOCK_RAW to SOCK_DGRAM */
|
||||
|
||||
ret = sendto(sock2, send_payload_raw, sizeof(send_payload_raw), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
ret = zsock_sendto(sock2, send_payload_raw, sizeof(send_payload_raw), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_equal(ret, sizeof(send_payload_raw), "Cannot send all data (%d)",
|
||||
-errno);
|
||||
|
||||
|
@ -484,8 +484,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_exchange)
|
|||
errno = 0;
|
||||
iter = 0;
|
||||
do {
|
||||
ret = recvfrom(sock1, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock1, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
k_msleep(10);
|
||||
iter++;
|
||||
} while (ret < 0 && errno == EAGAIN && iter < max_iter);
|
||||
|
@ -495,8 +495,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_exchange)
|
|||
zassert_mem_equal(data_to_send, data_to_receive, sizeof(data_to_send),
|
||||
"Data mismatch");
|
||||
|
||||
close(sock1);
|
||||
close(sock2);
|
||||
zsock_close(sock1);
|
||||
zsock_close(sock2);
|
||||
}
|
||||
|
||||
ZTEST(socket_packet, test_raw_and_dgram_socket_recv)
|
||||
|
@ -547,8 +547,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_recv)
|
|||
dst.sll_protocol = htons(ETH_P_IP);
|
||||
memcpy(dst.sll_addr, lladdr2, sizeof(lladdr1));
|
||||
|
||||
ret = sendto(sock1, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
ret = zsock_sendto(sock1, data_to_send, sizeof(data_to_send), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_equal(ret, sizeof(data_to_send), "Cannot send all data (%d)",
|
||||
-errno);
|
||||
|
||||
|
@ -560,8 +560,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_recv)
|
|||
errno = 0;
|
||||
iter = 0;
|
||||
do {
|
||||
ret = recvfrom(sock2, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock2, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
k_msleep(10);
|
||||
iter++;
|
||||
} while (ret < 0 && errno == EAGAIN && iter < max_iter);
|
||||
|
@ -578,8 +578,8 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_recv)
|
|||
errno = 0;
|
||||
iter = 0;
|
||||
do {
|
||||
ret = recvfrom(sock3, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
ret = zsock_recvfrom(sock3, data_to_receive, sizeof(data_to_receive),
|
||||
0, (struct sockaddr *)&src, &addrlen);
|
||||
k_msleep(10);
|
||||
iter++;
|
||||
} while (ret < 0 && errno == EAGAIN && iter < max_iter);
|
||||
|
@ -589,9 +589,9 @@ ZTEST(socket_packet, test_raw_and_dgram_socket_recv)
|
|||
zassert_mem_equal(expected_payload_raw, data_to_receive,
|
||||
sizeof(expected_payload_raw), "Data mismatch");
|
||||
|
||||
close(sock1);
|
||||
close(sock2);
|
||||
close(sock3);
|
||||
zsock_close(sock1);
|
||||
zsock_close(sock2);
|
||||
zsock_close(sock3);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(socket_packet, NULL, NULL, NULL, NULL, NULL);
|
||||
|
|
|
@ -5,7 +5,6 @@ CONFIG_NET_IPV6=n
|
|||
CONFIG_NET_UDP=n
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS_PACKET=y
|
||||
CONFIG_POSIX_MAX_FDS=8
|
||||
CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
|
||||
|
|
|
@ -120,27 +120,27 @@ ZTEST(net_sckt_packet_raw_ip, test_sckt_raw_packet_raw_ip)
|
|||
char receive_buffer[128];
|
||||
int sock;
|
||||
|
||||
sock = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW);
|
||||
sock = zsock_socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW);
|
||||
zassert_true(sock >= 0, "Could not create a socket");
|
||||
|
||||
dst.sll_ifindex = net_if_get_by_iface(iface);
|
||||
dst.sll_family = AF_PACKET;
|
||||
|
||||
ret = bind(sock, (const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
ret = zsock_bind(sock, (const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_true(ret >= 0, "Could not bind the socket");
|
||||
|
||||
/* Let's send some data: */
|
||||
ret = sendto(sock, testing_data, ARRAY_SIZE(testing_data), 0, (const struct sockaddr *)&dst,
|
||||
sizeof(struct sockaddr_ll));
|
||||
ret = zsock_sendto(sock, testing_data, ARRAY_SIZE(testing_data), 0,
|
||||
(const struct sockaddr *)&dst, sizeof(struct sockaddr_ll));
|
||||
zassert_true(ret > 0, "Could not send data");
|
||||
|
||||
/* Receive the same data back: */
|
||||
recv_data_len = recv(sock, receive_buffer, sizeof(receive_buffer), 0);
|
||||
recv_data_len = zsock_recv(sock, receive_buffer, sizeof(receive_buffer), 0);
|
||||
zassert_true(recv_data_len == ARRAY_SIZE(testing_data), "Expected data not received");
|
||||
|
||||
NET_DBG("Received successfully data %s", receive_buffer);
|
||||
|
||||
close(sock);
|
||||
zsock_close(sock);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(net_sckt_packet_raw_ip, NULL, test_setup, NULL, NULL, NULL);
|
||||
|
|
|
@ -9,7 +9,6 @@ CONFIG_NET_LOOPBACK=y
|
|||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_L2_ETHERNET=n
|
||||
|
||||
# Network driver config
|
||||
|
|
|
@ -110,7 +110,7 @@ static bool check_dns_query(uint8_t *buf, int buf_len)
|
|||
|
||||
static int process_dns(void)
|
||||
{
|
||||
struct pollfd pollfds[2];
|
||||
struct zsock_pollfd pollfds[2];
|
||||
struct sockaddr *addr;
|
||||
socklen_t addr_len;
|
||||
int ret, idx;
|
||||
|
@ -123,19 +123,19 @@ static int process_dns(void)
|
|||
while (true) {
|
||||
memset(pollfds, 0, sizeof(pollfds));
|
||||
pollfds[0].fd = sock_v4;
|
||||
pollfds[0].events = POLLIN;
|
||||
pollfds[0].events = ZSOCK_POLLIN;
|
||||
pollfds[1].fd = sock_v6;
|
||||
pollfds[1].events = POLLIN;
|
||||
pollfds[1].events = ZSOCK_POLLIN;
|
||||
|
||||
NET_DBG("Polling...");
|
||||
|
||||
ret = poll(pollfds, ARRAY_SIZE(pollfds), -1);
|
||||
ret = zsock_poll(pollfds, ARRAY_SIZE(pollfds), -1);
|
||||
if (ret <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (idx = 0; idx < ARRAY_SIZE(pollfds); idx++) {
|
||||
if (pollfds[idx].revents & POLLIN) {
|
||||
if (pollfds[idx].revents & ZSOCK_POLLIN) {
|
||||
if (pollfds[idx].fd == sock_v4) {
|
||||
addr_len = sizeof(addr_v4);
|
||||
addr = (struct sockaddr *)&addr_v4;
|
||||
|
@ -144,9 +144,9 @@ static int process_dns(void)
|
|||
addr = (struct sockaddr *)&addr_v6;
|
||||
}
|
||||
|
||||
ret = recvfrom(pollfds[idx].fd,
|
||||
recv_buf, sizeof(recv_buf), 0,
|
||||
addr, &addr_len);
|
||||
ret = zsock_recvfrom(pollfds[idx].fd,
|
||||
recv_buf, sizeof(recv_buf), 0,
|
||||
addr, &addr_len);
|
||||
if (ret < 0) {
|
||||
/* Socket error */
|
||||
NET_ERR("DNS: Connection error (%d)",
|
||||
|
@ -200,13 +200,13 @@ static void *test_getaddrinfo_setup(void)
|
|||
memcpy(&addr_v6, net_sin6(&addr), sizeof(struct sockaddr_in6));
|
||||
}
|
||||
|
||||
addr_str = inet_ntop(AF_INET, &addr_v4.sin_addr, str, sizeof(str));
|
||||
addr_str = zsock_inet_ntop(AF_INET, &addr_v4.sin_addr, str, sizeof(str));
|
||||
NET_DBG("v4: [%s]:%d", addr_str, ntohs(addr_v4.sin_port));
|
||||
|
||||
sock_v4 = prepare_listen_sock_udp_v4(&addr_v4);
|
||||
zassert_true(sock_v4 >= 0, "Invalid IPv4 socket");
|
||||
|
||||
addr_str = inet_ntop(AF_INET6, &addr_v6.sin6_addr, str, sizeof(str));
|
||||
addr_str = zsock_inet_ntop(AF_INET6, &addr_v6.sin6_addr, str, sizeof(str));
|
||||
NET_DBG("v6: [%s]:%d", addr_str, ntohs(addr_v6.sin6_port));
|
||||
|
||||
sock_v6 = prepare_listen_sock_udp_v6(&addr_v6);
|
||||
|
@ -225,7 +225,7 @@ static void *test_getaddrinfo_setup(void)
|
|||
|
||||
ZTEST(net_socket_getaddrinfo, test_getaddrinfo_ok)
|
||||
{
|
||||
struct addrinfo *res = NULL;
|
||||
struct zsock_addrinfo *res = NULL;
|
||||
|
||||
queries_received = 0;
|
||||
|
||||
|
@ -235,7 +235,7 @@ ZTEST(net_socket_getaddrinfo, test_getaddrinfo_ok)
|
|||
* that the query triggered a function call to process_dns() function
|
||||
* and that it could parse the DNS query.
|
||||
*/
|
||||
(void)getaddrinfo(QUERY_HOST, NULL, NULL, &res);
|
||||
(void)zsock_getaddrinfo(QUERY_HOST, NULL, NULL, &res);
|
||||
|
||||
(void)sys_sem_take(&wait_data, K_NO_WAIT);
|
||||
(void)sys_sem_take(&wait_data, K_NO_WAIT);
|
||||
|
@ -244,15 +244,15 @@ ZTEST(net_socket_getaddrinfo, test_getaddrinfo_ok)
|
|||
"Did not receive both IPv4 and IPv6 query (got %d, expected %d)",
|
||||
queries_received, expected_query_count);
|
||||
|
||||
freeaddrinfo(res);
|
||||
zsock_freeaddrinfo(res);
|
||||
}
|
||||
|
||||
ZTEST(net_socket_getaddrinfo, test_getaddrinfo_cancelled)
|
||||
{
|
||||
struct addrinfo *res = NULL;
|
||||
struct zsock_addrinfo *res = NULL;
|
||||
int ret;
|
||||
|
||||
ret = getaddrinfo(QUERY_HOST, NULL, NULL, &res);
|
||||
ret = zsock_getaddrinfo(QUERY_HOST, NULL, NULL, &res);
|
||||
|
||||
(void)sys_sem_take(&wait_data, K_NO_WAIT);
|
||||
(void)sys_sem_take(&wait_data, K_NO_WAIT);
|
||||
|
@ -264,21 +264,21 @@ ZTEST(net_socket_getaddrinfo, test_getaddrinfo_cancelled)
|
|||
/* Without a local DNS server this request will be canceled. */
|
||||
zassert_equal(ret, DNS_EAI_CANCELED, "Invalid result");
|
||||
|
||||
freeaddrinfo(res);
|
||||
zsock_freeaddrinfo(res);
|
||||
}
|
||||
|
||||
ZTEST(net_socket_getaddrinfo, test_getaddrinfo_no_host)
|
||||
{
|
||||
struct addrinfo *res = NULL;
|
||||
struct zsock_addrinfo *res = NULL;
|
||||
int ret;
|
||||
|
||||
ret = getaddrinfo(NULL, NULL, NULL, &res);
|
||||
ret = zsock_getaddrinfo(NULL, NULL, NULL, &res);
|
||||
|
||||
zassert_equal(ret, DNS_EAI_SYSTEM, "Invalid result");
|
||||
zassert_equal(errno, EINVAL, "Invalid errno");
|
||||
zassert_is_null(res, "ai_addr is not NULL");
|
||||
|
||||
freeaddrinfo(res);
|
||||
zsock_freeaddrinfo(res);
|
||||
}
|
||||
|
||||
ZTEST(net_socket_getaddrinfo, test_getaddrinfo_num_ipv4)
|
||||
|
|
|
@ -9,7 +9,6 @@ CONFIG_NET_LOOPBACK=y
|
|||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
|
||||
# Network driver config
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
|
|
@ -22,8 +22,8 @@ ZTEST_USER(net_socket_getnameinfo, test_getnameinfo_ipv4)
|
|||
memset(&saddr, 0, sizeof(saddr));
|
||||
saddr.sin_family = AF_INET;
|
||||
|
||||
ret = getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
ret = zsock_getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
zassert_equal(ret, 0, "");
|
||||
|
||||
printk("%s %s\n", host, serv);
|
||||
|
@ -33,8 +33,8 @@ ZTEST_USER(net_socket_getnameinfo, test_getnameinfo_ipv4)
|
|||
saddr.sin_port = htons(1234);
|
||||
saddr.sin_addr.s_addr = htonl(0x7f000001);
|
||||
|
||||
ret = getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
ret = zsock_getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
zassert_equal(ret, 0, "");
|
||||
|
||||
printk("%s %s\n", host, serv);
|
||||
|
@ -52,8 +52,8 @@ ZTEST_USER(net_socket_getnameinfo, test_getnameinfo_ipv6)
|
|||
memset(&saddr, 0, sizeof(saddr));
|
||||
saddr.sin6_family = AF_INET6;
|
||||
|
||||
ret = getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
ret = zsock_getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
zassert_equal(ret, 0, "");
|
||||
|
||||
printk("%s %s\n", host, serv);
|
||||
|
@ -65,8 +65,8 @@ ZTEST_USER(net_socket_getnameinfo, test_getnameinfo_ipv6)
|
|||
saddr.sin6_addr.s6_addr[1] = 0x55;
|
||||
saddr.sin6_addr.s6_addr[15] = 0x11;
|
||||
|
||||
ret = getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
ret = zsock_getnameinfo((struct sockaddr *)&saddr, sizeof(saddr),
|
||||
host, sizeof(host), serv, sizeof(serv), 0);
|
||||
zassert_equal(ret, 0, "");
|
||||
|
||||
printk("%s %s\n", host, serv);
|
||||
|
|
|
@ -11,7 +11,6 @@ CONFIG_NET_IPV6=y
|
|||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_L2_DUMMY=y
|
||||
CONFIG_NET_IPV6_DAD=n
|
||||
CONFIG_NET_IPV6_MLD=n
|
||||
|
|
|
@ -23,7 +23,7 @@ ZTEST_USER(socket_misc_test_suite, test_gethostname)
|
|||
static ZTEST_BMEM char buf[80];
|
||||
int res;
|
||||
|
||||
res = gethostname(buf, sizeof(buf));
|
||||
res = zsock_gethostname(buf, sizeof(buf));
|
||||
zassert_equal(res, 0, "");
|
||||
printk("%s\n", buf);
|
||||
zassert_equal(strcmp(buf, "ztest_hostname"), 0, "");
|
||||
|
@ -34,22 +34,22 @@ ZTEST_USER(socket_misc_test_suite, test_inet_pton)
|
|||
int res;
|
||||
uint8_t buf[32];
|
||||
|
||||
res = inet_pton(AF_INET, "127.0.0.1", buf);
|
||||
res = zsock_inet_pton(AF_INET, "127.0.0.1", buf);
|
||||
zassert_equal(res, 1, "");
|
||||
|
||||
res = inet_pton(AF_INET, "127.0.0.1a", buf);
|
||||
res = zsock_inet_pton(AF_INET, "127.0.0.1a", buf);
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
res = inet_pton(AF_INET6, "a:b:c:d:0:1:2:3", buf);
|
||||
res = zsock_inet_pton(AF_INET6, "a:b:c:d:0:1:2:3", buf);
|
||||
zassert_equal(res, 1, "");
|
||||
|
||||
res = inet_pton(AF_INET6, "::1", buf);
|
||||
res = zsock_inet_pton(AF_INET6, "::1", buf);
|
||||
zassert_equal(res, 1, "");
|
||||
|
||||
res = inet_pton(AF_INET6, "1::", buf);
|
||||
res = zsock_inet_pton(AF_INET6, "1::", buf);
|
||||
zassert_equal(res, 1, "");
|
||||
|
||||
res = inet_pton(AF_INET6, "a:b:c:d:0:1:2:3z", buf);
|
||||
res = zsock_inet_pton(AF_INET6, "a:b:c:d:0:1:2:3z", buf);
|
||||
zassert_equal(res, 0, "");
|
||||
}
|
||||
|
||||
|
@ -181,14 +181,14 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
uint8_t send_buf[32];
|
||||
uint8_t recv_buf[sizeof(send_buf)] = { 0 };
|
||||
|
||||
ret = bind(sock_s, bind_addr, bind_addrlen);
|
||||
ret = zsock_bind(sock_s, bind_addr, bind_addrlen);
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
/* Bind server socket with interface 2. */
|
||||
|
||||
strcpy(ifreq.ifr_name, DEV2_NAME);
|
||||
ret = setsockopt(sock_s, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
ret = zsock_setsockopt(sock_s, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
zassert_equal(ret, 0, "SO_BINDTODEVICE failed, %d", errno);
|
||||
|
||||
/* Bind client socket with interface 1 and send a packet. */
|
||||
|
@ -198,12 +198,12 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
strcpy(ifreq.ifr_name, DEV1_NAME);
|
||||
strcpy(send_buf, DEV1_NAME);
|
||||
|
||||
ret = setsockopt(sock_c, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
ret = zsock_setsockopt(sock_c, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
zassert_equal(ret, 0, "SO_BINDTODEVICE failed, %d", errno);
|
||||
|
||||
ret = sendto(sock_c, send_buf, strlen(send_buf) + 1, 0,
|
||||
peer_addr, peer_addrlen);
|
||||
ret = zsock_sendto(sock_c, send_buf, strlen(send_buf) + 1, 0,
|
||||
peer_addr, peer_addrlen);
|
||||
zassert_equal(ret, strlen(send_buf) + 1, "sendto failed, %d", errno);
|
||||
|
||||
ret = sys_sem_take(&send_sem, K_MSEC(100));
|
||||
|
@ -223,12 +223,12 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
strcpy(ifreq.ifr_name, DEV2_NAME);
|
||||
strcpy(send_buf, DEV2_NAME);
|
||||
|
||||
ret = setsockopt(sock_c, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
ret = zsock_setsockopt(sock_c, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
zassert_equal(ret, 0, "SO_BINDTODEVICE failed, %d", errno);
|
||||
|
||||
ret = sendto(sock_c, send_buf, strlen(send_buf) + 1, 0,
|
||||
peer_addr, peer_addrlen);
|
||||
ret = zsock_sendto(sock_c, send_buf, strlen(send_buf) + 1, 0,
|
||||
peer_addr, peer_addrlen);
|
||||
zassert_equal(ret, strlen(send_buf) + 1, "sendto failed, %d", errno);
|
||||
|
||||
ret = sys_sem_take(&send_sem, K_MSEC(100));
|
||||
|
@ -243,7 +243,7 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
|
||||
k_msleep(10);
|
||||
|
||||
ret = recv(sock_s, recv_buf, sizeof(recv_buf), MSG_DONTWAIT);
|
||||
ret = zsock_recv(sock_s, recv_buf, sizeof(recv_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_true(ret > 0, "recv failed, %d", errno);
|
||||
zassert_mem_equal(recv_buf, DEV2_NAME, strlen(DEV2_NAME),
|
||||
"received datagram from invalid interface");
|
||||
|
@ -251,8 +251,8 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
/* Remove the binding from the server socket. */
|
||||
|
||||
strcpy(ifreq.ifr_name, "");
|
||||
ret = setsockopt(sock_s, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
ret = zsock_setsockopt(sock_s, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
zassert_equal(ret, 0, "SO_BINDTODEVICE failed, %d", errno);
|
||||
|
||||
/* Bind client socket with interface 1 again. */
|
||||
|
@ -261,12 +261,12 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
strcpy(ifreq.ifr_name, DEV1_NAME);
|
||||
strcpy(send_buf, DEV1_NAME);
|
||||
|
||||
ret = setsockopt(sock_c, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
ret = zsock_setsockopt(sock_c, SOL_SOCKET, SO_BINDTODEVICE, &ifreq,
|
||||
sizeof(ifreq));
|
||||
zassert_equal(ret, 0, "SO_BINDTODEVICE failed, %d", errno);
|
||||
|
||||
ret = sendto(sock_c, send_buf, strlen(send_buf) + 1, 0,
|
||||
peer_addr, peer_addrlen);
|
||||
ret = zsock_sendto(sock_c, send_buf, strlen(send_buf) + 1, 0,
|
||||
peer_addr, peer_addrlen);
|
||||
zassert_equal(ret, strlen(send_buf) + 1, "sendto failed, %d", errno);
|
||||
|
||||
ret = sys_sem_take(&send_sem, K_MSEC(100));
|
||||
|
@ -280,14 +280,14 @@ void test_so_bindtodevice(int sock_c, int sock_s, struct sockaddr *peer_addr,
|
|||
|
||||
k_msleep(10);
|
||||
|
||||
ret = recv(sock_s, recv_buf, sizeof(recv_buf), MSG_DONTWAIT);
|
||||
ret = zsock_recv(sock_s, recv_buf, sizeof(recv_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_true(ret > 0, "recv failed, %d", errno);
|
||||
zassert_mem_equal(recv_buf, DEV1_NAME, strlen(DEV1_NAME),
|
||||
"received datagram from invalid interface");
|
||||
|
||||
ret = close(sock_c);
|
||||
ret = zsock_close(sock_c);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(sock_s);
|
||||
ret = zsock_close(sock_s);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
k_sleep(K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY));
|
||||
|
@ -305,15 +305,15 @@ void test_ipv4_so_bindtodevice(void)
|
|||
.sin_addr = INADDR_ANY_INIT,
|
||||
};
|
||||
|
||||
sock_c = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_c = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_c >= 0, "socket open failed");
|
||||
sock_s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_s = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_s >= 0, "socket open failed");
|
||||
|
||||
peer_addr.sin_family = AF_INET;
|
||||
peer_addr.sin_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET, TEST_PEER_IPV4_ADDR,
|
||||
&peer_addr.sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, TEST_PEER_IPV4_ADDR,
|
||||
&peer_addr.sin_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
test_so_bindtodevice(sock_c, sock_s, (struct sockaddr *)&peer_addr,
|
||||
|
@ -333,15 +333,15 @@ void test_ipv6_so_bindtodevice(void)
|
|||
.sin6_addr = IN6ADDR_ANY_INIT,
|
||||
};
|
||||
|
||||
sock_c = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_c = zsock_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_c >= 0, "socket open failed");
|
||||
sock_s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_s = zsock_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_s >= 0, "socket open failed");
|
||||
|
||||
peer_addr.sin6_family = AF_INET6;
|
||||
peer_addr.sin6_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET6, TEST_PEER_IPV6_ADDR,
|
||||
&peer_addr.sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, TEST_PEER_IPV6_ADDR,
|
||||
&peer_addr.sin6_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
test_so_bindtodevice(sock_c, sock_s, (struct sockaddr *)&peer_addr,
|
||||
|
@ -365,67 +365,67 @@ void test_getpeername(int family)
|
|||
srv_addr.sa_family = family;
|
||||
if (family == AF_INET) {
|
||||
net_sin(&srv_addr)->sin_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
} else {
|
||||
net_sin6(&srv_addr)->sin6_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr)->sin6_addr);
|
||||
}
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
/* UDP socket */
|
||||
sock_c = socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_c = zsock_socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_c >= 0, "socket open failed");
|
||||
|
||||
peer_addr_len = ADDR_SIZE(family);
|
||||
ret = getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
ret = zsock_getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
zassert_equal(ret, -1, "getpeername shouldn've failed");
|
||||
zassert_equal(errno, ENOTCONN, "getpeername returned invalid error");
|
||||
|
||||
ret = connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "connect failed");
|
||||
|
||||
memset(&peer_addr, 0, sizeof(peer_addr));
|
||||
peer_addr_len = ADDR_SIZE(family);
|
||||
ret = getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
ret = zsock_getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
zassert_equal(ret, 0, "getpeername failed");
|
||||
zassert_mem_equal(&peer_addr, &srv_addr, ADDR_SIZE(family),
|
||||
"obtained wrong address");
|
||||
|
||||
ret = close(sock_c);
|
||||
ret = zsock_close(sock_c);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
/* TCP socket */
|
||||
sock_c = socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_c = zsock_socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_c >= 0, "socket open failed");
|
||||
sock_s = socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s = zsock_socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s >= 0, "socket open failed");
|
||||
|
||||
ret = bind(sock_s, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_bind(sock_s, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
ret = listen(sock_s, 1);
|
||||
ret = zsock_listen(sock_s, 1);
|
||||
zassert_equal(ret, 0, "listen failed, %d", errno);
|
||||
|
||||
peer_addr_len = ADDR_SIZE(family);
|
||||
ret = getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
ret = zsock_getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
zassert_equal(ret, -1, "getpeername shouldn've failed");
|
||||
zassert_equal(errno, ENOTCONN, "getpeername returned invalid error");
|
||||
|
||||
ret = connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "connect failed");
|
||||
|
||||
memset(&peer_addr, 0, sizeof(peer_addr));
|
||||
peer_addr_len = ADDR_SIZE(family);
|
||||
ret = getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
ret = zsock_getpeername(sock_c, &peer_addr, &peer_addr_len);
|
||||
zassert_equal(ret, 0, "getpeername failed");
|
||||
zassert_mem_equal(&peer_addr, &srv_addr, ADDR_SIZE(family),
|
||||
"obtained wrong address");
|
||||
|
||||
ret = close(sock_c);
|
||||
ret = zsock_close(sock_c);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(sock_s);
|
||||
ret = zsock_close(sock_s);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
k_sleep(K_MSEC(2 * CONFIG_NET_TCP_TIME_WAIT_DELAY));
|
||||
|
@ -454,58 +454,58 @@ void test_getsockname_tcp(int family)
|
|||
srv_addr.sa_family = family;
|
||||
if (family == AF_INET) {
|
||||
net_sin(&srv_addr)->sin_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
} else {
|
||||
net_sin6(&srv_addr)->sin6_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr)->sin6_addr);
|
||||
}
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
sock_c = socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_c = zsock_socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_c >= 0, "socket open failed");
|
||||
sock_s = socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s = zsock_socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s >= 0, "socket open failed");
|
||||
|
||||
/* Verify that unbound/unconnected socket has no local address set */
|
||||
ret = getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, -1, "getsockname shouldn've failed");
|
||||
zassert_equal(errno, EINVAL, "getsockname returned invalid error");
|
||||
ret = getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, -1, "getsockname shouldn've failed");
|
||||
zassert_equal(errno, EINVAL, "getsockname returned invalid error");
|
||||
|
||||
/* Verify that getsockname() can read local address of a bound socket */
|
||||
ret = bind(sock_s, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_bind(sock_s, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
memset(&local_addr, 0, sizeof(local_addr));
|
||||
local_addr_len = ADDR_SIZE(family);
|
||||
ret = getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, 0, "getsockname failed");
|
||||
zassert_mem_equal(&local_addr, &srv_addr, ADDR_SIZE(family),
|
||||
"obtained wrong address");
|
||||
|
||||
ret = listen(sock_s, 1);
|
||||
ret = zsock_listen(sock_s, 1);
|
||||
zassert_equal(ret, 0, "listen failed, %d", errno);
|
||||
|
||||
/* Verify that getsockname() can read local address of a connected socket */
|
||||
ret = connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "connect failed");
|
||||
|
||||
memset(&local_addr, 0, sizeof(local_addr));
|
||||
local_addr_len = ADDR_SIZE(family);
|
||||
ret = getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, 0, "getsockname failed");
|
||||
zassert_equal(local_addr.sa_family, family, "wrong family");
|
||||
/* Can't verify address/port of client socket here reliably as they're
|
||||
* chosen by net stack
|
||||
*/
|
||||
|
||||
ret = close(sock_c);
|
||||
ret = zsock_close(sock_c);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(sock_s);
|
||||
ret = zsock_close(sock_s);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
k_sleep(K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY));
|
||||
|
@ -523,55 +523,55 @@ void test_getsockname_udp(int family)
|
|||
srv_addr.sa_family = family;
|
||||
if (family == AF_INET) {
|
||||
net_sin(&srv_addr)->sin_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
} else {
|
||||
net_sin6(&srv_addr)->sin6_port = htons(DST_PORT);
|
||||
ret = inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr)->sin6_addr);
|
||||
}
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
sock_c = socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_c = zsock_socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_c >= 0, "socket open failed");
|
||||
sock_s = socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_s = zsock_socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_s >= 0, "socket open failed");
|
||||
|
||||
/* Verify that unbound/unconnected socket has no local address set */
|
||||
ret = getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, -1, "getsockname shouldn've failed");
|
||||
zassert_equal(errno, EINVAL, "getsockname returned invalid error");
|
||||
ret = getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, -1, "getsockname shouldn've failed");
|
||||
zassert_equal(errno, EINVAL, "getsockname returned invalid error");
|
||||
|
||||
/* Verify that getsockname() can read local address of a bound socket */
|
||||
ret = bind(sock_s, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_bind(sock_s, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
memset(&local_addr, 0, sizeof(local_addr));
|
||||
local_addr_len = ADDR_SIZE(family);
|
||||
ret = getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_s, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, 0, "getsockname failed");
|
||||
zassert_mem_equal(&local_addr, &srv_addr, ADDR_SIZE(family),
|
||||
"obtained wrong address");
|
||||
|
||||
/* Verify that getsockname() can read local address of a connected socket */
|
||||
ret = connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
ret = zsock_connect(sock_c, &srv_addr, ADDR_SIZE(family));
|
||||
zassert_equal(ret, 0, "connect failed");
|
||||
|
||||
memset(&local_addr, 0, sizeof(local_addr));
|
||||
local_addr_len = ADDR_SIZE(family);
|
||||
ret = getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
ret = zsock_getsockname(sock_c, &local_addr, &local_addr_len);
|
||||
zassert_equal(ret, 0, "getsockname failed");
|
||||
zassert_equal(local_addr.sa_family, family, "wrong family");
|
||||
/* Can't verify address/port of client socket here reliably as they're
|
||||
* chosen by net stack
|
||||
*/
|
||||
|
||||
ret = close(sock_c);
|
||||
ret = zsock_close(sock_c);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(sock_s);
|
||||
ret = zsock_close(sock_s);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
}
|
||||
|
||||
|
@ -590,34 +590,34 @@ void test_ipv4_mapped_to_ipv6_disabled(void)
|
|||
|
||||
srv_addr4.sa_family = AF_INET;
|
||||
net_sin(&srv_addr4)->sin_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr4)->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, TEST_MY_IPV4_ADDR,
|
||||
&net_sin(&srv_addr4)->sin_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
srv_addr6.sa_family = AF_INET6;
|
||||
net_sin6(&srv_addr6)->sin6_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr6)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, TEST_MY_IPV6_ADDR,
|
||||
&net_sin6(&srv_addr6)->sin6_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
sock_s4 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s4 = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s4 >= 0, "socket open failed");
|
||||
|
||||
ret = bind(sock_s4, &srv_addr4, ADDR_SIZE(AF_INET));
|
||||
ret = zsock_bind(sock_s4, &srv_addr4, ADDR_SIZE(AF_INET));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
ret = listen(sock_s4, 1);
|
||||
ret = zsock_listen(sock_s4, 1);
|
||||
zassert_equal(ret, 0, "listen failed, %d", errno);
|
||||
|
||||
sock_s6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s6 = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s6 >= 0, "socket open failed");
|
||||
|
||||
ret = bind(sock_s6, &srv_addr6, ADDR_SIZE(AF_INET6));
|
||||
ret = zsock_bind(sock_s6, &srv_addr6, ADDR_SIZE(AF_INET6));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
ret = close(sock_s4);
|
||||
ret = zsock_close(sock_s4);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(sock_s6);
|
||||
ret = zsock_close(sock_s6);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
}
|
||||
|
||||
|
@ -639,58 +639,58 @@ void test_ipv4_mapped_to_ipv6_enabled(void)
|
|||
*/
|
||||
srv_addr4.sa_family = AF_INET;
|
||||
net_sin(&srv_addr4)->sin_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET, "0.0.0.0",
|
||||
&net_sin(&srv_addr4)->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, "0.0.0.0",
|
||||
&net_sin(&srv_addr4)->sin_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
srv_addr6.sa_family = AF_INET6;
|
||||
net_sin6(&srv_addr6)->sin6_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET6, "::",
|
||||
&net_sin6(&srv_addr6)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, "::",
|
||||
&net_sin6(&srv_addr6)->sin6_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
/* First create IPv6 socket */
|
||||
sock_s6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s6 = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s6 >= 0, "socket open failed");
|
||||
|
||||
ret = bind(sock_s6, &srv_addr6, ADDR_SIZE(AF_INET6));
|
||||
ret = zsock_bind(sock_s6, &srv_addr6, ADDR_SIZE(AF_INET6));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
ret = listen(sock_s6, 1);
|
||||
ret = zsock_listen(sock_s6, 1);
|
||||
zassert_equal(ret, 0, "listen failed, %d", errno);
|
||||
|
||||
/* Then try to create IPv4 socket to the same port */
|
||||
sock_s4 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s4 = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s4 >= 0, "socket open failed");
|
||||
|
||||
/* Initially the IPV6_V6ONLY is set so the next bind is ok */
|
||||
ret = bind(sock_s4, &srv_addr4, ADDR_SIZE(AF_INET));
|
||||
ret = zsock_bind(sock_s4, &srv_addr4, ADDR_SIZE(AF_INET));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
ret = close(sock_s4);
|
||||
ret = zsock_close(sock_s4);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
/* Then we turn off IPV6_V6ONLY which means that IPv4 and IPv6
|
||||
* will have same port space and the next bind should fail.
|
||||
*/
|
||||
ret = setsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off));
|
||||
ret = zsock_setsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off));
|
||||
zassert_equal(ret, 0, "setsockopt failed, %d", errno);
|
||||
|
||||
ret = getsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, &optlen);
|
||||
ret = zsock_getsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", errno);
|
||||
zassert_equal(off, 0, "IPV6_V6ONLY option setting failed");
|
||||
|
||||
sock_s4 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s4 = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s4 >= 0, "socket open failed");
|
||||
|
||||
/* Now v4 bind should fail */
|
||||
ret = bind(sock_s4, &srv_addr4, ADDR_SIZE(AF_INET));
|
||||
ret = zsock_bind(sock_s4, &srv_addr4, ADDR_SIZE(AF_INET));
|
||||
zassert_equal(ret, -1, "bind failed, %d", errno);
|
||||
zassert_equal(errno, EADDRINUSE, "bind failed");
|
||||
|
||||
ret = close(sock_s4);
|
||||
ret = zsock_close(sock_s4);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(sock_s6);
|
||||
ret = zsock_close(sock_s6);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
}
|
||||
|
||||
|
@ -723,14 +723,14 @@ void test_ipv4_mapped_to_ipv6_server(void)
|
|||
*/
|
||||
srv_addr.sa_family = AF_INET;
|
||||
net_sin(&srv_addr)->sin_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET, "192.0.2.1",
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
ret = zsock_inet_pton(AF_INET, "192.0.2.1",
|
||||
&net_sin(&srv_addr)->sin_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
connect_addr6.sa_family = AF_INET6;
|
||||
net_sin6(&connect_addr6)->sin6_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET6, TEST_PEER_IPV6_ADDR,
|
||||
&net_sin6(&connect_addr6)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, TEST_PEER_IPV6_ADDR,
|
||||
&net_sin6(&connect_addr6)->sin6_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
net_ipv6_addr_create_v4_mapped(&net_sin(&srv_addr)->sin_addr,
|
||||
|
@ -741,16 +741,16 @@ void test_ipv4_mapped_to_ipv6_server(void)
|
|||
*/
|
||||
srv_addr6.sa_family = AF_INET6;
|
||||
net_sin6(&srv_addr6)->sin6_port = htons(MAPPING_PORT);
|
||||
ret = inet_pton(AF_INET6, "::",
|
||||
&net_sin6(&srv_addr6)->sin6_addr);
|
||||
ret = zsock_inet_pton(AF_INET6, "::",
|
||||
&net_sin6(&srv_addr6)->sin6_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
/* First create IPv6 socket */
|
||||
sock_s6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_s6 = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_s6 >= 0, "socket open failed");
|
||||
|
||||
/* Verify that by default the IPV6_V6ONLY option is set */
|
||||
ret = getsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, &optlen);
|
||||
ret = zsock_getsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", errno);
|
||||
zassert_not_equal(off, 0, "IPV6_V6ONLY option setting failed");
|
||||
|
||||
|
@ -758,27 +758,27 @@ void test_ipv4_mapped_to_ipv6_server(void)
|
|||
* will have same port space.
|
||||
*/
|
||||
off = 0;
|
||||
ret = setsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off));
|
||||
ret = zsock_setsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off));
|
||||
zassert_equal(ret, 0, "setsockopt failed, %d", errno);
|
||||
|
||||
ret = getsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, &optlen);
|
||||
ret = zsock_getsockopt(sock_s6, IPPROTO_IPV6, IPV6_V6ONLY, &off, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", errno);
|
||||
zassert_equal(off, 0, "IPV6_V6ONLY option setting failed, %d", off);
|
||||
|
||||
ret = bind(sock_s6, &srv_addr6, ADDR_SIZE(AF_INET6));
|
||||
ret = zsock_bind(sock_s6, &srv_addr6, ADDR_SIZE(AF_INET6));
|
||||
zassert_equal(ret, 0, "bind failed, %d", errno);
|
||||
|
||||
ret = listen(sock_s6, 1);
|
||||
ret = zsock_listen(sock_s6, 1);
|
||||
zassert_equal(ret, 0, "listen failed, %d", errno);
|
||||
|
||||
/* Then create IPv4 socket and connect to the IPv6 port */
|
||||
sock_c4 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_c4 = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_c4 >= 0, "socket open failed");
|
||||
|
||||
ret = connect(sock_c4, &srv_addr, ADDR_SIZE(AF_INET));
|
||||
ret = zsock_connect(sock_c4, &srv_addr, ADDR_SIZE(AF_INET));
|
||||
zassert_equal(ret, 0, "connect failed");
|
||||
|
||||
new_sock = accept(sock_s6, &addr, &addrlen);
|
||||
new_sock = zsock_accept(sock_s6, &addr, &addrlen);
|
||||
zassert_true(new_sock >= 0, "accept failed, %d", errno);
|
||||
|
||||
/* Note that we should get IPv6 address here (mapped from IPv4) */
|
||||
|
@ -793,44 +793,44 @@ void test_ipv4_mapped_to_ipv6_server(void)
|
|||
net_sprint_ipv6_addr(&net_sin6(&addr)->sin6_addr));
|
||||
|
||||
/* Send data back to IPv4 client from IPv6 socket */
|
||||
ret = send(new_sock, "foobar", len, 0);
|
||||
ret = zsock_send(new_sock, "foobar", len, 0);
|
||||
zassert_equal(ret, len, "cannot send (%d vs %d), errno %d", ret, len, errno);
|
||||
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
ret = recv(sock_c4, buf, sizeof(buf), 0);
|
||||
ret = zsock_recv(sock_c4, buf, sizeof(buf), 0);
|
||||
zassert_equal(ret, strlen("foobar"), "cannot recv");
|
||||
|
||||
ret = close(sock_c4);
|
||||
ret = zsock_close(sock_c4);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
(void)close(new_sock);
|
||||
(void)zsock_close(new_sock);
|
||||
|
||||
/* Let the system stabilize and cleanup itself */
|
||||
k_sleep(K_MSEC(200));
|
||||
|
||||
/* Then create IPv6 socket and make sure it works ok too */
|
||||
sock_c6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_c6 = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_c6 >= 0, "socket open failed");
|
||||
|
||||
ret = connect(sock_c6, &connect_addr6, ADDR_SIZE(AF_INET6));
|
||||
ret = zsock_connect(sock_c6, &connect_addr6, ADDR_SIZE(AF_INET6));
|
||||
zassert_equal(ret, 0, "connect failed, %d", errno);
|
||||
|
||||
new_sock = accept(sock_s6, &addr, &addrlen);
|
||||
new_sock = zsock_accept(sock_s6, &addr, &addrlen);
|
||||
zassert_true(new_sock >= 0, "accept failed, %d", errno);
|
||||
|
||||
ret = send(new_sock, "foobar", len, 0);
|
||||
ret = zsock_send(new_sock, "foobar", len, 0);
|
||||
zassert_equal(ret, len, "cannot send (%d vs %d), errno %d", ret, len, errno);
|
||||
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
ret = recv(sock_c6, buf, sizeof(buf), 0);
|
||||
ret = zsock_recv(sock_c6, buf, sizeof(buf), 0);
|
||||
zassert_equal(ret, strlen("foobar"), "cannot recv");
|
||||
|
||||
ret = close(sock_c6);
|
||||
ret = zsock_close(sock_c6);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
|
||||
ret = close(sock_s6);
|
||||
ret = zsock_close(sock_s6);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
ret = close(new_sock);
|
||||
ret = zsock_close(new_sock);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
}
|
||||
|
||||
|
@ -895,30 +895,30 @@ ZTEST(socket_misc_test_suite, test_so_domain_socket_option)
|
|||
socklen_t optlen = sizeof(int);
|
||||
int domain;
|
||||
|
||||
sock_t = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
sock_t = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
zassert_true(sock_t >= 0, "TCP socket open failed");
|
||||
sock_u = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
sock_u = zsock_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(sock_u >= 0, "UDP socket open failed");
|
||||
|
||||
ret = getsockopt(sock_t, SOL_SOCKET, SO_DOMAIN, &domain, &optlen);
|
||||
ret = zsock_getsockopt(sock_t, SOL_SOCKET, SO_DOMAIN, &domain, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", -errno);
|
||||
zassert_equal(domain, AF_INET, "Mismatch domain value %d vs %d",
|
||||
AF_INET, domain);
|
||||
|
||||
ret = getsockopt(sock_u, SOL_SOCKET, SO_DOMAIN, &domain, &optlen);
|
||||
ret = zsock_getsockopt(sock_u, SOL_SOCKET, SO_DOMAIN, &domain, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", -errno);
|
||||
zassert_equal(domain, AF_INET6, "Mismatch domain value %d vs %d",
|
||||
AF_INET6, domain);
|
||||
|
||||
/* setsockopt() is not supported for this option */
|
||||
domain = AF_INET;
|
||||
ret = setsockopt(sock_u, SOL_SOCKET, SO_DOMAIN, &domain, optlen);
|
||||
ret = zsock_setsockopt(sock_u, SOL_SOCKET, SO_DOMAIN, &domain, optlen);
|
||||
zassert_equal(ret, -1, "setsockopt succeed");
|
||||
zassert_equal(errno, ENOPROTOOPT, "Invalid errno %d", errno);
|
||||
|
||||
ret = close(sock_t);
|
||||
ret = zsock_close(sock_t);
|
||||
zassert_equal(ret, 0, "close failed, %d", -errno);
|
||||
ret = close(sock_u);
|
||||
ret = zsock_close(sock_u);
|
||||
zassert_equal(ret, 0, "close failed, %d", -errno);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ CONFIG_NET_TEST=y
|
|||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS_NET_MGMT=y
|
||||
CONFIG_NET_MGMT=y
|
||||
CONFIG_NET_MGMT_EVENT=y
|
||||
|
|
|
@ -363,7 +363,7 @@ static void test_net_mgmt_setup(void)
|
|||
net_if_foreach(iface_cb, &default_iface);
|
||||
zassert_not_null(default_iface, "Cannot find test interface");
|
||||
|
||||
fd = socket(AF_NET_MGMT, SOCK_DGRAM, NET_MGMT_EVENT_PROTO);
|
||||
fd = zsock_socket(AF_NET_MGMT, SOCK_DGRAM, NET_MGMT_EVENT_PROTO);
|
||||
zassert_false(fd < 0, "Cannot create net_mgmt socket (%d)", errno);
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
|
@ -385,7 +385,7 @@ static void test_net_mgmt_setup(void)
|
|||
NET_EVENT_IPV6_ADDR_ADD |
|
||||
NET_EVENT_IPV6_ADDR_DEL;
|
||||
|
||||
ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
||||
ret = zsock_bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
||||
zassert_false(ret < 0, "Cannot bind net_mgmt socket (%d)", errno);
|
||||
|
||||
k_thread_start(trigger_events_thread_id);
|
||||
|
@ -406,9 +406,9 @@ static void test_net_mgmt_catch_events(void)
|
|||
memset(buf, 0, sizeof(buf));
|
||||
event_addr_len = sizeof(event_addr);
|
||||
|
||||
ret = recvfrom(fd, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&event_addr,
|
||||
&event_addr_len);
|
||||
ret = zsock_recvfrom(fd, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&event_addr,
|
||||
&event_addr_len);
|
||||
if (ret < 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -468,9 +468,9 @@ static void test_net_mgmt_catch_events_failure(void)
|
|||
memset(buf, 0, sizeof(buf));
|
||||
event_addr_len = sizeof(event_addr);
|
||||
|
||||
ret = recvfrom(fd, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&event_addr,
|
||||
&event_addr_len);
|
||||
ret = zsock_recvfrom(fd, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&event_addr,
|
||||
&event_addr_len);
|
||||
zassert_equal(ret, -1, "Msg check failed, %d", errno);
|
||||
zassert_equal(errno, EMSGSIZE, "Msg check failed, errno %d", errno);
|
||||
}
|
||||
|
@ -501,9 +501,9 @@ static void test_ethernet_set_qav(void)
|
|||
params.qav_param.type = ETHERNET_QAV_PARAM_TYPE_STATUS;
|
||||
params.qav_param.enabled = true;
|
||||
|
||||
ret = setsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_SET_QAV_PARAM,
|
||||
¶ms, sizeof(params));
|
||||
ret = zsock_setsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_SET_QAV_PARAM,
|
||||
¶ms, sizeof(params));
|
||||
zassert_equal(ret, 0, "Cannot set Qav parameters");
|
||||
}
|
||||
|
||||
|
@ -528,9 +528,9 @@ static void test_ethernet_get_qav(void)
|
|||
params.qav_param.queue_id = 1;
|
||||
params.qav_param.type = ETHERNET_QAV_PARAM_TYPE_STATUS;
|
||||
|
||||
ret = getsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_GET_QAV_PARAM,
|
||||
¶ms, &optlen);
|
||||
ret = zsock_getsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_GET_QAV_PARAM,
|
||||
¶ms, &optlen);
|
||||
zassert_equal(ret, 0, "Cannot get Qav parameters (%d)", ret);
|
||||
zassert_equal(optlen, sizeof(params), "Invalid optlen (%d)", optlen);
|
||||
|
||||
|
@ -555,9 +555,9 @@ static void test_ethernet_get_unknown_option(void)
|
|||
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
|
||||
ret = getsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM,
|
||||
¶ms, &optlen);
|
||||
ret = zsock_getsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM,
|
||||
¶ms, &optlen);
|
||||
zassert_equal(ret, -1, "Could get prio queue parameters (%d)", errno);
|
||||
zassert_equal(errno, EINVAL, "prio queue get parameters");
|
||||
}
|
||||
|
@ -580,9 +580,9 @@ static void test_ethernet_set_unknown_option(void)
|
|||
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
|
||||
ret = setsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_SET_MAC_ADDRESS,
|
||||
¶ms, optlen);
|
||||
ret = zsock_setsockopt(fd, SOL_NET_MGMT_RAW,
|
||||
NET_REQUEST_ETHERNET_SET_MAC_ADDRESS,
|
||||
¶ms, optlen);
|
||||
zassert_equal(ret, -1, "Could set promisc_mode parameters (%d)", errno);
|
||||
zassert_equal(errno, EINVAL, "promisc_mode set parameters");
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ CONFIG_NET_IPV6=y
|
|||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_POSIX_MAX_FDS=10
|
||||
CONFIG_NET_PKT_TX_COUNT=8
|
||||
CONFIG_NET_PKT_RX_COUNT=8
|
||||
|
|
|
@ -40,8 +40,8 @@ ZTEST(net_socket_poll, test_poll)
|
|||
int s_sock_tcp;
|
||||
struct sockaddr_in6 c_addr;
|
||||
struct sockaddr_in6 s_addr;
|
||||
struct pollfd pollfds[2];
|
||||
struct pollfd pollout[1];
|
||||
struct zsock_pollfd pollfds[2];
|
||||
struct zsock_pollfd pollout[1];
|
||||
uint32_t tstamp;
|
||||
ssize_t len;
|
||||
char buf[10];
|
||||
|
@ -51,35 +51,35 @@ ZTEST(net_socket_poll, test_poll)
|
|||
prepare_sock_tcp_v6(MY_IPV6_ADDR, CLIENT_PORT, &c_sock_tcp, &c_addr);
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, SERVER_PORT, &s_sock_tcp, &s_addr);
|
||||
|
||||
res = bind(s_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
res = zsock_bind(s_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
zassert_equal(res, 0, "bind failed");
|
||||
|
||||
res = connect(c_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
res = zsock_connect(c_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
zassert_equal(res, 0, "connect failed");
|
||||
|
||||
memset(pollfds, 0, sizeof(pollfds));
|
||||
pollfds[0].fd = c_sock;
|
||||
pollfds[0].events = POLLIN;
|
||||
pollfds[0].events = ZSOCK_POLLIN;
|
||||
pollfds[1].fd = s_sock;
|
||||
pollfds[1].events = POLLIN;
|
||||
pollfds[1].events = ZSOCK_POLLIN;
|
||||
|
||||
/* Poll non-ready fd's with timeout of 0 */
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollfds, ARRAY_SIZE(pollfds), 0);
|
||||
res = zsock_poll(pollfds, ARRAY_SIZE(pollfds), 0);
|
||||
zassert_true(k_uptime_get_32() - tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
zassert_equal(pollfds[0].fd, c_sock, "");
|
||||
zassert_equal(pollfds[0].events, POLLIN, "");
|
||||
zassert_equal(pollfds[0].events, ZSOCK_POLLIN, "");
|
||||
zassert_equal(pollfds[0].revents, 0, "");
|
||||
zassert_equal(pollfds[1].fd, s_sock, "");
|
||||
zassert_equal(pollfds[1].events, POLLIN, "");
|
||||
zassert_equal(pollfds[1].events, ZSOCK_POLLIN, "");
|
||||
zassert_equal(pollfds[1].revents, 0, "");
|
||||
|
||||
|
||||
/* Poll non-ready fd's with timeout of 30 */
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollfds, ARRAY_SIZE(pollfds), 30);
|
||||
res = zsock_poll(pollfds, ARRAY_SIZE(pollfds), 30);
|
||||
tstamp = k_uptime_get_32() - tstamp;
|
||||
zassert_true(tstamp >= 30U && tstamp <= 30 + FUZZ * 2, "tstamp %d",
|
||||
tstamp);
|
||||
|
@ -87,29 +87,29 @@ ZTEST(net_socket_poll, test_poll)
|
|||
|
||||
|
||||
/* Send pkt for s_sock and poll with timeout of 10 */
|
||||
len = send(c_sock, BUF_AND_SIZE(TEST_STR_SMALL), 0);
|
||||
len = zsock_send(c_sock, BUF_AND_SIZE(TEST_STR_SMALL), 0);
|
||||
zassert_equal(len, STRLEN(TEST_STR_SMALL), "invalid send len");
|
||||
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollfds, ARRAY_SIZE(pollfds), 30);
|
||||
res = zsock_poll(pollfds, ARRAY_SIZE(pollfds), 30);
|
||||
tstamp = k_uptime_get_32() - tstamp;
|
||||
zassert_true(tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 1, "");
|
||||
|
||||
zassert_equal(pollfds[0].fd, c_sock, "");
|
||||
zassert_equal(pollfds[0].events, POLLIN, "");
|
||||
zassert_equal(pollfds[0].events, ZSOCK_POLLIN, "");
|
||||
zassert_equal(pollfds[0].revents, 0, "");
|
||||
zassert_equal(pollfds[1].fd, s_sock, "");
|
||||
zassert_equal(pollfds[1].events, POLLIN, "");
|
||||
zassert_equal(pollfds[1].revents, POLLIN, "");
|
||||
zassert_equal(pollfds[1].events, ZSOCK_POLLIN, "");
|
||||
zassert_equal(pollfds[1].revents, ZSOCK_POLLIN, "");
|
||||
|
||||
|
||||
/* Recv pkt from s_sock and ensure no poll events happen */
|
||||
len = recv(s_sock, BUF_AND_SIZE(buf), 0);
|
||||
len = zsock_recv(s_sock, BUF_AND_SIZE(buf), 0);
|
||||
zassert_equal(len, STRLEN(TEST_STR_SMALL), "invalid recv len");
|
||||
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollfds, ARRAY_SIZE(pollfds), 0);
|
||||
res = zsock_poll(pollfds, ARRAY_SIZE(pollfds), 0);
|
||||
zassert_true(k_uptime_get_32() - tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 0, "");
|
||||
zassert_equal(pollfds[1].revents, 0, "");
|
||||
|
@ -117,61 +117,61 @@ ZTEST(net_socket_poll, test_poll)
|
|||
/* Make sure that POLLOUT does not wait if not really needed */
|
||||
memset(pollout, 0, sizeof(pollout));
|
||||
pollout[0].fd = c_sock;
|
||||
pollout[0].events = POLLOUT;
|
||||
pollout[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
res = connect(c_sock, (const struct sockaddr *)&s_addr,
|
||||
sizeof(s_addr));
|
||||
res = zsock_connect(c_sock, (const struct sockaddr *)&s_addr,
|
||||
sizeof(s_addr));
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollout, ARRAY_SIZE(pollout), 200);
|
||||
res = zsock_poll(pollout, ARRAY_SIZE(pollout), 200);
|
||||
zassert_true(k_uptime_get_32() - tstamp < 100, "");
|
||||
zassert_equal(res, 1, "");
|
||||
zassert_equal(pollout[0].revents, POLLOUT, "");
|
||||
zassert_equal(pollout[0].revents, ZSOCK_POLLOUT, "");
|
||||
|
||||
/* First test that TCP POLLOUT will not wait if there is enough
|
||||
* room in TCP window
|
||||
*/
|
||||
memset(pollout, 0, sizeof(pollout));
|
||||
pollout[0].fd = c_sock_tcp;
|
||||
pollout[0].events = POLLOUT;
|
||||
pollout[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
res = bind(s_sock_tcp, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
res = zsock_bind(s_sock_tcp, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
zassert_equal(res, 0, "");
|
||||
res = listen(s_sock_tcp, 0);
|
||||
res = zsock_listen(s_sock_tcp, 0);
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
res = connect(c_sock_tcp, (const struct sockaddr *)&s_addr,
|
||||
sizeof(s_addr));
|
||||
res = zsock_connect(c_sock_tcp, (const struct sockaddr *)&s_addr,
|
||||
sizeof(s_addr));
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollout, ARRAY_SIZE(pollout), 200);
|
||||
res = zsock_poll(pollout, ARRAY_SIZE(pollout), 200);
|
||||
zassert_true(k_uptime_get_32() - tstamp < 100, "");
|
||||
zassert_equal(res, 1, "");
|
||||
zassert_equal(pollout[0].revents, POLLOUT, "");
|
||||
zassert_equal(pollout[0].revents, ZSOCK_POLLOUT, "");
|
||||
|
||||
/* Let the network stack run */
|
||||
k_msleep(10);
|
||||
|
||||
res = close(c_sock_tcp);
|
||||
res = zsock_close(c_sock_tcp);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
|
||||
res = close(s_sock_tcp);
|
||||
res = zsock_close(s_sock_tcp);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
|
||||
/* Close one socket and ensure POLLNVAL happens */
|
||||
res = close(c_sock);
|
||||
res = zsock_close(c_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
|
||||
tstamp = k_uptime_get_32();
|
||||
res = poll(pollfds, ARRAY_SIZE(pollfds), 0);
|
||||
res = zsock_poll(pollfds, ARRAY_SIZE(pollfds), 0);
|
||||
zassert_true(k_uptime_get_32() - tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 1, "");
|
||||
zassert_equal(pollfds[0].revents, POLLNVAL, "");
|
||||
zassert_equal(pollfds[0].revents, ZSOCK_POLLNVAL, "");
|
||||
zassert_equal(pollfds[1].revents, 0, "");
|
||||
|
||||
res = close(s_sock);
|
||||
res = zsock_close(s_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
|
||||
k_sleep(TCP_TEARDOWN_TIMEOUT);
|
||||
|
@ -187,20 +187,20 @@ ZTEST(net_socket_poll, test_pollout_tcp)
|
|||
int new_sock;
|
||||
struct sockaddr_in6 c_addr;
|
||||
struct sockaddr_in6 s_addr;
|
||||
struct pollfd pollout[1];
|
||||
struct zsock_pollfd pollout[1];
|
||||
char buf[TEST_SNDBUF_SIZE] = { };
|
||||
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, CLIENT_PORT, &c_sock, &c_addr);
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, SERVER_PORT, &s_sock, &s_addr);
|
||||
|
||||
res = bind(s_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
res = zsock_bind(s_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
zassert_equal(res, 0, "");
|
||||
res = listen(s_sock, 0);
|
||||
res = zsock_listen(s_sock, 0);
|
||||
zassert_equal(res, 0, "");
|
||||
res = connect(c_sock, (const struct sockaddr *)&s_addr,
|
||||
sizeof(s_addr));
|
||||
res = zsock_connect(c_sock, (const struct sockaddr *)&s_addr,
|
||||
sizeof(s_addr));
|
||||
zassert_equal(res, 0, "");
|
||||
new_sock = accept(s_sock, NULL, NULL);
|
||||
new_sock = zsock_accept(s_sock, NULL, NULL);
|
||||
zassert_true(new_sock >= 0, "");
|
||||
|
||||
k_msleep(10);
|
||||
|
@ -208,47 +208,47 @@ ZTEST(net_socket_poll, test_pollout_tcp)
|
|||
/* POLLOUT should be reported after connecting */
|
||||
memset(pollout, 0, sizeof(pollout));
|
||||
pollout[0].fd = c_sock;
|
||||
pollout[0].events = POLLOUT;
|
||||
pollout[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
res = poll(pollout, ARRAY_SIZE(pollout), 10);
|
||||
res = zsock_poll(pollout, ARRAY_SIZE(pollout), 10);
|
||||
zassert_equal(res, 1, "");
|
||||
zassert_equal(pollout[0].revents, POLLOUT, "");
|
||||
zassert_equal(pollout[0].revents, ZSOCK_POLLOUT, "");
|
||||
|
||||
/* POLLOUT should not be reported after filling the window */
|
||||
res = send(c_sock, buf, sizeof(buf), 0);
|
||||
res = zsock_send(c_sock, buf, sizeof(buf), 0);
|
||||
zassert_equal(res, sizeof(buf), "");
|
||||
|
||||
memset(pollout, 0, sizeof(pollout));
|
||||
pollout[0].fd = c_sock;
|
||||
pollout[0].events = POLLOUT;
|
||||
pollout[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
res = poll(pollout, ARRAY_SIZE(pollout), 10);
|
||||
res = zsock_poll(pollout, ARRAY_SIZE(pollout), 10);
|
||||
zassert_equal(res, 0, "%d", pollout[0].revents);
|
||||
zassert_equal(pollout[0].revents, 0, "");
|
||||
|
||||
/* POLLOUT should be reported again after consuming the data server
|
||||
* side.
|
||||
*/
|
||||
res = recv(new_sock, buf, sizeof(buf), 0);
|
||||
res = zsock_recv(new_sock, buf, sizeof(buf), 0);
|
||||
zassert_equal(res, sizeof(buf), "");
|
||||
|
||||
memset(pollout, 0, sizeof(pollout));
|
||||
pollout[0].fd = c_sock;
|
||||
pollout[0].events = POLLOUT;
|
||||
pollout[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
/* Wait longer this time to give TCP stack a chance to send ZWP. */
|
||||
res = poll(pollout, ARRAY_SIZE(pollout), 500);
|
||||
res = zsock_poll(pollout, ARRAY_SIZE(pollout), 500);
|
||||
zassert_equal(res, 1, "");
|
||||
zassert_equal(pollout[0].revents, POLLOUT, "");
|
||||
zassert_equal(pollout[0].revents, ZSOCK_POLLOUT, "");
|
||||
|
||||
k_msleep(10);
|
||||
|
||||
/* Finalize the test */
|
||||
res = close(c_sock);
|
||||
res = zsock_close(c_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
res = close(s_sock);
|
||||
res = zsock_close(s_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
res = close(new_sock);
|
||||
res = zsock_close(new_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,5 @@ CONFIG_NET_IPV6_NBR_CACHE=n
|
|||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_NET_MAX_CONTEXTS=10
|
||||
|
|
|
@ -245,9 +245,9 @@ ZTEST(net_socket_register, test_create_sockets)
|
|||
for (i = 0; i < ARRAY_SIZE(expected_result); i++, current_test++) {
|
||||
errno = 0;
|
||||
|
||||
fd = socket(expected_result[i].test_case.family,
|
||||
expected_result[i].test_case.type,
|
||||
expected_result[i].test_case.proto);
|
||||
fd = zsock_socket(expected_result[i].test_case.family,
|
||||
expected_result[i].test_case.type,
|
||||
expected_result[i].test_case.proto);
|
||||
|
||||
if (errno == EPROTONOSUPPORT) {
|
||||
func_called--;
|
||||
|
@ -271,7 +271,7 @@ ZTEST(net_socket_register, test_create_sockets)
|
|||
}
|
||||
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
zsock_close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ CONFIG_NET_IPV6=y
|
|||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_L2_DUMMY=y
|
||||
CONFIG_NET_IPV6_DAD=n
|
||||
CONFIG_NET_IPV6_MLD=n
|
||||
|
|
|
@ -102,14 +102,14 @@ static inline void prepare_sock_udp(sa_family_t family, const char *ip, uint16_t
|
|||
|
||||
static void test_getsocketopt_reuseaddr(int sock, void *optval, socklen_t *optlen)
|
||||
{
|
||||
zassert_equal(getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, optval, optlen),
|
||||
zassert_equal(zsock_getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, optval, optlen),
|
||||
0,
|
||||
"getsocketopt() failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_setsocketopt_reuseaddr(int sock, void *optval, socklen_t optlen)
|
||||
{
|
||||
zassert_equal(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, optval, optlen),
|
||||
zassert_equal(zsock_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, optval, optlen),
|
||||
0,
|
||||
"setsocketopt() failed with error %d", errno);
|
||||
}
|
||||
|
@ -123,14 +123,14 @@ static void test_enable_reuseaddr(int sock)
|
|||
|
||||
static void test_getsocketopt_reuseport(int sock, void *optval, socklen_t *optlen)
|
||||
{
|
||||
zassert_equal(getsockopt(sock, SOL_SOCKET, SO_REUSEPORT, optval, optlen),
|
||||
zassert_equal(zsock_getsockopt(sock, SOL_SOCKET, SO_REUSEPORT, optval, optlen),
|
||||
0,
|
||||
"getsocketopt() failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_setsocketopt_reuseport(int sock, void *optval, socklen_t optlen)
|
||||
{
|
||||
zassert_equal(setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, optval, optlen),
|
||||
zassert_equal(zsock_setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, optval, optlen),
|
||||
0,
|
||||
"setsocketopt() failed with error %d", errno);
|
||||
}
|
||||
|
@ -144,14 +144,14 @@ static void test_enable_reuseport(int sock)
|
|||
|
||||
static void test_bind_success(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(bind(sock, addr, addrlen),
|
||||
zassert_equal(zsock_bind(sock, addr, addrlen),
|
||||
0,
|
||||
"bind() failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_bind_fail(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(bind(sock, addr, addrlen),
|
||||
zassert_equal(zsock_bind(sock, addr, addrlen),
|
||||
-1,
|
||||
"bind() succeeded incorrectly");
|
||||
|
||||
|
@ -160,14 +160,14 @@ static void test_bind_fail(int sock, const struct sockaddr *addr, socklen_t addr
|
|||
|
||||
static void test_listen(int sock)
|
||||
{
|
||||
zassert_equal(listen(sock, 0),
|
||||
zassert_equal(zsock_listen(sock, 0),
|
||||
0,
|
||||
"listen() failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_connect_success(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(connect(sock, addr, addrlen),
|
||||
zassert_equal(zsock_connect(sock, addr, addrlen),
|
||||
0,
|
||||
"connect() failed with error %d", errno);
|
||||
|
||||
|
@ -179,7 +179,7 @@ static void test_connect_success(int sock, const struct sockaddr *addr, socklen_
|
|||
|
||||
static void test_connect_fail(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(connect(sock, addr, addrlen),
|
||||
zassert_equal(zsock_connect(sock, addr, addrlen),
|
||||
-1,
|
||||
"connect() succeeded incorrectly");
|
||||
|
||||
|
@ -188,7 +188,7 @@ static void test_connect_fail(int sock, const struct sockaddr *addr, socklen_t a
|
|||
|
||||
static int test_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
int new_sock = accept(sock, addr, addrlen);
|
||||
int new_sock = zsock_accept(sock, addr, addrlen);
|
||||
|
||||
zassert_not_equal(new_sock, -1, "accept() failed with error %d", errno);
|
||||
|
||||
|
@ -198,7 +198,7 @@ static int test_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
|
|||
static void test_sendto(int sock, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(sendto(sock, buf, len, flags, dest_addr, addrlen),
|
||||
zassert_equal(zsock_sendto(sock, buf, len, flags, dest_addr, addrlen),
|
||||
len,
|
||||
"sendto failed with error %d", errno);
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ static void test_sendto(int sock, const void *buf, size_t len, int flags,
|
|||
static void test_recvfrom_success(int sock, void *buf, size_t max_len, int flags,
|
||||
struct sockaddr *src_addr, socklen_t *addrlen)
|
||||
{
|
||||
zassert_equal(recvfrom(sock, buf, max_len, flags, src_addr, addrlen),
|
||||
zassert_equal(zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen),
|
||||
max_len,
|
||||
"recvfrom failed with error %d", errno);
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ static void test_recvfrom_success(int sock, void *buf, size_t max_len, int flags
|
|||
static void test_recvfrom_fail(int sock, void *buf, size_t max_len, int flags,
|
||||
struct sockaddr *src_addr, socklen_t *addrlen)
|
||||
{
|
||||
zassert_equal(recvfrom(sock, buf, max_len, flags, src_addr, addrlen),
|
||||
zassert_equal(zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen),
|
||||
-1,
|
||||
"recvfrom succeeded incorrectly");
|
||||
|
||||
|
@ -223,18 +223,18 @@ static void test_recvfrom_fail(int sock, void *buf, size_t max_len, int flags,
|
|||
|
||||
static void test_recv_success(int sock, void *buf, size_t max_len, int flags)
|
||||
{
|
||||
zassert_equal(recv(sock, buf, max_len, flags),
|
||||
zassert_equal(zsock_recv(sock, buf, max_len, flags),
|
||||
max_len,
|
||||
"recv failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_recv_fail(int sock, void *buf, size_t max_len, int flags)
|
||||
{
|
||||
zassert_equal(recv(sock, buf, max_len, flags),
|
||||
zassert_equal(zsock_recv(sock, buf, max_len, flags),
|
||||
-1,
|
||||
"recvfrom succeeded incorrectly");
|
||||
|
||||
zassert_equal(errno, EAGAIN, "recvfrom() returned unexpected errno (%d)", errno);
|
||||
zassert_equal(errno, EAGAIN, "recv() returned unexpected errno (%d)", errno);
|
||||
}
|
||||
|
||||
ZTEST_USER(socket_reuseaddr_test_suite, test_enable_disable)
|
||||
|
@ -275,7 +275,7 @@ ZTEST_USER(socket_reuseaddr_test_suite, test_enable_disable)
|
|||
test_getsocketopt_reuseaddr(server_sock, (void *)&value, &value_size);
|
||||
zassert_equal(value, (int) true, "SO_REUSEADDR not correctly set, returned %d", value);
|
||||
|
||||
close(server_sock);
|
||||
zsock_close(server_sock);
|
||||
}
|
||||
|
||||
|
||||
|
@ -310,8 +310,8 @@ static void test_reuseaddr_unspecified_specified_common(sa_family_t family,
|
|||
test_bind_fail(server_sock2, &bind_addr2, sizeof(bind_addr2));
|
||||
}
|
||||
|
||||
close(server_sock1);
|
||||
close(server_sock2);
|
||||
zsock_close(server_sock1);
|
||||
zsock_close(server_sock2);
|
||||
}
|
||||
|
||||
ZTEST_USER(socket_reuseaddr_test_suite, test_ipv4_first_unspecified)
|
||||
|
@ -389,8 +389,8 @@ static void test_reuseaddr_tcp_listening_common(sa_family_t family,
|
|||
/* Try to bind the second socket, should fail */
|
||||
test_bind_fail(server_sock2, (struct sockaddr *) &bind_addr2, sizeof(bind_addr2));
|
||||
|
||||
close(server_sock1);
|
||||
close(server_sock2);
|
||||
zsock_close(server_sock1);
|
||||
zsock_close(server_sock2);
|
||||
}
|
||||
|
||||
ZTEST_USER(socket_reuseaddr_test_suite, test_ipv4_tcp_unspecified_listening)
|
||||
|
@ -452,10 +452,10 @@ static void test_reuseaddr_tcp_tcp_time_wait_common(sa_family_t family,
|
|||
accept_sock = test_accept(server_sock, &accept_addr, &accept_addrlen);
|
||||
|
||||
/* Close the server socket */
|
||||
close(server_sock);
|
||||
zsock_close(server_sock);
|
||||
|
||||
/* Close the accepted socket */
|
||||
close(accept_sock);
|
||||
zsock_close(accept_sock);
|
||||
|
||||
/* Wait a short time for the accept socket to enter TIME_WAIT state*/
|
||||
k_msleep(50);
|
||||
|
@ -472,8 +472,8 @@ static void test_reuseaddr_tcp_tcp_time_wait_common(sa_family_t family,
|
|||
/* Try to bind the new server socket again, should work now */
|
||||
test_bind_success(server_sock, (struct sockaddr *) &bind_addr, sizeof(bind_addr));
|
||||
|
||||
close(client_sock);
|
||||
close(server_sock);
|
||||
zsock_close(client_sock);
|
||||
zsock_close(server_sock);
|
||||
|
||||
/* Connection is in TIME_WAIT state, context will be released
|
||||
* after K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY), so wait for it.
|
||||
|
@ -552,7 +552,7 @@ ZTEST_USER(socket_reuseport_test_suite, test_enable_disable)
|
|||
test_getsocketopt_reuseport(server_sock, (void *)&value, &value_size);
|
||||
zassert_equal(value, (int) true, "SO_REUSEPORT not correctly set, returned %d", value);
|
||||
|
||||
close(server_sock);
|
||||
zsock_close(server_sock);
|
||||
}
|
||||
|
||||
|
||||
|
@ -592,8 +592,8 @@ static void test_reuseport_unspecified_specified_common(sa_family_t family,
|
|||
test_bind_fail(server_sock2, &bind_addr2, sizeof(bind_addr2));
|
||||
}
|
||||
|
||||
close(server_sock1);
|
||||
close(server_sock2);
|
||||
zsock_close(server_sock1);
|
||||
zsock_close(server_sock2);
|
||||
}
|
||||
|
||||
ZTEST_USER(socket_reuseport_test_suite, test_ipv4_both_unspecified_bad)
|
||||
|
@ -772,12 +772,12 @@ static void test_reuseport_udp_server_client_common(sa_family_t family,
|
|||
|
||||
/* Receive data from the client */
|
||||
rx_buf = 0;
|
||||
test_recvfrom_success(server_sock, &rx_buf, sizeof(rx_buf), MSG_DONTWAIT,
|
||||
test_recvfrom_success(server_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT,
|
||||
&accept_addr, &accept_addr_len);
|
||||
zassert_equal(rx_buf, tx_buf, "wrong data");
|
||||
|
||||
/* Create a more specific socket to have a direct connection to the new client */
|
||||
accept_sock = socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
accept_sock = zsock_socket(family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(accept_sock >= 0, "socket open failed");
|
||||
|
||||
/* Make sure we can bind to the address:port */
|
||||
|
@ -809,24 +809,24 @@ static void test_reuseport_udp_server_client_common(sa_family_t family,
|
|||
if (setup == BOTH_SET) {
|
||||
/* We should receive data on the new specific socket, not on the general one */
|
||||
rx_buf = 0;
|
||||
test_recvfrom_fail(server_sock, &rx_buf, sizeof(rx_buf), MSG_DONTWAIT,
|
||||
test_recvfrom_fail(server_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT,
|
||||
&accept_addr, &accept_addr_len);
|
||||
|
||||
rx_buf = 0;
|
||||
test_recv_success(accept_sock, &rx_buf, sizeof(rx_buf), MSG_DONTWAIT);
|
||||
test_recv_success(accept_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
} else {
|
||||
/* We should receive data on the general server socket */
|
||||
rx_buf = 0;
|
||||
test_recvfrom_success(server_sock, &rx_buf, sizeof(rx_buf), MSG_DONTWAIT,
|
||||
test_recvfrom_success(server_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT,
|
||||
&accept_addr, &accept_addr_len);
|
||||
|
||||
rx_buf = 0;
|
||||
test_recv_fail(accept_sock, &rx_buf, sizeof(rx_buf), MSG_DONTWAIT);
|
||||
test_recv_fail(accept_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
}
|
||||
|
||||
close(accept_sock);
|
||||
close(client_sock);
|
||||
close(server_sock);
|
||||
zsock_close(accept_sock);
|
||||
zsock_close(client_sock);
|
||||
zsock_close(server_sock);
|
||||
}
|
||||
|
||||
ZTEST_USER(socket_reuseport_test_suite, test_ipv4_udp_bad_both_not_set)
|
||||
|
@ -931,10 +931,10 @@ static void test_reuseport_tcp_identical_clients_common(sa_family_t family,
|
|||
/* Connect the second client, should fail */
|
||||
test_connect_fail(client_sock2, (struct sockaddr *)&connect_addr, sizeof(connect_addr));
|
||||
|
||||
close(accept_sock);
|
||||
close(client_sock1);
|
||||
close(client_sock2);
|
||||
close(server_sock);
|
||||
zsock_close(accept_sock);
|
||||
zsock_close(client_sock1);
|
||||
zsock_close(client_sock2);
|
||||
zsock_close(server_sock);
|
||||
|
||||
/* Connection is in TIME_WAIT state, context will be released
|
||||
* after K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY), so wait for it.
|
||||
|
|
|
@ -9,7 +9,6 @@ CONFIG_NET_LOOPBACK=y
|
|||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
# Defines fd_set size
|
||||
CONFIG_POSIX_MAX_FDS=33
|
||||
|
||||
|
|
|
@ -32,35 +32,35 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
|
|||
|
||||
ZTEST_USER(net_socket_select, test_fd_set)
|
||||
{
|
||||
fd_set set;
|
||||
zsock_fd_set set;
|
||||
|
||||
/* Relies on specific value of CONFIG_POSIX_MAX_FDS in prj.conf */
|
||||
zassert_equal(sizeof(set.bitset), sizeof(uint32_t) * 2, "");
|
||||
|
||||
FD_ZERO(&set);
|
||||
ZSOCK_FD_ZERO(&set);
|
||||
zassert_equal(set.bitset[0], 0, "");
|
||||
zassert_equal(set.bitset[1], 0, "");
|
||||
zassert_false(FD_ISSET(0, &set), "");
|
||||
zassert_false(ZSOCK_FD_ISSET(0, &set), "");
|
||||
|
||||
FD_SET(0, &set);
|
||||
zassert_true(FD_ISSET(0, &set), "");
|
||||
ZSOCK_FD_SET(0, &set);
|
||||
zassert_true(ZSOCK_FD_ISSET(0, &set), "");
|
||||
|
||||
FD_CLR(0, &set);
|
||||
zassert_false(FD_ISSET(0, &set), "");
|
||||
ZSOCK_FD_CLR(0, &set);
|
||||
zassert_false(ZSOCK_FD_ISSET(0, &set), "");
|
||||
|
||||
FD_SET(0, &set);
|
||||
ZSOCK_FD_SET(0, &set);
|
||||
zassert_equal(set.bitset[0], 0x00000001, "");
|
||||
zassert_equal(set.bitset[1], 0, "");
|
||||
|
||||
FD_SET(31, &set);
|
||||
ZSOCK_FD_SET(31, &set);
|
||||
zassert_equal(set.bitset[0], 0x80000001, "");
|
||||
zassert_equal(set.bitset[1], 0, "");
|
||||
|
||||
FD_SET(33, &set);
|
||||
ZSOCK_FD_SET(33, &set);
|
||||
zassert_equal(set.bitset[0], 0x80000001, "");
|
||||
zassert_equal(set.bitset[1], 0x00000002, "");
|
||||
|
||||
FD_ZERO(&set);
|
||||
ZSOCK_FD_ZERO(&set);
|
||||
zassert_equal(set.bitset[0], 0, "");
|
||||
zassert_equal(set.bitset[1], 0, "");
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ ZTEST_USER(net_socket_select, test_select)
|
|||
int s_sock;
|
||||
struct sockaddr_in6 c_addr;
|
||||
struct sockaddr_in6 s_addr;
|
||||
fd_set readfds;
|
||||
zsock_fd_set readfds;
|
||||
uint32_t tstamp;
|
||||
ssize_t len;
|
||||
char buf[10];
|
||||
|
@ -81,20 +81,20 @@ ZTEST_USER(net_socket_select, test_select)
|
|||
prepare_sock_udp_v6(MY_IPV6_ADDR, CLIENT_PORT, &c_sock, &c_addr);
|
||||
prepare_sock_udp_v6(MY_IPV6_ADDR, SERVER_PORT, &s_sock, &s_addr);
|
||||
|
||||
res = bind(s_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
res = zsock_bind(s_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
zassert_equal(res, 0, "bind failed");
|
||||
|
||||
res = connect(c_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
res = zsock_connect(c_sock, (struct sockaddr *)&s_addr, sizeof(s_addr));
|
||||
zassert_equal(res, 0, "connect failed");
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(c_sock, &readfds);
|
||||
FD_SET(s_sock, &readfds);
|
||||
ZSOCK_FD_ZERO(&readfds);
|
||||
ZSOCK_FD_SET(c_sock, &readfds);
|
||||
ZSOCK_FD_SET(s_sock, &readfds);
|
||||
|
||||
/* Poll non-ready fd's with timeout of 0 */
|
||||
tval.tv_sec = tval.tv_usec = 0;
|
||||
tstamp = k_uptime_get_32();
|
||||
res = select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
res = zsock_select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
tstamp = k_uptime_get_32() - tstamp;
|
||||
/* Even though we expect select to be non-blocking, scheduler may
|
||||
* preempt the thread. That's why we add FUZZ to the expected
|
||||
|
@ -103,67 +103,67 @@ ZTEST_USER(net_socket_select, test_select)
|
|||
zassert_true(tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
zassert_false(FD_ISSET(c_sock, &readfds), "");
|
||||
zassert_false(FD_ISSET(s_sock, &readfds), "");
|
||||
zassert_false(ZSOCK_FD_ISSET(c_sock, &readfds), "");
|
||||
zassert_false(ZSOCK_FD_ISSET(s_sock, &readfds), "");
|
||||
|
||||
/* Poll non-ready fd's with timeout of 10ms */
|
||||
FD_SET(c_sock, &readfds);
|
||||
FD_SET(s_sock, &readfds);
|
||||
ZSOCK_FD_SET(c_sock, &readfds);
|
||||
ZSOCK_FD_SET(s_sock, &readfds);
|
||||
tval.tv_sec = 0;
|
||||
tval.tv_usec = TIMEOUT_MS * 1000;
|
||||
tstamp = k_uptime_get_32();
|
||||
res = select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
res = zsock_select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
tstamp = k_uptime_get_32() - tstamp;
|
||||
zassert_true(tstamp >= TIMEOUT_MS && tstamp <= TIMEOUT_MS + FUZZ, "");
|
||||
zassert_equal(res, 0, "");
|
||||
|
||||
|
||||
/* Send pkt for s_sock and poll with timeout of 10ms */
|
||||
len = send(c_sock, BUF_AND_SIZE(TEST_STR_SMALL), 0);
|
||||
len = zsock_send(c_sock, BUF_AND_SIZE(TEST_STR_SMALL), 0);
|
||||
zassert_equal(len, STRLEN(TEST_STR_SMALL), "invalid send len");
|
||||
|
||||
FD_SET(c_sock, &readfds);
|
||||
FD_SET(s_sock, &readfds);
|
||||
ZSOCK_FD_SET(c_sock, &readfds);
|
||||
ZSOCK_FD_SET(s_sock, &readfds);
|
||||
tval.tv_sec = 0;
|
||||
tval.tv_usec = TIMEOUT_MS * 1000;
|
||||
tstamp = k_uptime_get_32();
|
||||
res = select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
res = zsock_select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
tstamp = k_uptime_get_32() - tstamp;
|
||||
zassert_true(tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 1, "");
|
||||
|
||||
zassert_false(FD_ISSET(c_sock, &readfds), "");
|
||||
zassert_true(FD_ISSET(s_sock, &readfds), "");
|
||||
zassert_false(ZSOCK_FD_ISSET(c_sock, &readfds), "");
|
||||
zassert_true(ZSOCK_FD_ISSET(s_sock, &readfds), "");
|
||||
|
||||
|
||||
/* Recv pkt from s_sock and ensure no poll events happen */
|
||||
len = recv(s_sock, BUF_AND_SIZE(buf), 0);
|
||||
len = zsock_recv(s_sock, BUF_AND_SIZE(buf), 0);
|
||||
zassert_equal(len, STRLEN(TEST_STR_SMALL), "invalid recv len");
|
||||
|
||||
FD_SET(c_sock, &readfds);
|
||||
FD_SET(s_sock, &readfds);
|
||||
ZSOCK_FD_SET(c_sock, &readfds);
|
||||
ZSOCK_FD_SET(s_sock, &readfds);
|
||||
tval.tv_sec = tval.tv_usec = 0;
|
||||
tstamp = k_uptime_get_32();
|
||||
res = select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
res = zsock_select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
zassert_true(k_uptime_get_32() - tstamp <= FUZZ, "");
|
||||
zassert_equal(res, 0, "");
|
||||
zassert_false(FD_ISSET(s_sock, &readfds), "");
|
||||
zassert_false(ZSOCK_FD_ISSET(s_sock, &readfds), "");
|
||||
|
||||
|
||||
/* Close one socket and ensure POLLNVAL happens */
|
||||
res = close(c_sock);
|
||||
res = zsock_close(c_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
|
||||
FD_SET(c_sock, &readfds);
|
||||
FD_SET(s_sock, &readfds);
|
||||
ZSOCK_FD_SET(c_sock, &readfds);
|
||||
ZSOCK_FD_SET(s_sock, &readfds);
|
||||
tval.tv_sec = tval.tv_usec = 0;
|
||||
tstamp = k_uptime_get_32();
|
||||
res = select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
res = zsock_select(s_sock + 1, &readfds, NULL, NULL, &tval);
|
||||
zassert_true(k_uptime_get_32() - tstamp <= FUZZ, "");
|
||||
zassert_true(res < 0, "");
|
||||
zassert_equal(errno, EBADF, "");
|
||||
|
||||
res = close(s_sock);
|
||||
res = zsock_close(s_sock);
|
||||
zassert_equal(res, 0, "close failed");
|
||||
}
|
||||
|
||||
|
|
|
@ -22,14 +22,14 @@ static inline int prepare_listen_sock_udp_v4(struct sockaddr_in *addr)
|
|||
|
||||
zassert_not_null(addr, "null sockaddr");
|
||||
|
||||
ret = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ret = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(ret >= 0, "socket open failed");
|
||||
|
||||
sock = ret;
|
||||
|
||||
zassert_equal(addr->sin_family, AF_INET, "Invalid family");
|
||||
|
||||
ret = bind(sock, (struct sockaddr *)addr, sizeof(*addr));
|
||||
ret = zsock_bind(sock, (struct sockaddr *)addr, sizeof(*addr));
|
||||
zassert_equal(ret, 0, "bind failed (%d/%d)", ret, errno);
|
||||
|
||||
return sock;
|
||||
|
@ -41,14 +41,14 @@ static inline int prepare_listen_sock_udp_v6(struct sockaddr_in6 *addr)
|
|||
|
||||
zassert_not_null(addr, "null sockaddr");
|
||||
|
||||
ret = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ret = zsock_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(ret >= 0, "socket open failed");
|
||||
|
||||
sock = ret;
|
||||
|
||||
zassert_equal(addr->sin6_family, AF_INET6, "Invalid family");
|
||||
|
||||
ret = bind(sock, (struct sockaddr *)addr, sizeof(*addr));
|
||||
ret = zsock_bind(sock, (struct sockaddr *)addr, sizeof(*addr));
|
||||
zassert_equal(ret, 0, "bind failed (%d/%d)", ret, errno);
|
||||
|
||||
return sock;
|
||||
|
@ -63,12 +63,12 @@ static inline void prepare_sock_udp_v4(const char *addr, uint16_t port,
|
|||
zassert_not_null(sock, "null sock");
|
||||
zassert_not_null(sockaddr, "null sockaddr");
|
||||
|
||||
*sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
*sock = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
zassert_true(*sock >= 0, "socket open failed");
|
||||
|
||||
sockaddr->sin_family = AF_INET;
|
||||
sockaddr->sin_port = htons(port);
|
||||
rv = inet_pton(AF_INET, addr, &sockaddr->sin_addr);
|
||||
rv = zsock_inet_pton(AF_INET, addr, &sockaddr->sin_addr);
|
||||
zassert_equal(rv, 1, "inet_pton failed");
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ CONFIG_NET_IPV4=y
|
|||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETPAIR=y
|
||||
CONFIG_NET_SOCKETPAIR_BUFFER_SIZE=64
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
|
||||
# Network driver config
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
|
|
@ -27,7 +27,7 @@ static void before(void *arg)
|
|||
fixture->sv[i] = -1;
|
||||
}
|
||||
}
|
||||
zassert_ok(socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv));
|
||||
zassert_ok(zsock_socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv));
|
||||
}
|
||||
|
||||
static void after(void *arg)
|
||||
|
@ -36,7 +36,7 @@ static void after(void *arg)
|
|||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (fixture->sv[i] >= 0) {
|
||||
zassert_ok(close(fixture->sv[i]));
|
||||
zassert_ok(zsock_close(fixture->sv[i]));
|
||||
fixture->sv[i] = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/net/socket.h>
|
||||
#include <zephyr/posix/fcntl.h>
|
||||
#include <zephyr/net/socket.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ static void work_handler(struct k_work *w)
|
|||
LOG_DBG("%sing 1 byte %s fd %d", ctx.write ? "read" : "writ",
|
||||
ctx.write ? "from" : "to", ctx.fd);
|
||||
if (ctx.write) {
|
||||
res = recv(ctx.fd, &c, 1, 0);
|
||||
res = zsock_recv(ctx.fd, &c, 1, 0);
|
||||
} else {
|
||||
res = send(ctx.fd, "x", 1, 0);
|
||||
res = zsock_send(ctx.fd, "x", 1, 0);
|
||||
}
|
||||
if (-1 == res || 1 != res) {
|
||||
LOG_DBG("%s() failed: %d", ctx.write ? "recv" : "send", errno);
|
||||
|
@ -77,7 +77,7 @@ ZTEST_F(net_socketpair, test_write_block)
|
|||
for (ctx.m = 0; atomic_get(&ctx.m)
|
||||
< CONFIG_NET_SOCKETPAIR_BUFFER_SIZE;) {
|
||||
|
||||
res = send(fixture->sv[i], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[i], "x", 1, 0);
|
||||
zassert_not_equal(res, -1, "send() failed: %d", errno);
|
||||
zassert_equal(res, 1, "wrote %d bytes instead of 1",
|
||||
res);
|
||||
|
@ -88,7 +88,7 @@ ZTEST_F(net_socketpair, test_write_block)
|
|||
|
||||
/* try to write one more byte */
|
||||
LOG_DBG("writing to fd %d", fixture->sv[i]);
|
||||
res = send(fixture->sv[i], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[i], "x", 1, 0);
|
||||
zassert_not_equal(res, -1, "send() failed: %d", errno);
|
||||
zassert_equal(res, 1, "wrote %d bytes instead of 1", res);
|
||||
|
||||
|
@ -117,7 +117,7 @@ ZTEST_F(net_socketpair, test_read_block)
|
|||
/* try to read one byte */
|
||||
LOG_DBG("reading from fd %d", fixture->sv[i]);
|
||||
x = '\0';
|
||||
res = recv(fixture->sv[i], &x, 1, 0);
|
||||
res = zsock_recv(fixture->sv[i], &x, 1, 0);
|
||||
zassert_not_equal(res, -1, "recv() failed: %d", errno);
|
||||
zassert_equal(res, 1, "read %d bytes instead of 1", res);
|
||||
|
||||
|
|
|
@ -10,20 +10,20 @@ ZTEST_USER_F(net_socketpair, test_close_one_end_and_write_to_the_other)
|
|||
int res;
|
||||
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
res = close(fixture->sv[i]);
|
||||
res = zsock_close(fixture->sv[i]);
|
||||
zassert_equal(res, 0, "close(fixture->sv[%u]) failed: %d", i, errno);
|
||||
fixture->sv[i] = -1;
|
||||
|
||||
res = send(fixture->sv[(!i) & 1], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[(!i) & 1], "x", 1, 0);
|
||||
zassert_equal(res, -1, "expected send() to fail");
|
||||
zassert_equal(res, -1, "errno: expected: EPIPE actual: %d",
|
||||
errno);
|
||||
|
||||
res = close(fixture->sv[(!i) & 1]);
|
||||
res = zsock_close(fixture->sv[(!i) & 1]);
|
||||
zassert_equal(res, 0, "close(fixture->sv[%u]) failed: %d", i, errno);
|
||||
fixture->sv[(!i) & 1] = -1;
|
||||
|
||||
res = socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv);
|
||||
res = zsock_socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv);
|
||||
zassert_equal(res, 0, "socketpair() failed: %d", errno);
|
||||
}
|
||||
}
|
||||
|
@ -39,28 +39,28 @@ ZTEST_USER_F(net_socketpair, test_close_one_end_and_read_from_the_other)
|
|||
* reading is possible from the other end still and that data
|
||||
* is not lost.
|
||||
*/
|
||||
res = send(fixture->sv[i], "xx", 2, 0);
|
||||
res = zsock_send(fixture->sv[i], "xx", 2, 0);
|
||||
zassert_not_equal(res, -1, "send() failed: %d", errno);
|
||||
zassert_equal(res, 2, "write() failed to write 2 bytes");
|
||||
|
||||
res = close(fixture->sv[i]);
|
||||
res = zsock_close(fixture->sv[i]);
|
||||
zassert_equal(res, 0, "close(fixture->sv[%u]) failed: %d", i, errno);
|
||||
fixture->sv[i] = -1;
|
||||
|
||||
memset(xx, 0, sizeof(xx));
|
||||
res = recv(fixture->sv[(!i) & 1], xx, sizeof(xx), 0);
|
||||
res = zsock_recv(fixture->sv[(!i) & 1], xx, sizeof(xx), 0);
|
||||
zassert_not_equal(res, -1, "read() failed: %d", errno);
|
||||
zassert_equal(res, 2, "expected to read 2 bytes but read %d",
|
||||
res);
|
||||
|
||||
res = recv(fixture->sv[(!i) & 1], xx, sizeof(xx), 0);
|
||||
res = zsock_recv(fixture->sv[(!i) & 1], xx, sizeof(xx), 0);
|
||||
zassert_equal(res, 0, "expected read() to succeed but read 0 bytes");
|
||||
|
||||
res = close(fixture->sv[(!i) & 1]);
|
||||
res = zsock_close(fixture->sv[(!i) & 1]);
|
||||
zassert_equal(res, 0, "close(fixture->sv[%u]) failed: %d", i, errno);
|
||||
fixture->sv[(!i) & 1] = -1;
|
||||
|
||||
res = socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv);
|
||||
res = zsock_socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv);
|
||||
zassert_equal(res, 0, "socketpair() failed: %d", errno);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ ZTEST_USER_F(net_socketpair, test_expected_failures)
|
|||
|
||||
/* Use invalid values in fields starting from left to right */
|
||||
|
||||
res = socketpair(AF_INET, SOCK_STREAM, 0, fixture->sv);
|
||||
res = zsock_socketpair(AF_INET, SOCK_STREAM, 0, fixture->sv);
|
||||
if (res != -1) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
zassert_ok(close(fixture->sv[i]));
|
||||
zassert_ok(zsock_close(fixture->sv[i]));
|
||||
fixture->sv[i] = -1;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ ZTEST_USER_F(net_socketpair, test_expected_failures)
|
|||
zassert_equal(errno, EAFNOSUPPORT,
|
||||
"errno should be EAFNOSUPPORT with bad address family");
|
||||
|
||||
res = socketpair(AF_UNIX, 42, 0, fixture->sv);
|
||||
res = zsock_socketpair(AF_UNIX, 42, 0, fixture->sv);
|
||||
if (res != -1) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
zassert_ok(close(fixture->sv[i]));
|
||||
zassert_ok(zsock_close(fixture->sv[i]));
|
||||
fixture->sv[i] = -1;
|
||||
}
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ ZTEST_USER_F(net_socketpair, test_expected_failures)
|
|||
zassert_equal(errno, EPROTOTYPE,
|
||||
"errno should be EPROTOTYPE with bad socket type");
|
||||
|
||||
res = socketpair(AF_UNIX, SOCK_STREAM, IPPROTO_TLS_1_0, fixture->sv);
|
||||
res = zsock_socketpair(AF_UNIX, SOCK_STREAM, IPPROTO_TLS_1_0, fixture->sv);
|
||||
if (res != -1) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
zassert_ok(close(fixture->sv[i]));
|
||||
zassert_ok(zsock_close(fixture->sv[i]));
|
||||
fixture->sv[i] = -1;
|
||||
}
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ ZTEST_USER_F(net_socketpair, test_expected_failures)
|
|||
"errno should be EPROTONOSUPPORT with bad protocol");
|
||||
|
||||
/* This is not a POSIX requirement, but should be safe */
|
||||
res = socketpair(AF_UNIX, SOCK_STREAM, 0, NULL);
|
||||
res = zsock_socketpair(AF_UNIX, SOCK_STREAM, 0, NULL);
|
||||
if (res != -1) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
zassert_ok(close(fixture->sv[i]));
|
||||
zassert_ok(zsock_close(fixture->sv[i]));
|
||||
fixture->sv[i] = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ ZTEST_USER_F(net_socketpair, test_fcntl)
|
|||
int res;
|
||||
int flags;
|
||||
|
||||
res = fcntl(fixture->sv[0], F_GETFL, 0);
|
||||
res = zsock_fcntl(fixture->sv[0], F_GETFL, 0);
|
||||
zassert_not_equal(res, -1,
|
||||
"fcntl(fixture->sv[0], F_GETFL) failed. errno: %d", errno);
|
||||
|
||||
|
@ -19,11 +19,11 @@ ZTEST_USER_F(net_socketpair, test_fcntl)
|
|||
zassert_equal(res & O_NONBLOCK, 0,
|
||||
"socketpair should block by default");
|
||||
|
||||
res = fcntl(fixture->sv[0], F_SETFL, flags | O_NONBLOCK);
|
||||
res = zsock_fcntl(fixture->sv[0], F_SETFL, flags | O_NONBLOCK);
|
||||
zassert_not_equal(res, -1,
|
||||
"fcntl(fixture->sv[0], F_SETFL, flags | O_NONBLOCK) failed. errno: %d",
|
||||
errno);
|
||||
|
||||
res = fcntl(fixture->sv[0], F_GETFL, 0);
|
||||
res = zsock_fcntl(fixture->sv[0], F_GETFL, 0);
|
||||
zassert_equal(res ^ flags, O_NONBLOCK, "expected O_NONBLOCK set");
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ ZTEST_F(net_socketpair, test_ioctl_fionread)
|
|||
/* both ends should have zero bytes available after being newly created */
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
avail = 42;
|
||||
zassert_ok(ioctl(fixture->sv[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_ok(zsock_ioctl(fixture->sv[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_equal(avail, 0);
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,14 @@ ZTEST_F(net_socketpair, test_ioctl_fionread)
|
|||
int j = (i + 1) % 2;
|
||||
|
||||
zassert_equal(1, write(fixture->sv[i], "\x42", 1));
|
||||
zassert_ok(ioctl(fixture->sv[j], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_ok(zsock_ioctl(fixture->sv[j], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_equal(avail, 1);
|
||||
}
|
||||
|
||||
/* read the other end, ensure availability is zero again */
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
zassert_equal(1, read(fixture->sv[i], &byte, 1));
|
||||
zassert_ok(ioctl(fixture->sv[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_ok(zsock_ioctl(fixture->sv[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_equal(avail, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ static void happy_path(
|
|||
* Test with send() / recv()
|
||||
*/
|
||||
|
||||
res = send(fixture->sv[i], expected_msg, expected_msg_len, 0);
|
||||
res = zsock_send(fixture->sv[i], expected_msg, expected_msg_len, 0);
|
||||
|
||||
zassert_not_equal(res, -1, "send() failed: %d", errno);
|
||||
actual_msg_len = res;
|
||||
|
@ -39,7 +39,7 @@ static void happy_path(
|
|||
|
||||
memset(actual_msg, 0, sizeof(actual_msg));
|
||||
|
||||
res = recv(fixture->sv[(!i) & 1], actual_msg, sizeof(actual_msg), 0);
|
||||
res = zsock_recv(fixture->sv[(!i) & 1], actual_msg, sizeof(actual_msg), 0);
|
||||
|
||||
zassert_not_equal(res, -1, "recv() failed: %d", errno);
|
||||
actual_msg_len = res;
|
||||
|
@ -54,7 +54,7 @@ static void happy_path(
|
|||
* Test with sendto(2) / recvfrom(2)
|
||||
*/
|
||||
|
||||
res = sendto(fixture->sv[i], expected_msg, expected_msg_len, 0, NULL, 0);
|
||||
res = zsock_sendto(fixture->sv[i], expected_msg, expected_msg_len, 0, NULL, 0);
|
||||
|
||||
zassert_not_equal(res, -1, "sendto() failed: %d", errno);
|
||||
actual_msg_len = res;
|
||||
|
@ -64,8 +64,8 @@ static void happy_path(
|
|||
memset(actual_msg, 0, sizeof(actual_msg));
|
||||
|
||||
len = 0;
|
||||
res = recvfrom(fixture->sv[(!i) & 1], actual_msg, sizeof(actual_msg), 0,
|
||||
NULL, &len);
|
||||
res = zsock_recvfrom(fixture->sv[(!i) & 1], actual_msg, sizeof(actual_msg), 0,
|
||||
NULL, &len);
|
||||
zassert_true(res >= 0, "recvfrom() failed: %d", errno);
|
||||
actual_msg_len = res;
|
||||
zassert_equal(actual_msg_len, expected_msg_len,
|
||||
|
@ -85,14 +85,14 @@ static void happy_path(
|
|||
iovec.iov_base = (void *)expected_msg;
|
||||
iovec.iov_len = expected_msg_len;
|
||||
|
||||
res = sendmsg(fixture->sv[i], &msghdr, 0);
|
||||
res = zsock_sendmsg(fixture->sv[i], &msghdr, 0);
|
||||
|
||||
zassert_not_equal(res, -1, "sendmsg() failed: %d", errno);
|
||||
actual_msg_len = res;
|
||||
zassert_equal(actual_msg_len, expected_msg_len,
|
||||
"did not sendmsg entire message");
|
||||
|
||||
res = recv(fixture->sv[(!i) & 1], actual_msg, sizeof(actual_msg), 0);
|
||||
res = zsock_recv(fixture->sv[(!i) & 1], actual_msg, sizeof(actual_msg), 0);
|
||||
|
||||
zassert_not_equal(res, -1, "recv() failed: %d", errno);
|
||||
actual_msg_len = res;
|
||||
|
|
|
@ -14,19 +14,19 @@ ZTEST_USER_F(net_socketpair, test_write_nonblock)
|
|||
/* first, fill up the buffer */
|
||||
for (size_t k = 0; k < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE;
|
||||
++k) {
|
||||
res = send(fixture->sv[i], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[i], "x", 1, 0);
|
||||
zassert_equal(res, 1, "send() failed: %d", errno);
|
||||
}
|
||||
|
||||
/* then set the O_NONBLOCK flag */
|
||||
res = fcntl(fixture->sv[i], F_GETFL, 0);
|
||||
res = zsock_fcntl(fixture->sv[i], F_GETFL, 0);
|
||||
zassert_not_equal(res, -1, "fcntl() failed: %d", i, errno);
|
||||
|
||||
res = fcntl(fixture->sv[i], F_SETFL, res | O_NONBLOCK);
|
||||
res = zsock_fcntl(fixture->sv[i], F_SETFL, res | O_NONBLOCK);
|
||||
zassert_not_equal(res, -1, "fcntl() failed: %d", i, errno);
|
||||
|
||||
/* then, try to write one more byte */
|
||||
res = send(fixture->sv[i], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[i], "x", 1, 0);
|
||||
zassert_equal(res, -1, "expected send to fail");
|
||||
zassert_equal(errno, EAGAIN, "errno: expected: EAGAIN "
|
||||
"actual: %d", errno);
|
||||
|
@ -40,14 +40,14 @@ ZTEST_USER_F(net_socketpair, test_read_nonblock)
|
|||
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
/* set the O_NONBLOCK flag */
|
||||
res = fcntl(fixture->sv[i], F_GETFL, 0);
|
||||
res = zsock_fcntl(fixture->sv[i], F_GETFL, 0);
|
||||
zassert_not_equal(res, -1, "fcntl() failed: %d", i, errno);
|
||||
|
||||
res = fcntl(fixture->sv[i], F_SETFL, res | O_NONBLOCK);
|
||||
res = zsock_fcntl(fixture->sv[i], F_SETFL, res | O_NONBLOCK);
|
||||
zassert_not_equal(res, -1, "fcntl() failed: %d", i, errno);
|
||||
|
||||
/* then, try to read one byte */
|
||||
res = recv(fixture->sv[i], &c, 1, 0);
|
||||
res = zsock_recv(fixture->sv[i], &c, 1, 0);
|
||||
zassert_equal(res, -1, "expected recv() to fail");
|
||||
zassert_equal(errno, EAGAIN, "errno: expected: EAGAIN "
|
||||
"actual: %d", errno);
|
||||
|
|
|
@ -24,23 +24,23 @@ static ZTEST_BMEM struct k_work work;
|
|||
static void test_socketpair_poll_timeout_common(struct net_socketpair_fixture *fixture)
|
||||
{
|
||||
int res;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLIN;
|
||||
res = poll(fds, 1, 1);
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
res = zsock_poll(fds, 1, 1);
|
||||
zassert_equal(res, 0, "poll: expected: 0 actual: %d", res);
|
||||
|
||||
for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) {
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_equal(res, 1, "send() failed: %d", res);
|
||||
}
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
res = poll(fds, 1, 1);
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
res = zsock_poll(fds, 1, 1);
|
||||
zassert_equal(res, 0, "poll: expected: 0 actual: %d", res);
|
||||
}
|
||||
|
||||
|
@ -54,15 +54,15 @@ ZTEST_USER_F(net_socketpair, test_poll_timeout_nonblocking)
|
|||
{
|
||||
int res;
|
||||
|
||||
res = fcntl(fixture->sv[0], F_GETFL, 0);
|
||||
res = zsock_fcntl(fixture->sv[0], F_GETFL, 0);
|
||||
zassert_not_equal(res, -1, "fcntl failed: %d", errno);
|
||||
|
||||
int flags = res;
|
||||
|
||||
res = fcntl(fixture->sv[0], F_SETFL, O_NONBLOCK | flags);
|
||||
res = zsock_fcntl(fixture->sv[0], F_SETFL, O_NONBLOCK | flags);
|
||||
zassert_not_equal(res, -1, "fcntl failed: %d", errno);
|
||||
|
||||
res = fcntl(fixture->sv[1], F_SETFL, O_NONBLOCK | flags);
|
||||
res = zsock_fcntl(fixture->sv[1], F_SETFL, O_NONBLOCK | flags);
|
||||
zassert_not_equal(res, -1, "fcntl failed: %d", errno);
|
||||
|
||||
test_socketpair_poll_timeout_common(fixture);
|
||||
|
@ -78,7 +78,7 @@ static void close_fun(struct k_work *w)
|
|||
}
|
||||
|
||||
LOG_DBG("about to close fd %d", *ctx.fd);
|
||||
close(*ctx.fd);
|
||||
zsock_close(*ctx.fd);
|
||||
*ctx.fd = -1;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ ZTEST_F(net_socketpair, test_poll_close_remote_end_POLLIN)
|
|||
{
|
||||
int res;
|
||||
char c;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
/*
|
||||
* poll until there are bytes to read.
|
||||
|
@ -102,7 +102,7 @@ ZTEST_F(net_socketpair, test_poll_close_remote_end_POLLIN)
|
|||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLIN;
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.fd = &fixture->sv[1];
|
||||
|
@ -112,35 +112,35 @@ ZTEST_F(net_socketpair, test_poll_close_remote_end_POLLIN)
|
|||
k_work_init(&work, close_fun);
|
||||
k_work_submit(&work);
|
||||
|
||||
res = poll(fds, 1, -1);
|
||||
res = zsock_poll(fds, 1, -1);
|
||||
zassert_equal(res, 1, "poll() failed: %d", res);
|
||||
zassert_equal(fds[0].revents & POLLIN, POLLIN, "POLLIN not set");
|
||||
zassert_equal(fds[0].revents & ZSOCK_POLLIN, ZSOCK_POLLIN, "POLLIN not set");
|
||||
|
||||
res = recv(fixture->sv[0], &c, 1, 0);
|
||||
res = zsock_recv(fixture->sv[0], &c, 1, 0);
|
||||
zassert_equal(res, 0, "read did not return EOF");
|
||||
}
|
||||
|
||||
ZTEST_F(net_socketpair, test_poll_close_remote_end_POLLOUT)
|
||||
{
|
||||
int res;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
/*
|
||||
* Fill up the remote q and then poll until write space is available.
|
||||
* But rather than reading, close the other end of the channel
|
||||
*/
|
||||
|
||||
res = socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv);
|
||||
res = zsock_socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv);
|
||||
zassert_not_equal(res, -1, "socketpair() failed: %d", errno);
|
||||
|
||||
for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) {
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_equal(res, 1, "send failed: %d", res);
|
||||
}
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.fd = &fixture->sv[1];
|
||||
|
@ -150,11 +150,11 @@ ZTEST_F(net_socketpair, test_poll_close_remote_end_POLLOUT)
|
|||
k_work_init(&work, close_fun);
|
||||
k_work_submit(&work);
|
||||
|
||||
res = poll(fds, 1, -1);
|
||||
res = zsock_poll(fds, 1, -1);
|
||||
zassert_equal(res, 1, "poll() failed: %d", res);
|
||||
zassert_equal(fds[0].revents & POLLHUP, POLLHUP, "POLLHUP not set");
|
||||
zassert_equal(fds[0].revents & ZSOCK_POLLHUP, ZSOCK_POLLHUP, "POLLHUP not set");
|
||||
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_equal(res, -1, "send(): expected: -1 actual: %d", res);
|
||||
zassert_equal(errno, EPIPE, "errno: expected: EPIPE actual: %d", errno);
|
||||
}
|
||||
|
@ -169,38 +169,38 @@ ZTEST_F(net_socketpair, test_poll_close_remote_end_POLLOUT)
|
|||
ZTEST_USER_F(net_socketpair, test_poll_immediate_data)
|
||||
{
|
||||
int res;
|
||||
struct pollfd fds[2];
|
||||
struct zsock_pollfd fds[2];
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
res = poll(fds, 1, 0);
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
res = zsock_poll(fds, 1, 0);
|
||||
zassert_not_equal(res, -1, "poll() failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLOUT, 0, "POLLOUT not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set");
|
||||
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_not_equal(res, -1, "send() failed: %d", errno);
|
||||
zassert_equal(res, 1, "write(): expected: 1 actual: %d", res);
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[1];
|
||||
fds[0].events |= POLLIN;
|
||||
res = poll(fds, 1, 0);
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
res = zsock_poll(fds, 1, 0);
|
||||
zassert_not_equal(res, -1, "poll() failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLIN, 0, "POLLIN not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, 0, "POLLIN not set");
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
fds[1].fd = fixture->sv[1];
|
||||
fds[1].events |= POLLIN;
|
||||
res = poll(fds, 2, 0);
|
||||
fds[1].events |= ZSOCK_POLLIN;
|
||||
res = zsock_poll(fds, 2, 0);
|
||||
zassert_not_equal(res, -1, "poll() failed: %d", errno);
|
||||
zassert_equal(res, 2, "poll(): expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLOUT, 0, "POLLOUT not set");
|
||||
zassert_not_equal(fds[1].revents & POLLIN, 0, "POLLIN not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set");
|
||||
zassert_not_equal(fds[1].revents & ZSOCK_POLLIN, 0, "POLLIN not set");
|
||||
}
|
||||
|
||||
static void rw_fun(struct k_work *w)
|
||||
|
@ -217,7 +217,7 @@ static void rw_fun(struct k_work *w)
|
|||
|
||||
if (ctx.should_write) {
|
||||
LOG_DBG("about to write 1 byte");
|
||||
res = send(*ctx.fd, "x", 1, 0);
|
||||
res = zsock_send(*ctx.fd, "x", 1, 0);
|
||||
if (-1 == res) {
|
||||
LOG_DBG("send() failed: %d", errno);
|
||||
} else {
|
||||
|
@ -225,7 +225,7 @@ static void rw_fun(struct k_work *w)
|
|||
}
|
||||
} else {
|
||||
LOG_DBG("about to read 1 byte");
|
||||
res = recv(*ctx.fd, &c, 1, 0);
|
||||
res = zsock_recv(*ctx.fd, &c, 1, 0);
|
||||
if (-1 == res) {
|
||||
LOG_DBG("recv() failed: %d", errno);
|
||||
} else {
|
||||
|
@ -242,11 +242,11 @@ static void rw_fun(struct k_work *w)
|
|||
ZTEST_F(net_socketpair, test_poll_delayed_data)
|
||||
{
|
||||
int res;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLIN;
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.fd = &fixture->sv[1];
|
||||
|
@ -257,19 +257,19 @@ ZTEST_F(net_socketpair, test_poll_delayed_data)
|
|||
k_work_init(&work, rw_fun);
|
||||
k_work_submit(&work);
|
||||
|
||||
res = poll(fds, 1, 5000);
|
||||
res = zsock_poll(fds, 1, 5000);
|
||||
zassert_not_equal(res, -1, "poll() failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLIN, 0, "POLLIN not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, 0, "POLLIN not set");
|
||||
|
||||
for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) {
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_equal(res, 1, "send() failed: %d", res);
|
||||
}
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.fd = &fixture->sv[1];
|
||||
|
@ -280,10 +280,10 @@ ZTEST_F(net_socketpair, test_poll_delayed_data)
|
|||
k_work_init(&work, rw_fun);
|
||||
k_work_submit(&work);
|
||||
|
||||
res = poll(fds, 1, 5000);
|
||||
res = zsock_poll(fds, 1, 5000);
|
||||
zassert_not_equal(res, -1, "poll() failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll(): expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLOUT, 0, "POLLOUT was not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT was not set");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -298,42 +298,42 @@ ZTEST_USER_F(net_socketpair, test_poll_signalling_POLLIN)
|
|||
int res;
|
||||
char c;
|
||||
int64_t timestamp, delta;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[1];
|
||||
fds[0].events |= POLLIN;
|
||||
res = poll(fds, 1, 0);
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
res = zsock_poll(fds, 1, 0);
|
||||
zassert_not_equal(res, -1, "poll failed: %d", errno);
|
||||
zassert_equal(res, 0, "poll: expected: 0 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLIN, POLLIN, "POLLIN set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, ZSOCK_POLLIN, "POLLIN set");
|
||||
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_equal(res, 1, "send failed: %d", res);
|
||||
|
||||
timestamp = k_uptime_get();
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[1];
|
||||
fds[0].events |= POLLIN;
|
||||
res = poll(fds, 1, 1000);
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
res = zsock_poll(fds, 1, 1000);
|
||||
zassert_not_equal(res, -1, "poll failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll: expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLIN, 0, "POLLIN not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, 0, "POLLIN not set");
|
||||
|
||||
delta = k_uptime_delta(×tamp);
|
||||
zassert_true(delta < 100, "poll did not exit immediately");
|
||||
|
||||
res = recv(fixture->sv[1], &c, 1, 0);
|
||||
res = zsock_recv(fixture->sv[1], &c, 1, 0);
|
||||
zassert_equal(res, 1, "recv failed: %d", res);
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[1];
|
||||
fds[0].events |= POLLIN;
|
||||
res = poll(fds, 1, 0);
|
||||
fds[0].events |= ZSOCK_POLLIN;
|
||||
res = zsock_poll(fds, 1, 0);
|
||||
zassert_not_equal(res, -1, "poll failed: %d", errno);
|
||||
zassert_equal(res, 0, "poll: expected: 0 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLIN, POLLIN, "POLLIN set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLIN, ZSOCK_POLLIN, "POLLIN set");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -348,47 +348,47 @@ ZTEST_USER_F(net_socketpair, test_poll_signalling_POLLOUT)
|
|||
int res;
|
||||
char c;
|
||||
int64_t timestamp, delta;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
timestamp = k_uptime_get();
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
res = poll(fds, 1, 1000);
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
res = zsock_poll(fds, 1, 1000);
|
||||
zassert_not_equal(res, -1, "poll failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll: expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLOUT, 0, "POLLOUT not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set");
|
||||
|
||||
delta = k_uptime_delta(×tamp);
|
||||
zassert_true(delta < 100, "poll did not exit immediately");
|
||||
|
||||
/* Fill up the remote buffer */
|
||||
for (size_t i = 0; i < CONFIG_NET_SOCKETPAIR_BUFFER_SIZE; ++i) {
|
||||
res = send(fixture->sv[0], "x", 1, 0);
|
||||
res = zsock_send(fixture->sv[0], "x", 1, 0);
|
||||
zassert_equal(res, 1, "send() failed: %d", res);
|
||||
}
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
res = poll(fds, 1, 0);
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
res = zsock_poll(fds, 1, 0);
|
||||
zassert_not_equal(res, -1, "poll failed: %d", errno);
|
||||
zassert_equal(res, 0, "poll: expected: 0 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLOUT, POLLOUT, "POLLOUT is set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, ZSOCK_POLLOUT, "POLLOUT is set");
|
||||
|
||||
res = recv(fixture->sv[1], &c, 1, 0);
|
||||
res = zsock_recv(fixture->sv[1], &c, 1, 0);
|
||||
zassert_equal(res, 1, "recv() failed: %d", res);
|
||||
|
||||
timestamp = k_uptime_get();
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fixture->sv[0];
|
||||
fds[0].events |= POLLOUT;
|
||||
res = poll(fds, 1, 1000);
|
||||
fds[0].events |= ZSOCK_POLLOUT;
|
||||
res = zsock_poll(fds, 1, 1000);
|
||||
zassert_not_equal(res, -1, "poll failed: %d", errno);
|
||||
zassert_equal(res, 1, "poll: expected: 1 actual: %d", res);
|
||||
zassert_not_equal(fds[0].revents & POLLOUT, 0, "POLLOUT not set");
|
||||
zassert_not_equal(fds[0].revents & ZSOCK_POLLOUT, 0, "POLLOUT not set");
|
||||
|
||||
delta = k_uptime_delta(×tamp);
|
||||
zassert_true(delta < 100, "poll did not exit immediately");
|
||||
|
|
|
@ -16,25 +16,25 @@ ZTEST_USER_F(net_socketpair, test_unsupported_calls)
|
|||
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
|
||||
res = bind(fixture->sv[i], (struct sockaddr *)&addr, len);
|
||||
res = zsock_bind(fixture->sv[i], (struct sockaddr *)&addr, len);
|
||||
zassert_equal(res, -1,
|
||||
"bind should fail on a socketpair endpoint");
|
||||
zassert_equal(errno, EISCONN,
|
||||
"bind should set errno to EISCONN");
|
||||
|
||||
res = connect(fixture->sv[i], (struct sockaddr *)&addr, len);
|
||||
res = zsock_connect(fixture->sv[i], (struct sockaddr *)&addr, len);
|
||||
zassert_equal(res, -1,
|
||||
"connect should fail on a socketpair endpoint");
|
||||
zassert_equal(errno, EISCONN,
|
||||
"connect should set errno to EISCONN");
|
||||
|
||||
res = listen(fixture->sv[i], 1);
|
||||
res = zsock_listen(fixture->sv[i], 1);
|
||||
zassert_equal(res, -1,
|
||||
"listen should fail on a socketpair endpoint");
|
||||
zassert_equal(errno, EINVAL,
|
||||
"listen should set errno to EINVAL");
|
||||
|
||||
res = accept(fixture->sv[i], (struct sockaddr *)&addr, &len);
|
||||
res = zsock_accept(fixture->sv[i], (struct sockaddr *)&addr, &len);
|
||||
zassert_equal(res, -1,
|
||||
"accept should fail on a socketpair endpoint");
|
||||
zassert_equal(errno, EOPNOTSUPP,
|
||||
|
|
|
@ -11,7 +11,6 @@ CONFIG_NET_IPV6=y
|
|||
CONFIG_NET_IPV6_ND=n
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_POSIX_MAX_FDS=10
|
||||
|
||||
# Network driver config
|
||||
|
|
|
@ -36,21 +36,21 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
|
|||
|
||||
static void test_bind(int sock, struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(bind(sock, addr, addrlen),
|
||||
zassert_equal(zsock_bind(sock, addr, addrlen),
|
||||
0,
|
||||
"bind failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_listen(int sock)
|
||||
{
|
||||
zassert_equal(listen(sock, MAX_CONNS),
|
||||
zassert_equal(zsock_listen(sock, MAX_CONNS),
|
||||
0,
|
||||
"listen failed with error %d", errno);
|
||||
}
|
||||
|
||||
static void test_connect(int sock, struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(connect(sock, addr, addrlen),
|
||||
zassert_equal(zsock_connect(sock, addr, addrlen),
|
||||
0,
|
||||
"connect failed with error %d", errno);
|
||||
|
||||
|
@ -62,7 +62,7 @@ static void test_connect(int sock, struct sockaddr *addr, socklen_t addrlen)
|
|||
|
||||
static void test_send(int sock, const void *buf, size_t len, int flags)
|
||||
{
|
||||
zassert_equal(send(sock, buf, len, flags),
|
||||
zassert_equal(zsock_send(sock, buf, len, flags),
|
||||
len,
|
||||
"send failed");
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ static void test_send(int sock, const void *buf, size_t len, int flags)
|
|||
static void test_sendto(int sock, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(sendto(sock, buf, len, flags, addr, addrlen),
|
||||
zassert_equal(zsock_sendto(sock, buf, len, flags, addr, addrlen),
|
||||
len,
|
||||
"send failed");
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ static void test_accept(int sock, int *new_sock, struct sockaddr *addr,
|
|||
{
|
||||
zassert_not_null(new_sock, "null newsock");
|
||||
|
||||
*new_sock = accept(sock, addr, addrlen);
|
||||
*new_sock = zsock_accept(sock, addr, addrlen);
|
||||
zassert_true(*new_sock >= 0, "accept failed");
|
||||
}
|
||||
|
||||
|
@ -89,14 +89,14 @@ static void test_accept_timeout(int sock, int *new_sock, struct sockaddr *addr,
|
|||
{
|
||||
zassert_not_null(new_sock, "null newsock");
|
||||
|
||||
*new_sock = accept(sock, addr, addrlen);
|
||||
*new_sock = zsock_accept(sock, addr, addrlen);
|
||||
zassert_equal(*new_sock, -1, "accept succeed");
|
||||
zassert_equal(errno, EAGAIN, "");
|
||||
}
|
||||
|
||||
static void test_fcntl(int sock, int cmd, int val)
|
||||
{
|
||||
zassert_equal(fcntl(sock, cmd, val), 0, "fcntl failed");
|
||||
zassert_equal(zsock_fcntl(sock, cmd, val), 0, "fcntl failed");
|
||||
}
|
||||
|
||||
static void test_recv(int sock, int flags)
|
||||
|
@ -104,7 +104,7 @@ static void test_recv(int sock, int flags)
|
|||
ssize_t recved = 0;
|
||||
char rx_buf[30] = {0};
|
||||
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), flags);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), flags);
|
||||
zassert_equal(recved,
|
||||
strlen(TEST_STR_SMALL),
|
||||
"unexpected received bytes");
|
||||
|
@ -121,12 +121,7 @@ static void test_recvfrom(int sock,
|
|||
ssize_t recved = 0;
|
||||
char rx_buf[30] = {0};
|
||||
|
||||
recved = recvfrom(sock,
|
||||
rx_buf,
|
||||
sizeof(rx_buf),
|
||||
flags,
|
||||
addr,
|
||||
addrlen);
|
||||
recved = zsock_recvfrom(sock, rx_buf, sizeof(rx_buf), flags, addr, addrlen);
|
||||
zassert_equal(recved,
|
||||
strlen(TEST_STR_SMALL),
|
||||
"unexpected received bytes");
|
||||
|
@ -143,7 +138,7 @@ static void test_recvmsg(int sock,
|
|||
{
|
||||
ssize_t recved;
|
||||
|
||||
recved = recvmsg(sock, msg, flags);
|
||||
recved = zsock_recvmsg(sock, msg, flags);
|
||||
|
||||
zassert_equal(recved, expected,
|
||||
"line %d, unexpected received bytes (%d vs %d)",
|
||||
|
@ -152,14 +147,14 @@ static void test_recvmsg(int sock,
|
|||
|
||||
static void test_shutdown(int sock, int how)
|
||||
{
|
||||
zassert_equal(shutdown(sock, how),
|
||||
zassert_equal(zsock_shutdown(sock, how),
|
||||
0,
|
||||
"shutdown failed");
|
||||
}
|
||||
|
||||
static void test_close(int sock)
|
||||
{
|
||||
zassert_equal(close(sock),
|
||||
zassert_equal(zsock_close(sock),
|
||||
0,
|
||||
"close failed");
|
||||
}
|
||||
|
@ -173,16 +168,16 @@ static void test_eof(int sock)
|
|||
ssize_t recved;
|
||||
|
||||
/* Test that EOF properly detected. */
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(recved, 0, "");
|
||||
|
||||
/* Calling again should be OK. */
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(recved, 0, "");
|
||||
|
||||
/* Calling when TCP connection is fully torn down should be still OK. */
|
||||
k_sleep(TCP_TEARDOWN_TIMEOUT);
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(recved, 0, "");
|
||||
}
|
||||
|
||||
|
@ -254,7 +249,7 @@ ZTEST_USER(net_socket_tcp, test_v4_send_recv)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
test_recv(new_sock, MSG_PEEK);
|
||||
test_recv(new_sock, ZSOCK_MSG_PEEK);
|
||||
test_recv(new_sock, 0);
|
||||
|
||||
test_close(c_sock);
|
||||
|
@ -289,7 +284,7 @@ ZTEST_USER(net_socket_tcp, test_v6_send_recv)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in6), "wrong addrlen");
|
||||
|
||||
test_recv(new_sock, MSG_PEEK);
|
||||
test_recv(new_sock, ZSOCK_MSG_PEEK);
|
||||
test_recv(new_sock, 0);
|
||||
|
||||
test_close(c_sock);
|
||||
|
@ -337,7 +332,7 @@ void tcp_server_block_thread(void *vps_sock, void *unused2, void *unused3)
|
|||
chunk_size = remain;
|
||||
}
|
||||
|
||||
recved = recv(new_sock, buffer, chunk_size, 0);
|
||||
recved = zsock_recv(new_sock, buffer, chunk_size, 0);
|
||||
|
||||
zassert(recved > 0, "received bigger then 0",
|
||||
"Error receiving bytes %i bytes, got %i on top of %i in iteration %i, errno %i",
|
||||
|
@ -399,7 +394,7 @@ void test_send_recv_large_common(int tcp_nodelay, int family)
|
|||
|
||||
test_connect(c_sock, s_saddr, addrlen);
|
||||
|
||||
rv = setsockopt(c_sock, IPPROTO_TCP, TCP_NODELAY, (char *) &tcp_nodelay, sizeof(int));
|
||||
rv = zsock_setsockopt(c_sock, IPPROTO_TCP, TCP_NODELAY, (char *) &tcp_nodelay, sizeof(int));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", rv);
|
||||
|
||||
/* send piece by piece */
|
||||
|
@ -422,7 +417,7 @@ void test_send_recv_large_common(int tcp_nodelay, int family)
|
|||
chunk_size = remain;
|
||||
}
|
||||
|
||||
int send_bytes = send(c_sock, buffer, chunk_size, 0);
|
||||
int send_bytes = zsock_send(c_sock, buffer, chunk_size, 0);
|
||||
|
||||
zassert(send_bytes > 0, "send_bytes bigger then 0",
|
||||
"Error sending %i bytes on top of %i, got %i in iteration %i, errno %i",
|
||||
|
@ -531,11 +526,11 @@ ZTEST(net_socket_tcp, test_v4_broken_link)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
rv = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
test_recv(new_sock, MSG_PEEK);
|
||||
test_recv(new_sock, ZSOCK_MSG_PEEK);
|
||||
test_recv(new_sock, 0);
|
||||
|
||||
/* At this point break the interface */
|
||||
|
@ -548,7 +543,7 @@ ZTEST(net_socket_tcp, test_v4_broken_link)
|
|||
start_time = k_uptime_get_32();
|
||||
|
||||
/* Test the loopback packet loss: message should never arrive */
|
||||
recved = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(recved, -1, "Unexpected return code");
|
||||
|
@ -557,7 +552,7 @@ ZTEST(net_socket_tcp, test_v4_broken_link)
|
|||
"was %dms", time_diff);
|
||||
|
||||
/* Reading from client should indicate the socket has been closed */
|
||||
recved = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(recved, -1, "Unexpected return code");
|
||||
zassert_equal(errno, ETIMEDOUT, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -603,7 +598,7 @@ ZTEST_USER(net_socket_tcp, test_v4_sendto_recvfrom)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
test_recvfrom(new_sock, MSG_PEEK, &addr, &addrlen);
|
||||
test_recvfrom(new_sock, ZSOCK_MSG_PEEK, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
test_recvfrom(new_sock, 0, &addr, &addrlen);
|
||||
|
@ -640,7 +635,7 @@ ZTEST_USER(net_socket_tcp, test_v6_sendto_recvfrom)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in6), "wrong addrlen");
|
||||
|
||||
test_recvfrom(new_sock, MSG_PEEK, &addr, &addrlen);
|
||||
test_recvfrom(new_sock, ZSOCK_MSG_PEEK, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in6), "wrong addrlen");
|
||||
|
||||
test_recvfrom(new_sock, 0, &addr, &addrlen);
|
||||
|
@ -760,7 +755,7 @@ ZTEST_USER(net_socket_tcp, test_v4_sendto_recvmsg)
|
|||
msg.msg_name = &addr;
|
||||
msg.msg_namelen = addrlen;
|
||||
|
||||
test_recvmsg(new_sock, &msg, MSG_PEEK, strlen(TEST_STR_SMALL),
|
||||
test_recvmsg(new_sock, &msg, ZSOCK_MSG_PEEK, strlen(TEST_STR_SMALL),
|
||||
__LINE__);
|
||||
zassert_mem_equal(buf, TEST_STR_SMALL, strlen(TEST_STR_SMALL),
|
||||
"wrong data (%s)", buf);
|
||||
|
@ -832,13 +827,13 @@ void _test_recv_enotconn(int c_sock, int s_sock)
|
|||
test_listen(s_sock);
|
||||
|
||||
/* Check "client" socket, just created. */
|
||||
res = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
res = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(res, -1, "recv() on not connected sock didn't fail");
|
||||
zassert_equal(errno, ENOTCONN, "recv() on not connected sock didn't "
|
||||
"lead to ENOTCONN");
|
||||
|
||||
/* Check "server" socket, bound and listen()ed . */
|
||||
res = recv(s_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
res = zsock_recv(s_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(res, -1, "recv() on not connected sock didn't fail");
|
||||
zassert_equal(errno, ENOTCONN, "recv() on not connected sock didn't "
|
||||
"lead to ENOTCONN");
|
||||
|
@ -928,7 +923,7 @@ static void shutdown_work(struct k_work *work)
|
|||
struct shutdown_data *data = CONTAINER_OF(dwork, struct shutdown_data,
|
||||
work);
|
||||
|
||||
shutdown(data->fd, data->how);
|
||||
zsock_shutdown(data->fd, data->how);
|
||||
}
|
||||
|
||||
ZTEST(net_socket_tcp, test_shutdown_rd_while_recv)
|
||||
|
@ -1000,8 +995,8 @@ ZTEST(net_socket_tcp, test_open_close_immediately)
|
|||
*/
|
||||
s_saddr.sin_port = htons(SERVER_PORT + 1);
|
||||
|
||||
zassert_not_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
zassert_not_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
0, "connect succeed");
|
||||
|
||||
test_close(c_sock);
|
||||
|
@ -1051,9 +1046,9 @@ ZTEST(net_socket_tcp, test_connect_timeout)
|
|||
|
||||
loopback_set_packet_drop_ratio(1.0f);
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
-1, "connect succeed");
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
-1, "connect succeed");
|
||||
|
||||
zassert_equal(errno, ETIMEDOUT,
|
||||
"connect should be timed out, got %i", errno);
|
||||
|
@ -1087,7 +1082,7 @@ ZTEST(net_socket_tcp, test_async_connect_timeout)
|
|||
struct sockaddr_in s_saddr;
|
||||
int c_sock;
|
||||
int rv;
|
||||
struct pollfd poll_fds[POLL_FDS_NUM];
|
||||
struct zsock_pollfd poll_fds[POLL_FDS_NUM];
|
||||
|
||||
loopback_set_packet_drop_ratio(1.0f);
|
||||
|
||||
|
@ -1098,18 +1093,18 @@ ZTEST(net_socket_tcp, test_async_connect_timeout)
|
|||
rv = zsock_inet_pton(AF_INET, MY_IPV4_ADDR, &s_saddr.sin_addr);
|
||||
zassert_equal(rv, 1, "inet_pton failed");
|
||||
|
||||
rv = connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr));
|
||||
rv = zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr));
|
||||
zassert_equal(rv, -1, "connect should not succeed");
|
||||
zassert_equal(errno, EINPROGRESS,
|
||||
"connect should be in progress, got %i", errno);
|
||||
|
||||
poll_fds[0].fd = c_sock;
|
||||
poll_fds[0].events = POLLOUT;
|
||||
int poll_rc = poll(poll_fds, POLL_FDS_NUM, ASYNC_POLL_TIMEOUT);
|
||||
poll_fds[0].events = ZSOCK_POLLOUT;
|
||||
int poll_rc = zsock_poll(poll_fds, POLL_FDS_NUM, ASYNC_POLL_TIMEOUT);
|
||||
|
||||
zassert_equal(poll_rc, 1, "poll should return 1, got %i", poll_rc);
|
||||
zassert_equal(poll_fds[0].revents, POLLERR,
|
||||
zassert_equal(poll_fds[0].revents, ZSOCK_POLLERR,
|
||||
"poll should set error event");
|
||||
|
||||
test_close(c_sock);
|
||||
|
@ -1128,7 +1123,7 @@ ZTEST(net_socket_tcp, test_async_connect)
|
|||
struct sockaddr_in s_saddr;
|
||||
struct sockaddr addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
struct pollfd poll_fds[1];
|
||||
struct zsock_pollfd poll_fds[1];
|
||||
int poll_rc;
|
||||
|
||||
prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &c_sock, &c_saddr);
|
||||
|
@ -1138,7 +1133,7 @@ ZTEST(net_socket_tcp, test_async_connect)
|
|||
test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr));
|
||||
test_listen(s_sock);
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)),
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)),
|
||||
-1,
|
||||
"connect shouldn't complete right away");
|
||||
|
||||
|
@ -1146,10 +1141,10 @@ ZTEST(net_socket_tcp, test_async_connect)
|
|||
"connect should be in progress, got %i", errno);
|
||||
|
||||
poll_fds[0].fd = c_sock;
|
||||
poll_fds[0].events = POLLOUT;
|
||||
poll_rc = poll(poll_fds, 1, ASYNC_POLL_TIMEOUT);
|
||||
poll_fds[0].events = ZSOCK_POLLOUT;
|
||||
poll_rc = zsock_poll(poll_fds, 1, ASYNC_POLL_TIMEOUT);
|
||||
zassert_equal(poll_rc, 1, "poll should return 1, got %i", poll_rc);
|
||||
zassert_equal(poll_fds[0].revents, POLLOUT,
|
||||
zassert_equal(poll_fds[0].revents, ZSOCK_POLLOUT,
|
||||
"poll should set POLLOUT");
|
||||
|
||||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
|
@ -1188,9 +1183,9 @@ ZTEST(net_socket_tcp, test_z_close_obstructed)
|
|||
test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr));
|
||||
test_listen(s_sock);
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
0, "connect not succeed");
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
0, "connect not succeed");
|
||||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
|
||||
/* We should have two contexts open now */
|
||||
|
@ -1277,12 +1272,12 @@ ZTEST(net_socket_tcp, test_so_type)
|
|||
prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &sock1, &bind_addr4);
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, ANY_PORT, &sock2, &bind_addr6);
|
||||
|
||||
rv = getsockopt(sock1, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock1, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, SOCK_STREAM, "getsockopt got invalid type");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
rv = getsockopt(sock2, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock2, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, SOCK_STREAM, "getsockopt got invalid type");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
@ -1306,12 +1301,12 @@ ZTEST(net_socket_tcp, test_so_protocol)
|
|||
prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &sock1, &bind_addr4);
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, ANY_PORT, &sock2, &bind_addr6);
|
||||
|
||||
rv = getsockopt(sock1, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock1, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, IPPROTO_TCP, "getsockopt got invalid protocol");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
rv = getsockopt(sock2, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock2, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, IPPROTO_TCP, "getsockopt got invalid protocol");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
@ -1334,26 +1329,26 @@ ZTEST(net_socket_tcp, test_so_rcvbuf)
|
|||
prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &sock1, &bind_addr4);
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, ANY_PORT, &sock2, &bind_addr6);
|
||||
|
||||
rv = setsockopt(sock1, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
rv = zsock_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);
|
||||
rv = zsock_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));
|
||||
rv = zsock_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);
|
||||
rv = zsock_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));
|
||||
rv = zsock_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));
|
||||
rv = zsock_setsockopt(sock2, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
zassert_equal(rv, -1, "setsockopt failed (%d)", rv);
|
||||
|
||||
test_close(sock1);
|
||||
|
@ -1387,11 +1382,11 @@ ZTEST(net_socket_tcp, test_so_rcvbuf_win_size)
|
|||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
/* Lower server-side RX window size. */
|
||||
rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
rv = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT);
|
||||
rv = zsock_send(c_sock, tx_buf, sizeof(tx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv);
|
||||
|
||||
/* Window should've dropped to 0, so the ACK will be delayed - wait for
|
||||
|
@ -1400,7 +1395,7 @@ ZTEST(net_socket_tcp, test_so_rcvbuf_win_size)
|
|||
k_msleep(150);
|
||||
|
||||
/* Client should not be able to send now (RX window full). */
|
||||
rv = send(c_sock, tx_buf, 1, MSG_DONTWAIT);
|
||||
rv = zsock_send(c_sock, tx_buf, 1, ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, -1, "Unexpected return code %d", rv);
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1423,26 +1418,26 @@ ZTEST(net_socket_tcp, test_so_sndbuf)
|
|||
prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &sock1, &bind_addr4);
|
||||
prepare_sock_tcp_v6(MY_IPV6_ADDR, ANY_PORT, &sock2, &bind_addr6);
|
||||
|
||||
rv = setsockopt(sock1, SOL_SOCKET, SO_SNDBUF, &optval, sizeof(optval));
|
||||
rv = zsock_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);
|
||||
rv = zsock_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));
|
||||
rv = zsock_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);
|
||||
rv = zsock_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));
|
||||
rv = zsock_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));
|
||||
rv = zsock_setsockopt(sock2, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
|
||||
zassert_equal(rv, -1, "setsockopt failed (%d)", rv);
|
||||
|
||||
test_close(sock1);
|
||||
|
@ -1468,8 +1463,8 @@ ZTEST(net_socket_tcp, test_so_sndbuf_win_size)
|
|||
prepare_sock_tcp_v4(MY_IPV4_ADDR, SERVER_PORT, &s_sock, &s_saddr);
|
||||
|
||||
/* Lower client-side TX window size. */
|
||||
rv = setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
rv = zsock_setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr));
|
||||
|
@ -1483,11 +1478,11 @@ ZTEST(net_socket_tcp, test_so_sndbuf_win_size)
|
|||
/* Make sure the ACK from the server does not arrive. */
|
||||
loopback_set_packet_drop_ratio(1.0f);
|
||||
|
||||
rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT);
|
||||
rv = zsock_send(c_sock, tx_buf, sizeof(tx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv);
|
||||
|
||||
/* Client should not be able to send now (TX window full). */
|
||||
rv = send(c_sock, tx_buf, 1, MSG_DONTWAIT);
|
||||
rv = zsock_send(c_sock, tx_buf, 1, ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, -1, "Unexpected return code %d", rv);
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1531,17 +1526,17 @@ ZTEST(net_socket_tcp, test_v4_so_rcvtimeo)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
rv = setsockopt(c_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
rv = zsock_setsockopt(c_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval.tv_usec = 0;
|
||||
rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
rv = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
start_time = k_uptime_get_32();
|
||||
recved = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(recved, -1, "Unexpected return code");
|
||||
|
@ -1550,7 +1545,7 @@ ZTEST(net_socket_tcp, test_v4_so_rcvtimeo)
|
|||
"was %dms", time_diff);
|
||||
|
||||
start_time = k_uptime_get_32();
|
||||
recved = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(recved, -1, "Unexpected return code");
|
||||
|
@ -1598,17 +1593,17 @@ ZTEST(net_socket_tcp, test_v6_so_rcvtimeo)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in6), "wrong addrlen");
|
||||
|
||||
rv = setsockopt(c_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
rv = zsock_setsockopt(c_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval.tv_usec = 0;
|
||||
rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
rv = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
start_time = k_uptime_get_32();
|
||||
recved = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(recved, -1, "Unexpected return code");
|
||||
|
@ -1617,7 +1612,7 @@ ZTEST(net_socket_tcp, test_v6_so_rcvtimeo)
|
|||
"was %dms", time_diff);
|
||||
|
||||
start_time = k_uptime_get_32();
|
||||
recved = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(recved, -1, "Unexpected return code");
|
||||
|
@ -1663,16 +1658,16 @@ ZTEST(net_socket_tcp, test_v4_so_sndtimeo)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen");
|
||||
|
||||
rv = setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
rv = zsock_setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Simulate window full scenario with SO_RCVBUF option. */
|
||||
rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
rv = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT);
|
||||
rv = zsock_send(c_sock, tx_buf, sizeof(tx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv);
|
||||
|
||||
/* Wait for ACK (empty window). */
|
||||
|
@ -1680,7 +1675,7 @@ ZTEST(net_socket_tcp, test_v4_so_sndtimeo)
|
|||
|
||||
/* Client should not be able to send now and time out after SO_SNDTIMEO */
|
||||
start_time = k_uptime_get_32();
|
||||
rv = send(c_sock, tx_buf, 1, 0);
|
||||
rv = zsock_send(c_sock, tx_buf, 1, 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(rv, -1, "Unexpected return code %d", rv);
|
||||
|
@ -1724,16 +1719,16 @@ ZTEST(net_socket_tcp, test_v6_so_sndtimeo)
|
|||
test_accept(s_sock, &new_sock, &addr, &addrlen);
|
||||
zassert_equal(addrlen, sizeof(struct sockaddr_in6), "wrong addrlen");
|
||||
|
||||
rv = setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
rv = zsock_setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Simulate window full scenario with SO_RCVBUF option. */
|
||||
rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
rv = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(rv, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT);
|
||||
rv = zsock_send(c_sock, tx_buf, sizeof(tx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv);
|
||||
|
||||
/* Wait for ACK (empty window). */
|
||||
|
@ -1741,7 +1736,7 @@ ZTEST(net_socket_tcp, test_v6_so_sndtimeo)
|
|||
|
||||
/* Client should not be able to send now and time out after SO_SNDTIMEO */
|
||||
start_time = k_uptime_get_32();
|
||||
rv = send(c_sock, tx_buf, 1, 0);
|
||||
rv = zsock_send(c_sock, tx_buf, 1, 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(rv, -1, "Unexpected return code %d", rv);
|
||||
|
@ -1819,7 +1814,7 @@ ZTEST(net_socket_tcp, test_v4_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
k_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf), "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf),
|
||||
"Invalid data received");
|
||||
|
@ -1828,8 +1823,8 @@ ZTEST(net_socket_tcp, test_v4_msg_waitall)
|
|||
/* MSG_WAITALL + SO_RCVTIMEO - make sure recv returns the amount of data
|
||||
* received so far
|
||||
*/
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
|
@ -1840,7 +1835,7 @@ ZTEST(net_socket_tcp, test_v4_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
k_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf) - 1, MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf) - 1, ZSOCK_MSG_WAITALL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("receive return val %i", ret);
|
||||
}
|
||||
|
@ -1896,7 +1891,7 @@ ZTEST(net_socket_tcp, test_v6_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
k_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf), "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf),
|
||||
"Invalid data received");
|
||||
|
@ -1905,8 +1900,8 @@ ZTEST(net_socket_tcp, test_v6_msg_waitall)
|
|||
/* MSG_WAITALL + SO_RCVTIMEO - make sure recv returns the amount of data
|
||||
* received so far
|
||||
*/
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
|
@ -1917,7 +1912,7 @@ ZTEST(net_socket_tcp, test_v6_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
k_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf) - 1, MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf) - 1, ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf) - 1, "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf) - 1,
|
||||
"Invalid data received");
|
||||
|
@ -1940,7 +1935,7 @@ static void child_entry(void *p1, void *p2, void *p3)
|
|||
{
|
||||
int sock = POINTER_TO_INT(p1);
|
||||
|
||||
result = close(sock);
|
||||
result = zsock_close(sock);
|
||||
}
|
||||
|
||||
static void spawn_child(int sock)
|
||||
|
@ -2016,7 +2011,7 @@ static void close_work(struct k_work *work)
|
|||
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
|
||||
struct close_data *data = CONTAINER_OF(dwork, struct close_data, work);
|
||||
|
||||
close(data->fd);
|
||||
zsock_close(data->fd);
|
||||
}
|
||||
|
||||
ZTEST(net_socket_tcp, test_close_while_recv)
|
||||
|
@ -2053,7 +2048,7 @@ ZTEST(net_socket_tcp, test_close_while_recv)
|
|||
/* Start blocking recv(), which should be unblocked by close() from
|
||||
* another thread and return an error.
|
||||
*/
|
||||
ret = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv did not return error");
|
||||
zassert_equal(errno, EINTR, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -2088,7 +2083,7 @@ ZTEST(net_socket_tcp, test_close_while_accept)
|
|||
/* Start blocking accept(), which should be unblocked by close() from
|
||||
* another thread and return an error.
|
||||
*/
|
||||
new_sock = accept(s_sock, &addr, &addrlen);
|
||||
new_sock = zsock_accept(s_sock, &addr, &addrlen);
|
||||
zassert_equal(new_sock, -1, "accept did not return error");
|
||||
zassert_equal(errno, EINTR, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -2164,7 +2159,7 @@ static void test_ioctl_fionread_common(int af)
|
|||
/* both ends should have zero bytes available after being newly created */
|
||||
for (enum fde i = SERVER; i <= CLIENT; ++i) {
|
||||
avail = 42;
|
||||
zassert_ok(ioctl(fd[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_ok(zsock_ioctl(fd[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_equal(0, avail, "exp: %d: act: %d", 0, avail);
|
||||
}
|
||||
|
||||
|
@ -2175,7 +2170,7 @@ static void test_ioctl_fionread_common(int af)
|
|||
zassert_equal(1, write(fd[i], "\x42", 1));
|
||||
zassert_equal(1, write(fd[i], "\x73", 1));
|
||||
k_msleep(100);
|
||||
zassert_ok(ioctl(fd[j], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_ok(zsock_ioctl(fd[j], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_equal(ARRAY_SIZE(bytes), avail, "exp: %d: act: %d", ARRAY_SIZE(bytes),
|
||||
avail);
|
||||
}
|
||||
|
@ -2186,13 +2181,13 @@ static void test_ioctl_fionread_common(int af)
|
|||
int act = read(fd[i], bytes, ARRAY_SIZE(bytes));
|
||||
|
||||
zassert_equal(ex, act, "read() failed: errno: %d exp: %d act: %d", errno, ex, act);
|
||||
zassert_ok(ioctl(fd[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_ok(zsock_ioctl(fd[i], ZFD_IOCTL_FIONREAD, &avail));
|
||||
zassert_equal(0, avail, "exp: %d: act: %d", 0, avail);
|
||||
}
|
||||
|
||||
close(fd[SERVER]);
|
||||
close(fd[CLIENT]);
|
||||
close(fd[ACCEPT]);
|
||||
zsock_close(fd[SERVER]);
|
||||
zsock_close(fd[CLIENT]);
|
||||
zsock_close(fd[ACCEPT]);
|
||||
|
||||
test_context_cleanup();
|
||||
}
|
||||
|
@ -2217,12 +2212,12 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_select)
|
|||
int fd, flags, ret, optval;
|
||||
socklen_t optlen = sizeof(optval);
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
fd = zsock_socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
flags = fcntl(fd, F_GETFL, 0);
|
||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
flags = zsock_fcntl(fd, F_GETFL, 0);
|
||||
zsock_fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
inet_pton(AF_INET, "127.0.0.1", (void *)&v4addr);
|
||||
zsock_inet_pton(AF_INET, "127.0.0.1", (void *)&v4addr);
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
net_ipaddr_copy(&addr.sin_addr, &v4addr);
|
||||
|
@ -2230,29 +2225,29 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_select)
|
|||
/* There should be nobody serving this port */
|
||||
addr.sin_port = htons(8088);
|
||||
|
||||
ret = connect(fd, (const struct sockaddr *)&addr, sizeof(addr));
|
||||
ret = zsock_connect(fd, (const struct sockaddr *)&addr, sizeof(addr));
|
||||
zassert_equal(ret, -1, "connect succeed, %d", errno);
|
||||
zassert_equal(errno, EINPROGRESS, "connect succeed, %d", errno);
|
||||
|
||||
/* Wait for the connection (this should fail eventually) */
|
||||
while (1) {
|
||||
fd_set wfds;
|
||||
zsock_fd_set wfds;
|
||||
struct timeval tv = {
|
||||
.tv_sec = 1,
|
||||
.tv_usec = 0
|
||||
};
|
||||
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(fd, &wfds);
|
||||
ZSOCK_FD_ZERO(&wfds);
|
||||
ZSOCK_FD_SET(fd, &wfds);
|
||||
|
||||
/* Check if the connection is there, this should timeout */
|
||||
ret = select(fd + 1, NULL, &wfds, NULL, &tv);
|
||||
ret = zsock_select(fd + 1, NULL, &wfds, NULL, &tv);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret > 0) {
|
||||
if (FD_ISSET(fd, &wfds)) {
|
||||
if (ZSOCK_FD_ISSET(fd, &wfds)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2261,7 +2256,7 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_select)
|
|||
zassert_true(ret > 0, "select failed, %d", errno);
|
||||
|
||||
/* Get the reason for the connect */
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
ret = zsock_getsockopt(fd, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", errno);
|
||||
|
||||
/* If SO_ERROR is 0, then it means that connect succeed. Any
|
||||
|
@ -2269,7 +2264,7 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_select)
|
|||
*/
|
||||
zassert_equal(optval, ECONNREFUSED, "unexpected connect status, %d", optval);
|
||||
|
||||
ret = close(fd);
|
||||
ret = zsock_close(fd);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
}
|
||||
|
||||
|
@ -2280,18 +2275,18 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_select)
|
|||
ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_poll)
|
||||
{
|
||||
struct sockaddr_in addr = { 0 };
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
struct in_addr v4addr;
|
||||
int fd, flags, ret, optval;
|
||||
bool closed = false;
|
||||
socklen_t optlen = sizeof(optval);
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
fd = zsock_socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
flags = fcntl(fd, F_GETFL, 0);
|
||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
flags = zsock_fcntl(fd, F_GETFL, 0);
|
||||
zsock_fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
inet_pton(AF_INET, "127.0.0.1", (void *)&v4addr);
|
||||
zsock_inet_pton(AF_INET, "127.0.0.1", (void *)&v4addr);
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
net_ipaddr_copy(&addr.sin_addr, &v4addr);
|
||||
|
@ -2299,7 +2294,7 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_poll)
|
|||
/* There should be nobody serving this port */
|
||||
addr.sin_port = htons(8088);
|
||||
|
||||
ret = connect(fd, (const struct sockaddr *)&addr, sizeof(addr));
|
||||
ret = zsock_connect(fd, (const struct sockaddr *)&addr, sizeof(addr));
|
||||
zassert_equal(ret, -1, "connect succeed, %d", errno);
|
||||
zassert_equal(errno, EINPROGRESS, "connect succeed, %d", errno);
|
||||
|
||||
|
@ -2307,16 +2302,16 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_poll)
|
|||
while (1) {
|
||||
memset(fds, 0, sizeof(fds));
|
||||
fds[0].fd = fd;
|
||||
fds[0].events = POLLOUT;
|
||||
fds[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
/* Check if the connection is there, this should timeout */
|
||||
ret = poll(fds, 1, 10);
|
||||
ret = zsock_poll(fds, 1, 10);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (fds[0].revents > 0) {
|
||||
if (fds[0].revents & POLLERR) {
|
||||
if (fds[0].revents & ZSOCK_POLLERR) {
|
||||
closed = true;
|
||||
break;
|
||||
}
|
||||
|
@ -2326,7 +2321,7 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_poll)
|
|||
zassert_true(closed, "poll failed, %d", errno);
|
||||
|
||||
/* Get the reason for the connect */
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
ret = zsock_getsockopt(fd, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed, %d", errno);
|
||||
|
||||
/* If SO_ERROR is 0, then it means that connect succeed. Any
|
||||
|
@ -2334,7 +2329,7 @@ ZTEST(net_socket_tcp, test_connect_and_wait_for_v4_poll)
|
|||
*/
|
||||
zassert_equal(optval, ECONNREFUSED, "unexpected connect status, %d", optval);
|
||||
|
||||
ret = close(fd);
|
||||
ret = zsock_close(fd);
|
||||
zassert_equal(ret, 0, "close failed, %d", errno);
|
||||
}
|
||||
|
||||
|
@ -2348,36 +2343,36 @@ ZTEST(net_socket_tcp, test_so_keepalive)
|
|||
prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &sock, &bind_addr4);
|
||||
|
||||
/* Keep-alive should be disabled by default. */
|
||||
ret = getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, 0, "getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
/* Enable keep-alive. */
|
||||
optval = 1;
|
||||
ret = setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
ret = getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, 1, "getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
/* Check keep-alive parameters defaults. */
|
||||
ret = getsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, CONFIG_NET_TCP_KEEPIDLE_DEFAULT,
|
||||
"getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
ret = getsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, CONFIG_NET_TCP_KEEPINTVL_DEFAULT,
|
||||
"getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
ret = getsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, CONFIG_NET_TCP_KEEPCNT_DEFAULT,
|
||||
"getsockopt got invalid value");
|
||||
|
@ -2385,31 +2380,31 @@ ZTEST(net_socket_tcp, test_so_keepalive)
|
|||
|
||||
/* Check keep-alive parameters update. */
|
||||
optval = 123;
|
||||
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval = 10;
|
||||
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval = 2;
|
||||
ret = setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
ret = getsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, 123, "getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
ret = getsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, 10, "getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
ret = getsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &optval, &optlen);
|
||||
ret = zsock_getsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, 2, "getsockopt got invalid value");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
@ -2432,35 +2427,35 @@ ZTEST(net_socket_tcp, test_keepalive_timeout)
|
|||
|
||||
/* Enable keep-alive on both ends and set timeouts/retries to minimum */
|
||||
optval = 1;
|
||||
ret = setsockopt(c_sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(c_sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
ret = setsockopt(s_sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(s_sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval = 1;
|
||||
ret = setsockopt(c_sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(c_sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
ret = setsockopt(s_sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(s_sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval = 1;
|
||||
ret = setsockopt(c_sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(c_sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
ret = setsockopt(s_sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(s_sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
optval = 1;
|
||||
ret = setsockopt(c_sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(c_sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
ret = setsockopt(s_sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
&optval, sizeof(optval));
|
||||
ret = zsock_setsockopt(s_sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
&optval, sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Establish connection */
|
||||
|
@ -2474,12 +2469,12 @@ ZTEST(net_socket_tcp, test_keepalive_timeout)
|
|||
*/
|
||||
loopback_set_packet_drop_ratio(1.0f);
|
||||
|
||||
ret = recv(c_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(c_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, ETIMEDOUT, "wrong errno value, %d", errno);
|
||||
|
||||
/* Same on the other end. */
|
||||
ret = recv(new_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, ETIMEDOUT, "wrong errno value, %d", errno);
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ CONFIG_NET_IPV6=y
|
|||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
|
||||
CONFIG_NET_SOCKETS_ENABLE_DTLS=y
|
||||
CONFIG_NET_SOCKETS_DTLS_SENDMSG_BUF_SIZE=128
|
||||
|
|
|
@ -73,13 +73,13 @@ static void test_config_psk(int s_sock, int c_sock)
|
|||
0, "Failed to register PSK ID");
|
||||
|
||||
if (s_sock >= 0) {
|
||||
zassert_equal(setsockopt(s_sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||
zassert_equal(zsock_setsockopt(s_sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||
sec_tag_list, sizeof(sec_tag_list)),
|
||||
0, "Failed to set PSK on server socket");
|
||||
}
|
||||
|
||||
if (c_sock >= 0) {
|
||||
zassert_equal(setsockopt(c_sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||
zassert_equal(zsock_setsockopt(c_sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||
sec_tag_list, sizeof(sec_tag_list)),
|
||||
0, "Failed to set PSK on client socket");
|
||||
}
|
||||
|
@ -87,19 +87,19 @@ static void test_config_psk(int s_sock, int c_sock)
|
|||
|
||||
static void test_fcntl(int sock, int cmd, int val)
|
||||
{
|
||||
zassert_equal(fcntl(sock, cmd, val), 0, "fcntl failed");
|
||||
zassert_equal(zsock_fcntl(sock, cmd, val), 0, "fcntl failed");
|
||||
}
|
||||
|
||||
static void test_bind(int sock, struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
zassert_equal(bind(sock, addr, addrlen),
|
||||
zassert_equal(zsock_bind(sock, addr, addrlen),
|
||||
0,
|
||||
"bind failed");
|
||||
}
|
||||
|
||||
static void test_listen(int sock)
|
||||
{
|
||||
zassert_equal(listen(sock, MAX_CONNS),
|
||||
zassert_equal(zsock_listen(sock, MAX_CONNS),
|
||||
0,
|
||||
"listen failed");
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ static void test_connect(int sock, struct sockaddr *addr, socklen_t addrlen)
|
|||
{
|
||||
k_yield();
|
||||
|
||||
zassert_equal(connect(sock, addr, addrlen),
|
||||
zassert_equal(zsock_connect(sock, addr, addrlen),
|
||||
0,
|
||||
"connect failed");
|
||||
|
||||
|
@ -120,7 +120,7 @@ static void test_connect(int sock, struct sockaddr *addr, socklen_t addrlen)
|
|||
|
||||
static void test_send(int sock, const void *buf, size_t len, int flags)
|
||||
{
|
||||
zassert_equal(send(sock, buf, len, flags),
|
||||
zassert_equal(zsock_send(sock, buf, len, flags),
|
||||
len,
|
||||
"send failed");
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ static void test_sendmsg(int sock, const struct msghdr *msg, int flags)
|
|||
total_len += vec->iov_len;
|
||||
}
|
||||
|
||||
zassert_equal(sendmsg(sock, msg, flags),
|
||||
zassert_equal(zsock_sendmsg(sock, msg, flags),
|
||||
total_len,
|
||||
"sendmsg failed");
|
||||
}
|
||||
|
@ -145,20 +145,20 @@ static void test_accept(int sock, int *new_sock, struct sockaddr *addr,
|
|||
{
|
||||
zassert_not_null(new_sock, "null newsock");
|
||||
|
||||
*new_sock = accept(sock, addr, addrlen);
|
||||
*new_sock = zsock_accept(sock, addr, addrlen);
|
||||
zassert_true(*new_sock >= 0, "accept failed");
|
||||
}
|
||||
|
||||
static void test_shutdown(int sock, int how)
|
||||
{
|
||||
zassert_equal(shutdown(sock, how),
|
||||
zassert_equal(zsock_shutdown(sock, how),
|
||||
0,
|
||||
"shutdown failed");
|
||||
}
|
||||
|
||||
static void test_close(int sock)
|
||||
{
|
||||
zassert_equal(close(sock),
|
||||
zassert_equal(zsock_close(sock),
|
||||
0,
|
||||
"close failed");
|
||||
}
|
||||
|
@ -187,16 +187,16 @@ static void test_eof(int sock)
|
|||
ssize_t recved;
|
||||
|
||||
/* Test that EOF properly detected. */
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(recved, 0, "");
|
||||
|
||||
/* Calling again should be OK. */
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(recved, 0, "");
|
||||
|
||||
/* Calling when TCP connection is fully torn down should be still OK. */
|
||||
k_sleep(TCP_TEARDOWN_TIMEOUT);
|
||||
recved = recv(sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
recved = zsock_recv(sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(recved, 0, "");
|
||||
}
|
||||
|
||||
|
@ -211,12 +211,12 @@ ZTEST(net_socket_tls, test_so_type)
|
|||
prepare_sock_tls_v4(MY_IPV4_ADDR, ANY_PORT, &sock1, &bind_addr4, IPPROTO_TLS_1_2);
|
||||
prepare_sock_tls_v6(MY_IPV6_ADDR, ANY_PORT, &sock2, &bind_addr6, IPPROTO_TLS_1_2);
|
||||
|
||||
rv = getsockopt(sock1, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock1, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, SOCK_STREAM, "getsockopt got invalid type");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
rv = getsockopt(sock2, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock2, SOL_SOCKET, SO_TYPE, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, SOCK_STREAM, "getsockopt got invalid type");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
@ -236,13 +236,13 @@ ZTEST(net_socket_tls, test_so_protocol)
|
|||
prepare_sock_tls_v4(MY_IPV4_ADDR, ANY_PORT, &sock1, &bind_addr4, IPPROTO_TLS_1_2);
|
||||
prepare_sock_tls_v6(MY_IPV6_ADDR, ANY_PORT, &sock2, &bind_addr6, IPPROTO_TLS_1_1);
|
||||
|
||||
rv = getsockopt(sock1, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock1, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, IPPROTO_TLS_1_2,
|
||||
"getsockopt got invalid protocol");
|
||||
zassert_equal(optlen, sizeof(optval), "getsockopt got invalid size");
|
||||
|
||||
rv = getsockopt(sock2, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
rv = zsock_getsockopt(sock2, SOL_SOCKET, SO_PROTOCOL, &optval, &optlen);
|
||||
zassert_equal(rv, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, IPPROTO_TLS_1_1,
|
||||
"getsockopt got invalid protocol");
|
||||
|
@ -357,7 +357,7 @@ static void test_prepare_dtls_connection(sa_family_t family)
|
|||
sizeof(struct sockaddr_in);
|
||||
struct connect_data test_data;
|
||||
int role = TLS_DTLS_ROLE_SERVER;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
uint8_t rx_buf;
|
||||
int ret;
|
||||
|
||||
|
@ -380,7 +380,7 @@ static void test_prepare_dtls_connection(sa_family_t family)
|
|||
|
||||
test_config_psk(s_sock, c_sock);
|
||||
|
||||
zassert_equal(setsockopt(s_sock, SOL_TLS, TLS_DTLS_ROLE,
|
||||
zassert_equal(zsock_setsockopt(s_sock, SOL_TLS, TLS_DTLS_ROLE,
|
||||
&role, sizeof(role)),
|
||||
0, "setsockopt() failed");
|
||||
|
||||
|
@ -396,12 +396,12 @@ static void test_prepare_dtls_connection(sa_family_t family)
|
|||
* unblock poll().
|
||||
*/
|
||||
fds[0].fd = s_sock;
|
||||
fds[0].events = POLLIN;
|
||||
ret = poll(fds, 1, 1000);
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
ret = zsock_poll(fds, 1, 1000);
|
||||
zassert_equal(ret, 1, "poll() did not report data ready");
|
||||
|
||||
/* Flush the dummy byte. */
|
||||
ret = recv(s_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(s_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, sizeof(rx_buf), "recv() failed");
|
||||
|
||||
test_work_wait(&test_data.work);
|
||||
|
@ -431,7 +431,7 @@ ZTEST(net_socket_tls, test_v4_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf), "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf),
|
||||
"Invalid data received");
|
||||
|
@ -440,8 +440,8 @@ ZTEST(net_socket_tls, test_v4_msg_waitall)
|
|||
/* MSG_WAITALL + SO_RCVTIMEO - make sure recv returns the amount of data
|
||||
* received so far
|
||||
*/
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
|
@ -452,7 +452,7 @@ ZTEST(net_socket_tls, test_v4_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf) - 1, MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf) - 1, ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf) - 1, "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf) - 1,
|
||||
"Invalid data received");
|
||||
|
@ -487,7 +487,7 @@ ZTEST(net_socket_tls, test_v6_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf), "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf),
|
||||
"Invalid data received");
|
||||
|
@ -496,8 +496,8 @@ ZTEST(net_socket_tls, test_v6_msg_waitall)
|
|||
/* MSG_WAITALL + SO_RCVTIMEO - make sure recv returns the amount of data
|
||||
* received so far
|
||||
*/
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
|
@ -508,7 +508,7 @@ ZTEST(net_socket_tls, test_v6_msg_waitall)
|
|||
test_msg_waitall_tx_work_handler);
|
||||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf) - 1, MSG_WAITALL);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf) - 1, ZSOCK_MSG_WAITALL);
|
||||
zassert_equal(ret, sizeof(rx_buf) - 1, "Invalid length received");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(rx_buf) - 1,
|
||||
"Invalid data received");
|
||||
|
@ -553,13 +553,13 @@ void test_msg_trunc(sa_family_t family)
|
|||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
rv = recv(s_sock, rx_buf, 2, ZSOCK_MSG_TRUNC);
|
||||
rv = zsock_recv(s_sock, rx_buf, 2, ZSOCK_MSG_TRUNC);
|
||||
zassert_equal(rv, sizeof(TEST_STR_SMALL) - 1, "MSG_TRUNC flag failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, 2, "invalid rx data");
|
||||
zassert_equal(rx_buf[2], 0, "received more than requested");
|
||||
|
||||
/* The remaining data should've been discarded */
|
||||
rv = recv(s_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
rv = zsock_recv(s_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(rv, -1, "consecutive recv should've failed");
|
||||
zassert_equal(errno, EAGAIN, "incorrect errno value");
|
||||
|
||||
|
@ -628,7 +628,7 @@ static void test_dtls_sendmsg_no_buf(sa_family_t family)
|
|||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
rv = recv(s_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
rv = zsock_recv(s_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(rv, sizeof(TEST_STR_SMALL) - 1, "recv failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, "invalid rx data");
|
||||
|
||||
|
@ -642,7 +642,7 @@ static void test_dtls_sendmsg_no_buf(sa_family_t family)
|
|||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
rv = recv(s_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
rv = zsock_recv(s_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(rv, sizeof(TEST_STR_SMALL) - 1, "recv failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, "invalid rx data");
|
||||
|
||||
|
@ -653,7 +653,7 @@ static void test_dtls_sendmsg_no_buf(sa_family_t family)
|
|||
iov[0].iov_base = TEST_STR_SMALL;
|
||||
iov[0].iov_len = sizeof(TEST_STR_SMALL) - 1;
|
||||
|
||||
rv = sendmsg(c_sock, &msg, 0);
|
||||
rv = zsock_sendmsg(c_sock, &msg, 0);
|
||||
zassert_equal(rv, -1, "sendmsg succeeded");
|
||||
zassert_equal(errno, EMSGSIZE, "incorrect errno value");
|
||||
|
||||
|
@ -716,7 +716,7 @@ static void test_dtls_sendmsg(sa_family_t family)
|
|||
test_work_reschedule(&test_data.tx_work, K_NO_WAIT);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
rv = recv(s_sock, buf, sizeof(buf), 0);
|
||||
rv = zsock_recv(s_sock, buf, sizeof(buf), 0);
|
||||
zassert_equal(rv, sizeof(expected_str) - 1, "recv failed");
|
||||
zassert_mem_equal(buf, expected_str, sizeof(expected_str) - 1, "invalid rx data");
|
||||
|
||||
|
@ -734,7 +734,7 @@ static void test_dtls_sendmsg(sa_family_t family)
|
|||
test_work_reschedule(&test_data.tx_work, K_NO_WAIT);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
rv = recv(s_sock, buf, sizeof(buf), 0);
|
||||
rv = zsock_recv(s_sock, buf, sizeof(buf), 0);
|
||||
zassert_equal(rv, sizeof(expected_str) - 1, "recv failed");
|
||||
zassert_mem_equal(buf, expected_str, sizeof(expected_str) - 1, "invalid rx data");
|
||||
|
||||
|
@ -756,7 +756,7 @@ static void test_dtls_sendmsg(sa_family_t family)
|
|||
k_msleep(10);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
rv = recv(s_sock, buf, sizeof(buf), 0);
|
||||
rv = zsock_recv(s_sock, buf, sizeof(buf), 0);
|
||||
zassert_equal(rv, sizeof(buf), "recv failed");
|
||||
for (int i = 0; i < sizeof(buf); i++) {
|
||||
zassert_equal(buf[i], 'a', "invalid rx data");
|
||||
|
@ -773,7 +773,7 @@ static void test_dtls_sendmsg(sa_family_t family)
|
|||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 2;
|
||||
|
||||
rv = sendmsg(c_sock, &msg, 0);
|
||||
rv = zsock_sendmsg(c_sock, &msg, 0);
|
||||
zassert_equal(rv, -1, "sendmsg succeeded");
|
||||
zassert_equal(errno, EMSGSIZE, "incorrect errno value");
|
||||
|
||||
|
@ -811,7 +811,7 @@ static void close_work(struct k_work *work)
|
|||
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
|
||||
struct close_data *data = CONTAINER_OF(dwork, struct close_data, work);
|
||||
|
||||
close(*data->fd);
|
||||
zsock_close(*data->fd);
|
||||
*data->fd = -1;
|
||||
}
|
||||
|
||||
|
@ -837,7 +837,7 @@ ZTEST(net_socket_tls, test_close_while_accept)
|
|||
/* Start blocking accept(), which should be unblocked by close() from
|
||||
* another thread and return an error.
|
||||
*/
|
||||
new_sock = accept(s_sock, &addr, &addrlen);
|
||||
new_sock = zsock_accept(s_sock, &addr, &addrlen);
|
||||
zassert_equal(new_sock, -1, "accept did not return error");
|
||||
zassert_equal(errno, EINTR, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -857,7 +857,7 @@ ZTEST(net_socket_tls, test_close_while_recv)
|
|||
close_work_data.fd = &new_sock;
|
||||
test_work_reschedule(&close_work_data.work, K_MSEC(10));
|
||||
|
||||
ret = recv(new_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, &rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv did not return error");
|
||||
zassert_equal(errno, EINTR, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -885,8 +885,8 @@ ZTEST(net_socket_tls, test_connect_timeout)
|
|||
|
||||
loopback_set_packet_drop_ratio(1.0f);
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
-1, "connect succeed");
|
||||
zassert_equal(errno, ETIMEDOUT,
|
||||
"connect should be timed out, got %d", errno);
|
||||
|
@ -912,8 +912,8 @@ ZTEST(net_socket_tls, test_connect_closed_port)
|
|||
ret = zsock_inet_pton(AF_INET6, MY_IPV6_ADDR, &s_saddr.sin6_addr);
|
||||
zassert_equal(ret, 1, "inet_pton failed");
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
-1, "connect succeed");
|
||||
zassert_equal(errno, ETIMEDOUT,
|
||||
"connect should fail, got %d", errno);
|
||||
|
@ -948,12 +948,12 @@ static void fake_tcp_server_work(struct k_work *work)
|
|||
int ret;
|
||||
char rx_buf[32];
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
if (ret <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
(void)send(new_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL), 0);
|
||||
(void)zsock_send(new_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL), 0);
|
||||
}
|
||||
|
||||
out:
|
||||
|
@ -998,8 +998,8 @@ ZTEST(net_socket_tls, test_connect_invalid_handshake_data)
|
|||
test_prepare_fake_tcp_server(&server_data, AF_INET6, &s_sock,
|
||||
(struct sockaddr *)&s_saddr, true);
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
-1, "connect succeed");
|
||||
zassert_equal(errno, ECONNABORTED,
|
||||
"connect should fail, got %d", errno);
|
||||
|
@ -1025,8 +1025,8 @@ ZTEST(net_socket_tls, test_connect_no_handshake_data)
|
|||
test_prepare_fake_tcp_server(&server_data, AF_INET6, &s_sock,
|
||||
(struct sockaddr *)&s_saddr, false);
|
||||
|
||||
zassert_equal(connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
zassert_equal(zsock_connect(c_sock, (struct sockaddr *)&s_saddr,
|
||||
sizeof(s_saddr)),
|
||||
-1, "connect succeed");
|
||||
zassert_equal(errno, ECONNABORTED,
|
||||
"connect should fail, got %d", errno);
|
||||
|
@ -1051,7 +1051,7 @@ ZTEST(net_socket_tls, test_accept_non_block)
|
|||
test_listen(s_sock);
|
||||
|
||||
timestamp = k_uptime_get_32();
|
||||
new_sock = accept(s_sock, NULL, NULL);
|
||||
new_sock = zsock_accept(s_sock, NULL, NULL);
|
||||
zassert_true(k_uptime_get_32() - timestamp <= 100, "");
|
||||
zassert_equal(new_sock, -1, "accept did not return error");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
@ -1076,7 +1076,7 @@ ZTEST(net_socket_tls, test_accept_invalid_handshake_data)
|
|||
test_connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr));
|
||||
test_send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL), 0);
|
||||
|
||||
new_sock = accept(s_sock, NULL, NULL);
|
||||
new_sock = zsock_accept(s_sock, NULL, NULL);
|
||||
zassert_equal(new_sock, -1, "accept did not return error");
|
||||
zassert_equal(errno, ECONNABORTED, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1091,29 +1091,29 @@ ZTEST(net_socket_tls, test_recv_non_block)
|
|||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
/* Verify ZSOCK_MSG_DONTWAIT flag first */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "recv()) should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
/* Verify fcntl and O_NONBLOCK */
|
||||
test_fcntl(new_sock, F_SETFL, O_NONBLOCK);
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
/* Let the data got through. */
|
||||
k_sleep(K_MSEC(10));
|
||||
|
||||
/* Should get data now */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
/* And EAGAIN on consecutive read */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ ZTEST(net_socket_tls, test_recv_block)
|
|||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
/* recv() shall block until send work sends the data. */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
|
@ -1173,12 +1173,12 @@ ZTEST(net_socket_tls, test_send_non_block)
|
|||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
/* Simulate window full scenario with SO_RCVBUF option. */
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Fill out the window */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
/* Wait for ACK (empty window, min. 100 ms due to silly window
|
||||
|
@ -1187,18 +1187,18 @@ ZTEST(net_socket_tls, test_send_non_block)
|
|||
k_sleep(K_MSEC(150));
|
||||
|
||||
/* Verify ZSOCK_MSG_DONTWAIT flag first */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL),
|
||||
ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL),
|
||||
ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "send() should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
/* Verify fcntl and O_NONBLOCK */
|
||||
test_fcntl(c_sock, F_SETFL, O_NONBLOCK);
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, -1, "send() should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
|
@ -1206,16 +1206,16 @@ ZTEST(net_socket_tls, test_send_non_block)
|
|||
k_sleep(K_MSEC(10));
|
||||
|
||||
/* Should succeed now. */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
/* Flush the data */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
/* And make sure there's no more data left. */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1242,7 +1242,7 @@ static void recv_work_handler(struct k_work *work)
|
|||
while (off < test_data->datalen) {
|
||||
size_t recvlen = MIN(sizeof(rx_buf), test_data->datalen - off);
|
||||
|
||||
ret = recv(test_data->sock, rx_buf, recvlen, 0);
|
||||
ret = zsock_recv(test_data->sock, rx_buf, recvlen, 0);
|
||||
zassert_true(ret > 0, "recv() error");
|
||||
zassert_mem_equal(rx_buf, test_data->data + off, ret,
|
||||
"unexpected data");
|
||||
|
@ -1266,12 +1266,12 @@ ZTEST(net_socket_tls, test_send_block)
|
|||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
/* Simulate window full scenario with SO_RCVBUF option. */
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Fill out the window */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
/* Wait for ACK (empty window, min. 100 ms due to silly window
|
||||
|
@ -1284,16 +1284,16 @@ ZTEST(net_socket_tls, test_send_block)
|
|||
test_work_reschedule(&test_data.work, K_MSEC(10));
|
||||
|
||||
/* Should block and succeed. */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
/* Flush the data */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
/* And make sure there's no more data left. */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1316,13 +1316,13 @@ ZTEST(net_socket_tls, test_send_on_close)
|
|||
k_msleep(10);
|
||||
|
||||
/* Verify send() reports an error after connection is closed. */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, -1, "send() should've failed");
|
||||
zassert_equal(errno, ECONNABORTED, "Unexpected errno value: %d", errno);
|
||||
|
||||
/* send() on closed connection marked error on a socket. */
|
||||
ret = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "send() should've failed");
|
||||
/* recv() on closed connection marked error on a socket. */
|
||||
ret = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
zassert_equal(errno, ECONNABORTED, "Unexpected errno value: %d", errno);
|
||||
|
||||
test_sockets_close();
|
||||
|
@ -1338,11 +1338,11 @@ ZTEST(net_socket_tls, test_send_on_close)
|
|||
k_msleep(10);
|
||||
|
||||
/* Graceful connection close should be reported first. */
|
||||
ret = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, 0, "recv() should've reported connection close");
|
||||
|
||||
/* And consecutive send() should fail. */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, -1, "send() should've failed");
|
||||
zassert_equal(errno, ECONNABORTED, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1367,12 +1367,12 @@ ZTEST(net_socket_tls, test_so_rcvtimeo)
|
|||
|
||||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
ret = setsockopt(c_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
ret = zsock_setsockopt(c_sock, SOL_SOCKET, SO_RCVTIMEO, &optval,
|
||||
sizeof(optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
start_time = k_uptime_get_32();
|
||||
ret = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(ret, -1, "recv() should've failed");
|
||||
|
@ -1385,7 +1385,7 @@ ZTEST(net_socket_tls, test_so_rcvtimeo)
|
|||
test_work_reschedule(&test_data.tx_work, K_MSEC(10));
|
||||
|
||||
/* recv() shall return as soon as it gets data, regardless of timeout. */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
|
@ -1410,16 +1410,16 @@ ZTEST(net_socket_tls, test_so_sndtimeo)
|
|||
|
||||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
ret = setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
ret = zsock_setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval,
|
||||
sizeof(timeo_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Simulate window full scenario with SO_RCVBUF option. */
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
ret = send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, 0);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "send() failed");
|
||||
|
||||
/* Wait for ACK (empty window). */
|
||||
|
@ -1427,7 +1427,7 @@ ZTEST(net_socket_tls, test_so_sndtimeo)
|
|||
|
||||
/* Client should not be able to send now and time out after SO_SNDTIMEO */
|
||||
start_time = k_uptime_get_32();
|
||||
ret = send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, 0);
|
||||
time_diff = k_uptime_get_32() - start_time;
|
||||
|
||||
zassert_equal(ret, -1, "send() should've failed");
|
||||
|
@ -1440,7 +1440,7 @@ ZTEST(net_socket_tls, test_so_sndtimeo)
|
|||
test_work_reschedule(&test_data.work, K_MSEC(10));
|
||||
|
||||
/* Should block and succeed. */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
test_sockets_close();
|
||||
|
@ -1475,7 +1475,7 @@ static void shutdown_work(struct k_work *work)
|
|||
struct shutdown_data *data = CONTAINER_OF(dwork, struct shutdown_data,
|
||||
work);
|
||||
|
||||
shutdown(data->sock, data->how);
|
||||
zsock_shutdown(data->sock, data->how);
|
||||
}
|
||||
|
||||
ZTEST(net_socket_tls, test_shutdown_rd_while_recv)
|
||||
|
@ -1525,12 +1525,12 @@ ZTEST(net_socket_tls, test_send_while_recv)
|
|||
/* recv() shall block until the second work is executed. The second work
|
||||
* will execute only if the first one won't block.
|
||||
*/
|
||||
ret = recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(c_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
/* Check if the server sock got its data. */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), 0);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
|
@ -1543,25 +1543,25 @@ ZTEST(net_socket_tls, test_poll_tls_pollin)
|
|||
{
|
||||
uint8_t rx_buf[sizeof(TEST_STR_SMALL) - 1];
|
||||
int ret;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = new_sock;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
|
||||
ret = poll(fds, 1, 0);
|
||||
ret = zsock_poll(fds, 1, 0);
|
||||
zassert_equal(ret, 0, "Unexpected poll() event");
|
||||
|
||||
ret = send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, sizeof(TEST_STR_SMALL) - 1, 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_equal(fds[0].revents, POLLIN, "No POLLIN event");
|
||||
zassert_equal(fds[0].revents, ZSOCK_POLLIN, "No POLLIN event");
|
||||
|
||||
/* Check that data is really available */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
|
@ -1578,26 +1578,26 @@ ZTEST(net_socket_tls, test_poll_dtls_pollin)
|
|||
.datalen = sizeof(TEST_STR_SMALL) - 1
|
||||
};
|
||||
int ret;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
test_prepare_dtls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = s_sock;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
|
||||
ret = poll(fds, 1, 0);
|
||||
ret = zsock_poll(fds, 1, 0);
|
||||
zassert_equal(ret, 0, "Unexpected poll() event");
|
||||
|
||||
test_data.sock = c_sock;
|
||||
k_work_init_delayable(&test_data.tx_work, send_work_handler);
|
||||
test_work_reschedule(&test_data.tx_work, K_NO_WAIT);
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_equal(fds[0].revents, POLLIN, "No POLLIN event");
|
||||
zassert_equal(fds[0].revents, ZSOCK_POLLIN, "No POLLIN event");
|
||||
|
||||
/* Check that data is really available */
|
||||
ret = recv(s_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(s_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
|
@ -1612,24 +1612,24 @@ ZTEST(net_socket_tls, test_poll_tls_pollout)
|
|||
int buf_optval = TLS_RECORD_OVERHEAD + sizeof(TEST_STR_SMALL) - 1;
|
||||
uint8_t rx_buf[sizeof(TEST_STR_SMALL) - 1];
|
||||
int ret;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
|
||||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = c_sock;
|
||||
fds[0].events = POLLOUT;
|
||||
fds[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
ret = poll(fds, 1, 0);
|
||||
ret = zsock_poll(fds, 1, 0);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_equal(fds[0].revents, POLLOUT, "No POLLOUT event");
|
||||
zassert_equal(fds[0].revents, ZSOCK_POLLOUT, "No POLLOUT event");
|
||||
|
||||
/* Simulate window full scenario with SO_RCVBUF option. */
|
||||
ret = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
ret = zsock_setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval,
|
||||
sizeof(buf_optval));
|
||||
zassert_equal(ret, 0, "setsockopt failed (%d)", errno);
|
||||
|
||||
/* Fill out the window */
|
||||
ret = send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
ret = zsock_send(c_sock, TEST_STR_SMALL, strlen(TEST_STR_SMALL), 0);
|
||||
zassert_equal(ret, strlen(TEST_STR_SMALL), "send() failed");
|
||||
|
||||
/* Wait for ACK (empty window, min. 100 ms due to silly window
|
||||
|
@ -1638,17 +1638,17 @@ ZTEST(net_socket_tls, test_poll_tls_pollout)
|
|||
k_sleep(K_MSEC(150));
|
||||
|
||||
/* poll() shouldn't report POLLOUT now */
|
||||
ret = poll(fds, 1, 0);
|
||||
ret = zsock_poll(fds, 1, 0);
|
||||
zassert_equal(ret, 0, "Unexpected poll() event");
|
||||
|
||||
/* Consume the data, and check if the client sock is writeable again */
|
||||
ret = recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, sizeof(TEST_STR_SMALL) - 1, "recv() failed");
|
||||
zassert_mem_equal(rx_buf, TEST_STR_SMALL, ret, "Invalid data received");
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_equal(fds[0].revents, POLLOUT, "No POLLOUT event");
|
||||
zassert_equal(fds[0].revents, ZSOCK_POLLOUT, "No POLLOUT event");
|
||||
|
||||
test_sockets_close();
|
||||
|
||||
|
@ -1657,18 +1657,18 @@ ZTEST(net_socket_tls, test_poll_tls_pollout)
|
|||
|
||||
ZTEST(net_socket_tls, test_poll_dtls_pollout)
|
||||
{
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
int ret;
|
||||
|
||||
test_prepare_dtls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = c_sock;
|
||||
fds[0].events = POLLOUT;
|
||||
fds[0].events = ZSOCK_POLLOUT;
|
||||
|
||||
/* DTLS socket should always be writeable. */
|
||||
ret = poll(fds, 1, 0);
|
||||
ret = zsock_poll(fds, 1, 0);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_equal(fds[0].revents, POLLOUT, "No POLLOUT event");
|
||||
zassert_equal(fds[0].revents, ZSOCK_POLLOUT, "No POLLOUT event");
|
||||
|
||||
test_sockets_close();
|
||||
|
||||
|
@ -1678,25 +1678,25 @@ ZTEST(net_socket_tls, test_poll_dtls_pollout)
|
|||
|
||||
ZTEST(net_socket_tls, test_poll_tls_pollhup)
|
||||
{
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
uint8_t rx_buf;
|
||||
int ret;
|
||||
|
||||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = new_sock;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
|
||||
test_close(c_sock);
|
||||
c_sock = -1;
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_true(fds[0].revents & POLLIN, "No POLLIN event");
|
||||
zassert_true(fds[0].revents & POLLHUP, "No POLLHUP event");
|
||||
zassert_true(fds[0].revents & ZSOCK_POLLIN, "No POLLIN event");
|
||||
zassert_true(fds[0].revents & ZSOCK_POLLHUP, "No POLLHUP event");
|
||||
|
||||
/* Check that connection was indeed closed */
|
||||
ret = recv(new_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, 0, "recv() did not report connection close");
|
||||
|
||||
test_sockets_close();
|
||||
|
@ -1706,24 +1706,24 @@ ZTEST(net_socket_tls, test_poll_tls_pollhup)
|
|||
|
||||
ZTEST(net_socket_tls, test_poll_dtls_pollhup)
|
||||
{
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
uint8_t rx_buf;
|
||||
int ret;
|
||||
|
||||
test_prepare_dtls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = s_sock;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
|
||||
test_close(c_sock);
|
||||
c_sock = -1;
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_equal(fds[0].revents, POLLHUP, "No POLLHUP event");
|
||||
zassert_equal(fds[0].revents, ZSOCK_POLLHUP, "No POLLHUP event");
|
||||
|
||||
/* Check that connection was indeed closed */
|
||||
ret = recv(s_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(s_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "recv() should report EAGAIN");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1739,7 +1739,7 @@ ZTEST(net_socket_tls, test_poll_tls_pollerr)
|
|||
{
|
||||
uint8_t rx_buf;
|
||||
int ret;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
int optval;
|
||||
socklen_t optlen = sizeof(optval);
|
||||
mbedtls_ssl_context *ssl_ctx;
|
||||
|
@ -1747,23 +1747,23 @@ ZTEST(net_socket_tls, test_poll_tls_pollerr)
|
|||
test_prepare_tls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = new_sock;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
|
||||
/* Get access to the underlying ssl context, and send alert. */
|
||||
ssl_ctx = ztls_get_mbedtls_ssl_context(c_sock);
|
||||
mbedtls_ssl_send_alert_message(ssl_ctx, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR);
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_true(fds[0].revents & POLLERR, "No POLLERR event");
|
||||
zassert_true(fds[0].revents & ZSOCK_POLLERR, "No POLLERR event");
|
||||
|
||||
ret = getsockopt(new_sock, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
ret = zsock_getsockopt(new_sock, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, ECONNABORTED, "getsockopt got invalid error %d",
|
||||
optval);
|
||||
|
||||
ret = recv(new_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(new_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "recv() did not report error");
|
||||
zassert_equal(errno, ECONNABORTED, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
@ -1776,7 +1776,7 @@ ZTEST(net_socket_tls, test_poll_dtls_pollerr)
|
|||
{
|
||||
uint8_t rx_buf;
|
||||
int ret;
|
||||
struct pollfd fds[1];
|
||||
struct zsock_pollfd fds[1];
|
||||
int optval;
|
||||
socklen_t optlen = sizeof(optval);
|
||||
mbedtls_ssl_context *ssl_ctx;
|
||||
|
@ -1784,24 +1784,24 @@ ZTEST(net_socket_tls, test_poll_dtls_pollerr)
|
|||
test_prepare_dtls_connection(AF_INET6);
|
||||
|
||||
fds[0].fd = s_sock;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].events = ZSOCK_POLLIN;
|
||||
|
||||
/* Get access to the underlying ssl context, and send alert. */
|
||||
ssl_ctx = ztls_get_mbedtls_ssl_context(c_sock);
|
||||
mbedtls_ssl_send_alert_message(ssl_ctx, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR);
|
||||
|
||||
ret = poll(fds, 1, 100);
|
||||
ret = zsock_poll(fds, 1, 100);
|
||||
zassert_equal(ret, 1, "poll() should've report event");
|
||||
zassert_true(fds[0].revents & POLLERR, "No POLLERR event");
|
||||
zassert_true(fds[0].revents & ZSOCK_POLLERR, "No POLLERR event");
|
||||
|
||||
ret = getsockopt(s_sock, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
ret = zsock_getsockopt(s_sock, SOL_SOCKET, SO_ERROR, &optval, &optlen);
|
||||
zassert_equal(ret, 0, "getsockopt failed (%d)", errno);
|
||||
zassert_equal(optval, ECONNABORTED, "getsockopt got invalid error %d",
|
||||
optval);
|
||||
|
||||
/* DTLS server socket should recover and be ready to accept new session. */
|
||||
ret = recv(s_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
ret = zsock_recv(s_sock, &rx_buf, sizeof(rx_buf), ZSOCK_MSG_DONTWAIT);
|
||||
zassert_equal(ret, -1, "recv() did not report error");
|
||||
zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno);
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ CONFIG_NET_IPV4=y
|
|||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
CONFIG_POSIX_MAX_FDS=10
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
|
||||
CONFIG_NET_IPV6_DAD=n
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,6 @@ CONFIG_NET_LOOPBACK=y
|
|||
|
||||
# Sockets
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
|
||||
# Network driver config
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
|
Loading…
Reference in a new issue