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 f86246f7c6a95f24ccaa605c4bb3d12d3cfd3415
Author: anpeiyun <[email protected]>
AuthorDate: Sun Oct 26 11:38:14 2025 +0800

    ostest/spinlock: fix the operations does not affect the result.
    
    When expanding the macro VERIY, (0 == 
pthread_barrier_wait(&param->pub->barrier)) < 0 always false.
    Regardless of the value of its operands.
    
    Signed-off-by: anpeiyun <[email protected]>
---
 testing/ostest/spinlock.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/testing/ostest/spinlock.c b/testing/ostest/spinlock.c
index dd49c4d54..df691d7ca 100644
--- a/testing/ostest/spinlock.c
+++ b/testing/ostest/spinlock.c
@@ -91,7 +91,12 @@ FAR static void * lock_type##_test_thread(FAR void *arg) \
   struct timespec start; \
   struct timespec end; \
   int i; \
-  VERIFY(0 == pthread_barrier_wait(&param->pub->barrier)); \
+  int ret; \
+  ret = pthread_barrier_wait(&param->pub->barrier); \
+  if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) \
+    { \
+      ASSERT(false); \
+    } \
   clock_gettime(CLOCK_REALTIME, &start); \
   for (i = 0; i < LOOP_TIMES; i++) \
     { \
@@ -121,8 +126,14 @@ static inline void run_test_thread(
   struct timespec stime;
   struct timespec etime;
   int i;
+  int ret;
+
+  ret = pthread_barrier_init(&pub.barrier, NULL, THREAD_NUM + 1);
+  if (ret != 0)
+    {
+      ASSERT(false);
+    }
 
-  VERIFY(0 == pthread_barrier_init(&pub.barrier, NULL, THREAD_NUM + 1));
   pub.counter = 0;
   if (lock_type == RSPINLOCK)
     {
@@ -141,7 +152,11 @@ static inline void run_test_thread(
       pthread_create(&tid[i], NULL, thread_func, &param[i]);
     }
 
-  VERIFY(0 == pthread_barrier_wait(&pub.barrier));
+  ret = pthread_barrier_wait(&pub.barrier);
+  if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      ASSERT(false);
+    }
 
   for (i = 0; i < THREAD_NUM; i++)
     {
@@ -149,7 +164,11 @@ static inline void run_test_thread(
     }
 
   clock_gettime(CLOCK_REALTIME, &etime);
-  VERIFY(0 == pthread_barrier_destroy(&pub.barrier));
+  ret = pthread_barrier_destroy(&pub.barrier);
+  if (ret != 0)
+    {
+      ASSERT(false);
+    }
 
   uint64_t total_ns = 0;
   for (i = 0; i < THREAD_NUM; i++)

Reply via email to