annotate gcc/testsuite/ada/acats/tests/c9/c940016.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 -- C940016.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 -- TEST OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that an Unchecked_Deallocation of a protected object
kono
parents:
diff changeset
28 -- performs the required finalization on the protected object.
kono
parents:
diff changeset
29 --
kono
parents:
diff changeset
30 -- TEST DESCRIPTION:
kono
parents:
diff changeset
31 -- Test that finalization takes place when an Unchecked_Deallocation
kono
parents:
diff changeset
32 -- deallocates a protected object with queued callers.
kono
parents:
diff changeset
33 -- Try protected objects that have no other finalization code and
kono
parents:
diff changeset
34 -- protected objects with user defined finalization.
kono
parents:
diff changeset
35 --
kono
parents:
diff changeset
36 --
kono
parents:
diff changeset
37 -- CHANGE HISTORY:
kono
parents:
diff changeset
38 -- 16 Jan 96 SAIC ACVC 2.1
kono
parents:
diff changeset
39 -- 10 Jul 96 SAIC Fixed race condition noted by reviewers.
kono
parents:
diff changeset
40 --
kono
parents:
diff changeset
41 --!
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 with Ada.Finalization;
kono
parents:
diff changeset
45 package C940016_0 is
kono
parents:
diff changeset
46 Verbose : constant Boolean := False;
kono
parents:
diff changeset
47 Finalization_Occurred : Boolean := False;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 type Has_Finalization is new Ada.Finalization.Limited_Controlled with
kono
parents:
diff changeset
50 record
kono
parents:
diff changeset
51 Placeholder : Integer;
kono
parents:
diff changeset
52 end record;
kono
parents:
diff changeset
53 procedure Finalize (Object : in out Has_Finalization);
kono
parents:
diff changeset
54 end C940016_0;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 with Report;
kono
parents:
diff changeset
58 with ImpDef;
kono
parents:
diff changeset
59 package body C940016_0 is
kono
parents:
diff changeset
60 procedure Finalize (Object : in out Has_Finalization) is
kono
parents:
diff changeset
61 begin
kono
parents:
diff changeset
62 delay ImpDef.Clear_Ready_Queue;
kono
parents:
diff changeset
63 Finalization_Occurred := True;
kono
parents:
diff changeset
64 if Verbose then
kono
parents:
diff changeset
65 Report.Comment ("in Finalize");
kono
parents:
diff changeset
66 end if;
kono
parents:
diff changeset
67 end Finalize;
kono
parents:
diff changeset
68 end C940016_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 with Ada.Finalization;
kono
parents:
diff changeset
74 with C940016_0;
kono
parents:
diff changeset
75 with Ada.Unchecked_Deallocation;
kono
parents:
diff changeset
76 with ImpDef;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 procedure C940016 is
kono
parents:
diff changeset
79 Verbose : constant Boolean := C940016_0.Verbose;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 begin
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 Report.Test ("C940016", "Check that Unchecked_Deallocation of a" &
kono
parents:
diff changeset
84 " protected object finalizes the" &
kono
parents:
diff changeset
85 " protected object");
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 First_Check: declare
kono
parents:
diff changeset
88 protected type Semaphore is
kono
parents:
diff changeset
89 entry Wait;
kono
parents:
diff changeset
90 procedure Signal;
kono
parents:
diff changeset
91 private
kono
parents:
diff changeset
92 Count : Integer := 0;
kono
parents:
diff changeset
93 end Semaphore;
kono
parents:
diff changeset
94 protected body Semaphore is
kono
parents:
diff changeset
95 entry Wait when Count > 0 is
kono
parents:
diff changeset
96 begin
kono
parents:
diff changeset
97 Count := Count - 1;
kono
parents:
diff changeset
98 end Wait;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Signal is
kono
parents:
diff changeset
101 begin
kono
parents:
diff changeset
102 Count := Count + 1;
kono
parents:
diff changeset
103 end Signal;
kono
parents:
diff changeset
104 end Semaphore;
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 type pSem is access Semaphore;
kono
parents:
diff changeset
107 procedure Zap_Semaphore is new
kono
parents:
diff changeset
108 Ada.Unchecked_Deallocation (Semaphore, pSem);
kono
parents:
diff changeset
109 Sem_Ptr : pSem := new Semaphore;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 -- positive confirmation that Blocker got the exception
kono
parents:
diff changeset
112 Ok : Boolean := False;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 task Blocker;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 task body Blocker is
kono
parents:
diff changeset
117 begin
kono
parents:
diff changeset
118 Sem_Ptr.Wait;
kono
parents:
diff changeset
119 Report.Failed ("Program_Error not raised in waiting task");
kono
parents:
diff changeset
120 exception
kono
parents:
diff changeset
121 when Program_Error =>
kono
parents:
diff changeset
122 Ok := True;
kono
parents:
diff changeset
123 if Verbose then
kono
parents:
diff changeset
124 Report.Comment ("Blocker received Program_Error");
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126 when others =>
kono
parents:
diff changeset
127 Report.Failed ("Wrong exception in Blocker");
kono
parents:
diff changeset
128 end Blocker;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 begin -- First_Check
kono
parents:
diff changeset
131 -- wait for Blocker to get blocked on the semaphore
kono
parents:
diff changeset
132 delay ImpDef.Clear_Ready_Queue;
kono
parents:
diff changeset
133 Zap_Semaphore (Sem_Ptr);
kono
parents:
diff changeset
134 -- make sure Blocker has time to complete
kono
parents:
diff changeset
135 delay ImpDef.Clear_Ready_Queue * 2;
kono
parents:
diff changeset
136 if not Ok then
kono
parents:
diff changeset
137 Report.Failed ("finalization not properly performed");
kono
parents:
diff changeset
138 -- Blocker is probably hung so kill it
kono
parents:
diff changeset
139 abort Blocker;
kono
parents:
diff changeset
140 end if;
kono
parents:
diff changeset
141 end First_Check;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 Second_Check : declare
kono
parents:
diff changeset
145 -- here we want to check that the raising of Program_Error
kono
parents:
diff changeset
146 -- occurs before the other finalization actions.
kono
parents:
diff changeset
147 protected type Semaphore is
kono
parents:
diff changeset
148 entry Wait;
kono
parents:
diff changeset
149 procedure Signal;
kono
parents:
diff changeset
150 private
kono
parents:
diff changeset
151 Count : Integer := 0;
kono
parents:
diff changeset
152 Component : C940016_0.Has_Finalization;
kono
parents:
diff changeset
153 end Semaphore;
kono
parents:
diff changeset
154 protected body Semaphore is
kono
parents:
diff changeset
155 entry Wait when Count > 0 is
kono
parents:
diff changeset
156 begin
kono
parents:
diff changeset
157 Count := Count - 1;
kono
parents:
diff changeset
158 end Wait;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 procedure Signal is
kono
parents:
diff changeset
161 begin
kono
parents:
diff changeset
162 Count := Count + 1;
kono
parents:
diff changeset
163 end Signal;
kono
parents:
diff changeset
164 end Semaphore;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 type pSem is access Semaphore;
kono
parents:
diff changeset
167 procedure Zap_Semaphore is new
kono
parents:
diff changeset
168 Ada.Unchecked_Deallocation (Semaphore, pSem);
kono
parents:
diff changeset
169 Sem_Ptr : pSem := new Semaphore;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 -- positive confirmation that Blocker got the exception
kono
parents:
diff changeset
172 Ok : Boolean := False;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 task Blocker;
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 task body Blocker is
kono
parents:
diff changeset
177 begin
kono
parents:
diff changeset
178 Sem_Ptr.Wait;
kono
parents:
diff changeset
179 Report.Failed ("Program_Error not raised in waiting task 2");
kono
parents:
diff changeset
180 exception
kono
parents:
diff changeset
181 when Program_Error =>
kono
parents:
diff changeset
182 Ok := True;
kono
parents:
diff changeset
183 if C940016_0.Finalization_Occurred then
kono
parents:
diff changeset
184 Report.Failed ("wrong order for finalization 2");
kono
parents:
diff changeset
185 elsif Verbose then
kono
parents:
diff changeset
186 Report.Comment ("Blocker received Program_Error 2");
kono
parents:
diff changeset
187 end if;
kono
parents:
diff changeset
188 when others =>
kono
parents:
diff changeset
189 Report.Failed ("Wrong exception in Blocker 2");
kono
parents:
diff changeset
190 end Blocker;
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 begin -- Second_Check
kono
parents:
diff changeset
193 -- wait for Blocker to get blocked on the semaphore
kono
parents:
diff changeset
194 delay ImpDef.Clear_Ready_Queue;
kono
parents:
diff changeset
195 Zap_Semaphore (Sem_Ptr);
kono
parents:
diff changeset
196 -- make sure Blocker has time to complete
kono
parents:
diff changeset
197 delay ImpDef.Clear_Ready_Queue * 2;
kono
parents:
diff changeset
198 if not Ok then
kono
parents:
diff changeset
199 Report.Failed ("finalization not properly performed 2");
kono
parents:
diff changeset
200 -- Blocker is probably hung so kill it
kono
parents:
diff changeset
201 abort Blocker;
kono
parents:
diff changeset
202 end if;
kono
parents:
diff changeset
203 if not C940016_0.Finalization_Occurred then
kono
parents:
diff changeset
204 Report.Failed ("user defined finalization didn't happen");
kono
parents:
diff changeset
205 end if;
kono
parents:
diff changeset
206 end Second_Check;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 Report.Result;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 end C940016;