source: rtems/testsuites/psxtests/psxonce01/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • 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
17const char rtems_test_name[] = "PSXONCE 1";
18
19static pthread_once_t nesting_once = PTHREAD_ONCE_INIT;
20
21static void Test_init_routine_nesting( void )
22{
23  int status;
24  puts( "Test_init_routine_nesting: invoked" );
25  puts( "Test_init_routine_nesting: pthread_once - EINVAL (init_routine_nesting does not execute)" );
26  status = pthread_once( &nesting_once, Test_init_routine_nesting );
27  rtems_test_assert( status == EINVAL );
28}
29
30static int test_init_routine_call_counter = 0;
31
32static void Test_init_routine( void )
33{
34  puts( "Test_init_routine: invoked" );
35  ++test_init_routine_call_counter;
36}
37
38rtems_task Init(rtems_task_argument argument)
39{
40  int status;
41  pthread_once_t once = PTHREAD_ONCE_INIT;
42
43  TEST_BEGIN();
44
45  puts( "Init: pthread_once - EINVAL (NULL once_control)" );
46  status = pthread_once( NULL, Test_init_routine );
47  rtems_test_assert( status == EINVAL );
48
49  puts( "Init: pthread_once - EINVAL (NULL init_routine)" );
50  status = pthread_once( &once, NULL );
51  rtems_test_assert( status == EINVAL );
52
53  puts( "Init: pthread_once - SUCCESSFUL (init_routine executes)" );
54  status = pthread_once( &once, Test_init_routine );
55  rtems_test_assert( !status );
56  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
57  rtems_test_assert( test_init_routine_call_counter == 1 );
58
59  puts( "Init: pthread_once - SUCCESSFUL (init_routine does not execute)" );
60  status = pthread_once( &once, Test_init_routine );
61  rtems_test_assert( !status );
62  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
63  rtems_test_assert( test_init_routine_call_counter == 1 );
64
65  puts( "Init: pthread_once - SUCCESSFUL (init_routine_nesting executes)" );
66  status = pthread_once( &nesting_once, Test_init_routine_nesting );
67  rtems_test_assert( !status );
68
69  TEST_END();
70  rtems_test_exit( 0 );
71}
Note: See TracBrowser for help on using the repository browser.