From 12e8fab78c51055d36b524286ca84c5df033309c Mon Sep 17 00:00:00 2001 From: guanyi3 Date: Tue, 22 Jul 2025 18:32:23 +0800 Subject: [PATCH 1/6] testing/ostest: reduce test time reduce sleep() time in testcase, total test time reduced from 150s to 60s Signed-off-by: guanyi3 --- testing/ostest/aio.c | 18 +++++++++--------- testing/ostest/fpu.c | 4 ++-- testing/ostest/posixtimer.c | 6 +++--- testing/ostest/prioinherit.c | 8 ++++---- testing/ostest/pthread_cleanup.c | 2 +- testing/ostest/pthread_exit.c | 10 +++++----- testing/ostest/pthread_rwlock.c | 6 +++--- testing/ostest/pthread_rwlock_cancel.c | 2 +- testing/ostest/restart.c | 8 ++++---- testing/ostest/robust.c | 6 +++--- testing/ostest/schedlock.c | 2 +- testing/ostest/semtimed.c | 4 ++-- testing/ostest/sighand.c | 9 ++------- testing/ostest/signest.c | 2 +- testing/ostest/sporadic.c | 8 ++++---- testing/ostest/sporadic2.c | 2 +- testing/ostest/suspend.c | 8 ++++---- testing/ostest/timedmqueue.c | 4 ++-- testing/ostest/timedmutex.c | 2 +- testing/ostest/timedwait.c | 4 ++-- testing/ostest/vfork.c | 2 +- testing/ostest/waitpid.c | 10 +++++----- testing/ostest/wdog.c | 2 +- testing/ostest/wqueue.c | 2 +- 24 files changed, 63 insertions(+), 68 deletions(-) diff --git a/testing/ostest/aio.c b/testing/ostest/aio.c index 8a6fe96372d..fb15de4b19e 100644 --- a/testing/ostest/aio.c +++ b/testing/ostest/aio.c @@ -319,7 +319,7 @@ void aio_test(void) do { - usleep(500 * 1000); + usleep(50 * 1000); ret = check_done(); } while (ret < 0); @@ -333,7 +333,7 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500 * 1000); + usleep(50 * 1000); printf("AIO test case 2: Use LIO_WAIT for transfer complete\n"); g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); @@ -371,7 +371,7 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500 * 1000); + usleep(50 * 1000); printf("AIO test case 3: Use aio_suspend for transfer complete\n"); g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); @@ -439,7 +439,7 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500 * 1000); + usleep(50 * 1000); printf("AIO test case 4: Use individual signals for transfer complete\n"); g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); @@ -502,7 +502,7 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500 * 1000); + usleep(50 * 1000); printf("AIO test case 5:" " Use list complete signal for transfer complete\n"); @@ -566,7 +566,7 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500 * 1000); + usleep(50 * 1000); printf("AIO test case 6: Cancel I/O by AIO control block\n"); g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); @@ -599,7 +599,7 @@ void aio_test(void) do { - usleep(500 * 1000); + usleep(50 * 1000); ret = check_done(); } while (ret < 0); @@ -613,7 +613,7 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500 * 1000); + usleep(50 * 1000); printf("AIO test case 7:Cancel I/O by file descriptor\n"); g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); @@ -646,7 +646,7 @@ void aio_test(void) do { - usleep(500 * 1000); + usleep(50 * 1000); ret = check_done(); } while (ret < 0); diff --git a/testing/ostest/fpu.c b/testing/ostest/fpu.c index 841d458c7d9..66f0ffceeed 100644 --- a/testing/ostest/fpu.c +++ b/testing/ostest/fpu.c @@ -62,11 +62,11 @@ #ifdef HAVE_FPU #ifndef CONFIG_TESTING_OSTEST_FPULOOPS -# define CONFIG_TESTING_OSTEST_FPULOOPS 16 +# define CONFIG_TESTING_OSTEST_FPULOOPS 8 #endif #ifndef CONFIG_TESTING_OSTEST_FPUMSDELAY -# define CONFIG_TESTING_OSTEST_FPUMSDELAY 750 +# define CONFIG_TESTING_OSTEST_FPUMSDELAY 10 #endif #ifndef CONFIG_TESTING_OSTEST_FPUPRIORITY diff --git a/testing/ostest/posixtimer.c b/testing/ostest/posixtimer.c index ea47261b2ae..ba9ab926140 100644 --- a/testing/ostest/posixtimer.c +++ b/testing/ostest/posixtimer.c @@ -204,9 +204,9 @@ void timer_test(void) printf("timer_test: Starting timer\n"); - timer.it_value.tv_sec = 2; + timer.it_value.tv_sec = 1; timer.it_value.tv_nsec = 0; - timer.it_interval.tv_sec = 2; + timer.it_interval.tv_sec = 1; timer.it_interval.tv_nsec = 0; status = timer_settime(timerid, 0, &timer, NULL); @@ -219,7 +219,7 @@ void timer_test(void) /* Take the semaphore */ - for (i = 0; i < 5; i++) + for (i = 0; i < 3; i++) { printf("timer_test: Waiting on semaphore\n"); FFLUSH(); diff --git a/testing/ostest/prioinherit.c b/testing/ostest/prioinherit.c index a9ffe3d4fe9..f1052bb89d7 100644 --- a/testing/ostest/prioinherit.c +++ b/testing/ostest/prioinherit.c @@ -215,7 +215,7 @@ static FAR void *highpri_thread(FAR void *parameter) printf("highpri_thread-%d: Started\n", threadno); FFLUSH(); - sleep(1); + usleep(10 * 1000); printf("highpri_thread-%d: Calling sem_wait()\n", threadno); g_highstate[threadno - 1] = WAITING; @@ -363,7 +363,7 @@ static FAR void *lowpri_thread(FAR void *parameter) printf(" I still have a count on the semaphore\n"); sem_enumholders(&g_sem); FFLUSH(); - sleep(1); + usleep(10 * 1000); } /* Account for all of the semaphore counts. At any given time if there @@ -574,7 +574,7 @@ void priority_inheritance(void) } printf("priority_inheritance: Waiting...\n"); - sleep(2); + usleep(20 * 1000); dump_nfreeholders("priority_inheritance:"); /* Start the medium priority thread */ @@ -615,7 +615,7 @@ void priority_inheritance(void) } printf("priority_inheritance: Waiting...\n"); - sleep(1); + usleep(10 * 1000); dump_nfreeholders("priority_inheritance:"); /* Start the high priority threads */ diff --git a/testing/ostest/pthread_cleanup.c b/testing/ostest/pthread_cleanup.c index 00a6b91d429..171cbdb3066 100644 --- a/testing/ostest/pthread_cleanup.c +++ b/testing/ostest/pthread_cleanup.c @@ -122,7 +122,7 @@ static void test_cleanup(void) return; } - usleep(500 * 1000); + usleep(50 * 1000); status = pthread_cancel(thread1); if (status != 0) diff --git a/testing/ostest/pthread_exit.c b/testing/ostest/pthread_exit.c index bc4ca5eac5e..040f9d572be 100644 --- a/testing/ostest/pthread_exit.c +++ b/testing/ostest/pthread_exit.c @@ -51,10 +51,10 @@ static FAR void *pthread_exit_thread(FAR void *parameter) { unsigned me = (unsigned)pthread_self(); - printf("pthread_exit_thread %u: Sleeping for 10 second\n", me); - sleep(5); + printf("pthread_exit_thread %u: Sleeping for 100 ms\n", me); + usleep(50 * 1000); printf("pthread_exit_thread %u: Still running...\n", me); - sleep(5); + usleep(50 * 1000); printf("pthread_exit_thread %u: Exiting\n", me); return NULL; } @@ -80,9 +80,9 @@ static FAR void *pthread_exit_main(FAR void *arg) printf("Thread creation failed, return code %d", ret); } - printf("pthread_exit_main %u: Sleeping for 5 seconds\n", me); + printf("pthread_exit_main %u: Sleeping for 50 ms\n", me); fflush(stdout); - sleep(5); + usleep(50 * 1000); printf("pthread_exit_main %u: Calling pthread_exit()\n", me); pthread_exit(NULL); diff --git a/testing/ostest/pthread_rwlock.c b/testing/ostest/pthread_rwlock.c index ed4159d80af..4688f6d26fc 100644 --- a/testing/ostest/pthread_rwlock.c +++ b/testing/ostest/pthread_rwlock.c @@ -336,7 +336,7 @@ static FAR void *timeout_thread2(FAR void *data) pthread_yield(); status = clock_gettime(CLOCK_REALTIME, &time); - time.tv_sec += 2; + time.tv_sec += 1; status = pthread_rwlock_timedwrlock(rc->rw_lock, &time); if (status != ETIMEDOUT) @@ -347,7 +347,7 @@ static FAR void *timeout_thread2(FAR void *data) } status = clock_gettime(CLOCK_REALTIME, &time); - time.tv_sec += 2; + time.tv_sec += 1; status = pthread_rwlock_timedrdlock(rc->rw_lock, &time); if (status != ETIMEDOUT) @@ -357,7 +357,7 @@ static FAR void *timeout_thread2(FAR void *data) } status = clock_gettime(CLOCK_REALTIME, &time); - time.tv_sec += 2; + time.tv_sec += 1; sem_post(rc->sem1); status = pthread_rwlock_timedrdlock(rc->rw_lock, &time); diff --git a/testing/ostest/pthread_rwlock_cancel.c b/testing/ostest/pthread_rwlock_cancel.c index ab8e84c0c02..cf388d644ef 100644 --- a/testing/ostest/pthread_rwlock_cancel.c +++ b/testing/ostest/pthread_rwlock_cancel.c @@ -180,7 +180,7 @@ static void test_timeout(void) for (i = 0; i < 10; i++) { - usleep(300 * 1000); /* Give threads few seconds to run */ + usleep(30 * 1000); /* Give threads few seconds to run */ } status = pthread_cancel(thread1); diff --git a/testing/ostest/restart.c b/testing/ostest/restart.c index 891a5b5d663..2e8bb4bf904 100644 --- a/testing/ostest/restart.c +++ b/testing/ostest/restart.c @@ -134,7 +134,7 @@ static int restart_main(int argc, char *argv[]) case 0: for (; ; ) { - sleep(2); + usleep(20 * 1000); printf("restart_main: I am still here\n"); } break; @@ -194,7 +194,7 @@ void restart_test(void) /* Wait a bit and restart the task */ - sleep(5); + usleep(50 * 1000); g_restartstep = 1; @@ -211,7 +211,7 @@ void restart_test(void) /* Wait a bit and restart the task */ - sleep(5); + usleep(50 * 1000); g_restartstep = 2; @@ -222,7 +222,7 @@ void restart_test(void) ASSERT(false); } - sleep(1); + usleep(10 * 1000); } sem_destroy(&g_sem); diff --git a/testing/ostest/robust.c b/testing/ostest/robust.c index 9a2baa20fe4..c130ab9654a 100644 --- a/testing/ostest/robust.c +++ b/testing/ostest/robust.c @@ -71,7 +71,7 @@ static FAR void *robust_waiter(FAR void *parameter) printf("robust_waiter: Exiting with mutex\n"); } - sleep(2); + usleep(20 * 1000); return NULL; } @@ -161,7 +161,7 @@ void robust_test(void) /* Wait one second.. the robust waiter should still be waiting */ - sleep(1); + usleep(10 * 1000); /* Now try to take the mutex held by the robust waiter. This should wait * one second there fail with EOWNERDEAD. @@ -208,7 +208,7 @@ void robust_test(void) do { - sleep(1); + usleep(10 * 1000); } while (kill(waiter, 0) == 0 || errno != ESRCH); diff --git a/testing/ostest/schedlock.c b/testing/ostest/schedlock.c index 69d2ef0a387..282cb636d77 100644 --- a/testing/ostest/schedlock.c +++ b/testing/ostest/schedlock.c @@ -252,7 +252,7 @@ void sched_lock_test(void) } printf("sched_lock: Waiting...\n"); - sleep(1); + usleep(10 * 1000); pthread_join(g_highpri, NULL); pthread_join(g_lowpri, NULL); diff --git a/testing/ostest/semtimed.c b/testing/ostest/semtimed.c index ce3f163c111..a93b8252fe4 100644 --- a/testing/ostest/semtimed.c +++ b/testing/ostest/semtimed.c @@ -55,8 +55,8 @@ static void *poster_func(void *parameter) /* Wait for one second, then post the semaphore */ - printf("poster_func: Waiting for 1 second\n"); - sleep(1); + printf("poster_func: Waiting for 10 ms\n"); + usleep(10 * 1000); printf("poster_func: Posting\n"); status = sem_post(&sem); diff --git a/testing/ostest/sighand.c b/testing/ostest/sighand.c index c368a37f1e3..4e62160cb9a 100644 --- a/testing/ostest/sighand.c +++ b/testing/ostest/sighand.c @@ -296,7 +296,7 @@ void sighand_test(void) /* Wait a bit */ FFLUSH(); - sleep(2); + usleep(20 * 1000); /* Then signal the waiter thread. */ @@ -314,12 +314,7 @@ void sighand_test(void) /* Wait a bit */ - FFLUSH(); - status = sleep(2); - while (status) - { - status = sleep(status); - } + usleep(2000); /* Then check the result */ diff --git a/testing/ostest/signest.c b/testing/ostest/signest.c index 5e8e6596140..009213eb371 100644 --- a/testing/ostest/signest.c +++ b/testing/ostest/signest.c @@ -522,7 +522,7 @@ void signest_test(void) sem_post(&g_interferer_sem); do { - usleep(500 * 1000L); + usleep(50 * 1000L); } while (g_waiter_running || g_interferer_running); diff --git a/testing/ostest/sporadic.c b/testing/ostest/sporadic.c index 5e6986ba774..290ac6b44d5 100644 --- a/testing/ostest/sporadic.c +++ b/testing/ostest/sporadic.c @@ -88,7 +88,7 @@ static void *nuisance_func(void *parameter) { /* Sleep gracefully for awhile */ - usleep(500 * 1000); + usleep(50 * 1000); /* Then hog some CPU time */ @@ -344,19 +344,19 @@ void sporadic_test(void) /* Wait a while then kill the FIFO thread */ - sleep(15); + usleep(150 * 1000); ret = pthread_cancel(fifo_thread); pthread_join(fifo_thread, &result); /* Wait a bit longer then kill the nuisance thread */ - sleep(10); + usleep(100 * 1000); ret = pthread_cancel(nuisance_thread); pthread_join(nuisance_thread, &result); /* Wait a bit longer then kill the sporadic thread */ - sleep(10); + usleep(100 * 1000); ret = pthread_cancel(sporadic_thread); pthread_join(sporadic_thread, &result); sched_unlock(); diff --git a/testing/ostest/sporadic2.c b/testing/ostest/sporadic2.c index acc7f34e164..e3a24d7f754 100644 --- a/testing/ostest/sporadic2.c +++ b/testing/ostest/sporadic2.c @@ -290,7 +290,7 @@ static void sporadic_test_case(int32_t budget_1_ns, int32_t budget_2_ns) sem_post(&g_sporadic_sem); sem_post(&g_sporadic_sem); - sleep(100); + sleep(1); ret = pthread_cancel(sporadic_thread1); pthread_join(sporadic_thread1, &result); diff --git a/testing/ostest/suspend.c b/testing/ostest/suspend.c index a1d6f6b877c..a8777433d16 100644 --- a/testing/ostest/suspend.c +++ b/testing/ostest/suspend.c @@ -96,7 +96,7 @@ void suspend_test(void) printf("suspend_test: Is the victim saying anything?\n"); FFLUSH(); - sleep(10); + usleep(10 * 1000); /* Then signal the victim thread. */ @@ -110,7 +110,7 @@ void suspend_test(void) printf("suspend_test: Is the victim still jabbering?\n"); FFLUSH(); - sleep(10); + usleep(10 * 1000); printf("suspend_test: Signaling pid=%d with SIGCONT\n", victim); ret = kill(victim, SIGCONT); @@ -122,7 +122,7 @@ void suspend_test(void) printf("suspend_test: The victim should continue the rant.\n"); FFLUSH(); - sleep(10); + usleep(10 * 1000); printf("suspend_test: Signaling pid=%d with SIGKILL\n", victim); ret = kill(victim, SIGKILL); @@ -133,7 +133,7 @@ void suspend_test(void) } FFLUSH(); - sleep(1); + usleep(10 * 1000); ret = kill(victim, 0); if (ret >= 0) { diff --git a/testing/ostest/timedmqueue.c b/testing/ostest/timedmqueue.c index 5a4dcb29a13..f7af0ac1ef2 100644 --- a/testing/ostest/timedmqueue.c +++ b/testing/ostest/timedmqueue.c @@ -135,7 +135,7 @@ static void *sender_thread(void *arg) ASSERT(false); } - ts.tv_sec += 5; + ts.tv_sec += 1; /* The first TEST_SEND_NMSGS-1 send should succeed. The last * one should fail with errno == ETIMEDOUT @@ -236,7 +236,7 @@ static void *receiver_thread(void *arg) ASSERT(false); } - ts.tv_sec += 5; + ts.tv_sec += 1; /* The first TEST_SEND_NMSGS-1 send should succeed. The last * one should fail with errno == ETIMEDOUT diff --git a/testing/ostest/timedmutex.c b/testing/ostest/timedmutex.c index 303dc260c01..bfba0270194 100644 --- a/testing/ostest/timedmutex.c +++ b/testing/ostest/timedmutex.c @@ -107,7 +107,7 @@ static void *thread_func(FAR void *parameter) /* Release the lock and wait a bit in case the main thread wants it. */ pthread_mutex_unlock(&g_mutex); - usleep(500 * 1000); + usleep(50 * 1000); } g_running = false; diff --git a/testing/ostest/timedwait.c b/testing/ostest/timedwait.c index ab3f6794cc3..4d7a22873f2 100644 --- a/testing/ostest/timedwait.c +++ b/testing/ostest/timedwait.c @@ -65,7 +65,7 @@ static void *thread_waiter(void *parameter) ASSERT(false); } - printf("thread_waiter: Starting 5 second wait for condition\n"); + printf("thread_waiter: Starting 1 second wait for condition\n"); status = clock_gettime(CLOCK_REALTIME, &ts); if (status != 0) @@ -74,7 +74,7 @@ static void *thread_waiter(void *parameter) ASSERT(false); } - ts.tv_sec += 5; + ts.tv_sec += 1; /* The wait -- no-one is ever going to awaken us */ diff --git a/testing/ostest/vfork.c b/testing/ostest/vfork.c index bd6cfabadb9..fb57d91062e 100644 --- a/testing/ostest/vfork.c +++ b/testing/ostest/vfork.c @@ -70,7 +70,7 @@ int vfork_test(void) } else { - sleep(1); + usleep(10 * 1000); if (g_vforkchild) { printf("vfork_test: Child %d ran successfully\n", pid); diff --git a/testing/ostest/waitpid.c b/testing/ostest/waitpid.c index 2be66e8c944..2230b22d15c 100644 --- a/testing/ostest/waitpid.c +++ b/testing/ostest/waitpid.c @@ -66,7 +66,7 @@ static int waitpid_main(int argc, char *argv[]) pid_t me = getpid(); printf("waitpid_main: PID %d Started\n", me); - sleep(3); + usleep(30 * 1000); printf("waitpid_main: PID %d exitting with result=%d\n", me, RETURN_STATUS); return RETURN_STATUS; @@ -237,7 +237,7 @@ int waitpid_test(void) /* Wait a bit to make sure that the other threads complete */ waitpid_last(); - sleep(1); + usleep(10 * 1000); #ifdef CONFIG_SCHED_HAVE_PARENT /* Start the children and wait for first one to complete */ @@ -294,7 +294,7 @@ int waitpid_test(void) /* Wait a bit to make sure that the other threads complete */ waitpid_last(); - sleep(1); + usleep(10 * 1000); /* Start the children and wait for any one to complete */ @@ -343,7 +343,7 @@ int waitpid_test(void) /* Wait a bit to make sure that the other threads complete */ waitpid_last(); - sleep(1); + usleep(10 * 1000); /* Start the children and wait for first one to complete */ @@ -392,7 +392,7 @@ int waitpid_test(void) /* Wait a bit to make sure that the other threads complete */ waitpid_last(); - sleep(1); + usleep(10 * 1000); #endif return 0; diff --git a/testing/ostest/wdog.c b/testing/ostest/wdog.c index ca692f27453..f4602a15e35 100644 --- a/testing/ostest/wdog.c +++ b/testing/ostest/wdog.c @@ -305,7 +305,7 @@ static void wdog_test_run(FAR wdtest_param_t *param) /* Sleep for 1s */ - wdtest_delay(USEC_PER_SEC); + wdtest_delay(USEC_PER_SEC / 100); /* Testing wd_gettime */ diff --git a/testing/ostest/wqueue.c b/testing/ostest/wqueue.c index 9d0444a968b..e5c07e100bd 100644 --- a/testing/ostest/wqueue.c +++ b/testing/ostest/wqueue.c @@ -41,7 +41,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define SLEEP_TIME (100 * 1000) +#define SLEEP_TIME (10 * 1000) #define TEST_COUNT (100) #define VERIFY_COUNT (100) From f264f33d9bc984fb62d36df65ceb80c776820ab5 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Wed, 30 Jul 2025 16:58:04 +0800 Subject: [PATCH 2/6] testing/ostest/suspend: use waitpid inside of usleep usleep too fast, victim maybe not exit. Signed-off-by: An Jiahao --- testing/ostest/suspend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/ostest/suspend.c b/testing/ostest/suspend.c index a8777433d16..1df96bd6f9d 100644 --- a/testing/ostest/suspend.c +++ b/testing/ostest/suspend.c @@ -133,7 +133,8 @@ void suspend_test(void) } FFLUSH(); - usleep(10 * 1000); + + sleep(1); /* Wait for the task to exit */ ret = kill(victim, 0); if (ret >= 0) { From 4995dd9d3acaa69e60738bad291d34148a4a7b5b Mon Sep 17 00:00:00 2001 From: wangzhi16 Date: Thu, 31 Jul 2025 14:07:16 +0800 Subject: [PATCH 3/6] testing/ostest: fix robust_test In a single-core environment, there is no problem because sleep will give up control of the CPU, ensuring that the child thread obtains the mutex first, and there is no timing problem. However, in an SMP environment, since there are two cores, the newly created thread can run on the other core. If the parent thread sleeps for a short time, it will obtain the mutex before the child thread obtains the mutex, causing the case to fail. Here, you need to increase the sleep time of the parent thread to ensure that the child thread obtains the mutex first. Failed case like this: thread_wait_mutex(CPU0) thread_hold_mutex(CPU1) sleep printf -- takes a long time pthread_mutex_lock -- succeed assert -- failed pthread_mutex_lock -- failed Signed-off-by: wangzhi16 --- testing/ostest/robust.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/ostest/robust.c b/testing/ostest/robust.c index c130ab9654a..24205c1201f 100644 --- a/testing/ostest/robust.c +++ b/testing/ostest/robust.c @@ -161,7 +161,7 @@ void robust_test(void) /* Wait one second.. the robust waiter should still be waiting */ - usleep(10 * 1000); + sleep(1); /* Now try to take the mutex held by the robust waiter. This should wait * one second there fail with EOWNERDEAD. From 32c4eea6818188d4234eeecf7e6ec934936c1ff0 Mon Sep 17 00:00:00 2001 From: wushenhui Date: Fri, 8 Aug 2025 12:07:47 +0800 Subject: [PATCH 4/6] ostest/pthread_rwlock: Increase the wait time of pthread_rwlock_timedrdlock The timeout for pthread_rwlock_timedrdlock in the success case was too short (1 second). This could cause test failures on slower systems or under high load, as there may not be enough time for the semaphore post, thread scheduling, lock release, and lock acquisition sequence to complete. Increase the timeout to 10 seconds to provide sufficient margin for test stability while still maintaining reasonable test execution time. Signed-off-by: wushenhui --- testing/ostest/pthread_rwlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/ostest/pthread_rwlock.c b/testing/ostest/pthread_rwlock.c index 4688f6d26fc..d69621f6d4f 100644 --- a/testing/ostest/pthread_rwlock.c +++ b/testing/ostest/pthread_rwlock.c @@ -357,7 +357,7 @@ static FAR void *timeout_thread2(FAR void *data) } status = clock_gettime(CLOCK_REALTIME, &time); - time.tv_sec += 1; + time.tv_sec += 10; sem_post(rc->sem1); status = pthread_rwlock_timedrdlock(rc->rw_lock, &time); From 8809175535445cc057c2e4204f863ee1454c2437 Mon Sep 17 00:00:00 2001 From: tengshuangshuang Date: Mon, 11 Aug 2025 19:44:22 +0800 Subject: [PATCH 5/6] ostest: use sem_get_value for sighandle_test sync Replace usleep(20ms) with polling sem_getvalue() to verify the waiter thread is in sem_wait() state before sending the signal. This ensures deterministic synchronization regardless of system speed. Signed-off-by: ligd --- testing/ostest/sighand.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/testing/ostest/sighand.c b/testing/ostest/sighand.c index 4e62160cb9a..394bf9b2eaf 100644 --- a/testing/ostest/sighand.c +++ b/testing/ostest/sighand.c @@ -293,10 +293,18 @@ void sighand_test(void) printf("sighand_test: Started waiter_main pid=%d\n", waiterpid); } - /* Wait a bit */ + /* Wait the child thread enter sem_wait() */ - FFLUSH(); - usleep(20 * 1000); + while (1) + { + usleep(1000); + + sem_getvalue(&sem1, &status); + if (status < 0) + { + break; + } + } /* Then signal the waiter thread. */ From f322a004e6ddc97abc861142878ff9059aa0252d Mon Sep 17 00:00:00 2001 From: ligd Date: Thu, 14 Aug 2025 22:18:22 +0800 Subject: [PATCH 6/6] ostest: update restart case to avoid assert in semaphore/sem_wait.c Here is the assert backtrace: sched_dumpstack: [242] [<0x63617e>] __assert+0x1d/0x3c34a7 sched_dumpstack: [242] [<0x6c17ee>] nxsem_wait_slow+0x3e9/0xfff77d3c sched_dumpstack: [242] [<0x62e724>] uart_write+0xb7/0x22e8 sched_dumpstack: [242] [<0x688944>] file_writev+0xf3/0x29818c sched_dumpstack: [242] [<0x6889e2>] write+0x4d/0x69d04 sched_dumpstack: [242] [<0x63ff72>] lib_fflush_unlocked+0x99/0x95d30 sched_dumpstack: [242] [<0x6df1c0>] fputc+0x43/0x109784c sched_dumpstack: [242] [<0x6d7174>] stdoutstream_putc+0x3f/0xffffff68 sched_dumpstack: [242] [<0x63c45a>] vsprintf_internal.constprop.0+0x55/0xffffdbfc sched_dumpstack: [242] [<0x63d32a>] lib_vsprintf+0x1d/0x3c sched_dumpstack: [242] [<0x6d603a>] vfprintf+0x29/0x10a0b70 sched_dumpstack: [242] [<0x1776228>] printf+0x23/0xfefa0774 sched_dumpstack: [242] [<0x6d603a>] vfprintf+0x29/0x10a0b70 sched_dumpstack: [242] [<0x1776228>] printf+0x23/0xfefa0774 sched_dumpstack: [242] [<0x72cebc>] restart_main+0x1f/0x1fc sched_dumpstack: [242] [<0x638c66>] nxtask_startup+0x1d/0xdb4b6c Root cause: task: child task: start child nxmutex_lock sleep(1) restart_task() nxmutex_lock (assert happen) The nxsem_recover() only recover when the sem in WAIT_LIST, if we want recover it, or we must open CONFIG_PRIORITY_INHERITANCE, it is a heavy method for a embedded-RTOS. So I change the restart case, and let the restart happen in control Signed-off-by: ligd --- testing/ostest/restart.c | 49 +++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/testing/ostest/restart.c b/testing/ostest/restart.c index 2e8bb4bf904..0bee23e9ff2 100644 --- a/testing/ostest/restart.c +++ b/testing/ostest/restart.c @@ -127,26 +127,16 @@ static int restart_main(int argc, char *argv[]) } #endif - /* Were we restarted? */ + /* Let the main task restart */ - switch (g_restartstep) + g_restartstep++; + sem_post(&g_sem); + + /* Don't call printf here, to avoid recover sem failed during restart */ + + for (; ; ) { - case 0: - for (; ; ) - { - usleep(20 * 1000); - printf("restart_main: I am still here\n"); - } - break; - case 1: - if (sem_wait(&g_sem) != 0) - { - printf("restart_main: ERROR thread sem_wait failed\n"); - ASSERT(false); - } - break; - default: - break; + sleep(1); } return 0; /* Won't get here unless we were restarted */ @@ -192,11 +182,12 @@ void restart_test(void) printf("restart_main: Started restart_main at PID=%d\n", pid); - /* Wait a bit and restart the task */ + /* Check the child task result */ - usleep(50 * 1000); + sem_wait(&g_sem); + ASSERT(g_restartstep == 1); - g_restartstep = 1; + /* Restart the task */ ret = task_restart(pid); if (ret < 0) @@ -205,15 +196,14 @@ void restart_test(void) ASSERT(false); } - /* Start the task wait for a semaphore */ - - printf("restart_main: Started restart_main at PID=%d\n", pid); + /* Check the child task result */ - /* Wait a bit and restart the task */ + sem_wait(&g_sem); + ASSERT(g_restartstep == 2); - usleep(50 * 1000); + printf("restart_main: Started restart_main at PID=%d\n", pid); - g_restartstep = 2; + /* Restart the task */ ret = task_restart(pid); if (ret < 0) @@ -222,7 +212,10 @@ void restart_test(void) ASSERT(false); } - usleep(10 * 1000); + /* Check the child task result */ + + sem_wait(&g_sem); + ASSERT(g_restartstep == 3); } sem_destroy(&g_sem);