source: rtems/testsuites/psxtests/psxonce01/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17static pthread_once_t nesting_once = PTHREAD_ONCE_INIT;
18
19static void Test_init_routine_nesting( void )
20{
21  int status;
22  puts( "Test_init_routine_nesting: invoked" );
23  puts( "Test_init_routine_nesting: pthread_once - EINVAL (init_routine_nesting does not execute)" );
24  status = pthread_once( &nesting_once, Test_init_routine_nesting );
25  rtems_test_assert( status == EINVAL );
26}
27
28static int test_init_routine_call_counter = 0;
29
30static void Test_init_routine( void )
31{
32  puts( "Test_init_routine: invoked" );
33  ++test_init_routine_call_counter;
34}
35
36rtems_task Init(rtems_task_argument argument)
37{
38  int status;
39  pthread_once_t once = PTHREAD_ONCE_INIT;
40
41  puts( "\n\n*** TEST POSIX ONCE 01 ***" );
42
43  puts( "Init: pthread_once - EINVAL (NULL once_control)" );
44  status = pthread_once( NULL, Test_init_routine );
45  rtems_test_assert( status == EINVAL );
46
47  puts( "Init: pthread_once - EINVAL (NULL init_routine)" );
48  status = pthread_once( &once, NULL );
49  rtems_test_assert( status == EINVAL );
50
51  puts( "Init: pthread_once - SUCCESSFUL (init_routine executes)" );
52  status = pthread_once( &once, Test_init_routine );
53  rtems_test_assert( !status );
54  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
55  rtems_test_assert( test_init_routine_call_counter == 1 );
56
57  puts( "Init: pthread_once - SUCCESSFUL (init_routine does not execute)" );
58  status = pthread_once( &once, Test_init_routine );
59  rtems_test_assert( !status );
60  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
61  rtems_test_assert( test_init_routine_call_counter == 1 );
62
63  puts( "Init: pthread_once - SUCCESSFUL (init_routine_nesting executes)" );
64  status = pthread_once( &nesting_once, Test_init_routine_nesting );
65  rtems_test_assert( !status );
66
67  puts( "*** END OF TEST POSIX ONCE 01 ***" );
68  rtems_test_exit( 0 );
69}
Note: See TracBrowser for help on using the repository browser.