summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-08-12 15:54:46 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-08-18 07:28:00 +0200
commit5d1fc66ce7b1afccb2537a7acb34ae7eace97f74 (patch)
tree3bec3ad97f00b73402e7ef522892c3a9eb601c23
parentscore: Fix undefined behaviour (diff)
downloadrtems-5d1fc66ce7b1afccb2537a7acb34ae7eace97f74.tar.bz2
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.
-rw-r--r--testsuites/psxtests/psx09/init.c120
-rw-r--r--testsuites/psxtests/psx09/psx09.scn18
-rw-r--r--testsuites/psxtests/psx12/init.c25
3 files changed, 64 insertions, 99 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();
diff --git a/testsuites/psxtests/psx09/psx09.scn b/testsuites/psxtests/psx09/psx09.scn
index c3e6dadc71..766fd0f27d 100644
--- a/testsuites/psxtests/psx09/psx09.scn
+++ b/testsuites/psxtests/psx09/psx09.scn
@@ -1,22 +1,20 @@
-*** POSIX TEST 9 ***
+*** BEGIN OF TEST PSX 9 ***
Init's ID is 0x0b010001
Init: pthread_getschedparam - SUCCESSFUL
Init: Fri May 24 11:05:00 1996 - current priority = 2
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 = 254
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: Initializing mutex attributes for priority ceiling
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: 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: Fri May 24 11:05:01 1996 - new priority = 254
-Init: Fri May 24 11:05:01 1996 - new priority = 250
-*** END OF POSIX TEST 9 ***
+Init: Fri May 24 11:05:03 1996 - new priority = 253
+Init: Fri May 24 11:05:03 1996 - new priority = 252
+*** END OF TEST PSX 9 **
diff --git a/testsuites/psxtests/psx12/init.c b/testsuites/psxtests/psx12/init.c
index d7218933ee..46fb0161b7 100644
--- a/testsuites/psxtests/psx12/init.c
+++ b/testsuites/psxtests/psx12/init.c
@@ -44,16 +44,25 @@ typedef struct {
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 )
{
- int status;
- int policy;
- struct sched_param param;
-
- do {
- status = pthread_getschedparam( pthread_self(), &policy, &param );
- rtems_test_assert( status == 0 );
- } while ( prio != param.sched_priority );
+ while ( prio != get_current_prio( pthread_self() ) ) {
+ /* Wait */
+ }
}
static uint64_t timeval_to_us( const struct timeval *tv )