From 644c0fa6184bafa0ca8cd560ce9b5b4224863ee6 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 8 Aug 1996 16:28:24 +0000 Subject: added complete test cases for pthread_once. --- c/src/tests/psxtests/psx01/init.c | 16 +++++++------- c/src/tests/psxtests/psx01/system.h | 1 + c/src/tests/psxtests/psx01/task.c | 43 ++++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 16 deletions(-) (limited to 'c/src') diff --git a/c/src/tests/psxtests/psx01/init.c b/c/src/tests/psxtests/psx01/init.c index 75aa73ac65..e62030c295 100644 --- a/c/src/tests/psxtests/psx01/init.c +++ b/c/src/tests/psxtests/psx01/init.c @@ -62,7 +62,7 @@ void *POSIX_Init( /* check the time remaining */ - printf( "seconds remaining (%d)\n", (int)remaining ); + printf( "Init: seconds remaining (%d)\n", (int)remaining ); assert( !remaining ); /* use nanosleep to delay */ @@ -82,33 +82,33 @@ void *POSIX_Init( /* check the time remaining */ - printf( "sec (%d), nsec (%d) remaining\n", (int)tr.tv_sec, (int)tr.tv_nsec ); + printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec ); assert( !tr.tv_sec && !tr.tv_nsec ); /* get id of this thread */ Init_id = pthread_self(); - printf( "Init's ID is 0x%08x\n", Init_id ); + printf( "Init: ID is 0x%08x\n", Init_id ); /* print the minimum priority */ priority = sched_get_priority_min( SCHED_FIFO ); - printf( "Minimum priority for FIFO is %d\n", priority ); + printf( "Init: Minimum priority for FIFO is %d\n", priority ); assert( priority != -1 ); /* print the maximum priority */ priority = sched_get_priority_max( SCHED_FIFO ); - printf( "Maximum priority for FIFO is %d\n", priority ); + printf( "Init: Maximum priority for FIFO is %d\n", priority ); assert( priority != -1 ); /* print the round robin time quantum */ status = sched_rr_get_interval( getpid(), &tr ); printf( - "Round Robin quantum is %d seconds, %d nanoseconds\n", - (int) tr.tv_sec, - (int) tr.tv_nsec + "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n", + tr.tv_sec, + tr.tv_nsec ); assert( !status ); diff --git a/c/src/tests/psxtests/psx01/system.h b/c/src/tests/psxtests/psx01/system.h index 3abfff0e19..a0e2220827 100644 --- a/c/src/tests/psxtests/psx01/system.h +++ b/c/src/tests/psxtests/psx01/system.h @@ -18,6 +18,7 @@ #include #include +#include void *POSIX_Init( void *argument diff --git a/c/src/tests/psxtests/psx01/task.c b/c/src/tests/psxtests/psx01/task.c index 4ff3d8e450..d9ee2e781a 100644 --- a/c/src/tests/psxtests/psx01/task.c +++ b/c/src/tests/psxtests/psx01/task.c @@ -21,36 +21,63 @@ #include "system.h" +void Test_init_routine( void ) +{ + puts( "Test_init_routine: invoked" ); +} + + void *Task_1_through_3( void *argument ) { int status; + pthread_once_t once = PTHREAD_ONCE_INIT; - /* XXX temporary */ + empty_line(); /* get id of this thread */ Task_id = pthread_self(); - printf( "Task's ID is 0x%08x\n", Task_id ); + printf( "Task_1: ID is 0x%08x\n", Task_id ); + + /* exercise pthread_equal */ status = pthread_equal( Task_id, Task_id ); if ( status ) - puts( "pthread_equal match case passed" ); + puts( "Task_1: pthread_equal match case passed" ); assert( status ); status = pthread_equal( Init_id, Task_id ); if ( !status ) - puts( "pthread_equal different case passed" ); + puts( "Task_1: pthread_equal different case passed" ); assert( !status ); - puts( "pthread_equal first id bad" ); + puts( "Task_1: pthread_equal first id bad" ); status = pthread_equal( -1, Task_id ); - assert( status == 0); + assert( !status ); - puts( "pthread_equal second id bad" ); + puts( "Task_1: pthread_equal second id bad" ); status = pthread_equal( Init_id, -1 ); - assert( status == 0); + assert( !status ); + + /* exercise pthread_once */ + + puts( "Task_1: pthread_once - EINVAL (NULL once_control)" ); + status = pthread_once( NULL, Test_init_routine ); + assert( status == EINVAL ); + + puts( "Task_1: pthread_once - EINVAL (NULL init_routine)" ); + status = pthread_once( &once, NULL ); + assert( status == EINVAL ); + + puts( "Task_1: pthread_once - SUCCESSFUL (init_routine executes)" ); + status = pthread_once( &once, Test_init_routine ); + assert( !status ); + + puts( "Task_1: pthread_once - SUCCESSFUL (init_routine does not execute)" ); + status = pthread_once( &once, Test_init_routine ); + assert( !status ); puts( "*** END OF POSIX TEST 1 ***" ); exit( 0 ); -- cgit v1.2.3