[PATCH 1/3] posix: Simplify POSIX_API_Control

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Oct 9 13:55:04 UTC 2017


Return stack area via pthread_getattr_np().

Simplify

* pthread_attr_setaffinity_np(), and
* pthread_attr_getaffinity_np()

and let the scheduler do the more sophisticated error checks.

Make

* pthread_setaffinity_np(),
* pthread_getaffinity_np(),
* pthread_attr_setaffinity_np(), and
* pthread_attr_getaffinity_np()

available in all configurations.

Update #2514.
Close #3145.
Close #3168.
---
 cpukit/posix/Makefile.am                           | 12 ++---
 cpukit/posix/include/rtems/posix/pthreadimpl.h     |  4 +-
 cpukit/posix/include/rtems/posix/threadsup.h       | 10 +++-
 cpukit/posix/preinstall.am                         |  2 -
 cpukit/posix/src/pthread.c                         | 13 +++---
 cpukit/posix/src/pthreadattrcompare.c              |  5 +-
 cpukit/posix/src/pthreadattrgetaffinitynp.c        | 14 ++----
 cpukit/posix/src/pthreadattrsetaffinitynp.c        | 16 ++-----
 cpukit/posix/src/pthreadcreate.c                   |  5 +-
 cpukit/posix/src/pthreadgetaffinitynp.c            |  2 -
 cpukit/posix/src/pthreadgetattrnp.c                | 31 ++++++++++++-
 cpukit/posix/src/pthreadgetschedparam.c            |  4 +-
 cpukit/posix/src/pthreadsetaffinitynp.c            |  9 ----
 cpukit/posix/src/pthreadsetschedparam.c            |  4 +-
 testsuites/psxtests/psxgetattrnp01/init.c          | 33 ++++++++++++++
 .../psxtests/psxgetattrnp01/psxgetattrnp01.scn     |  9 +++-
 testsuites/smptests/smppsxaffinity01/init.c        | 53 ++++++++++++----------
 .../smptests/smppsxaffinity01/smppsxaffinity01.scn | 16 +++----
 18 files changed, 151 insertions(+), 91 deletions(-)

diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index a4ce099752..627030bcb4 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -89,6 +89,11 @@ libposix_a_SOURCES += src/mutexattrdestroy.c src/mutexattrgetprioceiling.c \
     src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
     src/mutextrylock.c src/mutexunlock.c
 
+## PTHREAD_AFFINITY_C_FILES
+libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
+    src/pthreadattrgetaffinitynp.c  src/pthreadgetaffinitynp.c   \
+    src/pthreadsetaffinitynp.c
+
 if HAS_PTHREADS
 libposix_a_SOURCES +=  src/pthreadatfork.c
 
@@ -148,13 +153,6 @@ libposix_a_SOURCES += src/pthreadsetschedprio.c
 ## RTEMS specific support methods
 libposix_a_SOURCES += src/pthreadattrcompare.c
 
-if HAS_SMP
-## PTHREAD_AFFINITY_C_FILES
-libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
-    src/pthreadattrgetaffinitynp.c  src/pthreadgetaffinitynp.c   \
-    src/pthreadsetaffinitynp.c
-endif
-
 ## PSIGNAL_C_FILES
 libposix_a_SOURCES += src/psignal.c src/alarm.c src/kill.c src/killinfo.c \
     src/kill_r.c src/pause.c src/psignalclearprocesssignals.c \
diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index 90a60b6c4d..290fbad02e 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -59,12 +59,12 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
 )
 {
   the_thread->cpu_time_budget =
-    _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget );
+    _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
 
   _Watchdog_Per_CPU_insert_relative(
     &api->Sporadic.Timer,
     _Per_CPU_Get(),
-    _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period )
+    _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
   );
 }
 
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index 3bb2210d97..cc250f7464 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -43,8 +43,14 @@ typedef struct {
   /** Back pointer to thread of this POSIX API control. */
   Thread_Control         *thread;
 
-  /** This is the POSIX threads attribute set. */
-  pthread_attr_t          Attributes;
+  /** Created with explicit or inherited scheduler. */
+  bool created_with_explicit_scheduler;
+
+  /** The scheduler policy. */
+  int schedpolicy;
+
+  /** The scheduler parameters */
+  struct sched_param schedparam;
 
   /**
    * @brief Control block for the sporadic server scheduling policy.
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
index c3ce5e5aa9..157be567c2 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -140,5 +140,3 @@ $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h: include/rtems/posix/timerimpl.h $(PR
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
 endif
-if HAS_PTHREADS
-endif
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index edbfa13121..1d791df7eb 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -75,9 +75,11 @@ pthread_attr_t _POSIX_Threads_Default_attributes = {
     .cputime_clock_allowed = 1,                        /* cputime_clock_allowed */
   #endif
   .detachstate             = PTHREAD_CREATE_JOINABLE,    /* detachstate */
-  .affinitysetsize         = 0,
-  .affinityset             = NULL,
-  .affinitysetpreallocated = {{0x0}}
+  .affinitysetsize         =
+    sizeof( _POSIX_Threads_Default_attributes.affinitysetpreallocated ),
+  .affinityset             =
+    &_POSIX_Threads_Default_attributes.affinitysetpreallocated,
+  .affinitysetpreallocated = {{0x1}}
 };
 
 void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
