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 */
|
/* check the time remaining */
|
||||||
|
|
||||||
printf( "seconds remaining (%d)\n", (int)remaining );
|
printf( "Init: seconds remaining (%d)\n", (int)remaining );
|
||||||
assert( !remaining );
|
assert( !remaining );
|
||||||
|
|
||||||
/* use nanosleep to delay */
|
/* use nanosleep to delay */
|
||||||
@@ -82,33 +82,33 @@ void *POSIX_Init(
|
|||||||
|
|
||||||
/* check the time remaining */
|
/* 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 );
|
assert( !tr.tv_sec && !tr.tv_nsec );
|
||||||
|
|
||||||
/* get id of this thread */
|
/* get id of this thread */
|
||||||
|
|
||||||
Init_id = pthread_self();
|
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 */
|
/* print the minimum priority */
|
||||||
|
|
||||||
priority = sched_get_priority_min( SCHED_FIFO );
|
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 );
|
assert( priority != -1 );
|
||||||
|
|
||||||
/* print the maximum priority */
|
/* print the maximum priority */
|
||||||
|
|
||||||
priority = sched_get_priority_max( SCHED_FIFO );
|
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 );
|
assert( priority != -1 );
|
||||||
|
|
||||||
/* print the round robin time quantum */
|
/* print the round robin time quantum */
|
||||||
|
|
||||||
status = sched_rr_get_interval( getpid(), &tr );
|
status = sched_rr_get_interval( getpid(), &tr );
|
||||||
printf(
|
printf(
|
||||||
"Round Robin quantum is %d seconds, %d nanoseconds\n",
|
"Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
|
||||||
(int) tr.tv_sec,
|
tr.tv_sec,
|
||||||
(int) tr.tv_nsec
|
tr.tv_nsec
|
||||||
);
|
);
|
||||||
assert( !status );
|
assert( !status );
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <pmacros.h>
|
#include <pmacros.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
void *POSIX_Init(
|
void *POSIX_Init(
|
||||||
void *argument
|
void *argument
|
||||||
|
|||||||
@@ -21,36 +21,63 @@
|
|||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
void Test_init_routine( void )
|
||||||
|
{
|
||||||
|
puts( "Test_init_routine: invoked" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *Task_1_through_3(
|
void *Task_1_through_3(
|
||||||
void *argument
|
void *argument
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||||
|
|
||||||
/* XXX temporary */
|
empty_line();
|
||||||
|
|
||||||
/* get id of this thread */
|
/* get id of this thread */
|
||||||
|
|
||||||
Task_id = pthread_self();
|
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 );
|
status = pthread_equal( Task_id, Task_id );
|
||||||
if ( status )
|
if ( status )
|
||||||
puts( "pthread_equal match case passed" );
|
puts( "Task_1: pthread_equal match case passed" );
|
||||||
assert( status );
|
assert( status );
|
||||||
|
|
||||||
status = pthread_equal( Init_id, Task_id );
|
status = pthread_equal( Init_id, Task_id );
|
||||||
if ( !status )
|
if ( !status )
|
||||||
puts( "pthread_equal different case passed" );
|
puts( "Task_1: pthread_equal different case passed" );
|
||||||
assert( !status );
|
assert( !status );
|
||||||
|
|
||||||
puts( "pthread_equal first id bad" );
|
puts( "Task_1: pthread_equal first id bad" );
|
||||||
status = pthread_equal( -1, Task_id );
|
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 );
|
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 ***" );
|
puts( "*** END OF POSIX TEST 1 ***" );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void *POSIX_Init(
|
|||||||
|
|
||||||
/* check the time remaining */
|
/* check the time remaining */
|
||||||
|
|
||||||
printf( "seconds remaining (%d)\n", (int)remaining );
|
printf( "Init: seconds remaining (%d)\n", (int)remaining );
|
||||||
assert( !remaining );
|
assert( !remaining );
|
||||||
|
|
||||||
/* use nanosleep to delay */
|
/* use nanosleep to delay */
|
||||||
@@ -82,33 +82,33 @@ void *POSIX_Init(
|
|||||||
|
|
||||||
/* check the time remaining */
|
/* 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 );
|
assert( !tr.tv_sec && !tr.tv_nsec );
|
||||||
|
|
||||||
/* get id of this thread */
|
/* get id of this thread */
|
||||||
|
|
||||||
Init_id = pthread_self();
|
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 */
|
/* print the minimum priority */
|
||||||
|
|
||||||
priority = sched_get_priority_min( SCHED_FIFO );
|
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 );
|
assert( priority != -1 );
|
||||||
|
|
||||||
/* print the maximum priority */
|
/* print the maximum priority */
|
||||||
|
|
||||||
priority = sched_get_priority_max( SCHED_FIFO );
|
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 );
|
assert( priority != -1 );
|
||||||
|
|
||||||
/* print the round robin time quantum */
|
/* print the round robin time quantum */
|
||||||
|
|
||||||
status = sched_rr_get_interval( getpid(), &tr );
|
status = sched_rr_get_interval( getpid(), &tr );
|
||||||
printf(
|
printf(
|
||||||
"Round Robin quantum is %d seconds, %d nanoseconds\n",
|
"Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n",
|
||||||
(int) tr.tv_sec,
|
tr.tv_sec,
|
||||||
(int) tr.tv_nsec
|
tr.tv_nsec
|
||||||
);
|
);
|
||||||
assert( !status );
|
assert( !status );
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <pmacros.h>
|
#include <pmacros.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
void *POSIX_Init(
|
void *POSIX_Init(
|
||||||
void *argument
|
void *argument
|
||||||
|
|||||||
@@ -21,36 +21,63 @@
|
|||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
void Test_init_routine( void )
|
||||||
|
{
|
||||||
|
puts( "Test_init_routine: invoked" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *Task_1_through_3(
|
void *Task_1_through_3(
|
||||||
void *argument
|
void *argument
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||||
|
|
||||||
/* XXX temporary */
|
empty_line();
|
||||||
|
|
||||||
/* get id of this thread */
|
/* get id of this thread */
|
||||||
|
|
||||||
Task_id = pthread_self();
|
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 );
|
status = pthread_equal( Task_id, Task_id );
|
||||||
if ( status )
|
if ( status )
|
||||||
puts( "pthread_equal match case passed" );
|
puts( "Task_1: pthread_equal match case passed" );
|
||||||
assert( status );
|
assert( status );
|
||||||
|
|
||||||
status = pthread_equal( Init_id, Task_id );
|
status = pthread_equal( Init_id, Task_id );
|
||||||
if ( !status )
|
if ( !status )
|
||||||
puts( "pthread_equal different case passed" );
|
puts( "Task_1: pthread_equal different case passed" );
|
||||||
assert( !status );
|
assert( !status );
|
||||||
|
|
||||||
puts( "pthread_equal first id bad" );
|
puts( "Task_1: pthread_equal first id bad" );
|
||||||
status = pthread_equal( -1, Task_id );
|
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 );
|
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 ***" );
|
puts( "*** END OF POSIX TEST 1 ***" );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|||||||
Reference in New Issue
Block a user