psxtests/psx09: Improve sporadic server tests

Drop thread parameter from get_current_prio().

Lock/unlock ceiling mutex while executing at low and high priority.

Update #5164.
This commit is contained in:
Sebastian Huber
2024-11-26 04:30:39 +01:00
committed by Chris Johns
parent e565dbba65
commit 5eb938283d

View File

@@ -39,13 +39,13 @@
const char rtems_test_name[] = "PSX 9"; const char rtems_test_name[] = "PSX 9";
static int get_current_prio( pthread_t thread ) static int get_current_prio( void )
{ {
rtems_status_code sc; rtems_status_code sc;
rtems_task_priority prio; rtems_task_priority prio;
int max; int max;
sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio ); sc = rtems_task_set_priority( RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio );
rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rtems_test_assert( sc == RTEMS_SUCCESSFUL );
max = sched_get_priority_max( SCHED_FIFO ); max = sched_get_priority_max( SCHED_FIFO );
@@ -109,7 +109,6 @@ void *POSIX_Init(
char buffer[ 80 ]; char buffer[ 80 ];
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
time_t start; time_t start;
time_t now;
int ceiling_priority; int ceiling_priority;
int high_priority; int high_priority;
int low_priority; int low_priority;
@@ -141,10 +140,10 @@ void *POSIX_Init(
sprintf( buffer, " - current priority = %d", priority ); sprintf( buffer, " - current priority = %d", priority );
print_current_time( "Init: ", buffer ); print_current_time( "Init: ", buffer );
schedparam.sched_ss_repl_period.tv_sec = 0; schedparam.sched_ss_repl_period.tv_sec = 2;
schedparam.sched_ss_repl_period.tv_nsec = 500000000; /* 1/2 second */ schedparam.sched_ss_repl_period.tv_nsec = 0;
schedparam.sched_ss_init_budget.tv_sec = 0; schedparam.sched_ss_init_budget.tv_sec = 1;
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */ schedparam.sched_ss_init_budget.tv_nsec = 0;
schedparam.sched_priority = high_priority; schedparam.sched_priority = high_priority;
schedparam.sched_ss_low_priority = low_priority; schedparam.sched_ss_low_priority = low_priority;
@@ -153,7 +152,7 @@ void *POSIX_Init(
status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
rtems_test_assert( !status ); rtems_test_assert( !status );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) ); sprintf( buffer, " - new priority = %d", get_current_prio() );
print_current_time( "Init: ", buffer ); print_current_time( "Init: ", buffer );
/* go into a loop consuming CPU time to watch our priority change */ /* go into a loop consuming CPU time to watch our priority change */
@@ -161,7 +160,7 @@ void *POSIX_Init(
for ( passes=0 ; passes <= 3 ; ) { for ( passes=0 ; passes <= 3 ; ) {
int current_priority; int current_priority;
current_priority = get_current_prio( pthread_self() ); current_priority = get_current_prio();
if ( priority != current_priority ) { if ( priority != current_priority ) {
priority = current_priority; priority = current_priority;
@@ -206,48 +205,48 @@ void *POSIX_Init(
printf( "status = %d\n", status ); printf( "status = %d\n", status );
rtems_test_assert( !status ); rtems_test_assert( !status );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) ); sprintf( buffer, " - new priority = %d", get_current_prio() );
print_current_time( "Init: ", buffer ); print_current_time( "Init: ", buffer );
/* go into a loop consuming CPU time to watch our priority NOT lower */
start = time( &start ); start = time( &start );
puts( "Init: pthread_mutex_lock acquire the lock" ); puts( "Init: Go into low priority and lock/unlock ceiling mutex" );
while ( get_current_prio() == low_priority ) {
/* Be busy until sched_ss_repl_period elapses */
}
rtems_test_assert( get_current_prio() == high_priority );
status = pthread_mutex_lock( &Mutex_id ); status = pthread_mutex_lock( &Mutex_id );
if ( status ) if ( status )
printf( "status = %d %s\n", status, strerror(status) ); printf( "status = %d %s\n", status, strerror(status) );
rtems_test_assert( !status ); rtems_test_assert( !status );
rtems_test_assert( get_current_prio() == ceiling_priority );
do { status = pthread_mutex_unlock( &Mutex_id );
priority = get_current_prio( pthread_self() ); if ( status )
printf( "status = %d %s\n", status, strerror(status) );
rtems_test_assert( !status );
rtems_test_assert( get_current_prio() == high_priority );
if ( priority != ceiling_priority ) { puts( "Init: Go into high priority and lock/unlock ceiling mutex" );
puts( "ERROR - Init's priority lowered while holding mutex" );
rtems_test_exit(0); while ( get_current_prio() == high_priority ) {
/* Be busy until sched_ss_init_budget elapses */
} }
now = time( &now ); rtems_test_assert( get_current_prio() == low_priority );
} while ( now - start < 3 ); status = pthread_mutex_lock( &Mutex_id );
if ( status )
printf( "status = %d %s\n", status, strerror(status) );
rtems_test_assert( !status );
rtems_test_assert( get_current_prio() == ceiling_priority );
/* with this unlock we should be able to go to low priority */
puts( "Init: unlock mutex" );
status = pthread_mutex_unlock( &Mutex_id ); status = pthread_mutex_unlock( &Mutex_id );
if ( status ) if ( status )
printf( "status = %d\n", status ); printf( "status = %d\n", status );
rtems_test_assert( !status ); rtems_test_assert( !status );
rtems_test_assert( get_current_prio() == low_priority );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
print_current_time( "Init: ", buffer );
for ( ; ; ) {
if ( get_current_prio( pthread_self() ) == low_priority )
break;
}
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
print_current_time( "Init: ", buffer );
TEST_END(); TEST_END();
rtems_test_exit( 0 ); rtems_test_exit( 0 );