1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* Test_task2 |
---|
4 | * |
---|
5 | * This task attempts to receive control of a global semaphore. |
---|
6 | * If running on the node on which the semaphore resides, the wait is |
---|
7 | * forever, otherwise it times out on a remote semaphore. |
---|
8 | * |
---|
9 | * Input parameters: |
---|
10 | * argument - task argument |
---|
11 | * |
---|
12 | * Output parameters: NONE |
---|
13 | * |
---|
14 | * COPYRIGHT (c) 1989-2009. |
---|
15 | * On-Line Applications Research Corporation (OAR). |
---|
16 | * |
---|
17 | * Redistribution and use in source and binary forms, with or without |
---|
18 | * modification, are permitted provided that the following conditions |
---|
19 | * are met: |
---|
20 | * 1. Redistributions of source code must retain the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer. |
---|
22 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer in the |
---|
24 | * documentation and/or other materials provided with the distribution. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | #ifdef HAVE_CONFIG_H |
---|
40 | #include "config.h" |
---|
41 | #endif |
---|
42 | |
---|
43 | #include "system.h" |
---|
44 | |
---|
45 | rtems_task Test_task2( |
---|
46 | rtems_task_argument argument |
---|
47 | ) |
---|
48 | { |
---|
49 | rtems_status_code status; |
---|
50 | |
---|
51 | puts( "Getting SMID of semaphore" ); |
---|
52 | do { |
---|
53 | status = rtems_semaphore_ident( |
---|
54 | Semaphore_name[ 1 ], |
---|
55 | RTEMS_SEARCH_ALL_NODES, |
---|
56 | &Semaphore_id[ 1 ] |
---|
57 | ); |
---|
58 | } while ( !rtems_is_status_successful( status ) ); |
---|
59 | |
---|
60 | directive_failed( status, "rtems_semaphore_ident" ); |
---|
61 | |
---|
62 | if ( rtems_object_get_local_node() == 1 ) { |
---|
63 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); |
---|
64 | directive_failed( status, "rtems_task_wake_after" ); |
---|
65 | |
---|
66 | puts( "Releasing semaphore ..." ); |
---|
67 | status = rtems_semaphore_release( Semaphore_id[ 1 ] ); |
---|
68 | directive_failed( status, "rtems_semaphore_release" ); |
---|
69 | |
---|
70 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 ); |
---|
71 | directive_failed( status, "rtems_task_wake_after" ); |
---|
72 | |
---|
73 | puts( "Getting semaphore ..." ); |
---|
74 | status = rtems_semaphore_obtain( |
---|
75 | Semaphore_id[ 1 ], |
---|
76 | RTEMS_DEFAULT_OPTIONS, |
---|
77 | RTEMS_NO_TIMEOUT |
---|
78 | ); |
---|
79 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
80 | |
---|
81 | puts( "Getting semaphore ..." ); |
---|
82 | status = rtems_semaphore_obtain( |
---|
83 | Semaphore_id[ 1 ], |
---|
84 | RTEMS_DEFAULT_OPTIONS, |
---|
85 | RTEMS_NO_TIMEOUT |
---|
86 | ); |
---|
87 | puts( "How did I get back from here????" ); |
---|
88 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
89 | } |
---|
90 | |
---|
91 | /* |
---|
92 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 ); |
---|
93 | directive_failed( status, "rtems_task_wake_after" ); |
---|
94 | */ |
---|
95 | |
---|
96 | puts( "Getting semaphore ..." ); |
---|
97 | status = rtems_semaphore_obtain( |
---|
98 | Semaphore_id[ 1 ], |
---|
99 | RTEMS_DEFAULT_OPTIONS, |
---|
100 | RTEMS_NO_TIMEOUT |
---|
101 | ); |
---|
102 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
103 | |
---|
104 | puts( "Releasing semaphore ..." ); |
---|
105 | status = rtems_semaphore_release( Semaphore_id[ 1 ] ); |
---|
106 | directive_failed( status, "rtems_semaphore_release" ); |
---|
107 | |
---|
108 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); |
---|
109 | directive_failed( status, "rtems_task_wake_after" ); |
---|
110 | |
---|
111 | puts( "Getting semaphore ..." ); |
---|
112 | status = rtems_semaphore_obtain( |
---|
113 | Semaphore_id[ 1 ], |
---|
114 | RTEMS_DEFAULT_OPTIONS, |
---|
115 | 2 * rtems_clock_get_ticks_per_second() |
---|
116 | ); |
---|
117 | fatal_directive_status( |
---|
118 | status, |
---|
119 | RTEMS_TIMEOUT, |
---|
120 | "rtems_semaphore_obtain" |
---|
121 | ); |
---|
122 | puts( "rtems_semaphore_obtain correctly returned RTEMS_TIMEOUT" ); |
---|
123 | |
---|
124 | puts( "*** END OF TEST 13 ***" ); |
---|
125 | rtems_test_exit( 0 ); |
---|
126 | } |
---|