source: rtems/testsuites/sptests/sp12/task1.c

Last change on this file was eb57966, checked in by Joel Sherrill <joel@…>, on 03/31/22 at 21:32:14

testsuites/sptests/sp1*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*  Task_1
4 *
5 *  This routine serves as a test task.  It verifies the semaphore manager.
6 *
7 *  Input parameters:
8 *    argument - task argument
9 *
10 *  Output parameters:  NONE
11 *
12 *  COPYRIGHT (c) 1989-2009.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifdef HAVE_CONFIG_H
38#include "config.h"
39#endif
40
41#include "system.h"
42
43rtems_task Task_1(
44  rtems_task_argument argument
45)
46{
47  rtems_id          smid;
48  rtems_status_code status;
49
50  status = rtems_semaphore_ident(
51    Semaphore_name[ 1 ],
52    RTEMS_SEARCH_ALL_NODES,
53    &smid
54  );
55  printf( "TA1 - rtems_semaphore_ident - smid => %08" PRIxrtems_id "\n", smid );
56  directive_failed( status, "rtems_semaphore_ident of SM1" );
57
58  puts( "TA1 - rtems_semaphore_obtain - wait forever on SM2" );
59  status = rtems_semaphore_obtain(
60    Semaphore_id[ 2 ],
61    RTEMS_DEFAULT_OPTIONS,
62    RTEMS_NO_TIMEOUT
63  );
64  directive_failed( status, "rtems_semaphore_obtain of SM2" );
65  puts( "TA1 - got SM2" );
66
67  puts( "TA1 - rtems_semaphore_obtain - wait forever on SM3" );
68  status = rtems_semaphore_obtain(
69    Semaphore_id[ 3 ],
70    RTEMS_DEFAULT_OPTIONS,
71    RTEMS_NO_TIMEOUT
72  );
73  directive_failed( status, "rtems_semaphore_obtain of SM3" );
74  puts( "TA1 - got SM3" );
75
76  puts( "TA1 - rtems_semaphore_obtain - get SM1 - RTEMS_NO_WAIT" );
77  status = rtems_semaphore_obtain(
78    Semaphore_id[ 1 ],
79    RTEMS_NO_WAIT,
80    RTEMS_NO_TIMEOUT
81  );
82  directive_failed( status, "rtems_semaphore_obtain of SM1" );
83  puts( "TA1 - got SM1" );
84
85  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
86  status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
87  directive_failed( status, "rtems_task_wake_after" );
88
89  puts( "TA1 - rtems_semaphore_release - release SM1" );
90  status = rtems_semaphore_release( Semaphore_id[ 1 ] );
91  directive_failed( status, "rtems_semaphore_release of SM1" );
92
93  puts(
94    "TA1 - rtems_semaphore_obtain - waiting for SM1 with 10 second timeout"
95  );
96  status = rtems_semaphore_obtain(
97    Semaphore_id[ 1 ],
98    RTEMS_DEFAULT_OPTIONS,
99    10 * rtems_clock_get_ticks_per_second()
100  );
101  directive_failed( status, "rtems_semaphore_obtain of SM1" );
102  puts( "TA1 - got SM1" );
103
104  puts( "TA1 - rtems_semaphore_release - release SM2" );
105  status = rtems_semaphore_release( Semaphore_id[ 2 ] );
106  directive_failed( status, "rtems_semaphore_release of SM2" );
107
108  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
109  status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
110  directive_failed( status, "rtems_task_wake_after" );
111
112  puts( "TA1 - rtems_task_delete - delete TA3" );
113  status = rtems_task_delete( Task_id[ 3 ] );
114  directive_failed( status, "rtems_task_delete of TA3" );
115
116  status = rtems_task_create(
117    Task_name[ 4 ],
118    4,
119    RTEMS_MINIMUM_STACK_SIZE,
120    RTEMS_DEFAULT_MODES,
121    RTEMS_DEFAULT_ATTRIBUTES,
122    &Task_id[ 4 ]
123  );
124  directive_failed( status, "rtems_task_create of TA4" );
125
126  status = rtems_task_create(
127    Task_name[ 5 ],
128    4,
129    RTEMS_MINIMUM_STACK_SIZE,
130    RTEMS_DEFAULT_MODES,
131    RTEMS_DEFAULT_ATTRIBUTES,
132    &Task_id[ 5 ]
133   );
134  directive_failed( status, "rtems_task_create of TA5" );
135
136  status = rtems_task_start( Task_id[ 4 ], Task_4, 0 );
137  directive_failed( status, "rtems_task_start of TA4" );
138
139  status = rtems_task_start( Task_id[ 5 ], Task5, 0 );
140  directive_failed( status, "rtems_task_start of TA5" );
141
142  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
143  status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
144  directive_failed( status, "rtems_task_wake_after" );
145
146  puts( "TA1 - rtems_task_delete - delete TA4" );
147  status = rtems_task_delete( Task_id[ 4 ] );
148  directive_failed( status, "rtems_task_delete of TA4" );
149
150  puts( "TA1 - rtems_semaphore_release - release SM1" );
151  status = rtems_semaphore_release( Semaphore_id[ 1 ] );
152  directive_failed( status, "rtems_semaphore_release on SM1" );
153
154  puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
155  status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
156  directive_failed( status, "rtems_task_wake_after" );
157
158  puts( "TA1 - rtems_semaphore_delete - delete SM1" );
159  status = rtems_semaphore_delete( Semaphore_id[ 1 ] );
160  directive_failed( status, "rtems_semaphore_delete of SM1" );
161
162  puts( "TA1 - rtems_semaphore_delete - delete SM3" );
163  status = rtems_semaphore_delete( Semaphore_id[ 3 ] );
164  directive_failed( status, "rtems_semaphore_delete of SM3" );
165
166  puts( "TA1 - rtems_task_exit" );
167  rtems_task_exit();
168}
Note: See TracBrowser for help on using the repository browser.