Index: testsuites/psxtests/ChangeLog
===================================================================
--- testsuites/psxtests/ChangeLog	(revision 7c6375bbdb7cde84aa25e008c7c49acbf82b7e55)
+++ testsuites/psxtests/ChangeLog	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -1,2 +1,12 @@
+2009-07-19	Joel Sherrill <joel.sherrill@oarcorp.com>
+
+	* Makefile.am, configure.ac: Add psxspin02 to exercise case where
+	trylock is unable to obtain the spinlock and that attempting to
+	unlock a spinlock from a thread which did not lock it works as
+	expected.
+	* psxspin02/.cvsignore, psxspin02/Makefile.am, psxspin02/main.c,
+	psxspin02/psxspin02.doc, psxspin02/psxspin02.scn, psxspin02/test.c:
+	New files.
+
 2009-07-19	Joel Sherrill <joel.sherrill@oarcorp.com>
 
Index: testsuites/psxtests/Makefile.am
===================================================================
--- testsuites/psxtests/Makefile.am	(revision 7c6375bbdb7cde84aa25e008c7c49acbf82b7e55)
+++ testsuites/psxtests/Makefile.am	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -9,6 +9,6 @@
     psxcancel psxcleanup psxenosys psxfatal01 psxfatal02 psxkey01 psxitimer \
     psxmsgq01 psxmsgq02 psxmsgq03 psxmutexattr01 psxobj01 psxrwlock01 \
-    psxsem01 psxsignal01 psxspin01 psxsysconf psxtime psxtimer01 psxtimer02  \
-    psxualarm 
+    psxsem01 psxsignal01 psxspin01 psxspin02 psxsysconf psxtime psxtimer01 \
+    psxtimer02 psxualarm 
 
 ## File IO tests
Index: testsuites/psxtests/configure.ac
===================================================================
--- testsuites/psxtests/configure.ac	(revision 7c6375bbdb7cde84aa25e008c7c49acbf82b7e55)
+++ testsuites/psxtests/configure.ac	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -66,4 +66,5 @@
 psxsignal01/Makefile
 psxspin01/Makefile
+psxspin02/Makefile
 psxstat/Makefile
 psxsysconf/Makefile
