1-- C954A02.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. 15-- 16-- DISCLAIMER 17-- 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--* 25-- 26-- OBJECTIVE: 27-- Check that if a task requeued with abort on a protected entry queue 28-- is aborted, the protected entry call is canceled and the aborted 29-- task becomes completed. 30-- 31-- TEST DESCRIPTION: 32-- Declare a protected type which simulates a printer device driver 33-- (foundation code). 34-- 35-- Declare a task which simulates a printer server for multiple printers. 36-- 37-- For the protected type, declare an entry with a barrier that is set 38-- false by a protected procedure (which simulates starting a print job 39-- on the printer), and is set true by a second protected procedure (which 40-- simulates a handler called when the printer interrupts, indicating 41-- that printing is done). 42-- 43-- For the task, declare an entry whose corresponding accept statement 44-- contains a call to first protected procedure of the protected type 45-- (which sets the barrier of the protected entry to false), followed by 46-- a requeue with abort to the protected entry. Declare a second entry 47-- which does nothing. 48-- 49-- Declare a "requesting" task which calls the printer server task entry 50-- (and thus executes the requeue). Attempt to abort the requesting 51-- task. Verify that it is aborted, that the requeued entry call is 52-- canceled, and that the corresponding entry body is not executed. 53-- 54-- TEST FILES: 55-- This test depends on the following foundation code: 56-- 57-- F954A00.A 58-- 59-- 60-- 61-- CHANGE HISTORY: 62-- 06 Dec 94 SAIC ACVC 2.0 63-- 10 Oct 96 SAIC Added pragma elaborate 64-- 65--! 66 67package C954A02_0 is -- Printer server abstraction. 68 69 -- Simulate a system with multiple printers. The entry Print requests 70 -- that data be printed on the next available printer. The entry call 71 -- is accepted when a printer is available, and completes when printing 72 -- is done. 73 74 75 task Printer_Server is 76 entry Print (File_Name : String); -- Test the requeue statement. 77 entry Verify_Results; -- Artifice for test purposes. 78 end Printer_Server; 79 80end C954A02_0; 81 82 83 --==================================================================-- 84 85 86with Report; 87with ImpDef; 88 89with F954A00; -- Printer device abstraction. 90use F954A00; 91pragma Elaborate(F954a00); 92 93package body C954A02_0 is -- Printer server abstraction. 94 95 task body Printer_Server is 96 Printers_Busy : Boolean := True; 97 Index : Printer_ID := 1; 98 Print_Accepted : Boolean := False; 99 begin 100 101 loop 102 -- Wait for a printer to become available: 103 104 while Printers_Busy loop 105 Printers_Busy := False; -- Exit loop if 106 -- entry accepted. 107 select 108 Printer(Index).Done_Printing; -- Accepted immed. 109 -- when printer is 110 -- available. 111 else 112 Index := 1 + (Index mod Number_Of_Printers);-- Entry not immed. 113 Printers_Busy := True; -- accepted; keep 114 end select; -- looping. 115 116 -- Allow other task to get control 117 delay ImpDef.Minimum_Task_Switch; 118 119 end loop; -- Value of Index 120 -- at loop exit 121 -- identifies the 122 -- avail. printer. 123 124 -- Wait for a print request or terminate: 125 126 select 127 accept Print (File_Name : String) do 128 Print_Accepted := True; -- Allow 129 -- Verify_Results 130 -- to be accepted. 131 132 Printer(Index).Start_Printing (File_Name); -- Begin printing on 133 -- the available 134 -- -- -- printer. 135 -- Requeue is tested here -- 136 -- -- 137 -- Requeue caller so 138 requeue Printer(Index).Done_Printing -- server task free 139 with abort; -- to accept other 140 end Print; -- requests. 141 or 142 -- Guard ensures that Verify_Results cannot be accepted 143 -- until after Print has been accepted. This avoids a 144 -- race condition in the main program. 145 146 when Print_Accepted => accept Verify_Results; -- Artifice for 147 -- testing purposes. 148 or 149 terminate; 150 end select; 151 152 end loop; 153 154 exception 155 when others => 156 Report.Failed ("Exception raised in Printer_Server task"); 157 end Printer_Server; 158 159 160end C954A02_0; 161 162 163 --==================================================================-- 164 165 166with Report; 167with ImpDef; 168 169with F954A00; -- Printer device abstraction. 170with C954A02_0; -- Printer server abstraction. 171 172use C954A02_0; 173use F954A00; 174 175procedure C954A02 is 176 177 -- Length of time which simulates a very long process 178 Long_Enough : constant Duration := ImpDef.Clear_Ready_Queue; 179 180 --==============================================-- 181 182 task Print_Request; -- Send a print request. 183 184 task body Print_Request is 185 My_File : constant String := "MYFILE.DAT"; 186 begin 187 Printer_Server.Print (My_File); -- Invoke requeue statement. 188 Report.Failed ("Task continued execution following entry call"); 189 exception 190 when others => 191 Report.Failed ("Exception raised in Print_Request task"); 192 end Print_Request; 193 194 --==============================================-- 195 196begin -- Main program. 197 198 Report.Test ("C954A02", "Abort a requeue on a Protected entry"); 199 200 -- To pass this test, the following must be true: 201 -- 202 -- (A) The abort of Print_Request takes place immediately. 203 -- (B) The Done_Printing entry call is canceled, and the corresponding 204 -- entry body is not executed. 205 -- 206 -- Call the entry Verify_Results. The entry call will not be accepted 207 -- until after Print_Request has been requeued to Done_Printing. 208 209 Printer_Server.Verify_Results; -- Accepted after Print_Request is 210 -- requeued to Done_Printing. 211 212 -- Verify that the Done_Printing entry call has not been completed. 213 -- 214 if Printer(1).Is_Done then 215 Report.Failed ("Target entry of requeue executed prematurely"); 216 else 217 218 -- Simulate an application which needs access to the printer within 219 -- a specified time, and which aborts the current printer job if time 220 -- runs out. 221 222 select 223 Printer(1).Done_Printing; -- Wait for printer to come free. 224 or 225 delay Long_Enough; -- Print job took too long. 226 abort Print_Request; -- Abort print job. 227 end select; 228 229 Printer_Server.Verify_Results; -- Abortion completion point: force 230 -- Print_Request abort to complete. 231 232 -- Verify (A): that Print_Request has been aborted. 233 -- Note: the test will hang if the task as not been aborted 234 -- 235 while not Print_Request'Terminated loop 236 delay ImpDef.Minimum_Task_Switch; 237 end loop; 238 239 -- Verify (B): that the Done_Printing entry call was canceled, and 240 -- the corresponding entry body was not executed. 241 -- 242 -- Set the barrier of the entry to true, then check that the entry 243 -- body is not executed. If the entry call is NOT canceled, the 244 -- entry body will execute when the barrier is set true. 245 246 Printer(1).Handle_Interrupt; -- Simulate a printer interrupt, 247 -- signaling that printing is 248 -- done. 249 if Printer(1).Is_Done then 250 Report.Failed ("Entry call was not canceled"); 251 end if; 252 253 254 end if; 255 256 257 Report.Result; 258 259end C954A02; 260