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

lupyuen pushed a commit to branch releases/12.7
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

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

    system/uorb: support build in aosp
    
    Signed-off-by: dongjiuzhu1 <dongjiuz...@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 6345f77b1..41c44d2c4 100644
--- a/system/uorb/Kconfig
+++ b/system/uorb/Kconfig
@@ -28,7 +28,7 @@ config UORB_TESTS
 
 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 84774d2af..aceccc014 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>
@@ -79,34 +82,42 @@ typedef struct sensor_device_info_s orb_info_t;
 #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__)

Reply via email to