Index: testsuites/psxtests/psxspin02/.cvsignore
===================================================================
--- testsuites/psxtests/psxspin02/.cvsignore	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
+++ testsuites/psxtests/psxspin02/.cvsignore	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: testsuites/psxtests/psxspin02/Makefile.am
===================================================================
--- testsuites/psxtests/psxspin02/Makefile.am	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
+++ testsuites/psxtests/psxspin02/Makefile.am	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -0,0 +1,30 @@
+##
+## $Id$
+##
+
+MANAGERS = all
+
+rtems_tests_PROGRAMS = psxspin02
+psxspin02_SOURCES = main.c test.c ../include/pmacros.h
+
+scndir = $(rtems_testsdir)
+dist_scn_DATA = psxspin02.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+psxspin02_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
+
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxspin02_OBJECTS) $(psxspin02_LDADD)
+LINK_LIBS = $(psxspin02_LDLIBS)
+
+psxspin02$(EXEEXT): $(psxspin02_OBJECTS) \
+    $(psxspin02_DEPENDENCIES)
+	@rm -f psxspin02$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
Index: testsuites/psxtests/psxspin02/main.c
===================================================================
--- testsuites/psxtests/psxspin02/main.c	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
+++ testsuites/psxtests/psxspin02/main.c	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -0,0 +1,49 @@
+/*
+ *  Simple test program wrapper for Spinlocks
+ *
+ *  COPYRIGHT (c) 1989-2008.
+ *  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.
+ *
+ *  $Id$
+ */
+
+#define CONFIGURE_INIT
+
+#include <bsp.h>
+#include <pmacros.h>
+
+void test_main( void );
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  test_main();
+  rtems_test_exit( 0 );
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 2
+
+#define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_INIT_TASK_STACK_SIZE    (RTEMS_MINIMUM_STACK_SIZE * 2)
+#define CONFIGURE_INIT_TASK_PRIORITY      2
+#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_PREEMPT
+
+#define CONFIGURE_EXTRA_TASK_STACKS       RTEMS_MINIMUM_STACK_SIZE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+
+/* end of file */
Index: testsuites/psxtests/psxspin02/psxspin02.scn
===================================================================
--- testsuites/psxtests/psxspin02/psxspin02.scn	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
+++ testsuites/psxtests/psxspin02/psxspin02.scn	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -0,0 +1,8 @@
+*** POSIX SPINLOCK TEST 02 ***
+pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK
+pthread_spin_lock( &Spinlock ) -- OK
+pthread_spin_trylock( &Spinlock ) -- EBUSY
+pthread_spin_unlock( &Spinlock ) -- EPERM
+pthread_spin_unlock( &Spinlock ) -- OK
+pthread_spin_destroy( &Spinlock ) -- OK
+*** END OF POSIX SPINLOCK TEST 02 ***
Index: testsuites/psxtests/psxspin02/test.c
===================================================================
--- testsuites/psxtests/psxspin02/test.c	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
+++ testsuites/psxtests/psxspin02/test.c	(revision 1938cc07dfb66d4192083ad0c91a9ae57c3b4a6c)
@@ -0,0 +1,101 @@
+/*
+ *  This test exercises the POSIX Spinlock manager.
+ *
+ *  COPYRIGHT (c) 1989-2006.
+ *  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.
+ *
+ *  $Id$
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#include <rtems.h>  /* for task creation */
+
+pthread_spinlock_t Spinlock;
+
+rtems_task SpinlockThread(rtems_task_argument arg)
+{
+  int  status;
+
+  puts( "pthread_spin_trylock( &Spinlock ) -- EBUSY" );
+  status = pthread_spin_trylock( &Spinlock );
+  assert( status == EBUSY );
+
+  puts( "pthread_spin_unlock( &Spinlock ) -- EPERM" );
+  status = pthread_spin_unlock( &Spinlock );
+  assert( status == EPERM );
+
+  rtems_task_delete( RTEMS_SELF );
+}
+
+/*
+ *  main entry point to the test
+ */
+
+#if defined(__rtems__)
+int test_main(void)
+#else
+int main(
+  int    argc,
+  char **argv
+)
+#endif
+{
+  pthread_spinlock_t    spinlock;
+  pthread_spinlock_t    spinlockExtra;
+  int                   status;
+  int                   p;
+  pthread_t             thread_id;
+  int                   i;
+  rtems_status_code     rstatus;
+  rtems_id              taskid;
+
+  puts( "\n\n*** POSIX SPINLOCK TEST 02 ***" );
+
+  /* This successfully creates one */
+  puts( "pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK" );
+  status = pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE );
+  assert( status == 0 );
+
+  /* Lock it */
+  puts( "pthread_spin_lock( &Spinlock ) -- OK" );
+  status = pthread_spin_lock( &Spinlock );
+  assert( status == 0 );
+
+  /*  Create a helper task */
+  rstatus = rtems_task_create(
+     rtems_build_name( 'S', 'P', 'I', 'N' ),
+     1,
+     RTEMS_MINIMUM_STACK_SIZE,
+     RTEMS_DEFAULT_MODES,
+     RTEMS_DEFAULT_ATTRIBUTES,
+     &taskid
+  );
+  assert( rstatus == RTEMS_SUCCESSFUL );
+
+  rstatus = rtems_task_start( taskid, SpinlockThread, 0 );
+  assert( rstatus == RTEMS_SUCCESSFUL );
+
+  sleep(1);
+  
+  puts( "pthread_spin_unlock( &Spinlock ) -- OK" );
+  status = pthread_spin_unlock( &Spinlock );
+  assert( status == 0 );
+
+  puts( "pthread_spin_destroy( &Spinlock ) -- OK" );
+  status = pthread_spin_destroy( &Spinlock );
+  assert( status == 0 );
+
+  /*************** END OF TEST *****************/
+  puts( "*** END OF POSIX SPINLOCK TEST 02 ***" );
+  exit(0);
+}
