You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/01 06:58:14 UTC

[incubator-nuttx-apps] branch master updated (c427f408c -> 3d0a49f33)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


    from c427f408c testing:add MTD Fail-safe config-data tests
     new a8d2924c5 examples/usrsocktest: correct return value check of dup2()
     new 5b47bc24a examples/usrsocktest: correct the check region of remote address
     new 046e83bec examples/usrsocktest: fix build break
     new 45a21aea8 examples/usrsocktest: add USRSOCK_REQUEST_IOCTL support
     new 6bc5196ff examples/usrsocktest: add some delay to wait the daemon task ready
     new 3d0a49f33 examples/usrsocktest: read from the closed remote should return EOF

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 examples/usrsocktest/usrsocktest_basic_daemon.c    |   2 +-
 examples/usrsocktest/usrsocktest_block_recv.c      |   6 +-
 examples/usrsocktest/usrsocktest_daemon.c          | 155 ++++++++++++++++++++-
 examples/usrsocktest/usrsocktest_noblock_recv.c    |   5 +-
 .../usrsocktest/usrsocktest_wake_with_signal.c     |   2 +
 5 files changed, 163 insertions(+), 7 deletions(-)


[incubator-nuttx-apps] 03/06: examples/usrsocktest: fix build break

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 046e83bec9ad3de739f4f488620969c883d373e5
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Aug 31 22:52:57 2022 +0800

    examples/usrsocktest: fix build break
    
    usrsocktest_wake_with_signal.c: In function ‘do_wake_test’:
    usrsocktest_wake_with_signal.c:553:16: error: ‘USEC_PER_MSEC’ undeclared (first use in this function)
      553 |   usleep(100 * USEC_PER_MSEC); /* Let worker thread proceed to blocking
          |                ^~~~~~~~~~~~~
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 examples/usrsocktest/usrsocktest_wake_with_signal.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/examples/usrsocktest/usrsocktest_wake_with_signal.c b/examples/usrsocktest/usrsocktest_wake_with_signal.c
index 438ed934d..7e49aa28a 100644
--- a/examples/usrsocktest/usrsocktest_wake_with_signal.c
+++ b/examples/usrsocktest/usrsocktest_wake_with_signal.c
@@ -29,6 +29,8 @@
 #include <errno.h>
 #include <poll.h>
 
+#include <nuttx/clock.h>
+
 #include "defines.h"
 
 /****************************************************************************


[incubator-nuttx-apps] 01/06: examples/usrsocktest: correct return value check of dup2()

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit a8d2924c55f349bb733c6b43ec4559665680e27e
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Aug 31 22:48:45 2022 +0800

    examples/usrsocktest: correct return value check of dup2()
    
    DUP(2) Linux Programmer's Manual
    
    NAME
           dup, dup2, dup3 - duplicate a file descriptor
    ...
    RETURN VALUE
           On success, these system calls return the new file descriptor.
           On error, -1 is returned, and errno is set appropriately.
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 examples/usrsocktest/usrsocktest_basic_daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/usrsocktest/usrsocktest_basic_daemon.c b/examples/usrsocktest/usrsocktest_basic_daemon.c
index 80021ba40..6387f7722 100644
--- a/examples/usrsocktest/usrsocktest_basic_daemon.c
+++ b/examples/usrsocktest/usrsocktest_basic_daemon.c
@@ -333,7 +333,7 @@ static void basic_daemon_dup2(FAR struct usrsocktest_daemon_conf_s *dconf)
   TEST_ASSERT_EQUAL(2, usrsocktest_daemon_get_num_active_sockets());
 
   ret = dup2(sd2, sd);
-  TEST_ASSERT_EQUAL(0, ret);
+  TEST_ASSERT_EQUAL(sd, ret);
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets());
 
   ret = close(sd2);


[incubator-nuttx-apps] 04/06: examples/usrsocktest: add USRSOCK_REQUEST_IOCTL support

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 45a21aea8e9ade6dd40b43d9e4c237b0f317dd24
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Aug 31 22:55:32 2022 +0800

    examples/usrsocktest: add USRSOCK_REQUEST_IOCTL support
    
    The test model of usrsock ioctl() has changed after file socket layer implemented from vfs,
    usrsock must implement the ioctl() hook to pass this test
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 examples/usrsocktest/usrsocktest_daemon.c | 142 +++++++++++++++++++++++++++++-
 1 file changed, 141 insertions(+), 1 deletion(-)

diff --git a/examples/usrsocktest/usrsocktest_daemon.c b/examples/usrsocktest/usrsocktest_daemon.c
index f948395e3..f9c80f84b 100644
--- a/examples/usrsocktest/usrsocktest_daemon.c
+++ b/examples/usrsocktest/usrsocktest_daemon.c
@@ -36,6 +36,7 @@
 #include <pthread.h>
 
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <nuttx/net/usrsock.h>
@@ -74,6 +75,7 @@ struct test_socket_s
   bool connect_refused:1;
   bool disconnected:1;
   int recv_avail_bytes;
+  int flags;
   FAR void *endp;
   struct usrsock_message_req_ack_s pending_resp;
 };
@@ -1333,7 +1335,12 @@ prepare:
 
   resp.reqack.head.flags = 0;
   resp.reqack.result = ret;
-  if (ret >= 0)
+  if (req->max_addrlen == 0)
+    {
+      resp.valuelen = 0;
+      resp.valuelen_nontrunc = sizeof(addr);
+    }
+  else if (ret >= 0)
     {
       resp.valuelen = sizeof(addr);
       resp.valuelen_nontrunc = sizeof(addr);
@@ -1380,6 +1387,133 @@ prepare:
   return OK;
 }
 
+static int ioctl_request(int fd, FAR struct daemon_priv_s *priv,
+                         FAR void *hdrbuf)
+{
+  FAR struct usrsock_request_ioctl_s *req = hdrbuf;
+  struct usrsock_message_datareq_ack_s resp = {
+  };
+
+  FAR struct test_socket_s *tsock;
+  uint32_t value;
+  ssize_t wlen;
+  ssize_t rlen;
+  int ret;
+
+  /* Check if this socket exists. */
+
+  tsock = test_socket_get(priv, req->usockid);
+  if (!tsock)
+    {
+      ret = -EBADFD;
+      goto prepare;
+    }
+
+  if (req->arglen != sizeof(value))
+    {
+      ret = -EINVAL;
+      goto prepare;
+    }
+
+  /* Read value. */
+
+  rlen = read(fd, &value, sizeof(value));
+  if (rlen < 0 || rlen < sizeof(value))
+    {
+      ret = -EFAULT;
+      goto prepare;
+    }
+
+  ret = OK;
+
+prepare:
+
+  /* Prepare response. */
+
+  resp.reqack.xid = req->head.xid;
+  resp.reqack.head.msgid  = USRSOCK_MESSAGE_RESPONSE_DATA_ACK;
+  resp.reqack.head.flags  = 0;
+  resp.reqack.head.events = 0;
+
+  if (priv->conf->delay_all_responses)
+    {
+      resp.reqack.head.flags = USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS;
+      resp.reqack.result = -EINPROGRESS;
+      resp.valuelen = 0;
+      resp.valuelen_nontrunc = 0;
+
+      /* Send ack response. */
+
+      wlen = write(fd, &resp, sizeof(resp));
+      if (wlen < 0)
+        {
+          return -errno;
+        }
+
+      if (wlen != sizeof(resp))
+        {
+          return -ENOSPC;
+        }
+
+      pthread_mutex_unlock(&daemon_mutex);
+      usleep(50 * 1000);
+      pthread_mutex_lock(&daemon_mutex);
+
+      /* Previous write was acknowledgment to request, informing that request
+       * is still in progress. Now write actual completion response.
+       */
+
+      resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK;
+      resp.reqack.head.flags &= ~USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS;
+    }
+
+  resp.reqack.head.flags = 0;
+  resp.reqack.result = ret;
+  if (ret >= 0)
+    {
+      resp.valuelen = sizeof(value);
+      resp.valuelen_nontrunc = sizeof(value);
+
+      tsock->flags |= value;
+      value = tsock->flags;
+    }
+  else
+    {
+      resp.valuelen = 0;
+    }
+
+  /* Send response. */
+
+  wlen = write(fd, &resp, sizeof(resp));
+  if (wlen < 0)
+    {
+      return -errno;
+    }
+
+  if (wlen != sizeof(resp))
+    {
+      return -ENOSPC;
+    }
+
+  if (resp.valuelen > 0)
+    {
+      /* Send address (value) */
+
+      wlen = write(fd, &value, resp.valuelen);
+      if (wlen < 0)
+        {
+          return -errno;
+        }
+
+      if (wlen != resp.valuelen)
+        {
+          return -ENOSPC;
+        }
+    }
+
+  return OK;
+}
+
 static int handle_usrsock_request(int fd, FAR struct daemon_priv_s *priv)
 {
   static const struct
@@ -1437,6 +1571,12 @@ static int handle_usrsock_request(int fd, FAR struct daemon_priv_s *priv)
           sizeof(struct usrsock_request_getsockname_s),
           getsockname_request,
         },
