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 exceptions are raised and can be directly propagated to
28 -- the calling unit by protected operations.
31 -- Declare a package with a protected type, including protected operation
32 -- declarations and private data, simulating a counting semaphore.
33 -- In the main procedure, perform calls on protected operations
34 -- of the protected object designed to induce the raising of exceptions.
36 -- The exceptions raised are to be propagated directly from the protected
37 -- operations to the calling unit.
39 -- Ensure that the exceptions are raised and correctly propagated directly
40 -- to the calling unit from protected procedures and functions.
44 -- 06 Dec 94 SAIC ACVC 2.0
48 package CB20007_0
is -- Package Semaphore.
50 Handled_In_Function_Caller
,
51 Handled_In_Procedure_Caller
: Boolean := False;
54 Resource_Underflow
: exception;
56 protected type Counting_Semaphore
(Max_Resources
: Integer) is
58 function Resource_Limit_Exceeded
return Boolean;
61 Count
: Integer := Max_Resources
;
62 end Counting_Semaphore
;
66 --=================================================================--
70 package body CB20007_0
is -- Package Semaphore.
72 protected body Counting_Semaphore
is
76 if (Count
= 0) then -- No resources left to secure.
77 raise Resource_Underflow
;
78 Report
.Failed
("Program control not transferred by raise");
80 Count
:= Count
- 1; -- Available resources decremented.
82 -- No exception handlers here, direct propagation to calling unit.
86 function Resource_Limit_Exceeded
return Boolean is
88 if (Count
> Max_Resources
) then
89 raise Resource_Overflow
; -- Exception used as control flow
91 Report
.Failed
("Program control not transferred by raise");
95 -- No exception handlers here, direct propagation to calling unit.
96 end Resource_Limit_Exceeded
;
101 Count
:= Count
+ 1; -- Count of resources available
103 if Resource_Limit_Exceeded
then -- Call to protected operation
104 Count
:= Count
- 1; -- function that raises an
106 Report
.Failed
("Resource limit exceeded");
108 -- No exception handler here for exception raised in function.
109 -- Exception will propagate directly to calling unit.
113 end Counting_Semaphore
;
118 --=================================================================--
121 with CB20007_0
; -- Package Semaphore.
130 package Semaphore
renames CB20007_0
;
132 Total_Resources_Available
: constant := 1;
134 Resources
: Semaphore
.Counting_Semaphore
(Total_Resources_Available
);
135 -- An object of protected type.
139 Report
.Test
("CB20007", "Check that exceptions are raised and can " &
140 "be directly propagated to the calling unit " &
141 "by protected operations" );
145 Loop_Count
: Integer := Total_Resources_Available
+ 1;
146 begin -- Force exception.
147 for I
in 1..Loop_Count
loop
150 Report
.Failed
("Exception not propagated from protected " &
151 " operation in Allocate_Resources");
153 when Semaphore
.Resource_Underflow
=> -- Exception prop.
154 Semaphore
.Handled_In_Procedure_Caller
:= True; -- from protected
157 Report
.Failed
("Unknown exception during resource allocation");
158 end Allocate_Resources
;
161 Deallocate_Resources
:
163 Loop_Count
: Integer := Total_Resources_Available
+ 1;
164 begin -- Force exception.
165 for I
in 1..Loop_Count
loop
168 Report
.Failed
("Exception not propagated from protected " &
169 "operation in Deallocate_Resources");
171 when Semaphore
.Resource_Overflow
=> -- Exception prop
172 Semaphore
.Handled_In_Function_Caller
:= True; -- from protected
175 Report
.Failed
("Exception raised during resource deallocation");
176 end Deallocate_Resources
;
179 if not (Semaphore
.Handled_In_Procedure_Caller
and -- Incorrect exception
180 Semaphore
.Handled_In_Function_Caller
) -- handling in
181 then -- protected ops.
183 ("Improper exception propagation by protected operations");
189 Report
.Failed
("Unexpected exception " &
190 " raised and propagated in test");