[PATCH 2/2] psxtests: Add tests for POSIX Keys.
Gedare Bloom
gedare at rtems.org
Wed Mar 13 00:34:48 UTC 2013
From: Zhongwei Yao <ashi08104 at gmail.com>
These are test cases for the POSIX Keys implementation.
This code was contributed during GSOC 2012.
---
testsuites/psxtests/Makefile.am | 3 +-
testsuites/psxtests/configure.ac | 5 +
testsuites/psxtests/psxkey01/init.c | 4 +-
testsuites/psxtests/psxkey01/psxkey01.scn | 4 +-
testsuites/psxtests/psxkey04/Makefile.am | 23 +++++
testsuites/psxtests/psxkey04/init.c | 128 ++++++++++++++++++++++++
testsuites/psxtests/psxkey04/psxkey04.doc | 22 ++++
testsuites/psxtests/psxkey04/psxkey04.scn | 11 ++
testsuites/psxtests/psxkey05/Makefile.am | 23 +++++
testsuites/psxtests/psxkey05/init.c | 82 +++++++++++++++
testsuites/psxtests/psxkey05/psxkey05.doc | 22 ++++
testsuites/psxtests/psxkey05/psxkey05.scn | 10 ++
testsuites/psxtests/psxkey06/Makefile.am | 23 +++++
testsuites/psxtests/psxkey06/init.c | 153 +++++++++++++++++++++++++++++
testsuites/psxtests/psxkey06/psxkey06.doc | 23 +++++
testsuites/psxtests/psxkey06/psxkey06.scn | 18 ++++
testsuites/psxtests/psxkey07/Makefile.am | 23 +++++
testsuites/psxtests/psxkey07/init.c | 100 +++++++++++++++++++
testsuites/psxtests/psxkey07/psxkey07.doc | 24 +++++
testsuites/psxtests/psxkey07/psxkey07.scn | 9 ++
testsuites/psxtests/psxkey08/Makefile.am | 23 +++++
testsuites/psxtests/psxkey08/init.c | 100 +++++++++++++++++++
testsuites/psxtests/psxkey08/psxkey08.doc | 22 ++++
testsuites/psxtests/psxkey08/psxkey08.scn | 10 ++
24 files changed, 860 insertions(+), 5 deletions(-)
create mode 100644 testsuites/psxtests/psxkey04/Makefile.am
create mode 100644 testsuites/psxtests/psxkey04/init.c
create mode 100644 testsuites/psxtests/psxkey04/psxkey04.doc
create mode 100644 testsuites/psxtests/psxkey04/psxkey04.scn
create mode 100644 testsuites/psxtests/psxkey05/Makefile.am
create mode 100644 testsuites/psxtests/psxkey05/init.c
create mode 100644 testsuites/psxtests/psxkey05/psxkey05.doc
create mode 100644 testsuites/psxtests/psxkey05/psxkey05.scn
create mode 100644 testsuites/psxtests/psxkey06/Makefile.am
create mode 100644 testsuites/psxtests/psxkey06/init.c
create mode 100644 testsuites/psxtests/psxkey06/psxkey06.doc
create mode 100644 testsuites/psxtests/psxkey06/psxkey06.scn
create mode 100644 testsuites/psxtests/psxkey07/Makefile.am
create mode 100644 testsuites/psxtests/psxkey07/init.c
create mode 100644 testsuites/psxtests/psxkey07/psxkey07.doc
create mode 100644 testsuites/psxtests/psxkey07/psxkey07.scn
create mode 100644 testsuites/psxtests/psxkey08/Makefile.am
create mode 100644 testsuites/psxtests/psxkey08/init.c
create mode 100644 testsuites/psxtests/psxkey08/psxkey08.doc
create mode 100644 testsuites/psxtests/psxkey08/psxkey08.scn
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 0e8a3e8..3549326 100644
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -7,7 +7,8 @@ SUBDIRS += psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 psx09 \
psxaio01 psxaio02 psxaio03 \
psxalarm01 psxautoinit01 psxautoinit02 psxbarrier01 \
psxcancel psxcancel01 psxclassic01 psxcleanup psxcleanup01 \
- psxcond01 psxconfig01 psxenosys psxkey01 psxkey02 psxkey03 \
+ psxcond01 psxconfig01 psxenosys psxkey01 psxkey02 psxkey03 psxkey04 \
+ psxkey05 psxkey06 psxkey07 psxkey08 \
psxitimer psxmsgq01 psxmsgq02 psxmsgq03 psxmsgq04 \
psxmutexattr01 psxobj01 psxrwlock01 psxsem01 psxsignal01 psxsignal02 \
psxsignal03 psxsignal04 psxsignal05 psxsignal06 \
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index a04fc5e..b149ac2 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -122,6 +122,11 @@ psxitimer/Makefile
psxkey01/Makefile
psxkey02/Makefile
psxkey03/Makefile
+psxkey04/Makefile
+psxkey05/Makefile
+psxkey06/Makefile
+psxkey07/Makefile
+psxkey08/Makefile
psxmount/Makefile
psxmsgq01/Makefile
psxmsgq02/Makefile
diff --git a/testsuites/psxtests/psxkey01/init.c b/testsuites/psxtests/psxkey01/init.c
index 3383c8d..e63407c 100644
--- a/testsuites/psxtests/psxkey01/init.c
+++ b/testsuites/psxtests/psxkey01/init.c
@@ -43,10 +43,10 @@ void *POSIX_Init(
rtems_workspace_greedy_allocate( NULL, 0 );
- puts("Init: pthread_key_create - ENOMEM (Workspace not available)");
+ puts("Init: pthread_key_create - OK");
empty_line();
status = pthread_key_create( &Key_id[0], Key_destructor );
- fatal_directive_check_status_only( status, ENOMEM, "no workspace available" );
+ fatal_directive_check_status_only( status, 0, "OK" );
puts( "*** END OF POSIX KEY 01 TEST ***" );
rtems_test_exit( 0 );
diff --git a/testsuites/psxtests/psxkey01/psxkey01.scn b/testsuites/psxtests/psxkey01/psxkey01.scn
index 597b0f8..e1a747c 100644
--- a/testsuites/psxtests/psxkey01/psxkey01.scn
+++ b/testsuites/psxtests/psxkey01/psxkey01.scn
@@ -1,5 +1,5 @@
*** POSIX KEY 01 TEST ***
Init's ID is 0x0b010001
-Allocate_majority_of_workspace:
-Init: pthread_key_create - ENOMEM (Workspace not available)
+Init: pthread_key_create - OK
+
*** END OF POSIX KEY 01 TEST ***
diff --git a/testsuites/psxtests/psxkey04/Makefile.am b/testsuites/psxtests/psxkey04/Makefile.am
new file mode 100644
index 0000000..cd5f2bb
--- /dev/null
+++ b/testsuites/psxtests/psxkey04/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxkey04
+psxkey04_SOURCES = init.c
+
+dist_rtems_tests_DATA = psxkey04.scn
+dist_rtems_tests_DATA += psxkey04.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 = $(psxkey04_OBJECTS)
+LINK_LIBS = $(psxkey04_LDLIBS)
+
+psxkey04$(EXEEXT): $(psxkey04_OBJECTS) $(psxkey04_DEPENDENCIES)
+ @rm -f psxkey04$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxkey04/init.c b/testsuites/psxtests/psxkey04/init.c
new file mode 100644
index 0000000..76540dd
--- /dev/null
+++ b/testsuites/psxtests/psxkey04/init.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2012 Zhongwei Yao.
+ * COPYRIGHT (c) 1989-2012.
+ * 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
+
+#include <pthread.h>
+#include <errno.h>
+#include "tmacros.h"
+#include "pmacros.h"
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+void *Test_Thread1(void *argument);
+void *Test_Thread2(void *argument);
+
+int Data_array[2] = {1, 2};
+pthread_t thread1, thread2;
+
+pthread_key_t Key;
+
+void *Test_Thread1(
+ void *argument
+)
+{
+ int sc;
+ int *value;
+ struct timespec delay_request;
+ /*
+ * Detach ourselves so we don't wait for a join that won't happen.
+ */
+ pthread_detach( pthread_self() );
+
+ puts( "Test_Thread 1 - pthread_setspecific - OK" );
+ sc = pthread_setspecific( Key, &Data_array[0] );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 1 - sleep - let thread 2 run - OK" );
+ delay_request.tv_sec = 0;
+ delay_request.tv_nsec = 4 * 100000000;
+ sc = nanosleep( &delay_request, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 1 - pthread_getspecific - OK" );
+ value = pthread_getspecific( Key );
+ rtems_test_assert( *value == Data_array[0] );
+
+ return NULL;
+}
+
+void *Test_Thread2(
+ void *argument
+)
+{
+ int sc;
+ int *value;
+ /*
+ * Detach ourselves so we don't wait for a join that won't happen.
+ */
+ pthread_detach( pthread_self() );
+
+ puts( "Test_Thread 2 - pthread_setspecific - OK" );
+ sc = pthread_setspecific( Key, &Data_array[1] );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 2 - pthread_getspecific - OK" );
+ value = pthread_getspecific( Key );
+ rtems_test_assert( *value == Data_array[1] );
+
+ return NULL;
+}
+
+void *POSIX_Init(
+ void *ignored
+)
+{
+ int sc;
+ struct timespec delay_request;
+
+ puts( "\n\n*** TEST KEY 04 ***" );
+
+ puts( "Init - pthread_key_create - OK" );
+ sc = pthread_key_create( &Key, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread_create - OK" );
+ sc = pthread_create( &thread1, NULL, Test_Thread1, NULL );
+ rtems_test_assert( !sc );
+
+ sc = pthread_create( &thread2, NULL, Test_Thread2, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - sleep - let thread run - OK" );
+ delay_request.tv_sec = 0;
+ delay_request.tv_nsec = 8 * 100000000;
+ sc = nanosleep( &delay_request, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread_key_delete - OK" );
+ sc = pthread_key_delete( Key );
+ rtems_test_assert( sc == 0 );
+
+ puts( "*** END OF TEST KEY 04 ***" );
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 3
+#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+/* global variables */
diff --git a/testsuites/psxtests/psxkey04/psxkey04.doc b/testsuites/psxtests/psxkey04/psxkey04.doc
new file mode 100644
index 0000000..6438d4e
--- /dev/null
+++ b/testsuites/psxtests/psxkey04/psxkey04.doc
@@ -0,0 +1,22 @@
+# COPYRIGHT (c) 1989-2009.
+# 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: psxkey04
+
+directives:
+
+ pthread_key_create
+ pthread_setspecific
+ pthread_getspecific
+ pthread_key_delete
+
+concepts:
+
++ Ensure that key data's operation(set and get) under multithreads work.
diff --git a/testsuites/psxtests/psxkey04/psxkey04.scn b/testsuites/psxtests/psxkey04/psxkey04.scn
new file mode 100644
index 0000000..aa0500f
--- /dev/null
+++ b/testsuites/psxtests/psxkey04/psxkey04.scn
@@ -0,0 +1,11 @@
+*** TEST KEY 04 ***
+Init - pthread_key_create - OK
+Init - pthread_create - OK
+Init - sleep - let thread run - OK
+Test_Thread 1 - pthread_setspecific - OK
+Test_Thread 1 - sleep - let thread 2 run - OK
+Test_Thread 2 - pthread_setspecific - OK
+Test_Thread 2 - pthread_getspecific - OK
+Test_Thread 1 - pthread_getspecific - OK
+Init - pthread_key_delete - OK
+*** END OF TEST KEY 04 ***
diff --git a/testsuites/psxtests/psxkey05/Makefile.am b/testsuites/psxtests/psxkey05/Makefile.am
new file mode 100644
index 0000000..c253900
--- /dev/null
+++ b/testsuites/psxtests/psxkey05/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxkey05
+psxkey05_SOURCES = init.c
+
+dist_rtems_tests_DATA = psxkey05.scn
+dist_rtems_tests_DATA += psxkey05.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 = $(psxkey05_OBJECTS)
+LINK_LIBS = $(psxkey05_LDLIBS)
+
+psxkey05$(EXEEXT): $(psxkey05_OBJECTS) $(psxkey05_DEPENDENCIES)
+ @rm -f psxkey05$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxkey05/init.c b/testsuites/psxtests/psxkey05/init.c
new file mode 100644
index 0000000..1d866c7
--- /dev/null
+++ b/testsuites/psxtests/psxkey05/init.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 Zhongwei Yao.
+ * COPYRIGHT (c) 1989-2012.
+ * 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
+
+#include <pthread.h>
+#include <errno.h>
+#include "tmacros.h"
+#include "pmacros.h"
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+
+void *POSIX_Init(
+ void *ignored
+)
+{
+ pthread_key_t key1, key2;
+ int sc, *value;
+ int Data_array[2] = {1, 2};
+
+ puts( "\n\n*** TEST KEY 05 ***" );
+
+ puts( "Init - pthread key1 create - OK" );
+ sc = pthread_key_create( &key1, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread key2 create - OK" );
+ sc = pthread_key_create( &key2, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - key1 pthread_setspecific - OK" );
+ sc = pthread_setspecific( key1, &Data_array[0] );
+ rtems_test_assert( !sc );
+
+ puts( "Init - key2 pthread_setspecific - OK" );
+ sc = pthread_setspecific( key2, &Data_array[1] );
+ rtems_test_assert( !sc );
+
+ puts( "Init - key1 pthread_getspecific - OK" );
+ value = pthread_getspecific( key1 );
+ rtems_test_assert( *value == Data_array[0] );
+
+ puts( "Init - key2 pthread_getspecific - OK" );
+ value = pthread_getspecific( key2 );
+ rtems_test_assert( *value == Data_array[1] );
+
+ puts( "Init - pthread key1 delete - OK" );
+ sc = pthread_key_delete( key1 );
+ rtems_test_assert( sc == 0 );
+
+ puts( "Init - pthread key2 delete - OK" );
+ sc = pthread_key_delete( key2 );
+ rtems_test_assert( sc == 0 );
+
+ puts( "*** END OF TEST KEY 05 ***" );
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 3
+#define CONFIGURE_MAXIMUM_POSIX_KEYS 2
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+/* global variables */
diff --git a/testsuites/psxtests/psxkey05/psxkey05.doc b/testsuites/psxtests/psxkey05/psxkey05.doc
new file mode 100644
index 0000000..f4359d6
--- /dev/null
+++ b/testsuites/psxtests/psxkey05/psxkey05.doc
@@ -0,0 +1,22 @@
+# COPYRIGHT (c) 1989-2009.
+# 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: psxkey05
+
+directives:
+
+ pthread_key_create
+ pthread_setspecific
+ pthread_getspecific
+ pthread_key_delete
+
+concepts:
+
++ Ensure that key data's operation(create, set, get and delete) under multikeys work.
diff --git a/testsuites/psxtests/psxkey05/psxkey05.scn b/testsuites/psxtests/psxkey05/psxkey05.scn
new file mode 100644
index 0000000..f352a36
--- /dev/null
+++ b/testsuites/psxtests/psxkey05/psxkey05.scn
@@ -0,0 +1,10 @@
+*** TEST KEY 05 ***
+Init - pthread key1 create - OK
+Init - pthread key2 create - OK
+Init - key1 pthread_setspecific - OK
+Init - key1 pthread_getspecific - OK
+Init - key2 pthread_setspecific - OK
+Init - key2 pthread_getspecific - OK
+Init - pthread key1 delete - OK
+Init - pthread key2 delete - OK
+*** END OF TEST KEY 05 ***
\ No newline at end of file
diff --git a/testsuites/psxtests/psxkey06/Makefile.am b/testsuites/psxtests/psxkey06/Makefile.am
new file mode 100644
index 0000000..9815baf
--- /dev/null
+++ b/testsuites/psxtests/psxkey06/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxkey06
+psxkey06_SOURCES = init.c
+
+dist_rtems_tests_DATA = psxkey06.scn
+dist_rtems_tests_DATA += psxkey06.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 = $(psxkey06_OBJECTS)
+LINK_LIBS = $(psxkey06_LDLIBS)
+
+psxkey06$(EXEEXT): $(psxkey06_OBJECTS) $(psxkey06_DEPENDENCIES)
+ @rm -f psxkey06$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxkey06/init.c b/testsuites/psxtests/psxkey06/init.c
new file mode 100644
index 0000000..98b46a4
--- /dev/null
+++ b/testsuites/psxtests/psxkey06/init.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2012 Zhongwei Yao.
+ * COPYRIGHT (c) 1989-2012.
+ * 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
+
+#include <pthread.h>
+#include <errno.h>
+#include "tmacros.h"
+#include "pmacros.h"
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+void *Test_Thread1(void *argument);
+void *Test_Thread2(void *argument);
+
+int Data_array[4] = {1, 2, 3, 4};
+
+pthread_key_t key1, key2;
+
+void *Test_Thread1(
+ void *argument
+)
+{
+ int sc;
+ int *value;
+ struct timespec delay_request;
+ /*
+ * Detach ourselves so we don't wait for a join that won't happen.
+ */
+ pthread_detach( pthread_self() );
+
+ puts( "Test_Thread 1 - key1 pthread_setspecific - OK" );
+ sc = pthread_setspecific( key1, &Data_array[0] );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 1 - key2 pthread_setspecific - OK" );
+ sc = pthread_setspecific( key2, &Data_array[1] );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 1 - sleep - let thread2 run - OK" );
+ delay_request.tv_sec = 0;
+ delay_request.tv_nsec = 4 * 100000000;
+ sc = nanosleep( &delay_request, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 1 - key1 pthread_getspecific - OK" );
+ value = pthread_getspecific( key1 );
+ rtems_test_assert( *value == Data_array[0] );
+
+ puts( "Test_Thread 1 - key2 pthread_getspecific - OK" );
+ value = pthread_getspecific( key2 );
+ rtems_test_assert( *value == Data_array[1] );
+
+ return NULL;
+}
+
+void *Test_Thread2(
+ void *argument
+)
+{
+ int sc;
+ int *value;
+ /*
+ * Detach ourselves so we don't wait for a join that won't happen.
+ */
+ pthread_detach( pthread_self() );
+
+ puts( "Test_Thread 2 - key1 pthread_setspecific - OK" );
+ sc = pthread_setspecific( key1, &Data_array[2] );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 2 - key2 pthread_setspecific - OK" );
+ sc = pthread_setspecific( key2, &Data_array[3] );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread 2 - key1 pthread_getspecific - OK" );
+ value = pthread_getspecific( key1 );
+ rtems_test_assert( *value == Data_array[2] );
+
+ puts( "Test_Thread 2 - key2 pthread_getspecific - OK" );
+ value = pthread_getspecific( key2 );
+ rtems_test_assert( *value == Data_array[3] );
+
+ return NULL;
+}
+
+void *POSIX_Init(
+ void *ignored
+)
+{
+ pthread_t thread1, thread2;
+ int sc;
+ struct timespec delay_request;
+
+ puts( "\n\n*** TEST KEY 06 ***" );
+
+ puts( "Init - pthread key1 create - OK" );
+ sc = pthread_key_create( &key1, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread key2 create - OK" );
+ sc = pthread_key_create( &key2, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread1 create - OK" );
+ sc = pthread_create( &thread1, NULL, Test_Thread1, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread2 create - OK" );
+ sc = pthread_create( &thread2, NULL, Test_Thread2, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - sleep - let thread run - OK" );
+ delay_request.tv_sec = 0;
+ delay_request.tv_nsec = 8 * 100000000;
+ sc = nanosleep( &delay_request, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - pthread key1 delete - OK" );
+ sc = pthread_key_delete( key1 );
+ rtems_test_assert( sc == 0 );
+
+ puts( "Init - pthread key2 delete - OK" );
+ sc = pthread_key_delete( key2 );
+ rtems_test_assert( sc == 0 );
+
+ puts( "*** END OF TEST KEY 06 ***" );
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 3
+#define CONFIGURE_MAXIMUM_POSIX_KEYS 2
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+/* global variables */
diff --git a/testsuites/psxtests/psxkey06/psxkey06.doc b/testsuites/psxtests/psxkey06/psxkey06.doc
new file mode 100644
index 0000000..6becdb9
--- /dev/null
+++ b/testsuites/psxtests/psxkey06/psxkey06.doc
@@ -0,0 +1,23 @@
+# COPYRIGHT (c) 1989-2009.
+# 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: psxkey06
+
+directives:
+
+ pthread_key_create
+ pthread_setspecific
+ pthread_getspecific
+ pthread_key_delete
+
+concepts:
+
++ Ensure that key data's operation(create, set, get and delete) under
+ multikeys and multi threads work.
diff --git a/testsuites/psxtests/psxkey06/psxkey06.scn b/testsuites/psxtests/psxkey06/psxkey06.scn
new file mode 100644
index 0000000..a105b6f
--- /dev/null
+++ b/testsuites/psxtests/psxkey06/psxkey06.scn
@@ -0,0 +1,18 @@
+*** TEST KEY 06 ***
+Init - pthread key1 create - OK
+Init - pthread key2 create - OK
+Init - pthread1 create - OK
+Init - pthread2 create - OK
+Init - sleep - let thread run - OK
+Test_Thread 1 - key1 pthread_setspecific - OK
+Test_Thread 1 - key2 pthread_setspecific - OK
+Test_Thread 1 - sleep - let thread2 run - OK
+Test_Thread 2 - key1 pthread_setspecific - OK
+Test_Thread 2 - key2 pthread_setspecific - OK
+Test_Thread 2 - key1 pthread_getspecific - OK
+Test_Thread 2 - key2 pthread_getspecific - OK
+Test_Thread 1 - key1 pthread_getspecific - OK
+Test_Thread 1 - key2 pthread_getspecific - OK
+Init - pthread key1 delete - OK
+Init - pthread key2 delete - OK
+*** END OF TEST KEY 06 ***
diff --git a/testsuites/psxtests/psxkey07/Makefile.am b/testsuites/psxtests/psxkey07/Makefile.am
new file mode 100644
index 0000000..a701f30
--- /dev/null
+++ b/testsuites/psxtests/psxkey07/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxkey07
+psxkey07_SOURCES = init.c
+
+dist_rtems_tests_DATA = psxkey07.scn
+dist_rtems_tests_DATA += psxkey07.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 = $(psxkey07_OBJECTS)
+LINK_LIBS = $(psxkey07_LDLIBS)
+
+psxkey07$(EXEEXT): $(psxkey07_OBJECTS) $(psxkey07_DEPENDENCIES)
+ @rm -f psxkey07$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxkey07/init.c b/testsuites/psxtests/psxkey07/init.c
new file mode 100644
index 0000000..5042731
--- /dev/null
+++ b/testsuites/psxtests/psxkey07/init.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2012 Zhongwei Yao.
+ * COPYRIGHT (c) 1989-2012.
+ * 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
+
+#include <pthread.h>
+#include <errno.h>
+#include "tmacros.h"
+#include "pmacros.h"
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+void destructor(void *value);
+void *Test_Thread(void *argument);
+
+int Data_array[1] = {1};
+
+pthread_key_t key;
+volatile bool destructor_ran;
+
+void destructor(void *value)
+{
+ destructor_ran = true;
+}
+
+void *Test_Thread(
+ void *argument
+)
+{
+ int sc;
+
+ /**
+ * Detach ourselves to release test thread's resource after thread exit.
+ */
+ pthread_detach( pthread_self() );
+
+ puts( "Test_Thread - key pthread_setspecific - OK" );
+ sc = pthread_setspecific( key, argument );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread - pthread_exit to run key destructors - OK" );
+
+ return NULL;
+}
+
+void *POSIX_Init(
+ void *ignored
+)
+{
+ pthread_t thread;
+ int sc;
+ struct timespec delay_request;
+
+ puts( "\n\n*** TEST KEY 07 ***" );
+
+ puts( "Init - pthread key create with destructor - OK" );
+ sc = pthread_key_create( &key, destructor );
+ puts( "Init - pthread create - OK" );
+ sc = pthread_create( &thread, NULL, Test_Thread, &sc );
+ rtems_test_assert( !sc );
+
+ puts( "Init - sleep - let thread run - OK" );
+ delay_request.tv_sec = 0;
+ delay_request.tv_nsec = 8 * 100000000;
+ sc = nanosleep( &delay_request, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - verify destructor run - OK" );
+ rtems_test_assert( destructor_ran == true );
+ puts( "Init - pthread key delete - OK" );
+ sc = pthread_key_delete( key );
+ rtems_test_assert( sc == 0 );
+
+ puts( "*** END OF TEST KEY 07 ***" );
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
+#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+/* global variables */
diff --git a/testsuites/psxtests/psxkey07/psxkey07.doc b/testsuites/psxtests/psxkey07/psxkey07.doc
new file mode 100644
index 0000000..bdf3846
--- /dev/null
+++ b/testsuites/psxtests/psxkey07/psxkey07.doc
@@ -0,0 +1,24 @@
+# COPYRIGHT (c) 1989-2009.
+# 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: psxkey07
+
+directives:
+
+ pthread_key_create
+ pthread_setspecific
+ pthread_key_delete
+
+ _POSIX_Keys_Run_destructors
+
+concepts:
+
++ Ensure that POSIX Key works when thread deleted first and then deleted key
+ self.
\ No newline at end of file
diff --git a/testsuites/psxtests/psxkey07/psxkey07.scn b/testsuites/psxtests/psxkey07/psxkey07.scn
new file mode 100644
index 0000000..05275fb
--- /dev/null
+++ b/testsuites/psxtests/psxkey07/psxkey07.scn
@@ -0,0 +1,9 @@
+*** TEST KEY 07 ***
+Init - pthread key create with destructor - OK
+Init - pthread create - OK
+Init - sleep - let thread run - OK
+Test_Thread - key pthread_setspecific - OK
+Test_Thread - pthread_exit to run key destructors - OK
+Init - verify destructor run - OK
+Init - pthread key delete - OK
+*** END OF TEST KEY 07 ***
diff --git a/testsuites/psxtests/psxkey08/Makefile.am b/testsuites/psxtests/psxkey08/Makefile.am
new file mode 100644
index 0000000..e5bf787
--- /dev/null
+++ b/testsuites/psxtests/psxkey08/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxkey08
+psxkey08_SOURCES = init.c
+
+dist_rtems_tests_DATA = psxkey08.scn
+dist_rtems_tests_DATA += psxkey08.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 = $(psxkey08_OBJECTS)
+LINK_LIBS = $(psxkey08_LDLIBS)
+
+psxkey08$(EXEEXT): $(psxkey08_OBJECTS) $(psxkey08_DEPENDENCIES)
+ @rm -f psxkey08$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxkey08/init.c b/testsuites/psxtests/psxkey08/init.c
new file mode 100644
index 0000000..b7d8d59
--- /dev/null
+++ b/testsuites/psxtests/psxkey08/init.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2012 Zhongwei Yao.
+ * COPYRIGHT (c) 1989-2012.
+ * 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
+
+#include <pthread.h>
+#include <errno.h>
+#include "tmacros.h"
+#include "pmacros.h"
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+void destructor(void *value);
+void *Test_Thread(void *argument);
+
+int Data_array[1] = {1};
+
+pthread_key_t key;
+volatile bool destructor_ran;
+
+void destructor(void *value)
+{
+ destructor_ran = true;
+}
+
+void *Test_Thread(
+ void *argument
+)
+{
+ int sc;
+
+ /**
+ * Detach ourselves to release test thread's resource after thread exit.
+ */
+ pthread_detach( pthread_self() );
+ puts( "Test_Thread - key pthread_setspecific - OK" );
+ sc = pthread_setspecific( key, argument );
+ rtems_test_assert( !sc );
+
+ puts( "Test_Thread - pthread key delete - OK" );
+ sc = pthread_key_delete( key );
+ rtems_test_assert( sc == 0 );
+
+ puts( "Test_Thread - pthread exit, but don't run key destructors - OK" );
+ return NULL;
+}
+
+void *POSIX_Init(
+ void *ignored
+)
+{
+ pthread_t thread;
+ int sc;
+ struct timespec delay_request;
+
+ puts( "\n\n*** TEST KEY 08 ***" );
+ puts( "Init - pthread key create with destructor - OK" );
+ sc = pthread_key_create( &key, destructor );
+ rtems_test_assert( !sc );
+
+ puts( "Init - sleep - let thread run - OK" );
+ delay_request.tv_sec = 0;
+ delay_request.tv_nsec = 8 * 100000000;
+ sc = nanosleep( &delay_request, NULL );
+ rtems_test_assert( !sc );
+
+ puts( "Init - verify destructor did NOT run - OK" );
+ rtems_test_assert( destructor_ran == false );
+
+ /* puts( "Init - pthread key delete - OK" ); */
+ /* sc = pthread_key_delete( key ); */
+ /* rtems_test_assert( sc == 0 ); */
+
+ puts( "*** END OF TEST KEY 08 ***" );
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
+#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+/* global variables */
diff --git a/testsuites/psxtests/psxkey08/psxkey08.doc b/testsuites/psxtests/psxkey08/psxkey08.doc
new file mode 100644
index 0000000..7730adf
--- /dev/null
+++ b/testsuites/psxtests/psxkey08/psxkey08.doc
@@ -0,0 +1,22 @@
+# COPYRIGHT (c) 1989-2009.
+# 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: psxkey08
+
+directives:
+
+ pthread_key_create
+ pthread_setspecific
+ pthread_key_delete
+ _POSIX_Keys_Run_destructors
+
+concepts:
+
+ +Ensure that POSIX Key works when key first and then deleted thread self.
\ No newline at end of file
diff --git a/testsuites/psxtests/psxkey08/psxkey08.scn b/testsuites/psxtests/psxkey08/psxkey08.scn
new file mode 100644
index 0000000..d63a7e3
--- /dev/null
+++ b/testsuites/psxtests/psxkey08/psxkey08.scn
@@ -0,0 +1,10 @@
+
+*** TEST KEY 08 ***
+Init - pthread key create with destructor - OK
+Init - pthread create - OK
+Init - sleep - let thread run - OK
+Test_Thread - key pthread_setspecific - OK
+Test_Thread - pthread key delete - OK
+Test_Thread - pthread exit, but don't run key destructors - OK
+Init - verify destructor did NOT run - OK
+*** END OF TEST KEY 08 ***
--
1.7.1
More information about the devel
mailing list