summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psxonce01/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/psxtests/psxonce01/init.c')
-rw-r--r--testsuites/psxtests/psxonce01/init.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/testsuites/psxtests/psxonce01/init.c b/testsuites/psxtests/psxonce01/init.c
new file mode 100644
index 0000000000..6fd65794ab
--- /dev/null
+++ b/testsuites/psxtests/psxonce01/init.c
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define CONFIGURE_INIT
+#include "system.h"
+
+pthread_once_t nesting_once = PTHREAD_ONCE_INIT;
+
+void Test_init_routine_nesting( void );
+
+void Test_init_routine_nesting( void )
+{
+ int status;
+ puts( "Test_init_routine_nesting: invoked" );
+ status = pthread_once( &nesting_once, Test_init_routine_nesting );
+ rtems_test_assert( status == EINVAL );
+}
+
+void Test_init_routine( void );
+
+void Test_init_routine( void )
+{
+ puts( "Test_init_routine: invoked" );
+}
+
+rtems_task Init(rtems_task_argument argument)
+{
+ int status;
+ pthread_once_t once = PTHREAD_ONCE_INIT;
+
+ puts( "\n\n*** TEST POSIX ONCE 01 ***" );
+
+ /* once nesting */
+ puts( "Init: pthread_once - SUCCESSFUL (init_routine_nesting executes)" );
+ status = pthread_once( &nesting_once, Test_init_routine_nesting );
+ rtems_test_assert( !status );
+
+ /* exercise pthread_once */
+
+ puts( "Init: pthread_once - EINVAL (NULL once_control)" );
+ status = pthread_once( NULL, Test_init_routine );
+ rtems_test_assert( status == EINVAL );
+
+ puts( "Init: pthread_once - EINVAL (NULL init_routine)" );
+ status = pthread_once( &once, NULL );
+ rtems_test_assert( status == EINVAL );
+
+ puts( "Init: pthread_once - SUCCESSFUL (init_routine executes)" );
+ status = pthread_once( &once, Test_init_routine );
+ rtems_test_assert( !status );
+
+ puts( "Init: pthread_once - SUCCESSFUL (init_routine does not execute)" );
+ status = pthread_once( &once, Test_init_routine );
+ rtems_test_assert( !status );
+
+ puts( "*** END OF TEST POSIX ONCE 01 ***" );
+ rtems_test_exit( 0 );
+}