[rtems commit] psxtests: Added test for pthread_getattr_np().

Jennifer Averett jennifer at rtems.org
Fri Mar 7 15:08:50 UTC 2014


Module:    rtems
Branch:    master
Commit:    c315dbf2f75c1dfca4741f4911fd6cb3d947b8f2
Changeset: http://git.rtems.org/rtems/commit/?id=c315dbf2f75c1dfca4741f4911fd6cb3d947b8f2

Author:    Jennifer Averett <jennifer.averett at oarcorp.com>
Date:      Tue Jan 14 12:45:49 2014 -0600

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 deletions(-)

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 at .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, &param );
+  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, &param );
+  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, &param );
+  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, &param );
+  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, &param );
+  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 ***




More information about the vc mailing list