diff options
Diffstat (limited to 'testsuites/psxtests/psx09/init.c')
-rw-r--r-- | testsuites/psxtests/psx09/init.c | 120 |
1 files changed, 39 insertions, 81 deletions
diff --git a/testsuites/psxtests/psx09/init.c b/testsuites/psxtests/psx09/init.c index 64bb4af252..d9226c9abb 100644 --- a/testsuites/psxtests/psx09/init.c +++ b/testsuites/psxtests/psx09/init.c @@ -20,33 +20,22 @@ const char rtems_test_name[] = "PSX 9"; -void print_schedparam( - char *prefix, - struct sched_param *schedparam -); - -int HIGH_PRIORITY; -int MEDIUM_PRIORITY; -int LOW_PRIORITY; - -void print_schedparam( - char *prefix, - struct sched_param *schedparam -) +static int CEILING_PRIORITY; +static int HIGH_PRIORITY; +static int LOW_PRIORITY; + +static int get_current_prio( pthread_t thread ) { - printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority ); -#if defined(_POSIX_SPORADIC_SERVER) - printf( "%ssched_ss_low_priority = %d\n", - prefix, schedparam->sched_ss_low_priority ); - printf( "%ssched_ss_repl_period = (%" PRIdtime_t ", %ld)\n", prefix, - schedparam->sched_ss_repl_period.tv_sec, - schedparam->sched_ss_repl_period.tv_nsec ); - printf( "%ssched_ss_init_budget = (%" PRIdtime_t ", %ld)\n", prefix, - schedparam->sched_ss_init_budget.tv_sec, - schedparam->sched_ss_init_budget.tv_nsec ); -#else - printf( "%s_POSIX_SPORADIC_SERVER is not defined\n", prefix ); -#endif + 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 *mutex_lock_task(void *arg) @@ -109,6 +98,10 @@ void *POSIX_Init( 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(); /* 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_nsec = 250000000; /* 1/4 second */ - schedparam.sched_priority = sched_get_priority_max(SCHED_SPORADIC); - schedparam.sched_ss_low_priority = sched_get_priority_max(SCHED_SPORADIC) - 2; + schedparam.sched_priority = HIGH_PRIORITY; + schedparam.sched_ss_low_priority = LOW_PRIORITY; puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" ); status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); rtems_test_assert( !status ); - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); - - priority = schedparam.sched_priority; - sprintf( buffer, " - new priority = %d", priority ); + sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) ); print_current_time( "Init: ", buffer ); /* go into a loop consuming CPU time to watch our priority change */ for ( passes=0 ; passes <= 3 ; ) { - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); + int current_priority; - if ( priority != schedparam.sched_priority ) { - priority = schedparam.sched_priority; + current_priority = get_current_prio( pthread_self() ); + + if ( priority != current_priority ) { + priority = current_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); passes++; @@ -175,10 +165,6 @@ void *POSIX_Init( schedparam.sched_ss_init_budget.tv_sec = 0; 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_ss_low_priority = LOW_PRIORITY; @@ -190,7 +176,10 @@ void *POSIX_Init( status = pthread_mutexattr_init( &attr ); 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 ); puts( "Init: Creating a mutex" ); @@ -199,11 +188,7 @@ void *POSIX_Init( printf( "status = %d\n", status ); rtems_test_assert( !status ); - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); - - priority = schedparam.sched_priority; - sprintf( buffer, " - new priority = %d", priority ); + sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) ); print_current_time( "Init: ", buffer ); /* 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) ); rtems_test_assert( !status ); - for ( ; ; ) { - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); + do { + priority = get_current_prio( pthread_self() ); - if ( schedparam.sched_priority == LOW_PRIORITY ) { + if ( priority != CEILING_PRIORITY ) { puts( "ERROR - Init's priority lowered while holding mutex" ); rtems_test_exit(0); } now = time( &now ); - if ( 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; - } + } while ( now - start < 3 ); /* with this unlock we should be able to go to low priority */ @@ -251,26 +220,15 @@ void *POSIX_Init( printf( "status = %d\n", status ); rtems_test_assert( !status ); - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); - - priority = schedparam.sched_priority; - sprintf( buffer, " - new priority = %d", priority ); + sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) ); print_current_time( "Init: ", buffer ); for ( ; ; ) { - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); - - if ( schedparam.sched_priority == LOW_PRIORITY ) + if ( get_current_prio( pthread_self() ) == LOW_PRIORITY ) break; } - status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); - rtems_test_assert( !status ); - - priority = schedparam.sched_priority; - sprintf( buffer, " - new priority = %d", priority ); + sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) ); print_current_time( "Init: ", buffer ); TEST_END(); |