summaryrefslogtreecommitdiffstats
path: root/tests/signness
blob: 8c29fe4df048846fd7e0844331fbc1b24a89015f (plain) (blame)
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# -*- sh -*-
# See LICENSE file for copyright and license details.

test $(parse-signed.tu 32767 32 0) = inval
test $(make-signed.tu 32767 32 0) = inval

check_signed () {
	test $(parse-signed.tu $1 $2 $3) = $4
	test $(make-signed.tu $1 $2 $4) = $3
}

ucheck_signed () {
	check_signed "$@"
	test $(make-signed.tu $1 $2 -$4) = $3
}

for sign in $(getnamelist SIGN); do
	signn=$(getnum SIGN $sign)
	if test $sign = UNDETERMINED; then
		ucheck_signed $signn 1 0 0
		ucheck_signed $signn 1 1 1
		ucheck_signed $signn 2 0 0
		ucheck_signed $signn 2 1 1
		ucheck_signed $signn 2 2 2
		ucheck_signed $signn 2 3 3
		ucheck_signed $signn 4 4 4
		ucheck_signed $signn 4 9 9
		ucheck_signed $signn 4 A A
		ucheck_signed $signn 4 C C
		ucheck_signed $signn 4 F F
		ucheck_signed $signn 7 00 00
		ucheck_signed $signn 7 08 08
		ucheck_signed $signn 7 70 70
		ucheck_signed $signn 7 7F 7F
		ucheck_signed $signn 8 00 00
		ucheck_signed $signn 8 08 08
		ucheck_signed $signn 8 80 80
		ucheck_signed $signn 8 FF FF
		ucheck_signed $signn 16 0001 0001
		ucheck_signed $signn 16 0020 0020
		ucheck_signed $signn 16 0300 0300
		ucheck_signed $signn 16 4000 4000
		ucheck_signed $signn 16 0008 0008
		ucheck_signed $signn 16 0090 0090
		ucheck_signed $signn 16 0A00 0A00
		ucheck_signed $signn 16 B000 B000
		ucheck_signed $signn 17 08100 08100
		ucheck_signed $signn 17 00820 00820
		ucheck_signed $signn 17 00083 00083
		ucheck_signed $signn 17 04008 04008
		ucheck_signed $signn 17 11008 11008
		ucheck_signed $signn 17 10280 10280
		ucheck_signed $signn 17 10830 10830
		ucheck_signed $signn 17 18004 18004
		ucheck_signed $signn 32 12345678 12345678
		ucheck_signed $signn 32 9ABCDEF0 9ABCDEF0
		ucheck_signed $signn 32 87654321 87654321
		ucheck_signed $signn 32 0FEDCBA9 0FEDCBA9
		ucheck_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
		ucheck_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
		ucheck_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
		ucheck_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
		ucheck_signed $signn 64 89ABCDEF01234567 89ABCDEF01234567
		ucheck_signed $signn 64 9ABCDEF012345678 9ABCDEF012345678
		ucheck_signed $signn 64 ABCDEF0123456789 ABCDEF0123456789
		ucheck_signed $signn 64 BCDEF0123456789A BCDEF0123456789A
		ucheck_signed $signn 64 0000000000000000 0000000000000000
		ucheck_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
		ucheck_signed $signn 64 8000000000000000 8000000000000000
		ucheck_signed $signn 64 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF

	elif test $sign = SIGN_MAGNITUDE; then
		check_signed $signn 1 0 0
		check_signed $signn 1 1 -0
		check_signed $signn 2 0 0
		check_signed $signn 2 1 1
		check_signed $signn 2 2 -0
		check_signed $signn 2 3 -1
		check_signed $signn 4 4 4
		check_signed $signn 4 9 -1
		check_signed $signn 4 A -2
		check_signed $signn 4 C -4
		check_signed $signn 4 F -7
		check_signed $signn 7 00 00
		check_signed $signn 7 08 08
		check_signed $signn 7 70 -30
		check_signed $signn 7 7F -3F
		check_signed $signn 8 00 00
		check_signed $signn 8 08 08
		check_signed $signn 8 80 -00
		check_signed $signn 8 FF -7F
		check_signed $signn 16 0001 0001
		check_signed $signn 16 0020 0020
		check_signed $signn 16 0300 0300
		check_signed $signn 16 4000 4000
		check_signed $signn 16 0008 0008
		check_signed $signn 16 0090 0090
		check_signed $signn 16 0A00 0A00
		check_signed $signn 16 B000 -3000
		check_signed $signn 17 08100 08100
		check_signed $signn 17 00820 00820
		check_signed $signn 17 00083 00083
		check_signed $signn 17 04008 04008
		check_signed $signn 17 11008 -01008
		check_signed $signn 17 10280 -00280
		check_signed $signn 17 10830 -00830
		check_signed $signn 17 18004 -08004
		check_signed $signn 32 12345678 12345678
		check_signed $signn 32 9ABCDEF0 -1ABCDEF0
		check_signed $signn 32 87654321 -07654321
		check_signed $signn 32 0FEDCBA9 0FEDCBA9
		check_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
		check_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
		check_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
		check_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
		check_signed $signn 64 89ABCDEF01234567 -09ABCDEF01234567
		check_signed $signn 64 9ABCDEF012345678 -1ABCDEF012345678
		check_signed $signn 64 ABCDEF0123456789 -2BCDEF0123456789
		check_signed $signn 64 BCDEF0123456789A -3CDEF0123456789A
		check_signed $signn 64 0000000000000000 0000000000000000
		check_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
		check_signed $signn 64 8000000000000000 -0000000000000000
		check_signed $signn 64 FFFFFFFFFFFFFFFF -7FFFFFFFFFFFFFFF

	elif test $sign = ONES_COMPLEMENT; then
		check_signed $signn 1 0 0
		check_signed $signn 1 1 -0
		check_signed $signn 2 0 0
		check_signed $signn 2 1 1
		check_signed $signn 2 2 -1
		check_signed $signn 2 3 -0
		check_signed $signn 4 4 4
		check_signed $signn 4 9 -6
		check_signed $signn 4 A -5
		check_signed $signn 4 C -3
		check_signed $signn 4 F -0
		check_signed $signn 7 00 00
		check_signed $signn 7 08 08
		check_signed $signn 7 70 -0F
		check_signed $signn 7 7F -00
		check_signed $signn 8 00 00
		check_signed $signn 8 08 08
		check_signed $signn 8 80 -7F
		check_signed $signn 8 FF -00
		check_signed $signn 16 0001 0001
		check_signed $signn 16 0020 0020
		check_signed $signn 16 0300 0300
		check_signed $signn 16 4000 4000
		check_signed $signn 16 0008 0008
		check_signed $signn 16 0090 0090
		check_signed $signn 16 0A00 0A00
		check_signed $signn 16 B000 -4FFF
		check_signed $signn 17 08100 08100
		check_signed $signn 17 00820 00820
		check_signed $signn 17 00083 00083
		check_signed $signn 17 04008 04008
		check_signed $signn 17 11008 -0EFF7
		check_signed $signn 17 10280 -0FD7F
		check_signed $signn 17 10830 -0F7CF
		check_signed $signn 17 18004 -07FFB
		check_signed $signn 32 12345678 12345678
		check_signed $signn 32 9ABCDEF0 -6543210F
		check_signed $signn 32 87654321 -789ABCDE
		check_signed $signn 32 0FEDCBA9 0FEDCBA9
		check_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
		check_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
		check_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
		check_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
		check_signed $signn 64 89ABCDEF01234567 -76543210FEDCBA98
		check_signed $signn 64 9ABCDEF012345678 -6543210FEDCBA987
		check_signed $signn 64 ABCDEF0123456789 -543210FEDCBA9876
		check_signed $signn 64 BCDEF0123456789A -43210FEDCBA98765
		check_signed $signn 64 0000000000000000 0000000000000000
		check_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
		check_signed $signn 64 8000000000000000 -7FFFFFFFFFFFFFFF
		check_signed $signn 64 FFFFFFFFFFFFFFFF -0000000000000000

	elif test $sign = TWOS_COMPLEMENT; then
		check_signed $signn 1 0 0
		check_signed $signn 1 1 -1
		check_signed $signn 2 0 0
		check_signed $signn 2 1 1
		check_signed $signn 2 2 -2
		check_signed $signn 2 3 -1
		check_signed $signn 4 4 4
		check_signed $signn 4 9 -7
		check_signed $signn 4 A -6
		check_signed $signn 4 C -4
		check_signed $signn 4 F -1
		check_signed $signn 7 00 00
		check_signed $signn 7 08 08
		check_signed $signn 7 70 -10
		check_signed $signn 7 7F -01
		check_signed $signn 8 00 00
		check_signed $signn 8 08 08
		check_signed $signn 8 80 -80
		check_signed $signn 8 FF -01
		check_signed $signn 16 0001 0001
		check_signed $signn 16 0020 0020
		check_signed $signn 16 0300 0300
		check_signed $signn 16 4000 4000
		check_signed $signn 16 0008 0008
		check_signed $signn 16 0090 0090
		check_signed $signn 16 0A00 0A00
		check_signed $signn 16 B000 -5000
		check_signed $signn 17 08100 08100
		check_signed $signn 17 00820 00820
		check_signed $signn 17 00083 00083
		check_signed $signn 17 04008 04008
		check_signed $signn 17 11008 -0EFF8
		check_signed $signn 17 10280 -0FD80
		check_signed $signn 17 10830 -0F7D0
		check_signed $signn 17 18004 -07FFC
		check_signed $signn 32 12345678 12345678
		check_signed $signn 32 9ABCDEF0 -65432110
		check_signed $signn 32 87654321 -789ABCDF
		check_signed $signn 32 0FEDCBA9 0FEDCBA9
		check_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
		check_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
		check_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
		check_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
		check_signed $signn 64 89ABCDEF01234567 -76543210FEDCBA99
		check_signed $signn 64 9ABCDEF012345678 -6543210FEDCBA988
		check_signed $signn 64 ABCDEF0123456789 -543210FEDCBA9877
		check_signed $signn 64 BCDEF0123456789A -43210FEDCBA98766
		check_signed $signn 64 0000000000000000 0000000000000000
		check_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
		check_signed $signn 64 8000000000000000 -8000000000000000
		check_signed $signn 64 FFFFFFFFFFFFFFFF -0000000000000001
		test $(make-signed.tu $signn 1 -0) = 0
		test $(make-signed.tu $signn 4 -0) = 0

	elif test $sign = EXCESS_HALF; then
		check_signed $signn 1 0 -1
		check_signed $signn 1 1 0
		check_signed $signn 2 0 -2
		check_signed $signn 2 1 -1
		check_signed $signn 2 2 0
		check_signed $signn 2 3 1
		check_signed $signn 4 4 -4
		check_signed $signn 4 9 1
		check_signed $signn 4 A 2
		check_signed $signn 4 C 4
		check_signed $signn 4 F 7
		check_signed $signn 7 00 -40
		check_signed $signn 7 08 -38
		check_signed $signn 7 70 30
		check_signed $signn 7 7F 3F
		check_signed $signn 8 00 -80
		check_signed $signn 8 08 -78
		check_signed $signn 8 80 00
		check_signed $signn 8 FF 7F
		check_signed $signn 16 0001 -7FFF
		check_signed $signn 16 0020 -7FE0
		check_signed $signn 16 0300 -7D00
		check_signed $signn 16 4000 -4000
		check_signed $signn 16 0008 -7FF8
		check_signed $signn 16 0090 -7F70
		check_signed $signn 16 0A00 -7600
		check_signed $signn 16 B000 3000
		check_signed $signn 17 08100 -07F00
		check_signed $signn 17 00820 -0F7E0
		check_signed $signn 17 00083 -0FF7D
		check_signed $signn 17 04008 -0BFF8
		check_signed $signn 17 11008 01008
		check_signed $signn 17 10280 00280
		check_signed $signn 17 10830 00830
		check_signed $signn 17 18004 08004
		check_signed $signn 32 12345678 -6DCBA988
		check_signed $signn 32 9ABCDEF0 1ABCDEF0
		check_signed $signn 32 87654321 07654321
		check_signed $signn 32 0FEDCBA9 -70123457
		check_signed $signn 64 0123456789ABCDEF -7EDCBA9876543211
		check_signed $signn 64 123456789ABCDEF0 -6DCBA98765432110
		check_signed $signn 64 23456789ABCDEF01 -5CBA9876543210FF
		check_signed $signn 64 3456789ABCDEF012 -4BA9876543210FEE
		check_signed $signn 64 89ABCDEF01234567 09ABCDEF01234567
		check_signed $signn 64 9ABCDEF012345678 1ABCDEF012345678
		check_signed $signn 64 ABCDEF0123456789 2BCDEF0123456789
		check_signed $signn 64 BCDEF0123456789A 3CDEF0123456789A
		check_signed $signn 64 0000000000000000 -8000000000000000
		check_signed $signn 64 7FFFFFFFFFFFFFFF -0000000000000001
		check_signed $signn 64 8000000000000000 0000000000000000
		check_signed $signn 64 FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
		test $(make-signed.tu $signn 1 -0) = 1
		test $(make-signed.tu $signn 4 -0) = 8

	else
		printf 'Missing test for LIBSYSCALLS_SIGN_%s in tests/signness\n' "$sign" >&2
		false
	fi
	test $(parse-signed.tu $signn 0 0) = inval
	test $(parse-signed.tu $signn 32767 0) = inval
	test $(make-signed.tu $signn 0 0) = inval
	test $(make-signed.tu $signn 32767 0) = inval
done