-- C954A03.A
|
-- C954A03.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
-- unlimited rights in the software and documentation contained herein.
|
-- unlimited rights in the software and documentation contained herein.
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- this public release, the Government intends to confer upon all
|
-- this public release, the Government intends to confer upon all
|
-- recipients unlimited rights equal to those held by the Government.
|
-- recipients unlimited rights equal to those held by the Government.
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- released technical data and computer software in whole or in part, in
|
-- released technical data and computer software in whole or in part, in
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- to do so.
|
-- to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that a requeue statement in an accept_statement with
|
-- Check that a requeue statement in an accept_statement with
|
-- parameters may requeue the entry call to a protected entry with no
|
-- parameters may requeue the entry call to a protected entry with no
|
-- parameters. Check that, if the call is queued on the new entry's
|
-- parameters. Check that, if the call is queued on the new entry's
|
-- queue, the original caller remains blocked after the requeue, but
|
-- queue, the original caller remains blocked after the requeue, but
|
-- the accept_statement containing the requeue is completed.
|
-- the accept_statement containing the requeue is completed.
|
--
|
--
|
-- Note that this test uses a requeue "with abort," although it does not
|
-- Note that this test uses a requeue "with abort," although it does not
|
-- check that such a requeued caller can be aborted; that feature is
|
-- check that such a requeued caller can be aborted; that feature is
|
-- tested elsewhere.
|
-- tested elsewhere.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- Declare a protected type which simulates a printer device driver
|
-- Declare a protected type which simulates a printer device driver
|
-- (foundation code).
|
-- (foundation code).
|
--
|
--
|
-- Declare a task which simulates a printer server for multiple printers.
|
-- Declare a task which simulates a printer server for multiple printers.
|
--
|
--
|
-- For the protected type, declare an entry with a barrier that is set
|
-- For the protected type, declare an entry with a barrier that is set
|
-- false by a protected procedure (which simulates starting a print job
|
-- false by a protected procedure (which simulates starting a print job
|
-- on the printer), and is set true by a second protected procedure (which
|
-- on the printer), and is set true by a second protected procedure (which
|
-- simulates a handler called when the printer interrupts, indicating
|
-- simulates a handler called when the printer interrupts, indicating
|
-- that printing is done).
|
-- that printing is done).
|
--
|
--
|
-- For the task, declare an entry whose corresponding accept statement
|
-- For the task, declare an entry whose corresponding accept statement
|
-- contains a call to first protected procedure of the protected type
|
-- contains a call to first protected procedure of the protected type
|
-- (which sets the barrier of the protected entry to false), followed by
|
-- (which sets the barrier of the protected entry to false), followed by
|
-- a requeue with abort to the protected entry. Declare a second entry
|
-- a requeue with abort to the protected entry. Declare a second entry
|
-- which does nothing.
|
-- which does nothing.
|
--
|
--
|
-- Declare a "requesting" task which calls the printer server task entry
|
-- Declare a "requesting" task which calls the printer server task entry
|
-- (and thus executes the requeue). Verify that, following the requeue,
|
-- (and thus executes the requeue). Verify that, following the requeue,
|
-- the requesting task remains blocked. Call the second entry of the
|
-- the requesting task remains blocked. Call the second entry of the
|
-- printer server task (the acceptance of this entry call verifies that
|
-- printer server task (the acceptance of this entry call verifies that
|
-- the requeue statement completed the entry call by the requesting task.
|
-- the requeue statement completed the entry call by the requesting task.
|
-- Call the second protected procedure of the protected type (the
|
-- Call the second protected procedure of the protected type (the
|
-- interrupt handler) and verify that the protected entry completes for
|
-- interrupt handler) and verify that the protected entry completes for
|
-- the requesting task (which verifies that the requeue statement queued
|
-- the requesting task (which verifies that the requeue statement queued
|
-- the first task object to the protected entry).
|
-- the first task object to the protected entry).
|
--
|
--
|
-- TEST FILES:
|
-- TEST FILES:
|
-- This test depends on the following foundation code:
|
-- This test depends on the following foundation code:
|
--
|
--
|
-- F954A00.A
|
-- F954A00.A
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 10 Oct 96 SAIC Added pragma elaborate.
|
-- 10 Oct 96 SAIC Added pragma elaborate.
|
--
|
--
|
--!
|
--!
|
|
|
package C954A03_0 is -- Printer server abstraction.
|
package C954A03_0 is -- Printer server abstraction.
|
|
|
-- Simulate a system with multiple printers. The entry Print requests
|
-- Simulate a system with multiple printers. The entry Print requests
|
-- that data be printed on the next available printer. The entry call
|
-- that data be printed on the next available printer. The entry call
|
-- is accepted when a printer is available, and completes when printing
|
-- is accepted when a printer is available, and completes when printing
|
-- is done.
|
-- is done.
|
|
|
task Printer_Server is
|
task Printer_Server is
|
entry Print (File_Name : String); -- Test the requeue statement.
|
entry Print (File_Name : String); -- Test the requeue statement.
|
entry Verify_Results; -- Artifice for test purposes.
|
entry Verify_Results; -- Artifice for test purposes.
|
end Printer_Server;
|
end Printer_Server;
|
|
|
end C954A03_0;
|
end C954A03_0;
|
|
|
|
|
--==================================================================--
|
--==================================================================--
|
|
|
|
|
with Report;
|
with Report;
|
with ImpDef;
|
with ImpDef;
|
|
|
with F954A00; -- Printer device abstraction.
|
with F954A00; -- Printer device abstraction.
|
use F954A00;
|
use F954A00;
|
pragma Elaborate(F954a00);
|
pragma Elaborate(F954a00);
|
|
|
package body C954A03_0 is -- Printer server abstraction.
|
package body C954A03_0 is -- Printer server abstraction.
|
|
|
|
|
task body Printer_Server is
|
task body Printer_Server is
|
Printers_Busy : Boolean := True;
|
Printers_Busy : Boolean := True;
|
Index : Printer_ID := 1;
|
Index : Printer_ID := 1;
|
Print_Accepted : Boolean := False;
|
Print_Accepted : Boolean := False;
|
begin
|
begin
|
|
|
loop
|
loop
|
-- Wait for a printer to become available:
|
-- Wait for a printer to become available:
|
|
|
while Printers_Busy loop
|
while Printers_Busy loop
|
Printers_Busy := False; -- Exit loop if
|
Printers_Busy := False; -- Exit loop if
|
-- entry accepted.
|
-- entry accepted.
|
select
|
select
|
Printer(Index).Done_Printing; -- Accepted immed.
|
Printer(Index).Done_Printing; -- Accepted immed.
|
-- when printer is
|
-- when printer is
|
-- available.
|
-- available.
|
else
|
else
|
Index := 1 + (Index mod Number_Of_Printers);-- Entry not immed.
|
Index := 1 + (Index mod Number_Of_Printers);-- Entry not immed.
|
Printers_Busy := True; -- accepted; keep
|
Printers_Busy := True; -- accepted; keep
|
end select; -- looping.
|
end select; -- looping.
|
|
|
-- Allow other tasks to get control
|
-- Allow other tasks to get control
|
delay ImpDef.Minimum_Task_Switch;
|
delay ImpDef.Minimum_Task_Switch;
|
|
|
end loop;
|
end loop;
|
-- Value of Index
|
-- Value of Index
|
-- at loop exit
|
-- at loop exit
|
-- identifies the
|
-- identifies the
|
-- avail. printer.
|
-- avail. printer.
|
|
|
-- Wait for a print request or terminate:
|
-- Wait for a print request or terminate:
|
|
|
select
|
select
|
accept Print (File_Name : String) do
|
accept Print (File_Name : String) do
|
Print_Accepted := True; -- Allow
|
Print_Accepted := True; -- Allow
|
-- Verify_Results
|
-- Verify_Results
|
-- to be accepted.
|
-- to be accepted.
|
|
|
Printer(Index).Start_Printing (File_Name); -- Begin printing on
|
Printer(Index).Start_Printing (File_Name); -- Begin printing on
|
-- the available
|
-- the available
|
-- -- -- printer.
|
-- -- -- printer.
|
-- Requeue is tested here --
|
-- Requeue is tested here --
|
-- --
|
-- --
|
-- Requeue caller so
|
-- Requeue caller so
|
requeue Printer(Index).Done_Printing -- server task free
|
requeue Printer(Index).Done_Printing -- server task free
|
with abort; -- to accept other
|
with abort; -- to accept other
|
end Print; -- requests.
|
end Print; -- requests.
|
or
|
or
|
-- Guard ensures that Verify_Results cannot be accepted
|
-- Guard ensures that Verify_Results cannot be accepted
|
-- until after Print has been accepted. This avoids a
|
-- until after Print has been accepted. This avoids a
|
-- race condition in the main program.
|
-- race condition in the main program.
|
|
|
when Print_Accepted => accept Verify_Results; -- Artifice for
|
when Print_Accepted => accept Verify_Results; -- Artifice for
|
-- testing purposes.
|
-- testing purposes.
|
or
|
or
|
terminate;
|
terminate;
|
end select;
|
end select;
|
|
|
end loop;
|
end loop;
|
|
|
exception
|
exception
|
when others =>
|
when others =>
|
Report.Failed ("Exception raised in Printer_Server task");
|
Report.Failed ("Exception raised in Printer_Server task");
|
end Printer_Server;
|
end Printer_Server;
|
|
|
|
|
end C954A03_0;
|
end C954A03_0;
|
|
|
|
|
--==================================================================--
|
--==================================================================--
|
|
|
|
|
with Report;
|
with Report;
|
with ImpDef;
|
with ImpDef;
|
|
|
with F954A00; -- Printer device abstraction.
|
with F954A00; -- Printer device abstraction.
|
with C954A03_0; -- Printer server abstraction.
|
with C954A03_0; -- Printer server abstraction.
|
|
|
use C954A03_0;
|
use C954A03_0;
|
use F954A00;
|
use F954A00;
|
|
|
procedure C954A03 is
|
procedure C954A03 is
|
|
|
Long_Enough : constant Duration := ImpDef.Clear_Ready_Queue;
|
Long_Enough : constant Duration := ImpDef.Clear_Ready_Queue;
|
|
|
|
|
--==============================================--
|
--==============================================--
|
|
|
Task_Completed : Boolean := False; -- Testing flag.
|
Task_Completed : Boolean := False; -- Testing flag.
|
|
|
protected Interlock is -- Artifice for test purposes.
|
protected Interlock is -- Artifice for test purposes.
|
entry Wait; -- Wait for lock to be released.
|
entry Wait; -- Wait for lock to be released.
|
procedure Release; -- Release the lock.
|
procedure Release; -- Release the lock.
|
private
|
private
|
Locked : Boolean := True;
|
Locked : Boolean := True;
|
end Interlock;
|
end Interlock;
|
|
|
|
|
protected body Interlock is
|
protected body Interlock is
|
|
|
entry Wait when not Locked is -- Calls are queued until after
|
entry Wait when not Locked is -- Calls are queued until after
|
-- -- Release is called.
|
-- -- Release is called.
|
begin
|
begin
|
Task_Completed := True;
|
Task_Completed := True;
|
end Wait;
|
end Wait;
|
|
|
procedure Release is -- Called by Print_Request.
|
procedure Release is -- Called by Print_Request.
|
begin
|
begin
|
Locked := False;
|
Locked := False;
|
end Release;
|
end Release;
|
|
|
end Interlock;
|
end Interlock;
|
|
|
--==============================================--
|
--==============================================--
|
|
|
task Print_Request is -- Send a print request.
|
task Print_Request is -- Send a print request.
|
end Print_Request;
|
end Print_Request;
|
|
|
task body Print_Request is
|
task body Print_Request is
|
My_File : constant String := "MYFILE.DAT";
|
My_File : constant String := "MYFILE.DAT";
|
begin
|
begin
|
Printer_Server.Print (My_File); -- Invoke requeue statement.
|
Printer_Server.Print (My_File); -- Invoke requeue statement.
|
Interlock.Release; -- Allow main to continue.
|
Interlock.Release; -- Allow main to continue.
|
exception
|
exception
|
when others =>
|
when others =>
|
Report.Failed ("Exception raised in Print_Request task");
|
Report.Failed ("Exception raised in Print_Request task");
|
end Print_Request;
|
end Print_Request;
|
|
|
--==============================================--
|
--==============================================--
|
|
|
begin -- Main program.
|
begin -- Main program.
|
|
|
Report.Test ("C954A03", "Requeue from an Accept with parameters" &
|
Report.Test ("C954A03", "Requeue from an Accept with parameters" &
|
" to a Protected Entry without parameters");
|
" to a Protected Entry without parameters");
|
|
|
-- To pass this test, the following must be true:
|
-- To pass this test, the following must be true:
|
--
|
--
|
-- (A) The Print entry call made by the task Print_Request must be
|
-- (A) The Print entry call made by the task Print_Request must be
|
-- completed by the requeue statement.
|
-- completed by the requeue statement.
|
-- (B) Print_Request must remain blocked following the requeue.
|
-- (B) Print_Request must remain blocked following the requeue.
|
-- (C) Print_Request must be queued on the Done_Printing queue of
|
-- (C) Print_Request must be queued on the Done_Printing queue of
|
-- Printer(1).
|
-- Printer(1).
|
-- (D) Print_Request must continue execution after Done_Printing is
|
-- (D) Print_Request must continue execution after Done_Printing is
|
-- complete.
|
-- complete.
|
--
|
--
|
-- First, verify (A): that the Print entry call is complete.
|
-- First, verify (A): that the Print entry call is complete.
|
--
|
--
|
-- Call the entry Verify_Results. If the requeue statement completed the
|
-- Call the entry Verify_Results. If the requeue statement completed the
|
-- entry call to Print, the entry call to Verify_Results should be
|
-- entry call to Print, the entry call to Verify_Results should be
|
-- accepted. Since the main will hang if this is NOT the case, make this
|
-- accepted. Since the main will hang if this is NOT the case, make this
|
-- a timed entry call.
|
-- a timed entry call.
|
|
|
select
|
select
|
Printer_Server.Verify_Results; -- Accepted if requeue completed
|
Printer_Server.Verify_Results; -- Accepted if requeue completed
|
-- entry call to Print.
|
-- entry call to Print.
|
or
|
or
|
delay Long_Enough; -- Time out otherwise.
|
delay Long_Enough; -- Time out otherwise.
|
Report.Failed ("Requeue did not complete entry call");
|
Report.Failed ("Requeue did not complete entry call");
|
end select;
|
end select;
|
|
|
-- Now verify (B): that Print_Request remains blocked following the
|
-- Now verify (B): that Print_Request remains blocked following the
|
-- requeue. Also verify that Done_Printing (the entry to which
|
-- requeue. Also verify that Done_Printing (the entry to which
|
-- Print_Request should have been queued) has not yet executed.
|
-- Print_Request should have been queued) has not yet executed.
|
|
|
if Printer(1).Is_Done then
|
if Printer(1).Is_Done then
|
Report.Failed ("Target entry of requeue executed prematurely");
|
Report.Failed ("Target entry of requeue executed prematurely");
|
elsif Print_Request'Terminated then
|
elsif Print_Request'Terminated then
|
Report.Failed ("Caller did not remain blocked after the requeue");
|
Report.Failed ("Caller did not remain blocked after the requeue");
|
else
|
else
|
|
|
-- Verify (C): that Print_Request is queued on the
|
-- Verify (C): that Print_Request is queued on the
|
-- Done_Printing queue of Printer(1).
|
-- Done_Printing queue of Printer(1).
|
--
|
--
|
-- Set the barrier for Printer(1).Done_Printing to true. Check
|
-- Set the barrier for Printer(1).Done_Printing to true. Check
|
-- that the Done flag is updated and that Print_Request terminates.
|
-- that the Done flag is updated and that Print_Request terminates.
|
|
|
Printer(1).Handle_Interrupt; -- Simulate a printer interrupt,
|
Printer(1).Handle_Interrupt; -- Simulate a printer interrupt,
|
-- signaling that printing is
|
-- signaling that printing is
|
-- done.
|
-- done.
|
|
|
-- The Done_Printing entry body will complete before the next
|
-- The Done_Printing entry body will complete before the next
|
-- protected action is called (Printer(1).Is_Done).
|
-- protected action is called (Printer(1).Is_Done).
|
|
|
if not Printer(1).Is_Done then
|
if not Printer(1).Is_Done then
|
Report.Failed ("Caller was not requeued on target entry");
|
Report.Failed ("Caller was not requeued on target entry");
|
end if;
|
end if;
|
|
|
-- Finally, verify (D): that Print_Request continues after Done_Printing
|
-- Finally, verify (D): that Print_Request continues after Done_Printing
|
-- completes.
|
-- completes.
|
--
|
--
|
-- After Done_Printing completes, there is a potential race condition
|
-- After Done_Printing completes, there is a potential race condition
|
-- between the main program and Print_Request. The protected object
|
-- between the main program and Print_Request. The protected object
|
-- Interlock is provided to ensure that the check of whether
|
-- Interlock is provided to ensure that the check of whether
|
-- Print_Request continued is made *after* it has had a chance to do so.
|
-- Print_Request continued is made *after* it has had a chance to do so.
|
-- The main program waits until the statement in Print_Request following
|
-- The main program waits until the statement in Print_Request following
|
-- the requeue-causing statement has executed, then checks to see
|
-- the requeue-causing statement has executed, then checks to see
|
-- whether Print_Request did in fact continue executing.
|
-- whether Print_Request did in fact continue executing.
|
--
|
--
|
-- Note that the test will hang here if Print_Request does not continue
|
-- Note that the test will hang here if Print_Request does not continue
|
-- executing following the completion of the requeued entry call.
|
-- executing following the completion of the requeued entry call.
|
|
|
Interlock.Wait; -- Wait until Print_Request is
|
Interlock.Wait; -- Wait until Print_Request is
|
-- done.
|
-- done.
|
if not Task_Completed then
|
if not Task_Completed then
|
Report.Failed ("Caller remained blocked after target " &
|
Report.Failed ("Caller remained blocked after target " &
|
"entry released");
|
"entry released");
|
end if;
|
end if;
|
|
|
-- Wait for Print_Request to finish before calling Report.Result.
|
-- Wait for Print_Request to finish before calling Report.Result.
|
while not Print_Request'Terminated loop
|
while not Print_Request'Terminated loop
|
delay ImpDef.Minimum_Task_Switch;
|
delay ImpDef.Minimum_Task_Switch;
|
end loop;
|
end loop;
|
|
|
end if;
|
end if;
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end C954A03;
|
end C954A03;
|
|
|