2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
Iddec printf:proc;
|
|
|
32 |
Iddec main:proc;
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
Tokdec TRY :[EXP, NAT, EXP]EXP;
|
|
|
36 |
Tokdec ~Set_signal_handler: []EXP;
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
String passed = "passed\n";
|
|
|
40 |
String failed = "failed\n";
|
|
|
41 |
String s = "\n";
|
|
|
42 |
|
|
|
43 |
String s8 = "\n\nInt8:\n\n";
|
|
|
44 |
String u8 = "\n\nUInt8:\n\n";
|
|
|
45 |
String s16 = "\n\nInt16:\n\n";
|
|
|
46 |
String u16 = "\n\nUInt16:\n\n";
|
|
|
47 |
String s32 = "\n\nInt32:\n\n";
|
|
|
48 |
String u32 = "\n\nUInt32:\n\n";
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
Tokdef Int8 = [] VARIETY var_width (true,8);
|
|
|
52 |
Tokdef Int16 = [] VARIETY var_width (true,16);
|
|
|
53 |
Tokdef Int32 = [] VARIETY var_width (true,32);
|
|
|
54 |
|
|
|
55 |
Tokdef UInt8 = [] VARIETY var_width (false,8);
|
|
|
56 |
Tokdef UInt16 = [] VARIETY var_width (false,16);
|
|
|
57 |
Tokdef UInt32 = [] VARIETY var_width (false,32);
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
Tokdef Check = [e:EXP, p:EXP, f:EXP] EXP
|
|
|
61 |
{
|
|
|
62 |
TRY[{e; printf [top] (f)},
|
|
|
63 |
error_val(overflow),
|
|
|
64 |
printf [top] (p)];
|
|
|
65 |
};
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
Proc main = top()
|
|
|
70 |
Let p = make_null_ptr(alignment(Int))
|
|
|
71 |
Let msize = env_size(main)
|
|
|
72 |
Let tosize = msize .+.
|
|
|
73 |
(offset_pad(alignment(Int),shape_offset(Int)) .* 100(Int))
|
|
|
74 |
|
|
|
75 |
{
|
|
|
76 |
/* Check Int8 */
|
|
|
77 |
~Set_signal_handler;
|
|
|
78 |
printf [top] (s8);
|
|
|
79 |
|
|
|
80 |
Check [plus([overflow], 127(Int8), 1(Int8)), passed, failed];
|
|
|
81 |
Check [plus([overflow], 127(Int8), -1(Int8)), failed, passed];
|
|
|
82 |
Check [plus([overflow], -128(Int8), 1(Int8)), failed, passed];
|
|
|
83 |
Check [plus([overflow], -128(Int8), -1(Int8)), passed, failed];
|
|
|
84 |
|
|
|
85 |
Check [minus([overflow], 127(Int8), -1(Int8)), passed, failed];
|
|
|
86 |
Check [minus([overflow], 127(Int8), 1(Int8)), failed, passed];
|
|
|
87 |
Check [minus([overflow], -128(Int8), -1(Int8)), failed, passed];
|
|
|
88 |
Check [minus([overflow], -128(Int8), 1(Int8)), passed, failed];
|
|
|
89 |
|
|
|
90 |
Check [mult([overflow], -128(Int8), -1(Int8)), passed, failed];
|
|
|
91 |
Check [mult([overflow], -127(Int8), -1(Int8)), failed, passed];
|
|
|
92 |
Check [mult([overflow], 64(Int8), 2(Int8)), passed, failed];
|
|
|
93 |
Check [mult([overflow], 63(Int8), 2(Int8)), failed, passed];
|
|
|
94 |
|
|
|
95 |
Check [div2(impossible, [overflow], -128(Int8), -1(Int8)), passed, failed];
|
|
|
96 |
Check [div2(impossible, [overflow], -127(Int8), -1(Int8)), failed, passed];
|
|
|
97 |
|
|
|
98 |
Check [abs([overflow], -128(Int8)), passed, failed];
|
|
|
99 |
Check [abs([overflow], -127(Int8)), failed, passed];
|
|
|
100 |
|
|
|
101 |
Check [negate([overflow], -128(Int8)), passed, failed];
|
|
|
102 |
Check [negate([overflow], -127(Int8)), failed, passed];
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
/* Check UInt8 */
|
|
|
106 |
|
|
|
107 |
printf [top] (u8);
|
|
|
108 |
|
|
|
109 |
Check [plus([overflow], 255(UInt8), 1(UInt8)), passed, failed];
|
|
|
110 |
Check [plus([overflow], 0(UInt8), 1(UInt8)), failed, passed];
|
|
|
111 |
Check [minus([overflow], 0(UInt8), 1(UInt8)), passed, failed];
|
|
|
112 |
Check [minus([overflow], 255(UInt8), 1(UInt8)), failed, passed];
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
/* Check Int16 */
|
|
|
116 |
|
|
|
117 |
printf [top] (s16);
|
|
|
118 |
|
|
|
119 |
Check [plus([overflow], 32767(Int16), 1(Int16)), passed, failed];
|
|
|
120 |
Check [plus([overflow], 32767(Int16), -1(Int16)), failed, passed];
|
|
|
121 |
Check [plus([overflow], -32768(Int16), 1(Int16)), failed, passed];
|
|
|
122 |
Check [plus([overflow], -32768(Int16), -1(Int16)), passed, failed];
|
|
|
123 |
Check [minus([overflow], 32767(Int16), -1(Int16)), passed, failed];
|
|
|
124 |
Check [minus([overflow], 32767(Int16), 1(Int16)), failed, passed];
|
|
|
125 |
Check [minus([overflow], -32768(Int16), -1(Int16)), failed, passed];
|
|
|
126 |
Check [minus([overflow], -32768(Int16), 1(Int16)), passed, failed];
|
|
|
127 |
|
|
|
128 |
Check [mult([overflow], -32768(Int16), -1(Int16)), passed, failed];
|
|
|
129 |
Check [mult([overflow], -32767(Int16), -1(Int16)), failed, passed];
|
|
|
130 |
Check [mult([overflow], 16384(Int16), 2(Int16)), passed, failed];
|
|
|
131 |
Check [mult([overflow], 16383(Int16), 2(Int16)), failed, passed];
|
|
|
132 |
|
|
|
133 |
Check [div2(impossible, [overflow], -32768(Int16), -1(Int16)), passed, failed];
|
|
|
134 |
Check [div2(impossible, [overflow], -32767(Int16), -1(Int16)), failed, passed];
|
|
|
135 |
|
|
|
136 |
Check [abs([overflow], -32768(Int16)), passed, failed];
|
|
|
137 |
Check [abs([overflow], -32767(Int16)), failed, passed];
|
|
|
138 |
|
|
|
139 |
Check [negate([overflow], -32768(Int16)), passed, failed];
|
|
|
140 |
Check [negate([overflow], -32767(Int16)), failed, passed];
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
/* Check UInt16 */
|
|
|
144 |
|
|
|
145 |
printf [top] (u16);
|
|
|
146 |
|
|
|
147 |
Check [plus([overflow], 65535(UInt16), 1(UInt16)), passed, failed];
|
|
|
148 |
Check [plus([overflow], 0(UInt16), 1(UInt16)), failed, passed];
|
|
|
149 |
Check [minus([overflow], 0(UInt16), 1(UInt16)), passed, failed];
|
|
|
150 |
Check [minus([overflow], 65535(UInt16), 1(UInt16)), failed, passed];
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
/* Check Int32 */
|
|
|
154 |
|
|
|
155 |
printf [top] (s32);
|
|
|
156 |
|
|
|
157 |
Check [plus([overflow], 2147483647(Int32), 1(Int32)), passed, failed];
|
|
|
158 |
Check [plus([overflow], 2147483647(Int32), -1(Int32)), failed, passed];
|
|
|
159 |
Check [plus([overflow], -2147483648(Int32), 1(Int32)), failed, passed];
|
|
|
160 |
Check [plus([overflow], -2147483648(Int32), -1(Int32)), passed, failed];
|
|
|
161 |
|
|
|
162 |
Check [minus([overflow], 2147483647(Int32), -1(Int32)), passed, failed];
|
|
|
163 |
Check [minus([overflow], 2147483647(Int32), 1(Int32)), failed, passed];
|
|
|
164 |
Check [minus([overflow], -2147483648(Int32), -1(Int32)), failed, passed];
|
|
|
165 |
Check [minus([overflow], -2147483648(Int32), 1(Int32)), passed, failed];
|
|
|
166 |
|
|
|
167 |
Check [mult([overflow], -2147483648(Int32), -1(Int32)), passed, failed];
|
|
|
168 |
Check [mult([overflow], -2147483647(Int32), -1(Int32)), failed, passed];
|
|
|
169 |
Check [mult([overflow], 1073741824(Int32), 2(Int32)), passed, failed];
|
|
|
170 |
Check [mult([overflow], 1073741823(Int32), 2(Int32)), failed, passed];
|
|
|
171 |
|
|
|
172 |
Check [div2(impossible, [overflow], -2147483648(Int32), -1(Int32)), passed, failed];
|
|
|
173 |
Check [div2(impossible, [overflow], -2147483647(Int32), -1(Int32)), failed, passed];
|
|
|
174 |
|
|
|
175 |
Check [abs([overflow], -2147483648(Int32)), passed, failed];
|
|
|
176 |
Check [abs([overflow], -2147483647(Int32)), failed, passed];
|
|
|
177 |
|
|
|
178 |
Check [negate([overflow], -2147483648(Int32)), passed, failed];
|
|
|
179 |
Check [negate([overflow], -2147483647(Int32)), failed, passed];
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
/* Check UInt32 */
|
|
|
183 |
|
|
|
184 |
printf [top] (u32);
|
|
|
185 |
|
|
|
186 |
Check [plus([overflow], 4294967295(UInt32), 1(UInt32)), passed, failed];
|
|
|
187 |
Check [plus([overflow], 0(UInt32), 1(UInt32)), failed, passed];
|
|
|
188 |
Check [minus([overflow], 0(UInt32), 1(UInt32)), passed, failed];
|
|
|
189 |
Check [minus([overflow], 4294967295(UInt32), 1(UInt32)), failed, passed];
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
return(make_top)
|
|
|
193 |
};
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
Keep (main)
|