annotate gcc/testsuite/ada/acats/tests/cb/cb20006.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CB20006.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that exceptions are raised and properly handled (including
kono
parents:
diff changeset
28 -- propagation by reraise) in protected operations.
kono
parents:
diff changeset
29 --
kono
parents:
diff changeset
30 -- TEST DESCRIPTION:
kono
parents:
diff changeset
31 -- Declare a package with a protected type, including protected operation
kono
parents:
diff changeset
32 -- declarations and private data, simulating a counting semaphore.
kono
parents:
diff changeset
33 -- In the main procedure, perform calls on protected operations
kono
parents:
diff changeset
34 -- of the protected object designed to induce the raising of exceptions.
kono
parents:
diff changeset
35 --
kono
parents:
diff changeset
36 -- The exceptions raised are to be initially handled in the protected
kono
parents:
diff changeset
37 -- operations, but this handling involves the reraise of the exception
kono
parents:
diff changeset
38 -- and the propagation of the exception to the caller.
kono
parents:
diff changeset
39 --
kono
parents:
diff changeset
40 -- Ensure that the exceptions are raised, handled / reraised successfully
kono
parents:
diff changeset
41 -- in protected procedures and functions. Use "others" handlers in the
kono
parents:
diff changeset
42 -- protected operations.
kono
parents:
diff changeset
43 --
kono
parents:
diff changeset
44 --
kono
parents:
diff changeset
45 -- CHANGE HISTORY:
kono
parents:
diff changeset
46 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
47 --
kono
parents:
diff changeset
48 --!
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package CB20006_0 is -- Package Semaphore.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Reraised_In_Function,
kono
parents:
diff changeset
53 Reraised_In_Procedure,
kono
parents:
diff changeset
54 Handled_In_Function_Caller,
kono
parents:
diff changeset
55 Handled_In_Procedure_Caller : Boolean := False;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 Resource_Overflow,
kono
parents:
diff changeset
58 Resource_Underflow : exception;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 protected type Counting_Semaphore (Max_Resources : Integer) is
kono
parents:
diff changeset
61 procedure Secure;
kono
parents:
diff changeset
62 function Resource_Limit_Exceeded return Boolean;
kono
parents:
diff changeset
63 procedure Release;
kono
parents:
diff changeset
64 private
kono
parents:
diff changeset
65 Count : Integer := Max_Resources;
kono
parents:
diff changeset
66 end Counting_Semaphore;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 end CB20006_0;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 --=================================================================--
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 with Report;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 package body CB20006_0 is -- Package Semaphore.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 protected body Counting_Semaphore is
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 procedure Secure is
kono
parents:
diff changeset
79 begin
kono
parents:
diff changeset
80 if (Count = 0) then -- No resources left to secure.
kono
parents:
diff changeset
81 raise Resource_Underflow;
kono
parents:
diff changeset
82 Report.Failed
kono
parents:
diff changeset
83 ("Program control not transferred by raise in Procedure Secure");
kono
parents:
diff changeset
84 else
kono
parents:
diff changeset
85 Count := Count - 1; -- Available resources decremented.
kono
parents:
diff changeset
86 end if;
kono
parents:
diff changeset
87 exception
kono
parents:
diff changeset
88 when Resource_Underflow =>
kono
parents:
diff changeset
89 Reraised_In_Procedure := True;
kono
parents:
diff changeset
90 raise; -- Exception propagated to caller.
kono
parents:
diff changeset
91 Report.Failed ("Exception not propagated to caller from Secure");
kono
parents:
diff changeset
92 when others =>
kono
parents:
diff changeset
93 Report.Failed ("Unexpected exception raised in Secure");
kono
parents:
diff changeset
94 end Secure;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 function Resource_Limit_Exceeded return Boolean is
kono
parents:
diff changeset
98 begin
kono
parents:
diff changeset
99 if (Count > Max_Resources) then
kono
parents:
diff changeset
100 raise Resource_Overflow; -- Exception used as control flow
kono
parents:
diff changeset
101 -- mechanism.
kono
parents:
diff changeset
102 Report.Failed
kono
parents:
diff changeset
103 ("Specific raise did not alter program control" &
kono
parents:
diff changeset
104 " from Resource_Limit_Exceeded");
kono
parents:
diff changeset
105 else
kono
parents:
diff changeset
106 return (False);
kono
parents:
diff changeset
107 end if;
kono
parents:
diff changeset
108 exception
kono
parents:
diff changeset
109 when others =>
kono
parents:
diff changeset
110 Reraised_In_Function := True;
kono
parents:
diff changeset
111 raise; -- Exception propagated to caller.
kono
parents:
diff changeset
112 Report.Failed ("Exception not propagated to caller" &
kono
parents:
diff changeset
113 " from Resource_Limit_Exceeded");
kono
parents:
diff changeset
114 end Resource_Limit_Exceeded;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Release is
kono
parents:
diff changeset
118 begin
kono
parents:
diff changeset
119 Count := Count + 1; -- Count of resources available
kono
parents:
diff changeset
120 -- incremented.
kono
parents:
diff changeset
121 if Resource_Limit_Exceeded then -- Call to protected operation
kono
parents:
diff changeset
122 Count := Count - 1; -- function that raises/reraises
kono
parents:
diff changeset
123 -- an exception.
kono
parents:
diff changeset
124 Report.Failed("Resource limit exceeded");
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 exception
kono
parents:
diff changeset
128 when others =>
kono
parents:
diff changeset
129 raise; -- Reraised and propagated again.
kono
parents:
diff changeset
130 Report.Failed ("Exception not reraised by procedure Release");
kono
parents:
diff changeset
131 end Release;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 end Counting_Semaphore;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 end CB20006_0;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 --=================================================================--
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 with CB20006_0; -- Package Semaphore.
kono
parents:
diff changeset
143 with Report;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 procedure CB20006 is
kono
parents:
diff changeset
146 begin
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 Report.Test ("CB20006", "Check that exceptions are raised and " &
kono
parents:
diff changeset
149 "handled / reraised and propagated " &
kono
parents:
diff changeset
150 "correctly by protected operations" );
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 Test_Block:
kono
parents:
diff changeset
153 declare
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 package Semaphore renames CB20006_0;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 Total_Resources_Available : constant := 1;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 Resources : Semaphore.Counting_Semaphore (Total_Resources_Available);
kono
parents:
diff changeset
160 -- An object of protected type.
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 Allocate_Resources:
kono
parents:
diff changeset
165 declare
kono
parents:
diff changeset
166 Loop_Count : Integer := Total_Resources_Available + 1;
kono
parents:
diff changeset
167 begin
kono
parents:
diff changeset
168 for I in 1..Loop_Count loop -- Force exception
kono
parents:
diff changeset
169 Resources.Secure;
kono
parents:
diff changeset
170 end loop;
kono
parents:
diff changeset
171 Report.Failed
kono
parents:
diff changeset
172 ("Exception not propagated from protected operation Secure");
kono
parents:
diff changeset
173 exception
kono
parents:
diff changeset
174 when Semaphore.Resource_Underflow => -- Exception propagated
kono
parents:
diff changeset
175 Semaphore.Handled_In_Procedure_Caller := True; -- from protected
kono
parents:
diff changeset
176 when others => -- procedure.
kono
parents:
diff changeset
177 Semaphore.Handled_In_Procedure_Caller := False;
kono
parents:
diff changeset
178 end Allocate_Resources;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 Deallocate_Resources:
kono
parents:
diff changeset
182 declare
kono
parents:
diff changeset
183 Loop_Count : Integer := Total_Resources_Available + 1;
kono
parents:
diff changeset
184 begin
kono
parents:
diff changeset
185 for I in 1..Loop_Count loop -- Force exception
kono
parents:
diff changeset
186 Resources.Release;
kono
parents:
diff changeset
187 end loop;
kono
parents:
diff changeset
188 Report.Failed
kono
parents:
diff changeset
189 ("Exception not propagated from protected operation Release");
kono
parents:
diff changeset
190 exception
kono
parents:
diff changeset
191 when Semaphore.Resource_Overflow => -- Exception propagated
kono
parents:
diff changeset
192 Semaphore.Handled_In_Function_Caller := True; -- from protected
kono
parents:
diff changeset
193 when others => -- function.
kono
parents:
diff changeset
194 Semaphore.Handled_In_Function_Caller := False;
kono
parents:
diff changeset
195 end Deallocate_Resources;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 if not (Semaphore.Reraised_In_Procedure and
kono
parents:
diff changeset
199 Semaphore.Reraised_In_Function and
kono
parents:
diff changeset
200 Semaphore.Handled_In_Procedure_Caller and
kono
parents:
diff changeset
201 Semaphore.Handled_In_Function_Caller)
kono
parents:
diff changeset
202 then -- Incorrect excpt. handling
kono
parents:
diff changeset
203 Report.Failed -- in protected operations.
kono
parents:
diff changeset
204 ("Improper exception handling/reraising by protected operations");
kono
parents:
diff changeset
205 end if;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 exception
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 when others =>
kono
parents:
diff changeset
210 Report.Failed ("Unexpected exception " &
kono
parents:
diff changeset
211 " raised and propagated in test");
kono
parents:
diff changeset
212 end Test_Block;
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 Report.Result;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 end CB20006;