forked from Imagelibrary/rtems
added complete test cases for pthread_once.
This commit is contained in:
@@ -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 );
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <pmacros.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
void *POSIX_Init(
|
||||
void *argument
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <pmacros.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
void *POSIX_Init(
|
||||
void *argument
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user