source: rtems/testsuites/psxtests/psxonce01/init.c @ 3d65f45

5
Last change on this file since 3d65f45 was 3d65f45, checked in by Sebastian Huber <sebastian.huber@…>, on 02/18/19 at 07:32:42

psxtests/psxonce01: Fix typo

Update #3334.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  Copyright (C) 2019 embedded brains GmbH
3 *  Copyright (C) 2019 Sebastian Huber
4 *
5 *  COPYRIGHT (c) 1989-2009.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.org/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#define CONFIGURE_INIT
18#include "system.h"
19
20const char rtems_test_name[] = "PSXONCE 1";
21
22static pthread_once_t once_a = PTHREAD_ONCE_INIT;
23
24static pthread_once_t once_b = PTHREAD_ONCE_INIT;
25
26static rtems_id master;
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
36static void routine_b( void )
37{
38  rtems_status_code sc;
39
40  rtems_test_assert( test_init_routine_call_counter == 2 );
41  ++test_init_routine_call_counter;
42
43  sc = rtems_event_send( master, RTEMS_EVENT_0 );
44  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
45}
46
47static void use_b( rtems_task_argument arg )
48{
49  int status;
50
51  (void) arg;
52
53  status = pthread_once( &once_b, routine_b );
54  rtems_test_assert( status == 0 );
55
56  rtems_task_exit();
57}
58
59static void routine_a( void )
60{
61  rtems_status_code sc;
62  rtems_id id;
63  rtems_event_set events;
64
65  rtems_test_assert( test_init_routine_call_counter == 1 );
66  ++test_init_routine_call_counter;
67
68  master = rtems_task_self();
69
70  sc = rtems_task_create(
71    rtems_build_name( 'T', 'A', 'S', 'K' ),
72    RTEMS_MINIMUM_PRIORITY,
73    RTEMS_MINIMUM_STACK_SIZE,
74    RTEMS_DEFAULT_MODES,
75    RTEMS_DEFAULT_ATTRIBUTES,
76    &id
77  );
78  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
79
80  sc = rtems_task_start( id, use_b, 0 );
81  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
82
83  events = 0;
84  sc = rtems_event_receive(
85    RTEMS_EVENT_0,
86    RTEMS_EVENT_ANY | RTEMS_WAIT,
87    RTEMS_NO_TIMEOUT,
88    &events
89  );
90  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
91  rtems_test_assert( events == RTEMS_EVENT_0 );
92
93  rtems_test_assert( test_init_routine_call_counter == 3 );
94}
95
96rtems_task Init(rtems_task_argument argument)
97{
98  int status;
99  pthread_once_t once = PTHREAD_ONCE_INIT;
100
101  TEST_BEGIN();
102
103  puts( "Init: pthread_once - EINVAL (NULL once_control)" );
104  status = pthread_once( NULL, Test_init_routine );
105  rtems_test_assert( status == EINVAL );
106
107  puts( "Init: pthread_once - EINVAL (NULL init_routine)" );
108  status = pthread_once( &once, NULL );
109  rtems_test_assert( status == EINVAL );
110
111  puts( "Init: pthread_once - SUCCESSFUL (init_routine executes)" );
112  status = pthread_once( &once, Test_init_routine );
113  rtems_test_assert( !status );
114  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
115  rtems_test_assert( test_init_routine_call_counter == 1 );
116
117  puts( "Init: pthread_once - SUCCESSFUL (init_routine does not execute)" );
118  status = pthread_once( &once, Test_init_routine );
119  rtems_test_assert( !status );
120  printf( "Init: call counter: %d\n", test_init_routine_call_counter );
121  rtems_test_assert( test_init_routine_call_counter == 1 );
122
123  status = pthread_once( &once_a, routine_a );
124  rtems_test_assert( status == 0 );
125  rtems_test_assert( test_init_routine_call_counter == 3 );
126
127  TEST_END();
128  rtems_test_exit( 0 );
129}
Note: See TracBrowser for help on using the repository browser.