source: rtems/testsuites/mptests/mp06/task1.c

Last change on this file was 42d4ebe, checked in by Joel Sherrill <joel@…>, on 04/01/22 at 19:01:34

testsuites/mptests/*: Change license to BSD-2.

Updates #3053.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include "system.h"
34
35#define DOT_COUNT 25
36
37/*
38 *  Stop_Test_TSR
39 */
40static rtems_timer_service_routine Stop_Test_TSR(
41  rtems_id  ignored_id,
42  void     *ignored_address
43)
44{
45  Stop_Test = true;
46}
47
48/*
49 *  Event_set_table
50 */
51rtems_event_set Event_set_table[] = {
52  RTEMS_EVENT_0,
53  RTEMS_EVENT_1,
54  RTEMS_EVENT_2,
55  RTEMS_EVENT_3,
56  RTEMS_EVENT_4,
57  RTEMS_EVENT_5,
58  RTEMS_EVENT_6,
59  RTEMS_EVENT_7,
60  RTEMS_EVENT_8,
61  RTEMS_EVENT_9,
62  RTEMS_EVENT_10,
63  RTEMS_EVENT_11,
64  RTEMS_EVENT_12,
65  RTEMS_EVENT_13,
66  RTEMS_EVENT_14,
67  RTEMS_EVENT_15,
68  RTEMS_EVENT_16,
69  RTEMS_EVENT_17,
70  RTEMS_EVENT_18,
71  RTEMS_EVENT_19,
72  RTEMS_EVENT_20,
73  RTEMS_EVENT_21,
74  RTEMS_EVENT_22,
75  RTEMS_EVENT_23,
76  RTEMS_EVENT_24,
77  RTEMS_EVENT_25,
78  RTEMS_EVENT_26,
79  RTEMS_EVENT_27,
80  RTEMS_EVENT_28,
81  RTEMS_EVENT_29,
82  RTEMS_EVENT_30,
83  RTEMS_EVENT_31
84};
85
86/*
87 *  Test_task
88 */
89rtems_task Test_task(
90  rtems_task_argument argument
91)
92{
93  rtems_status_code status;
94  uint32_t    count;
95  uint32_t    remote_node;
96  rtems_id          remote_tid;
97  rtems_event_set   event_out;
98  rtems_event_set   event_for_this_iteration;
99
100  Stop_Test = false;
101
102  remote_node = (rtems_object_get_local_node() == 1) ? 2 : 1;
103  puts_nocr( "Remote task's name is : " );
104  put_name( Task_name[ remote_node ], TRUE );
105
106  puts( "Getting TID of remote task" );
107  do {
108      status = rtems_task_ident(
109          Task_name[ remote_node ],
110          RTEMS_SEARCH_ALL_NODES,
111          &remote_tid
112          );
113  } while ( status != RTEMS_SUCCESSFUL );
114  directive_failed( status, "rtems_task_ident FAILED!!" );
115
116  if ( rtems_object_get_local_node() == 1 )
117    puts( "Sending events to remote task" );
118  else
119    puts( "Receiving events from remote task" );
120
121  status = rtems_timer_fire_after(
122    Timer_id[ 1 ],
123    5 * rtems_clock_get_ticks_per_second(),
124    Stop_Test_TSR,
125    NULL
126  );
127  directive_failed( status, "rtems_timer_fire_after" );
128
129  count = 0;
130
131  for ( ; ; ) {
132    if ( Stop_Test == true )
133      break;
134
135    event_for_this_iteration = Event_set_table[ count % 32 ];
136
137    if ( rtems_object_get_local_node() == 1 ) {
138      status = rtems_event_send( remote_tid, event_for_this_iteration );
139      directive_failed( status, "rtems_event_send" );
140
141      status = rtems_task_wake_after( 1 );
142      directive_failed( status, "rtems_task_wake_after" );
143    } else {
144      status = rtems_event_receive(
145        event_for_this_iteration,
146        RTEMS_DEFAULT_OPTIONS,
147        1 * rtems_clock_get_ticks_per_second(),
148        &event_out
149      );
150      if ( rtems_are_statuses_equal( status, RTEMS_TIMEOUT ) ) {
151        if ( rtems_object_get_local_node() == 2 )
152          puts( "\nCorrect behavior if the other node exitted." );
153        else
154          puts( "\nERROR... node 1 died" );
155        break;
156      } else
157        directive_failed( status, "rtems_event_receive" );
158    }
159
160    if ( (count % DOT_COUNT) == 0 )
161      put_dot('.');
162
163    count++;
164  }
165
166  putchar( '\n' );
167
168  if ( rtems_object_get_local_node() == 2 ) {
169    /* Flush events */
170    puts( "Flushing RTEMS_EVENT_16" );
171    (void) rtems_event_receive(RTEMS_EVENT_16, RTEMS_NO_WAIT, 0, &event_out);
172
173    puts( "Waiting for RTEMS_EVENT_16" );
174    status = rtems_event_receive(
175      RTEMS_EVENT_16,
176      RTEMS_DEFAULT_OPTIONS,
177      1 * rtems_clock_get_ticks_per_second(),
178      &event_out
179    );
180    fatal_directive_status( status, RTEMS_TIMEOUT, "rtems_event_receive" );
181    puts( "rtems_event_receive - correctly returned RTEMS_TIMEOUT" );
182  }
183  puts( "*** END OF TEST 6 ***" );
184  rtems_test_exit( 0 );
185}
Note: See TracBrowser for help on using the repository browser.