aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/ada/acats/tests/cd/cd20001.a
blob: 21f9738733bee6600bcedd13b9f53d357525f606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
-- CD20001.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that for packed records the components are packed as tightly
--      as possible subject to the Size of the component subtypes.
--      Specifically check that Boolean objects are packed one to a bit.
--
--      Check that the Component_Size for a packed array type is less than
--      or equal to the smallest of those factors of the word size that are
--      greater than or equal to the Size of the component subtype.
--      
-- TEST DESCRIPTION:
--      This test defines and packs several types, and checks that the sizes
--      of the resulting objects is as expected.
--
-- APPLICABILITY CRITERIA:
--      All implementations must attempt to compile this test.
--
--      For implementations validating against Systems Programming Annex (C):
--        this test must execute and report PASSED.
--
--      For implementations not validating against Annex C:
--        this test may report compile time errors at one or more points
--        indicated by "-- ANX-C RQMT", in which case it may be graded as
--        inapplicable.  Otherwise, the test must execute and report PASSED.
--
--
-- CHANGE HISTORY:
--      22 JUL 95   SAIC   Initial version
--      08 MAY 96   SAIC   Strengthened for 2.1
--      29 JAN 98   EDS    Deleted check that Component_Size is really a
--                         factor of Word_Size.
--!

----------------------------------------------------------------- CD20001_0

with System;
package CD20001_0 is

  type Wordlong_Bool_Array is array(1..System.Word_Size) of Boolean;
    pragma Pack(Wordlong_Bool_Array);                         -- ANX-C RQMT

  type Def_Rep_Components is range 0..2**(System.Storage_Unit-2);

  type Spec_Rep_Components is range 0..2**(System.Storage_Unit-2);
    for Spec_Rep_Components'Size use System.Storage_Unit;     -- ANX-C RQMT

  type Packed_Array_Def_Components is array(1..32) of Def_Rep_Components;
    pragma Pack(Packed_Array_Def_Components);                 -- ANX-C RQMT

  type Packed_Array_Spec_Components is array(1..32) of Spec_Rep_Components;
    pragma Pack(Packed_Array_Spec_Components);                -- ANX-C RQMT

  procedure TC_Check_Values;

end CD20001_0;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
with TCTouch;
package body CD20001_0 is

  procedure TC_Check_Values is
    My_Word      : Wordlong_Bool_Array := (others => False);

    Cited_Unit   : Spec_Rep_Components := 0;

    Packed_Array : Packed_Array_Def_Components := (others => 0);

    Cited_Packed : Packed_Array_Spec_Components := (others => 0);

  begin
    TCTouch.Assert( My_Word'Size = System.Word_Size,
       "pragma Pack on array of Booleans does not pack one Boolean per bit" );

    TCTouch.Assert( My_Word'Component_Size = 1,
                    "size of Boolean array component not 1 bit");

    TCTouch.Assert( Cited_Unit'Size = System.Storage_Unit,
                    "Object specified to be Storage_Unit bits not " &
                    "Storage_Unit bits in size");

    TCTouch.Assert( Packed_Array'Component_Size <= System.Storage_Unit,
                    "Packed array component expected to be less than or " &
                    "equal to Storage_Unit bits in size is greater than " &
                    "Storage_Unit bits in size");

    TCTouch.Assert( Cited_Packed'Component_Size = System.Storage_Unit,
                    "Array component specified to be Storage_Unit " &
                    "bits not Storage_Unit bits in size");

  end TC_Check_Values;

end CD20001_0;

----------------------------------------------------------------- CD20001_1

