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 an Unchecked_Deallocation of a protected object
28 -- performs the required finalization on the protected object.
31 -- Test that finalization takes place when an Unchecked_Deallocation
32 -- deallocates a protected object with queued callers.
33 -- Try protected objects that have no other finalization code and
34 -- protected objects with user defined finalization.
38 -- 16 Jan 96 SAIC ACVC 2.1
39 -- 10 Jul 96 SAIC Fixed race condition noted by reviewers.
44 with Ada
.Finalization
;
46 Verbose
: constant Boolean := False;
47 Finalization_Occurred
: Boolean := False;
49 type Has_Finalization
is new Ada
.Finalization
.Limited_Controlled
with
51 Placeholder
: Integer;
53 procedure Finalize
(Object
: in out Has_Finalization
);
59 package body C940016_0
is
60 procedure Finalize
(Object
: in out Has_Finalization
) is
62 delay ImpDef
.Clear_Ready_Queue
;
63 Finalization_Occurred
:= True;
65 Report
.Comment
("in Finalize");
73 with Ada
.Finalization
;
75 with Ada
.Unchecked_Deallocation
;
79 Verbose
: constant Boolean := C940016_0
.Verbose
;
83 Report
.Test
("C940016", "Check that Unchecked_Deallocation of a" &
84 " protected object finalizes the" &
88 protected type Semaphore
is
94 protected body Semaphore
is
95 entry Wait
when Count
> 0 is
106 type pSem
is access Semaphore
;
107 procedure Zap_Semaphore
is new
108 Ada
.Unchecked_Deallocation
(Semaphore
, pSem
);
109 Sem_Ptr
: pSem
:= new Semaphore
;
111 -- positive confirmation that Blocker got the exception
112 Ok
: Boolean := False;
119 Report
.Failed
("Program_Error not raised in waiting task");
121 when Program_Error
=>
124 Report
.Comment
("Blocker received Program_Error");
127 Report
.Failed
("Wrong exception in Blocker");
131 -- wait for Blocker to get blocked on the semaphore
132 delay ImpDef
.Clear_Ready_Queue
;
133 Zap_Semaphore
(Sem_Ptr
);
134 -- make sure Blocker has time to complete
135 delay ImpDef
.Clear_Ready_Queue
* 2;
137 Report
.Failed
("finalization not properly performed");
138 -- Blocker is probably hung so kill it
144 Second_Check
: declare
145 -- here we want to check that the raising of Program_Error
146 -- occurs before the other finalization actions.
147 protected type Semaphore
is
151 Count
: Integer := 0;
152 Component
: C940016_0
.Has_Finalization
;
154 protected body Semaphore
is
155 entry Wait
when Count
> 0 is
166 type pSem
is access Semaphore
;
167 procedure Zap_Semaphore
is new
168 Ada
.Unchecked_Deallocation
(Semaphore
, pSem
);
169 Sem_Ptr
: pSem
:= new Semaphore
;
171 -- positive confirmation that Blocker got the exception
172 Ok
: Boolean := False;
179 Report
.Failed
("Program_Error not raised in waiting task 2");
181 when Program_Error
=>
183 if C940016_0
.Finalization_Occurred
then
184 Report
.Failed
("wrong order for finalization 2");
186 Report
.Comment
("Blocker received Program_Error 2");
189 Report
.Failed
("Wrong exception in Blocker 2");
192 begin -- Second_Check
193 -- wait for Blocker to get blocked on the semaphore
194 delay ImpDef
.Clear_Ready_Queue
;
195 Zap_Semaphore
(Sem_Ptr
);
196 -- make sure Blocker has time to complete
197 delay ImpDef
.Clear_Ready_Queue
* 2;
199 Report
.Failed
("finalization not properly performed 2");
200 -- Blocker is probably hung so kill it
203 if not C940016_0
.Finalization_Occurred
then
204 Report
.Failed
("user defined finalization didn't happen");