OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [c4/] [c460008.a] - Blame information for rev 720

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 720 jeremybenn
-- C460008.A
2
--
3
--                             Grant of Unlimited Rights
4
--
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
14
--     to do so.
15
--
16
--                                    DISCLAIMER
17
--
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.
24
--*
25
--
26
-- OBJECTIVE:
27
--     Check that conversion to a modular type raises Constraint_Error
28
--     when the operand value is outside the base range of the modular type.
29
--
30
-- TEST DESCRIPTION:
31
--      Test conversion from integer, float, fixed and decimal types to
32
--      modular types.  Test conversion to mod 255, mod 256 and mod 258
33
--      to test the boundaries of 8 bit (+/-) unsigned numbers.
34
--      Test operand values that are negative, the value of the mod,
35
--      and greater than the value of the mod.
36
--      Declare a generic test procedure and instantiate it for each of the
37
--      unsigned types for each operand type.
38
--
39
--
40
-- CHANGE HISTORY:
41
--      04 OCT 95   SAIC   Initial version
42
--      15 MAY 96   SAIC   Revised for 2.1
43
--      24 NOV 98   RLB    Moved decimal cases into new test, C460011, to
44
--                         prevent this test from being inapplicable to
45
--                         implementations not supporting decimal types.
46
--
47
--!
48
 
49
------------------------------------------------------------------- C460008
50
 
51
with Report;
52
 
53
procedure C460008 is
54
 
55
  Shy_By_One   : constant := 2**8-1;
56
  Heavy_By_Two : constant := 2**8+2;
57
 
58
  type Unsigned_Edge_8 is mod Shy_By_One;
59
  type Unsigned_8_Bit  is mod 2**8;
60
  type Unsigned_Over_8 is mod Heavy_By_Two;
61
 
62
  NPC : constant String := " not properly converted";
63
 
64
  procedure Assert( Truth: Boolean; Message: String ) is
65
  begin
66
    if not Truth then
67
      Report.Failed(Message);
68
    end if;
69
  end Assert;
70
 
71
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
72
 
73
  generic
74
    type Source is range <>;
75
    type Target is mod <>;
76
  procedure Integer_Conversion_Check( For_The_Value : Source;
77
                                      Message       : String );
78
 
79
  procedure Integer_Conversion_Check( For_The_Value : Source;
80
                                      Message       : String ) is
81
 
82
    Item : Target;
83
 
84
  begin
85
    Item := Target( For_The_Value );
86
    Report.Failed("Int expected Constraint_Error " & Message);
87
    -- the call to Comment is to make the otherwise dead assignment to
88
    -- Item live.
89
    -- To avoid invoking C_E on a call to 'Image in Report.Failed that
90
    -- could cause a false pass
