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 several access types can share the same pool.
29 -- Check that any exception propagated by Allocate is
30 -- propagated by the allocator.
32 -- Check that for an access type S, S'Max_Size_In_Storage_Elements
33 -- denotes the maximum values for Size_In_Storage_Elements that will
34 -- be requested via Allocate.
37 -- After checking correct operation of the tree packages, the limits of
38 -- the storage pools (first the shared user defined storage pool, then
39 -- the system storage pool) are intentionally exceeded. The test checks
40 -- that the correct exception is raised.
44 -- The following files comprise this test:
46 -- FDB0A00.A (foundation code)
51 -- 10 AUG 95 SAIC Initial version
52 -- 07 MAY 96 SAIC Disambiguated for 2.1
53 -- 13 FEB 97 PWB.CTA Reduced minimum allowable
54 -- Max_Size_In_Storage_Units, for implementations
55 -- with larger storage units
56 -- 25 JAN 01 RLB Removed dubious checks on Max_Size_In_Storage_Units;
57 -- tightened important one.
61 ---------------------------------------------------------- FDB0A00.Pool2
63 package FDB0A00
.Pool2
is
64 Pond
: Stack_Heap
( 5_000
);
67 ---------------------------------------------------------------- CDB0A02_2
73 type Small_Tree
is access Small_Cell
;
75 for Small_Tree
'Storage_Pool use FDB0A00
.Pool2
.Pond
; -- first usage
77 type Small_Cell
is record
79 Left
,Right
: Small_Tree
;
82 procedure Insert
( Item
: Character; On_Tree
: in out Small_Tree
);
84 procedure Traverse
( The_Tree
: Small_Tree
);
86 procedure Defoliate
( The_Tree
: in out Small_Tree
);
88 procedure TC_Exceed_Pool
;
90 Pool_Max_Elements
: constant := 6000;
91 -- to guarantee overflow in TC_Exceed_Pool
95 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
99 with Unchecked_Deallocation
;
100 package body CDB0A02_2
is
101 procedure Deallocate
is new Unchecked_Deallocation
(Small_Cell
,Small_Tree
);
103 -- Sort: zeros on the left, ones on the right...
104 procedure Insert
( Item
: Character; On_Tree
: in out Small_Tree
) is
106 if On_Tree
= null then
107 On_Tree
:= new Small_Cell
'(Item,null,null);
108 elsif Item > On_Tree.Data then
109 Insert(Item,On_Tree.Right);
111 Insert(Item,On_Tree.Left);
115 procedure Traverse( The_Tree : Small_Tree ) is
117 if The_Tree = null then
118 null; -- how very symmetrical
120 Traverse(The_Tree.Left);
121 TCTouch.Touch(The_Tree.Data);
122 Traverse(The_Tree.Right);
126 procedure Defoliate( The_Tree : in out Small_Tree ) is
129 if The_Tree.Left /= null then
130 Defoliate(The_Tree.Left);
133 if The_Tree.Right /= null then
134 Defoliate(The_Tree.Right);
137 Deallocate(The_Tree);
141 procedure TC_Exceed_Pool is
142 Wild_Branch : Small_Tree;
144 for Ever in 1..Pool_Max_Elements loop
145 Wild_Branch := new Small_Cell'('a', Wild_Branch
, Wild_Branch
);
146 TCTouch
.Validate
("A","Allocating element for overflow");
148 Report
.Failed
(" Pool_Overflow not raised on exceeding user pool size");
150 when FDB0A00
.Pool_Overflow
=> null; -- anticipated case
152 Report
.Failed
("wrong exception raised in user Exceed_Pool");
157 ---------------------------------------------------------------- CDB0A02_3
159 -- This package is essentially identical to CDB0A02_2, except that the size
160 -- of a cell is significantly larger. This is used to check that different
161 -- access types may share a single pool
167 type Large_Tree
is access Large_Cell
;
169 for Large_Tree
'Storage_Pool use FDB0A00
.Pool2
.Pond
; -- second usage
171 type Large_Cell
is record
173 Extra_Data
: String(1..2);
174 Left
,Right
: Large_Tree
;
177 procedure Insert
( Item
: Character; On_Tree
: in out Large_Tree
);
179 procedure Traverse
( The_Tree
: Large_Tree
);
181 procedure Defoliate
( The_Tree
: in out Large_Tree
);
185 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
188 with Unchecked_Deallocation
;
189 package body CDB0A02_3
is
190 procedure Deallocate
is new Unchecked_Deallocation
(Large_Cell
,Large_Tree
);
192 -- Sort: zeros on the left, ones on the right...
193 procedure Insert
( Item
: Character; On_Tree
: in out Large_Tree
) is
195 if On_Tree
= null then
196 On_Tree
:= new Large_Cell
'(Item,(Item,Item),null,null);
197 elsif Item > On_Tree.Data then
198 Insert(Item,On_Tree.Right);
200 Insert(Item,On_Tree.Left);
204 procedure Traverse( The_Tree : Large_Tree ) is
206 if The_Tree = null then
207 null; -- how very symmetrical
209 Traverse(The_Tree.Left);
210 TCTouch.Touch(The_Tree.Data);
211 Traverse(The_Tree.Right);
215 procedure Defoliate( The_Tree : in out Large_Tree ) is
218 if The_Tree.Left /= null then
219 Defoliate(The_Tree.Left);
222 if The_Tree.Right /= null then
223 Defoliate(The_Tree.Right);
226 Deallocate(The_Tree);
232 ------------------------------------------------------------------ CDB0A02
236 with System.Storage_Elements;
243 Banyan : CDB0A02_2.Small_Tree;
244 Torrey : CDB0A02_3.Large_Tree;
246 use type CDB0A02_2.Small_Tree;
247 use type CDB0A02_3.Large_Tree;
249 Countess1 : constant String := "Ada ";
250 Countess2 : constant String := "Augusta ";
251 Countess3 : constant String := "Lovelace";
252 Cenosstu : constant String := " AALaaacdeeglostuuv";
253 Insertion : constant String := "AAAAAAAAAAAAAAAAAAAA"
254 & "AAAAAAAAAAAAAAAAAAAA";
255 Deallocation : constant String := "DDDDDDDDDDDDDDDDDDDD";
257 begin -- Main test procedure.
259 Report.Test ("CDB0A02", "Check that several access types can share " &
260 "the same pool. Check that any exception " &
261 "propagated by Allocate is propagated by the " &
262 "allocator. Check that for an access type S, " &
263 "S'Max_Size_In_Storage_Elements denotes the " &
264 "maximum values for Size_In_Storage_Elements " &
265 "that will be requested via Allocate" );
267 -- Check that access types can share the same pool.
269 for Count in Countess1'Range loop
270 CDB0A02_2.Insert( Countess1(Count), Banyan );
273 for Count in Countess1'Range loop
274 CDB0A02_3.Insert( Countess1(Count), Torrey );
277 for Count in Countess2'Range loop
278 CDB0A02_2.Insert( Countess2(Count), Banyan );
281 for Count in Countess2'Range loop
282 CDB0A02_3.Insert( Countess2(Count), Torrey );
285 for Count in Countess3'Range loop
286 CDB0A02_2.Insert( Countess3(Count), Banyan );
289 for Count in Countess3'Range loop
290 CDB0A02_3.Insert( Countess3(Count), Torrey );
293 TCTouch.Validate(Insertion, "Allocate calls via CDB0A02_2" );
296 CDB0A02_2.Traverse(Banyan);
297 TCTouch.Validate(Cenosstu, "Traversal of Banyan" );
299 CDB0A02_3.Traverse(Torrey);
300 TCTouch.Validate(Cenosstu, "Traversal of Torrey" );
302 CDB0A02_2.Defoliate(Banyan);
303 TCTouch.Validate(Deallocation, "Deforestation of Banyan" );
304 TCTouch.Assert(Banyan = null, "Banyan Deallocation result not null");
306 CDB0A02_3.Defoliate(Torrey);
307 TCTouch.Validate(Deallocation, "Deforestation of Torrey" );
308 TCTouch.Assert(Torrey = null, "Torrey Deallocation result not null");
310 -- Check that for an access type S, S'Max_Size_In_Storage_Elements
311 -- denotes the maximum values for Size_In_Storage_Elements that will
312 -- be requested via Allocate. (Of course, all we can do is check that
313 -- whatever was requested of Allocate did not exceed the values of the
316 TCTouch.Assert( FDB0A00.TC_Largest_Request in 1 ..
317 System.Storage_Elements.Storage_Count'Max (
318 CDB0A02_2.Small_Cell'Max_Size_In_Storage_Elements,
319 CDB0A02_3.Large_Cell'Max_Size_In_Storage_Elements),
320 "An object of excessive size was allocated. Size: "
321 & System.Storage_Elements.Storage_Count'Image(FDB0A00.TC_Largest_Request));
323 -- Check that an exception raised in Allocate is propagated by the allocator.
325 CDB0A02_2.TC_Exceed_Pool;