+
+      [USRSOCK_REQUEST_IOCTL] =
+        {
+          sizeof(struct usrsock_request_ioctl_s),
+          ioctl_request,
+        },
     };
 
   uint8_t hdrbuf[16];


[incubator-nuttx-apps] 06/06: examples/usrsocktest: read from the closed remote should return EOF

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 3d0a49f33e1122fc61fab8faeee797d2946bb43d
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Aug 31 23:33:29 2022 +0800

    examples/usrsocktest: read from the closed remote should return EOF
    
    fix usrsock remote_disconnect fail:
    
    nsh> usrsocktest
    ...
    Testing group "remote_disconnect" =>
            [TEST ASSERT FAILED!]
                    In function "receive":
                    line 497: Assertion `(ssize_t)((ret)) == (ssize_t)((0))' failed.
                            got value: -1
                            should be: 0
            Group "remote_disconnect": [FAILED]
    ...
    
    Reference:
    
    RECV(2)
    
    NAME
           recv, recvfrom, recvmsg - receive a message from a socket
    ...
    RETURN VALUE
    ...
           When a stream socket peer has performed an orderly shutdown,
           the return value will be 0 (the traditional "end-of-file" return).
    
           Datagram sockets in various domains (e.g., the UNIX and Internet domains)
           permit zero-length datagrams.  When such a datagram is received, the return value is 0.
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 examples/usrsocktest/usrsocktest_daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/usrsocktest/usrsocktest_daemon.c b/examples/usrsocktest/usrsocktest_daemon.c
index 849339ab1..9bdd8ccfe 100644
--- a/examples/usrsocktest/usrsocktest_daemon.c
+++ b/examples/usrsocktest/usrsocktest_daemon.c
@@ -856,7 +856,7 @@ static int recvfrom_request(int fd, FAR struct daemon_priv_s *priv,
 
   if (!tsock->connected)
     {
-      ret = -ENOTCONN;
+      ret = (tsock->endp) ? 0 : -ENOTCONN;
       goto prepare;
     }
 


[incubator-nuttx-apps] 02/06: examples/usrsocktest: correct the check region of remote address

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 5b47bc24ae824c0a33fffff8efaf8141ea1a810e
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Aug 31 22:51:02 2022 +0800

    examples/usrsocktest: correct the check region of remote address
    
    let us skip the sin_zero
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 examples/usrsocktest/usrsocktest_block_recv.c   | 6 ++++--
 examples/usrsocktest/usrsocktest_noblock_recv.c | 5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/examples/usrsocktest/usrsocktest_block_recv.c b/examples/usrsocktest/usrsocktest_block_recv.c
index d5126ca64..a6684380d 100644
--- a/examples/usrsocktest/usrsocktest_block_recv.c
+++ b/examples/usrsocktest/usrsocktest_block_recv.c
@@ -248,7 +248,8 @@ static void no_block_connect(FAR struct usrsocktest_daemon_conf_s *dconf)
   TEST_ASSERT_EQUAL(1, ret);
   TEST_ASSERT_EQUAL_UINT8_ARRAY("a", data, 1);
   TEST_ASSERT_EQUAL(sizeof(remoteaddr), addrlen);
-  TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, addrlen);
+  TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr,
+                                addrlen - sizeof(addr.sin_zero));
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets());
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets());
   TEST_ASSERT_EQUAL(6, usrsocktest_daemon_get_recv_bytes());
@@ -265,7 +266,8 @@ static void no_block_connect(FAR struct usrsocktest_daemon_conf_s *dconf)
   TEST_ASSERT_EQUAL(5, ret);
   TEST_ASSERT_EQUAL_UINT8_ARRAY("abcde", data, 5);
   TEST_ASSERT_EQUAL(sizeof(remoteaddr), addrlen);
-  TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, addrlen);
+  TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr,
+                                addrlen - sizeof(addr.sin_zero));
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets());
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets());
   TEST_ASSERT_EQUAL(11, usrsocktest_daemon_get_recv_bytes());
diff --git a/examples/usrsocktest/usrsocktest_noblock_recv.c b/examples/usrsocktest/usrsocktest_noblock_recv.c
index 585843fe1..01995f6d3 100644
--- a/examples/usrsocktest/usrsocktest_noblock_recv.c
+++ b/examples/usrsocktest/usrsocktest_noblock_recv.c
@@ -180,7 +180,8 @@ static void receive(struct usrsocktest_daemon_conf_s *dconf)
   TEST_ASSERT_EQUAL(3, ret);
   TEST_ASSERT_EQUAL_UINT8_ARRAY("abc", data, 3);
   TEST_ASSERT_EQUAL(addrlen, sizeof(remoteaddr));
-  TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr, addrlen);
+  TEST_ASSERT_EQUAL_UINT8_ARRAY(&remoteaddr, &addr,
+                                addrlen - sizeof(addr.sin_zero));
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets());
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets());
   TEST_ASSERT_EQUAL(datalen + ret, usrsocktest_daemon_get_recv_bytes());
@@ -365,7 +366,7 @@ static void delayed_connect(struct usrsocktest_daemon_conf_s *dconf)
                  &addrlen);
   TEST_ASSERT_EQUAL(-1, ret);
   TEST_ASSERT_EQUAL(EAGAIN, errno);
-  TEST_ASSERT_EQUAL(0, addrlen);
+  TEST_ASSERT_EQUAL(sizeof(remoteaddr), addrlen);
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_connected_sockets());
   TEST_ASSERT_EQUAL(1, usrsocktest_daemon_get_num_active_sockets());
   TEST_ASSERT_EQUAL(0, usrsocktest_daemon_get_send_bytes());


[incubator-nuttx-apps] 05/06: examples/usrsocktest: add some delay to wait the daemon task ready

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 6bc5196ff058b77f1e62d2283755728f7a2ee6f2
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Aug 31 23:05:38 2022 +0800

    examples/usrsocktest: add some delay to wait the daemon task ready
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 examples/usrsocktest/usrsocktest_daemon.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/examples/usrsocktest/usrsocktest_daemon.c b/examples/usrsocktest/usrsocktest_daemon.c
index f9c80f84b..849339ab1 100644
--- a/examples/usrsocktest/usrsocktest_daemon.c
+++ b/examples/usrsocktest/usrsocktest_daemon.c
@@ -2053,6 +2053,12 @@ errout_closepipe:
 out:
   pthread_mutex_unlock(&daemon_mutex);
   usrsocktest_dbg("ret: %d\n", ret);
+
+  if (ret == OK)
+    {
+      usleep(100);
+    }
+
   return ret;
 }
 
@@ -2329,6 +2335,11 @@ bool usrsocktest_send_delayed_command(const char cmd,
 
   sq_addlast(&delayed_cmd->node, &priv->delayed_cmd_threads);
 
+  if (ret == OK)
+    {
+      usleep(100);
+    }
+
   return true;
 }