@@ -166,8 +168,7 @@ static bool _POSIX_Threads_Create_extension(
 
   /* XXX check all fields are touched */
   api->thread = created;
-  _POSIX_Threads_Initialize_attributes( &api->Attributes );
-  api->Attributes.schedparam.sched_priority = _POSIX_Priority_From_core(
+  api->schedparam.sched_priority = _POSIX_Priority_From_core(
     _Thread_Scheduler_get_home( created ),
     _Thread_Get_priority( created )
   );
@@ -203,7 +204,7 @@ static void _POSIX_Threads_Terminate_extension( Thread_Control *executing )
 
   _Thread_State_acquire( executing, &lock_context );
 
-  if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) {
+  if ( api->schedpolicy == SCHED_SPORADIC ) {
     _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer );
   }
 
diff --git a/cpukit/posix/src/pthreadattrcompare.c b/cpukit/posix/src/pthreadattrcompare.c
index 6a3b625be1..26ab28db33 100644
--- a/cpukit/posix/src/pthreadattrcompare.c
+++ b/cpukit/posix/src/pthreadattrcompare.c
@@ -32,7 +32,10 @@ int rtems_pthread_attribute_compare(
   if ( attr1->is_initialized  !=  attr2->is_initialized )
     return 1;
 
-  if ( attr1->stackaddr != attr2->stackaddr )
+  if (
+    attr1->stackaddr != NULL &&
+      attr2->stackaddr != NULL &&
+      attr1->stackaddr != attr2->stackaddr )
     return 1;
 
   if ( attr1->stacksize != attr2->stacksize )
diff --git a/cpukit/posix/src/pthreadattrgetaffinitynp.c b/cpukit/posix/src/pthreadattrgetaffinitynp.c
index 6ed50507be..b281b11e5f 100644
--- a/cpukit/posix/src/pthreadattrgetaffinitynp.c
+++ b/cpukit/posix/src/pthreadattrgetaffinitynp.c
@@ -24,23 +24,19 @@
 #include <pthread.h>
 #include <errno.h>
 
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
-#include <rtems/score/threadimpl.h>
-
 int pthread_attr_getaffinity_np(
   const pthread_attr_t *attr,
   size_t                cpusetsize,
   cpu_set_t            *cpuset
 )
 {
-  if ( !cpuset )
-    return EFAULT;
-  if ( !attr )
-    return EFAULT;
+  if ( attr == NULL || !attr->is_initialized ) {
+    return EINVAL;
+  }
 
-  if ( cpusetsize != attr->affinitysetsize)
+  if ( cpuset == NULL || cpusetsize != attr->affinitysetsize ) {
     return EINVAL;
+  }
 
   CPU_COPY( attr->affinityset, cpuset );
   return 0;
diff --git a/cpukit/posix/src/pthreadattrsetaffinitynp.c b/cpukit/posix/src/pthreadattrsetaffinitynp.c
index e5462ec5c4..0e3c828c38 100644
--- a/cpukit/posix/src/pthreadattrsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadattrsetaffinitynp.c
@@ -24,27 +24,21 @@
 #include <pthread.h>
 #include <errno.h>
 
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
-#include <rtems/score/threadimpl.h>
-#include <rtems/score/cpusetimpl.h>
-
 int pthread_attr_setaffinity_np(
   pthread_attr_t    *attr,
   size_t             cpusetsize,
   const cpu_set_t   *cpuset
 )
 {
-  if ( !cpuset )
-    return EFAULT;
-  if ( !attr )
-    return EFAULT;
+  if ( attr == NULL || !attr->is_initialized ) {
+    return EINVAL;
+  }
 
-  if (! _CPU_set_Is_valid( cpuset, cpusetsize ) )
+  if ( cpuset == NULL || cpusetsize != attr->affinitysetsize ) {
     return EINVAL;
+  }
 
   CPU_COPY( cpuset, attr->affinityset );
-
   return 0;
 }
 
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 5c5ea5f4de..ebb96bf8a4 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -242,7 +242,10 @@ int pthread_create(
    */
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
 
-  _POSIX_Threads_Copy_attributes( &api->Attributes, the_attr );
+  api->created_with_explicit_scheduler =
+    ( the_attr->inheritsched == PTHREAD_EXPLICIT_SCHED );
+  api->schedpolicy = the_attr->schedpolicy;
+  api->schedparam = the_attr->schedparam;
   _Priority_Node_initialize( &api->Sporadic.Low_priority, core_low_prio );
   _Priority_Node_set_inactive( &api->Sporadic.Low_priority );
 
diff --git a/cpukit/posix/src/pthreadgetaffinitynp.c b/cpukit/posix/src/pthreadgetaffinitynp.c
index b843f931d4..dab6b63aa0 100644
--- a/cpukit/posix/src/pthreadgetaffinitynp.c
+++ b/cpukit/posix/src/pthreadgetaffinitynp.c
@@ -25,8 +25,6 @@
 #include <pthread.h>
 #include <errno.h>
 
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/schedulerimpl.h>
 
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
index 63de97be4b..d815fc8c53 100644
--- a/cpukit/posix/src/pthreadgetattrnp.c
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -21,8 +21,10 @@
 #define  _GNU_SOURCE
 #include <pthread.h>
 #include <errno.h>
+#include <string.h>
 
 #include <rtems/posix/pthreadimpl.h>
+#include <rtems/score/schedulerimpl.h>
 #include <rtems/score/threadimpl.h>
 
 int pthread_getattr_np(
@@ -33,11 +35,14 @@ int pthread_getattr_np(
   Thread_Control    *the_thread;
   ISR_lock_Context   lock_context;
   POSIX_API_Control *api;
+  bool               ok;
 
   if ( attr == NULL ) {
     return EINVAL;
   }
 
+  attr = memset( attr, 0, sizeof( *attr ) );
+
   the_thread = _Thread_Get( thread, &lock_context );
 
   if ( the_thread == NULL ) {
@@ -47,7 +52,21 @@ int pthread_getattr_np(
   _Thread_State_acquire_critical( the_thread, &lock_context );
 
   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
-  _POSIX_Threads_Copy_attributes( attr, &api->Attributes);
+
+  attr->is_initialized = true;
+  attr->stackaddr = the_thread->Start.Initial_stack.area;
+  attr->stacksize = the_thread->Start.Initial_stack.size;
+  attr->contentionscope = PTHREAD_SCOPE_PROCESS;
+
+  if ( api->created_with_explicit_scheduler ) {
+    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
+  } else {
+    attr->inheritsched = PTHREAD_INHERIT_SCHED;
+  }
+
+  attr->schedpolicy = api->schedpolicy;
+  attr->schedparam = api->schedparam;
+  attr->cputime_clock_allowed = 1;
 
   if ( _Thread_Is_joinable( the_thread ) ) {
     attr->detachstate = PTHREAD_CREATE_JOINABLE;
@@ -55,6 +74,14 @@ int pthread_getattr_np(
     attr->detachstate = PTHREAD_CREATE_DETACHED;
   }
 
+  attr->affinityset = &attr->affinitysetpreallocated;
+  attr->affinitysetsize = sizeof( attr->affinitysetpreallocated );
+  ok = _Scheduler_Get_affinity(
+    the_thread,
+    attr->affinitysetsize,
+    attr->affinityset
+  );
+
   _Thread_State_release( the_thread, &lock_context );
-  return 0;
+  return ok ? 0 : EINVAL;
 }
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
index b809db95dc..f172caecd4 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -56,8 +56,8 @@ int pthread_getschedparam(
 
   _Thread_Wait_acquire_critical( the_thread, &queue_context );
 
-  *policy = api->Attributes.schedpolicy;
-  *param  = api->Attributes.schedparam;
+  *policy = api->schedpolicy;
+  *param  = api->schedparam;
 
   scheduler = _Thread_Scheduler_get_home( the_thread );
   priority = the_thread->Real_priority.priority;
diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c
index 4ce51ec9ea..c504de5cd7 100644
--- a/cpukit/posix/src/pthreadsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadsetaffinitynp.c
@@ -24,8 +24,6 @@
 #include <pthread.h>
 #include <errno.h>
 
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/cpusetimpl.h>
 #include <rtems/score/schedulerimpl.h>
@@ -60,13 +58,6 @@ int pthread_setaffinity_np(
     cpuset
   );
 
-  if ( ok ) {
-    POSIX_API_Control *api;
-
-    api = the_thread->API_Extensions[ THREAD_API_POSIX ];
-    CPU_COPY( cpuset, api->Attributes.affinityset );
-  }
-
   _Thread_State_release( the_thread, &lock_context );
   _Thread_Dispatch_enable( cpu_self );
   return ok ? 0 : EINVAL;
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 4da2ebf2a8..5d33f1d095 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -94,8 +94,8 @@ static int _POSIX_Set_sched_param(
     );
   }
 
-  api->Attributes.schedpolicy = policy;
-  api->Attributes.schedparam  = *param;
+  api->schedpolicy = policy;
+  api->schedparam  = *param;
 
   the_thread->budget_algorithm = budget_algorithm;
   the_thread->budget_callout   = budget_callout;
diff --git a/testsuites/psxtests/psxgetattrnp01/init.c b/testsuites/psxtests/psxgetattrnp01/init.c
index df3e33541d..190e4f498e 100644
--- a/testsuites/psxtests/psxgetattrnp01/init.c
+++ b/testsuites/psxtests/psxgetattrnp01/init.c
@@ -41,6 +41,9 @@ void *Thread_1(
   struct sched_param  param;
   int                 sc;
   int                 value;
+  void               *stackaddr;
+  size_t              stacksize;
+  cpu_set_t           set;
 
   puts("Thread - pthread_getattr_np - Verify value");
   sc = pthread_getattr_np( Thread_id, &attr );
@@ -61,6 +64,24 @@ void *Thread_1(
   sc = pthread_getattr_np( Thread_id, &attr );
   rtems_test_assert( !sc );
 
+  puts("Thread - Verify get stack");
+  stackaddr = NULL;
+  stacksize = 0;
+  sc = pthread_attr_getstack( &attr, &stackaddr, &stacksize );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( stackaddr != NULL );
+  rtems_test_assert( stacksize != 0 );
+
+  puts("Thread - Verify contention scope");
+  sc = pthread_attr_getscope( &attr, &value );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( value == PTHREAD_SCOPE_PROCESS );
+
+  puts("Thread - Verify explicit scheduler");
+  sc = pthread_attr_getinheritsched( &attr, &value );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( value == PTHREAD_EXPLICIT_SCHED );
+
   puts("Thread - Verify SCHED_FIFO policy");
   sc = pthread_attr_getschedpolicy( &attr, &value );
   rtems_test_assert( !sc );
@@ -73,8 +94,20 @@ void *Thread_1(
 
   puts("Thread - Verify detached");
   sc = pthread_attr_getdetachstate( &attr, &value );
+  rtems_test_assert( sc == 0 );
   rtems_test_assert( value == PTHREAD_CREATE_DETACHED );
 
+  puts("Thread - Verify affinity");
+  CPU_ZERO( &set );
+  sc = pthread_attr_getaffinity_np( &attr, sizeof( set ), &set );
+  rtems_test_assert( sc == 0 );
+  rtems_test_assert( CPU_ISSET( 0, &set ) );
+  rtems_test_assert( !CPU_ISSET( 1, &set ) );
+
+  puts("Thread - Destroy");
+  sc = pthread_attr_destroy( &attr );
+  rtems_test_assert( sc == 0 );
+
   return NULL; /* just so the compiler thinks we returned something */
 }
 
diff --git a/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
index a3572e048c..ab09630f75 100644
--- a/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
+++ b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
@@ -1,4 +1,4 @@
-*** POSIX ATTRIBUTE TEST 1 ***
+*** BEGIN OF TEST PSXGETATTRNP 1 ***
 Init - pthread_getattr_np - attr NULL - EINVAL
 Init - pthread_getattr_np - invalid id - ESRCH
 Init - pthread_attr_init
@@ -16,7 +16,12 @@ Thread - pthread_getattr_np - Verify value
 Thread - pthread_setschedparam: Setting highest priority SCHED_FIFO
 Thread - Detach
 Thread - pthread_getattr_np
+Thread - Verify get stack
+Thread - Verify contention scope
+Thread - Verify explicit scheduler
 Thread - Verify SCHED_FIFO policy
 Thread - Verify max priority
 Thread - Verify detached
-*** END OF POSIX ATTRIBUTE TEST 1 ***
+Thread - Verify affinity
+Thread - Destroy
+*** END OF TEST PSXGETATTRNP 1 ***
diff --git a/testsuites/smptests/smppsxaffinity01/init.c b/testsuites/smptests/smppsxaffinity01/init.c
index c4c4f4f7c3..58e1db5435 100644
--- a/testsuites/smptests/smppsxaffinity01/init.c
+++ b/testsuites/smptests/smppsxaffinity01/init.c
@@ -38,21 +38,30 @@ void Validate_attrgetaffinity_errors(void)
   cpu_set_t           cpuset;
   pthread_attr_t      attr;
 
+  sc = pthread_attr_init( &attr );
+  rtems_test_assert( sc == 0 );
+
   /* Verify pthread_attr_getaffinity_np validates attr  */
-  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT" );
-  sc = pthread_attr_getaffinity_np( NULL, sizeof(cpu_set_t), &cpuset );
-  rtems_test_assert( sc == EFAULT );
+  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
+  sc = pthread_attr_getaffinity_np( NULL, sizeof( cpuset ), &cpuset );
+  rtems_test_assert( sc == EINVAL );
 
   /* Verify pthread_attr_getaffinity_np validates cpuset */
-  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT" );
-  sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t), NULL );
-  rtems_test_assert( sc == EFAULT );
+  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
+  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), NULL );
+  rtems_test_assert( sc == EINVAL );
 
   /* Verify pthread_attr_getaffinity_np validates cpusetsize */
   puts( "Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL" );
-  sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t) * 2 , &cpuset );
+  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
   rtems_test_assert( sc == EINVAL );
 
+  sc = pthread_attr_destroy( &attr );
+  rtems_test_assert( sc == 0 );
+
+  puts( "Init - pthread_attr_getaffinity_np - Not initialized attr - EINVAL" );
+  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), &cpuset );
+  rtems_test_assert( sc == EINVAL );
 }
 
 void Validate_attrsetaffinity_errors(void)
@@ -61,31 +70,29 @@ void Validate_attrsetaffinity_errors(void)
   cpu_set_t           cpuset;
   pthread_attr_t      attr;
 
+  sc = pthread_attr_init( &attr );
+  rtems_test_assert( sc == 0 );
+
   /* Verify pthread_attr_setaffinity_np validates attr.  */
-  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT" );
-  sc = pthread_attr_setaffinity_np( NULL, sizeof(cpu_set_t), &cpuset );
-  rtems_test_assert( sc == EFAULT );
+  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
+  sc = pthread_attr_setaffinity_np( NULL, sizeof( cpuset ), &cpuset );
+  rtems_test_assert( sc == EINVAL );
 
   /* Verify pthread_attr_setaffinity_np validates cpuset    */
-  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT" );
-  sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t), NULL );
-  rtems_test_assert( sc == EFAULT );
+  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
+  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), NULL );
+  rtems_test_assert( sc == EINVAL );
 
   /* Verify pthread_attr_setaffinity_np validates cpusetsize */
   puts( "Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL" );
