summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psx09
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1996-08-07 21:27:25 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1996-08-07 21:27:25 +0000
commit7e811af1eb23008c83427f6f3b5379741a23b1c0 (patch)
treece17f09d61a1c67a7c0b7df8f015ac5c0db83380 /testsuites/psxtests/psx09
parent_POSIX_Mutex_From_core_mutex_status: added priority ceiling violation case (diff)
downloadrtems-7e811af1eb23008c83427f6f3b5379741a23b1c0.tar.bz2
basic sporadic server test.
sporadic server with priority ceiling mutex test.
Diffstat (limited to 'testsuites/psxtests/psx09')
-rw-r--r--testsuites/psxtests/psx09/init.c227
-rw-r--r--testsuites/psxtests/psx09/psx09.scn0
-rw-r--r--testsuites/psxtests/psx09/system.h58
3 files changed, 285 insertions, 0 deletions
diff --git a/testsuites/psxtests/psx09/init.c b/testsuites/psxtests/psx09/init.c
new file mode 100644
index 0000000000..e7047b55c9
--- /dev/null
+++ b/testsuites/psxtests/psx09/init.c
@@ -0,0 +1,227 @@
+/*
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
+ * On-Line Applications Research Corporation (OAR).
+ * All rights assigned to U.S. Government, 1994.
+ *
+ * This material may be reproduced by or for the U.S. Government pursuant
+ * to the copyright license under the clause at DFARS 252.227-7013. This
+ * notice must appear in all copies of this file and its derivatives.
+ *
+ * $Id$
+ */
+
+#define CONFIGURE_INIT
+#include "system.h"
+#include <errno.h>
+
+void print_schedparam(
+ char *prefix,
+ struct sched_param *schedparam
+)
+{
+ printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority );
+#if defined(_POSIX_SPORADIC_SERVER)
+ printf( "%sss_low_priority = %d\n", prefix, schedparam->ss_low_priority );
+ printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
+ schedparam->ss_replenish_period.tv_sec,
+ schedparam->ss_replenish_period.tv_nsec );
+ printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
+ schedparam->ss_initial_budget.tv_sec,
+ schedparam->ss_initial_budget.tv_nsec );
+#else
+ printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
+#endif
+}
+
+void *POSIX_Init(
+ void *argument
+)
+{
+ int status;
+ int schedpolicy;
+ int priority;
+ struct sched_param schedparam;
+ char buffer[ 80 ];
+ pthread_mutexattr_t attr;
+
+ puts( "\n\n*** POSIX TEST 9 ***" );
+
+ /* set the time of day, and print our buffer in multiple ways */
+
+ set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
+
+ /* get id of this thread */
+
+ Init_id = pthread_self();
+ printf( "Init's ID is 0x%08x\n", Init_id );
+
+#if 0
+ /* try to use this thread as a sporadic server */
+
+ puts( "Init: pthread_getschedparam - SUCCESSFUL" );
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - current priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ schedparam.ss_replenish_period.tv_sec = 0;
+ schedparam.ss_replenish_period.tv_nsec = 500000000; /* 1/2 second */
+ schedparam.ss_initial_budget.tv_sec = 0;
+ schedparam.ss_initial_budget.tv_nsec = 250000000; /* 1/4 second */
+
+ schedparam.sched_priority = 200;
+ schedparam.ss_low_priority = 100;
+
+ puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
+ status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
+ assert( !status );
+
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ 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 );
+ assert( !status );
+
+ if ( priority != schedparam.sched_priority ) {
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+ passes++;
+ }
+ }
+
+#endif
+ /* now see if this works if we are holding a priority ceiling mutex */
+
+ empty_line();
+
+
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ schedparam.ss_replenish_period.tv_sec = 0;
+ schedparam.ss_replenish_period.tv_nsec = 500000000; /* 1/2 second */
+ schedparam.ss_initial_budget.tv_sec = 0;
+ schedparam.ss_initial_budget.tv_nsec = 250000000; /* 1/4 second */
+
+#define HIGH_PRIORITY 150
+#define MEDIUM_PRIORITY 131
+#define LOW_PRIORITY 100
+
+ schedparam.sched_priority = HIGH_PRIORITY;
+ schedparam.ss_low_priority = LOW_PRIORITY;
+
+ puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
+ status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
+ assert( !status );
+
+ puts( "Init: Initializing mutex attributes for priority ceiling" );
+ status = pthread_mutexattr_init( &attr );
+ assert( !status );
+
+ status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
+ assert( !status );
+
+ status = pthread_mutexattr_setprioceiling( &attr, MEDIUM_PRIORITY );
+ assert( !status );
+
+ puts( "Init: Creating a mutex" );
+ status = pthread_mutex_init( &Mutex_id, &attr );
+ if ( status )
+ printf( "status = %d\n", status );
+ assert( !status );
+
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ /* go into a loop consuming CPU time to watch our priority lower */
+
+ for ( ; ; ) {
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ if ( schedparam.sched_priority != LOW_PRIORITY )
+ continue;
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ puts( "Init: pthread_mutex_lock acquire the lock" );
+ status = pthread_mutex_lock( &Mutex_id );
+ if ( status )
+ printf( "status = %d\n", status );
+ assert( !status );
+
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ break;
+ }
+
+ /* now spin waiting for our budget to be replenished */
+
+ for ( ; ; ) {
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ if ( schedparam.sched_priority == HIGH_PRIORITY )
+ break;
+ }
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ /* with this unlock we should be able to go to low priority */
+
+ puts( "Init: unlock mutex" );
+ status = pthread_mutex_unlock( &Mutex_id );
+ if ( status )
+ printf( "status = %d\n", status );
+ assert( !status );
+
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ for ( ; ; ) {
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ if ( schedparam.sched_priority == LOW_PRIORITY )
+ break;
+ }
+
+ status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
+ assert( !status );
+
+ priority = schedparam.sched_priority;
+ sprintf( buffer, " - new priority = %d", priority );
+ print_current_time( "Init: ", buffer );
+
+ puts( "*** END OF POSIX TEST 9 ***" );
+ exit( 0 );
+
+ return NULL; /* just so the compiler thinks we returned something */
+}
diff --git a/testsuites/psxtests/psx09/psx09.scn b/testsuites/psxtests/psx09/psx09.scn
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuites/psxtests/psx09/psx09.scn
diff --git a/testsuites/psxtests/psx09/system.h b/testsuites/psxtests/psx09/system.h
new file mode 100644
index 0000000000..125a3516a0
--- /dev/null
+++ b/testsuites/psxtests/psx09/system.h
@@ -0,0 +1,58 @@
+/* system.h
+ *
+ * This include file contains information that is included in every
+ * function in the test set.
+ *
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
+ * On-Line Applications Research Corporation (OAR).
+ * All rights assigned to U.S. Government, 1994.
+ *
+ * This material may be reproduced by or for the U.S. Government pursuant
+ * to the copyright license under the clause at DFARS 252.227-7013. This
+ * notice must appear in all copies of this file and its derivatives.
+ *
+ * $Id$
+ */
+
+/* functions */
+
+#include <pmacros.h>
+
+void *POSIX_Init(
+ void *argument
+);
+
+void *Task_1(
+ void *argument
+);
+
+void *Task_2(
+ void *argument
+);
+
+/* configuration information */
+
+#define CONFIGURE_SPTEST
+
+#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_MAXIMUM_POSIX_KEYS 10
+#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10
+
+#include <confdefs.h>
+
+/* global variables */
+
+#ifdef CONFIGURE_INIT
+#define TEST_EXTERN
+#else
+#define TEST_EXTERN extern
+#endif
+
+TEST_EXTERN pthread_t Init_id;
+TEST_EXTERN pthread_mutex_t Mutex_id;
+
+/* end of include file */