annotate gcc/testsuite/ada/acats/tests/cb/cb20007.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 -- CB20007.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 can be directly propagated to
kono
parents:
diff changeset
28 -- the calling unit by 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 propagated directly from the protected
kono
parents:
diff changeset
37 -- operations to the calling unit.
kono
parents:
diff changeset
38 --
kono
parents:
diff changeset
39 -- Ensure that the exceptions are raised and correctly propagated directly
kono
parents:
diff changeset
40 -- to the calling unit from protected procedures and functions.
kono
parents:
diff changeset
41 --
kono
parents:
diff changeset
42 --
kono
parents:
diff changeset
43 -- CHANGE HISTORY:
kono
parents:
diff changeset
44 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
45 --
kono
parents:
diff changeset
46 --!
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package CB20007_0 is -- Package Semaphore.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 Handled_In_Function_Caller,
kono
parents:
diff changeset
51 Handled_In_Procedure_Caller : Boolean := False;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 Resource_Overflow,
kono
parents:
diff changeset
54 Resource_Underflow : exception;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 protected type Counting_Semaphore (Max_Resources : Integer) is
kono
parents:
diff changeset
57 procedure Secure;
kono
parents:
diff changeset
58 function Resource_Limit_Exceeded return Boolean;
kono
parents:
diff changeset
59 procedure Release;
kono
parents:
diff changeset
60 private
kono
parents:
diff changeset
61 Count : Integer := Max_Resources;
kono
parents:
diff changeset
62 end Counting_Semaphore;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 end CB20007_0;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 --=================================================================--
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 with Report;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 package body CB20007_0 is -- Package Semaphore.
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 protected body Counting_Semaphore is
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 procedure Secure is
kono
parents:
diff changeset
75 begin
kono
parents:
diff changeset
76 if (Count = 0) then -- No resources left to secure.
kono
parents:
diff changeset
77 raise Resource_Underflow;
kono
parents:
diff changeset
78 Report.Failed ("Program control not transferred by raise");
kono
parents:
diff changeset
79 else
kono
parents:
diff changeset
80 Count := Count - 1; -- Available resources decremented.
kono
parents:
diff changeset
81 end if;
kono
parents:
diff changeset
82 -- No exception handlers here, direct propagation to calling unit.
kono
parents:
diff changeset
83 end Secure;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 function Resource_Limit_Exceeded return Boolean is
kono
parents:
diff changeset
87 begin
kono
parents:
diff changeset
88 if (Count > Max_Resources) then
kono
parents:
diff changeset
89 raise Resource_Overflow; -- Exception used as control flow
kono
parents:
diff changeset
90 -- mechanism.
kono
parents:
diff changeset
91 Report.Failed ("Program control not transferred by raise");
kono
parents:
diff changeset
92 else
kono
parents:
diff changeset
93 return (False);
kono
parents:
diff changeset
94 end if;
kono
parents:
diff changeset
95 -- No exception handlers here, direct propagation to calling unit.
kono
parents:
diff changeset
96 end Resource_Limit_Exceeded;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 procedure Release is
kono
parents:
diff changeset
100 begin
kono
parents:
diff changeset
101 Count := Count + 1; -- Count of resources available
kono
parents:
diff changeset
102 -- incremented.
kono
parents:
diff changeset
103 if Resource_Limit_Exceeded then -- Call to protected operation
kono
parents:
diff changeset
104 Count := Count - 1; -- function that raises an
kono
parents:
diff changeset
105 -- exception.
kono
parents:
diff changeset
106 Report.Failed("Resource limit exceeded");
kono
parents:
diff changeset
107 end if;
kono
parents:
diff changeset
108 -- No exception handler here for exception raised in function.
kono
parents:
diff changeset
109 -- Exception will propagate directly to calling unit.
kono
parents:
diff changeset
110 end Release;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 end Counting_Semaphore;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 end CB20007_0;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 --=================================================================--
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 with CB20007_0; -- Package Semaphore.
kono
parents:
diff changeset
122 with Report;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 procedure CB20007 is
kono
parents:
diff changeset
125 begin
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 Test_Block:
kono
parents:
diff changeset
128 declare
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 package Semaphore renames CB20007_0;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 Total_Resources_Available : constant := 1;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 Resources : Semaphore.Counting_Semaphore (Total_Resources_Available);
kono
parents:
diff changeset
135 -- An object of protected type.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 begin
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 Report.Test ("CB20007", "Check that exceptions are raised and can " &
kono
parents:
diff changeset
140 "be directly propagated to the calling unit " &
kono
parents:
diff changeset
141 "by protected operations" );
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 Allocate_Resources:
kono
parents:
diff changeset
144 declare
kono
parents:
diff changeset
145 Loop_Count : Integer := Total_Resources_Available + 1;
kono
parents:
diff changeset
146 begin -- Force exception.
kono
parents:
diff changeset
147 for I in 1..Loop_Count loop
kono
parents:
diff changeset
148 Resources.Secure;
kono
parents:
diff changeset
149 end loop;
kono
parents:
diff changeset
150 Report.Failed ("Exception not propagated from protected " &
kono
parents:
diff changeset
151 " operation in Allocate_Resources");
kono
parents:
diff changeset
152 exception
kono
parents:
diff changeset
153 when Semaphore.Resource_Underflow => -- Exception prop.
kono
parents:
diff changeset
154 Semaphore.Handled_In_Procedure_Caller := True; -- from protected
kono
parents:
diff changeset
155 -- procedure.
kono
parents:
diff changeset
156 when others =>
kono
parents:
diff changeset
157 Report.Failed ("Unknown exception during resource allocation");
kono
parents:
diff changeset
158 end Allocate_Resources;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 Deallocate_Resources:
kono
parents:
diff changeset
162 declare
kono
parents:
diff changeset
163 Loop_Count : Integer := Total_Resources_Available + 1;
kono
parents:
diff changeset
164 begin -- Force exception.
kono
parents:
diff changeset
165 for I in 1..Loop_Count loop
kono
parents:
diff changeset
166 Resources.Release;
kono
parents:
diff changeset
167 end loop;
kono
parents:
diff changeset
168 Report.Failed ("Exception not propagated from protected " &
kono
parents:
diff changeset
169 "operation in Deallocate_Resources");
kono
parents:
diff changeset
170 exception
kono
parents:
diff changeset
171 when Semaphore.Resource_Overflow => -- Exception prop
kono
parents:
diff changeset
172 Semaphore.Handled_In_Function_Caller := True; -- from protected
kono
parents:
diff changeset
173 -- function.
kono
parents:
diff changeset
174 when others =>
kono
parents:
diff changeset
175 Report.Failed ("Exception raised during resource deallocation");
kono
parents:
diff changeset
176 end Deallocate_Resources;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 if not (Semaphore.Handled_In_Procedure_Caller and -- Incorrect exception
kono
parents:
diff changeset
180 Semaphore.Handled_In_Function_Caller) -- handling in
kono
parents:
diff changeset
181 then -- protected ops.
kono
parents:
diff changeset
182 Report.Failed
kono
parents:
diff changeset
183 ("Improper exception propagation by protected operations");
kono
parents:
diff changeset
184 end if;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 exception
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 when others =>
kono
parents:
diff changeset
189 Report.Failed ("Unexpected exception " &
kono
parents:
diff changeset
190 " raised and propagated in test");
kono
parents:
diff changeset
191 end Test_Block;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 Report.Result;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 end CB20007;