-  sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) * 2 , &cpuset );
+  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
   rtems_test_assert( sc == EINVAL );
 
-  /* Verify pthread_attr_setaffinity_np validates cpuset greater than 0  */
-  CPU_ZERO(&cpuset);
-  puts( "Init - pthread_attr_setaffinity_np - No cpus in cpuset - EINVAL" );
-  sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) , &cpuset );
-  rtems_test_assert( sc == EINVAL );
+  sc = pthread_attr_destroy( &attr );
+  rtems_test_assert( sc == 0 );
 
-  /* Verify pthread_attr_setaffinity_np validates invalid cpu in cpuset */
-  CPU_FILL(&cpuset);
-  puts( "Init - pthread_attr_setaffinity_np - Too many cpus in cpuset - EINVAL" );
-  sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) , &cpuset );
+  puts( "Init - pthread_attr_setaffinity_np - Not initialized attr - EINVAL" );
+  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), &cpuset  );
   rtems_test_assert( sc == EINVAL );
 }
 
diff --git a/testsuites/smptests/smppsxaffinity01/smppsxaffinity01.scn b/testsuites/smptests/smppsxaffinity01/smppsxaffinity01.scn
index 70bd6d31c8..15459e0c2c 100644
--- a/testsuites/smptests/smppsxaffinity01/smppsxaffinity01.scn
+++ b/testsuites/smptests/smppsxaffinity01/smppsxaffinity01.scn
@@ -1,11 +1,11 @@
-*** SMP POSIX AFFINITY ATTRIBUTE TEST 1 ***
-Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT
-Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT
+*** BEGIN OF TEST SMPPSXAFFINITY 1 ***
+Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL
+Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL
 Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL
-Init - pthread_attr_setaffinity_np - No cpus in cpuset - EINVAL
-Init - pthread_attr_setaffinity_np - Too many cpus in cpuset - EINVAL
-Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT
-Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT
+Init - pthread_attr_setaffinity_np - Not initialized attr - EINVAL
+Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL
+Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL
 Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL
+Init - pthread_attr_getaffinity_np - Not initialized attr - EINVAL
 Init - Validate pthread_attr_setaffinity_np and pthread_attr_getaffinity_np
-*** END OF SMP POSIX AFFINITY ATTRIBUTE TEST 1 ***
+*** END OF TEST SMPPSXAFFINITY 1 ***
-- 
2.12.3



More information about the devel mailing list