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 properly handled (including
28 -- propagation by reraise) in 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 initially handled in the protected
37 -- operations, but this handling involves the reraise of the exception
38 -- and the propagation of the exception to the caller.
40 -- Ensure that the exceptions are raised, handled / reraised successfully
41 -- in protected procedures and functions. Use "others" handlers in the
42 -- protected operations.
46 -- 06 Dec 94 SAIC ACVC 2.0
50 package CB20006_0
is -- Package Semaphore.
53 Reraised_In_Procedure
,
54 Handled_In_Function_Caller
,
55 Handled_In_Procedure_Caller
: Boolean := False;
58 Resource_Underflow
: exception;
60 protected type Counting_Semaphore
(Max_Resources
: Integer) is
62 function Resource_Limit_Exceeded
return Boolean;
65 Count
: Integer := Max_Resources
;
66 end Counting_Semaphore
;
70 --=================================================================--
74 package body CB20006_0
is -- Package Semaphore.
76 protected body Counting_Semaphore
is
80 if (Count
= 0) then -- No resources left to secure.
81 raise Resource_Underflow
;
83 ("Program control not transferred by raise in Procedure Secure");
85 Count
:= Count
- 1; -- Available resources decremented.
88 when Resource_Underflow
=>
89 Reraised_In_Procedure
:= True;
90 raise; -- Exception propagated to caller.
91 Report
.Failed
("Exception not propagated to caller from Secure");
93 Report
.Failed
("Unexpected exception raised in Secure");
97 function Resource_Limit_Exceeded
return Boolean is
99 if (Count
> Max_Resources
) then
100 raise Resource_Overflow
; -- Exception used as control flow
103 ("Specific raise did not alter program control" &
104 " from Resource_Limit_Exceeded");
110 Reraised_In_Function
:= True;
111 raise; -- Exception propagated to caller.
112 Report
.Failed
("Exception not propagated to caller" &
113 " from Resource_Limit_Exceeded");
114 end Resource_Limit_Exceeded
;
119 Count
:= Count
+ 1; -- Count of resources available
121 if Resource_Limit_Exceeded
then -- Call to protected operation
122 Count
:= Count
- 1; -- function that raises/reraises
124 Report
.Failed
("Resource limit exceeded");
129 raise; -- Reraised and propagated again.
130 Report
.Failed
("Exception not reraised by procedure Release");
134 end Counting_Semaphore
;
139 --=================================================================--
142 with CB20006_0
; -- Package Semaphore.
148 Report
.Test
("CB20006", "Check that exceptions are raised and " &
149 "handled / reraised and propagated " &
150 "correctly by protected operations" );
155 package Semaphore
renames CB20006_0
;
157 Total_Resources_Available
: constant := 1;
159 Resources
: Semaphore
.Counting_Semaphore
(Total_Resources_Available
);
160 -- An object of protected type.
166 Loop_Count
: Integer := Total_Resources_Available
+ 1;
168 for I
in 1..Loop_Count
loop -- Force exception
172 ("Exception not propagated from protected operation Secure");
174 when Semaphore
.Resource_Underflow
=> -- Exception propagated
175 Semaphore
.Handled_In_Procedure_Caller
:= True; -- from protected
176 when others => -- procedure.
177 Semaphore
.Handled_In_Procedure_Caller
:= False;
178 end Allocate_Resources
;
181 Deallocate_Resources
:
183 Loop_Count
: Integer := Total_Resources_Available
+ 1;
185 for I
in 1..Loop_Count
loop -- Force exception
189 ("Exception not propagated from protected operation Release");
191 when Semaphore
.Resource_Overflow
=> -- Exception propagated
192 Semaphore
.Handled_In_Function_Caller
:= True; -- from protected
193 when others => -- function.
194 Semaphore
.Handled_In_Function_Caller
:= False;
195 end Deallocate_Resources
;
198 if not (Semaphore
.Reraised_In_Procedure
and
199 Semaphore
.Reraised_In_Function
and
200 Semaphore
.Handled_In_Procedure_Caller
and
201 Semaphore
.Handled_In_Function_Caller
)
202 then -- Incorrect excpt. handling
203 Report
.Failed
-- in protected operations.
204 ("Improper exception handling/reraising by protected operations");
210 Report
.Failed
("Unexpected exception " &
211 " raised and propagated in test");