-
Notifications
You must be signed in to change notification settings - Fork 138
/
integer.t
259 lines (214 loc) · 8 KB
/
integer.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
#! perl
# Copyright (C) 2001-2010, Parrot Foundation.
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/integer.t - Integers
=head1 SYNOPSIS
% prove t/native_pbc/integer.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 (4_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double
(linux-gcc-i386, freebsd-gcc, cygwin, ...)
_2 (4_le) i386 32 bit opcode_t, 4 byte intval, 12 byte long double
(linux-gcc-i386 or cygwin with --floatval="long double")
_3 (4_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 (8_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 (8_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")
=cut
=begin comment
See t/native_pbc/number.t for additional comments.
See tools/dev/mk_native_pbc to create the platform-specific native pbcs.
Test files on different architectures are generated by:
$ parrot -o i.pbc -a - <<EOF
print 0x10203040
end
EOF
$ mv i.pbc t/native_pbc/integer_${N}.pbc
The output of
$ pbc_dump -h i.pbc
should be included for reference.
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
my @archtest = qw(4_le 4_le 4_be 8_le 8_le 8_be 8_be 4_le);
sub this_arch {
return $PConfig{intvalsize}
. "_"
. (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();
# all should pass
my $todo = {};
my $skip = {};
# expected result
my $output = '270544960';
# test_pbc_integer(1, "(4_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double");
sub test_pbc_integer {
my $id = shift;
my $desc = shift;
my $file = "t/native_pbc/integer_$id.pbc";
my $cvt = "$archtest[$id-1]=>$arch";
my $skip_msg;
# check if this a platform where we can produce the needed file
if ($archtest[$id-1] eq $arch) {
$skip_msg = "Want to help? Regenerate $file "
. "with tools/dev/mk_native_pbc --noconf";
}
else {
$skip_msg = "$file is outdated. "
. "Need $archtest[$id-1] platform.";
}
# 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($file));
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, $output, "$cvt $desc",
todo => "$todo_msg" );
}
else {
skip $skip_msg, 1
if ($bc ne bc_version($file));
pbc_output_is( undef, $output, "$cvt $desc" );
}
}
}
# execute the file t/native_pbc/integer_1.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_integer(1, "(4_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double");
# adding --floatval="long 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_integer(2, "(4_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_integer(3, "(4_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_integer(4, "(8_le) i86_64 64 bit opcode_t, 8 byte intval, 8 byte double");
# adding --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_integer(5, "(8_le) i86_64 64 bit opcode_t, 8 byte intval, 16 byte long double");
# ppc/mips -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_integer(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_integer(7, "(8_be) big-endian 64 bit opcode_t, 8 byte intval, 16 byte long double");
# i386 --floatval=float
#test_pbc_integer(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: