3 -- Grant of Unlimited Rights
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
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.
27 -- Check that a requeue statement in an accept_statement with
28 -- parameters may requeue the entry call to a protected entry with no
29 -- parameters. Check that, if the call is queued on the new entry's
30 -- queue, the original caller remains blocked after the requeue, but
31 -- the accept_statement containing the requeue is completed.
33 -- Note that this test uses a requeue "with abort," although it does not
34 -- check that such a requeued caller can be aborted; that feature is
38 -- Declare a protected type which simulates a printer device driver
41 -- Declare a task which simulates a printer server for multiple printers.
43 -- For the protected type, declare an entry with a barrier that is set
44 -- false by a protected procedure (which simulates starting a print job
45 -- on the printer), and is set true by a second protected procedure (which
46 -- simulates a handler called when the printer interrupts, indicating
47 -- that printing is done).
49 -- For the task, declare an entry whose corresponding accept statement
50 -- contains a call to first protected procedure of the protected type
51 -- (which sets the barrier of the protected entry to false), followed by
52 -- a requeue with abort to the protected entry. Declare a second entry
53 -- which does nothing.
55 -- Declare a "requesting" task which calls the printer server task entry
56 -- (and thus executes the requeue). Verify that, following the requeue,
57 -- the requesting task remains blocked. Call the second entry of the
58 -- printer server task (the acceptance of this entry call verifies that
59 -- the requeue statement completed the entry call by the requesting task.
60 -- Call the second protected procedure of the protected type (the
61 -- interrupt handler) and verify that the protected entry completes for
62 -- the requesting task (which verifies that the requeue statement queued
63 -- the first task object to the protected entry).
66 -- This test depends on the following foundation code:
72 -- 06 Dec 94 SAIC ACVC 2.0
73 -- 10 Oct 96 SAIC Added pragma elaborate.
77 package C954A03_0
is -- Printer server abstraction.
79 -- Simulate a system with multiple printers. The entry Print requests
80 -- that data be printed on the next available printer. The entry call
81 -- is accepted when a printer is available, and completes when printing
84 task Printer_Server
is
85 entry Print
(File_Name
: String); -- Test the requeue statement.
86 entry Verify_Results
; -- Artifice for test purposes.
92 --==================================================================--
98 with F954A00
; -- Printer device abstraction.
100 pragma Elaborate
(F954a00
);
102 package body C954A03_0
is -- Printer server abstraction.
105 task body Printer_Server
is
106 Printers_Busy
: Boolean := True;
107 Index
: Printer_ID
:= 1;
108 Print_Accepted
: Boolean := False;
112 -- Wait for a printer to become available:
114 while Printers_Busy
loop
115 Printers_Busy
:= False; -- Exit loop if
118 Printer
(Index
).Done_Printing
; -- Accepted immed.
122 Index
:= 1 + (Index
mod Number_Of_Printers
);-- Entry not immed.
123 Printers_Busy
:= True; -- accepted; keep
124 end select; -- looping.
126 -- Allow other tasks to get control
127 delay ImpDef
.Minimum_Task_Switch
;
135 -- Wait for a print request or terminate:
138 accept Print
(File_Name
: String) do
139 Print_Accepted
:= True; -- Allow
143 Printer
(Index
).Start_Printing
(File_Name
); -- Begin printing on
146 -- Requeue is tested here --
149 requeue Printer
(Index
).Done_Printing
-- server task free
150 with abort; -- to accept other
151 end Print
; -- requests.
153 -- Guard ensures that Verify_Results cannot be accepted
154 -- until after Print has been accepted. This avoids a
155 -- race condition in the main program.
157 when Print_Accepted
=> accept Verify_Results
; -- Artifice for
167 Report
.Failed
("Exception raised in Printer_Server task");
174 --==================================================================--
180 with F954A00
; -- Printer device abstraction.
181 with C954A03_0
; -- Printer server abstraction.
188 Long_Enough
: constant Duration := ImpDef
.Clear_Ready_Queue
;
191 --==============================================--
193 Task_Completed
: Boolean := False; -- Testing flag.
195 protected Interlock
is -- Artifice for test purposes.
196 entry Wait
; -- Wait for lock to be released.
197 procedure Release
; -- Release the lock.
199 Locked
: Boolean := True;
203 protected body Interlock
is
205 entry Wait
when not Locked
is -- Calls are queued until after
206 -- -- Release is called.
208 Task_Completed
:= True;
211 procedure Release
is -- Called by Print_Request.
218 --==============================================--
220 task Print_Request
is -- Send a print request.
223 task body Print_Request
is
224 My_File
: constant String := "MYFILE.DAT";
226 Printer_Server
.Print
(My_File
); -- Invoke requeue statement.
227 Interlock
.Release
; -- Allow main to continue.
230 Report
.Failed
("Exception raised in Print_Request task");
233 --==============================================--
235 begin -- Main program.
237 Report
.Test
("C954A03", "Requeue from an Accept with parameters" &
238 " to a Protected Entry without parameters");
240 -- To pass this test, the following must be true:
242 -- (A) The Print entry call made by the task Print_Request must be
243 -- completed by the requeue statement.
244 -- (B) Print_Request must remain blocked following the requeue.
245 -- (C) Print_Request must be queued on the Done_Printing queue of
247 -- (D) Print_Request must continue execution after Done_Printing is
250 -- First, verify (A): that the Print entry call is complete.
252 -- Call the entry Verify_Results. If the requeue statement completed the
253 -- entry call to Print, the entry call to Verify_Results should be
254 -- accepted. Since the main will hang if this is NOT the case, make this
255 -- a timed entry call.
258 Printer_Server
.Verify_Results
; -- Accepted if requeue completed
259 -- entry call to Print.
261 delay Long_Enough
; -- Time out otherwise.
262 Report
.Failed
("Requeue did not complete entry call");
265 -- Now verify (B): that Print_Request remains blocked following the
266 -- requeue. Also verify that Done_Printing (the entry to which
267 -- Print_Request should have been queued) has not yet executed.
269 if Printer
(1).Is_Done
then
270 Report
.Failed
("Target entry of requeue executed prematurely");
271 elsif Print_Request
'Terminated then
272 Report
.Failed
("Caller did not remain blocked after the requeue");
275 -- Verify (C): that Print_Request is queued on the
276 -- Done_Printing queue of Printer(1).
278 -- Set the barrier for Printer(1).Done_Printing to true. Check
279 -- that the Done flag is updated and that Print_Request terminates.
281 Printer
(1).Handle_Interrupt
; -- Simulate a printer interrupt,
282 -- signaling that printing is
285 -- The Done_Printing entry body will complete before the next
286 -- protected action is called (Printer(1).Is_Done).
288 if not Printer
(1).Is_Done
then
289 Report
.Failed
("Caller was not requeued on target entry");
292 -- Finally, verify (D): that Print_Request continues after Done_Printing
295 -- After Done_Printing completes, there is a potential race condition
296 -- between the main program and Print_Request. The protected object
297 -- Interlock is provided to ensure that the check of whether
298 -- Print_Request continued is made *after* it has had a chance to do so.
299 -- The main program waits until the statement in Print_Request following
300 -- the requeue-causing statement has executed, then checks to see
301 -- whether Print_Request did in fact continue executing.
303 -- Note that the test will hang here if Print_Request does not continue
304 -- executing following the completion of the requeued entry call.
306 Interlock
.Wait
; -- Wait until Print_Request is
308 if not Task_Completed
then
309 Report
.Failed
("Caller remained blocked after target " &
313 -- Wait for Print_Request to finish before calling Report.Result.
314 while not Print_Request
'Terminated loop
315 delay ImpDef
.Minimum_Task_Switch
;