21 struct lwip_sock*
s = lwip_socket_dbg_get_socket(
i);
46 tcpip_thread_poll_one();
48 tcp_abort(tcp_tw_pcbs);
49 tcpip_thread_poll_one();
51 tcpip_thread_poll_one();
57#define NUM_SOCKETS MEMP_NUM_NETCONN
62test_sockets_alloc_socket_nonblocking(
int domain,
int type)
67 fail_unless(
ret == 0);
86 fail_unless(
s2[
i] >= 0);
93 ret = lwip_close(
s2[0]);
94 fail_unless(
ret == 0);
97 fail_unless(
s2[0] >= 0);
102 fail_unless(
ret == 0);
107static void test_sockets_allfunctions_basic_domain(
int domain)
117 ret = lwip_listen(
s, 0);
118 fail_unless(
ret == 0);
120 addrlen =
sizeof(
addr);
122 fail_unless(
ret == 0);
125 fail_unless(
s2 >= 0);
140 fail_unless(
ret == -1);
143 fail_unless(
ret == -1);
146 while(tcpip_thread_poll_one());
148 s3 = lwip_accept(
s, (
struct sockaddr*)&addr2, &addr2len);
149 fail_unless(s3 >= 0);
152 fail_unless(
ret == -1);
156 ret = lwip_write(s3,
"test", 4);
157 fail_unless(
ret == 4);
159 ret = lwip_shutdown(s3, SHUT_WR);
160 fail_unless(
ret == 0);
162 while(tcpip_thread_poll_one());
165 fail_unless(
ret == 3);
168 fail_unless(
ret == 3);
171 fail_unless(
ret == 4);
174 fail_unless(
ret == 0);
177 fail_unless(
ret == -1);
179 ret = lwip_write(
s2,
"foo", 3);
180 fail_unless(
ret == 3);
182 ret = lwip_close(
s2);
183 fail_unless(
ret == 0);
185 while(tcpip_thread_poll_one());
188 ret = lwip_read(s3,
buf, 4);
189 fail_unless(
ret == 3);
191 ret = lwip_read(s3,
buf, 1);
192 fail_unless(
ret == 0);
194 ret = lwip_read(s3,
buf, 1);
195 fail_unless(
ret == -1);
197 while(tcpip_thread_poll_one());
200 fail_unless(
ret == 0);
201 ret = lwip_close(s3);
202 fail_unless(
ret == 0);
211 test_sockets_allfunctions_basic_domain(
AF_INET);
214 test_sockets_allfunctions_basic_domain(
AF_INET6);
221 memset(addr_st, 0,
sizeof(*addr_st));
229 addr->sin6_addr = lo6;
251static void test_sockets_msgapi_update_iovs(
struct msghdr *
msg,
size_t bytes)
260 for (
i = 0;
i <
msg->msg_iovlen;
i++) {
270 msg->msg_iov = &
msg->msg_iov[
i];
271 msg->msg_iovlen -=
i;
278static void test_sockets_msgapi_tcp(
int domain)
280 #define BUF_SZ (TCP_SND_BUF/4)
281 #define TOTAL_DATA_SZ (BUF_SZ*8)
282 #define NEED_TRAILER (BUF_SZ % 4 != 0)
284 int bytes_written, bytes_read;
287 struct iovec siovs[8];
290 struct iovec riovs[5];
291 struct iovec riovs_tmp[5];
298 test_sockets_init_loopback_addr(
domain, &addr_storage, &addr_size);
301 fail_unless(listnr >= 0);
303 fail_unless(
s1 >= 0);
306 ret = lwip_bind(listnr, (
struct sockaddr*)&addr_storage, addr_size);
307 fail_unless(
ret == 0);
308 ret = lwip_listen(listnr, 0);
309 fail_unless(
ret == 0);
312 ret = lwip_getsockname(listnr, (
struct sockaddr*)&addr_storage, &addr_size);
313 fail_unless(
ret == 0);
316 ret = lwip_connect(
s1, (
struct sockaddr*)&addr_storage, addr_size);
317 fail_unless(
ret == -1);
320 while (tcpip_thread_poll_one());
324 fail_unless(
s2 >= 0);
327 ret = lwip_connect(
s1, (
struct sockaddr*)&addr_storage, addr_size);
328 fail_unless(
ret == -1);
332 opt = lwip_fcntl(
s2, F_GETFL, 0);
333 fail_unless(opt ==
O_RDWR);
335 ret = lwip_fcntl(
s2, F_SETFL, opt);
336 fail_unless(
ret == 0);
339 ret = lwip_close(listnr);
340 fail_unless(
ret == 0);
347 fail_unless(snd_buf !=
NULL);
348 for (
i = 0;
i < BUF_SZ;
i++,
val++) {
353 for (
i = 0;
i < 8;
i++) {
354 siovs[
i].iov_base = snd_buf;
355 siovs[
i].iov_len = BUF_SZ;
360 fail_unless(rcv_buf !=
NULL);
362 for (
i = 0;
i < 4;
i++) {
363 riovs[
i].iov_base = &rcv_buf[
i*(BUF_SZ/4)];
364 riovs[
i].iov_len = BUF_SZ/4;
368 if ((BUF_SZ % 4) != 0) {
369 riovs[5].iov_base = &rcv_buf[4*(BUF_SZ/4)];
370 riovs[5].iov_len = BUF_SZ - (4*(BUF_SZ/4));
377 memcpy(riovs_tmp, riovs,
sizeof(riovs));
379 memset(&smsg, 0,
sizeof(smsg));
380 smsg.msg_iov = siovs;
383 memset(&rmsg, 0,
sizeof(rmsg));
384 rmsg.msg_iov = riovs_tmp;
385 rmsg.msg_iovlen = (rcv_trailer ? 5 : 4);
391 while (bytes_written < TOTAL_DATA_SZ && (bytes_read < TOTAL_DATA_SZ)) {
393 if (bytes_written < TOTAL_DATA_SZ) {
394 ret = lwip_sendmsg(
s1, &smsg, 0);
397 fail_unless(
ret > 0);
399 bytes_written +=
ret;
400 if (bytes_written < TOTAL_DATA_SZ) {
401 test_sockets_msgapi_update_iovs(&smsg, (
size_t)
ret);
405 while (tcpip_thread_poll_one());
409 if (bytes_read < TOTAL_DATA_SZ) {
410 ret = lwip_recvmsg(
s2, &rmsg, 0);
416 if (rcv_off == BUF_SZ) {
418 fail_unless(!
memcmp(snd_buf, rcv_buf, BUF_SZ));
419 bytes_read += BUF_SZ;
422 memset(rcv_buf, 0, BUF_SZ);
423 memcpy(riovs_tmp, riovs,
sizeof(riovs));
424 rmsg.msg_iov = riovs_tmp;
425 rmsg.msg_iovlen = (rcv_trailer ? 5 : 4);
427 test_sockets_msgapi_update_iovs(&rmsg, (
size_t)
ret);
436 ret = lwip_close(
s1);
437 fail_unless(
ret == 0);
438 ret = lwip_close(
s2);
439 fail_unless(
ret == 0);
444static void test_sockets_msgapi_udp_send_recv_loop(
int s,
struct msghdr *smsg,
struct msghdr *rmsg)
449 for (
i = 0;
i < 10;
i++) {
450 ret = lwip_sendmsg(
s, smsg, 0);
451 fail_unless(
ret == 4);
453 while (tcpip_thread_poll_one());
456 ret = lwip_recvmsg(
s, rmsg, 0);
457 fail_unless(
ret == 4);
460 fail_unless(*((
u8_t*)rmsg->
msg_iov[0].iov_base) == 0xDE);
461 fail_unless(*((
u8_t*)rmsg->
msg_iov[1].iov_base) == 0xAD);
462 fail_unless(*((
u8_t*)rmsg->
msg_iov[2].iov_base) == 0xBE);
463 fail_unless(*((
u8_t*)rmsg->
msg_iov[3].iov_base) == 0xEF);
473static void test_sockets_msgapi_udp(
int domain)
478 struct iovec riovs[4];
481 struct iovec siovs[4];
483 u8_t snd_buf[4] = {0xDE, 0xAD, 0xBE, 0xEF};
486 for (
i = 0;
i < 4;
i++) {
487 siovs[
i].iov_base = &snd_buf[
i];
488 siovs[
i].iov_len =
sizeof(
u8_t);
489 riovs[
i].iov_base = &rcv_buf[
i];
490 riovs[
i].iov_len =
sizeof(
u8_t);
493 test_sockets_init_loopback_addr(
domain, &addr_storage, &addr_size);
498 ret = lwip_bind(
s, (
struct sockaddr*)&addr_storage, addr_size);
499 fail_unless(
ret == 0);
502 ret = lwip_getsockname(
s, (
struct sockaddr*)&addr_storage, &addr_size);
503 fail_unless(
ret == 0);
512 fail_unless(addr_size ==
sizeof(
struct sockaddr_in));
521 memset(&smsg, 0,
sizeof(smsg));
524 memset(&rmsg, 0,
sizeof(rmsg));
532 test_sockets_msgapi_udp_send_recv_loop(
s, &smsg, &rmsg);
535 ret = lwip_connect(
s, (
struct sockaddr*)&addr_storage, addr_size);
536 fail_unless(
ret == 0);
541 test_sockets_msgapi_udp_send_recv_loop(
s, &smsg, &rmsg);
544 fail_unless(
ret == 0);
548static void test_sockets_msgapi_cmsg(
int domain)
555 struct cmsghdr *cmsg;
558 u8_t snd_buf[4] = {0xDE, 0xAD, 0xBE, 0xEF};
561 test_sockets_init_loopback_addr(
domain, &addr_storage, &addr_size);
566 ret = lwip_bind(
s, (
struct sockaddr*)&addr_storage, addr_size);
567 fail_unless(
ret == 0);
570 ret = lwip_getsockname(
s, (
struct sockaddr*)&addr_storage, &addr_size);
571 fail_unless(
ret == 0);
575 fail_unless(
ret == 0);
578 iov.iov_base = rcv_buf;
579 iov.iov_len =
sizeof(rcv_buf);
580 msg.msg_control = cmsg_buf;
581 msg.msg_controllen =
sizeof(cmsg_buf);
588 memset(rcv_buf, 0,
sizeof(rcv_buf));
589 ret = lwip_sendto(
s, snd_buf,
sizeof(snd_buf), 0, (
struct sockaddr*)&addr_storage, addr_size);
590 fail_unless(
ret ==
sizeof(snd_buf));
592 tcpip_thread_poll_one();
594 ret = lwip_recvmsg(
s, &
msg, 0);
595 fail_unless(
ret ==
sizeof(rcv_buf));
596 fail_unless(!
memcmp(rcv_buf, snd_buf,
sizeof(rcv_buf)));
599 cmsg = CMSG_FIRSTHDR(&
msg);
600 fail_unless(cmsg !=
NULL);
601 fail_unless(cmsg->cmsg_len > 0);
612 cmsg = CMSG_NXTHDR(&
msg, cmsg);
613 fail_unless(cmsg ==
NULL);
616 memset(rcv_buf, 0,
sizeof(rcv_buf));
617 ret = lwip_sendto(
s, snd_buf,
sizeof(snd_buf), 0, (
struct sockaddr*)&addr_storage, addr_size);
618 fail_unless(
ret ==
sizeof(snd_buf));
620 tcpip_thread_poll_one();
622 msg.msg_controllen = 1;
624 ret = lwip_recvmsg(
s, &
msg, 0);
625 fail_unless(
ret ==
sizeof(rcv_buf));
626 fail_unless(!
memcmp(rcv_buf, snd_buf,
sizeof(rcv_buf)));
630 fail_unless(
msg.msg_controllen == 0);
633 fail_unless(
ret == 0);
641 test_sockets_msgapi_udp(
AF_INET);
642 test_sockets_msgapi_tcp(
AF_INET);
643 test_sockets_msgapi_cmsg(
AF_INET);
654#if LWIP_SOCKET_SELECT
675 tv.tv_sec = tv.tv_usec = 0;
676 ret = lwip_select(
s + 1, &readset, &writeset, &errset, &tv);
677 fail_unless(
ret == 0);
681 fail_unless(
ret == 0);
696 const char txbuf[] =
"something";
698 struct lwip_sock *sact_sock;
704 memset(&sa_listen, 0,
sizeof(sa_listen));
705 sa_listen.sin_family =
AF_INET;
711 fail_unless(sl >= 0);
714 ret = lwip_bind(sl, (
struct sockaddr *)&sa_listen,
sizeof(sa_listen));
715 fail_unless(
ret == 0);
716 ret = lwip_listen(sl, 0);
717 fail_unless(
ret == 0);
721 fail_unless(sact >= 0);
726 fail_unless(
ret == 0);
729 ret = lwip_connect(sact, (
struct sockaddr *)&sa_listen,
sizeof(sa_listen));
731 fail_unless((
ret == 0) || (
ret == -1));
744 ret = lwip_connect(sact, (
struct sockaddr *)&sa_listen,
sizeof(sa_listen));
746 fail_unless(
ret == -1);
752 tcpip_thread_poll_one();
753 tcpip_thread_poll_one();
754 tcpip_thread_poll_one();
755 tcpip_thread_poll_one();
758 fail_unless(
ret == 0);
761 spass = lwip_accept(sl,
NULL,
NULL);
762 fail_unless(spass >= 0);
765 ret = lwip_send(sact, txbuf,
sizeof(txbuf), 0);
766 fail_unless(
ret ==
sizeof(txbuf));
768 tcpip_thread_poll_one();
769 tcpip_thread_poll_one();
772 sact_sock = lwip_socket_dbg_get_socket(sact);
773 fail_unless(sact_sock !=
NULL);
774 if (sact_sock !=
NULL) {
775 struct netconn *sact_conn = sact_sock->conn;
776 fail_unless(sact_conn !=
NULL);
777 if (sact_conn !=
NULL) {
778 struct tcp_pcb *pcb = sact_conn->pcb.tcp;
779 fail_unless(pcb !=
NULL);
781 tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
782 pcb->local_port, pcb->remote_port);
786 tcpip_thread_poll_one();
787 tcpip_thread_poll_one();
790 ret = lwip_recv(spass, rxbuf,
sizeof(rxbuf), 0);
791 fail_unless(
ret > 0);
792 tcpip_thread_poll_one();
793 tcpip_thread_poll_one();
796 ret = lwip_recv(spass, rxbuf,
sizeof(rxbuf), 0);
797 fail_unless(
ret == -1);
800 tcpip_thread_poll_one();
801 tcpip_thread_poll_one();
804 ret = lwip_recv(spass, rxbuf,
sizeof(rxbuf), 0);
805 fail_unless(
ret == -1);
808 tcpip_thread_poll_one();
809 tcpip_thread_poll_one();
812 ret = lwip_recv(spass, rxbuf,
sizeof(rxbuf), 0);
813 fail_unless(
ret == -1);
816 tcpip_thread_poll_one();
817 tcpip_thread_poll_one();
820 ret = lwip_close(sl);
821 fail_unless(
ret == 0);
822 ret = lwip_close(sact);
823 fail_unless(
ret == 0);
825 ret = lwip_close(spass);
826 fail_unless(
ret == 0);
837 TESTFUNC(test_sockets_allfunctions_basic),
840 TESTFUNC(test_sockets_recv_after_rst),
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
static unsigned char bytes[4]
#define mem_free(ptr, bsize)
static void cleanup(void)
void * mem_calloc(mem_size_t count, mem_size_t size)
void * mem_malloc(mem_size_t size_in)
GLuint GLuint GLsizei GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum const GLvoid * addr
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define LWIP_UNUSED_ARG(x)
#define IN6ADDR_LOOPBACK_INIT
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
void lwip_check_ensure_no_alloc(unsigned int skip)
#define memcpy(s1, s2, n)
static struct test_info tests[]
__kernel_size_t msg_iovlen
static int test_sockets_get_used_count(void)
static void sockets_teardown(void)
static void sockets_setup(void)
Suite * sockets_suite(void)