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 2024/10/01 17:48:53 UTC

(nuttx-apps) branch master updated (302c1f9dc -> a5516121e)

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/nuttx-apps.git


    from 302c1f9dc drivertest_watchdog:change busyloop after capture.
     new 44239f11f apps/uorb: change nuttx/list to posix queue
     new 5b729162a system/uorb: support build in aosp
     new 5732c76f3 system/uorb: fix memory leak report by coverity
     new 686bab316 system/uorb: fix compile warning
     new aa5a38399 system/uorb: fix compile warning
     new 925efc231 system/uORB: using lib_sprintf to output va_format and printf normal info in aosp adb shell
     new 6c237cfbc system/uorb: add O_DIRECT to access sensor as wachers
     new b0b4ac0f3 system/uORB: return subscibe latency/interval
     new a5516121e uorb/flush: support flush operation

The 9 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:
 system/uorb/Kconfig          |   2 +-
 system/uorb/listener.c       |  97 ++++++++++-------
 system/uorb/sensor/topics.c  |   2 -
 system/uorb/test/unit_test.c | 250 ++++++++++++++++++++++++++++++-------------
 system/uorb/uORB/uORB.c      |  37 +++++--
 system/uorb/uORB/uORB.h      |  74 +++++++++++--
 6 files changed, 326 insertions(+), 136 deletions(-)


(nuttx-apps) 06/09: system/uORB: using lib_sprintf to output va_format and printf normal info in aosp adb shell

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/nuttx-apps.git

commit 925efc2314b86e832233bb5da1f9ffc8246d5072
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Sat Jun 15 16:38:00 2024 +0800

    system/uORB: using lib_sprintf to output va_format and printf normal info in aosp adb shell
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/uORB/uORB.c | 6 +++++-
 system/uorb/uORB/uORB.h | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c
index d979277cb..67bf6461b 100644
--- a/system/uorb/uORB/uORB.c
+++ b/system/uorb/uORB/uORB.c
@@ -348,11 +348,15 @@ int orb_sscanf(FAR const char *buf, FAR const char *format, FAR void *data)
 void orb_info(FAR const char *format, FAR const char *name,
               FAR const void *data)
 {
+  struct lib_stdoutstream_s stdoutstream;
   struct va_format vaf;
 
   vaf.fmt = format;
   vaf.va  = (va_list *)data;
-  uorbinfo_raw("%s(now:%" PRIu64 "):%pB\n", name, orb_absolute_time(), &vaf);
+
+  lib_stdoutstream(&stdoutstream, stdout);
+  lib_sprintf(&stdoutstream.common, "%s(now:%" PRIu64 "):%pB",
+              name, orb_absolute_time(), &vaf);
 }
 
 int orb_fprintf(FAR FILE *stream, FAR const char *format,
diff --git a/system/uorb/uORB/uORB.h b/system/uorb/uORB/uORB.h
index 1db6e78c2..a4ccf35dc 100644
--- a/system/uorb/uORB/uORB.h
+++ b/system/uorb/uORB/uORB.h
@@ -156,7 +156,7 @@ struct orb_handle_s
 #  define uorbdebug            uorbnone
 #endif
 
-#define uorbinfo_raw(fmt, ...) syslog(LOG_INFO, fmt "\n", ##__VA_ARGS__)
+#define uorbinfo_raw(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
 
 /* Generates a pointer to the uORB metadata structure for
  * a given topic.


(nuttx-apps) 05/09: system/uorb: fix compile warning

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/nuttx-apps.git

commit aa5a38399a2c805e67b86190ba50076decdd7326
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Wed Jun 5 16:36:38 2024 +0800

    system/uorb: fix compile warning
    
    1. add string.h becuase strlen in uORB.c
    2. add inttypes.h becuase PRIu64/... in sensor/*.c
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/uORB/uORB.c | 1 +
 system/uorb/uORB/uORB.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c
index 9d9f6ac75..d979277cb 100644
--- a/system/uorb/uORB/uORB.c
+++ b/system/uorb/uORB/uORB.c
@@ -28,6 +28,7 @@
 #include <sys/ioctl.h>
 #include <time.h>
 #include <unistd.h>
+#include <string.h>
 
 #include <nuttx/streams.h>
 #include <uORB/uORB.h>
diff --git a/system/uorb/uORB/uORB.h b/system/uorb/uORB/uORB.h
index ba0c9bcf0..1db6e78c2 100644
--- a/system/uorb/uORB/uORB.h
+++ b/system/uorb/uORB/uORB.h
@@ -36,6 +36,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <syslog.h>
+#include <inttypes.h>
 
 /****************************************************************************
  * Public Types


(nuttx-apps) 04/09: system/uorb: fix compile warning

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/nuttx-apps.git

commit 686bab3160cb9714f52ac9bc30f00df12d4bb944
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Tue Jun 4 14:54:00 2024 +0800

    system/uorb: fix compile warning
    
    apps/system/uorb/listener.c:543:38:
    warning: unused parameter 'file' [-Wunused-parameter]
                               FAR FILE *file)
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/listener.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/system/uorb/listener.c b/system/uorb/listener.c
index fa310e0f1..83b8efb17 100644
--- a/system/uorb/listener.c
+++ b/system/uorb/listener.c
@@ -551,6 +551,8 @@ static int listener_record(FAR const struct orb_metadata *meta, int fd,
     {
       ret = orb_fprintf(file, meta->o_format, buffer);
     }
+#else
+  (void)file;
 #endif
 
   return ret;


(nuttx-apps) 08/09: system/uORB: return subscibe latency/interval

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/nuttx-apps.git

commit b0b4ac0f39f4432abb1374e4db32078c951e21cd
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Thu May 9 12:29:52 2024 +0800

    system/uORB: return subscibe latency/interval
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/uORB/uORB.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c
index 67bf6461b..09f611c1b 100644
--- a/system/uorb/uORB/uORB.c
+++ b/system/uorb/uORB/uORB.c
@@ -246,16 +246,16 @@ int orb_set_interval(int fd, unsigned interval)
 
 int orb_get_interval(int fd, FAR unsigned *interval)
 {
-  struct sensor_state_s tmp;
+  struct sensor_ustate_s tmp;
   int ret;
 
-  ret = ioctl(fd, SNIOC_GET_STATE, (unsigned long)(uintptr_t)&tmp);
+  ret = ioctl(fd, SNIOC_GET_USTATE, (unsigned long)(uintptr_t)&tmp);
   if (ret < 0)
     {
       return ret;
     }
 
-  *interval = tmp.min_interval;
+  *interval = tmp.interval;
   return ret;
 }
 
@@ -276,16 +276,16 @@ int orb_set_batch_interval(int fd, unsigned batch_interval)
 
 int orb_get_batch_interval(int fd, FAR unsigned *batch_interval)
 {
-  struct sensor_state_s tmp;
+  struct sensor_ustate_s tmp;
   int ret;
 
-  ret = ioctl(fd, SNIOC_GET_STATE, (unsigned long)(uintptr_t)&tmp);
+  ret = ioctl(fd, SNIOC_GET_USTATE, (unsigned long)(uintptr_t)&tmp);
   if (ret < 0)
     {
       return ret;
     }
 
-  *batch_interval = tmp.min_latency;
+  *batch_interval = tmp.latency;
   return ret;
 }
 
@@ -367,4 +367,4 @@ int orb_fprintf(FAR FILE *stream, FAR const char *format,
   lib_stdoutstream(&stdoutstream, stream);
   return lib_bsprintf(&stdoutstream.common, format, data);
 }
-#endif
\ No newline at end of file
+#endif


(nuttx-apps) 01/09: apps/uorb: change nuttx/list to posix queue

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/nuttx-apps.git

commit 44239f11ff580361ae7cb91b2565afbb19bdafdb
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Wed Apr 3 20:35:37 2024 +0800

    apps/uorb: change nuttx/list to posix queue
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/listener.c | 92 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 55 insertions(+), 37 deletions(-)

diff --git a/system/uorb/listener.c b/system/uorb/listener.c
index 6f4af7808..2a2f77f88 100644
--- a/system/uorb/listener.c
+++ b/system/uorb/listener.c
@@ -22,11 +22,10 @@
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/list.h>
-
 #include <ctype.h>
 #include <errno.h>
 #include <dirent.h>
+#include <inttypes.h>
 #include <poll.h>
 #include <signal.h>
 #include <stdio.h>
@@ -34,6 +33,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <sys/queue.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -53,31 +53,35 @@
 
 struct listen_object_s
 {
-  struct list_node  node;         /* Node of object info list */
-  struct orb_object object;       /* Object id */
-  orb_abstime       timestamp;    /* Time of lastest generation  */
-  unsigned long     generation;   /* Latest generation */
-  FAR FILE         *file;
+  SLIST_ENTRY(listen_object_s) node; /* Node of object info list */
+
+  struct orb_object object; /* Object id */
+  orb_abstime timestamp;    /* Time of lastest generation */
+  unsigned long generation; /* Latest generation */
+  FAR FILE *file;
 };
 
