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/02/22 14:55:07 UTC
(nuttx-apps) branch master updated: add mm/sched and open posix on CI
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
The following commit(s) were added to refs/heads/master by this push:
new be74e34ed add mm/sched and open posix on CI
be74e34ed is described below
commit be74e34ede8ecd6f805355254ddbef516ba6e110
Author: vela-mib <ve...@xiaomi.com>
AuthorDate: Thu Feb 22 16:55:30 2024 +0800
add mm/sched and open posix on CI
Signed-off-by: vela-mib <ve...@xiaomi.com>
---
testing/ltp/Kconfig | 3 +
testing/ltp/Makefile | 103 ++++--------
testing/ostest/ostest_main.c | 2 +-
testing/testsuites/Kconfig | 47 ++++++
testing/testsuites/Make.defs | 24 +++
testing/testsuites/Makefile | 57 +++++++
testing/testsuites/kernel/mm/cases/mm_test_001.c | 69 ++++++++
testing/testsuites/kernel/mm/cases/mm_test_002.c | 78 +++++++++
testing/testsuites/kernel/mm/cases/mm_test_003.c | 77 +++++++++
testing/testsuites/kernel/mm/cases/mm_test_004.c | 58 +++++++
testing/testsuites/kernel/mm/cases/mm_test_005.c | 69 ++++++++
testing/testsuites/kernel/mm/cases/mm_test_006.c | 91 +++++++++++
testing/testsuites/kernel/mm/cases/mm_test_007.c | 138 ++++++++++++++++
testing/testsuites/kernel/mm/cases/mm_test_008.c | 158 ++++++++++++++++++
testing/testsuites/kernel/mm/cmocka_mm_test.c | 77 +++++++++
.../testsuites/kernel/mm/common/test_mm_common.c | 123 ++++++++++++++
testing/testsuites/kernel/mm/include/MmTest.h | 82 ++++++++++
.../kernel/mm/tool/mem_batch_opt_perf_test.c | 153 +++++++++++++++++
.../kernel/mm/tool/mem_cycle_opt_perf_test.c | 139 ++++++++++++++++
.../kernel/pthread/cases/posix_pthread_test_003.c | 89 ++++++++++
.../kernel/pthread/cases/posix_pthread_test_004.c | 90 ++++++++++
.../kernel/pthread/cases/posix_pthread_test_005.c | 94 +++++++++++
.../kernel/pthread/cases/posix_pthread_test_006.c | 84 ++++++++++
.../kernel/pthread/cases/posix_pthread_test_009.c | 102 ++++++++++++
.../kernel/pthread/cases/posix_pthread_test_018.c | 146 +++++++++++++++++
.../kernel/pthread/cases/posix_pthread_test_019.c | 75 +++++++++
.../kernel/pthread/cases/posix_pthread_test_021.c | 87 ++++++++++
.../kernel/pthread/cmocka_pthread_test.c | 62 +++++++
.../kernel/pthread/common/test_pthread_common.c | 64 ++++++++
.../kernel/pthread/include/PthreadTest.h | 126 ++++++++++++++
.../kernel/sched/cases/api_pthread_test_001.c | 79 +++++++++
.../kernel/sched/cases/api_pthread_test_002.c | 105 ++++++++++++
.../kernel/sched/cases/api_pthread_test_003.c | 90 ++++++++++
.../kernel/sched/cases/api_pthread_test_004.c | 101 ++++++++++++
.../kernel/sched/cases/api_pthread_test_005.c | 84 ++++++++++
.../kernel/sched/cases/api_pthread_test_006.c | 92 +++++++++++
.../kernel/sched/cases/api_pthread_test_007.c | 94 +++++++++++
.../kernel/sched/cases/api_pthread_test_008.c | 103 ++++++++++++
.../kernel/sched/cases/api_pthread_test_009.c | 105 ++++++++++++
.../kernel/sched/cases/api_task_test_001.c | 80 +++++++++
.../kernel/sched/cases/api_task_test_002.c | 89 ++++++++++
.../kernel/sched/cases/api_task_test_003.c | 90 ++++++++++
.../kernel/sched/cases/api_task_test_004.c | 116 +++++++++++++
.../kernel/sched/cases/api_task_test_005.c | 86 ++++++++++
.../kernel/sched/cases/api_task_test_006.c | 84 ++++++++++
.../kernel/sched/cases/api_task_test_007.c | 97 +++++++++++
.../testsuites/kernel/sched/cmocka_sched_test.c | 68 ++++++++
.../kernel/sched/common/test_sched_common.c | 59 +++++++
.../testsuites/kernel/sched/include/SchedTest.h | 112 +++++++++++++
.../kernel/time/cases/clock_test_clock01.c | 98 +++++++++++
.../kernel/time/cases/clock_test_clock02.c | 58 +++++++
.../kernel/time/cases/clock_test_smoke.c | 118 +++++++++++++
.../kernel/time/cases/clock_test_timer01.c | 182 +++++++++++++++++++++
.../kernel/time/cases/clock_test_timer03.c | 137 ++++++++++++++++
.../kernel/time/cases/clock_test_timer04.c | 161 ++++++++++++++++++
.../kernel/time/cases/clock_test_timer05.c | 169 +++++++++++++++++++
testing/testsuites/kernel/time/cmocka_time_test.c | 57 +++++++
testing/testsuites/kernel/time/include/TimeTest.h | 87 ++++++++++
58 files changed, 5296 insertions(+), 72 deletions(-)
diff --git a/testing/ltp/Kconfig b/testing/ltp/Kconfig
index 228fe99f0..8d9c4734a 100644
--- a/testing/ltp/Kconfig
+++ b/testing/ltp/Kconfig
@@ -9,3 +9,6 @@ config TESTING_LTP
---help---
Enable support for the Linux Test Project(LTP) framework
+config TESTING_LTP_STACKSIZE
+ int "Linux Test Project stack size"
+ default 4096
diff --git a/testing/ltp/Makefile b/testing/ltp/Makefile
index 27ca50107..947029a54 100644
--- a/testing/ltp/Makefile
+++ b/testing/ltp/Makefile
@@ -32,89 +32,49 @@ ifeq ($(CONFIG_FS_AIO),)
BLACKWORDS += "aio.h"
BLACKWORDS += "SIGPOLL"
endif
-BLACKWORDS += "SA_RESTART"
-BLACKWORDS += "pthread_atfork"
-BLACKWORDS += "pthread_condattr_setpshared"
-BLACKWORDS += "pthread_condattr_getpshared"
-BLACKWORDS += "pthread_mutex_getprioceiling"
BLACKWORDS += "pthread_mutexattr_setprioceiling"
BLACKWORDS += "pthread_mutexattr_getprioceiling"
BLACKWORDS += "pthread_getattr_np"
-BLACKWORDS += "pthread_getcpuclockid"
-BLACKWORDS += "pthread_rwlockattr_init"
-BLACKWORDS += "pthread_rwlockattr_destroy"
BLACKWORDS += "pthread_mutex_getprioceiling"
-BLACKWORDS += "clock_getcpuclockid"
-BLACKWORDS += "shm_unlink"
-BLACKWORDS += "shm_open"
-BLACKWORDS += "mlock"
-BLACKWORDS += "munlock"
-BLACKWORDS += "mlockall"
-BLACKWORDS += "msync"
-BLACKWORDS += "getpgrp"
-BLACKWORDS += "lfind"
-BLACKWORDS += "killpg"
-BLACKWORDS += "setpwent"
ifeq ($(CONFIG_PTHREAD_SPINLOCKS),)
-BLACKWORDS += "pthread_spin_init"
-BLACKWORDS += "pthread_spin_destroy"
-BLACKWORDS += "pthread_spin_trylock"
+BLACKWORDS += "pthread_spin_init"
+BLACKWORDS += "pthread_spin_destroy"
+BLACKWORDS += "pthread_spin_trylock"
endif
-BLACKWORDS += "affinity.h"
-BLACKWORDS += "langinfo.h"
-BLACKWORDS += "ucontext.h"
-BLACKWORDS += "noatime.h"
-BLACKWORDS += "CLOCK_PROCESS_CPUTIME_ID"
-BLACKWORDS += "CLOCK_THREAD_CPUTIME_ID"
-BLACKWORDS += "fork()"
-BLACKWORDS += "pthread_attr_setscope"
-BLACKWORDS += "RLIMIT_MEMLOCK"
+BLACKWORDS += "CHILD_MAX"
+BLACKWORDS += "setpgid("
BLACKWORDS += "PTHREAD_SCOPE_PROCESS"
-BLACKWORDS += "SIGABRT"
-BLACKWORDS += "SIGBUS"
-BLACKWORDS += "SIGFPE"
-BLACKWORDS += "SIGHUP"
-BLACKWORDS += "SIGILL"
-BLACKWORDS += "SIGPROF"
-BLACKWORDS += "SIGSEGV"
-BLACKWORDS += "SIGSYS"
-BLACKWORDS += "SIGTRAP"
-BLACKWORDS += "SIGTSTP"
-BLACKWORDS += "SIGTTIN"
-BLACKWORDS += "SIGTTOU"
-BLACKWORDS += "SIGURG"
-BLACKWORDS += "SIGVTALRM"
-BLACKWORDS += "SIGXCPU"
-BLACKWORDS += "SIGXFSZ"
-BLACKWORDS += "SIGSTKSZ"
-BLACKWORDS += "stack_t"
-BLACKWORDS += "siginterrupt"
+BLACKWORDS += "setpgrp"
BLACKWORDS += "threads_scenarii.c"
-BLACKWORDS += "PTHREAD_PRIO_PROTECT"
BLACKWORDS += "pthread_mutex_lock"
+BLACKWORDS += "ucontext.h"
-BLACKWORDS += "ILL_[A-Z]"
-BLACKWORDS += "FPE_[A-Z]"
-BLACKWORDS += "BUS_[A-Z]"
-BLACKWORDS += "TRAP_[A-Z]"
-BLACKWORDS += "SEGV_[A-Z]"
-BLACKWORDS += "POLL_[A-Z]"
-BLACKWORDS += "SA_ONSTACK"
-BLACKWORDS += "MINSIGSTKSZ"
-BLACKWORDS += "FPE_FLTINV"
+BLACKWORDS += "msync"
+BLACKWORDS += "lfind"
-BLACKSRCS += 19-1-buildonly.c
-BLACKSRCS += 21-1-buildonly.c
-BLACKSRCS += 27-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/time_h/19-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/signal_h/21-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/signal_h/27-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/time_h/19-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/sem_post/8-1.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/9-1.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/2-2.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/10-1.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/1-5.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/1-3.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/2-3.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/clock_nanosleep/1-4.c
+BLACKSRCS += $(TESTDIR)/conformance/interfaces/pthread_sigmask/18-1.c
ifeq ($(CONFIG_LIBC_LOCALTIME),)
-BLACKSRCS += 34-1-buildonly.c
-BLACKSRCS += 35-3-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/time_h/34-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/time_h/35-3-buildonly.c
endif
-BLACKSRCS += 35-1-buildonly.c
-BLACKSRCS += 35-2-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/time_h/35-1-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/time_h/35-2-buildonly.c
+BLACKSRCS += $(TESTDIR)/stress/threads/pthread_kill/stress.c
ifeq ($(CONFIG_PTHREAD_SPINLOCKS),)
-BLACKSRCS += 3-12-buildonly.c
+BLACKSRCS += $(TESTDIR)/conformance/definitions/pthread_h/3-12-buildonly.c
endif
ifeq ($(CONFIG_SCHED_CHILD_STATUS),)
BLACKSRCS += $(TESTDIR)/conformance/interfaces/pthread_exit/6-1.c
@@ -151,8 +111,8 @@ ifeq ($(CONFIG_SIG_DEFAULT),)
BLACKWORDS += SIGKILL
BLACKWORDS += SIGSTOP
endif
-ifeq ($(CONFIG_RR_INTERVAL),)
-BLACKSRCS += $(TESTDIR)/functional/threads/condvar/pthread_cond_wait_1.c
+ifneq ($(shell expr $(CONFIG_RR_INTERVAL) \> 0),1)
+BLACKWORDS += SCHED_RR
endif
ifeq ($(CONFIG_FS_NAMED_SEMAPHORES),)
BLACKWORDS += sem_open
@@ -254,7 +214,7 @@ MAINSRC += $(TESTDIR)/../network/can/filter-tests/can_filter.c
MAINSRC += $(TESTDIR)/../network/can/filter-tests/can_rcv_own_msgs.c
endif
PRIORITY = SCHED_PRIORITY_DEFAULT
-STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
+STACKSIZE = $(CONFIG_TESTING_LTP_STACKSIZE)
MODULE = $(CONFIG_TESTING_LTP)
CSRCS := $(LTP_CSRCS)
@@ -266,6 +226,7 @@ endif
# Relax warning checks to avoid expected compile errors:
CFLAGS += -Wno-strict-prototypes -Wno-return-type -Wno-format -Wno-uninitialized
CFLAGS += -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-value
+CFLAGS += -Wno-int-conversion -Wno-shadow
# Should be removed if possible in the future
CFLAGS += -Wno-incompatible-pointer-types -Wno-overflow -Wno-int-to-pointer-cast
diff --git a/testing/ostest/ostest_main.c b/testing/ostest/ostest_main.c
index c856aea40..18ef0d9ce 100644
--- a/testing/ostest/ostest_main.c
+++ b/testing/ostest/ostest_main.c
@@ -584,7 +584,7 @@ static int user_main(int argc, char *argv[])
check_test_memory_usage();
#endif
-#if defined(CONFIG_ARCH_HAVE_FORK) && defined(CONFIG_SCHED_WAITPID)
+#if defined(CONFIG_ARCH_HAVE_VFORK) && defined(CONFIG_SCHED_WAITPID)
#ifndef CONFIG_BUILD_KERNEL
printf("\nuser_main: vfork() test\n");
vfork_test();
diff --git a/testing/testsuites/Kconfig b/testing/testsuites/Kconfig
new file mode 100644
index 000000000..8c3b70d0c
--- /dev/null
+++ b/testing/testsuites/Kconfig
@@ -0,0 +1,47 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config TESTS_TESTSUITES
+ tristate "vela test suite"
+ default n
+ depends on TESTING_CMOCKA
+ ---help---
+ Enable testsuites for the vela
+
+if TESTS_TESTSUITES
+
+config TESTS_TESTSUITES_MOUNT_DIR
+ string "Mount directory for the testsuites"
+ default "/data"
+
+config TESTS_TESTSUITES_PRIORITY
+ int "Testsuites task priority"
+ default 99
+
+config TESTS_TESTSUITES_STACKSIZE
+ int "Testsuites stack size"
+ default 16384
+
+config CM_SCHED_TEST
+ bool "enbale schedule test"
+ default n
+ depends on TESTS_TESTSUITES
+
+config CM_MM_TEST
+ bool "enbale MM test"
+ default n
+ depends on TESTS_TESTSUITES
+
+config CM_TIME_TEST
+ bool "enbale time test"
+ default n
+ depends on TESTS_TESTSUITES
+
+config CM_PTHREAD_TEST
+ bool "enbale pthread test"
+ default n
+ depends on TESTS_TESTSUITES
+
+endif # TESTS_TESTSUITES
diff --git a/testing/testsuites/Make.defs b/testing/testsuites/Make.defs
new file mode 100644
index 000000000..94143ad6f
--- /dev/null
+++ b/testing/testsuites/Make.defs
@@ -0,0 +1,24 @@
+############################################################################
+# apps/tests/testsuites/Make.defs
+#
+# 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.
+#
+#
+############################################################################
+
+ifneq ($(CONFIG_TESTS_TESTSUITES),)
+CONFIGURED_APPS += $(APPDIR)/testing/testsuites
+endif
diff --git a/testing/testsuites/Makefile b/testing/testsuites/Makefile
new file mode 100644
index 000000000..515a98ddd
--- /dev/null
+++ b/testing/testsuites/Makefile
@@ -0,0 +1,57 @@
+# apps/tests/testsuites/Makefile
+#
+# Licensed 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.
+
+include $(APPDIR)/Make.defs
+
+
+PRIORITY = $(CONFIG_TESTS_TESTSUITES_PRIORITY)
+STACKSIZE = $(CONFIG_TESTS_TESTSUITES_STACKSIZE)
+MODULE = $(CONFIG_TESTS_TESTSUITES)
+
+ifneq ($(CONFIG_CM_SCHED_TEST),)
+CFLAGS += -I$(CURDIR)/kernel/sched/include
+CSRCS += $(wildcard kernel/sched/cases/*.c)
+CSRCS += $(wildcard kernel/sched/common/*.c)
+PROGNAME += cmocka_sched_test
+MAINSRC += $(CURDIR)/kernel/sched/cmocka_sched_test.c
+endif
+
+ifneq ($(CONFIG_CM_MM_TEST),)
+CFLAGS += -I$(CURDIR)/kernel/mm/include
+CSRCS += $(wildcard kernel/mm/cases/*.c)
+CSRCS += $(wildcard kernel/mm/common/*.c)
+PROGNAME += cmocka_mm_test
+MAINSRC += $(CURDIR)/kernel/mm/cmocka_mm_test.c
+PROGNAME += mem_batch_opt_perf_test
+MAINSRC += $(CURDIR)/kernel/mm/tool/mem_batch_opt_perf_test.c
+PROGNAME += mem_cycle_opt_perf_test
+MAINSRC += $(CURDIR)/kernel/mm/tool/mem_cycle_opt_perf_test.c
+endif
+
+ifneq ($(CONFIG_CM_TIME_TEST),)
+CFLAGS += -I$(CURDIR)/kernel/time/include
+CSRCS += $(wildcard kernel/time/cases/*.c)
+PROGNAME += cmocka_time_test
+MAINSRC += $(CURDIR)/kernel/time/cmocka_time_test.c
+endif
+
+ifneq ($(CONFIG_CM_PTHREAD_TEST),)
+CFLAGS += -I$(CURDIR)/kernel/pthread/include
+CSRCS += $(wildcard kernel/pthread/cases/*.c)
+CSRCS += $(wildcard kernel/pthread/common/*.c)
+PROGNAME += cmocka_pthread_test
+MAINSRC += $(CURDIR)/kernel/pthread/cmocka_pthread_test.c
+endif
+
+include $(APPDIR)/Application.mk
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_001.c b/testing/testsuites/kernel/mm/cases/mm_test_001.c
new file mode 100644
index 000000000..aecee6970
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_001.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_001.c
+ *
+ * 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 <stdlib.h>
+#include <inttypes.h>
+#include <syslog.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm01
+ ****************************************************************************/
+
+void test_nuttx_mm01(FAR void **state)
+{
+ int i = 0;
+ int flag = 0;
+ char *pm1;
+ char *pm2;
+ unsigned long memsize;
+
+ memsize = mmtest_get_memsize();
+ pm2 = pm1 = malloc(memsize);
+ assert_non_null(pm1);
+
+ for (i = 0; i < memsize; i++)
+ *pm2++ = 'X';
+ pm2 = pm1;
+ for (i = 0; i < memsize; i++)
+ {
+ if (*pm2++ != 'X')
+ {
+ flag = 1;
+ }
+ }
+
+ free(pm1);
+ assert_int_equal(flag, 0);
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_002.c b/testing/testsuites/kernel/mm/cases/mm_test_002.c
new file mode 100644
index 000000000..bad38c4ca
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_002.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_002.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm02
+ ****************************************************************************/
+
+void test_nuttx_mm02(FAR void **state)
+{
+ int i = 0;
+ int flag = 0;
+ char *pm1;
+ char *pm2;
+ unsigned long memsize;
+
+ memsize = mmtest_get_memsize();
+ pm2 = pm1 = calloc(memsize, 1);
+ assert_non_null(pm2);
+
+ for (i = 0; i < memsize; i++)
+ {
+ if (*pm2++ != 0)
+ {
+ flag = 1;
+ }
+ }
+
+ pm2 = pm1;
+ for (i = 0; i < memsize; i++)
+ *pm2++ = 'X';
+ pm2 = pm1;
+ for (i = 0; i < memsize; i++)
+ {
+ if (*pm2++ != 'X')
+ {
+ flag = 1;
+ }
+ }
+
+ free(pm1);
+ assert_int_equal(flag, 0);
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_003.c b/testing/testsuites/kernel/mm/cases/mm_test_003.c
new file mode 100644
index 000000000..09553c465
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_003.c
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_003.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm03
+ ****************************************************************************/
+
+void test_nuttx_mm03(FAR void **state)
+{
+ int i;
+ int flag = 0;
+ char *pm1;
+ char *pm2;
+ pm2 = pm1 = malloc(10);
+ assert_non_null(pm2);
+ for (i = 0; i < 10; i++)
+ *pm2++ = 'X';
+
+ pm2 = realloc(pm1, 5);
+ pm1 = pm2;
+ for (i = 0; i < 5; i++)
+ {
+ if (*pm2++ != 'X')
+ {
+ flag = 1;
+ }
+ }
+
+ pm2 = realloc(pm1, 15);
+ pm1 = pm2;
+ for (i = 0; i < 5; i++)
+ {
+ if (*pm2++ != 'X')
+ {
+ flag = 1;
+ }
+ }
+
+ free(pm1);
+ assert_int_equal(flag, 0);
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_004.c b/testing/testsuites/kernel/mm/cases/mm_test_004.c
new file mode 100644
index 000000000..59960fd1b
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_004.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_004.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <string.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm04
+ ****************************************************************************/
+
+void test_nuttx_mm04(FAR void **state)
+{
+ int i;
+ char *temp_ptr = NULL;
+
+ for (i = 0; i < 10; i++)
+ {
+ temp_ptr = memalign(64, 1024 * sizeof(char));
+ assert_non_null(temp_ptr);
+
+ memset(temp_ptr, 0x33, 1024 * sizeof(char));
+ free(temp_ptr);
+ }
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_005.c b/testing/testsuites/kernel/mm/cases/mm_test_005.c
new file mode 100644
index 000000000..127391515
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_005.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_005.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm05
+ ****************************************************************************/
+
+void test_nuttx_mm05(FAR void **state)
+{
+ int i = 0;
+ int flag = 0;
+ char *ptr = NULL;
+ char *temp_ptr = NULL;
+
+ ptr = temp_ptr = zalloc(1024 * sizeof(char));
+ assert_non_null(temp_ptr);
+
+ for (i = 0; i < 1024; i++)
+ {
+ if (*temp_ptr++ != 0)
+ {
+ flag = 1;
+ }
+ }
+
+ free(ptr);
+ assert_int_equal(flag, 0);
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_006.c b/testing/testsuites/kernel/mm/cases/mm_test_006.c
new file mode 100644
index 000000000..8525b9543
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_006.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_006.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Random size range, we will apply the memory size in this range */
+
+#define MALLOC_MIN_SIZE 64
+#define MALLOC_MAX_SIZE 8192
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm06
+ ****************************************************************************/
+
+void test_nuttx_mm06(FAR void **state)
+{
+ int malloc_size;
+ int test_num = 1000;
+ char check_character = 0x67; /* Memory write content check character */
+ char *address_ptr = NULL;
+
+ for (int i = 0; i < test_num; i++)
+ {
+ srand(i + gettid());
+
+ /* Produces a random size */
+
+ malloc_size = mmtest_get_rand_size(MALLOC_MIN_SIZE, MALLOC_MAX_SIZE);
+ address_ptr = (char *)malloc(malloc_size * sizeof(char));
+ assert_non_null(address_ptr);
+ memset(address_ptr, check_character, malloc_size);
+
+ /* Checking Content Consistency */
+
+ for (int j = 0; j < malloc_size; j++)
+ {
+ if (address_ptr[j] != check_character)
+ {
+ free(address_ptr);
+ fail_msg("check fail !\n");
+ }
+ }
+
+ /* Free test memory */
+
+ free(address_ptr);
+ }
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_007.c b/testing/testsuites/kernel/mm/cases/mm_test_007.c
new file mode 100644
index 000000000..a131200b2
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_007.c
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_007.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <malloc.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MEMORY_LIST_LENGTH 200
+
+/* Random size range, we will apply the memory size in this range */
+
+#define MALLOC_MIN_SIZE 32
+#define MALLOC_MAX_SIZE 2048
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm07
+ ****************************************************************************/
+
+void test_nuttx_mm07(FAR void **state)
+{
+ char *mem_list[MEMORY_LIST_LENGTH];
+ char *tmp_str = NULL;
+ int malloc_size;
+ int index = 0;
+ int total_size = 0;
+ int flag = 0;
+ struct mallinfo test_befor_info;
+ struct mallinfo test_during_info;
+ struct mallinfo test_after_info;
+
+ for (int i = 0; i < MEMORY_LIST_LENGTH; i++)
+ {
+ mem_list[i] = NULL;
+ }
+
+ test_befor_info = mallinfo();
+
+ /* get a random size */
+
+ malloc_size = mmtest_get_rand_size(MALLOC_MIN_SIZE, MALLOC_MAX_SIZE);
+ for (int k = 0; k < MEMORY_LIST_LENGTH; k++)
+ {
+ if (malloc_size > 0)
+ {
+ tmp_str = (char *)malloc(malloc_size * sizeof(char));
+ }
+ else
+ {
+ malloc_size = 512;
+ tmp_str = (char *)malloc(malloc_size * sizeof(char));
+ }
+
+ mem_list[k] = tmp_str;
+ if (tmp_str != NULL)
+ {
+ memset(tmp_str, 0x67, malloc_size);
+ total_size = total_size + malloc_size;
+ for (int j = 0; j < malloc_size; j++)
+ {
+ if (*tmp_str++ != 0x67)
+ {
+ syslog(LOG_ERR, "check error !\n");
+ flag = 1;
+ }
+ }
+ }
+ }
+
+ test_during_info = mallinfo();
+
+ /* Random memory release */
+
+ for (int n = 0; n < MEMORY_LIST_LENGTH; n++)
+ {
+ srand(n);
+ index = rand() % 2;
+ if (index == 0 && mem_list[n] != NULL)
+ {
+ free(mem_list[n]);
+ mem_list[n] = NULL;
+ }
+ }
+
+ for (int l = 0; l < MEMORY_LIST_LENGTH; l++)
+ {
+ if (mem_list[l] != NULL)
+ free(mem_list[l]);
+ }
+
+ test_after_info = mallinfo();
+ assert_int_in_range(test_befor_info.fordblks,
+ test_during_info.fordblks, test_befor_info.arena);
+ assert_int_in_range(test_after_info.fordblks,
+ test_during_info.fordblks, test_befor_info.arena);
+ assert_int_equal(flag, 0);
+}
diff --git a/testing/testsuites/kernel/mm/cases/mm_test_008.c b/testing/testsuites/kernel/mm/cases/mm_test_008.c
new file mode 100644
index 000000000..f49148b78
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cases/mm_test_008.c
@@ -0,0 +1,158 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cases/mm_test_008.c
+ *
+ * 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 <stdlib.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <malloc.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MEMORY_LIST_LENGTH 200
+
+/* Random size range, we will apply the memory size in this range */
+
+#define MALLOC_MIN_SIZE 32
+#define MALLOC_MAX_SIZE 2048
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int test_nuttx08_routine_1(int argc, char *argv[])
+{
+ char *ptr = NULL;
+ char *tmp_ptr = NULL;
+ int malloc_size;
+ int flag = 0;
+
+ for (int n = 0; n < 1000; n++)
+ {
+ malloc_size = mmtest_get_rand_size(64, 512);
+ tmp_ptr = ptr = malloc(sizeof(char) * malloc_size);
+ if (ptr == NULL)
+ {
+ flag = 1;
+ break;
+ }
+
+ for (int i = 0; i < malloc_size; i++)
+ *tmp_ptr++ = 'X';
+ tmp_ptr = ptr;
+ for (int j = 0; j < malloc_size; j++)
+ {
+ if (*tmp_ptr++ != 'X')
+ {
+ flag = 1;
+ }
+ }
+
+ free(ptr);
+ }
+
+ assert_int_equal(flag, 0);
+ return 0;
+}
+
+static int test_nuttx08_routine_2(int argc, char *argv[])
+{
+ char *temp_ptr = NULL;
+ int flag = 0;
+
+ for (int n = 0; n < 1000; n++)
+ {
+ temp_ptr = memalign(64, 1024 * sizeof(char));
+ if (temp_ptr == NULL)
+ {
+ flag = 1;
+ break;
+ }
+
+ assert_non_null(temp_ptr);
+
+ memset(temp_ptr, 0x33, 1024 * sizeof(char));
+ free(temp_ptr);
+ }
+
+ assert_int_equal(flag, 0);
+ return 0;
+}
+
+static int test_nuttx08_routine_3(int argc, char *argv[])
+{
+ char *pm;
+ unsigned long memsize;
+ for (int i = 0; i < 500; i++)
+ {
+ /* Apply for as much memory as a system allows */
+
+ memsize = mmtest_get_rand_size(1024, 2048);
+ pm = malloc(memsize);
+ assert_non_null(pm);
+ free(pm);
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMm08
+ ****************************************************************************/
+
+void test_nuttx_mm08(FAR void **state)
+{
+ pid_t pid;
+ int status;
+
+ pid = task_create("TestNuttx08_routine_1",
+ TASK_PRIORITY, DEFAULT_STACKSIZE, test_nuttx08_routine_1, NULL);
+ assert_true(pid > 0);
+ pid = task_create("TestNuttx08_routine_2",
+ TASK_PRIORITY, DEFAULT_STACKSIZE, test_nuttx08_routine_2, NULL);
+ assert_true(pid > 0);
+ pid = task_create("TestNuttx08_routine_3",
+ TASK_PRIORITY, DEFAULT_STACKSIZE, test_nuttx08_routine_3, NULL);
+ assert_true(pid > 0);
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/mm/cmocka_mm_test.c b/testing/testsuites/kernel/mm/cmocka_mm_test.c
new file mode 100644
index 000000000..3b6ea07fe
--- /dev/null
+++ b/testing/testsuites/kernel/mm/cmocka_mm_test.c
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/cmocka_mm_test.c
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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 <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "MmTest.h"
+#include <cmocka.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cmocka_sched_test_main
+ ****************************************************************************/
+
+int main(int argc, char *argv[])
+{
+ /* Add Test Cases */
+
+ const struct CMUnitTest nuttx_mm_test_suites[] = {
+ cmocka_unit_test_setup_teardown(test_nuttx_mm01,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm02,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm03,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm04,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm05,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm06,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm07,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ cmocka_unit_test_setup_teardown(test_nuttx_mm08,
+ test_nuttx_mmsetup,
+ test_nuttx_mmteardown),
+ };
+
+ /* Run Test cases */
+
+ cmocka_run_group_tests(nuttx_mm_test_suites, NULL, NULL);
+
+ return 0;
+}
diff --git a/testing/testsuites/kernel/mm/common/test_mm_common.c b/testing/testsuites/kernel/mm/common/test_mm_common.c
new file mode 100644
index 000000000..a5f2ba2b2
--- /dev/null
+++ b/testing/testsuites/kernel/mm/common/test_mm_common.c
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/common/test_mm_common.c
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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 <stdio.h>
+#include <malloc.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: get_rand_size
+ ****************************************************************************/
+
+int mmtest_get_rand_size(int min, int max)
+{
+ int rval = 1;
+ if (min > 0 && max > 0 && (max - min) > 0)
+ {
+ rval = rand() % (max - min) + min;
+ }
+
+ return rval;
+}
+
+/****************************************************************************
+ * Name: mm_showmallinfo
+ ****************************************************************************/
+
+void mmtest_showmallinfo(void)
+{
+ struct mallinfo alloc_info;
+ alloc_info = mallinfo();
+ syslog(LOG_INFO, " mallinfo:\n");
+ syslog(LOG_INFO, " Total space allocated from system = %lu\n",
+ (unsigned long)alloc_info.arena);
+ syslog(LOG_INFO, " Number of non-inuse chunks = %lu\n",
+ (unsigned long)alloc_info.ordblks);
+ syslog(LOG_INFO, " Largest non-inuse chunk = %lu\n",
+ (unsigned long)alloc_info.mxordblk);
+ syslog(LOG_INFO, " Total allocated space = %lu\n",
+ (unsigned long)alloc_info.uordblks);
+ syslog(LOG_INFO, " Total non-inuse space = %lu\n",
+ (unsigned long)alloc_info.fordblks);
+}
+
+/****************************************************************************
+ * Name: mmtest_get_memsize
+ ****************************************************************************/
+
+unsigned long mmtest_get_memsize(void)
+{
+#ifdef CONFIG_ARCH_SIM
+ return 2048;
+#else
+ unsigned long memsize;
+ unsigned long mem_largest;
+ struct mallinfo alloc_info;
+
+ alloc_info = mallinfo();
+ mem_largest = alloc_info.mxordblk;
+ memsize = mem_largest * 0.5;
+
+ /* During the test, the maximum memory is less than 2M */
+
+ if (memsize > 1024 * 1024 * 2)
+ {
+ memsize = 1024 * 1024 * 2;
+ }
+
+ return memsize;
+#endif
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxMmsetup
+ ****************************************************************************/
+
+int test_nuttx_mmsetup(void **state)
+{
+ return 0;
+}
+
+/****************************************************************************
+ * Name: TestNuttxMmteardown
+ ****************************************************************************/
+
+int test_nuttx_mmteardown(void **state)
+{
+ return 0;
+}
diff --git a/testing/testsuites/kernel/mm/include/MmTest.h b/testing/testsuites/kernel/mm/include/MmTest.h
new file mode 100644
index 000000000..3f8509250
--- /dev/null
+++ b/testing/testsuites/kernel/mm/include/MmTest.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/include/MmTest.h
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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.
+ */
+
+#ifndef __SYSCALLTEST_H
+#define __SYSCALLTEST_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define PTHREAD_STACK_SIZE CONFIG_DEFAULT_TASK_STACKSIZE
+#define DEFAULT_STACKSIZE CONFIG_DEFAULT_TASK_STACKSIZE
+#define TASK_PRIORITY SCHED_PRIORITY_DEFAULT
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+int mmtest_get_rand_size(int min, int max);
+void mmtest_showmallinfo(void);
+unsigned long mmtest_get_memsize(void);
+
+int test_nuttx_mmsetup(void **state);
+int test_nuttx_mmteardown(void **state);
+
+/* test case function */
+
+/* cases/mm_test_001.c ******************************************************/
+
+void test_nuttx_mm01(FAR void **state);
+
+/* cases/mm_test_002.c ******************************************************/
+
+void test_nuttx_mm02(FAR void **state);
+
+/* cases/mm_test_003.c ******************************************************/
+
+void test_nuttx_mm03(FAR void **state);
+
+/* cases/mm_test_004.c ******************************************************/
+
+void test_nuttx_mm04(FAR void **state);
+
+/* cases/mm_test_005.c ******************************************************/
+
+void test_nuttx_mm05(FAR void **state);
+
+/* cases/mm_test_006.c ******************************************************/
+
+void test_nuttx_mm06(FAR void **state);
+
+/* cases/mm_test_007.c ******************************************************/
+
+void test_nuttx_mm07(FAR void **state);
+
+/* cases/mm_test_008.c ******************************************************/
+
+void test_nuttx_mm08(FAR void **state);
+
+#endif
\ No newline at end of file
diff --git a/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c b/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c
new file mode 100644
index 000000000..780779cbd
--- /dev/null
+++ b/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c
@@ -0,0 +1,153 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c
+ *
+ * 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 <stdlib.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <time.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: show_usage
+ ****************************************************************************/
+
+static void show_usage(void)
+{
+ printf("\nUsage: mm_stress_test <min_size> \
+ <max_size> <list_length> <test_num>\n");
+ printf("\nWhere:\n");
+ printf(" <min_size> Minimum number of memory requests.\n");
+ printf(" <max_size> Maximum number of memory requests.\n");
+ printf(" <list_length> The length of the memory request list.\n");
+ printf(" <test_num> Number of tests.\n");
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: main
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+ int malloc_size = 0;
+ int mallc_min_size; /* The minimum memory length requested in the test */
+ int mallc_max_size; /* The maximum memory length requested in the test */
+ int list_length;
+ int test_num = 1;
+ struct timespec t_start;
+ struct timespec t_end;
+ long timedif;
+ char *address_ptr = NULL;
+ char **mem_list = NULL;
+
+ if (argc < 5)
+ {
+ syslog(LOG_WARNING, "Missing required arguments\n");
+ show_usage();
+ exit(1);
+ }
+
+ mallc_min_size = atoi(argv[1]);
+ mallc_max_size = atoi(argv[2]);
+ list_length = atoi(argv[3]);
+ test_num = atoi(argv[4]);
+
+ for (int n = 1; n <= test_num; n++)
+ {
+ mem_list = (char **)malloc(sizeof(char *) * list_length);
+ if (mem_list == NULL)
+ {
+ syslog(LOG_ERR, "Failed to apply for the memory list !\n");
+ exit(1);
+ }
+
+ for (int i = 0; i < list_length; i++)
+ {
+ srand(i + gettid());
+ malloc_size = mmtest_get_rand_size(mallc_min_size, mallc_max_size);
+
+ clock_gettime(CLOCK_MONOTONIC, &t_start);
+ address_ptr = (char *)malloc(malloc_size * sizeof(char));
+ clock_gettime(CLOCK_MONOTONIC, &t_end);
+ timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec)
+ + (t_end.tv_nsec - t_start.tv_nsec) / 1000;
+ if (address_ptr != NULL)
+ {
+ syslog(LOG_INFO,
+ "[Test %d Round] Allocate success -> mem_list[%d]"
+ " (address:%p size:%d) takes:%ld microseconds\n",
+ n, i, address_ptr, malloc_size, timedif);
+ memset(address_ptr, 0x67, malloc_size);
+
+ /* Add to list */
+
+ mem_list[i] = address_ptr;
+ }
+ else
+ {
+ syslog(LOG_ERR,
+ "Malloc failed ! The remaining memory may be insufficient\n");
+ syslog(LOG_ERR, "Continue to test !!\n");
+
+ /* Memory allocation failure */
+
+ mem_list[i] = NULL;
+ continue;
+ }
+ }
+
+ for (int k = 0; k < list_length; k++)
+ {
+ address_ptr = mem_list[k];
+ if (address_ptr != NULL)
+ {
+ clock_gettime(CLOCK_MONOTONIC, &t_start);
+ free(address_ptr);
+ clock_gettime(CLOCK_MONOTONIC, &t_end);
+ timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec)
+ + (t_end.tv_nsec - t_start.tv_nsec) / 1000;
+ syslog(LOG_INFO,
+ "[Test %d Round] Free -> mem_list[%d] (size:%d)"
+ " takes:%ld microseconds\n",
+ n, k, malloc_size, timedif);
+ mem_list[k] = NULL;
+ }
+ }
+
+ free(mem_list);
+ }
+
+ return 0;
+}
diff --git a/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c b/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c
new file mode 100644
index 000000000..d4890a7b4
--- /dev/null
+++ b/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c
@@ -0,0 +1,139 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c
+ *
+ * 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 <stdlib.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <time.h>
+#include "MmTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: show_usage
+ ****************************************************************************/
+
+static void show_usage(void)
+{
+ printf("\nUsage: mm_stress_test <min_size> \
+ <max_size> <test_num> <delay_time>\n");
+ printf("\nWhere:\n");
+ printf(" <min_size> Minimum number of memory requests.\n");
+ printf(" <max_size> Maximum number of memory requests.\n");
+ printf(" <test_num> Number of tests.\n");
+ printf(" <delay_time> Malloc delay time, Unit: microseconds.\n");
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: main
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+ int malloc_size;
+ int mallc_min_size; /* The minimum memory length requested in the test */
+ int mallc_max_size; /* The maximum memory length requested in the test */
+ int test_num;
+ int application_delay_time = 1; /* Delay in test */
+ char check_character; /* Memory write content check character */
+ char *address_ptr = NULL;
+ struct timespec t_start;
+ struct timespec t_end;
+ long timedif;
+
+ if (argc < 5)
+ {
+ syslog(LOG_WARNING, "Missing required arguments\n");
+ show_usage();
+ exit(1);
+ }
+
+ mallc_min_size = atoi(argv[1]);
+ mallc_max_size = atoi(argv[2]);
+ test_num = atoi(argv[3]);
+ application_delay_time = atoi(argv[4]);
+
+ for (int i = 0; i < test_num; i++)
+ {
+ srand(i + gettid());
+ malloc_size = mmtest_get_rand_size(mallc_min_size, mallc_max_size);
+ check_character = 0x65;
+ clock_gettime(CLOCK_MONOTONIC, &t_start);
+ address_ptr = (char *)malloc(malloc_size * sizeof(char));
+ clock_gettime(CLOCK_MONOTONIC, &t_end);
+ timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec)
+ + (t_end.tv_nsec - t_start.tv_nsec) / 1000;
+ if (address_ptr != NULL)
+ {
+ syslog(LOG_INFO,
+ "[Test malloc] (address:%p size:%d) takes:%ld microseconds\n",
+ address_ptr, malloc_size, timedif);
+ memset(address_ptr, check_character, malloc_size);
+ }
+ else
+ {
+ syslog(LOG_ERR,
+ "Malloc failed ! The remaining memory may be insufficient\n");
+ syslog(LOG_ERR, "Continue to test !!\n");
+ continue;
+ }
+
+ /* Checking Content Consistency */
+
+ for (int j = 0; j < malloc_size; j++)
+ {
+ if (address_ptr[j] != check_character)
+ {
+ syslog(LOG_ERR, "ERROR:Inconsistent content checking\n");
+ free(address_ptr);
+ return -1;
+ }
+ }
+
+ clock_gettime(CLOCK_MONOTONIC, &t_start);
+
+ /* Free test memory */
+
+ clock_gettime(CLOCK_MONOTONIC, &t_end);
+ timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec)
+ + (t_end.tv_nsec - t_start.tv_nsec) / 1000;
+ syslog(LOG_INFO,
+ "[Test free] (address:%p size:%d) takes:%ld microseconds\n\n",
+ address_ptr, malloc_size, timedif);
+ free(address_ptr);
+ usleep(application_delay_time);
+ }
+
+ return 0;
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c
new file mode 100644
index 000000000..30aaea94a
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void *thread_f01(void *arg)
+{
+ pthread_exit(NULL);
+ return NULL;
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest03
+ ****************************************************************************/
+
+void test_nuttx_pthread_test03(FAR void **state)
+{
+ pthread_t a_thread;
+ pthread_t ptid;
+ pthread_t a = 0;
+ pthread_t b = 0;
+ int tmp;
+ pthread_attr_t aa =
+ {
+ 0
+ };
+
+ int detachstate;
+ UINT32 ret;
+
+ ptid = pthread_self();
+ syslog(LOG_INFO, "ptid: %d \n", ptid);
+ assert_int_not_equal(ptid, 0);
+ pthread_create(&a_thread, NULL, thread_f01, NULL);
+
+ tmp = pthread_equal(a, b);
+ syslog(LOG_INFO, "ret: %d\n", tmp);
+ assert_int_not_equal(tmp, 0);
+
+ pthread_attr_init(&aa);
+
+ ret = pthread_attr_getdetachstate(&aa, &detachstate);
+ syslog(LOG_INFO, "ret of getdetachstate: %d\n", ret);
+ assert_int_equal(ret, 0);
+
+ ret = pthread_attr_setdetachstate(&aa, PTHREAD_CREATE_DETACHED);
+ syslog(LOG_INFO, "ret of setdetachstate: %d\n", ret);
+ assert_int_equal(ret, 0);
+
+ pthread_attr_destroy(&aa);
+
+ ret = pthread_join(a_thread, NULL);
+ syslog(LOG_INFO, "ret of pthread_join: %d\n", ret);
+ assert_int_equal(ret, 0);
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c
new file mode 100644
index 000000000..3a6b98186
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void *thread_f01(void *arg)
+{
+ pthread_exit((void *)2); /* 2, here set value of the exit status. */
+ return NULL;
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest04
+ ****************************************************************************/
+
+void test_nuttx_pthread_test04(FAR void **state)
+{
+ pthread_t main_th;
+ pthread_t new_th;
+ UINT32 ret;
+ UINTPTR temp;
+
+ if (pthread_create(&new_th, NULL, thread_f01, NULL) != 0)
+ {
+ printf("Error creating thread\n");
+ assert_int_equal(1, 0);
+ }
+
+ usleep(1000);
+
+ /* LOS_TaskDelay(1);
+ * Obtain the thread ID of this main function
+ */
+
+ main_th = test_pthread_self();
+
+ /* Compare the thread ID of the new thread to the main thread.
+ * They should be different. If not, the test fails.
+ */
+
+ if (pthread_equal(new_th, main_th) != 0)
+ {
+ printf("Test FAILED: A new thread wasn't created\n");
+ assert_int_equal(1, 0);
+ }
+
+ usleep(1000);
+
+ /* TestExtraTaskDelay(1); */
+
+ ret = pthread_join(new_th, (void *)&temp);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "temp: %ld \n", temp);
+ assert_int_equal(ret, 0);
+ assert_int_equal(temp, 2); /* 2, here assert the result. */
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c
new file mode 100644
index 000000000..7c3e92104
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <time.h>
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void *thread_f01(void *arg)
+{
+ sleep(500);
+
+ /* Shouldn't reach here. If we do, then the pthread_cancel()
+ * function did not succeed.
+ */
+
+ pthread_exit((void *)6);
+ return NULL;
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest05
+ ****************************************************************************/
+
+void test_nuttx_pthread_test05(FAR void **state)
+{
+ pthread_t new_th;
+ UINT32 ret;
+ UINTPTR temp;
+ clock_t start;
+ clock_t finish;
+ double duration;
+
+ start = clock();
+ if (pthread_create(&new_th, NULL, thread_f01, NULL) < 0)
+ {
+ syslog(LOG_INFO, "Error creating thread\n");
+ assert_int_equal(1, 0);
+ }
+
+ usleep(1000);
+
+ /* LOS_TaskDelay(1);
+ * Try to cancel the newly created thread. If an error is returned,
+ * then the thread wasn't created successfully.
+ */
+
+ if (pthread_cancel(new_th) != 0)
+ {
+ syslog(LOG_INFO, "Test FAILED: A new thread wasn't created\n");
+ assert_int_equal(1, 0);
+ }
+
+ ret = pthread_join(new_th, (void *)&temp);
+ finish = clock();
+ duration = (double)(finish - start) / CLOCKS_PER_SEC * 1000;
+ syslog(LOG_INFO, "duration: %f \n", duration);
+ assert_int_equal(duration < 500, 1);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "temp: %ld \n", temp);
+ assert_int_equal(ret, 0);
+ assert_int_not_equal(temp, 6);
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c
new file mode 100644
index 000000000..bf23bcb32
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void *thread_f01(void *arg)
+{
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+
+ sleep(1);
+
+ pthread_exit((void *)0);
+ return NULL;
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest06
+ ****************************************************************************/
+
+void test_nuttx_pthread_test06(FAR void **state)
+{
+ UINT32 ret;
+ void *temp = NULL;
+ pthread_t a;
+
+ /* SIGALRM will be sent in 5 seconds. */
+
+ /* Create a new thread. */
+
+ if (pthread_create(&a, NULL, thread_f01, NULL) != 0)
+ {
+ printf("Error creating thread\n");
+ assert_int_equal(1, 0);
+ }
+
+ usleep(1000);
+
+ /* LOS_TaskDelay(1); */
+
+ pthread_cancel(a);
+
+ /* If 'main' has reached here, then the test passed because it means
+ * that the thread is truly asynchronise, and main isn't waiting for
+ * it to return in order to move on.
+ */
+
+ ret = pthread_join(a, &temp);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c
new file mode 100644
index 000000000..4d14b0e2a
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c
@@ -0,0 +1,102 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void *pthread_f01(void *arg)
+{
+ g_test_pthread_count++;
+
+ pthread_exit(NULL);
+
+ return (void *)9; /* 9, here set value about the return status. */
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest09
+ ****************************************************************************/
+
+void test_nuttx_pthread_test09(FAR void **state)
+{
+ pthread_t new_th;
+ UINT32 ret;
+ UINTPTR temp = 1;
+
+ /* _pthread_data *joinee = NULL; */
+
+ g_test_pthread_count = 0;
+ g_test_pthread_task_max_num = 128;
+
+ ret = pthread_create(&new_th, NULL, pthread_f01, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+ usleep(1000);
+
+ /* LOS_TaskDelay(1); */
+
+ syslog(LOG_INFO, "g_testPthreadCount: %d \n", g_test_pthread_count);
+ assert_int_equal(g_test_pthread_count, 1);
+
+ ret = pthread_join(g_test_pthread_task_max_num, (void *)&temp);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "temp: %ld \n", temp);
+ assert_int_equal(ret, ESRCH);
+ assert_int_equal(temp, 1);
+
+ ret = pthread_join(LOSCFG_BASE_CORE_TSK_CONFIG + 1, (void *)&temp);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, ESRCH);
+ syslog(LOG_INFO, "temp: %ld \n", temp);
+ assert_int_equal(temp, 1);
+
+ ret = pthread_detach(g_test_pthread_task_max_num);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, ESRCH);
+
+ ret = pthread_join(new_th, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+
+ sleep(1);
+ ret = pthread_detach(new_th);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, ESRCH);
+
+ ret = pthread_join(new_th, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, ESRCH);
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c
new file mode 100644
index 000000000..1753538e7
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c
@@ -0,0 +1,146 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <semaphore.h>
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+static sem_t re_pthread_f01;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void *pthread_f01(void *argument)
+{
+ g_test_pthread_count++;
+ sem_wait(&re_pthread_f01);
+
+ return argument;
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest18
+ ****************************************************************************/
+
+void test_nuttx_pthread_test18(FAR void **state)
+{
+ pthread_attr_t attr;
+ pthread_t new_th;
+ UINT32 ret;
+ UINTPTR temp;
+ int policy;
+ struct sched_param param;
+ struct sched_param param2 =
+ {
+ 2
+ }; /* 2, init */
+
+ g_test_pthread_count = 0;
+
+ ret = sem_init(&re_pthread_f01, 0, 0);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+
+ ret = pthread_attr_init(&attr);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+
+ ret = pthread_create(&new_th, NULL, pthread_f01, (void *)9); /* 9, test param of the function. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+ usleep(1000);
+
+ /* LOS_TaskDelay(1); */
+
+ syslog(LOG_INFO, "g_testPthreadCount: %d \n", g_test_pthread_count);
+ assert_int_equal(g_test_pthread_count, 1);
+
+ ret = pthread_setschedparam(new_th, -1, ¶m);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_setschedparam(new_th, 100, ¶m); /* 4, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+#if CONFIG_RR_INTERVAL > 0
+ param.sched_priority = 31; /* 31, init */
+ ret = pthread_setschedparam(new_th, SCHED_RR, ¶m);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+#endif
+
+ ret = pthread_getschedparam(new_th, NULL, ¶m2);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "param2.sched_priority: %d \n", param2.sched_priority);
+ assert_int_equal(ret, EINVAL);
+ assert_int_equal(param2.sched_priority, 2); /* 2, here assert the result. */
+
+ ret = pthread_getschedparam(new_th, &policy, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_getschedparam(new_th, &policy, ¶m2);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "param2.sched_priority: %d \n", param2.sched_priority);
+ assert_int_equal(ret, 0);
+#if CONFIG_RR_INTERVAL > 0
+ assert_int_equal(param2.sched_priority, 31); /* 31, here assert the result. */
+#endif
+
+ ret = sem_post(&re_pthread_f01);
+ syslog(LOG_INFO, "ret of sem_post: %d \n", ret);
+ assert_int_equal(ret, 0);
+ ret = pthread_join(new_th, (void *)&temp);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "temp: %ld \n", temp);
+ assert_int_equal(ret, 0);
+ assert_int_equal(temp, 9); /* 9, here assert the result. */
+
+#if CONFIG_RR_INTERVAL > 0
+ ret = pthread_setschedparam(new_th + 9, SCHED_RR, ¶m); /* 9, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, ESRCH);
+#endif
+
+ ret = pthread_getschedparam(new_th + 8, &policy, ¶m2); /* 8, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, ESRCH);
+
+ ret = pthread_attr_destroy(&attr);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+
+ ret = sem_destroy(&re_pthread_f01);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c
new file mode 100644
index 000000000..875c43bc8
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static void pthread_once_f01(void)
+{
+ g_test_pthread_count++;
+}
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest19
+ ****************************************************************************/
+
+void test_nuttx_pthread_test19(FAR void **state)
+{
+ UINT32 ret;
+ pthread_once_t once_block = PTHREAD_ONCE_INIT;
+
+ g_test_pthread_count = 0;
+
+ ret = pthread_once(NULL, pthread_once_f01);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_once(&once_block, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_once(&once_block, pthread_once_f01);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+ syslog(LOG_INFO, "g_testPthreadCount: %d \n", g_test_pthread_count);
+ assert_int_equal(g_test_pthread_count, 1);
+
+ ret = pthread_once(&once_block, pthread_once_f01);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "g_testPthreadCount: %d \n", g_test_pthread_count);
+ assert_int_equal(ret, 0);
+ assert_int_equal(g_test_pthread_count, 1);
+}
diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c
new file mode 100644
index 000000000..cc81e71bb
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c
+ *
+ * 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 <sys/syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "PthreadTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestNuttxPthreadTest21
+ ****************************************************************************/
+
+void test_nuttx_pthread_test21(FAR void **state)
+{
+ UINT32 ret;
+ int oldstate;
+ int oldstype;
+
+ ret = pthread_setcancelstate(2, &oldstate); /* 2, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_setcancelstate(3, &oldstate); /* 3, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+
+ ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+ syslog(LOG_INFO, "oldstate: %d \n", oldstate);
+ assert_int_equal(oldstate, PTHREAD_CANCEL_ENABLE);
+
+ ret = pthread_setcanceltype(2, &oldstype); /* 2, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_setcanceltype(3, &oldstype); /* 3, test for invalid param. */
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, EINVAL);
+
+ ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ assert_int_equal(ret, 0);
+
+#ifdef CONFIG_CANCELLATION_POINTS
+ ret = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldstate);
+ syslog(LOG_INFO, "ret: %d \n", ret);
+ syslog(LOG_INFO, "oldstate: %d \n", oldstate);
+ assert_int_equal(ret, 0);
+ assert_int_equal(oldstate, PTHREAD_CANCEL_ASYNCHRONOUS);
+#endif
+}
diff --git a/testing/testsuites/kernel/pthread/cmocka_pthread_test.c b/testing/testsuites/kernel/pthread/cmocka_pthread_test.c
new file mode 100644
index 000000000..364b57d0d
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/cmocka_pthread_test.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/cmocka_pthread_test.c
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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 <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "PthreadTest.h"
+#include <cmocka.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cmocka_sched_test_main
+ ****************************************************************************/
+
+int main(int argc, char *argv[])
+{
+ /* Add Test Cases */
+
+ const struct CMUnitTest nuttx_pthread_test_suites[] = {
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test03, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test04, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test05, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test06, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test09, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test18, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test19, NULL, NULL),
+ cmocka_unit_test_setup_teardown(test_nuttx_pthread_test21, NULL, NULL),
+ };
+
+ /* Run Test cases */
+
+ cmocka_run_group_tests(nuttx_pthread_test_suites, NULL, NULL);
+
+ return 0;
+}
diff --git a/testing/testsuites/kernel/pthread/common/test_pthread_common.c b/testing/testsuites/kernel/pthread/common/test_pthread_common.c
new file mode 100644
index 000000000..f0c2ce6e4
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/common/test_pthread_common.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/common/test_pthread_common.c
+ *
+ * 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 <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "PthreadTest.h"
+
+UINT32 g_test_pthread_count;
+UINT32 g_test_pthread_task_max_num = 128;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: TestPthreadSelf
+ ****************************************************************************/
+
+pthread_t test_pthread_self(void)
+{
+ pthread_t tid = pthread_self();
+ return tid;
+}
+
+/****************************************************************************
+ * Name: TestNuttxSyscallTestGroupTearDown
+ ****************************************************************************/
diff --git a/testing/testsuites/kernel/pthread/include/PthreadTest.h b/testing/testsuites/kernel/pthread/include/PthreadTest.h
new file mode 100644
index 000000000..9dc03c7ae
--- /dev/null
+++ b/testing/testsuites/kernel/pthread/include/PthreadTest.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/pthread/include/PthreadTest.h
+ *
+ * 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
+ ****************************************************************************/
+
+#ifndef PTHREAD_TEST_H
+#define PTHREAD_TEST_H
+
+#include <nuttx/config.h>
+#include <errno.h>
+#include <syslog.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "sched.h"
+#include "signal.h"
+#include "semaphore.h"
+#include "sched.h"
+#include "pthread.h"
+#include "limits.h"
+#include "unistd.h"
+#include "mqueue.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+typedef unsigned int UINT32;
+typedef unsigned long UINTPTR;
+
+#define PTHREAD_NO_ERROR 0
+#define PTHREAD_IS_ERROR (-1)
+#define PTHREAD_SIGNAL_SUPPORT 0 /* 0 means that not support the signal */
+#define PTHREAD_PRIORITY_TEST 20
+#define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE)
+#define PTHREAD_KEY_NUM 10
+#define THREAD_NUM 3
+#define PTHREAD_TIMEOUT (THREAD_NUM * 2)
+#define PTHREAD_INTHREAD_TEST 0 /* Control going to or is already for Thread */
+#define PTHREAD_INMAIN_TEST 1 /* Control going to or is already for Main */
+#define INVALID_PSHARED_VALUE (-100)
+#define NUM_OF_CONDATTR 10
+#define RUNTIME 5
+#define PTHREAD_THREADS_NUM 3
+#define TCOUNT 5 // Number of single-threaded polling
+#define COUNT_LIMIT 7 // The number of times the signal is sent
+#define HIGH_PRIORITY 5
+#define LOW_PRIORITY 10
+#define PTHREAD_EXIT_VALUE ((void *)100) /* The return code of the thread when using pthread_exit(). */
+
+#define PTHREAD_EXISTED_NUM TASK_EXISTED_NUM
+#define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM
+
+/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
+
+#define _POSIX_C_SOURCE 200112L
+#define PRIORITY_OTHER (-1)
+#define PRIORITY_FIFO 20
+#define PRIORITY_RR 20
+#define LOSCFG_BASE_CORE_TSK_CONFIG 1024
+
+extern UINT32 g_test_pthread_count;
+extern UINT32 g_test_pthread_task_max_num;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+pthread_t test_pthread_self(void);
+
+/* test case function */
+
+/* cases/posix_pthread_test_003.c *******************************************/
+
+void test_nuttx_pthread_test03(FAR void **state);
+
+/* cases/posix_pthread_test_004.c *******************************************/
+
+void test_nuttx_pthread_test04(FAR void **state);
+
+/* cases/posix_pthread_test_005.c *******************************************/
+
+void test_nuttx_pthread_test05(FAR void **state);
+
+/* cases/posix_pthread_test_006.c *******************************************/
+
+void test_nuttx_pthread_test06(FAR void **state);
+
+/* cases/posix_pthread_test_009.c *******************************************/
+
+void test_nuttx_pthread_test09(FAR void **state);
+
+/* cases/posix_pthread_test_018.c *******************************************/
+
+void test_nuttx_pthread_test18(FAR void **state);
+
+/* cases/posix_pthread_test_019.c *******************************************/
+
+void test_nuttx_pthread_test19(FAR void **state);
+
+/* cases/posix_pthread_test_021.c *******************************************/
+
+void test_nuttx_pthread_test21(FAR void **state);
+#endif
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c
new file mode 100644
index 000000000..84b17c3a2
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread01_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread01_threadroutine(void *arg)
+{
+ int flag;
+ flag = 1;
+ *((int *)arg) = flag;
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread01
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread01(FAR void **state)
+{
+ pthread_t p_t;
+ int run_flag = 0;
+
+ /* create thread */
+
+ pthread_create(&p_t, NULL, sched_pthread01_threadroutine, &run_flag);
+
+ /* pthread_join Wait for the thread to end */
+
+ pthread_join(p_t, NULL);
+ assert_int_equal(run_flag, 1);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c
new file mode 100644
index 000000000..5da762dad
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread02_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread02_threadroutine(void *arg)
+{
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread02
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread02(FAR void **state)
+{
+ int res;
+ pthread_t p_t;
+ pthread_attr_t attr;
+ size_t statck_size;
+ struct sched_param param;
+ struct sched_param o_param;
+
+ /* Initializes thread attributes object (attr) */
+
+ res = pthread_attr_init(&attr);
+ assert_int_equal(res, OK);
+
+ res = pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE);
+ assert_int_equal(res, OK);
+
+ res = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+ assert_int_equal(res, OK);
+
+ param.sched_priority = TASK_PRIORITY + 1;
+
+ res = pthread_attr_setschedparam(&attr, ¶m);
+ assert_int_equal(res, OK);
+
+ /* create thread */
+
+ pthread_create(&p_t, &attr, sched_pthread02_threadroutine, NULL);
+
+ /* Wait for the child thread finish */
+
+ pthread_join(p_t, NULL);
+
+ /* get schedparam */
+
+ res = pthread_attr_getschedparam(&attr, &o_param);
+ assert_int_equal(res, OK);
+
+ /* get stack size */
+
+ res = pthread_attr_getstacksize(&attr, &statck_size);
+ assert_int_equal(res, OK);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c
new file mode 100644
index 000000000..609c6bdaf
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread03_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread03_threadroutine(void *arg)
+{
+ int i = 0;
+ for (i = 0; i <= 5; i++)
+ {
+ if (i == 3)
+ {
+ pthread_exit(0);
+ }
+ }
+
+ /* This part of the code will not be executed */
+
+ *((int *)arg) = 1;
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread03
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread03(FAR void **state)
+{
+ pthread_t pid_1;
+ int ret;
+ int run_flag = 0;
+
+ /* create test thread */
+
+ ret = pthread_create(&pid_1, NULL,
+ (void *)sched_pthread03_threadroutine, &run_flag);
+ assert_int_equal(ret, 0);
+
+ pthread_join(pid_1, NULL);
+
+ assert_int_not_equal(run_flag, 1);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c
new file mode 100644
index 000000000..5d276beaf
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c
@@ -0,0 +1,101 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread04_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread04_threadroutine(void *arg)
+{
+ /* set enable */
+
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+
+ pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
+
+ sleep(1);
+
+ /* cancel point */
+
+ pthread_testcancel();
+
+ /* It can not be executed here */
+
+ *((int *)arg) = 1;
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread04
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread04(FAR void **state)
+{
+ int res;
+ pthread_t p_t_1;
+
+ /* int flag */
+
+ int sched_pthread_test04_run_flag = 0;
+
+ /* create thread_1 */
+
+ res = pthread_create(&p_t_1, NULL,
+ sched_pthread04_threadroutine,
+ &sched_pthread_test04_run_flag);
+ assert_int_equal(res, OK);
+
+ res = pthread_cancel(p_t_1);
+ assert_int_equal(res, OK);
+
+ /* join thread_1 */
+
+ pthread_join(p_t_1, NULL);
+ assert_int_equal(sched_pthread_test04_run_flag, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c
new file mode 100644
index 000000000..cffbfaacb
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread05_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread05_threadroutine(void *arg)
+{
+ int i;
+ for (i = 0; i <= 5; i++)
+ {
+ if (i == 2)
+ {
+ pthread_yield();
+ }
+ }
+
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread05
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread05(FAR void **state)
+{
+ int res;
+ pthread_t p_t;
+
+ /* create thread */
+
+ res = pthread_create(&p_t, NULL, sched_pthread05_threadroutine, NULL);
+
+ assert_int_equal(res, 0);
+
+ pthread_join(p_t, NULL);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c
new file mode 100644
index 000000000..7a52f2ecf
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c
@@ -0,0 +1,92 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread06_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread06_threadroutine(void *arg)
+{
+ int pid;
+
+ /* call pthread_self() */
+
+ pid = pthread_self();
+ assert_true(pid > 0);
+ if (pid > 0)
+ {
+ *((int *)arg) = 0;
+ }
+ else
+ {
+ *((int *)arg) = 1;
+ }
+
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread06
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread06(FAR void **state)
+{
+ pthread_t p_t;
+ int run_flag = 0;
+ int res;
+
+ /* create thread */
+
+ res = pthread_create(&p_t, NULL, sched_pthread06_threadroutine, &run_flag);
+ assert_int_equal(res, OK);
+
+ pthread_join(p_t, NULL);
+
+ assert_int_equal(run_flag, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c
new file mode 100644
index 000000000..82bc59489
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread07_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread07_threadroutine(void *arg)
+{
+ int i;
+ pthread_mutex_t sched_pthread_test07_mutex = PTHREAD_MUTEX_INITIALIZER;
+ for (i = 0; i < 100; i++)
+ {
+ pthread_mutex_lock(&sched_pthread_test07_mutex);
+ (*((int *)arg))++;
+ pthread_mutex_unlock(&sched_pthread_test07_mutex);
+ }
+
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread07
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread07(FAR void **state)
+{
+ int res;
+ pthread_t pt_1, pt_2, pt_3;
+ int run_flag = 0;
+
+ res = pthread_create(&pt_1, NULL,
+ (void *)sched_pthread07_threadroutine, &run_flag);
+ assert_int_equal(res, OK);
+ res = pthread_create(&pt_2, NULL,
+ (void *)sched_pthread07_threadroutine, &run_flag);
+ assert_int_equal(res, OK);
+ res = pthread_create(&pt_3, NULL,
+ (void *)sched_pthread07_threadroutine, &run_flag);
+ assert_int_equal(res, OK);
+
+ pthread_join(pt_1, NULL);
+ pthread_join(pt_2, NULL);
+ pthread_join(pt_3, NULL);
+ sleep(5);
+
+ assert_int_equal(run_flag, 300);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c
new file mode 100644
index 000000000..a2d25a522
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c
@@ -0,0 +1,103 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static sem_t sched_task08_sem;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread08_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread08_threadroutine(void *arg)
+{
+ int i;
+ for (i = 0; i < 5; i++)
+ {
+ sem_wait(&sched_task08_sem);
+ (*((int *)arg))++;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread08
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread08(FAR void **state)
+{
+ int res;
+ pthread_t pthread_id;
+ int run_flag = 0;
+
+ res = sem_init(&sched_task08_sem, 0, 0);
+ assert_int_equal(res, OK);
+
+ /* create pthread */
+
+ res = pthread_create(&pthread_id, NULL,
+ (void *)sched_pthread08_threadroutine, &run_flag);
+ assert_int_equal(res, OK);
+
+ while (1)
+ {
+ sleep(2);
+ res = sem_post(&sched_task08_sem);
+ assert_int_equal(res, OK);
+ if (run_flag == 5)
+ break;
+ }
+
+ res = sem_destroy(&sched_task08_sem);
+ assert_int_equal(res, OK);
+ assert_int_equal(run_flag, 5);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c
new file mode 100644
index 000000000..2e8840111
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static sem_t sched_task09_sem;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_pthread09_threadroutine
+ ****************************************************************************/
+
+static void *sched_pthread09_threadroutine(void *arg)
+{
+ int i;
+ int res;
+ for (i = 0; i < 10; i++)
+ {
+ res = sem_wait(&sched_task09_sem);
+ assert_int_equal(res, OK);
+ (*((int *)arg))++;
+ res = sem_post(&sched_task09_sem);
+ assert_int_equal(res, OK);
+ }
+
+ return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_pthread09
+ ****************************************************************************/
+
+void test_nuttx_sched_pthread09(FAR void **state)
+{
+ int res;
+ pthread_t pthread_id[10];
+ int run_flag = 0;
+
+ res = sem_init(&sched_task09_sem, 0, 1);
+ assert_int_equal(res, OK);
+
+ int i;
+ for (i = 0; i < 10; i++)
+ {
+ res = pthread_create(&pthread_id[i], NULL,
+ (void *)sched_pthread09_threadroutine, &run_flag);
+ assert_int_equal(res, OK);
+ }
+
+ int j;
+ for (j = 0; j < 10; j++)
+ pthread_join(pthread_id[j], NULL);
+
+ res = sem_destroy(&sched_task09_sem);
+ assert_int_equal(res, OK);
+
+ assert_int_equal(run_flag, 100);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_001.c b/testing/testsuites/kernel/sched/cases/api_task_test_001.c
new file mode 100644
index 000000000..a5b2ebf40
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_001.c
@@ -0,0 +1,80 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_001.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task01_routine
+ ****************************************************************************/
+
+static int sched_task01_routine(int argc, char *argv[])
+{
+ char *str = NULL;
+ str = (char *)malloc(sizeof(char) * 1024);
+ assert_non_null(str);
+ memset(str, 'A', 1024);
+ free(str);
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task01
+ ****************************************************************************/
+
+void test_nuttx_sched_task01(FAR void **state)
+{
+ pid_t pid;
+ int status;
+
+ pid = task_create("sched_task01_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task01_routine, NULL);
+ assert_true(pid > 0);
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_002.c b/testing/testsuites/kernel/sched/cases/api_task_test_002.c
new file mode 100644
index 000000000..9b7a1dfa6
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_002.c
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_002.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task02_routine
+ ****************************************************************************/
+
+static int sched_task02_routine(int argc, char *argv[])
+{
+ int i;
+ for (i = 0; i < 10; i++)
+ {
+ sleep(1);
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task02
+ ****************************************************************************/
+
+void test_nuttx_sched_task02(FAR void **state)
+{
+ pid_t pid;
+ int status;
+ int res;
+
+ pid = task_create("sched_task02_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task02_routine, NULL);
+ assert_true(pid > 0);
+ for (int i = 0; i < 2; i++)
+ {
+ sleep(2);
+ res = task_restart(pid);
+ assert_int_equal(res, OK);
+ }
+
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_003.c b/testing/testsuites/kernel/sched/cases/api_task_test_003.c
new file mode 100644
index 000000000..e26c289c6
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_003.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_003.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task03_routine
+ ****************************************************************************/
+
+static int sched_task03_routine(int argc, char *argv[])
+{
+ int i;
+ for (i = 0; i < 100; ++i)
+ {
+ usleep(20000);
+
+ /* Run some simulated tasks */
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task03
+ ****************************************************************************/
+
+void test_nuttx_sched_task03(FAR void **state)
+{
+ pid_t pid;
+ int res;
+ pid = task_create("sched_task03_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task03_routine, NULL);
+ assert_true(pid > 0);
+
+ int i;
+ for (i = 0; i < 5; ++i)
+ {
+ usleep(2000);
+ }
+
+ res = task_delete(pid);
+ assert_int_equal(res, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_004.c b/testing/testsuites/kernel/sched/cases/api_task_test_004.c
new file mode 100644
index 000000000..05dea32fd
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_004.c
@@ -0,0 +1,116 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_004.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task04_routine
+ ****************************************************************************/
+
+static int sched_task04_routine(int argc, char *argv[])
+{
+ for (int i = 0; i < 5; i++)
+ {
+ /* Run some simulated tasks */
+
+ sleep(1);
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task04
+ ****************************************************************************/
+
+void test_nuttx_sched_task04(FAR void **state)
+{
+ pid_t pid;
+ int status;
+ int ret;
+
+ struct sched_param task_entry_param;
+
+ /* create a test task */
+
+ pid = task_create("sched_task04_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task04_routine, NULL);
+ assert_true(pid > 0);
+ ret = sched_getparam(pid, &task_entry_param);
+ assert_int_equal(ret, 0);
+#if CONFIG_RR_INTERVAL > 0
+ ret = sched_setscheduler(pid, SCHED_RR, &task_entry_param);
+ assert_int_equal(ret, OK);
+ if (ret != OK)
+ {
+ syslog(LOG_ERR, "RR scheduling is not supported !\n");
+ }
+
+ switch (sched_getscheduler(pid))
+ {
+ case SCHED_FIFO:
+ syslog(LOG_INFO, "[%s]:scheduling policy is FIFO!\n", __func__);
+ break;
+ case SCHED_RR:
+ syslog(LOG_INFO, "[%s]:scheduling policy is RR!\n", __func__);
+ break;
+ case SCHED_OTHER:
+ syslog(LOG_INFO, "[%s]:scheduling policy is OTHER!\n", __func__);
+ break;
+ default:
+ break;
+ }
+
+#endif
+ task_entry_param.sched_priority = 100;
+ ret = sched_setparam(pid, &task_entry_param);
+ assert_int_equal(ret, OK);
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_005.c b/testing/testsuites/kernel/sched/cases/api_task_test_005.c
new file mode 100644
index 000000000..7e6d2fa96
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_005.c
@@ -0,0 +1,86 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_005.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task05_routine
+ ****************************************************************************/
+
+static int sched_task05_routine(int argc, char *argv[])
+{
+ int ret;
+ int i;
+ for (i = 1; i <= 10; i++)
+ {
+ if (i >= 4 && i <= 7)
+ {
+ ret = sched_yield();
+ assert_int_equal(ret, OK);
+ }
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task05
+ ****************************************************************************/
+
+void test_nuttx_sched_task05(FAR void **state)
+{
+ pid_t pid;
+ int status;
+
+ pid = task_create("sched_task05_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task05_routine, NULL);
+ assert_true(pid > 0);
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_006.c b/testing/testsuites/kernel/sched/cases/api_task_test_006.c
new file mode 100644
index 000000000..04e5ac995
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_006.c
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_006.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <nuttx/sched.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task06_routine
+ ****************************************************************************/
+
+static int sched_task06_routine(int argc, char *argv[])
+{
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task06
+ ****************************************************************************/
+
+void test_nuttx_sched_task06(FAR void **state)
+{
+ pid_t pid;
+ int status;
+ int priority_max;
+ int priority_min;
+
+ /* struct sched_param task_entry_param */
+
+ pid = task_create("sched_task06_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task06_routine, NULL);
+ assert_true(pid > 0);
+ priority_max = sched_get_priority_max(SCHED_FIFO);
+ priority_min = sched_get_priority_min(SCHED_FIFO);
+ assert_int_equal(priority_max, SCHED_PRIORITY_MAX);
+ assert_int_equal(priority_min, SCHED_PRIORITY_MIN);
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_007.c b/testing/testsuites/kernel/sched/cases/api_task_test_007.c
new file mode 100644
index 000000000..7c29dcbb2
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cases/api_task_test_007.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cases/api_task_test_007.c
+ *
+ * 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 <stdio.h>
+#include <syslog.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <nuttx/sched.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_task07_routine
+ ****************************************************************************/
+
+static int sched_task07_routine(int argc, char *argv[])
+{
+ /* lock */
+
+ sched_lock();
+ int i;
+ for (i = 0; i < 10; i++)
+ {
+ usleep(2000);
+
+ /* Run some simulated tasks */
+ }
+
+ if (sched_lockcount() != 1)
+ {
+ fail_msg("test fail !");
+ return 0;
+ }
+
+ /* unlock */
+
+ sched_unlock();
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_sched_task07
+ ****************************************************************************/
+
+void test_nuttx_sched_task07(FAR void **state)
+{
+ pid_t pid;
+ int status;
+
+ pid = task_create("sched_task07_routine", TASK_PRIORITY,
+ DEFAULT_STACKSIZE, sched_task07_routine, NULL);
+ assert_true(pid > 0);
+
+ waitpid(pid, &status, 0);
+}
diff --git a/testing/testsuites/kernel/sched/cmocka_sched_test.c b/testing/testsuites/kernel/sched/cmocka_sched_test.c
new file mode 100644
index 000000000..c962a5e79
--- /dev/null
+++ b/testing/testsuites/kernel/sched/cmocka_sched_test.c
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/cmocka_sched_test.c
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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 <stdarg.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include "SchedTest.h"
+#include <cmocka.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cmocka_sched_test_main
+ ****************************************************************************/
+
+int main(int argc, char *argv[])
+{
+ /* Add Test Cases */
+
+ const struct CMUnitTest nuttx_sched_testsuites[] = {
+ cmocka_unit_test(test_nuttx_sched_pthread01),
+ cmocka_unit_test(test_nuttx_sched_pthread02),
+ cmocka_unit_test(test_nuttx_sched_pthread03),
+ cmocka_unit_test(test_nuttx_sched_pthread04),
+ cmocka_unit_test(test_nuttx_sched_pthread05),
+ cmocka_unit_test(test_nuttx_sched_pthread06),
+ cmocka_unit_test(test_nuttx_sched_pthread07),
+ cmocka_unit_test(test_nuttx_sched_pthread08),
+ cmocka_unit_test(test_nuttx_sched_pthread09),
+ cmocka_unit_test(test_nuttx_sched_task01),
+ cmocka_unit_test(test_nuttx_sched_task02),
+ cmocka_unit_test(test_nuttx_sched_task03),
+ cmocka_unit_test(test_nuttx_sched_task04),
+ cmocka_unit_test(test_nuttx_sched_task05),
+ cmocka_unit_test(test_nuttx_sched_task06),
+ cmocka_unit_test(test_nuttx_sched_task07),
+ };
+
+ /* Run Test cases */
+
+ cmocka_run_group_tests(nuttx_sched_testsuites,
+ test_nuttx_schedtest_group_setup,
+ test_nuttx_schedtest_group_teardown);
+ return 0;
+}
diff --git a/testing/testsuites/kernel/sched/common/test_sched_common.c b/testing/testsuites/kernel/sched/common/test_sched_common.c
new file mode 100644
index 000000000..f83c4416b
--- /dev/null
+++ b/testing/testsuites/kernel/sched/common/test_sched_common.c
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/common/test_sched_common.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include "SchedTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_schedtest_group_setup
+ ****************************************************************************/
+
+int test_nuttx_schedtest_group_setup(void **state)
+{
+ /* syslog(LOG_INFO, "This is goup setup !\n"); */
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: test_nuttx_schedtest_group_teardown
+ ****************************************************************************/
+
+int test_nuttx_schedtest_group_teardown(void **state)
+{
+ /* syslog(LOG_INFO, "This is goup tearDown !\n"); */
+
+ return 0;
+}
diff --git a/testing/testsuites/kernel/sched/include/SchedTest.h b/testing/testsuites/kernel/sched/include/SchedTest.h
new file mode 100644
index 000000000..19312d688
--- /dev/null
+++ b/testing/testsuites/kernel/sched/include/SchedTest.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/sched/include/SchedTest.h
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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.
+ */
+
+#ifndef __SCHEDTEST_H
+#define __SCHEDTEST_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define PTHREAD_STACK_SIZE CONFIG_DEFAULT_TASK_STACKSIZE
+#define DEFAULT_STACKSIZE CONFIG_DEFAULT_TASK_STACKSIZE
+#define TASK_PRIORITY SCHED_PRIORITY_DEFAULT
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* common/common_test.c *****************************************************/
+
+int test_nuttx_schedtest_group_setup(void **state);
+int test_nuttx_schedtest_group_teardown(void **state);
+
+/* testcase function */
+
+/* cases/api_pthread_test_001.c *********************************************/
+
+void test_nuttx_sched_pthread01(FAR void **state);
+
+/* cases/api_pthread_test_002.c *********************************************/
+
+void test_nuttx_sched_pthread02(FAR void **state);
+
+/* cases/api_pthread_test_003.c *********************************************/
+
+void test_nuttx_sched_pthread03(FAR void **state);
+
+/* cases/api_pthread_test_004.c *********************************************/
+
+void test_nuttx_sched_pthread04(FAR void **state);
+
+/* cases/api_pthread_test_005.c *********************************************/
+
+void test_nuttx_sched_pthread05(FAR void **state);
+
+/* cases/api_pthread_test_006.c *********************************************/
+
+void test_nuttx_sched_pthread06(FAR void **state);
+
+/* cases/api_pthread_test_007.c *********************************************/
+
+void test_nuttx_sched_pthread07(FAR void **state);
+
+/* cases/api_pthread_test_008.c *********************************************/
+
+void test_nuttx_sched_pthread08(FAR void **state);
+
+/* cases/api_pthread_test_009.c *********************************************/
+
+void test_nuttx_sched_pthread09(FAR void **state);
+
+/* cases/api_task_test_001.c ************************************************/
+
+void test_nuttx_sched_task01(FAR void **state);
+
+/* cases/api_task_test_002.c ************************************************/
+
+void test_nuttx_sched_task02(FAR void **state);
+
+/* cases/api_task_test_003.c ************************************************/
+
+void test_nuttx_sched_task03(FAR void **state);
+
+/* cases/api_task_test_004.c ************************************************/
+
+void test_nuttx_sched_task04(FAR void **state);
+
+/* cases/api_task_test_005.c ************************************************/
+
+void test_nuttx_sched_task05(FAR void **state);
+
+/* cases/api_task_test_006.c ************************************************/
+
+void test_nuttx_sched_task06(FAR void **state);
+
+/* cases/api_task_test_007.c ************************************************/
+
+void test_nuttx_sched_task07(FAR void **state);
+
+#endif
\ No newline at end of file
diff --git a/testing/testsuites/kernel/time/cases/clock_test_clock01.c b/testing/testsuites/kernel/time/cases/clock_test_clock01.c
new file mode 100644
index 000000000..e2570a6b7
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_clock01.c
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_clock01.c
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_clock01
+ ****************************************************************************/
+
+void test_nuttx_clock_test_clock01(FAR void **state)
+{
+ clockid_t clk = CLOCK_REALTIME;
+ struct timespec res;
+ struct timespec tp;
+ struct timespec oldtp;
+ int ret;
+ int passflag = 0;
+
+ /* get clock resolution */
+
+ ret = clock_getres(clk, &res);
+ assert_int_equal(ret, 0);
+
+ /* get current real time */
+
+ ret = clock_gettime(clk, &oldtp);
+ syslog(LOG_INFO, "The current real time: sec is %lld, nsec is %ld\n",
+ (long long)oldtp.tv_sec, oldtp.tv_nsec);
+ assert_int_equal(ret, 0);
+
+ syslog(LOG_INFO, "sleep 2 seconds\n");
+ sleep(2); /* 2, seconds. */
+
+ tp.tv_sec = oldtp.tv_sec + 2; /* 2, use for testing clock setting */
+ tp.tv_nsec = oldtp.tv_nsec;
+
+ /* set real time */
+
+ ret = clock_settime(clk, &tp);
+ syslog(LOG_INFO, "Setting time: sec is %lld, nsec is %ld\n",
+ (long long)tp.tv_sec, tp.tv_nsec);
+ assert_int_equal(ret, 0);
+
+ syslog(LOG_INFO, "get real time clock again\n");
+
+ /* get current real time again */
+
+ ret = clock_gettime(clk, &tp);
+ syslog(LOG_INFO,
+ "Obtaining the current time after setting:"
+ " sec = %lld, nsec = %ld\n",
+ (long long)tp.tv_sec,
+ tp.tv_nsec);
+
+ /* 2, use for testing clock setting */
+
+ passflag = (tp.tv_sec >= 2 + oldtp.tv_sec)
+ && (tp.tv_sec <= 2 + oldtp.tv_sec + 1);
+
+ assert_int_equal(ret, 0);
+ assert_int_equal(passflag, 1);
+}
diff --git a/testing/testsuites/kernel/time/cases/clock_test_clock02.c b/testing/testsuites/kernel/time/cases/clock_test_clock02.c
new file mode 100644
index 000000000..c3b05ebba
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_clock02.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_clock02.c
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <pthread.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_clock02
+ ****************************************************************************/
+
+void test_nuttx_clock_test_clock02(FAR void **state)
+{
+ int ret;
+ struct timespec ts;
+ errno = 0;
+
+ /* check param invalid */
+
+ ret = clock_gettime((clockid_t)-2050, &ts); /* 2050, clock id. */
+ assert_int_equal(ret, -1);
+ assert_int_equal(errno, EINVAL);
+}
diff --git a/testing/testsuites/kernel/time/cases/clock_test_smoke.c b/testing/testsuites/kernel/time/cases/clock_test_smoke.c
new file mode 100644
index 000000000..595c1a48c
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_smoke.c
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_smoke.c
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_smoke01
+ ****************************************************************************/
+
+void test_nuttx_clock_test_smoke01(FAR void **state)
+{
+ clockid_t clk = CLOCK_REALTIME;
+ struct timespec res = {
+ 0,
+ 0,
+ };
+
+ struct timespec setts = {
+ 0,
+ 0,
+ };
+
+ struct timespec oldtp = {
+ 0,
+ 0
+ };
+
+ struct timespec ts = {
+ 0,
+ 0,
+ };
+
+ int ret;
+ int passflag = 0;
+
+ /* get clock resolution */
+
+ ret = clock_getres(clk, &res);
+ assert_int_equal(ret, 0);
+
+ /* get clock realtime */
+
+ ret = clock_gettime(clk, &oldtp);
+ syslog(LOG_INFO, "the clock current time: %lld second, %ld nanosecond\n",
+ (long long)oldtp.tv_sec, oldtp.tv_nsec);
+ assert_int_equal(ret, 0);
+
+ /* set clock realtime */
+
+ setts.tv_sec = oldtp.tv_sec + 1;
+ setts.tv_nsec = oldtp.tv_nsec;
+ syslog(LOG_INFO, "the clock setting time: %lld second, %ld nanosecond\n",
+ (long long)setts.tv_sec, setts.tv_nsec);
+ ret = clock_settime(CLOCK_REALTIME, &setts);
+ assert_int_equal(ret, 0);
+
+ ret = clock_gettime(clk, &ts);
+ syslog(LOG_INFO,
+ "obtaining the current time after "
+ "setting: %lld second, %ld nanosecond\n",
+ (long long)ts.tv_sec,
+ ts.tv_nsec);
+
+ /* 1, means obtaining time's errno is 1 second. */
+
+ passflag = (ts.tv_sec >= setts.tv_sec) && (ts.tv_sec <= setts.tv_sec + 1);
+ assert_int_equal(ret, 0);
+ assert_int_equal(passflag, 1);
+}
diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer01.c b/testing/testsuites/kernel/time/cases/clock_test_timer01.c
new file mode 100644
index 000000000..e2f1920b0
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_timer01.c
@@ -0,0 +1,182 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_timer01.c
+ *
+ * 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 <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SIG SIGALRM
+#define CLOCKID CLOCK_REALTIME
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static int test_timer01_g_sig_hdl_cnt = 0;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sig_handler01
+ ****************************************************************************/
+
+static void sig_handler01(int sig)
+{
+ test_timer01_g_sig_hdl_cnt++;
+ syslog(LOG_INFO, "signo = %d test_timer01_g_sig_hdl_cnt = %d\n",
+ sig, test_timer01_g_sig_hdl_cnt);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_timer01
+ ****************************************************************************/
+
+void test_nuttx_clock_test_timer01(FAR void **state)
+{
+ int interval = 3; /* 3, seconds */
+ timer_t timerid01;
+ timer_t timerid02;
+ struct sigevent sev;
+ struct itimerspec its;
+ sigset_t mask;
+ struct sigaction sa;
+ int ret;
+
+ sa.sa_flags = 0;
+ sa.sa_handler = sig_handler01;
+ sigemptyset(&sa.sa_mask);
+ ret = sigaction(SIG, &sa, NULL);
+ syslog(LOG_INFO, "sigaction %d: %d", SIG, ret);
+ assert_int_equal(ret, 0);
+
+ /* Block timer signal */
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIG);
+ ret = sigprocmask(SIG_BLOCK, &mask, NULL);
+ syslog(LOG_INFO, "sigprocmask setmask %d: %d", SIG, ret);
+ assert_int_equal(ret, 0);
+
+ /* Create the timer */
+
+ sev.sigev_notify = SIGEV_SIGNAL;
+ sev.sigev_signo = SIG;
+ sev.sigev_value.sival_ptr = &timerid01;
+ ret = timer_create(CLOCKID, &sev, &timerid01);
+ syslog(LOG_INFO, "timer_create %p: %d", timerid01, ret);
+ assert_int_equal(ret, 0);
+
+ /* Start the timer */
+
+ its.it_value.tv_sec = 0;
+ its.it_value.tv_nsec = 900000000; /* 900000000, 0.9s */
+ its.it_interval.tv_sec = its.it_value.tv_sec;
+ its.it_interval.tv_nsec = its.it_value.tv_nsec;
+
+ ret = timer_settime(timerid01, 0, &its, NULL);
+ syslog(LOG_INFO, "timer_settime %p: %d", timerid01, ret);
+ assert_int_equal(ret, 0);
+
+ /* Test of evp is NULL */
+
+ ret = timer_create(CLOCKID, NULL, &timerid02);
+ syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret);
+ assert_int_equal(ret, 0);
+
+ its.it_value.tv_sec = 1;
+ its.it_value.tv_nsec = 0;
+ its.it_interval.tv_sec = its.it_value.tv_sec;
+ its.it_interval.tv_nsec = its.it_value.tv_nsec;
+
+ ret = timer_settime(timerid02, 0, &its, NULL);
+ syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret);
+ assert_int_equal(ret, 0);
+
+ sleep(6);
+
+ /* Sleep for a while */
+
+ syslog(LOG_INFO, "sleep %ds", interval);
+
+ /* timer signal is blocked, this sleep should not be interrupted */
+
+ sleep(interval);
+
+ /* Get the timer's time */
+
+ ret = timer_gettime(timerid01, &its);
+ syslog(LOG_INFO, "timer_gettime %p: %d", timerid01, ret);
+ assert_int_equal(ret, 0); /* get time success */
+
+ syslog(LOG_INFO, "unblock signal %d", SIG);
+
+ /* Unlock the timer signal */
+
+ ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ syslog(LOG_INFO, "sigprocmask unblock %d: %d", SIG, ret);
+ assert_int_equal(ret, 0);
+
+ interval = 1;
+ syslog(LOG_INFO, "sleep another %ds", interval);
+ sleep(interval); /* this sleep may be interrupted by the timer */
+ syslog(LOG_INFO, "sleep time over, test_timer01_g_sig_hdl_cnt = %d",
+ test_timer01_g_sig_hdl_cnt);
+
+ syslog(LOG_INFO, "sleep another %ds", interval);
+ sleep(interval); /* this sleep may be interrupted by the timer */
+ syslog(LOG_INFO, "sleep time over, test_timer01_g_sig_hdl_cnt = %d",
+ test_timer01_g_sig_hdl_cnt);
+
+ ret = timer_delete(timerid01);
+ syslog(LOG_INFO, "timer_delete %p %d", timerid01, ret);
+ assert_int_equal(ret, 0);
+
+ ret = timer_delete(timerid02);
+ syslog(LOG_INFO, "timer_delete %p %d", timerid02, ret);
+ assert_int_equal(ret, 0);
+
+ assert_int_not_equal(test_timer01_g_sig_hdl_cnt, 0);
+}
diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer03.c b/testing/testsuites/kernel/time/cases/clock_test_timer03.c
new file mode 100644
index 000000000..421a86397
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_timer03.c
@@ -0,0 +1,137 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_timer03.c
+ *
+ * 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 <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SIG SIGALRM
+#define CLOCKID CLOCK_REALTIME
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_timer03
+ ****************************************************************************/
+
+void test_nuttx_clock_test_timer03(FAR void **state)
+{
+ int ret = 0;
+ int sig = 0;
+ int failed = 0;
+ timer_t timerid;
+ sigset_t set;
+ sigset_t old_set;
+ struct sigevent sev;
+
+ ret = sigemptyset(&set);
+ assert_int_equal(ret, 0);
+
+ ret = sigaddset(&set, SIG);
+ assert_int_equal(ret, 0);
+
+ ret = sigprocmask(SIG_BLOCK, &set, &old_set);
+ assert_int_equal(ret, 0);
+
+ /* Create the timer */
+
+ sev.sigev_notify = SIGEV_SIGNAL;
+ sev.sigev_signo = SIG;
+ sev.sigev_value.sival_ptr = &timerid;
+ ret = timer_create(CLOCKID, &sev, &timerid);
+ syslog(LOG_INFO, "timer_create %p: %d", timerid, ret);
+ assert_int_equal(ret, 0);
+
+ struct timespec testcases[] = {
+ {0, 30000000},
+ {1, 0},
+ {1, 5000},
+ };
+
+ struct timespec zero = {
+ 0,
+ 0,
+ };
+
+ for (int i = 0; i < sizeof(testcases) / sizeof(testcases[0]); ++i)
+ {
+ struct timespec start;
+ struct timespec end;
+ struct itimerspec its;
+ int64_t expected;
+ int64_t escaped;
+
+ its.it_interval = zero;
+ its.it_value = testcases[i];
+
+ ret = clock_gettime(CLOCKID, &start);
+ assert_int_equal(ret, 0);
+
+ ret = timer_settime(timerid, 0, &its, NULL);
+ assert_int_equal(ret, 0);
+
+ ret = sigwait(&set, &sig);
+ assert_int_equal(ret, 0);
+
+ ret = clock_gettime(CLOCKID, &end);
+ assert_int_equal(ret, 0);
+
+ expected = its.it_value.tv_sec * (int64_t)(1e9) + its.it_value.tv_nsec;
+ escaped = end.tv_sec * (int64_t)(1e9) + end.tv_nsec -
+ start.tv_sec * (int64_t)(1e9) - start.tv_nsec;
+
+ /* 20000000, 2 ticks. */
+
+ failed += (escaped < expected || (escaped - expected) >= 20000000);
+ syslog(LOG_INFO, "expected = %lld escaped = %lld failed = %d",
+ expected, escaped, failed);
+ }
+
+ ret = timer_delete(timerid);
+ assert_int_equal(ret, 0);
+
+ ret = sigprocmask(SIG_SETMASK, &old_set, NULL);
+ assert_int_equal(ret, 0);
+
+ assert_int_equal(failed, 0);
+}
diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer04.c b/testing/testsuites/kernel/time/cases/clock_test_timer04.c
new file mode 100644
index 000000000..972aa5c21
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_timer04.c
@@ -0,0 +1,161 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_timer04.c
+ *
+ * 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 <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* signo should be in the range SIGRTMIN to
+ * SIGRTMAX when SA_SIGINFO flag is set.
+ */
+
+#define SIG SIGRTMIN
+#define CLOCKID CLOCK_REALTIME
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static int test_timer04_g_handler_flag;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sig_handler
+ ****************************************************************************/
+
+static void sig_handler(int sig, siginfo_t *si, void *uc)
+{
+ if (si == NULL)
+ {
+ syslog(LOG_ERR, "sig %d, si %p, uc %p\n", sig, si, uc);
+ return;
+ }
+
+ test_timer04_g_handler_flag++;
+ syslog(LOG_INFO, "sig %d, si %p, uc %p\n", sig, si, uc);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_timer04
+ ****************************************************************************/
+
+void test_nuttx_clock_test_timer04(FAR void **state)
+{
+ int interval = 3; /* 3 seconds */
+ timer_t timerid;
+ struct sigevent sev;
+ struct itimerspec its;
+ sigset_t mask;
+ struct sigaction sa;
+ int ret;
+
+ /* Install handler for timer signal. */
+
+ sa.sa_flags = SA_SIGINFO;
+ sa.sa_sigaction = sig_handler;
+ sigemptyset(&sa.sa_mask);
+ ret = sigaction(SIG, &sa, NULL);
+ syslog(LOG_INFO, "sigaction %d: %d", SIG, ret);
+ assert_int_equal(ret, 0);
+
+ /* Block timer signal */
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIG);
+ ret = sigprocmask(SIG_BLOCK, &mask, NULL);
+ syslog(LOG_INFO, "sigaction %d: %d", SIG, ret);
+ assert_int_equal(ret, 0);
+
+ /* Create the timer */
+
+ sev.sigev_notify = SIGEV_SIGNAL;
+ sev.sigev_signo = SIG;
+ sev.sigev_value.sival_ptr = &timerid;
+ ret = timer_create(CLOCKID, &sev, &timerid);
+ syslog(LOG_INFO, "timer_create %p: %d", timerid, ret);
+ assert_int_equal(ret, 0);
+
+ /* Start the timer */
+
+ its.it_value.tv_sec = 0;
+ its.it_value.tv_nsec = 990000000; /* 990000000, 0.99s */
+ its.it_interval.tv_sec = its.it_value.tv_sec;
+ its.it_interval.tv_nsec = its.it_value.tv_nsec;
+
+ ret = timer_settime(timerid, 0, &its, NULL);
+ syslog(LOG_INFO, "timer_create %p: %d", timerid, ret);
+ assert_int_equal(ret, 0);
+
+ /* Sleep for a while */
+
+ syslog(LOG_INFO, "sleep %ds", interval);
+ sleep(interval); /* should not be interrupted */
+
+ /* Get the timer's time */
+
+ ret = timer_gettime(timerid, &its);
+ syslog(LOG_INFO, "timer_gettime %p: %d", timerid, ret);
+ assert_int_equal(ret, 0);
+
+ /* Unlock the timer signal */
+
+ ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ syslog(LOG_INFO, "sigprocmask unblock %d: %d", SIG, ret);
+ assert_int_equal(ret, 0);
+
+ syslog(LOG_INFO, "sleep another %ds", interval);
+ sleep(interval); /* should be interrupted */
+ syslog(LOG_INFO, "sleep time over, g_handlerFlag = %d",
+ test_timer04_g_handler_flag);
+
+ ret = timer_delete(timerid);
+ syslog(LOG_INFO, "timer_delete %p %d", timerid, ret);
+ assert_int_equal(ret, 0);
+
+ assert_int_not_equal(test_timer04_g_handler_flag, 0);
+}
diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer05.c b/testing/testsuites/kernel/time/cases/clock_test_timer05.c
new file mode 100644
index 000000000..4c0528d3c
--- /dev/null
+++ b/testing/testsuites/kernel/time/cases/clock_test_timer05.c
@@ -0,0 +1,169 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cases/clock_test_timer05.c
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <syslog.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include "TimeTest.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static int test_timer05_g_sig_hdl_cnt01;
+static int test_timer05_g_sig_hdl_cnt02;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: temp_sig_handler
+ ****************************************************************************/
+
+static void temp_sig_handler(union sigval v)
+{
+ syslog(LOG_INFO, "This is temp_sig_handler ...\r\n");
+ (*(void (*)(void))(v.sival_ptr))();
+}
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: temp_sig_handler01
+ ****************************************************************************/
+
+static void temp_sig_handler01(void)
+{
+ test_timer05_g_sig_hdl_cnt01++;
+}
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: temp_sig_handler02
+ ****************************************************************************/
+
+static void temp_sig_handler02(void)
+{
+ test_timer05_g_sig_hdl_cnt02++;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: test_nuttx_clock_test_timer05
+ ****************************************************************************/
+
+void test_nuttx_clock_test_timer05(FAR void **state)
+{
+ timer_t timerid01;
+ timer_t timerid02;
+ struct sigevent sev;
+ struct itimerspec its;
+ int ret;
+ char *p = NULL;
+
+ p = memset(&sev, 0, sizeof(struct sigevent));
+ assert_non_null(p);
+ sev.sigev_notify = SIGEV_THREAD;
+ sev.sigev_notify_function = temp_sig_handler;
+ sev.sigev_value.sival_ptr = (void *)temp_sig_handler01;
+
+ /* Start the timer */
+
+ its.it_value.tv_sec = 3; /* 3, timer time 3 seconds. */
+ its.it_value.tv_nsec = 0;
+ its.it_interval.tv_sec = its.it_value.tv_sec;
+ its.it_interval.tv_nsec = its.it_value.tv_nsec;
+ ret = timer_create(CLOCK_REALTIME, &sev, &timerid01);
+ syslog(LOG_INFO, "timer_settime %p: %d", timerid01, ret);
+ assert_int_equal(ret, 0);
+
+ ret = timer_settime(timerid01, 0, &its, NULL);
+ syslog(LOG_INFO, "timer_create %p: %d", timerid01, ret);
+ assert_int_equal(ret, 0);
+
+ its.it_value.tv_sec = 4; /* 4, timer time 4 seconds. */
+ its.it_value.tv_nsec = 0;
+ its.it_interval.tv_sec = its.it_value.tv_sec;
+ its.it_interval.tv_nsec = its.it_value.tv_nsec;
+
+ sev.sigev_value.sival_ptr = (void *)temp_sig_handler02;
+ ret = timer_create(CLOCK_REALTIME, &sev, &timerid02);
+ syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret);
+ assert_int_equal(ret, 0);
+
+ ret = timer_settime(timerid02, 0, &its, NULL);
+ syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret);
+ assert_int_equal(ret, 0);
+
+ its.it_value.tv_sec = 5; /* 5, timer time 5 seconds. */
+ its.it_value.tv_nsec = 0;
+ its.it_interval.tv_sec = its.it_value.tv_sec;
+ its.it_interval.tv_nsec = its.it_value.tv_nsec;
+
+ sleep(20); /* 20, sleep seconds for timer. */
+ ret = timer_delete(timerid01);
+ syslog(LOG_INFO, "timer_delete %p %d", timerid01, ret);
+ assert_int_equal(ret, 0);
+
+ ret = timer_delete(timerid02);
+ syslog(LOG_INFO, "timer_delete %p %d", timerid02, ret);
+ assert_int_equal(ret, 0);
+
+ assert_int_not_equal(test_timer05_g_sig_hdl_cnt01, 0);
+ assert_int_not_equal(test_timer05_g_sig_hdl_cnt02, 0);
+}
diff --git a/testing/testsuites/kernel/time/cmocka_time_test.c b/testing/testsuites/kernel/time/cmocka_time_test.c
new file mode 100644
index 000000000..f3fe1d06f
--- /dev/null
+++ b/testing/testsuites/kernel/time/cmocka_time_test.c
@@ -0,0 +1,57 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/cmocka_time_test.c
+ * Copyright (C) 2020 Xiaomi Corporation
+ *
+ * Licensed 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 <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include "TimeTest.h"
+#include <cmocka.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cmocka_time_test_main
+ ****************************************************************************/
+
+int main(int argc, char *argv[])
+{
+ /* Add Test Cases */
+
+ const struct CMUnitTest nuttx_time_testsuites[] = {
+ cmocka_unit_test(test_nuttx_clock_test_smoke01),
+ cmocka_unit_test(test_nuttx_clock_test_timer01),
+ cmocka_unit_test(test_nuttx_clock_test_timer03),
+ cmocka_unit_test(test_nuttx_clock_test_timer04),
+ cmocka_unit_test(test_nuttx_clock_test_timer05),
+ cmocka_unit_test(test_nuttx_clock_test_clock01),
+ cmocka_unit_test(test_nuttx_clock_test_clock02),
+ };
+
+ /* Run Test cases */
+
+ cmocka_run_group_tests(nuttx_time_testsuites, NULL, NULL);
+ return 0;
+}
diff --git a/testing/testsuites/kernel/time/include/TimeTest.h b/testing/testsuites/kernel/time/include/TimeTest.h
new file mode 100644
index 000000000..31d24d6f4
--- /dev/null
+++ b/testing/testsuites/kernel/time/include/TimeTest.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * apps/testing/testsuites/kernel/time/include/TimeTest.h
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TIME_CLOCK_LT_CLOCK_TEST_H_
+#define TIME_CLOCK_LT_CLOCK_TEST_H_
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/times.h>
+#include <sys/time.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CLOCK_RES_SEC 0
+#define CLOCK_RES_NSEC 1000
+#define CLOCK_COARSE_RES_SEC 0
+#define CLOCK_COARSE_RES_NSEC 1000000
+#define CLOCK_GET_CPU_CLOCKID(pid) ((-(pid) - 1) * 8U + 2)
+
+/* cases/clock_test_smoke.c *************************************************/
+
+void test_nuttx_clock_test_smoke01(FAR void **state);
+
+/* cases/clock_test_timer01.c ***********************************************/
+
+void test_nuttx_clock_test_timer01(FAR void **state);
+
+/* cases/clock_test_timer03.c ***********************************************/
+
+void test_nuttx_clock_test_timer03(FAR void **state);
+
+/* cases/clock_test_timer04.c ***********************************************/
+
+void test_nuttx_clock_test_timer04(FAR void **state);
+
+/* cases/clock_test_timer05.c ***********************************************/
+
+void test_nuttx_clock_test_timer05(FAR void **state);
+
+/* cases/clock_test_clock01.c ***********************************************/
+
+void test_nuttx_clock_test_clock01(FAR void **state);
+
+/* cases/clock_test_clock02.c ***********************************************/
+
+void test_nuttx_clock_test_clock02(FAR void **state);
+
+#endif /* TIME_CLOCK_LT_CLOCK_TEST_H_ */