Attached is the modified pthread get attribute
patch and its corresponding test.
Jennifer Averett
On-Line Applications Research
From 4f74ebdf993f09993355df27a2fab784997a8733 Mon Sep 17 00:00:00 2001
From: Jennifer Averett <jennifer.aver...@oarcorp.com>
Date: Tue, 14 Jan 2014 09:43:14 -0600
Subject: [PATCH 05/15] posix: Add pthread_getattr_np().
---
cpukit/posix/Makefile.am | 1 +
cpukit/posix/src/pthreadgetattrnp.c | 41 +++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
create mode 100644 cpukit/posix/src/pthreadgetattrnp.c
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index ea6d3d9..0e81abc 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -130,6 +130,7 @@ libposix_a_SOURCES += src/pthreadatfork.c src/pthreadattrdestroy.c \
src/pthreadattrsetschedparam.c src/pthreadattrsetschedpolicy.c \
src/pthreadattrsetscope.c src/pthreadattrsetstackaddr.c \
src/pthreadattrsetstack.c src/pthreadattrsetstacksize.c \
+ src/pthreadgetattrnp.c \
src/pthreadattrgetguardsize.c src/pthread.c \
src/pthreadcreate.c src/pthreaddetach.c src/pthreadequal.c \
src/pthreadexit.c src/pthreadgetcpuclockid.c \
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
new file mode 100644
index 0000000..b9a66ec
--- /dev/null
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -0,0 +1,41 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _GNU_SOURCE
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/posix/pthreadimpl.h>
+#include <rtems/score/threadimpl.h>
+
+int pthread_getattr_np(
+ pthread_t id,
+ pthread_attr_t *attr
+)
+{
+ Objects_Locations location;
+ POSIX_API_Control *api;
+ Thread_Control *the_thread;
+
+ if ( !attr )
+ return EINVAL;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+ _POSIX_Threads_Copy_attributes( attr, &api->Attributes);
+ _Objects_Put( &the_thread->Object );
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return ESRCH;
+}
--
1.8.1.4
From ef005266b44e5efe745c178768f68e19094ab16d Mon Sep 17 00:00:00 2001
From: Jennifer Averett <jennifer.aver...@oarcorp.com>
Date: Tue, 14 Jan 2014 12:45:49 -0600
Subject: [PATCH 06/15] psxtests: Added test for pthread_getattr_np.
---
testsuites/psxtests/Makefile.am | 2 +-
testsuites/psxtests/configure.ac | 1 +
testsuites/psxtests/psxgetattrnp01/Makefile.am | 23 +++
testsuites/psxtests/psxgetattrnp01/init.c | 191 +++++++++++++++++++++
.../psxtests/psxgetattrnp01/psxgetattrnp01.doc | 23 +++
.../psxtests/psxgetattrnp01/psxgetattrnp01.scn | 22 +++
6 files changed, 261 insertions(+), 1 deletion(-)
create mode 100644 testsuites/psxtests/psxgetattrnp01/Makefile.am
create mode 100644 testsuites/psxtests/psxgetattrnp01/init.c
create mode 100644 testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.doc
create mode 100644 testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 423cf07..0d457ea 100644
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -15,7 +15,7 @@ SUBDIRS += psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 psx09 \
psxspin01 psxspin02 psxsysconf \
psxtime psxtimer01 psxtimer02 psxualarm psxusleep psxfatal01 psxfatal02 \
psxintrcritical01 psxstack01 psxstack02 \
- psxeintr_join
+ psxeintr_join psxgetattrnp01
endif
## File IO tests
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 3320b1c..a7b3312 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -143,6 +143,7 @@ psxfchx01/Makefile
psxfile01/Makefile
psxfile02/Makefile
psxfilelock01/Makefile
+psxgetattrnp01/Makefile
psxgetrusage01/Makefile
psxhdrs/Makefile
psxid01/Makefile
diff --git a/testsuites/psxtests/psxgetattrnp01/Makefile.am b/testsuites/psxtests/psxgetattrnp01/Makefile.am
new file mode 100644
index 0000000..82569d8
--- /dev/null
+++ b/testsuites/psxtests/psxgetattrnp01/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxgetattrnp01
+psxgetattrnp01_SOURCES = init.c
+
+dist_rtems_tests_DATA = psxgetattrnp01.scn
+dist_rtems_tests_DATA += psxgetattrnp01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxgetattrnp01_OBJECTS)
+LINK_LIBS = $(psxgetattrnp01_LDLIBS)
+
+psxgetattrnp01$(EXEEXT): $(psxgetattrnp01_OBJECTS) $(psxgetattrnp01_DEPENDENCIES)
+ @rm -f psxgetattrnp01$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxgetattrnp01/init.c b/testsuites/psxtests/psxgetattrnp01/init.c
new file mode 100644
index 0000000..df9bff2
--- /dev/null
+++ b/testsuites/psxtests/psxgetattrnp01/init.c
@@ -0,0 +1,191 @@
+/*
+ * COPYRIGHT (c) 1989-2014.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _GNU_SOURCE
+#include <tmacros.h>
+#include <errno.h>
+#include <sched.h>
+#include <pthread.h>
+#include <rtems/posix/pthreadimpl.h>
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+
+#if HAVE_DECL_PTHREAD_GETATTR_NP
+
+
+void *Thread_1(void *argument);
+
+pthread_t Init_id;
+pthread_t Thread_id;
+pthread_attr_t Thread_attr;
+int max_priority;
+
+void *Thread_1(
+ void *argument
+)
+{
+ pthread_attr_t attr;
+ struct sched_param param;
+ int sc;
+ int value;
+
+ puts("Thread - pthread_getattr_np - Verify value");
+ sc = pthread_getattr_np( Thread_id, &attr );
+ rtems_test_assert( sc == 0 );
+ rtems_test_assert( ! rtems_pthread_attribute_compare(&attr, &Thread_attr) );
+
+ param.sched_priority = max_priority;
+
+ puts( "Thread - pthread_setschedparam: Setting highest priority SCHED_FIFO" );
+ sc = pthread_setschedparam( Thread_id, SCHED_FIFO, ¶m );
+ rtems_test_assert( !sc );
+
+ puts("Thread - Detach");
+ sc = pthread_detach( Thread_id );
+ rtems_test_assert( !sc );
+
+ puts("Thread - pthread_getattr_np");
+ sc = pthread_getattr_np( Thread_id, &attr );
+ rtems_test_assert( !sc );
+
+ puts("Thread - Verify SCHED_FIFO policy");
+ sc = pthread_attr_getschedpolicy( &attr, &value );
+ rtems_test_assert( !sc );
+ rtems_test_assert( value == SCHED_FIFO );
+
+ puts("Thread - Verify max priority");
+ sc = pthread_attr_getschedparam( &attr, ¶m );
+ rtems_test_assert( !sc );
+ rtems_test_assert( param.sched_priority == max_priority );
+
+ puts("Thread - Verify detached");
+ sc = pthread_attr_getdetachstate( &attr, &value );
+ rtems_test_assert( value == PTHREAD_CREATE_DETACHED );
+
+ return NULL; /* just so the compiler thinks we returned something */
+}
+
+void *POSIX_Init(
+ void *ignored
+)
+{
+ int sc;
+ pthread_attr_t attribute;
+ void *stackaddr;
+ size_t stacksize;
+ size_t guardsize;
+ struct sched_param param;
+
+ puts( "\n\n*** POSIX ATTRIBUTE TEST 1 ***" );
+
+ /* Initialize thread id */
+ Init_id = pthread_self();
+ max_priority = sched_get_priority_max( SCHED_FIFO );
+
+ puts( "Init - pthread_getattr_np - attr NULL - EINVAL" );
+ sc = pthread_getattr_np( Init_id, NULL );
+ rtems_test_assert( sc == EINVAL );
+
+ puts( "Init - pthread_getattr_np - invalid id - ESRCH" );
+ sc = pthread_getattr_np( 0xffff, &attribute );
+ rtems_test_assert( sc == ESRCH );
+
+
+ /* init task attributes */
+ puts("Init - pthread_attr_init");
+ sc = pthread_attr_init(&Thread_attr);
+ rtems_test_assert(!sc);
+
+ puts("Init - pthread_attr_setinheritsched - PTHREAD_EXPLICIT_SCHED");
+ sc = pthread_attr_setinheritsched( &Thread_attr, PTHREAD_EXPLICIT_SCHED );
+ rtems_test_assert(!sc);
+ rtems_test_assert( Thread_attr.inheritsched == PTHREAD_EXPLICIT_SCHED );
+
+ puts("Init - pthread_attr_setschedpolicy to SCHED_RR");
+ sc = pthread_attr_setschedpolicy(&Thread_attr, SCHED_RR);
+ rtems_test_assert(!sc);
+
+ puts("Init - pthread_attr_setschedparam to minimum priority + 2");
+ param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2;
+ sc = pthread_attr_setschedparam( &Thread_attr, ¶m );
+ rtems_test_assert(!sc);
+
+ puts("Init - pthread_attr_getstack");
+ sc = pthread_attr_getstack( &Thread_attr, &stackaddr, &stacksize );
+ rtems_test_assert(!sc);
+
+ stacksize *= 2;
+ puts("Init - pthread_attr_setstack double the stacksize");
+ sc = pthread_attr_setstacksize( &Thread_attr, stacksize );
+ rtems_test_assert(!sc);
+
+ puts("Init - pthread_attr_getguardsize");
+ sc = pthread_attr_getguardsize( &Thread_attr, &guardsize );
+ rtems_test_assert(!sc);
+
+ guardsize *= 2;
+ puts("Init - pthread_attr_setguardsize double the guardsize");
+ sc = pthread_attr_setguardsize( &Thread_attr, guardsize );
+ rtems_test_assert(!sc);
+
+ puts("Init - raise priority to max");
+ param.sched_priority = max_priority;
+ sc = pthread_setschedparam( Init_id, SCHED_RR, ¶m );
+ rtems_test_assert( !sc );
+
+ puts("Init - pthread_create");
+ sc = pthread_create( &Thread_id, &Thread_attr, Thread_1, NULL );
+ rtems_test_assert( !sc );
+
+ puts("Init - Lower priority");
+ fflush(stdout);
+ param.sched_priority = sched_get_priority_min( SCHED_RR );
+ sc = pthread_setschedparam( Init_id, SCHED_RR, ¶m );
+ rtems_test_assert(!sc);
+
+#if 0
+ sc = pthread_join( Thread_id, NULL );
+ rtems_test_assert( !sc );
+#endif
+
+ puts( "*** END OF POSIX ATTRIBUTE TEST 1 ***" );
+ rtems_test_exit(0);
+ return NULL; /* just so the compiler thinks we returned something */
+}
+#else
+void *POSIX_Init(
+ void *ignored
+)
+{
+ puts( "\n\n*** POSIX ATTRIBUTE TEST 1 ***" );
+ puts( " pthread_getattr_np NOT supported" );
+ puts( "*** END OF POSIX ATTRIBUTE TEST 1 ***" );
+ rtems_test_exit(0);
+ return NULL; /* just so the compiler thinks we returned something */
+}
+
+#endif
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+/* global variables */
diff --git a/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.doc b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.doc
new file mode 100644
index 0000000..2387a4f
--- /dev/null
+++ b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.doc
@@ -0,0 +1,23 @@
+# COPYRIGHT (c) 1989-2014.
+# On-Line Applications Research Corporation (OAR).
+#
+# The license and distribution terms for this file may be
+# found in the file LICENSE in this distribution or at
+# http://www.rtems.com/license/LICENSE.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: psxgetattr01
+
+directives:
+
+ pthread_getattr
+
+concepts:
+
++ Verify error conditions in pthread_getattr
+
++ Verify attribute set other than default on a created thread
+
++ Verify attribute set when changed by a running thread
diff --git a/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
new file mode 100644
index 0000000..a3572e0
--- /dev/null
+++ b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
@@ -0,0 +1,22 @@
+*** POSIX ATTRIBUTE TEST 1 ***
+Init - pthread_getattr_np - attr NULL - EINVAL
+Init - pthread_getattr_np - invalid id - ESRCH
+Init - pthread_attr_init
+Init - pthread_attr_setinheritsched - PTHREAD_EXPLICIT_SCHED
+Init - pthread_attr_setschedpolicy to SCHED_RR
+Init - pthread_attr_setschedparam to minimum priority + 2
+Init - pthread_attr_getstack
+Init - pthread_attr_setstack double the stacksize
+Init - pthread_attr_getguardsize
+Init - pthread_attr_setguardsize double the guardsize
+Init - raise priority to max
+Init - pthread_create
+Init - Lower priority
+Thread - pthread_getattr_np - Verify value
+Thread - pthread_setschedparam: Setting highest priority SCHED_FIFO
+Thread - Detach
+Thread - pthread_getattr_np
+Thread - Verify SCHED_FIFO policy
+Thread - Verify max priority
+Thread - Verify detached
+*** END OF POSIX ATTRIBUTE TEST 1 ***
--
1.8.1.4
_______________________________________________
rtems-devel mailing list
rtems-devel@rtems.org
http://www.rtems.org/mailman/listinfo/rtems-devel