91
   Report.Comment("Value of" & Target'Image(Item) & NPC);
92
  exception
93
    when Constraint_Error => null; -- expected case
94
    when others => Report.Failed("Int Raised wrong exception " & Message);
95
  end Integer_Conversion_Check;
96
 
97
  procedure Int_To_Short is
98
    new Integer_Conversion_Check( Integer, Unsigned_Edge_8 );
99
 
100
  procedure Int_To_Eight is
101
    new Integer_Conversion_Check( Integer, Unsigned_8_Bit );
102
 
103
  procedure Int_To_Wide is
104
    new Integer_Conversion_Check( Integer, Unsigned_Over_8 );
105
 
106
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
107
 
108
  generic
109
    type Source is digits <>;
110
    type Target is mod <>;
111
  procedure Float_Conversion_Check( For_The_Value : Source;
112
                                    Message       : String );
113
 
114
  procedure Float_Conversion_Check( For_The_Value : Source;
115
                                    Message       : String ) is
116
 
117
    Item : Target;
118
 
119
  begin
120
    Item := Target( For_The_Value );
121
    Report.Failed("Flt expected Constraint_Error " & Message);
122
    Report.Comment("Value of" & Target'Image(Item) & NPC);
123
  exception
124
    when Constraint_Error => null; -- expected case
125
    when others => Report.Failed("Flt raised wrong exception " & Message);
126
  end Float_Conversion_Check;
127
 
128
  procedure Float_To_Short is
129
    new Float_Conversion_Check( Float, Unsigned_Edge_8 );
130
 
131
  procedure Float_To_Eight is
132
    new Float_Conversion_Check( Float, Unsigned_8_Bit );
133
 
134
  procedure Float_To_Wide is
135
    new Float_Conversion_Check( Float, Unsigned_Over_8 );
136
 
137
  function Identity( Root_Beer: Float ) return Float is
138
    -- a knockoff of Report.Ident_Int for type Float
139
    Nothing : constant Float := 0.0;
140
  begin
141
    if Report.Ident_Bool( Root_Beer = Nothing ) then
142
      return Nothing;
143
    else
144
      return Root_Beer;
145
    end if;
146
  end Identity;
147
 
148
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
149
 
150
  generic
151
    type Source is delta <>;
152
    type Target is mod <>;
153
  procedure Fixed_Conversion_Check( For_The_Value : Source;
154
                                    Message       : String );
155
 
156
  procedure Fixed_Conversion_Check( For_The_Value : Source;
157
                                    Message       : String ) is
158
 
159
    Item : Target;
160
 
161
  begin
162
    Item := Target( For_The_Value );
163
    Report.Failed("Fix expected Constraint_Error " & Message);
164
    Report.Comment("Value of" & Target'Image(Item) & NPC);
165
  exception
166
    when Constraint_Error => null; -- expected case
167
    when others => Report.Failed("Fix raised wrong exception " & Message);
168
  end Fixed_Conversion_Check;
169
 
170
  procedure Fixed_To_Short is
171
    new Fixed_Conversion_Check( Duration, Unsigned_Edge_8 );
172
 
173
  procedure Fixed_To_Eight is
174
    new Fixed_Conversion_Check( Duration, Unsigned_8_Bit );
175
 
176
  procedure Fixed_To_Wide is
177
    new Fixed_Conversion_Check( Duration, Unsigned_Over_8 );
178
 
179
  function Identity( A_Stitch: Duration ) return Duration is
180
    Threadbare : constant Duration := 0.0;
181
  begin
182
    if Report.Ident_Bool( A_Stitch = Threadbare ) then
183
      return Threadbare;
184
    else
185
      return A_Stitch;
186
    end if;
187
  end Identity;
188
 
189
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
190
 
191
begin  -- Main test procedure.
192
 
193
  Report.Test ("C460008", "Check that conversion to " &
194
                          "a modular type raises Constraint_Error when " &
195
                          "the operand value is outside the base range " &
196
                          "of the modular type" );
197
 
198
 
199
  -- Integer Error cases
200
 
201
  Int_To_Short( Report.Ident_Int( -1 ), "I2S Dynamic, Negative" );
202
  Int_To_Short( Report.Ident_Int( Shy_By_One ), "I2S Dynamic, At_Mod" );
203
  Int_To_Short( Report.Ident_Int( Heavy_By_Two+1 ), "I2S Dynamic, Over_Mod" );
204
 
205
  Int_To_Eight( -Shy_By_One, "I28 Static,  Negative" );
206
  Int_To_Eight( 2**8, "I28 Static,  At_Mod" );
207
  Int_To_Eight( Heavy_By_Two+1, "I28 Static,  Over_Mod" );
208
 
209
  Int_To_Wide ( Report.Ident_Int( -(Heavy_By_Two*2) ),
210
                "I2W Dynamic, Negative" );
211
  Int_To_Wide ( Heavy_By_Two, "I2W Static,  At_Mod" );
212
  Int_To_Wide ( Report.Ident_Int( Heavy_By_Two*2 ), "I2W Dynamic, Over_Mod" );
213
 
214
  -- Float Error cases
215
 
216
  Float_To_Short( -13.31, "F2S Static,  Negative" );
217
  Float_To_Short( Identity ( Float(Shy_By_One)), "F2S Dynamic, At_Mod" );
218
  Float_To_Short( 6378.388, "F2S Static,  Over_Mod" );
219
 
220
  Float_To_Eight( Identity( -99.3574 ), "F28 Dynamic, Negative" );
221
  Float_To_Eight( 2.0**8, "F28 Static,  At_Mod" );
222
  Float_To_Eight( 2.0**9, "F28 Static,  Over_Mod" );
223
 
224
  Float_To_Wide ( -0.54953_93129_81644, "FTW Static,  Negative" );
225
  Float_To_Wide ( Identity( 2.0**8 +2.0 ), "FTW Dynamic, At_Mod" );
226
  Float_To_Wide ( Identity( 2.0**8 +2.5001 ), "FTW Dynamic, Over_Mod" );
227
  Float_To_Wide ( Identity( Float'Last ), "FTW Dynamic, Over_Mod" );
228
 
229
  -- Fixed Error cases
230
 
231
  Fixed_To_Short( Identity( -5.00 ), "D2S Dynamic, Negative" );
232
  Fixed_To_Short( Shy_By_One * 1.0, "D2S Static,  At_Mod" );
233
  Fixed_To_Short( 1995.9, "D2S Static,  Over_Mod" );
234
 
235
  Fixed_To_Eight( -0.5, "D28 Static, Negative" );
236
  Fixed_To_Eight( 2.0*128, "D28 Static,  At_Mod" );
237
  Fixed_To_Eight( Identity( 2001.2 ), "D28 Dynamic, Over_Mod" );
238
 
239
  Fixed_To_Wide ( Duration'First, "D2W Static,  Negative" );
240
  Fixed_To_Wide ( Identity( 2*128.0 +2.0 ), "D2W Dynamic, At_Mod" );
241
  Fixed_To_Wide ( Duration'Last, "D2W Static,  Over_Mod" );
242
 
243
  -- having made it this far, the rest is downhill...
244
  -- check a few, correct, edge cases, and we're done
245
 
246
  Eye_Dew: declare
247
    A_Float   : Float    := 0.0;
248
    Your_Time : Duration := 0.0;
249
    Number    : Integer  := 0;
250
 
251
    Little   : Unsigned_Edge_8;
252
    Moderate : Unsigned_8_Bit;
253
    Big      : Unsigned_Over_8;
254
 
255
  begin
256
    Little := Unsigned_Edge_8(A_Float);
257
    Assert( Little = 0, "Float => Little, 0");
258
 
259
 
260
    Moderate := Unsigned_8_Bit (Your_Time);
261
    Assert( Moderate = 0, "Your_Time => Moderate, 0");
262
 
263
    Big := Unsigned_Over_8 (Number);
264
    Assert( Big = 0, "Number => Big, 0");
265
 
266
    A_Float   := 2.0**8-2.0;
267
    Your_Time := 2.0*128-2.0;
268
    Number    := 2**8;
269
 
270
    Little := Unsigned_Edge_8(A_Float);
271
    Assert( Little = 254, "Float => Little, 254");
272
 
273
    Little := Unsigned_Edge_8(Your_Time);
274
    Assert( Little = 254, "Your_Time => Little, 254");
275
 
276
    Big := Unsigned_Over_8 (A_Float + 2.0);
277
    Assert( Big = 256, "Sense => Big, 256");
278
 
279
    Big := Unsigned_Over_8 (Number);
280
    Assert( Big = 256, "Number => Big, 256");
281
 
282
  end Eye_Dew;
283
 
284
  Report.Result;
285
 
286
end C460008;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.