with System;
package CD20001_1 is

  type Bits_2  is range 0..2**2-1;
    for Bits_2'Size use 2;                                    -- ANX-C RQMT

  type Bits_3  is range 0..2**3-1;
    for Bits_3'Size use 3;                                    -- ANX-C RQMT

  type Bits_7  is range 0..2**7-1;
    for Bits_7'Size use 7;                                    -- ANX-C RQMT

  type Bits_8  is range 0..2**8-1;
    for Bits_8'Size use 8;                                    -- ANX-C RQMT

  type Bits_9  is range 0..2**9-1;
    for Bits_9'Size use 9;                                    -- ANX-C RQMT

  type Bits_15 is range 0..2**15-1;
    for Bits_15'Size use 15;                                  -- ANX-C RQMT

  type Pact_Aray_2  is array(0..31) of Bits_2;
    pragma Pack( Pact_Aray_2 );                               -- ANX-C RQMT

  type Pact_Aray_3  is array(0..31) of Bits_3;
    pragma Pack( Pact_Aray_3 );                               -- ANX-C RQMT

  type Pact_Aray_7  is array(0..31) of Bits_7;
    pragma Pack( Pact_Aray_7 );                               -- ANX-C RQMT

  type Pact_Aray_8  is array(0..31) of Bits_8;
    pragma Pack( Pact_Aray_8 );                               -- ANX-C RQMT

  type Pact_Aray_9  is array(0..31) of Bits_9;
    pragma Pack( Pact_Aray_9 );                               -- ANX-C RQMT

  type Pact_Aray_15 is array(0..31) of Bits_15;
    pragma Pack( Pact_Aray_15 );                              -- ANX-C RQMT


  procedure TC_Check_Values;

end CD20001_1;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
with TCTouch;
package body CD20001_1 is

   function Next_Factor ( Value : Positive ) return Integer is
   -- Returns the factor of Word_Size that is next larger than Value.
   -- If Value is greater than Word_Size, then returns Word_Size.
     Test   : Integer := Value;
     Found  : Boolean := False;
  begin  -- Next_Factor
     while not Found and Test <= System.Word_Size loop
       if System.Word_Size mod Test = 0 then
          Found := True;
       else
          Test := Test + 1;
       end if;
     end loop;
     if Found then
        return Test;
     else
        return System.Word_Size;
     end if;
  end Next_Factor;

  procedure TC_Check_Values is
  begin
  
    if Pact_Aray_2'Component_Size > Next_Factor ( Bits_2'Size ) then
       Report.Failed
          ( "2 bit element Packed Array'Component_Size too big" );
    end if;

    TCTouch.Assert( Pact_Aray_2'Component_Size <= Pact_Aray_2'Size,
                    "2 bit Component_Size greater than array size" );

    if Pact_Aray_3'Component_Size > Next_Factor ( Bits_3'Size ) then
       Report.Failed
          ( "3 bit element Packed Array'Component_Size too big" );
    end if;

    TCTouch.Assert( Pact_Aray_3'Component_Size <= Pact_Aray_3'Size,
                    "3 bit Component_Size greater than array size" );

    if Pact_Aray_7'Component_Size > Next_Factor ( Bits_7'Size ) then
       Report.Failed
          ( "7 bit element Packed Array'Component_Size too big" );
    end if;

    TCTouch.Assert( Pact_Aray_7'Component_Size <= Pact_Aray_7'Size,
                    "7 bit Component_Size greater than array size" );

    if Pact_Aray_8'Component_Size > Next_Factor ( Bits_8'Size ) then
       Report.Failed
          ( "8 bit element Packed Array'Component_Size too big" );
    end if;

    TCTouch.Assert( Pact_Aray_8'Component_Size <= Pact_Aray_8'Size,
                    "8 bit Component_Size greater than array size" );

    if System.Word_Size > 8 then

      if Pact_Aray_9'Component_Size > Next_Factor ( Bits_9'Size ) then
         Report.Failed
            ( "9 bit element Packed Array'Component_Size too big" );
      end if;

      TCTouch.Assert( Pact_Aray_9'Component_Size <= Pact_Aray_9'Size,
                    "9 bit Component_Size greater than array size" );

      if Pact_Aray_15'Component_Size > Next_Factor ( Bits_15'Size ) then
         Report.Failed
            ( "15 bit element Packed Array'Component_Size too big" );
      end if;

      TCTouch.Assert( Pact_Aray_15'Component_Size <= Pact_Aray_15'Size,
                    "15 bit Component_Size greater than array size" );

    end if;

  end TC_Check_Values;

end CD20001_1;

------------------------------------------------------------------- CD20001

with Report;
with CD20001_0;
with CD20001_1;

procedure CD20001 is

begin  -- Main test procedure.

  Report.Test ("CD20001", "Check that packed records are packed as tightly " &
                          "as possible.  Check that Boolean objects are " &
                          "packed one to a bit. " &
                          "Check that the Component_Size for a packed " &
                          "array type is the value which is less than or " &
                          "equal to the Size of the component type, " &
                          "rounded up to the nearest factor of word_size" );
   
  CD20001_0.TC_Check_Values;

  CD20001_1.TC_Check_Values;

  Report.Result;

end CD20001;