+SLIST_HEAD(listen_list_s, listen_object_s);
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
 
 static int listener_get_state(FAR struct orb_object *object,
                               FAR struct orb_state *state);
-static int listener_add_object(FAR struct list_node *objlist,
+static int listener_add_object(FAR struct listen_list_s *objlist,
                                FAR struct orb_object *object);
-static void listener_delete_object_list(FAR struct list_node *objlist);
-static int listener_generate_object_list(FAR struct list_node *objlist,
+static void listener_delete_object_list(FAR struct listen_list_s *objlist);
+static int listener_generate_object_list(FAR struct listen_list_s *objlist,
                                          FAR const char *filter);
 static int listener_print(FAR const struct orb_metadata *meta, int fd);
-static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
-                             float topic_rate, int topic_latency,
-                             int nb_msgs, int timeout, bool record);
-static int listener_update(FAR struct list_node *objlist,
+static void listener_monitor(FAR struct listen_list_s *objlist,
+                             int nb_objects, float topic_rate,
+                             int topic_latency, int nb_msgs,
+                             int timeout, bool record);
+static int listener_update(FAR struct listen_list_s *objlist,
                            FAR struct orb_object *object);
-static void listener_top(FAR struct list_node *objlist,
+static void listener_top(FAR struct listen_list_s *objlist,
                          FAR const char *filter,
                          bool only_once);
 static int listener_create_dir(FAR char *dir, size_t size);
@@ -215,7 +219,7 @@ static int listener_get_state(FAR struct orb_object *object,
  *   0 on success, otherwise return negative errno.
  ****************************************************************************/
 
-static int listener_add_object(FAR struct list_node *objlist,
+static int listener_add_object(FAR struct listen_list_s *objlist,
                                FAR struct orb_object *object)
 {
   FAR struct listen_object_s *tmp;
@@ -234,7 +238,7 @@ static int listener_add_object(FAR struct list_node *objlist,
   tmp->timestamp       = orb_absolute_time();
   tmp->generation      = ret < 0 ? 0 : state.generation;
   tmp->file            = NULL;
-  list_add_tail(objlist, &tmp->node);
+  SLIST_INSERT_HEAD(objlist, tmp, node);
   return 0;
 }
 
@@ -252,7 +256,7 @@ static int listener_add_object(FAR struct list_node *objlist,
  *   0 on success.
  ****************************************************************************/
 
-static int listener_update(FAR struct list_node *objlist,
+static int listener_update(FAR struct listen_list_s *objlist,
                            FAR struct orb_object *object)
 {
   FAR struct listen_object_s *old = NULL;
@@ -261,7 +265,7 @@ static int listener_update(FAR struct list_node *objlist,
 
   /* Check wether object already exist in old list */
 
-  list_for_every_entry(objlist, tmp, struct listen_object_s, node)
+  SLIST_FOREACH(tmp, objlist, node)
     {
       if (tmp->object.meta == object->meta &&
           tmp->object.instance == object->instance)
@@ -335,18 +339,18 @@ static int listener_update(FAR struct list_node *objlist,
  *   None.
  ****************************************************************************/
 
-static void listener_delete_object_list(FAR struct list_node *objlist)
+static void listener_delete_object_list(FAR struct listen_list_s *objlist)
 {
   FAR struct listen_object_s *tmp;
-  FAR struct listen_object_s *next;
 
-  list_for_every_entry_safe(objlist, tmp, next, struct listen_object_s, node)
+  while (!SLIST_EMPTY(objlist))
     {
-      list_delete(&tmp->node);
+      tmp = SLIST_FIRST(objlist);
+      SLIST_REMOVE_HEAD(objlist, node);
       free(tmp);
     }
 
-  list_initialize(objlist);
+  SLIST_INIT(objlist);
 }
 
 /****************************************************************************
@@ -364,7 +368,7 @@ static void listener_delete_object_list(FAR struct list_node *objlist)
  *   Negative errno on failure.
  ****************************************************************************/
 
-static int listener_generate_object_list(FAR struct list_node *objlist,
+static int listener_generate_object_list(FAR struct listen_list_s *objlist,
                                          FAR const char *filter)
 {
   FAR struct dirent *entry;
@@ -570,9 +574,10 @@ static int listener_record(FAR const struct orb_metadata *meta, int fd,
  *   None
  ****************************************************************************/
 
-static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
-                             float topic_rate, int topic_latency,
-                             int nb_msgs, int timeout, bool record)
+static void listener_monitor(FAR struct listen_list_s *objlist,
+                             int nb_objects, float topic_rate,
+                             int topic_latency, int nb_msgs,
+                             int timeout, bool record)
 {
   FAR struct pollfd *fds;
   char path[PATH_MAX];
@@ -599,7 +604,7 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
 
   /* Prepare pollfd for all objects */
 
-  list_for_every_entry(objlist, tmp, struct listen_object_s, node)
+  SLIST_FOREACH(tmp, objlist, node)
     {
       int fd;
 
@@ -634,7 +639,7 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
       listener_create_dir(path, sizeof(path));
       dir = path + strlen(path);
 
-      list_for_every_entry(objlist, tmp, struct listen_object_s, node)
+      SLIST_FOREACH(tmp, objlist, node)
         {
           sprintf(dir, "%s%d.csv", tmp->object.meta->o_name,
                   tmp->object.instance);
@@ -664,7 +669,7 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
       if (poll(&fds[0], nb_objects, timeout * 1000) > 0)
         {
           i = 0;
-          list_for_every_entry(objlist, tmp, struct listen_object_s, node)
+          SLIST_FOREACH(tmp, objlist, node)
             {
               if (fds[i].revents & POLLIN)
                 {
@@ -706,7 +711,7 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
     }
 
   i = 0;
-  list_for_every_entry(objlist, tmp, struct listen_object_s, node)
+  SLIST_FOREACH(tmp, objlist, node)
     {
       if (fds[i].fd < 0)
         {
@@ -757,7 +762,20 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
  *   None.
  ****************************************************************************/
 
-static void listener_top(FAR struct list_node *objlist,
+static size_t listen_length(FAR struct listen_list_s *objlist)
+{
+  struct listen_object_s *tmp;
+  size_t count = 0;
+
+  SLIST_FOREACH(tmp, objlist, node)
+    {
+      count++;
+    }
+
+  return count;
+}
+
+static void listener_top(FAR struct listen_list_s *objlist,
                          FAR const char *filter,
                          bool only_once)
 {
@@ -791,7 +809,7 @@ static void listener_top(FAR struct list_node *objlist,
           uorbinfo_raw("\033[H"); /* move cursor to top left corner */
         }
 
-      uorbinfo_raw("\033[K" "current objects: %zu", list_length(objlist));
+      uorbinfo_raw("\033[K" "current objects: %zu", listen_length(objlist));
       uorbinfo_raw("\033[K" "%-*s INST #SUB RATE #Q SIZE",
                    ORB_MAX_PRINT_NAME - 2, "NAME");
 
@@ -820,8 +838,8 @@ static void exit_handler(int signo)
 
 int main(int argc, FAR char *argv[])
 {
-  struct list_node objlist;
   FAR struct listen_object_s *tmp;
+  struct listen_list_s objlist;
   float topic_rate = 0;
   int topic_latency = 0;
   int nb_msgs       = 0;
@@ -904,7 +922,7 @@ int main(int argc, FAR char *argv[])
 
   /* Alloc list and exec command */
 
-  list_initialize(&objlist);
+  SLIST_INIT(&objlist);
   ret = listener_generate_object_list(&objlist, filter);
   if (ret <= 0)
     {
@@ -918,7 +936,7 @@ int main(int argc, FAR char *argv[])
   else
     {
       uorbinfo_raw("\nMointor objects num:%d", ret);
-      list_for_every_entry(&objlist, tmp, struct listen_object_s, node)
+      SLIST_FOREACH(tmp, &objlist, node)
         {
           uorbinfo_raw("object_name:%s, object_instance:%d",
                        tmp->object.meta->o_name,


(nuttx-apps) 09/09: uorb/flush: support flush operation

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/nuttx-apps.git

commit a5516121e21bd48cffcde0cbed7cb87d0a1a8168
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Tue Apr 2 20:15:10 2024 +0800

    uorb/flush: support flush operation
    
    After you call orb_flush(), you can determine whether the
    flush is completed by listening to the POLLPRI event
    of fd and getting the event in orb_get_events.
    
    After calling orb_get_events, the flush events will be cleared.
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/uORB/uORB.c | 15 +++++++++++++++
 system/uorb/uORB/uORB.h | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c
index 09f611c1b..4efac9bce 100644
--- a/system/uorb/uORB/uORB.c
+++ b/system/uorb/uORB/uORB.c
@@ -229,6 +229,16 @@ int orb_get_state(int fd, FAR struct orb_state *state)
   return ret;
 }
 
+int orb_get_events(int fd, FAR unsigned int *events)
+{
+  if (!events)
+    {
+      return -EINVAL;
+    }
+
+  return ioctl(fd, SNIOC_GET_EVENTS, (unsigned long)(uintptr_t)events);
+}
+
 int orb_check(int fd, FAR bool *updated)
 {
   return ioctl(fd, SNIOC_UPDATED, (unsigned long)(uintptr_t)updated);
@@ -239,6 +249,11 @@ int orb_ioctl(int fd, int cmd, unsigned long arg)
   return ioctl(fd, cmd, arg);
 }
 
+int orb_flush(int fd)
+{
+  return ioctl(fd, SNIOC_FLUSH, 0);
+}
+
 int orb_set_interval(int fd, unsigned interval)
 {
   return ioctl(fd, SNIOC_SET_INTERVAL, (unsigned long)interval);
diff --git a/system/uorb/uORB/uORB.h b/system/uorb/uORB/uORB.h
index a4ccf35dc..212789918 100644
--- a/system/uorb/uORB/uORB.h
+++ b/system/uorb/uORB/uORB.h
@@ -114,6 +114,8 @@ struct orb_handle_s
  * Pre-processor Definitions
  ****************************************************************************/
 
+#define ORB_EVENT_FLUSH_COMPLETE SENSOR_EVENT_FLUSH_COMPLETE
+
 #define ORB_SENSOR_PATH        "/dev/uorb/"
 #define ORB_USENSOR_PATH       "/dev/usensor"
 #define ORB_PATH_MAX           (NAME_MAX + 16)
@@ -521,6 +523,23 @@ static inline int orb_copy(FAR const struct orb_metadata *meta,
 
 int orb_get_state(int fd, FAR struct orb_state *state);
 
+/****************************************************************************
+ * Name: orb_get_events
+ *
+ * Description:
+ *   Get the events about the specify subscriber of topic.
+ *
+ * Input Parameters:
+ *   fd       The fd returned from orb_advertise / orb_subscribe.
+ *   events   Pointer to events, type is unsigned int pointer.
+ *            eg: ORB_EVENT_FLUSH_COMPLETE
+ *
+ * Returned Value:
+ *   -1 on error.
+ ****************************************************************************/
+
+int orb_get_events(int fd, FAR unsigned int *events);
+
 /****************************************************************************
  * Name: orb_check
  *
@@ -563,6 +582,27 @@ int orb_check(int fd, FAR bool *updated);
 
 int orb_ioctl(int fd, int cmd, unsigned long arg);
 
+/****************************************************************************
+ * Name: orb_flush
+ *
+ * Description:
+ *   When topic data accumulates in the hardware buffer but does not reach
+ *   the watermark, you can mmediately read the fifo data through the flush
+ *   operation. You can call the flush operation at any time.
+ *
+ *   After you call flush, you can determine whether the flush is completed
+ *   by listening to the POLLPRI event of fd and getting the event in
+ *   orb_get_events
+ *
+ * Input Parameters:
+ *   fd       A fd returned from orb_advertise / orb_subscribe.
+ *
+ * Returned Value:
+ *   0 on success.
+ ****************************************************************************/
+
+int orb_flush(int fd);
+
 /****************************************************************************
  * Name: orb_set_batch_interval
  *


(nuttx-apps) 02/09: system/uorb: support build in aosp

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/nuttx-apps.git

commit 5b729162ad06de1b7fe9cbb60fd84791a881b9b0
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Wed Apr 3 17:50:07 2024 +0800

    system/uorb: support build in aosp
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/Kconfig          |  2 +-
 system/uorb/listener.c       |  1 +
 system/uorb/sensor/topics.c  |  2 -
 system/uorb/test/unit_test.c | 87 ++++++++++++++++++++++++++------------------
 system/uorb/uORB/uORB.c      |  1 +
 system/uorb/uORB/uORB.h      | 31 +++++++++++-----
 6 files changed, 76 insertions(+), 48 deletions(-)

diff --git a/system/uorb/Kconfig b/system/uorb/Kconfig
index ba99d2907..576751abb 100644
--- a/system/uorb/Kconfig
+++ b/system/uorb/Kconfig
@@ -32,7 +32,7 @@ config UORB_LOOP_MAX_EVENTS
 
 if UORB_TESTS
 
-config UORB_SRORAGE_DIR
+config UORB_STORAGE_DIR
 	string "uorb test result storage dir"
 	default "/data/"
 
diff --git a/system/uorb/listener.c b/system/uorb/listener.c
index 2a2f77f88..fa310e0f1 100644
--- a/system/uorb/listener.c
+++ b/system/uorb/listener.c
@@ -829,6 +829,7 @@ static void listener_top(FAR struct listen_list_s *objlist,
 
 static void exit_handler(int signo)
 {
+  (void)signo;
   g_should_exit = true;
 }
 
diff --git a/system/uorb/sensor/topics.c b/system/uorb/sensor/topics.c
index 7c66569ae..f12db068f 100644
--- a/system/uorb/sensor/topics.c
+++ b/system/uorb/sensor/topics.c
@@ -22,8 +22,6 @@
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/config.h>
-
 #include <ctype.h>
 #include <fcntl.h>
 #include <stdio.h>
diff --git a/system/uorb/test/unit_test.c b/system/uorb/test/unit_test.c
index 81f2355a8..fc8d340e2 100644
--- a/system/uorb/test/unit_test.c
+++ b/system/uorb/test/unit_test.c
@@ -25,15 +25,23 @@
 #include <errno.h>
 #include <math.h>
 #include <poll.h>
+#include <inttypes.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/param.h>
+#include <sched.h>
+#include <pthread.h>
 
 #include "utility.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define nitems(_a) (sizeof(_a) / sizeof(0[(_a)]))
+
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -48,7 +56,7 @@ static int           g_pubsubtest_res;
  * Private Functions
  ****************************************************************************/
 
-static int pubsubtest_thread_entry(int argc, FAR char *argv[])
+static FAR void *pubsubtest_thread_entry(FAR void *arg)
 {
   /* poll on test topic and output latency */
 
@@ -68,10 +76,11 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[])
   unsigned timing_max = 0;
   unsigned i;
 
+  (void)arg;
   timings = malloc(MAX_RUNS * sizeof(unsigned));
   if (timings == NULL)
     {
-      return -ENOMEM;
+      return NULL;
     }
 
   /* clear all ready flags */
@@ -117,7 +126,7 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[])
 
       if (pret < 0)
         {
-          snerr("poll error %d, %d", pret, errno);
+          printf("poll error %d, %d", pret, errno);
           continue;
         }
     }
@@ -130,14 +139,14 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[])
       FAR FILE *f;
 
       snprintf(fname, sizeof(fname),
-               CONFIG_UORB_SRORAGE_DIR"/uorb_timings%u.txt", timingsgroup);
+               UORB_STORAGE_DIR"/uorb_timings%u.txt", timingsgroup);
 
       f = fopen(fname, "w");
       if (f == NULL)
         {
-          snerr("Error opening file!");
+          printf("Error opening file!");
           free(timings);
-          return ERROR;
+          return NULL;
         }
 
       for (i = 0; i < MAX_RUNS; i++)
@@ -177,13 +186,13 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[])
     }
 
   free(timings);
-  return g_pubsubtest_res;
+  return NULL;
 }
 
 static int latency_test(bool print)
 {
   struct orb_test_medium_s sample;
-  int pubsub_task;
+  pthread_t pubsub_task;
   int instance = 0;
   int fd;
 
@@ -202,11 +211,10 @@ static int latency_test(bool print)
   g_pubsubtest_print  = print;
   g_pubsubtest_passed = false;
 
-  pubsub_task = task_create("uorb_latency",
-                            SCHED_PRIORITY_DEFAULT,
-                            CONFIG_UORB_STACKSIZE,
-                            pubsubtest_thread_entry,
-                            NULL);
+  if (pthread_create(&pubsub_task, NULL, pubsubtest_thread_entry, NULL) < 0)
+    {
+      return test_fail("failed launching task");
+    }
 
   /* give the test task some data */
 
@@ -605,7 +613,7 @@ static int test_unadvertise(int *afds)
   return OK;
 }
 
-static int pub_test_multi2_entry(int argc, char *argv[])
+static FAR void *pub_test_multi2_entry(FAR void *arg)
 {
   struct orb_test_medium_s data_topic;
   const int num_instances = 3;
@@ -615,6 +623,7 @@ static int pub_test_multi2_entry(int argc, char *argv[])
   int num_messages = 50 * num_instances;
   int i;
 
+  (void)arg;
   memset(&data_topic, '\0', sizeof(data_topic));
   for (i = 0; i < num_instances; ++i)
     {
@@ -650,7 +659,7 @@ static int pub_test_multi2_entry(int argc, char *argv[])
       orb_unadvertise(orb_pub[i]);
     }
 
-  return OK;
+  return NULL;
 }
 
 static int test_multi2(void)
@@ -659,7 +668,9 @@ static int test_multi2(void)
   int orb_data_fd[num_instances];
   int orb_data_next     = 0;
   orb_abstime last_time = 0;
-  int pubsub_task;
+  struct sched_param param;
+  pthread_attr_t attr;
+  pthread_t pubsub_task;
   int i;
 
   test_note("Testing multi-topic 2 test (queue simulation)");
@@ -675,16 +686,18 @@ static int test_multi2(void)
 
   /* launch the publisher thread */
 
-  pubsub_task = task_create("uorb_test_multi",
-                            SCHED_PRIORITY_MAX - 5,
-                            CONFIG_UORB_STACKSIZE,
-                            pub_test_multi2_entry,
-                            NULL);
-  if (pubsub_task < 0)
+  pthread_attr_init(&attr);
+  param.sched_priority = sched_get_priority_max(0) - 5;
+  pthread_attr_setschedparam(&attr, &param);
+
+  if (pthread_create(&pubsub_task, &attr, pub_test_multi2_entry, NULL) < 0)
     {
+      pthread_attr_destroy(&attr);
       return test_fail("failed launching task");
     }
 
+  pthread_attr_destroy(&attr);
+
   /* loop check update and copy new data */
 
   while (!g_thread_should_exit)
@@ -873,7 +886,7 @@ int test_queue(void)
   return test_note("PASS orb queuing");
 }
 
-static int pub_test_queue_entry(int argc, char *argv[])
+static FAR void *pub_test_queue_entry(FAR void *arg)
 {
   const int queue_size = 50;
   struct orb_test_medium_s t;
@@ -882,13 +895,15 @@ static int pub_test_queue_entry(int argc, char *argv[])
   int instance = 0;
   int ptopic;
 
+  (void)arg;
   memset(&t, '\0', sizeof(t));
   ptopic = orb_advertise_multi_queue_persist(
     ORB_ID(orb_test_medium_queue_poll), &t, &instance, queue_size);
   if (ptopic < 0)
     {
       g_thread_should_exit = true;
-      return test_fail("advertise failed: %d", errno);
+      test_fail("advertise failed: %d", errno);
+      return NULL;
     }
 
   ++t.val;
@@ -915,17 +930,18 @@ static int pub_test_queue_entry(int argc, char *argv[])
   usleep(100 * 1000);
   g_thread_should_exit = true;
   orb_unadvertise(ptopic);
-
-  return 0;
+  return NULL;
 }
 
 static int test_queue_poll_notify(void)
 {
   struct pollfd fds[1];
   struct orb_test_medium_s t;
+  struct sched_param param;
+  pthread_attr_t attr;
   bool updated;
   int next_expected_val = 0;
-  int pubsub_task;
+  pthread_t pubsub_task;
   int sfd;
 
   test_note("Testing orb queuing (poll & notify)");
@@ -951,17 +967,18 @@ static int test_queue_poll_notify(void)
 
   g_thread_should_exit = false;
 
-  pubsub_task = task_create("uorb_test_queue",
-                            SCHED_PRIORITY_MIN + 5,
-                            CONFIG_UORB_STACKSIZE,
-                            pub_test_queue_entry,
-                            NULL);
+  pthread_attr_init(&attr);
+  param.sched_priority = sched_get_priority_min(0) + 5;
+  pthread_attr_setschedparam(&attr, &param);
 
-  if (pubsub_task < 0)
+  if (pthread_create(&pubsub_task, &attr, pub_test_queue_entry, NULL) < 0)
     {
-      return test_fail("failed launching task");
+      pthread_attr_destroy(&attr);
+      return test_fail("failed test queue task");
     }
 
+  pthread_attr_destroy(&attr);
+
   fds[0].fd     = sfd;
   fds[0].events = POLLIN;
 
diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c
index cf3f70cb8..9d9f6ac75 100644
--- a/system/uorb/uORB/uORB.c
+++ b/system/uorb/uORB/uORB.c
@@ -26,6 +26,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <sys/ioctl.h>
+#include <time.h>
 #include <unistd.h>
 
 #include <nuttx/streams.h>
diff --git a/system/uorb/uORB/uORB.h b/system/uorb/uORB/uORB.h
index 448324f74..ba0c9bcf0 100644
--- a/system/uorb/uORB/uORB.h
+++ b/system/uorb/uORB/uORB.h
@@ -25,10 +25,13 @@
  * Included Files
  ****************************************************************************/
 
+#ifdef __NuttX__
 #include <nuttx/uorb.h>
+#else
+#include <linux/uorb.h>
+#endif
 
 #include <sys/time.h>
-#include <debug.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -114,34 +117,42 @@ struct orb_handle_s
 #define ORB_USENSOR_PATH       "/dev/usensor"
 #define ORB_PATH_MAX           (NAME_MAX + 16)
 
+#ifdef CONFIG_UORB_STORAGE_DIR
+#define UORB_STORAGE_DIR       CONFIG_UORB_STORAGE_DIR
+#else
+#define UORB_STORAGE_DIR       "/data"
+#endif
+
+#define uorbnone(fmt, ...)     do { if (0) syslog(LOG_INFO, fmt, ##__VA_ARGS__); } while (0)
+
 #ifdef CONFIG_UORB_ALERT
-#  define uorbpanic(fmt, ...)  _alert(fmt "\n", ##__VA_ARGS__)
+#  define uorbpanic(fmt, ...)  syslog(LOG_EMERGY, fmt "\n", ##__VA_ARGS__)
 #else
-#  define uorbpanic            _none
+#  define uorbpanic            uorbnone
 #endif
 
 #ifdef CONFIG_UORB_ERROR
-#  define uorberr(fmt, ...)    _err(fmt "\n", ##__VA_ARGS__)
+#  define uorberr(fmt, ...)    syslog(LOG_ERR, fmt "\n", ##__VA_ARGS__)
 #else
-#  define uorberr              _none
+#  define uorberr              uorbnone
 #endif
 
 #ifdef CONFIG_UORB_WARN
-#  define uorbwarn(fmt, ...)   _warn(fmt "\n", ##__VA_ARGS__)
+#  define uorbwarn(fmt, ...)   syslog(LOG_WARN, fmt "\n", ##__VA_ARGS__)
 #else
-#  define uorbwarn             _none
+#  define uorbwarn             uorbnone
 #endif
 
 #ifdef CONFIG_UORB_INFO
-#  define uorbinfo(fmt, ...)   _info(fmt "\n", ##__VA_ARGS__)
+#  define uorbinfo(fmt, ...)   syslog(LOG_INFO, fmt "\n", ##__VA_ARGS__)
 #else
-#  define uorbinfo             _none
+#  define uorbinfo             uorbnone
 #endif
 
 #ifdef CONFIG_DEBUG_UORB
 #  define uorbdebug(fmt, ...)  syslog(LOG_INFO, fmt "\n", ##__VA_ARGS__)
 #else
-#  define uorbdebug            _none
+#  define uorbdebug            uorbnone
 #endif
 
 #define uorbinfo_raw(fmt, ...) syslog(LOG_INFO, fmt "\n", ##__VA_ARGS__)


(nuttx-apps) 03/09: system/uorb: fix memory leak report by coverity

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/nuttx-apps.git

commit 5732c76f39a95cf586ac35e93cdaeeafc50ca5d1
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Sun Apr 21 15:04:31 2024 +0800

    system/uorb: fix memory leak report by coverity
    
    nsh> uorb_unit_test
    uORB note: try single-topic support
    uORB note: PASS single-topic test
    uORB note: PASS orb 10-instances
    uORB note: try multi-topic support
    uORB note: ---------------- LATENCY TEST ------------------
    mean:    0 us
    std dev: 0 us
    min:     0 us
    max:     0 us
    missed topic updates: 0
    uORB note: PASS multi-topic test
    uORB note: try multi-topic support subscribing before publishing
    uORB note: PASS multi-topic reversed
    uORB note: Testing unadvertise
    uORB note: Testing multi-topic 2 test (queue simulation)
    uORB note: PASS multi-topic 2 test (queue simulation)
    uORB note: Testing orb queuing
    uORB note:   Testing to write some elements...
    uORB note:   Testing overflow...
    uORB note:   Testing underflow...
    uORB note: PASS orb queuing
    uORB note: Testing orb queuing (poll & notify)
    PASS
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/test/unit_test.c | 165 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 123 insertions(+), 42 deletions(-)

diff --git a/system/uorb/test/unit_test.c b/system/uorb/test/unit_test.c
index fc8d340e2..901d0a794 100644
--- a/system/uorb/test/unit_test.c
+++ b/system/uorb/test/unit_test.c
@@ -194,6 +194,7 @@ static int latency_test(bool print)
   struct orb_test_medium_s sample;
   pthread_t pubsub_task;
   int instance = 0;
+  int ret = ERROR;
   int fd;
 
   test_note("---------------- LATENCY TEST ------------------");
@@ -213,7 +214,8 @@ static int latency_test(bool print)
 
   if (pthread_create(&pubsub_task, NULL, pubsubtest_thread_entry, NULL) < 0)
     {
-      return test_fail("failed launching task");
+      test_fail("failed launching task");
+      goto out;
     }
 
   /* give the test task some data */
@@ -224,7 +226,8 @@ static int latency_test(bool print)
       sample.timestamp = orb_absolute_time();
       if (OK != orb_publish(ORB_ID(orb_test_medium), fd, &sample))
         {
-          return test_fail("mult. pub0 timing fail");
+          test_fail("mult. pub0 timing fail");
+          goto out;
         }
 
       usleep(1000); /* simulate >800 Hz system operation */
@@ -232,11 +235,15 @@ static int latency_test(bool print)
 
   if (pubsub_task < 0)
     {
-      return test_fail("failed launching task");
+      test_fail("failed launching task");
+      goto out;
     }
 
+  ret = OK;
+
+out:
   orb_unadvertise(fd);
-  return g_pubsubtest_res;
+  return ret < 0 ? ret : g_pubsubtest_res;
 }
 
 static int test_single(void)
@@ -247,7 +254,7 @@ static int test_single(void)
   bool updated;
   int afd;
   int sfd;
-  int ret;
+  int ret = ERROR;
 
   test_note("try single-topic support");
 
@@ -265,6 +272,7 @@ static int test_single(void)
   sfd = orb_subscribe(ORB_ID(orb_test));
   if (sfd < 0)
     {
+      orb_unadvertise(afd);
       return test_fail("subscribe failed: %d", errno);
     }
 
@@ -274,23 +282,27 @@ static int test_single(void)
 
   if (OK != orb_copy(ORB_ID(orb_test), sfd, &sub_sample))
     {
-      return test_fail("copy(1) failed: %d", errno);
+      test_fail("copy(1) failed: %d", errno);
+      goto out;
     }
 
   if (sample.val != sub_sample.val)
     {
-      return test_fail("copy(1) mismatch: %d expected %d",
-                       sub_sample.val, sample.val);
+      test_fail("copy(1) mismatch: %d expected %d",
+                sub_sample.val, sample.val);
+      goto out;
     }
 
   if (OK != orb_check(sfd, &updated))
     {
-      return test_fail("check(1) failed");
+      test_fail("check(1) failed");
+      goto out;
     }
 
   if (updated)
     {
-      return test_fail("spurious updated flag");
+      test_fail("spurious updated flag");
+      goto out;
     }
 
   /* check second publish */
@@ -299,45 +311,56 @@ static int test_single(void)
 
   if (OK != orb_publish(ORB_ID(orb_test), afd, &sample))
     {
-      return test_fail("publish failed");
+      test_fail("publish failed");
+      goto out;
     }
 
   if (OK != orb_check(sfd, &updated))
     {
-      return test_fail("check(2) failed");
+      test_fail("check(2) failed");
+      goto out;
     }
 
   if (!updated)
     {
-      return test_fail("missing updated flag");
+      test_fail("missing updated flag");
+      goto out;
     }
 
   if (OK != orb_copy(ORB_ID(orb_test), sfd, &sub_sample))
     {
-      return test_fail("copy(2) failed: %d", errno);
+      test_fail("copy(2) failed: %d", errno);
+      goto out;
     }
 
   if (sample.val != sub_sample.val)
     {
-      return test_fail("copy(2) mismatch: %d expected %d",
-                       sub_sample.val, sample.val);
+      test_fail("copy(2) mismatch: %d expected %d",
+                sub_sample.val, sample.val);
+      goto out;
     }
 
   /* unadvertise and out */
 
+out:
   ret = orb_unadvertise(afd);
   if (ret != OK)
     {
-      return test_fail("orb_unadvertise failed: %i", ret);
+      test_fail("orb_unadvertise failed: %i", ret);
     }
 
   ret = orb_unsubscribe(sfd);
   if (ret != OK)
     {
-      return test_fail("orb_unsubscribe failed: %i", ret);
+      test_fail("orb_unsubscribe failed: %i", ret);
     }
 
-  return test_note("PASS single-topic test");
+  if (ret == OK)
+    {
+      test_note("PASS single-topic test");
+    }
+
+  return ret;
 }
 
 static int test_multi_inst10(void)
@@ -345,6 +368,7 @@ static int test_multi_inst10(void)
   const int max_inst = 10;
   int sfd[max_inst];
   int afd[max_inst];
+  int ret = ERROR;
   int i;
   int j;
 
@@ -359,7 +383,8 @@ static int test_multi_inst10(void)
     {
       if (OK == orb_exists(ORB_ID(orb_test), i))
         {
-          return test_fail("sub %d is advertised", i);
+          test_fail("sub %d is advertised", i);
+          goto out_with_sfd;
         }
     }
 
@@ -369,9 +394,16 @@ static int test_multi_inst10(void)
     {
       afd[i] = orb_advertise_multi_queue_persist(ORB_ID(orb_test),
                                                  NULL, &i, 1);
+    }
+
+  /* verify advertised yet */
+
+  for (i = 0; i < max_inst; i++)
+    {
       if (OK != orb_exists(ORB_ID(orb_test), i))
         {
-          return test_fail("sub %d advertise failed", i);
+          test_fail("sub %d advertise failed", i);
+          goto out_with_sfd;
         }
     }
 
@@ -401,7 +433,8 @@ static int test_multi_inst10(void)
               orb_check(sfd[sub_instance], &updated);
               if (!updated)
                 {
-                  return test_fail("sub %d not updated", sub_instance);
+                  test_fail("sub %d not updated", sub_instance);
+                  goto out;
                 }
               else
                 {
@@ -409,14 +442,16 @@ static int test_multi_inst10(void)
 
                   if (orb_copy(ORB_ID(orb_test), sfd[sub_instance], &sample))
                     {
-                      return test_fail("sub %d copy failed", sub_instance);
+                      test_fail("sub %d copy failed", sub_instance);
+                      goto out;
                     }
                   else
                     {
                       if (sample.val != (j * sub_instance + i))
                         {
-                          return test_fail("sub %d invalid value %d",
-                                           sub_instance, sample.val);
+                          test_fail("sub %d invalid value %d",
+                                    sub_instance, sample.val);
+                          goto out;
                         }
                     }
                 }
@@ -424,14 +459,26 @@ static int test_multi_inst10(void)
         }
     }
 
-  /* force unsubscribe all, then repeat */
+  ret = OK;
 
+out:
+  for (i = 0; i < max_inst; i++)
+    {
+      orb_unadvertise(afd[i]);
+    }
+
+out_with_sfd:
   for (i = 0; i < max_inst; i++)
     {
       orb_unsubscribe(sfd[i]);
     }
 
-  return test_note("PASS orb 10-instances");
+  if (ret == OK)
+    {
+      test_note("PASS orb 10-instances");
+    }
+
+  return ret;
 }
 
 static int test_multi(int *afds, int *sfds)
@@ -671,6 +718,7 @@ static int test_multi2(void)
   struct sched_param param;
   pthread_attr_t attr;
   pthread_t pubsub_task;
+  int ret = ERROR;
   int i;
 
   test_note("Testing multi-topic 2 test (queue simulation)");
@@ -693,7 +741,8 @@ static int test_multi2(void)
   if (pthread_create(&pubsub_task, &attr, pub_test_multi2_entry, NULL) < 0)
     {
       pthread_attr_destroy(&attr);
-      return test_fail("failed launching task");
+      test_fail("failed launching task");
+      goto out;
     }
 
   pthread_attr_destroy(&attr);
@@ -718,13 +767,15 @@ static int test_multi2(void)
           if (OK != orb_copy(ORB_ID(orb_test_medium_multi),
                              orb_data_cur_fd, &msg))
             {
-              return test_fail("copy failed: %d", errno);
+              test_fail("copy failed: %d", errno);
+              goto out;
             }
 
           if (last_time >= msg.timestamp && last_time != 0)
             {
-              return test_fail("Timestamp not increasing! (%" PRIu64
-                               " >= %" PRIu64 ")", last_time, msg.timestamp);
+              test_fail("Timestamp not increasing! (%" PRIu64
+                        " >= %" PRIu64 ")", last_time, msg.timestamp);
+              goto out;
             }
 
           last_time     = msg.timestamp;
@@ -732,12 +783,20 @@ static int test_multi2(void)
         }
     }
 
+  ret = OK;
+
+out:
   for (i = 0; i < num_instances; ++i)
     {
       orb_unsubscribe(orb_data_fd[i]);
     }
 
-  return test_note("PASS multi-topic 2 test (queue simulation)");
+  if (ret == OK)
+    {
+      test_note("PASS multi-topic 2 test (queue simulation)");
+    }
+
+  return ret;
 }
 
 int test_queue(void)
@@ -750,6 +809,7 @@ int test_queue(void)
   int instance = 0;
   int ptopic;
   int sfd;
+  int ret = ERROR;
   int i;
 
   test_note("Testing orb queuing");
@@ -779,52 +839,60 @@ int test_queue(void)
     ORB_ID(orb_test_medium_queue), &sample, &instance, queue_size);
   if (ptopic < 0)
     {
+      orb_unsubscribe(sfd);
       return test_fail("advertise failed: %d", errno);
     }
 
   orb_check(sfd, &updated);
   if (!updated)
     {
-      return test_fail("update flag not set");
+      test_fail("update flag not set");
+      goto out;
     }
 
   if (OK != orb_copy(ORB_ID(orb_test_medium_queue), sfd, &sub_sample))
     {
-      return test_fail("copy(1) failed: %d", errno);
+      test_fail("copy(1) failed: %d", errno);
+      goto out;
     }
 
   if (sub_sample.val != sample.val)
     {
-      return test_fail("copy(1) mismatch: %d expected %d",
-                       sub_sample.val, sample.val);
+      test_fail("copy(1) mismatch: %d expected %d",
+                sub_sample.val, sample.val);
+      goto out;
     }
 
   orb_check(sfd, &updated);
   if (updated)
     {
-      return test_fail("spurious updated flag");
+      test_fail("spurious updated flag");
+      goto out;
     }
 
 #define CHECK_UPDATED(element) \
   orb_check(sfd, &updated); \
   if (!updated) \
     { \
-      return test_fail("update flag not set, element %i", element); \
+      test_fail("update flag not set, element %i", element); \
+      goto out; \
     }
 
 #define CHECK_NOT_UPDATED(element) \
   orb_check(sfd, &updated); \
   if (updated) \
     { \
-      return test_fail("update flag set, element %i", element); \
+      test_fail("update flag set, element %i", element); \
+      goto out; \
     }
 
 #define CHECK_COPY(i_got, i_correct) \
   orb_copy(ORB_ID(orb_test_medium_queue), sfd, &sub_sample); \
   if (i_got != i_correct) \
     { \
-      return test_fail("got wrong element from the queue (got %i," \
-                       "should be %i)", i_got, i_correct); \
+      test_fail("got wrong element from the queue (got %i," \
+                "should be %i)", i_got, i_correct); \
+      goto out; \
     }
 
   /* no messages in the queue anymore */
@@ -880,10 +948,18 @@ int test_queue(void)
 #undef CHECK_UPDATED
 #undef CHECK_NOT_UPDATED
 
+  ret = OK;
+
+out:
   orb_unadvertise(ptopic);
   orb_unsubscribe(sfd);
 
-  return test_note("PASS orb queuing");
+  if (ret == OK)
+    {
+      test_note("PASS orb queuing");
+    }
+
+  return ret;
 }
 
 static FAR void *pub_test_queue_entry(FAR void *arg)
@@ -973,6 +1049,7 @@ static int test_queue_poll_notify(void)
 
   if (pthread_create(&pubsub_task, &attr, pub_test_queue_entry, NULL) < 0)
     {
+      orb_unsubscribe(sfd);
       pthread_attr_destroy(&attr);
       return test_fail("failed test queue task");
     }
@@ -994,10 +1071,12 @@ static int test_queue_poll_notify(void)
               break;
             }
 
+          orb_unsubscribe(sfd);
           return test_fail("poll timeout");
         }
       else if (poll_ret < 0 && errno != EINTR)
         {
+          orb_unsubscribe(sfd);
           return test_fail("poll error (%d, %d)", poll_ret, errno);
         }
 
@@ -1006,6 +1085,7 @@ static int test_queue_poll_notify(void)
           orb_copy(ORB_ID(orb_test_medium_queue_poll), sfd, &t);
           if (next_expected_val != t.val)
             {
+              orb_unsubscribe(sfd);
               return test_fail("copy mismatch: %d expected %d",
                                t.val, next_expected_val);
             }
@@ -1016,6 +1096,7 @@ static int test_queue_poll_notify(void)
 
   if (g_num_messages_sent != next_expected_val)
     {
+      orb_unsubscribe(sfd);
       return test_fail("number of sent and received messages mismatch"
                        " (sent: %i, received: %i)",
                        g_num_messages_sent, next_expected_val);


(nuttx-apps) 07/09: system/uorb: add O_DIRECT to access sensor as wachers

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/nuttx-apps.git

commit 6c237cfbc098499a3d26308d3a64bac9546b1657
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Sat Jun 15 17:46:12 2024 +0800

    system/uorb: add O_DIRECT to access sensor as wachers
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 system/uorb/listener.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/system/uorb/listener.c b/system/uorb/listener.c
index 83b8efb17..9479cb2dd 100644
--- a/system/uorb/listener.c
+++ b/system/uorb/listener.c
@@ -194,7 +194,7 @@ static int listener_get_state(FAR struct orb_object *object,
   int ret;
   int fd;
 
-  fd = orb_open(object->meta->o_name, object->instance, 0);
+  fd = orb_open(object->meta->o_name, object->instance, O_DIRECT);
   if (fd < 0)
     {
       return fd;