/
number.t
333 lines (288 loc) · 10 KB
/
number.t
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#! perl
# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Config;
use Parrot::BuildUtil;
use Parrot::Test skip_all => 'pending robust testing strategy, TT #357';
#use Parrot::Test tests => 7;
=head1 NAME
t/native_pbc/number.t - Floating-Point Numbers
=head1 SYNOPSIS
% prove t/native_pbc/number.t
=head1 DESCRIPTION
Tests word-size/float-type/endian-ness for different architectures.
These tests usually only work on updated native pbc test files.
See F<tools/dev/mk_native_pbc> to create the platform-specific
native pbcs.
=head1 PLATFORMS
_1 (8_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double
(linux-gcc-i386, freebsd-gcc, cygwin, ...)
_2 (12_le) i386 32 bit opcode_t, 4 byte intval, 12 byte long double
(linux-gcc-i386 or cygwin with --floatval="long double")
_3 (8_be) PPC BE 32 bit opcode_t, 4 byte intval, 8 byte double
(darwin-ppc or sparc32)
_4 (8_le) x86_64 64 bit opcode_t, 8 byte intval, 8 byte double
(linux-gcc-x86_64 resp. amd64, solaris-cc-64int)
_5 (16_le) x86_64 64 bit opcode_t, 8 byte intval, 16 byte long double
(linux-gcc-x86_64, solaris-cc-64int --floatval="long double")
_6 (8_be) big-endian 64 bit opcode_t, 8 byte intval, 8 byte double
(Sparc64/Solaris, MIPS irix or similar)
_7 (16_be) big-endian 64 bit opcode_t, 8 byte intval, 16 byte long double
(Sparc64/Solaris --floatval="long double")
_8 (4_le) i386 32 bit opcode_t, 4 byte intval, 4 byte single float
(linux-gcc-i386 or cygwin with --floatval="float")
_9 (4_be) big-endian 32 bit opcode_t, 4 byte intval, 4 byte single float
(darwin/ppc with --floatval="float")
=cut
=begin comment
# These are PBC files generated from t/op/number_1.pasm with
# different architectures.
# If your wordsize/floattype/endianess is not covered here
# please add it:
$ ./parrot -o n.pbc t/op/number_1.pasm
$ make pbc_dump
$ ./pbc_dump -h n.pbc
$ mv n.pbc t/native_pbc/number_$(N).pbc
# then
# - increase number of tests
# - include the pbc_dump header info for reference
# - put the file into MANIFEST
# - add the file as binary (svn add) and commit it
# thanks -leo and reini
On test failures please add the output of
$ ./pbc_dump -h t/native_pbc/number_${N}.pbc
into your report. We need your wordsize/floattype/endianess.
=cut
# TT #357: testmatrix for coverage overview
# float conversion src: left-side (pbc) to dest: upper-side (platform)
# 1: tested ok, 0: fails (skip), ?: not yet tested (todo)
# Note that the corresponding cvt_num* functions in F<pf_items.c> have odd names.
# The _le there is for reading.
my $testmatrix = <<EOF;
8_le 12_le 16_le 8_be 16_be
8_le 1 1 1 1 0
12_le 1 1 0 0 0
16_le 0 0 1 0 0
8_be 1 1 1 1 1
16_be 0 0 0 0 1
EOF
my $destarch = { '8_le' => [1,4], '12_le' => [2], '16_le' => [5],
'8_be' => [3,6], '16_be' => [7] };
# the reverse: which tests for which arch
my @archtest = qw(8_le 12_le 8_be 8_le 16_le 8_be 16_be);
# @todo lists of tests for your architecture.
# e.g. for arch 8_le => tests (8_be) => todo (3 6)
sub generate_skip_list {
my $arch = shift;
my $check = shift;
my %skip;
my @lines = split /\n/, $testmatrix;
my @dest = split /\s+/, shift @lines;
shift @dest unless $dest[0];
my $i = 0;
my %cols = map { $_ => $i++ } @dest;
my $col = $cols{$arch}; # the column for our arch
for my $s (@lines) {
my @s = split /\s+/, $s;
my $pbc = shift @s;
if ($s[$col] eq $check) {
for (@{$destarch->{$pbc}}) { $skip{$_}++ }
}
}
\%skip
}
# 16_le
sub this_arch {
return $PConfig{numvalsize}
. "_"
. (substr($PConfig{byteorder},0,2) eq '12' ? "le" : "be");
}
sub bc_version {
my $f = shift;
my $b;
open my $F, "<", "$f" or return "Can't open $f: $!";
binmode $F;
seek $F, 14, 0;
read $F, $b, 8;
my ($bc_major, $bc_minor) = unpack "cc", $b;
return ($bc_major . "." . $bc_minor);
}
my ( $bc_major, $bc_minor ) = Parrot::BuildUtil::get_bc_version();
my $bc = ($bc_major . "." . $bc_minor);
my $arch = this_arch();
my $todo = generate_skip_list($arch, '?');
my $skip = generate_skip_list($arch, '0');
my $output = << 'END_OUTPUT';
1
4
16
64
256
1024
4096
16384
65536
262144
1048576
4194304
16777216
67108864
268435456
1073741824
4294967296
17179869184
68719476736
274877906944
1099511627776
4398046511104
17592186044416
70368744177664
281474976710656
1.12589990684262e+15
END_OUTPUT
# 16=>8 drops some mantissa bits
my $output_16_8 = $output;
$output_16_8 =~ s/1\.12589990684262e\+15/1.12589990684058e+15/;
# test_pbc_number(1, "i386 8-byte double float, 32 bit opcode_t");
sub test_pbc_number {
my $id = shift;
my $desc = shift;
my $cvt = "$archtest[$id-1]=>$arch";
my $skip_msg;
my $expected = $output;
# check if this a platform where we can produce the needed file
if ($archtest[$id-1] eq $arch) {
$skip_msg = "Want to help? Regenerate t/native_pbc/number_$id.pbc "
. "with tools/dev/mk_native_pbc --noconf";
}
else {
$skip_msg = "t/native_pbc/number_$id.pbc is outdated. "
. "Need $archtest[$id-1] platform.";
}
if ($cvt =~ /^16_[bl]e=>8_/) {
$expected = $output_16_8;
}
# check if skip or todo
SKIP: {
if ( $skip->{$id} ) {
my $skip_msg = $skip->{$id};
if (length $skip_msg > 2) {
skip "$cvt $skip_msg", 1;
}
else {
skip "$cvt not yet implemented", 1;
}
}
elsif ( $todo->{$id} ) {
skip $skip_msg, 1
if ($bc ne bc_version("t/native_pbc/number_$id.pbc"));
my $todo_msg = $todo->{$id};
if (length $todo_msg > 2) {
$todo_msg = "$cvt $todo_msg"
}
else {
$todo_msg = "$cvt yet untested, TT #357. "
. "Please report success."
}
pbc_output_is( undef, $expected, "$cvt $desc",
todo => "$todo_msg" );
}
else {
skip $skip_msg, 1
if ($bc ne bc_version("t/native_pbc/number_$id.pbc"));
pbc_output_is( undef, $expected, "$cvt $desc" );
}
}
}
# execute t/native_pbc/number_*.pbc
#
# any ordinary intel 386 linux, cygwin, mingw, MSWin32, ...
# HEADER => [
# wordsize = 4 (interpreter's wordsize/INTVAL = 4/4)
# byteorder = 0 (interpreter's byteorder = 0)
# floattype = 0 (interpreter's NUMVAL_SIZE = 8)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(1, "(8_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double");
# HEADER => [
# wordsize = 4 (interpreter's wordsize/INTVAL = 4/4)
# byteorder = 0 (interpreter's byteorder = 0)
# floattype = 1 (interpreter's NUMVAL_SIZE = 12)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(2, "(12_le) i386 32 bit opcode_t, 4 byte intval, 12 byte long double");
# darwin/ppc:
# HEADER => [
# wordsize = 4 (interpreter's wordsize/INTVAL = 4/4)
# byteorder = 1 (interpreter's byteorder = 1)
# floattype = 0 (interpreter's NUMVAL_SIZE = 8)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(3, "(8_be) PPC BE 32 bit opcode_t, 4 byte intval, 8 byte double");
# any ordinary 64-bit intel unix:
# HEADER => [
# wordsize = 8 (interpreter's wordsize/INTVAL = 8/8)
# byteorder = 0 (interpreter's byteorder = 0)
# floattype = 0 (interpreter's NUMVAL_SIZE = 8)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(4, "(8_le) x86_64 64 bit opcode_t, 8 byte intval, 8 byte double");
# i86_64 with floatval='long double'
# HEADER => [
# wordsize = 8 (interpreter's wordsize/INTVAL = 8/8)
# byteorder = 0 (interpreter's byteorder = 0)
# floattype = 2 (interpreter's NUMVAL_SIZE = 16)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(5, "(16_le) x86_64 64 bit opcode_t, 8 byte intval, 16 byte long double");
# PowerPC64 -m64
# HEADER => [
# wordsize = 8 (interpreter's wordsize/INTVAL = 8/8)
# byteorder = 1 (interpreter's byteorder = 0)
# floattype = 0 (interpreter's NUMVAL_SIZE = 8)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# *need* endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(6, "(8_be) big-endian 64 bit opcode_t, 8 byte intval, 8 byte double");
# ppc/mips -m64 --floatval="long double"
# HEADER => [
# wordsize = 8 (interpreter's wordsize/INTVAL = 8/8)
# byteorder = 1 (interpreter's byteorder = 0)
# floattype = 2 (interpreter's NUMVAL_SIZE = 8)
# parrot-version 0.9.1, bytecode-version 3.38
# UUID type = 0, UUID size = 0
# *need* endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_number(7, "(16_be) big-endian 64 bit opcode_t, 8 byte intval, 16 byte long double");
# i386 --floatval=float
#test_pbc_number(8, "(4_le) i386 32 bit opcode_t, 4 byte intval, 4 byte single float");
# ppc -m32 --floatval=float
#test_pbc_number(9, "(4_le) big-endian 32 bit opcode_t, 4 byte intval, 4 byte single float");
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: