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 | |
---|
17 | static pthread_once_t nesting_once = PTHREAD_ONCE_INIT; |
---|
18 | |
---|
19 | static 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 | |
---|
28 | static int test_init_routine_call_counter = 0; |
---|
29 | |
---|
30 | static void Test_init_routine( void ) |
---|
31 | { |
---|
32 | puts( "Test_init_routine: invoked" ); |
---|
33 | ++test_init_routine_call_counter; |
---|
34 | } |
---|
35 | |
---|
36 | rtems_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 | } |
---|