Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / ada / acats / tests / c9 / c974011.a
blob4682db6286d8ef0740cdfb16e0fda6021be1395f
1 -- C974011.A
2 --
3 -- Grant of Unlimited Rights
4 --
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
14 -- to do so.
16 -- DISCLAIMER
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
24 --*
26 -- OBJECTIVE:
27 -- Check that the sequence of statements of the triggering alternative
28 -- of an asynchronous select statement is not executed if the triggering
29 -- statement is a task entry call and the entry is not accepted
30 -- before the abortable part completes.
31 -- Check that the call queued on the entry is cancelled
33 -- TEST DESCRIPTION:
34 -- Declare a main procedure containing an asynchronous select with a task
35 -- entry call as triggering statement. Force the entry call to be
36 -- queued by having the task call a procedure, prior to the corresponding
37 -- accept statement, which simulates (with a delay) a routine waiting
38 -- for user input
39 --
40 -- Once the call is known to be queued, complete the abortable part.
41 -- Check that the rendezvous (and thus the trigger) does not complete.
42 -- Then clear the barrier and check that the entry has been cancelled
45 -- CHANGE HISTORY:
46 -- 06 Dec 94 SAIC ACVC 2.0
47 -- 28 Nov 95 SAIC Eliminated shared global variable for ACVC 2.0.1
49 --!
51 with ImpDef;
53 package C974011_0 is -- Automated teller machine abstraction.
57 type Key_Enum is (None, Cancel, Deposit, Withdraw);
59 protected Key_PO is
60 procedure Set (K : Key_Enum);
61 function Value return Key_Enum;
62 private
63 Current : Key_Enum := None;
64 end Key_PO;
67 -- Flags for testing purposes
68 TC_Abortable_Part_Completed : Boolean := False;
69 TC_Rendezvous_Entered : Boolean := False;
70 TC_Delay_Time : constant duration := ImpDef.Switch_To_New_Task;
73 Count : Integer := 1234; -- Global to defeat optimization.
76 type Card_Number_Type is private;
77 type Card_PIN_Type is private;
78 type ATM_Card_Type is private;
81 Transaction_Canceled : exception;
84 task type ATM_Keyboard_Task is
85 entry Cancel_Pressed;
86 end ATM_Keyboard_Task;
88 procedure Read_Card (Card : in out ATM_Card_Type);
90 procedure Validate_Card (Card : in ATM_Card_Type);
92 procedure Perform_Transaction (Card : in ATM_Card_Type);
94 private
96 type Card_Number_Type is range 1 .. 9999;
97 type Card_PIN_Type is range 100 .. 999;
99 type ATM_Card_Type is record
100 Number : Card_Number_Type;
101 PIN : Card_PIN_Type;
102 end record;
104 end C974011_0;
107 --==================================================================--
110 with Report;
111 package body C974011_0 is
113 protected body Key_PO is
114 procedure Set (K : Key_Enum) is
115 begin
116 Current := K;
117 end Set;
119 function Value return Key_Enum is
120 begin
121 return Current;
122 end Value;
123 end Key_PO;
126 procedure Listen_For_Input (Key : out Key_Enum) is
127 begin
128 -- Model the situation where the user does not press cancel thus
129 -- allowing validation to complete
131 delay TC_Delay_Time; -- Long enough to force queuing on
132 -- Keyboard.Cancel_Pressed.
134 Key := Key_PO.Value;
136 end Listen_For_Input;
140 -- One of these gets created as "Keyboard" for each transaction
142 task body ATM_Keyboard_Task is
143 Key_Pressed : Key_Enum;
144 begin
145 loop
146 -- Force entry calls
147 Listen_For_Input (Key_Pressed); -- to be queued,
149 select
150 when (Key_Pressed = Cancel) =>
151 accept Cancel_Pressed do
152 TC_Rendezvous_Entered := True;
153 end Cancel_Pressed;
155 -- User has cancelled the transaction so we exit the
156 -- loop and allow the task to terminate
157 exit;
158 else
159 delay ImpDef.Switch_To_New_Task;
160 end select;
162 end loop;
163 exception
164 when others =>
165 Report.Failed ("Unexpected Exception in ATM_Keyboard_Task");
166 end ATM_Keyboard_Task;
170 procedure Read_Card (Card : in out ATM_Card_Type) is
171 begin
172 Card.Number := 9999;
173 Card.PIN := 111;
174 end Read_Card;
177 procedure Validate_Card (Card : in ATM_Card_Type) is
178 begin
179 Count := (Count + 1) mod Integer (Card.PIN);
181 -- Simulate a validation activity which is longer than the time
182 -- taken in Listen_For_Input but not inordinately so.
183 delay TC_Delay_Time * 2;
185 end Validate_Card;
188 procedure Perform_Transaction (Card : in ATM_Card_Type) is
189 begin
190 if TC_Rendezvous_Entered then
191 Report.Failed ("Triggering statement completed");
192 end if;
193 if Count = 1234 then
194 -- Initial value is unchanged
195 Report.Failed ("Abortable part did not execute");
196 end if;
197 if not TC_Abortable_Part_Completed then
198 Report.Failed ("Abortable part did not complete");
199 end if;
200 end Perform_Transaction;
203 end C974011_0;
206 --==================================================================--
209 with Report;
211 with C974011_0; -- Automated teller machine abstraction.
212 use C974011_0;
214 procedure C974011 is
216 Card_Data : ATM_Card_Type;
218 begin -- Main program.
220 Report.Test ("C974011", "Asynchronous Select: Trigger is queued on a " &
221 "task entry and the abortable part " &
222 "completes first");
224 Read_Card (Card_Data);
226 declare
227 -- Create the task for this transaction
228 Keyboard : C974011_0.ATM_Keyboard_Task;
229 begin
231 -- --
232 -- Asynchronous select is tested here --
233 -- --
235 select
237 Keyboard.Cancel_Pressed; -- Entry call is initially queued, so
238 -- abortable part starts.
239 raise Transaction_Canceled; -- This would be executed if we
240 -- completed the rendezvous
241 then abort
243 Validate_Card (Card_Data);
244 TC_Abortable_Part_Completed := true;
246 end select;
248 Perform_Transaction (Card_Data);
251 -- Now clear the entry barrier to allow the rendezvous to complete
252 -- if the triggering call has not been cancelled
253 Key_PO.Set (Cancel);
255 delay TC_Delay_Time; -- to allow it all to take place
257 if TC_Rendezvous_Entered then
258 Report.Failed ("Triggering Call was not cancelled");
259 end if;
261 abort Keyboard; -- clean up. (Note: the task will only exit the
262 -- loop and terminate if the call hanging on the
263 -- entry is executed.)
265 exception
266 when Transaction_Canceled =>
267 Report.Failed ("Triggering alternative sequence of statements " &
268 "executed");
269 when Others =>
270 Report.Failed ("Unexpected exception in the Main");
271 end;
273 Report.Result;
275 end C974011;