This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new e203ef587 testing/ostest: wait for the victim task to start before
suspending it
e203ef587 is described below
commit e203ef587a59e171ec3c5b0c26cbd478b96461ee
Author: anjiahao <[email protected]>
AuthorDate: Thu Nov 26 21:11:49 2026 +0800
testing/ostest: wait for the victim task to start before suspending it
The suspend test sleeps a fixed time and assumes the victim task has
started by then. Pass a semaphore to the victim and post it once the
task runs, so the test proceeds deterministically.
Signed-off-by: anjiahao <[email protected]>
---
testing/ostest/suspend.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/testing/ostest/suspend.c b/testing/ostest/suspend.c
index a1d6f6b87..cce38ca1c 100644
--- a/testing/ostest/suspend.c
+++ b/testing/ostest/suspend.c
@@ -34,6 +34,7 @@
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
@@ -51,8 +52,10 @@
static int victim_main(int argc, char *argv[])
{
- printf("victim_main: Victim started\n");
+ FAR sem_t *sem = (FAR sem_t *)(uintptr_t)strtoul(argv[2], NULL, 16);
+ sem_post(sem);
+ printf("victim_main: Victim started\n");
for (; ; )
{
sleep(3);
@@ -67,6 +70,9 @@ void suspend_test(void)
{
struct sched_param param;
pid_t victim;
+ FAR char *argv[3];
+ FAR char arg1[32];
+ sem_t sem;
int ret;
/* Start victim thread */
@@ -80,8 +86,13 @@ void suspend_test(void)
param.sched_priority = PTHREAD_DEFAULT_PRIORITY;
}
+ sem_init(&sem, 0, 0);
+ snprintf(arg1, sizeof(arg1), "%p", &sem);
+ argv[0] = "victim";
+ argv[1] = arg1;
+ argv[2] = NULL;
victim = task_create("victim", param.sched_priority,
- STACKSIZE, victim_main, NULL);
+ STACKSIZE, victim_main, argv);
if (victim == ERROR)
{
printf("suspend_test: ERROR failed to start victim_main\n");
@@ -96,7 +107,7 @@ void suspend_test(void)
printf("suspend_test: Is the victim saying anything?\n");
FFLUSH();
- sleep(10);
+ sem_wait(&sem);
/* Then signal the victim thread. */
@@ -141,6 +152,7 @@ void suspend_test(void)
ASSERT(false);
}
+ sem_destroy(&sem);
printf("suspend_test: done\n");
FFLUSH();
}