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 #include #include +#include #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"); }