[PATCH 2/2] psxonce01: Add call counter to check if init function has been called.

Christian Mauderer christian.mauderer at embedded-brains.de
Tue Mar 18 15:25:34 UTC 2014


From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>

---
 testsuites/psxtests/psxonce01/init.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/testsuites/psxtests/psxonce01/init.c b/testsuites/psxtests/psxonce01/init.c
index 6fd6579..9b6a5ee 100644
--- a/testsuites/psxtests/psxonce01/init.c
+++ b/testsuites/psxtests/psxonce01/init.c
@@ -14,23 +14,23 @@
 #define CONFIGURE_INIT
 #include "system.h"
 
-pthread_once_t nesting_once = PTHREAD_ONCE_INIT;
+static pthread_once_t nesting_once = PTHREAD_ONCE_INIT;
 
-void Test_init_routine_nesting( void );
-
-void Test_init_routine_nesting( void )
+static void Test_init_routine_nesting( void )
 {
   int status;
   puts( "Test_init_routine_nesting: invoked" );
+  puts( "Test_init_routine_nesting: pthread_once - EINVAL (init_routine_nesting does not execute)" );
   status = pthread_once( &nesting_once, Test_init_routine_nesting );
   rtems_test_assert( status == EINVAL );
 }
 
-void Test_init_routine( void );
+static int test_init_routine_call_counter = 0;
 
-void Test_init_routine( void )
+static void Test_init_routine( void )
 {
   puts( "Test_init_routine: invoked" );
+  ++test_init_routine_call_counter;
 }
 
 rtems_task Init(rtems_task_argument argument)
@@ -40,13 +40,6 @@ rtems_task Init(rtems_task_argument argument)
 
   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 );
@@ -58,10 +51,18 @@ rtems_task Init(rtems_task_argument argument)
   puts( "Init: pthread_once - SUCCESSFUL (init_routine executes)" );
   status = pthread_once( &once, Test_init_routine );
   rtems_test_assert( !status );
+  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
+  rtems_test_assert( test_init_routine_call_counter == 1 );
 
   puts( "Init: pthread_once - SUCCESSFUL (init_routine does not execute)" );
   status = pthread_once( &once, Test_init_routine );
   rtems_test_assert( !status );
+  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
+  rtems_test_assert( test_init_routine_call_counter == 1 );
+
+  puts( "Init: pthread_once - SUCCESSFUL (init_routine_nesting executes)" );
+  status = pthread_once( &nesting_once, Test_init_routine_nesting );
+  rtems_test_assert( !status );
 
   puts( "*** END OF TEST POSIX ONCE 01 ***" );
   rtems_test_exit( 0 );
-- 
1.8.4.5




More information about the devel mailing list