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 2022/10/11 07:29:50 UTC
[incubator-nuttx-apps] branch master updated: ostest: add semaphore wait case for task restart
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/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 7fcba8a11 ostest: add semaphore wait case for task restart
7fcba8a11 is described below
commit 7fcba8a1197c5f78cb995b728899a75a4fa3715e
Author: zhangyuan21 <zh...@xiaomi.com>
AuthorDate: Sun Oct 9 16:30:55 2022 +0800
ostest: add semaphore wait case for task restart
---
testing/ostest/restart.c | 57 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 43 insertions(+), 14 deletions(-)
diff --git a/testing/ostest/restart.c b/testing/ostest/restart.c
index 6bcb024fe..4323ae84a 100644
--- a/testing/ostest/restart.c
+++ b/testing/ostest/restart.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <sched.h>
#include <errno.h>
+#include <semaphore.h>
#include "ostest.h"
@@ -58,7 +59,9 @@ static const char g_varname[] = "VarName";
static const char g_varvalue[] = "VarValue";
#endif
-static bool g_restarted;
+static uint8_t g_restartstep;
+
+static sem_t g_sem;
/****************************************************************************
* Private Functions
@@ -117,19 +120,23 @@ static int restart_main(int argc, char *argv[])
/* Were we restarted? */
- if (!g_restarted)
+ switch (g_restartstep)
{
- /* No.. this is the first time we have been here */
-
- g_restarted = true;
-
- /* Now just wait to be restarted */
-
- for (; ; )
- {
- sleep(2);
- printf("restart_main: I am still here\n");
- }
+ case 0:
+ for (; ; )
+ {
+ sleep(2);
+ 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");
+ }
+ break;
+ default:
+ break;
}
return 0; /* Won't get here unless we were restarted */
@@ -146,7 +153,6 @@ void restart_test(void)
/* Start the children and wait for first one to complete */
printf("\nTest task_restart()\n");
- g_restarted = false;
/* Set up an environment variables */
@@ -155,6 +161,8 @@ void restart_test(void)
setenv(g_varname, g_varvalue, TRUE); /* Variable1=GoodValue1 */
#endif
+ sem_init(&g_sem, 0, 0);
+
/* Start the task */
ret = task_create("ostest", PRIORITY, STACKSIZE, restart_main, g_argv);
@@ -171,6 +179,25 @@ void restart_test(void)
/* Wait a bit and restart the task */
sleep(5);
+
+ g_restartstep = 1;
+
+ ret = task_restart(pid);
+ if (ret < 0)
+ {
+ printf("restart_main: ERROR: task_restart failed\n");
+ }
+
+ /* Start the task wait for a semaphore */
+
+ printf("restart_main: Started restart_main at PID=%d\n", pid);
+
+ /* Wait a bit and restart the task */
+
+ sleep(5);
+
+ g_restartstep = 2;
+
ret = task_restart(pid);
if (ret < 0)
{
@@ -180,5 +207,7 @@ void restart_test(void)
sleep(1);
}
+ sem_destroy(&g_sem);
+
printf("restart_main: Exiting\n");
}