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

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


The following commit(s) were added to refs/heads/master by this push:
     new e296be444 testing/testsuites: Test pthread_spin_init() with each 
pshared value.
e296be444 is described below

commit e296be444f080d027e6159b5cc3c44e7bffd05b8
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 29 22:59:09 2026 +0100

    testing/testsuites: Test pthread_spin_init() with each pshared value.
    
    test_nuttx_pthread_test22 initializes a spin lock with
    PTHREAD_PROCESS_PRIVATE, with PTHREAD_PROCESS_SHARED and with 0, and
    then locks it, tries it (EBUSY), unlocks it and destroys it.  0 is the
    value of PTHREAD_PROCESS_PRIVATE in glibc, and programs written for
    Linux often give it.  The NuttX change "libc/pthread: Accept any pshared
    value in pthread_spin_init()." makes pthread_spin_init() accept it.
    
    The case needs CONFIG_PTHREAD_SPINLOCKS (sim:citest and rv-virt:citest
    set it); without it the case is skipped.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 .../kernel/pthread/cases/posix_pthread_test_022.c  | 85 ++++++++++++++++++++++
 .../kernel/pthread/cmocka_pthread_test.c           |  2 +
 .../kernel/pthread/include/PthreadTest.h           |  5 ++
 3 files changed, 92 insertions(+)

diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_022.c 
b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_022.c
new file mode 100644
index 000000000..2c5d512ee
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_022.c
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_022.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_PTHREAD_SPINLOCKS
+
+/****************************************************************************
+ * Name: test_nuttx_pthread_spin
+ *
+ * Description:
+ *   Initialize a spin lock with 'pshared', then lock it, try it (EBUSY),
+ *   unlock it and destroy it.
+ *
+ ****************************************************************************/
+
+static void test_nuttx_pthread_spin(int pshared)
+{
+  pthread_spinlock_t lock;
+
+  syslog(LOG_INFO, "pthread_spin_init(&lock, %d)\n", pshared);
+  assert_int_equal(pthread_spin_init(&lock, pshared), 0);
+  assert_int_equal(pthread_spin_lock(&lock), 0);
+  assert_int_equal(pthread_spin_trylock(&lock), EBUSY);
+  assert_int_equal(pthread_spin_unlock(&lock), 0);
+  assert_int_equal(pthread_spin_trylock(&lock), 0);
+  assert_int_equal(pthread_spin_unlock(&lock), 0);
+  assert_int_equal(pthread_spin_destroy(&lock), 0);
+}
+
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_pthread_test22
+ *
+ * Description:
+ *   pthread_spin_init() with PTHREAD_PROCESS_PRIVATE, with
+ *   PTHREAD_PROCESS_SHARED and with 0, the value of PTHREAD_PROCESS_PRIVATE
+ *   in glibc that programs written for Linux often give.
+ *
+ ****************************************************************************/
+
+void test_nuttx_pthread_test22(FAR void **state)
+{
+#ifdef CONFIG_PTHREAD_SPINLOCKS
+  test_nuttx_pthread_spin(PTHREAD_PROCESS_PRIVATE);
+  test_nuttx_pthread_spin(PTHREAD_PROCESS_SHARED);
+  test_nuttx_pthread_spin(0);
+#else
+  skip();
+#endif
+}
diff --git a/testing/testsuites/kernel/pthread/cmocka_pthread_test.c 
b/testing/testsuites/kernel/pthread/cmocka_pthread_test.c
index 5e04ac87a..babf3e350 100644
--- a/testing/testsuites/kernel/pthread/cmocka_pthread_test.c
+++ b/testing/testsuites/kernel/pthread/cmocka_pthread_test.c
@@ -62,6 +62,8 @@ int main(int argc, char *argv[])
                                       NULL),
       cmocka_unit_test_setup_teardown(test_nuttx_pthread_test21, NULL,
                                       NULL),
+      cmocka_unit_test_setup_teardown(test_nuttx_pthread_test22, NULL,
+                                      NULL),
   };
 
   /* Run Test cases */
diff --git a/testing/testsuites/kernel/pthread/include/PthreadTest.h 
b/testing/testsuites/kernel/pthread/include/PthreadTest.h
index 3909171d3..e746305d6 100644
--- a/testing/testsuites/kernel/pthread/include/PthreadTest.h
+++ b/testing/testsuites/kernel/pthread/include/PthreadTest.h
@@ -138,4 +138,9 @@ void test_nuttx_pthread_test19(FAR void **state);
  * ************************************************/
 
 void test_nuttx_pthread_test21(FAR void **state);
+
+/* cases/posix_pthread_test_022.c
+ * ************************************************/
+
+void test_nuttx_pthread_test22(FAR void **state);
 #endif

Reply via email to