forked from Imagelibrary/rtems
psxtests: Adjust sporadic server tests
According to POSIX priority value returned from pthread_getschedparam() shall be the value specified by the most recent pthread_setschedparam(), pthread_setschedprio(), or pthread_create() call affecting the target thread. Read this as though a temporary lower priority due to the sporadic server policy shall not be visible through pthread_getschedparam(). Thus, use rtems_task_set_priority() to get the current priority of the threads. Use a priority ceiling mutex to prevent sporadic server priority adjustments.
This commit is contained in:
@@ -20,33 +20,22 @@
|
|||||||
|
|
||||||
const char rtems_test_name[] = "PSX 9";
|
const char rtems_test_name[] = "PSX 9";
|
||||||
|
|
||||||
void print_schedparam(
|
static int CEILING_PRIORITY;
|
||||||
char *prefix,
|
static int HIGH_PRIORITY;
|
||||||
struct sched_param *schedparam
|
static int LOW_PRIORITY;
|
||||||
);
|
|
||||||
|
|
||||||
int HIGH_PRIORITY;
|
static int get_current_prio( pthread_t thread )
|
||||||
int MEDIUM_PRIORITY;
|
|
||||||
int LOW_PRIORITY;
|
|
||||||
|
|
||||||
void print_schedparam(
|
|
||||||
char *prefix,
|
|
||||||
struct sched_param *schedparam
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority );
|
rtems_status_code sc;
|
||||||
#if defined(_POSIX_SPORADIC_SERVER)
|
rtems_task_priority prio;
|
||||||
printf( "%ssched_ss_low_priority = %d\n",
|
int max;
|
||||||
prefix, schedparam->sched_ss_low_priority );
|
|
||||||
printf( "%ssched_ss_repl_period = (%" PRIdtime_t ", %ld)\n", prefix,
|
sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio );
|
||||||
schedparam->sched_ss_repl_period.tv_sec,
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
||||||
schedparam->sched_ss_repl_period.tv_nsec );
|
|
||||||
printf( "%ssched_ss_init_budget = (%" PRIdtime_t ", %ld)\n", prefix,
|
max = sched_get_priority_max( SCHED_FIFO );
|
||||||
schedparam->sched_ss_init_budget.tv_sec,
|
|
||||||
schedparam->sched_ss_init_budget.tv_nsec );
|
return max + 1 - (int) prio;
|
||||||
#else
|
|
||||||
printf( "%s_POSIX_SPORADIC_SERVER is not defined\n", prefix );
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *mutex_lock_task(void *arg)
|
static void *mutex_lock_task(void *arg)
|
||||||
@@ -109,6 +98,10 @@ void *POSIX_Init(
|
|||||||
|
|
||||||
TEST_BEGIN();
|
TEST_BEGIN();
|
||||||
|
|
||||||
|
CEILING_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
|
||||||
|
HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 1;
|
||||||
|
LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
|
||||||
|
|
||||||
test_destroy_locked_mutex();
|
test_destroy_locked_mutex();
|
||||||
|
|
||||||
/* set the time of day, and print our buffer in multiple ways */
|
/* set the time of day, and print our buffer in multiple ways */
|
||||||
@@ -135,28 +128,25 @@ void *POSIX_Init(
|
|||||||
schedparam.sched_ss_init_budget.tv_sec = 0;
|
schedparam.sched_ss_init_budget.tv_sec = 0;
|
||||||
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */
|
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */
|
||||||
|
|
||||||
schedparam.sched_priority = sched_get_priority_max(SCHED_SPORADIC);
|
schedparam.sched_priority = HIGH_PRIORITY;
|
||||||
schedparam.sched_ss_low_priority = sched_get_priority_max(SCHED_SPORADIC) - 2;
|
schedparam.sched_ss_low_priority = LOW_PRIORITY;
|
||||||
|
|
||||||
puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
|
puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
|
||||||
status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
|
status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
|
||||||
rtems_test_assert( !status );
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
|
||||||
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 */
|
||||||
|
|
||||||
for ( passes=0 ; passes <= 3 ; ) {
|
for ( passes=0 ; passes <= 3 ; ) {
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
int current_priority;
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
if ( priority != schedparam.sched_priority ) {
|
current_priority = get_current_prio( pthread_self() );
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
|
if ( priority != current_priority ) {
|
||||||
|
priority = current_priority;
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
sprintf( buffer, " - new priority = %d", priority );
|
||||||
print_current_time( "Init: ", buffer );
|
print_current_time( "Init: ", buffer );
|
||||||
passes++;
|
passes++;
|
||||||
@@ -175,10 +165,6 @@ void *POSIX_Init(
|
|||||||
schedparam.sched_ss_init_budget.tv_sec = 0;
|
schedparam.sched_ss_init_budget.tv_sec = 0;
|
||||||
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */
|
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */
|
||||||
|
|
||||||
HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
|
|
||||||
MEDIUM_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
|
|
||||||
LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 4;
|
|
||||||
|
|
||||||
schedparam.sched_priority = HIGH_PRIORITY;
|
schedparam.sched_priority = HIGH_PRIORITY;
|
||||||
schedparam.sched_ss_low_priority = LOW_PRIORITY;
|
schedparam.sched_ss_low_priority = LOW_PRIORITY;
|
||||||
|
|
||||||
@@ -190,7 +176,10 @@ void *POSIX_Init(
|
|||||||
status = pthread_mutexattr_init( &attr );
|
status = pthread_mutexattr_init( &attr );
|
||||||
rtems_test_assert( !status );
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
|
status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
|
||||||
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
|
status = pthread_mutexattr_setprioceiling( &attr, CEILING_PRIORITY );
|
||||||
rtems_test_assert( !status );
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
puts( "Init: Creating a mutex" );
|
puts( "Init: Creating a mutex" );
|
||||||
@@ -199,11 +188,7 @@ void *POSIX_Init(
|
|||||||
printf( "status = %d\n", status );
|
printf( "status = %d\n", status );
|
||||||
rtems_test_assert( !status );
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
|
||||||
print_current_time( "Init: ", buffer );
|
print_current_time( "Init: ", buffer );
|
||||||
|
|
||||||
/* go into a loop consuming CPU time to watch our priority NOT lower */
|
/* go into a loop consuming CPU time to watch our priority NOT lower */
|
||||||
@@ -216,32 +201,16 @@ void *POSIX_Init(
|
|||||||
printf( "status = %d %s\n", status, strerror(status) );
|
printf( "status = %d %s\n", status, strerror(status) );
|
||||||
rtems_test_assert( !status );
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
for ( ; ; ) {
|
do {
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
priority = get_current_prio( pthread_self() );
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
if ( schedparam.sched_priority == LOW_PRIORITY ) {
|
if ( priority != CEILING_PRIORITY ) {
|
||||||
puts( "ERROR - Init's priority lowered while holding mutex" );
|
puts( "ERROR - Init's priority lowered while holding mutex" );
|
||||||
rtems_test_exit(0);
|
rtems_test_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
now = time( &now );
|
now = time( &now );
|
||||||
if ( now - start > 3 )
|
} while ( now - start < 3 );
|
||||||
break;
|
|
||||||
|
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
|
||||||
print_current_time( "Init: ", buffer );
|
|
||||||
|
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
|
||||||
print_current_time( "Init: ", buffer );
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* with this unlock we should be able to go to low priority */
|
/* with this unlock we should be able to go to low priority */
|
||||||
|
|
||||||
@@ -251,26 +220,15 @@ void *POSIX_Init(
|
|||||||
printf( "status = %d\n", status );
|
printf( "status = %d\n", status );
|
||||||
rtems_test_assert( !status );
|
rtems_test_assert( !status );
|
||||||
|
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
|
||||||
print_current_time( "Init: ", buffer );
|
print_current_time( "Init: ", buffer );
|
||||||
|
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
if ( get_current_prio( pthread_self() ) == LOW_PRIORITY )
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
if ( schedparam.sched_priority == LOW_PRIORITY )
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
|
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
|
||||||
rtems_test_assert( !status );
|
|
||||||
|
|
||||||
priority = schedparam.sched_priority;
|
|
||||||
sprintf( buffer, " - new priority = %d", priority );
|
|
||||||
print_current_time( "Init: ", buffer );
|
print_current_time( "Init: ", buffer );
|
||||||
|
|
||||||
TEST_END();
|
TEST_END();
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
*** POSIX TEST 9 ***
|
*** BEGIN OF TEST PSX 9 ***
|
||||||
Init's ID is 0x0b010001
|
Init's ID is 0x0b010001
|
||||||
Init: pthread_getschedparam - SUCCESSFUL
|
Init: pthread_getschedparam - SUCCESSFUL
|
||||||
Init: Fri May 24 11:05:00 1996 - current priority = 2
|
Init: Fri May 24 11:05:00 1996 - current priority = 2
|
||||||
Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
|
Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
|
||||||
Init: Fri May 24 11:05:00 1996 - new priority = 254
|
|
||||||
Init: Fri May 24 11:05:00 1996 - new priority = 252
|
Init: Fri May 24 11:05:00 1996 - new priority = 252
|
||||||
Init: Fri May 24 11:05:00 1996 - new priority = 254
|
|
||||||
Init: Fri May 24 11:05:00 1996 - new priority = 252
|
Init: Fri May 24 11:05:00 1996 - new priority = 252
|
||||||
Init: Fri May 24 11:05:01 1996 - new priority = 254
|
Init: Fri May 24 11:05:00 1996 - new priority = 253
|
||||||
|
Init: Fri May 24 11:05:00 1996 - new priority = 252
|
||||||
|
Init: Fri May 24 11:05:00 1996 - new priority = 253
|
||||||
|
|
||||||
Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
|
Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
|
||||||
Init: Initializing mutex attributes for priority ceiling
|
Init: Initializing mutex attributes for priority ceiling
|
||||||
Init: Creating a mutex
|
Init: Creating a mutex
|
||||||
Init: Fri May 24 11:05:01 1996 - new priority = 254
|
Init: Fri May 24 11:05:00 1996 - new priority = 252
|
||||||
Init: pthread_mutex_lock acquire the lock
|
Init: pthread_mutex_lock acquire the lock
|
||||||
Init: Fri May 24 11:05:01 1996 - new priority = 254
|
|
||||||
Init: Fri May 24 11:05:01 1996 - new priority = 254
|
|
||||||
Init: unlock mutex
|
Init: unlock mutex
|
||||||
Init: Fri May 24 11:05:01 1996 - new priority = 254
|
Init: Fri May 24 11:05:03 1996 - new priority = 253
|
||||||
Init: Fri May 24 11:05:01 1996 - new priority = 250
|
Init: Fri May 24 11:05:03 1996 - new priority = 252
|
||||||
*** END OF POSIX TEST 9 ***
|
*** END OF TEST PSX 9 **
|
||||||
|
|||||||
@@ -44,16 +44,25 @@ typedef struct {
|
|||||||
|
|
||||||
static test_context test_instance;
|
static test_context test_instance;
|
||||||
|
|
||||||
|
static int get_current_prio( pthread_t thread )
|
||||||
|
{
|
||||||
|
rtems_status_code sc;
|
||||||
|
rtems_task_priority prio;
|
||||||
|
int max;
|
||||||
|
|
||||||
|
sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio );
|
||||||
|
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
|
||||||
|
|
||||||
|
max = sched_get_priority_max( SCHED_FIFO );
|
||||||
|
|
||||||
|
return max + 1 - (int) prio;
|
||||||
|
}
|
||||||
|
|
||||||
static void wait_for_prio( int prio )
|
static void wait_for_prio( int prio )
|
||||||
{
|
{
|
||||||
int status;
|
while ( prio != get_current_prio( pthread_self() ) ) {
|
||||||
int policy;
|
/* Wait */
|
||||||
struct sched_param param;
|
}
|
||||||
|
|
||||||
do {
|
|
||||||
status = pthread_getschedparam( pthread_self(), &policy, ¶m );
|
|
||||||
rtems_test_assert( status == 0 );
|
|
||||||
} while ( prio != param.sched_priority );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t timeval_to_us( const struct timeval *tv )
|
static uint64_t timeval_to_us( const struct timeval *tv )
|
||||||
|
|||||||
Reference in New Issue
Block a user