Minor changes to make OS test more robust in the presence of many memory allocation failures

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5672 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-02-26 00:56:59 +00:00
parent 142c478747
commit 5ff8bb8c4f
5 changed files with 69 additions and 26 deletions

View File

@ -19,7 +19,7 @@ menu "Network Utilities"
source "$APPSDIR/netutils/Kconfig"
endmenu
menu "ModBus"
menu "FreeModBus"
source "$APPSDIR/modbus/Kconfig"
endmenu

View File

@ -140,9 +140,9 @@ static void *poster_func(void *parameter)
void sem_test(void)
{
pthread_t waiter_thread1;
pthread_t waiter_thread2;
pthread_t poster_thread;
pthread_t waiter_thread1 = (pthread_t)0;
pthread_t waiter_thread2 = (pthread_t)0;
pthread_t poster_thread = (pthread_t)0;
#ifdef SDCC
pthread_addr_t result;
#endif
@ -173,7 +173,7 @@ void sem_test(void)
status = pthread_attr_setschedparam(&attr,&sparam);
if (status != OK)
{
printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status);
printf("sem_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status);
}
else
{
@ -183,21 +183,21 @@ void sem_test(void)
status = pthread_create(&waiter_thread1, &attr, waiter_func, (pthread_addr_t)1);
if (status != 0)
{
printf("sem_test: Error in thread 1 creation, status=%d\n", status);
printf("sem_test: ERROR: Thread 1 creation failed: %d\n", status);
}
printf("sem_test: Starting waiter thread 2\n");
status = pthread_attr_init(&attr);
if (status != 0)
{
printf("sem_test: pthread_attr_init failed, status=%d\n", status);
printf("sem_test: ERROR: pthread_attr_init failed, status=%d\n", status);
}
sparam.sched_priority = prio_mid;
status = pthread_attr_setschedparam(&attr,&sparam);
if (status != OK)
{
printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status);
printf("sem_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status);
}
else
{
@ -207,14 +207,14 @@ void sem_test(void)
status = pthread_create(&waiter_thread2, &attr, waiter_func, (pthread_addr_t)2);
if (status != 0)
{
printf("sem_test: Error in thread 2 creation, status=%d\n", status);
printf("sem_test: ERROR: Thread 2 creation failed: %d\n", status);
}
printf("sem_test: Starting poster thread 3\n");
status = pthread_attr_init(&attr);
if (status != 0)
{
printf("sem_test: pthread_attr_init failed, status=%d\n", status);
printf("sem_test: ERROR: pthread_attr_init failed, status=%d\n", status);
}
sparam.sched_priority = (prio_min + prio_mid) / 2;
@ -231,16 +231,42 @@ void sem_test(void)
status = pthread_create(&poster_thread, &attr, poster_func, (pthread_addr_t)3);
if (status != 0)
{
printf("sem_test: Error in thread 3 creation, status=%d\n", status);
printf("sem_test: ERROR: Thread 3 creation failed: %d\n", status);
printf(" Canceling waiter threads\n");
pthread_cancel(waiter_thread1);
pthread_cancel(waiter_thread2);
}
#ifdef SDCC
pthread_join(waiter_thread1, &result);
pthread_join(waiter_thread2, &result);
pthread_join(poster_thread, &result);
if (waiter_thread1 != (pthread_t)0)
{
pthread_join(waiter_thread1, &result);
}
if (waiter_thread2 != (pthread_t)0)
{
pthread_join(waiter_thread2, &result);
}
if (poster_thread != (pthread_t)0)
{
pthread_join(poster_thread, &result);
}
#else
pthread_join(waiter_thread1, NULL);
pthread_join(waiter_thread2, NULL);
pthread_join(poster_thread, NULL);
if (waiter_thread1 != (pthread_t)0)
{
pthread_join(waiter_thread1, NULL);
}
if (waiter_thread2 != (pthread_t)0)
{
pthread_join(waiter_thread2, NULL);
}
if (poster_thread != (pthread_t)0)
{
pthread_join(poster_thread, NULL);
}
#endif
}

View File

@ -87,7 +87,7 @@ static void waitpid_start_children(void)
ret = TASK_CREATE("waitpid", PRIORITY, STACKSIZE, waitpid_main, NULL);
if (ret < 0)
{
printf("waitpid_start_child: ERROR Failed to start user_main\n");
printf("waitpid_start_child: ERROR Failed to start waitpid_main\n");
}
else
{
@ -100,8 +100,29 @@ static void waitpid_start_children(void)
static void waitpid_last(void)
{
pid_t pid = -1;
int stat_loc;
int ret;
int i;
/* Find the last child thread that was started successfully */
for (i = NCHILDREN-1; i > 0; i--)
{
if (g_waitpids[i] >= 0)
{
pid = i;
break;
}
}
/* Is there any thread to wait for? */
if (pid < 0)
{
printf("waitpid_last: ERROR: Nothing to wait for\n");
return;
}
printf("waitpid_last: Waiting for PID=%d with waitpid()\n",
g_waitpids[NCHILDREN-1]);
@ -196,7 +217,7 @@ int waitpid_test(void)
g_waitpids[0], stat_loc);
}
/* Wait a big to make sure that the other threads complete */
/* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);
@ -246,7 +267,7 @@ int waitpid_test(void)
info.si_pid, info.si_status);
}
/* Wait a big to make sure that the other threads complete */
/* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);
@ -289,7 +310,7 @@ int waitpid_test(void)
info.si_pid, info.si_status);
}
/* Wait a big to make sure that the other threads complete */
/* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);
@ -332,7 +353,7 @@ int waitpid_test(void)
ret, stat_loc);
}
/* Wait a big to make sure that the other threads complete */
/* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);

View File

@ -3,8 +3,6 @@
# see misc/tools/kconfig-language.txt.
#
comment "Interpreters"
source "$APPSDIR/interpreters/ficl/Kconfig"
config INTERPRETERS_PCODE

View File

@ -3,8 +3,6 @@
# see misc/tools/kconfig-language.txt.
#
comment "FreeModbus"
config MODBUS
bool "Modbus support via FreeModBus"
default n