diff --git a/testing/mm/mm_main.c b/testing/mm/mm_main.c index a08e2d988..4517b6dc2 100644 --- a/testing/mm/mm_main.c +++ b/testing/mm/mm_main.c @@ -59,18 +59,18 @@ static const int g_alloc_sizes[NTEST_ALLOCS] = { - 1024, 12, 962, 5692, 10254, 111, 9932, 601, + 1024, 12, 962, 5692, 10254, 111, 9932, 601, 222, 2746, 3, 124321, 68, 776, 6750, 852, - 4732, 28, 901, 480, 5011, 1536, 2011, 81647, + 4732, 28, 901, 480, 5011, 1536, 2011, 81647, 646, 1646, 69179, 194, 2590, 7, 969, 70 }; static const int g_realloc_sizes[NTEST_ALLOCS] = { - 18, 3088, 963, 123, 511, 11666, 3723, 42, - 9374, 1990, 1412, 6, 592, 4088, 11, 5040, - 8663, 91255, 28, 4346, 9172, 168, 229, 4734, - 59139, 221, 7830, 30421, 1666, 4, 812, 416 + 18, 3088, 963, 123, 511, 11666, 3723, 42, + 9374, 1990, 1412, 6, 592, 4088, 11, 5040, + 8663, 91255, 28, 4346, 9172, 168, 229, 4734, + 59139, 221, 7830, 30421, 1666, 4, 812, 416 }; static const int g_random1[NTEST_ALLOCS] = @@ -151,7 +151,8 @@ static void do_mallocs(FAR void **mem, FAR const int *size, if (allocsize > g_alloc_info.mxordblk) { - fprintf(stderr, " Normal, largest free block is only %lu\n", + fprintf(stderr, + " Normal, largest free block is only %lu\n", (unsigned long)g_alloc_info.mxordblk); } else @@ -190,7 +191,8 @@ static void do_reallocs(FAR void **mem, FAR const int *oldsize, { int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE); - fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize); + fprintf(stderr, + "(%d)realloc failed for allocsize=%d\n", i, allocsize); if (allocsize > g_alloc_info.mxordblk) { fprintf(stderr, " Normal, largest free block is only %lu\n", @@ -212,7 +214,9 @@ static void do_reallocs(FAR void **mem, FAR const int *oldsize, } } -static void do_memaligns(FAR void **mem, FAR const int *size, FAR const int *align, +static void do_memaligns(FAR void **mem, + FAR const int *size, + FAR const int *align, FAR const int *seq, int n) { int i; @@ -229,9 +233,11 @@ static void do_memaligns(FAR void **mem, FAR const int *size, FAR const int *ali if (mem[j] == NULL) { - int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + 2*align[i]; + int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + + 2 * align[i]; - fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize); + fprintf(stderr, + "(%d)memalign failed for allocsize=%d\n", i, allocsize); if (allocsize > g_alloc_info.mxordblk) { fprintf(stderr, " Normal, largest free block is only %lu\n", @@ -291,7 +297,8 @@ int main(int argc, FAR char *argv[]) /* Re-allocate the memory */ - do_reallocs(g_allocs, g_alloc_sizes, g_realloc_sizes, g_random2, NTEST_ALLOCS); + do_reallocs(g_allocs, g_alloc_sizes, + g_realloc_sizes, g_random2, NTEST_ALLOCS); /* Release the memory */ @@ -299,8 +306,10 @@ int main(int argc, FAR char *argv[]) /* Allocate aligned memory */ - do_memaligns(g_allocs, g_alloc_sizes, g_alignment, g_random2, NTEST_ALLOCS / 2); - do_memaligns(g_allocs, g_alloc_sizes, g_alignment, &g_random2[NTEST_ALLOCS / 2], + do_memaligns(g_allocs, g_alloc_sizes, + g_alignment, g_random2, NTEST_ALLOCS / 2); + do_memaligns(g_allocs, g_alloc_sizes, + g_alignment, &g_random2[NTEST_ALLOCS / 2], NTEST_ALLOCS / 2); /* Release aligned memory */ diff --git a/testing/ostest/aio.c b/testing/ostest/aio.c index efb000ebf..fd08ff3f1 100644 --- a/testing/ostest/aio.c +++ b/testing/ostest/aio.c @@ -53,6 +53,7 @@ /**************************************************************************** * Private Data ****************************************************************************/ + /* Constant write buffers */ static const char g_wrbuffer1[] = "This is write buffer #1\n"; @@ -61,8 +62,7 @@ static char g_rdbuffer[AIO_RDBUFFER_SIZE]; /* AIO control blocks: write, nop, write, NULL, read */ - -static struct aiocb g_aiocbs[AIO_NCTRLBLKS-1]; +static struct aiocb g_aiocbs[AIO_NCTRLBLKS - 1]; static struct aiocb *g_aiocb[AIO_NCTRLBLKS]; static struct aiocb * const g_aiocb_init[AIO_NCTRLBLKS] = @@ -70,7 +70,6 @@ static struct aiocb * const g_aiocb_init[AIO_NCTRLBLKS] = &g_aiocbs[0], &g_aiocbs[1], &g_aiocbs[2], NULL, &g_aiocbs[3] }; - static FAR void * const g_buffers[AIO_NCTRLBLKS] = { (FAR void *)g_wrbuffer1, @@ -110,7 +109,7 @@ static void init_aiocb(bool signal) FAR struct aiocb *aiocbp; int i; - memset(g_aiocbs, 0xff, (AIO_NCTRLBLKS-1)*sizeof(struct aiocb)); + memset(g_aiocbs, 0xff, (AIO_NCTRLBLKS - 1) * sizeof(struct aiocb)); memset(g_rdbuffer, 0xff, AIO_RDBUFFER_SIZE); for (i = 0; i < AIO_NCTRLBLKS; i++) @@ -120,7 +119,8 @@ static void init_aiocb(bool signal) if (aiocbp) { - aiocbp->aio_sigevent.sigev_notify = signal ? SIGEV_SIGNAL : SIGEV_NONE; + aiocbp->aio_sigevent.sigev_notify = + signal ? SIGEV_SIGNAL : SIGEV_NONE; aiocbp->aio_sigevent.sigev_signo = SIGUSR1; #ifdef CONFIG_SIG_EVTHREAD aiocbp->aio_sigevent.sigev_notify_function = NULL; @@ -133,7 +133,7 @@ static void init_aiocb(bool signal) aiocbp->aio_fildes = g_fildes; aiocbp->aio_reqprio = 0; aiocbp->aio_lio_opcode = g_opcode[i]; - } + } } } @@ -294,10 +294,11 @@ void aio_test(void) /* Case 1: Poll for transfer complete */ printf("AIO test case 1: Poll for transfer complete\n"); - g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -311,7 +312,7 @@ void aio_test(void) do { - usleep(500*1000); + usleep(500 * 1000); ret = check_done(); } while (ret < 0); @@ -325,13 +326,14 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500*1000); + usleep(500 * 1000); printf("AIO test case 2: Use LIO_WAIT for transfer complete\n"); - g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -359,13 +361,14 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500*1000); + usleep(500 * 1000); printf("AIO test case 3: Use aio_suspend for transfer complete\n"); - g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -381,7 +384,8 @@ void aio_test(void) for (i = 1; i <= AIO_NCTRLBLKS; i++) { printf(" Calling aio_suspend #%d\n", i); - ret = aio_suspend((FAR const struct aiocb *const *)g_aiocb, AIO_NCTRLBLKS, NULL); + ret = aio_suspend((FAR const struct aiocb *const *)g_aiocb, + AIO_NCTRLBLKS, NULL); if (ret < 0) { printf("aio_test: ERROR: aio_suspend failed: %d\n", errno); @@ -406,7 +410,8 @@ void aio_test(void) if (total != AIO_NCTRLBLKS) { - printf("aio_test: ERROR: Total is %d, should be %d\n", total, AIO_NCTRLBLKS); + printf("aio_test: ERROR: Total is %d, should be %d\n", + total, AIO_NCTRLBLKS); goto errout_with_fildes; } @@ -419,13 +424,14 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500*1000); + usleep(500 * 1000); printf("AIO test case 4: Use individual signals for transfer complete\n"); - g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -456,7 +462,8 @@ void aio_test(void) } else { - printf("aio_test: ERROR: sigwaitinfo failed: %d\n", errcode); + printf("aio_test: ERROR: sigwaitinfo failed: %d\n", + errcode); goto errout_with_fildes; } } @@ -477,13 +484,15 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500*1000); + usleep(500 * 1000); - printf("AIO test case 5: Use list complete signal for transfer complete\n"); - g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC); + printf("AIO test case 5:" + " Use list complete signal for transfer complete\n"); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -518,10 +527,11 @@ void aio_test(void) } else { - printf("aio_test: ERROR: sigwaitinfo failed: %d\n", errcode); + printf("aio_test: ERROR: sigwaitinfo failed: %d\n", + errcode); goto errout_with_fildes; } - } + } } } while (ret < 0); @@ -535,13 +545,14 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500*1000); + usleep(500 * 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); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -564,7 +575,7 @@ void aio_test(void) do { - usleep(500*1000); + usleep(500 * 1000); ret = check_done(); } while (ret < 0); @@ -578,13 +589,14 @@ void aio_test(void) * task end of the last test case -- especially the dangling SIGPOLL. */ - usleep(500*1000); + usleep(500 * 1000); printf("AIO test case 7:Cancel I/O by file descriptor\n"); - g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC); + g_fildes = open(AIO_FILEPATH, O_RDWR | O_CREAT | O_TRUNC); if (g_fildes < 0) { - printf("aio_test: ERROR: Failed to open %s: %d\n", AIO_FILEPATH, errno); + printf("aio_test: ERROR: Failed to open %s: %d\n", + AIO_FILEPATH, errno); goto errout_with_procmask; } @@ -607,7 +619,7 @@ void aio_test(void) do { - usleep(500*1000); + usleep(500 * 1000); ret = check_done(); } while (ret < 0); diff --git a/testing/ostest/cancel.c b/testing/ostest/cancel.c index 932345e5f..353a80693 100644 --- a/testing/ostest/cancel.c +++ b/testing/ostest/cancel.c @@ -69,7 +69,7 @@ static FAR void *sem_waiter(FAR void *parameter) for (i = 0; i < CONFIG_PTHREAD_CLEANUP_STACKSIZE ; i++) { - pthread_cleanup_push(sem_cleaner, (FAR void *)((uintptr_t)(i+1))); + pthread_cleanup_push(sem_cleaner, (FAR void *)((uintptr_t)(i + 1))); } #endif @@ -79,7 +79,8 @@ static FAR void *sem_waiter(FAR void *parameter) status = pthread_mutex_lock(&mutex); if (status != 0) { - printf("sem_waiter: ERROR pthread_mutex_lock failed, status=%d\n", status); + printf("sem_waiter: ERROR pthread_mutex_lock failed, status=%d\n", + status); } printf("sem_waiter: Starting wait for condition\n"); @@ -92,7 +93,9 @@ static FAR void *sem_waiter(FAR void *parameter) status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); if (status != 0) { - printf("sem_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status); + printf("sem_waiter: " + "ERROR pthread_setcancelstate failed, status=%d\n", + status); } } @@ -103,7 +106,8 @@ static FAR void *sem_waiter(FAR void *parameter) status = pthread_cond_wait(&cond, &mutex); if (status != 0) { - printf("sem_waiter: ERROR pthread_cond_wait failed, status=%d\n", status); + printf("sem_waiter: ERROR pthread_cond_wait failed, status=%d\n", + status); } if (!parameter) @@ -114,7 +118,9 @@ static FAR void *sem_waiter(FAR void *parameter) status = pthread_mutex_unlock(&mutex); if (status != 0) { - printf("sem_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", status); + printf("sem_waiter: " + "ERROR pthread_mutex_unlock failed, status=%d\n", + status); } /* Set the cancelable state */ @@ -123,12 +129,14 @@ static FAR void *sem_waiter(FAR void *parameter) status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if (status != 0) { - printf("sem_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status); + printf("sem_waiter: " + "ERROR pthread_setcancelstate failed, status=%d\n", status); } } else { - printf("sem_waiter: ERROR pthread_cond_wait returned after being cancelled!\n"); + printf("sem_waiter: " + "ERROR pthread_cond_wait returned after being cancelled!\n"); } /* Why is this here? Because pthread_setcancelstate() is not a @@ -180,7 +188,7 @@ static FAR void *mqueue_waiter(FAR void *parameter) attr.mq_msgsize = CONFIG_MQ_MAXMSGSIZE; attr.mq_flags = 0; - mqcancel = mq_open("mqcancel", O_RDONLY|O_CREAT, 0666, &attr); + mqcancel = mq_open("mqcancel", O_RDONLY | O_CREAT, 0666, &attr); if (mqcancel < 0) { printf("mqueue_waiter: ERROR mq_open failed\n"); @@ -196,9 +204,9 @@ static FAR void *mqueue_waiter(FAR void *parameter) printf("mqueue_waiter: Awakened with %d\n", (int)nbytes); if (mq_close(mqcancel) < 0) - { - printf("mqueue_waiter: ERROR mq_close failed\n"); - } + { + printf("mqueue_waiter: ERROR mq_close failed\n"); + } printf("mqueue_waiter: Exit with status 0x12345678\n"); pthread_exit((pthread_addr_t)0x12345678); @@ -239,7 +247,8 @@ static FAR void *asynch_waiter(FAR void *parameter) for (i = 0; i < CONFIG_PTHREAD_CLEANUP_STACKSIZE ; i++) { - pthread_cleanup_push(sem_cleaner, (FAR void *)((uintptr_t)(i+1))); + pthread_cleanup_push(sem_cleaner, + (FAR void *)((uintptr_t)(i + 1))); } #endif @@ -249,7 +258,9 @@ static FAR void *asynch_waiter(FAR void *parameter) status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); if (status != 0) { - printf("asynch_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status); + printf("asynch_waiter: " + "ERROR pthread_setcancelstate failed, status=%d\n", + status); } /* Set the asynchronous cancellation type */ @@ -258,14 +269,16 @@ static FAR void *asynch_waiter(FAR void *parameter) status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); if (status != 0) { - printf("asynch_waiter: ERROR pthread_setcanceltype failed, status=%d\n", status); + printf("asynch_waiter: " + "ERROR pthread_setcanceltype failed, status=%d\n", + status); } - /* Then wait a bit. We should be canceled aynchronously while waiting, but the - * cancellation should pend because we are non-cancellable. + /* Then wait a bit. We should be canceled aynchronously while waiting, but + * the cancellation should pend because we are non-cancellable. */ - usleep(250*1000); + usleep(250 * 1000); /* We should be canceled when restore the cancelable state. */ @@ -278,7 +291,8 @@ static FAR void *asynch_waiter(FAR void *parameter) if (status != 0) { - printf("asynch_waiter: ERROR pthread_setcancelstate failed, status=%d\n", + printf("asynch_waiter: " + "ERROR pthread_setcancelstate failed, status=%d\n", status); } @@ -302,7 +316,8 @@ static void start_thread(FAR void *(*entry)(FAR void *), pthread_t *waiter, status = pthread_mutex_init(&mutex, NULL); if (status != 0) { - printf("start_thread: ERROR pthread_mutex_init failed, status=%d\n", status); + printf("start_thread: " + "ERROR pthread_mutex_init failed, status=%d\n", status); } /* Initialize the condition variable */ @@ -311,7 +326,8 @@ static void start_thread(FAR void *(*entry)(FAR void *), pthread_t *waiter, status = pthread_cond_init(&cond, NULL); if (status != 0) { - printf("start_thread: ERROR pthread_cond_init failed, status=%d\n", status); + printf("start_thread: ERROR pthread_cond_init failed, status=%d\n", + status); } /* Set up attributes */ @@ -325,7 +341,8 @@ static void start_thread(FAR void *(*entry)(FAR void *), pthread_t *waiter, status = pthread_attr_setstacksize(&attr, STACKSIZE); if (status != 0) { - printf("start_thread: pthread_attr_setstacksize failed, status=%d\n", status); + printf("start_thread: pthread_attr_setstacksize failed, status=%d\n", + status); } /* Start the waiter thread */ @@ -335,7 +352,8 @@ static void start_thread(FAR void *(*entry)(FAR void *), pthread_t *waiter, (pthread_addr_t)((uintptr_t)cancelable)); if (status != 0) { - printf("start_thread: ERROR pthread_create failed, status=%d\n", status); + printf("start_thread: ERROR pthread_create failed, status=%d\n", + status); } /* Make sure that the waiter thread gets a chance to run */ @@ -355,18 +373,21 @@ static void restart_thread(FAR void *(*entry)(FAR void *), pthread_t *waiter, status = pthread_cond_destroy(&cond); if (status != 0) { - printf("restart_thread: ERROR pthread_cond_destroy failed, status=%d\n", status); + printf("restart_thread: " + "ERROR pthread_cond_destroy failed, status=%d\n", status); } - /* Destroy the mutex. Note that this relies on non-portable NuttX assumption, - * that it is possible to destroy a locked mutex owned by a cancelled thread. + /* Destroy the mutex. + * Note that this relies on non-portable NuttX assumption, that it + * is possible to destroy a locked mutex owned by a cancelled thread. */ printf("restart_thread: Destroying mutex\n"); status = pthread_mutex_destroy(&mutex); if (status != 0) { - printf("restart_thread: ERROR pthread_mutex_destroy failed, status=%d\n", status); + printf("restart_thread: " + "ERROR pthread_mutex_destroy failed, status=%d\n", status); } /* Then restart the thread */ @@ -389,7 +410,8 @@ void cancel_test(void) void *result; int status; - /* Test 1: Normal Cancel *********************************************/ + /* Test 1: Normal Cancel **************************************************/ + /* Start the waiter thread */ printf("cancel_test: Test 1a: Normal Cancellation\n"); @@ -400,13 +422,14 @@ void cancel_test(void) * make sure. */ - usleep(75*1000); + usleep(75 * 1000); printf("cancel_test: Canceling thread\n"); status = pthread_cancel(waiter); if (status != 0) { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", + status); } /* Then join to the thread to pick up the result (if we don't do @@ -417,22 +440,25 @@ void cancel_test(void) status = pthread_join(waiter, &result); if (status != 0) { - printf("cancel_test: ERROR pthread_join failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_join failed, status=%d\n", + status); } else { printf("cancel_test: waiter exited with result=%p\n", result); if (result != PTHREAD_CANCELED) { - printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED); + printf("cancel_test: ERROR expected result=%p\n", + PTHREAD_CANCELED); } else { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); + printf("cancel_test:" + " PASS thread terminated with PTHREAD_CANCELED\n"); } } - /* Test 2: Asynchronous Cancel ***************************************/ + /* Test 2: Asynchronous Cancel ********************************************/ printf("cancel_test: Test 2: Asynchronous Cancellation\n"); @@ -453,13 +479,14 @@ void cancel_test(void) * bit to make sure. */ - usleep(100*1000); + usleep(100 * 1000); printf("cancel_test: Canceling thread\n"); status = pthread_cancel(waiter); if (status != 0) { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", + status); } /* Then join to the thread to pick up the result (if we don't do @@ -470,25 +497,28 @@ void cancel_test(void) status = pthread_join(waiter, &result); if (status != 0) { - printf("cancel_test: ERROR pthread_join failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_join failed, status=%d\n", + status); } else { printf("cancel_test: waiter exited with result=%p\n", result); if (result != PTHREAD_CANCELED) { - printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED); + printf("cancel_test: ERROR expected result=%p\n", + PTHREAD_CANCELED); } else { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); + printf("cancel_test: " + "PASS thread terminated with PTHREAD_CANCELED\n"); } } #else printf("... Skipped\n"); #endif - /* Test 3: Cancel Detached Thread ************************************/ + /* Test 3: Cancel Detached Thread *****************************************/ printf("cancel_test: Test 3: Cancellation of detached thread\n"); printf("cancel_test: Re-starting thread\n"); @@ -506,13 +536,14 @@ void cancel_test(void) * bit to be certain. */ - usleep(100*1000); + usleep(100 * 1000); printf("cancel_test: Canceling thread\n"); status = pthread_cancel(waiter); if (status != 0) { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", + status); } #ifdef CONFIG_CANCELLATION_POINTS @@ -521,7 +552,7 @@ void cancel_test(void) * before the cancellation. */ - usleep(100*1000); + usleep(100 * 1000); #endif /* Join should now fail */ @@ -534,14 +565,17 @@ void cancel_test(void) } else if (status != ESRCH) { - printf("cancel_test: ERROR pthread_join failed but with wrong status=%d\n", status); + printf("cancel_test:" + " ERROR pthread_join failed but with wrong status=%d\n", + status); } else { printf("cancel_test: PASS pthread_join failed with status=ESRCH\n"); } - /* Test 4: Non-cancelable threads ************************************/ + /* Test 4: Non-cancelable threads *****************************************/ + /* This test currently depends on signals. It doesn't have to and * could be re-designed so that it does not depend on signals. */ @@ -554,7 +588,7 @@ void cancel_test(void) * This is the dependency on signals: */ - usleep(200*1000); + usleep(200 * 1000); /* Then cancel it. It should be in the pthread_cond_wait now. The * behavior here is non-standard: when the thread is at a cancellation @@ -563,13 +597,14 @@ void cancel_test(void) * The cancellation should succeed, because the cancellation is pending. */ - usleep(100*1000); + usleep(100 * 1000); printf("cancel_test: Canceling thread\n"); status = pthread_cancel(waiter); if (status != 0) { - printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", + status); } /* Signal the thread. It should wake up and restore the cancelable state. @@ -579,19 +614,22 @@ void cancel_test(void) status = pthread_mutex_lock(&mutex); if (status != 0) { - printf("cancel_test: ERROR pthread_mutex_lock failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_mutex_lock failed, status=%d\n", + status); } status = pthread_cond_signal(&cond); if (status != 0) { - printf("cancel_test: ERROR pthread_cond_signal failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_cond_signal failed, status=%d\n", + status); } status = pthread_mutex_unlock(&mutex); if (status != 0) { - printf("cancel_test: ERROR pthread_mutex_unlock failed, status=%d\n", status); + printf("cancel_test: ERROR pthread_mutex_unlock failed, status=%d\n", + status); } /* Then join to the thread to pick up the result (if we don't do @@ -609,11 +647,13 @@ void cancel_test(void) printf("cancel_test: waiter exited with result=%p\n", result); if (result != PTHREAD_CANCELED) { - printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED); + printf("cancel_test: ERROR expected result=%p\n", + PTHREAD_CANCELED); } else { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); + printf("cancel_test: " + "PASS thread terminated with PTHREAD_CANCELED\n"); } } @@ -629,7 +669,7 @@ void cancel_test(void) attr.mq_msgsize = CONFIG_MQ_MAXMSGSIZE; attr.mq_flags = 0; - mqcancel = mq_open("mqcancel", O_WRONLY|O_CREAT, 0666, &attr); + mqcancel = mq_open("mqcancel", O_WRONLY | O_CREAT, 0666, &attr); if (mqcancel == (mqd_t)-1) { printf("sender_thread: ERROR mq_open failed\n"); @@ -644,7 +684,7 @@ void cancel_test(void) * make sure. */ - usleep(75*1000); + usleep(75 * 1000); printf("cancel_test: Canceling thread\n"); status = pthread_cancel(waiter); @@ -675,7 +715,8 @@ void cancel_test(void) } else { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); + printf("cancel_test: " + "PASS thread terminated with PTHREAD_CANCELED\n"); } } @@ -686,7 +727,7 @@ void cancel_test(void) printf("sender_thread: ERROR mq_close failed\n"); } #else - printf("Skipped\n"); + printf("Skipped\n"); #endif printf("cancel_test: Test 7: Cancel signal wait\n"); @@ -701,7 +742,7 @@ void cancel_test(void) * make sure. */ - usleep(75*1000); + usleep(75 * 1000); printf("cancel_test: Canceling thread\n"); status = pthread_cancel(waiter); @@ -732,10 +773,11 @@ void cancel_test(void) } else { - printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n"); + printf("cancel_test: " + "PASS thread terminated with PTHREAD_CANCELED\n"); } } #else - printf("Skipped\n"); + printf("Skipped\n"); #endif } diff --git a/testing/ostest/cond.c b/testing/ostest/cond.c index 93ffe8256..8fc3432cc 100644 --- a/testing/ostest/cond.c +++ b/testing/ostest/cond.c @@ -18,16 +18,29 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include #include #include #include "ostest.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + #ifndef NULL # define NULL (void*)0 #endif -static volatile enum { RUNNING, MUTEX_WAIT, COND_WAIT} waiter_state; +static volatile enum +{ + RUNNING, + MUTEX_WAIT, + COND_WAIT +} waiter_state; static pthread_mutex_t mutex; static pthread_cond_t cond; @@ -40,13 +53,17 @@ static int signaler_already = 0; static int signaler_state = 0; static int signaler_nerrors = 0; +/**************************************************************************** + * Public Functions + ****************************************************************************/ + static void *thread_waiter(void *parameter) { int status; printf("waiter_thread: Started\n"); - for (;;) + for (; ; ) { /* Take the mutex */ @@ -56,7 +73,8 @@ static void *thread_waiter(void *parameter) if (status != 0) { - printf("waiter_thread: ERROR pthread_mutex_lock failed, status=%d\n", status); + printf("waiter_thread: " + "ERROR pthread_mutex_lock failed, status=%d\n", status); waiter_nerrors++; } @@ -66,24 +84,27 @@ static void *thread_waiter(void *parameter) if (!data_available) { - /* We are higher priority than the signaler thread so the - * only time that the signaler thread will have a chance to run is when - * we are waiting for the condition variable. In this case, pthread_cond_wait - * will automatically release the mutex for the signaler (then re-acquire - * the mutex before returning. - */ + /* We are higher priority than the signaler thread so the + * only time that the signaler thread will have a chance to run + * is when we are waiting for the condition variable. + * In this case, pthread_cond_wait will automatically release + * the mutex for the signaler (then re-acquire the mutex before + * returning. + */ - waiter_state = COND_WAIT; - status = pthread_cond_wait(&cond, &mutex); - waiter_state = RUNNING; + waiter_state = COND_WAIT; + status = pthread_cond_wait(&cond, &mutex); + waiter_state = RUNNING; - if (status != 0) - { - printf("waiter_thread: ERROR pthread_cond_wait failed, status=%d\n", status); - waiter_nerrors++; - } + if (status != 0) + { + printf("waiter_thread: " + "ERROR pthread_cond_wait failed, status=%d\n", + status); + waiter_nerrors++; + } - waiter_waits++; + waiter_waits++; } /* Now data should be available */ @@ -103,7 +124,8 @@ static void *thread_waiter(void *parameter) status = pthread_mutex_unlock(&mutex); if (status != 0) { - printf("waiter_thread: ERROR waiter: pthread_mutex_unlock failed, status=%d\n", status); + printf("waiter_thread: ERROR waiter: " + "pthread_mutex_unlock failed, status=%d\n", status); waiter_nerrors++; } @@ -129,7 +151,8 @@ static void *thread_signaler(void *parameter) status = pthread_mutex_lock(&mutex); if (status != 0) { - printf("thread_signaler: ERROR pthread_mutex_lock failed, status=%d\n", status); + printf("thread_signaler: " + "ERROR pthread_mutex_lock failed, status=%d\n", status); signaler_nerrors++; } @@ -137,13 +160,16 @@ static void *thread_signaler(void *parameter) if (waiter_state != COND_WAIT) { - printf("thread_signaler: ERROR waiter state = %d != COND_WAITING\n", waiter_state); + printf("thread_signaler: " + "ERROR waiter state = %d != COND_WAITING\n", waiter_state); signaler_state++; } if (data_available) { - printf("thread_signaler: ERROR data already available, waiter_state=%d\n", waiter_state); + printf("thread_signaler: " + "ERROR data already available, waiter_state=%d\n", + waiter_state); signaler_already++; } @@ -153,16 +179,18 @@ static void *thread_signaler(void *parameter) status = pthread_cond_signal(&cond); if (status != 0) { - printf("thread_signaler: ERROR pthread_cond_signal failed, status=%d\n", status); + printf("thread_signaler: " + "ERROR pthread_cond_signal failed, status=%d\n", status); signaler_nerrors++; } - /* Release the mutex */ + /* Release the mutex */ status = pthread_mutex_unlock(&mutex); if (status != 0) { - printf("thread_signaler: ERROR pthread_mutex_unlock failed, status=%d\n", status); + printf("thread_signaler: " + "ERROR pthread_mutex_unlock failed, status=%d\n", status); signaler_nerrors++; } @@ -207,7 +235,8 @@ void cond_test(void) status = pthread_mutex_init(&mutex, NULL); if (status != 0) { - printf("cond_test: ERROR pthread_mutex_init failed, status=%d\n", status); + printf("cond_test: " + "ERROR pthread_mutex_init failed, status=%d\n", status); } /* Initialize the condition variable */ @@ -216,7 +245,8 @@ void cond_test(void) status = pthread_cond_init(&cond, NULL); if (status != 0) { - printf("cond_test: ERROR pthread_condinit failed, status=%d\n", status); + printf("cond_test: " + "ERROR pthread_condinit failed, status=%d\n", status); } /* Start the waiter thread at higher priority */ @@ -233,14 +263,16 @@ void cond_test(void) prio_mid = (prio_min + prio_max) / 2; sparam.sched_priority = prio_mid; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status); + printf("cond_test: " + "pthread_attr_setschedparam failed, status=%d\n", status); } else { - printf("cond_test: Set thread 1 priority to %d\n", sparam.sched_priority); + printf("cond_test: Set thread 1 priority to %d\n", + sparam.sched_priority); } status = pthread_create(&waiter, &attr, thread_waiter, NULL); @@ -257,14 +289,16 @@ void cond_test(void) } sparam.sched_priority = (prio_min + prio_mid) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status); + printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", + status); } else { - printf("cond_test: Set thread 2 priority to %d\n", sparam.sched_priority); + printf("cond_test: Set thread 2 priority to %d\n", + sparam.sched_priority); } status = pthread_create(&signaler, &attr, thread_signaler, NULL); @@ -290,8 +324,10 @@ void cond_test(void) printf("cond_test:\n"); printf("cond_test: %d times, waiter did not have to wait for data\n", waiter_nloops - waiter_waits); - printf("cond_test: %d times, data was already available when the signaler run\n", + printf("cond_test: %d times, " + "data was already available when the signaler run\n", signaler_already); - printf("cond_test: %d times, the waiter was in an unexpected state when the signaler ran\n", + printf("cond_test: %d times, " + "the waiter was in an unexpected state when the signaler ran\n", signaler_state); } diff --git a/testing/ostest/nsem.c b/testing/ostest/nsem.c index 858d4a9cc..bc933be32 100644 --- a/testing/ostest/nsem.c +++ b/testing/ostest/nsem.c @@ -73,7 +73,7 @@ static FAR void *nsem_peer(void *parameter) /* Open semaphore 2. We will create that one */ printf("nsem_peer: Create semaphore 2 with value == 0\n"); - sem2 = sem_open(SEM2_NAME, O_CREAT|O_EXCL, 0644, 0); + sem2 = sem_open(SEM2_NAME, O_CREAT | O_EXCL, 0644, 0); if (sem1 == SEM_FAILED) { int errcode = errno; @@ -118,7 +118,7 @@ void nsem_test(void) /* Open semaphore 2. We will create that one */ printf("nsem_test: Create semaphore 1 with value == 0\n"); - sem1 = sem_open(SEM1_NAME, O_CREAT|O_EXCL, 0644, 0); + sem1 = sem_open(SEM1_NAME, O_CREAT | O_EXCL, 0644, 0); if (sem1 == SEM_FAILED) { int errcode = errno; @@ -140,10 +140,12 @@ void nsem_test(void) prio_mid = (prio_min + prio_max) / 2; sparam.sched_priority = (prio_mid + prio_max) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("nsem_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status); + printf("nsem_test: " + "ERROR: pthread_attr_setschedparam failed, status=%d\n", + status); } else { diff --git a/testing/ostest/pthread_rwlock.c b/testing/ostest/pthread_rwlock.c index d9af5d256..b88456d1f 100644 --- a/testing/ostest/pthread_rwlock.c +++ b/testing/ostest/pthread_rwlock.c @@ -40,6 +40,7 @@ struct race_cond_s /**************************************************************************** * Private Data ****************************************************************************/ + static int g_race_cond_thread_pos; /**************************************************************************** @@ -85,7 +86,8 @@ static FAR void *race_cond_thread1(FAR void *data) status = pthread_rwlock_rdlock(rc->rw_lock); if (status != 0) { - printf("pthread_rwlock: Failed to open rwlock for reading. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to open rwlock for reading. Status: %d\n", status); } sem_wait(rc->sem1); @@ -107,7 +109,8 @@ static FAR void *race_cond_thread1(FAR void *data) status = pthread_rwlock_rdlock(rc->rw_lock); if (status != 0) { - printf("pthread_rwlock: Failed to open rwlock for reading. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to open rwlock for reading. Status: %d\n", status); } sem_post(rc->sem2); @@ -124,7 +127,8 @@ static FAR void *race_cond_thread1(FAR void *data) status = pthread_rwlock_unlock(rc->rw_lock); if (status != 0) { - printf("pthread_rwlock: Failed to unlock lock held for reading. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to unlock lock held for reading. Status: %d\n", status); } return NULL; @@ -141,25 +145,31 @@ static FAR void *race_cond_thread2(FAR void *data) if (status != 0) { - printf("pthread_rwlock: Failed to wait on semaphore. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to wait on semaphore. Status: %d\n", status); } if (g_race_cond_thread_pos++ != 1) { - printf("pthread_rwlock: Thread order unexpected. Expected 1, got %d", g_race_cond_thread_pos); + printf("pthread_rwlock: " + "Thread order unexpected. Expected 1, got %d", + g_race_cond_thread_pos); } status = pthread_rwlock_tryrdlock(rc->rw_lock); if (status != EBUSY) { - printf("pthread_rwlock: Opened rw_lock for rd when locked for writing: %d\n", status); + printf("pthread_rwlock: " + "Opened rw_lock for rd when locked for writing: %d\n", status); } status = pthread_rwlock_trywrlock(rc->rw_lock); if (status != EBUSY) { - printf("pthread_rwlock: Opened rw_lock for wr when locked for writing: %d\n", status); + printf("pthread_rwlock: " + "Opened rw_lock for wr when locked for writing: %d\n", status); } + sem_post(rc->sem1); status = pthread_rwlock_rdlock(rc->rw_lock); @@ -167,7 +177,8 @@ static FAR void *race_cond_thread2(FAR void *data) if (status != 0) { - printf("pthread_rwlock: Failed to open rwlock for reading. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to open rwlock for reading. Status: %d\n", status); } if (g_race_cond_thread_pos++ != 3) @@ -200,7 +211,8 @@ static FAR void *race_cond_thread2(FAR void *data) if (status != 0) { - printf("pthread_rwlock: Failed to open rwlock for reading. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to open rwlock for reading. Status: %d\n", status); } if (g_race_cond_thread_pos++ != 7) @@ -212,7 +224,8 @@ static FAR void *race_cond_thread2(FAR void *data) status = pthread_rwlock_unlock(rc->rw_lock); if (status != 0) { - printf("pthread_rwlock: Failed to unlock lock held for writing. Status: %d\n", status); + printf("pthread_rwlock: " + "Failed to unlock lock held for writing. Status: %d\n", status); } return NULL; @@ -231,7 +244,8 @@ static void test_two_threads(void) status = pthread_rwlock_init(&rw_lock, NULL); if (status != 0) { - printf("pthread_rwlock: ERROR pthread_rwlock_init failed, status=%d\n", status); + printf("pthread_rwlock: " + "ERROR pthread_rwlock_init failed, status=%d\n", status); } status = sem_init(&sem1, 0, 0); @@ -265,7 +279,8 @@ static void * timeout_thread1(FAR void * data) status = pthread_rwlock_wrlock(rc->rw_lock); if (status != 0) { - printf("pthread_rwlock: Failed to acquire rw_lock. Status: %d\n", status); + printf("pthread_rwlock: Failed to acquire rw_lock. Status: %d\n", + status); } sem_wait(rc->sem1); @@ -273,7 +288,8 @@ static void * timeout_thread1(FAR void * data) status = pthread_rwlock_unlock(rc->rw_lock); if (status != 0) { - printf("pthread_rwlock: Failed to unlock rw_lock. Status: %d\n", status); + printf("pthread_rwlock: Failed to unlock rw_lock. Status: %d\n", + status); } return NULL; @@ -408,15 +424,15 @@ void pthread_rwlock_test(void) status = pthread_rwlock_trywrlock(&rw_lock); if (status != EBUSY) { - printf("pthread_rwlock: " - "ERROR able to acquire write lock when write lock already acquired\n"); + printf("pthread_rwlock: ERROR " + "able to acquire write lock when write lock already acquired\n"); } status = pthread_rwlock_tryrdlock(&rw_lock); if (status != EBUSY) { - printf("pthread_rwlock: " - "ERROR able to acquire read lock when write lock already acquired\n"); + printf("pthread_rwlock: ERROR " + "able to acquire read lock when write lock already acquired\n"); } status = pthread_rwlock_unlock(&rw_lock); diff --git a/testing/ostest/restart.c b/testing/ostest/restart.c index 40c1f3aaf..6bcb024fe 100644 --- a/testing/ostest/restart.c +++ b/testing/ostest/restart.c @@ -45,7 +45,7 @@ * Private Data ****************************************************************************/ -static char * const g_argv[NARGS+1] = +static char * const g_argv[NARGS + 1] = { "This is argument 1", "Argument 2 here", @@ -78,16 +78,17 @@ static int restart_main(int argc, char *argv[]) if (argc != NARGS + 1) { printf("restart_main: ERROR: Expected argc=%d got argc=%d\n", - NARGS+1, argc); + NARGS + 1, argc); } for (i = 0; i <= NARGS; i++) { printf("restart_main: argv[%d]=\"%s\"\n", i, argv[i]); - if (i > 0 && strcmp(argv[i], g_argv[i-1]) != 0) + if (i > 0 && strcmp(argv[i], g_argv[i - 1]) != 0) { - printf("restart_main: ERROR: Expected argv[%d]=\"%s\" got \"%s\"\n", - i, argv[i], g_argv[i-1]); + printf("restart_main: ERROR: " + "Expected argv[%d]=\"%s\" got \"%s\"\n", + i, argv[i], g_argv[i - 1]); } } @@ -102,8 +103,10 @@ static int restart_main(int argc, char *argv[]) } else { - printf("restart_main: ERROR Variable=%s has the wrong value\n", g_varname); - printf("restart_main: found=%s expected=%s\n", actual, g_varvalue); + printf("restart_main: ERROR Variable=%s has the wrong value\n", + g_varname); + printf("restart_main: found=%s expected=%s\n", + actual, g_varvalue); } } else @@ -122,7 +125,7 @@ static int restart_main(int argc, char *argv[]) /* Now just wait to be restarted */ - for (;;) + for (; ; ) { sleep(2); printf("restart_main: I am still here\n"); diff --git a/testing/ostest/rmutex.c b/testing/ostest/rmutex.c index 1ff680aa0..3fd10cd4f 100644 --- a/testing/ostest/rmutex.c +++ b/testing/ostest/rmutex.c @@ -18,16 +18,28 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include #include #include "ostest.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + #define NTHREADS 3 #define NLOOPS 3 #define NRECURSIONS 3 static pthread_mutex_t mut; +/**************************************************************************** + * Public Functions + ****************************************************************************/ + static void thread_inner(int id, int level) { int status; @@ -39,9 +51,11 @@ static void thread_inner(int id, int level) status = pthread_mutex_lock(&mut); if (status != 0) { - printf("thread_inner[%d, %d]: ERROR pthread_mutex_lock failed: %d\n", + printf("thread_inner[%d, %d]: " + "ERROR pthread_mutex_lock failed: %d\n", id, level, status); } + printf("thread_inner[%d, %d]: Locked\n", id, level); /* Try-lock already locked recursive mutex. */ @@ -49,7 +63,8 @@ static void thread_inner(int id, int level) status = pthread_mutex_trylock(&mut); if (status != 0) { - printf("thread_inner[%d, %d]: ERROR pthread_mutex_trylock failed: %d\n", + printf("thread_inner[%d, %d]: " + "ERROR pthread_mutex_trylock failed: %d\n", id, level, status); } else @@ -59,15 +74,16 @@ static void thread_inner(int id, int level) status = pthread_mutex_unlock(&mut); if (status != 0) { - printf("thread_inner[%d, %d]: ERROR pthread_mutex_unlock after try-lock failed: %d\n", - id, level, status); + printf("thread_inner[%d, %d]: ERROR " + "pthread_mutex_unlock after try-lock failed: %d\n", + id, level, status); } } /* Give the other threads a chance */ pthread_yield(); - thread_inner(id, level+1); + thread_inner(id, level + 1); pthread_yield(); /* Unlock the mutex */ @@ -76,9 +92,11 @@ static void thread_inner(int id, int level) status = pthread_mutex_unlock(&mut); if (status != 0) { - printf("thread_inner[%d, %d]: ERROR pthread_mutex_unlock failed: %d\n", + printf("thread_inner[%d, %d]: " + "ERROR pthread_mutex_unlock failed: %d\n", id, level, status); } + printf("thread_inner[%d, %d]: Unlocked\n", id, level); pthread_yield(); } @@ -118,17 +136,21 @@ void recursive_mutex_test(void) status = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE); if (status != 0) { - printf("recursive_mutex_test: ERROR pthread_mutexattr_settype failed, status=%d\n", status); + printf("recursive_mutex_test: " + "ERROR pthread_mutexattr_settype failed, status=%d\n", status); } status = pthread_mutexattr_gettype(&mattr, &type); if (status != 0) { - printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype failed, status=%d\n", status); + printf("recursive_mutex_test: " + "ERROR pthread_mutexattr_gettype failed, status=%d\n", status); } + if (type != PTHREAD_MUTEX_RECURSIVE) { - printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype return type=%d\n", type); + printf("recursive_mutex_test: " + "ERROR pthread_mutexattr_gettype return type=%d\n", type); } /* Initialize the mutex */ @@ -137,23 +159,27 @@ void recursive_mutex_test(void) status = pthread_mutex_init(&mut, &mattr); if (status != 0) { - printf("recursive_mutex_test: ERROR pthread_mutex_init failed, status=%d\n", status); + printf("recursive_mutex_test: " + "ERROR pthread_mutex_init failed, status=%d\n", status); } /* Start the threads -- all at the same, default priority */ for (i = 0; i < NTHREADS; i++) { - printf("recursive_mutex_test: Starting thread %d\n", i+1); + printf("recursive_mutex_test: Starting thread %d\n", i + 1); #ifdef SDCC pthread_attr_init(&attr); - status = pthread_create(&thread[i], &attr, thread_outer, (pthread_addr_t)((uintptr_t)i+1)); + status = pthread_create(&thread[i], &attr, thread_outer, + (pthread_addr_t)((uintptr_t)i + 1)); #else - status = pthread_create(&thread[i], NULL, thread_outer, (pthread_addr_t)((uintptr_t)i+1)); + status = pthread_create(&thread[i], NULL, thread_outer, + (pthread_addr_t)((uintptr_t)i + 1)); #endif if (status != 0) { - printf("recursive_mutex_test: ERROR thread#%d creation: %d\n", i+1, status); + printf("recursive_mutex_test: ERROR thread#%d creation: %d\n", + i + 1, status); } } @@ -161,7 +187,7 @@ void recursive_mutex_test(void) for (i = 0; i < NTHREADS; i++) { - printf("recursive_mutex_test: Waiting for thread %d\n", i+1); + printf("recursive_mutex_test: Waiting for thread %d\n", i + 1); #ifdef SDCC pthread_join(thread[i], &result[i]); #else diff --git a/testing/ostest/robust.c b/testing/ostest/robust.c index b595747db..fef270044 100644 --- a/testing/ostest/robust.c +++ b/testing/ostest/robust.c @@ -51,12 +51,14 @@ static FAR void *robust_waiter(FAR void *parameter) status = pthread_mutex_lock(&g_robust_mutex); if (status != 0) { - printf("thread_waiter: ERROR: pthread_mutex_lock failed, status=%d\n", status); + printf("thread_waiter: ERROR: pthread_mutex_lock failed, status=%d\n", + status); } if (status != 0) { - printf("robust_waiter: ERROR: pthread_mutex_lock failed, status=%d\n", status); + printf("robust_waiter: ERROR: pthread_mutex_lock failed, status=%d\n", + status); } else { @@ -87,7 +89,8 @@ void robust_test(void) status = pthread_mutexattr_init(&mattr); if (status != 0) { - printf("robust_test: ERROR: pthread_mutexattr_init failed, status=%d\n", + printf("robust_test: ERROR: " + "pthread_mutexattr_init failed, status=%d\n", status); nerrors++; } @@ -95,7 +98,8 @@ void robust_test(void) status = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST); if (status != 0) { - printf("robust_test: ERROR: pthread_mutexattr_setrobust failed, status=%d\n", + printf("robust_test: ERROR: " + "pthread_mutexattr_setrobust failed, status=%d\n", status); nerrors++; } @@ -123,7 +127,8 @@ void robust_test(void) status = pthread_attr_setstacksize(&pattr, STACKSIZE); if (status != 0) { - printf("robust_test: ERROR: pthread_attr_setstacksize failed, status=%d\n", + printf("robust_test: ERROR: " + "pthread_attr_setstacksize failed, status=%d\n", status); nerrors++; } @@ -135,7 +140,8 @@ void robust_test(void) status = pthread_create(&waiter, &pattr, robust_waiter, NULL); if (status != 0) { - printf("robust_test: ERROR: pthread_create failed, status=%d\n", status); + printf("robust_test: ERROR: " + "pthread_create failed, status=%d\n", status); printf(" ERROR: Terminating test\n"); nerrors++; return; @@ -157,12 +163,15 @@ void robust_test(void) } else if (status != EOWNERDEAD) { - printf("robust_test: ERROR: pthread_mutex_lock failed with %d\n", status); + printf("robust_test: ERROR: pthread_mutex_lock failed with %d\n", + status); printf(" ERROR: expected %d (EOWNERDEAD)\n", EOWNERDEAD); nerrors++; } - /* Try again, this should return immediately, still failing with EOWNERDEAD */ + /* Try again, + * this should return immediately, still failing with EOWNERDEAD + */ printf("robust_test: Take the lock again\n"); status = pthread_mutex_lock(&g_robust_mutex); @@ -173,7 +182,8 @@ void robust_test(void) } else if (status != EOWNERDEAD) { - printf("robust_test: ERROR: pthread_mutex_lock failed with %d\n", status); + printf("robust_test: ERROR: pthread_mutex_lock failed with %d\n", + status); printf(" ERROR: expected %d (EOWNERDEAD)\n", EOWNERDEAD); nerrors++; } @@ -184,7 +194,8 @@ void robust_test(void) status = pthread_mutex_consistent(&g_robust_mutex); if (status != 0) { - printf("robust_test: ERROR: pthread_mutex_consistent failed: %d\n", status); + printf("robust_test: ERROR: pthread_mutex_consistent failed: %d\n", + status); nerrors++; } @@ -192,7 +203,8 @@ void robust_test(void) status = pthread_mutex_lock(&g_robust_mutex); if (status != 0) { - printf("robust_test: ERROR: pthread_mutex_lock failed with: %d\n", status); + printf("robust_test: ERROR: pthread_mutex_lock failed with: %d\n", + status); nerrors++; } @@ -212,7 +224,8 @@ void robust_test(void) printf("robust_test: waiter exited with result=%p\n", result); if (result != NULL) { - printf("robust_test: ERROR: expected result=%p\n", PTHREAD_CANCELED); + printf("robust_test: ERROR: expected result=%p\n", + PTHREAD_CANCELED); nerrors++; } } @@ -222,14 +235,16 @@ void robust_test(void) status = pthread_mutex_unlock(&g_robust_mutex); if (status != 0) { - printf("robust_test: ERROR: pthread_mutex_unlock failed, status=%d\n", status); + printf("robust_test: ERROR: pthread_mutex_unlock failed, status=%d\n", + status); nerrors++; } status = pthread_mutex_destroy(&g_robust_mutex); if (status != 0) { - printf("robust_test: ERROR: pthread_mutex_unlock failed, status=%d\n", status); + printf("robust_test: ERROR: pthread_mutex_unlock failed, status=%d\n", + status); nerrors++; } diff --git a/testing/ostest/roundrobin.c b/testing/ostest/roundrobin.c index f7b741195..f46a8f423 100644 --- a/testing/ostest/roundrobin.c +++ b/testing/ostest/roundrobin.c @@ -39,7 +39,8 @@ /* This numbers should be tuned for different processor speeds via .config file. * With default values the test takes about 30s on Cortex-M3 @ 24MHz. With 32767 - * range and 10 runs it takes ~320s. */ + * range and 10 runs it takes ~320s. + */ #ifndef CONFIG_TESTING_OSTEST_RR_RANGE # define CONFIG_TESTING_OSTEST_RR_RANGE 10000 @@ -82,26 +83,26 @@ static void get_primes(int *count, int *last) *last = 0; /* To make the compiler happy */ for (number = 1; number < CONFIG_TESTING_OSTEST_RR_RANGE; number++) - { - int div; - bool is_prime = true; - - for (div = 2; div <= number / 2; div++) - if (number % div == 0) - { - is_prime = false; - break; - } - - if (is_prime) { - local_count++; - *last = number; + int div; + bool is_prime = true; + + for (div = 2; div <= number / 2; div++) + if (number % div == 0) + { + is_prime = false; + break; + } + + if (is_prime) + { + local_count++; + *last = number; #if 0 /* We don't really care what the numbers are */ - printf(" Prime %d: %d\n", local_count, number); + printf(" Prime %d: %d\n", local_count, number); #endif + } } - } *count = local_count; } @@ -119,7 +120,8 @@ static FAR void *get_primes_thread(FAR void *parameter) while (sem_wait(&g_rrsem) < 0); - printf("get_primes_thread id=%d started, looking for primes < %d, doing %d run(s)\n", + printf("get_primes_thread id=%d started, " + "looking for primes < %d, doing %d run(s)\n", id, CONFIG_TESTING_OSTEST_RR_RANGE, CONFIG_TESTING_OSTEST_RR_RUNS); for (i = 0; i < CONFIG_TESTING_OSTEST_RR_RUNS; i++) @@ -163,7 +165,8 @@ void rr_test(void) status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("rr_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status); + printf("rr_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", + status); } else { @@ -173,7 +176,8 @@ void rr_test(void) status = pthread_attr_setschedpolicy(&attr, SCHED_RR); if (status != OK) { - printf("rr_test: ERROR: pthread_attr_setschedpolicy failed, status=%d\n", status); + printf("rr_test: ERROR: pthread_attr_setschedpolicy failed, status=%d\n", + status); } else { @@ -189,7 +193,8 @@ void rr_test(void) printf("rr_test: Starting first get_primes_thread\n"); - status = pthread_create(&get_primes1_thread, &attr, get_primes_thread, (FAR void *)1); + status = pthread_create(&get_primes1_thread, + &attr, get_primes_thread, (FAR void *)1); if (status != 0) { printf(" ERROR: Thread 1 creation failed: %d\n", status); @@ -198,15 +203,18 @@ void rr_test(void) printf(" First get_primes_thread: %d\n", (int)get_primes1_thread); printf("rr_test: Starting second get_primes_thread\n"); - status = pthread_create(&get_primes2_thread, &attr, get_primes_thread, (FAR void *)2); + status = pthread_create(&get_primes2_thread, + &attr, get_primes_thread, (FAR void *)2); if (status != 0) { printf(" ERROR: Thread 2 creation failed: %d\n", status); } printf(" Second get_primes_thread: %d\n", (int)get_primes2_thread); - printf("rr_test: Waiting for threads to complete -- this should take awhile\n"); - printf(" If RR scheduling is working, they should start and complete at\n"); + printf("rr_test: " + "Waiting for threads to complete -- this should take awhile\n"); + printf(" " + "If RR scheduling is working, they should start and complete at\n"); printf(" about the same time\n"); sem_post(&g_rrsem); diff --git a/testing/ostest/sem.c b/testing/ostest/sem.c index 4ffe004a5..91bbd1361 100644 --- a/testing/ostest/sem.c +++ b/testing/ostest/sem.c @@ -59,11 +59,13 @@ static void *waiter_func(void *parameter) status = sem_getvalue(&sem, &value); if (status < 0) { - printf("waiter_func: ERROR thread %d could not get semaphore value\n", id); + printf("waiter_func: " + "ERROR thread %d could not get semaphore value\n", id); } else { - printf("waiter_func: Thread %d initial semaphore value = %d\n", id, value); + printf("waiter_func: " + "Thread %d initial semaphore value = %d\n", id, value); } printf("waiter_func: Thread %d waiting on semaphore\n", id); @@ -72,16 +74,19 @@ static void *waiter_func(void *parameter) { printf("waiter_func: ERROR thread %d sem_wait failed\n", id); } + printf("waiter_func: Thread %d awakened\n", id); status = sem_getvalue(&sem, &value); if (status < 0) { - printf("waiter_func: ERROR thread %d could not get semaphore value\n", id); + printf("waiter_func: " + "ERROR thread %d could not get semaphore value\n", id); } else { - printf("waiter_func: Thread %d new semaphore value = %d\n", id, value); + printf("waiter_func: " + "Thread %d new semaphore value = %d\n", id, value); } printf("waiter_func: Thread %d done\n", id); @@ -103,11 +108,13 @@ static void *poster_func(void *parameter) status = sem_getvalue(&sem, &value); if (status < 0) { - printf("poster_func: ERROR thread %d could not get semaphore value\n", id); + printf("poster_func: " + "ERROR thread %d could not get semaphore value\n", id); } else { - printf("poster_func: Thread %d semaphore value = %d\n", id, value); + printf("poster_func: " + "Thread %d semaphore value = %d\n", id, value); } if (value < 0) @@ -124,11 +131,13 @@ static void *poster_func(void *parameter) status = sem_getvalue(&sem, &value); if (status < 0) { - printf("poster_func: ERROR thread %d could not get semaphore value\n", id); + printf("poster_func: " + "ERROR thread %d could not get semaphore value\n", id); } else { - printf("poster_func: Thread %d new semaphore value = %d\n", id, value); + printf("poster_func: " + "Thread %d new semaphore value = %d\n", id, value); } } } @@ -136,7 +145,6 @@ static void *poster_func(void *parameter) printf("poster_func: Thread %d done\n", id); return NULL; - } /**************************************************************************** @@ -175,41 +183,49 @@ void sem_test(void) prio_mid = (prio_min + prio_max) / 2; sparam.sched_priority = (prio_mid + prio_max) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("sem_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status); + printf("sem_test: ERROR: " + "pthread_attr_setschedparam failed, status=%d\n", status); } else { - printf("sem_test: Set thread 1 priority to %d\n", sparam.sched_priority); + printf("sem_test: " + "Set thread 1 priority to %d\n", sparam.sched_priority); } - status = pthread_create(&waiter_thread1, &attr, waiter_func, (pthread_addr_t)1); + status = pthread_create(&waiter_thread1, &attr, + waiter_func, (pthread_addr_t)1); if (status != 0) { - printf("sem_test: ERROR: Thread 1 creation failed: %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: ERROR: 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); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("sem_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status); + printf("sem_test: ERROR: " + "pthread_attr_setschedparam failed, status=%d\n", status); } else { - printf("sem_test: Set thread 2 priority to %d\n", sparam.sched_priority); + printf("sem_test: " + "Set thread 2 priority to %d\n", sparam.sched_priority); } - status = pthread_create(&waiter_thread2, &attr, waiter_func, (pthread_addr_t)2); + status = pthread_create(&waiter_thread2, &attr, + waiter_func, (pthread_addr_t)2); if (status != 0) { printf("sem_test: ERROR: Thread 2 creation failed: %d\n", status); @@ -219,21 +235,25 @@ void sem_test(void) status = pthread_attr_init(&attr); if (status != 0) { - printf("sem_test: ERROR: 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; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status); + printf("sem_test: " + "pthread_attr_setschedparam failed, status=%d\n", status); } else { - printf("sem_test: Set thread 3 priority to %d\n", sparam.sched_priority); + printf("sem_test: Set thread 3 priority to %d\n", + sparam.sched_priority); } - status = pthread_create(&poster_thread, &attr, poster_func, (pthread_addr_t)3); + status = pthread_create(&poster_thread, &attr, + poster_func, (pthread_addr_t)3); if (status != 0) { printf("sem_test: ERROR: Thread 3 creation failed: %d\n", status); diff --git a/testing/ostest/semtimed.c b/testing/ostest/semtimed.c index be4e85af2..ad45013da 100644 --- a/testing/ostest/semtimed.c +++ b/testing/ostest/semtimed.c @@ -77,7 +77,8 @@ static void ostest_gettime(struct timespec *tp) { printf("ostest_gettime: ERROR: clock_gettime failed\n"); } - else if (tp->tv_sec < 0 || tp->tv_nsec < 0 || tp->tv_nsec >= 1000*1000*1000) + else if (tp->tv_sec < 0 || tp->tv_nsec < 0 || + tp->tv_nsec >= 1000 * 1000 * 1000) { printf("ostest_gettime: ERROR: clock_gettime returned bogus time\n"); } @@ -111,7 +112,9 @@ void semtimed_test(void) printf("semtimed_test: ERROR: sem_init failed\n"); } - /* First, make sure that the timeout expires if the semaphore is never posted */ + /* First, + * make sure that the timeout expires if the semaphore is never posted + */ ostest_gettime(&before); @@ -136,7 +139,8 @@ void semtimed_test(void) } else { - printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", errcode); + printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", + errcode); } } @@ -145,14 +149,18 @@ void semtimed_test(void) printf("AFTER: (%lu sec, %lu nsec)\n", (unsigned long)after.tv_sec, (unsigned long)after.tv_nsec); - /* Now make sure that the time wait returns successfully if the semaphore is posted */ + /* Now make sure that the time wait returns successfully if the semaphore + * is posted + */ + /* Start a poster thread. It will wait 1 seconds and post the semaphore */ printf("semtimed_test: Starting poster thread\n"); status = pthread_attr_init(&attr); if (status != OK) { - printf("semtimed_test: ERROR: pthread_attr_init failed, status=%d\n", status); + printf("semtimed_test: ERROR: pthread_attr_init failed, status=%d\n", + status); } prio_min = sched_get_priority_min(SCHED_FIFO); @@ -160,38 +168,44 @@ void semtimed_test(void) prio_mid = (prio_min + prio_max) / 2; sparam.sched_priority = (prio_mid + prio_max) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("semtimed_test: ERROR: pthread_attr_setschedparam failed, status=%d\n", status); + printf("semtimed_test: ERROR: " + "pthread_attr_setschedparam failed, status=%d\n", status); } else { - printf("semtimed_test: Set thread 1 priority to %d\n", sparam.sched_priority); + printf("semtimed_test: Set thread 1 priority to %d\n", + sparam.sched_priority); } printf("semtimed_test: Starting poster thread 3\n"); status = pthread_attr_init(&attr); if (status != 0) { - printf("semtimed_test: ERROR: pthread_attr_init failed, status=%d\n", status); + printf("semtimed_test: ERROR: pthread_attr_init failed, status=%d\n", + status); } sparam.sched_priority = (prio_min + prio_mid) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("semtimed_test: pthread_attr_setschedparam failed, status=%d\n", status); + printf("semtimed_test: pthread_attr_setschedparam failed, status=%d\n", + status); } else { - printf("semtimed_test: Set thread 3 priority to %d\n", sparam.sched_priority); + printf("semtimed_test: Set thread 3 priority to %d\n", + sparam.sched_priority); } status = pthread_create(&poster_thread, &attr, poster_func, NULL); if (status != 0) { - printf("semtimed_test: ERROR: Poster thread creation failed: %d\n", status); + printf("semtimed_test: ERROR: Poster thread creation failed: %d\n", + status); sem_destroy(&sem); return; } @@ -211,7 +225,8 @@ void semtimed_test(void) if (status < 0) { - printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", errcode); + printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", + errcode); } else { diff --git a/testing/ostest/sigprocmask.c b/testing/ostest/sigprocmask.c index 5dce87c5e..005d66c57 100644 --- a/testing/ostest/sigprocmask.c +++ b/testing/ostest/sigprocmask.c @@ -18,6 +18,10 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include #include #include @@ -37,7 +41,14 @@ * Private Data ****************************************************************************/ -static int g_some_signals[NSIGNALS] = {1, 3, 5, 7, 9}; +static int g_some_signals[NSIGNALS] = +{ + 1, + 3, + 5, + 7, + 9 +}; /**************************************************************************** * Public Functions @@ -187,7 +198,7 @@ void sigprocmask_test(void) goto errout; } - printf("sigprocmask_test: SUCCESS\n" ); + printf("sigprocmask_test: SUCCESS\n"); FFLUSH(); return; @@ -201,6 +212,6 @@ errout_with_mask: } errout: - printf("sigprocmask_test: Aborting\n" ); + printf("sigprocmask_test: Aborting\n"); FFLUSH(); } diff --git a/testing/ostest/suspend.c b/testing/ostest/suspend.c index 2d7dd4192..a24cf555f 100644 --- a/testing/ostest/suspend.c +++ b/testing/ostest/suspend.c @@ -18,6 +18,10 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include #include #include @@ -29,27 +33,23 @@ #include "ostest.h" /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ static int victim_main(int argc, char *argv[]) { - printf("victim_main: Victim started\n" ); + printf("victim_main: Victim started\n"); for (; ; ) { sleep(3); - printf("victim_main: Wasting time\n" ); + printf("victim_main: Wasting time\n"); FFLUSH(); } return 0; /* Won't get here */ } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - void suspend_test(void) { struct sched_param param; @@ -58,11 +58,11 @@ void suspend_test(void) /* Start victim thread */ - printf("suspend_test: Starting victim task\n" ); + printf("suspend_test: Starting victim task\n"); ret = sched_getparam (0, ¶m); if (ret < 0) { - printf("suspend_test: ERROR sched_getparam() failed\n" ); + printf("suspend_test: ERROR sched_getparam() failed\n"); param.sched_priority = PTHREAD_DEFAULT_PRIORITY; } @@ -70,7 +70,7 @@ void suspend_test(void) STACKSIZE, victim_main, NULL); if (victim == ERROR) { - printf("suspend_test: ERROR failed to start victim_main\n" ); + printf("suspend_test: ERROR failed to start victim_main\n"); } else { @@ -89,7 +89,7 @@ void suspend_test(void) ret = kill(victim, SIGSTOP); if (ret < 0) { - printf("suspend_test: ERROR kill() failed\n" ); + printf("suspend_test: ERROR kill() failed\n"); } printf("suspend_test: Is the victim still jabbering?\n"); @@ -100,7 +100,7 @@ void suspend_test(void) ret = kill(victim, SIGCONT); if (ret < 0) { - printf("suspend_test: ERROR kill() failed\n" ); + printf("suspend_test: ERROR kill() failed\n"); } printf("suspend_test: The victim should continue the rant.\n"); @@ -111,7 +111,7 @@ void suspend_test(void) ret = kill(victim, SIGKILL); if (ret < 0) { - printf("suspend_test: ERROR kill() failed\n" ); + printf("suspend_test: ERROR kill() failed\n"); } FFLUSH(); @@ -119,9 +119,9 @@ void suspend_test(void) ret = kill(victim, 0); if (ret >= 0) { - printf("suspend_test: ERROR kill() on the dead victim succeeded!\n" ); + printf("suspend_test: ERROR kill() on the dead victim succeeded!\n"); } - printf("suspend_test: done\n" ); + printf("suspend_test: done\n"); FFLUSH(); } diff --git a/testing/ostest/timedmqueue.c b/testing/ostest/timedmqueue.c index 2e76a8954..7689ae220 100644 --- a/testing/ostest/timedmqueue.c +++ b/testing/ostest/timedmqueue.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/testing/ostest/mqueue.c + * apps/testing/ostest/timedmqueue.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/testing/ostest/timedwait.c b/testing/ostest/timedwait.c index 78c6f0004..bc242d834 100644 --- a/testing/ostest/timedwait.c +++ b/testing/ostest/timedwait.c @@ -56,7 +56,8 @@ static void *thread_waiter(void *parameter) status = pthread_mutex_lock(&mutex); if (status != 0) { - printf("thread_waiter: ERROR pthread_mutex_lock failed, status=%d\n", status); + printf("thread_waiter: ERROR pthread_mutex_lock failed, status=%d\n", + status); } printf("thread_waiter: Starting 5 second wait for condition\n"); @@ -66,6 +67,7 @@ static void *thread_waiter(void *parameter) { printf("thread_waiter: ERROR clock_gettime failed\n"); } + ts.tv_sec += 5; /* The wait -- no-one is ever going to awaken us */ @@ -79,12 +81,15 @@ static void *thread_waiter(void *parameter) } else { - printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status); + printf("thread_waiter: " + "ERROR pthread_cond_timedwait failed, status=%d\n", status); } } else { - printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, status=%d\n", status); + printf("thread_waiter: ERROR " + "pthread_cond_timedwait returned without timeout, status=%d\n", + status); } /* Release the mutex */ @@ -93,7 +98,8 @@ static void *thread_waiter(void *parameter) status = pthread_mutex_unlock(&mutex); if (status != 0) { - printf("thread_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", status); + printf("thread_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", + status); } printf("thread_waiter: Exit with status 0x12345678\n"); @@ -120,7 +126,8 @@ void timedwait_test(void) status = pthread_mutex_init(&mutex, NULL); if (status != 0) { - printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", status); + printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", + status); } /* Initialize the condition variable */ @@ -129,7 +136,8 @@ void timedwait_test(void) status = pthread_cond_init(&cond, NULL); if (status != 0) { - printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", status); + printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", + status); } /* Start the waiter thread at higher priority */ @@ -138,7 +146,8 @@ void timedwait_test(void) status = pthread_attr_init(&attr); if (status != 0) { - printf("timedwait_test: pthread_attr_init failed, status=%d\n", status); + printf("timedwait_test: pthread_attr_init failed, status=%d\n", + status); } prio_max = sched_get_priority_max(SCHED_FIFO); @@ -150,14 +159,17 @@ void timedwait_test(void) } sparam.sched_priority = (prio_max + sparam.sched_priority) / 2; - status = pthread_attr_setschedparam(&attr,&sparam); + status = pthread_attr_setschedparam(&attr, &sparam); if (status != OK) { - printf("timedwait_test: pthread_attr_setschedparam failed, status=%d\n", status); + printf("timedwait_test: " + "pthread_attr_setschedparam failed, status=%d\n", + status); } else { - printf("timedwait_test: Set thread 2 priority to %d\n", sparam.sched_priority); + printf("timedwait_test: Set thread 2 priority to %d\n", + sparam.sched_priority); } status = pthread_create(&waiter, &attr, thread_waiter, NULL); @@ -171,7 +183,8 @@ void timedwait_test(void) status = pthread_join(waiter, &result); if (status != 0) { - printf("timedwait_test: ERROR pthread_join failed, status=%d\n", status); + printf("timedwait_test: ERROR pthread_join failed, status=%d\n", + status); } else { diff --git a/testing/ostest/waitpid.c b/testing/ostest/waitpid.c index b4d3bb236..352d4f2fc 100644 --- a/testing/ostest/waitpid.c +++ b/testing/ostest/waitpid.c @@ -58,7 +58,8 @@ static int waitpid_main(int argc, char *argv[]) printf("waitpid_main: PID %d Started\n", me); sleep(3); - printf("waitpid_main: PID %d exitting with result=%d\n", me, RETURN_STATUS); + printf("waitpid_main: PID %d exitting with result=%d\n", + me, RETURN_STATUS); return RETURN_STATUS; } @@ -72,11 +73,13 @@ 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 waitpid_main\n"); + printf("waitpid_start_child: " + "ERROR Failed to start waitpid_main\n"); } else { - printf("waitpid_start_child: Started waitpid_main at PID=%d\n", ret); + printf("waitpid_start_child: " + "Started waitpid_main at PID=%d\n", ret); } g_waitpids[i] = ret; @@ -92,7 +95,7 @@ static void waitpid_last(void) /* Find the last child thread that was started successfully */ - for (i = NCHILDREN-1; i > 0; i--) + for (i = NCHILDREN - 1; i > 0; i--) { if (g_waitpids[i] >= 0) { @@ -110,39 +113,46 @@ static void waitpid_last(void) } printf("waitpid_last: Waiting for PID=%d with waitpid()\n", - g_waitpids[NCHILDREN-1]); + g_waitpids[NCHILDREN - 1]); - ret = (int)waitpid(g_waitpids[NCHILDREN-1], &stat_loc, 0); + ret = (int)waitpid(g_waitpids[NCHILDREN - 1], &stat_loc, 0); if (ret < 0) { int errcode = errno; - /* Unfortunately, this main thread does not retain child status. If - * child status is enabled (via CONFIG_SCHED_CHILD_STATUS), ostest_main() - * disables the feature by calling sigactin with SA_NOCLDWAIT. + /* Unfortunately, this main thread does not retain child status. + * If child status is enabled (via CONFIG_SCHED_CHILD_STATUS), + * ostest_main() disables the feature by calling sigactin with + * SA_NOCLDWAIT. */ if (errcode == ECHILD) { - printf("waitpid_last: PASS: PID %d waitpid failed with ECHILD. That may be\n", - g_waitpids[NCHILDREN-1]); - printf(" acceptable because child status is disabled on this thread.\n"); + printf("waitpid_last: PASS: " + "PID %d waitpid failed with ECHILD. That may be\n", + g_waitpids[NCHILDREN - 1]); + printf(" acceptable " + "because child status is disabled on this thread.\n"); } else { printf("waitpid_last: ERROR: PID %d waitpid failed: %d\n", - g_waitpids[NCHILDREN-1], errcode); + g_waitpids[NCHILDREN - 1], errcode); } } else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) { - printf("waitpid_last: ERROR: PID %d return status is %d, expected %d\n", - g_waitpids[NCHILDREN-1], WEXITSTATUS(stat_loc), RETURN_STATUS); + printf("waitpid_last: ERROR: " + "PID %d return status is %d, expected %d\n", + g_waitpids[NCHILDREN - 1], + WEXITSTATUS(stat_loc), + RETURN_STATUS); } else { - printf("waitpid_last: PASS: PID %d waitpid succeeded with stat_loc=%04x\n", - g_waitpids[NCHILDREN-1], stat_loc); + printf("waitpid_last: PASS: " + "PID %d waitpid succeeded with stat_loc=%04x\n", + g_waitpids[NCHILDREN - 1], stat_loc); } } @@ -163,22 +173,26 @@ int waitpid_test(void) printf("\nTest waitpid()\n"); waitpid_start_children(); - printf("waitpid_test: Waiting for PID=%d with waitpid()\n", g_waitpids[0]); + printf("waitpid_test: Waiting for PID=%d with waitpid()\n", + g_waitpids[0]); ret = (int)waitpid(g_waitpids[0], &stat_loc, 0); if (ret < 0) { int errcode = errno; - /* Unfortunately, this main thread does not retain child status. If - * child status is enabled (via CONFIG_SCHED_CHILD_STATUS), ostest_main() - * disables the feature by calling sigactin with SA_NOCLDWAIT. + /* Unfortunately, this main thread does not retain child status. + * If child status is enabled (via CONFIG_SCHED_CHILD_STATUS), + * ostest_main() disables the feature by calling sigactin with + * SA_NOCLDWAIT. */ if (errcode == ECHILD) { - printf("waitpid_test: PASS: PID %d waitpid failed with ECHILD. That may be\n", - g_waitpids[NCHILDREN-1]); - printf(" acceptable because child status is disabled on this thread.\n"); + printf("waitpid_test: PASS: " + "PID %d waitpid failed with ECHILD. That may be\n", + g_waitpids[NCHILDREN - 1]); + printf(" acceptable " + "because child status is disabled on this thread.\n"); } else { @@ -193,12 +207,14 @@ int waitpid_test(void) } else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", + printf("waitpid_test: ERROR: " + "PID %d return status is %d, expected %d\n", g_waitpids[0], WEXITSTATUS(stat_loc), RETURN_STATUS); } else { - printf("waitpid_test: PID %d waitpid succeeded with stat_loc=%04x\n", + printf("waitpid_test: " + "PID %d waitpid succeeded with stat_loc=%04x\n", g_waitpids[0], stat_loc); } @@ -219,16 +235,19 @@ int waitpid_test(void) { int errcode = errno; - /* Unfortunately, this main thread does not retain child status. If - * child status is enabled (via CONFIG_SCHED_CHILD_STATUS), ostest_main() - * disables the feature by calling sigactin with SA_NOCLDWAIT. + /* Unfortunately, this main thread does not retain child status. + * If child status is enabled (via CONFIG_SCHED_CHILD_STATUS), + * ostest_main() disables the feature by calling sigactin with + * SA_NOCLDWAIT. */ if (errcode == ECHILD) { - printf("waitpid_test: PASS: PID %d waitpid failed with ECHILD. That may be\n", - g_waitpids[NCHILDREN-1]); - printf(" acceptable because child status is disabled on this thread.\n"); + printf("waitpid_test: PASS: " + "PID %d waitpid failed with ECHILD. That may be\n", + g_waitpids[NCHILDREN - 1]); + printf(" acceptable " + "because child status is disabled on this thread.\n"); } else { @@ -243,7 +262,8 @@ int waitpid_test(void) } else if (info.si_status != RETURN_STATUS) { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", + printf("waitpid_test: ERROR: " + "PID %d return status is %d, expected %d\n", info.si_pid, info.si_status, RETURN_STATUS); } else @@ -268,16 +288,19 @@ int waitpid_test(void) { int errcode = errno; - /* Unfortunately, this main thread does not retain child status. If - * child status is enabled (via CONFIG_SCHED_CHILD_STATUS), ostest_main() - * disables the feature by calling sigactin with SA_NOCLDWAIT. + /* Unfortunately, this main thread does not retain child status. + * If child status is enabled (via CONFIG_SCHED_CHILD_STATUS), + * ostest_main() disables the feature by calling sigactin with + * SA_NOCLDWAIT. */ if (errcode == ECHILD) { - printf("waitpid_test: PASS: PID %d waitpid failed with ECHILD. That may be\n", - g_waitpids[NCHILDREN-1]); - printf(" acceptable because child status is disabled on this thread.\n"); + printf("waitpid_test: PASS: " + "PID %d waitpid failed with ECHILD. That may be\n", + g_waitpids[NCHILDREN - 1]); + printf(" acceptable " + "because child status is disabled on this thread.\n"); } else { @@ -286,7 +309,8 @@ int waitpid_test(void) } else if (info.si_status != RETURN_STATUS) { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", + printf("waitpid_test: ERROR: " + "PID %d return status is %d, expected %d\n", info.si_pid, info.si_status, RETURN_STATUS); } else @@ -311,16 +335,19 @@ int waitpid_test(void) { int errcode = errno; - /* Unfortunately, this main thread does not retain child status. If - * child status is enabled (via CONFIG_SCHED_CHILD_STATUS), ostest_main() - * disables the feature by calling sigactin with SA_NOCLDWAIT. + /* Unfortunately, this main thread does not retain child status. + * If child status is enabled (via CONFIG_SCHED_CHILD_STATUS), + * ostest_main() disables the feature by calling sigactin with + * SA_NOCLDWAIT. */ if (errcode == ECHILD) { - printf("waitpid_test: PASS: PID %d waitpid failed with ECHILD. That may be\n", - g_waitpids[NCHILDREN-1]); - printf(" acceptable because child status is disabled on this thread.\n"); + printf("waitpid_test: PASS: " + "PID %d waitpid failed with ECHILD. That may be\n", + g_waitpids[NCHILDREN - 1]); + printf(" acceptable " + "because child status is disabled on this thread.\n"); } else { @@ -329,7 +356,8 @@ int waitpid_test(void) } else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) { - printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", + printf("waitpid_test: ERROR: " + "PID %d return status is %d, expected %d\n", ret, WEXITSTATUS(stat_loc), RETURN_STATUS); } else