Skip to content

Commit

Permalink
refactor t/native_pbc/ test ids
Browse files Browse the repository at this point in the history
Parrot::Test had the odd assumption that testing pbc can only be done for
native_pbc tests, and that the tests must be of _<int>++.pbc.
We pass now the filename as first arg to pbc_output_is() and check if it exists.
So we can use now readable test names.

mk_packfile_pbc refactor with t/native_pbc/testdata/annotations.pir
  • Loading branch information
Reini Urban committed Aug 29, 2012
1 parent 0314d17 commit 02feb07
Show file tree
Hide file tree
Showing 25 changed files with 141 additions and 178 deletions.
35 changes: 18 additions & 17 deletions MANIFEST
Expand Up @@ -1735,28 +1735,29 @@ t/manifest/03-regenerate_skip.t [test]
t/manifest/04-alt_file.t [test]
t/manifest/05-alt_skip.t [test]
t/manifest/README.pod []doc
t/native_pbc/annotations.pbc [test]
t/native_pbc/header.t [test]
t/native_pbc/integer.t [test]
t/native_pbc/integer_1.pbc [test]
t/native_pbc/integer_3.pbc [test]
t/native_pbc/integer_4.pbc [test]
t/native_pbc/integer_6.pbc [test]
t/native_pbc/Test.pm [test]
t/native_pbc/integer_4_be.pbc [test]
t/native_pbc/integer_4_le.pbc [test]
t/native_pbc/integer_8_be.pbc [test]
t/native_pbc/integer_8_le.pbc [test]
t/native_pbc/number.t [test]
t/native_pbc/number_1.pbc [test]
t/native_pbc/number_2.pbc [test]
t/native_pbc/number_3.pbc [test]
t/native_pbc/number_4.pbc [test]
t/native_pbc/number_5.pbc [test]
t/native_pbc/number_6.pbc [test]
t/native_pbc/number_7.pbc [test]
t/native_pbc/number_4_12_le.pbc [test]
t/native_pbc/number_4_8_be.pbc [test]
t/native_pbc/number_4_8_le.pbc [test]
t/native_pbc/number_8_16_be.pbc [test]
t/native_pbc/number_8_16_le.pbc [test]
t/native_pbc/number_8_8_be.pbc [test]
t/native_pbc/number_8_8_le.pbc [test]
t/native_pbc/string.t [test]
t/native_pbc/string_1.pbc [test]
t/native_pbc/string_3.pbc [test]
t/native_pbc/string_4.pbc [test]
t/native_pbc/string_6.pbc [test]
t/native_pbc/string_4_be.pbc [test]
t/native_pbc/string_4_le.pbc [test]
t/native_pbc/string_8_be.pbc [test]
t/native_pbc/string_8_le.pbc [test]
t/native_pbc/Test.pm [test]
t/native_pbc/testdata/README.pod []doc
t/native_pbc/testdata/annotations.pir [test]
t/native_pbc/testdata/integer.pasm [test]
t/native_pbc/testdata/number.pasm [test]
t/native_pbc/testdata/string.pasm [test]
t/oo/attributes.t [test]
Expand Down
13 changes: 5 additions & 8 deletions lib/Parrot/Test.pm
@@ -1,4 +1,4 @@
# Copyright (C) 2004-2009, Parrot Foundation.
# Copyright (C) 2004-2012, Parrot Foundation.

=head1 NAME
Expand Down Expand Up @@ -685,15 +685,16 @@ sub _run_test_file {
}
elsif ( $func =~ m/^pbc_(exit_code|.*?output_)/ ) {
$code_f = per_test( '.pbc', $test_no );
$code_f = $code if $code =~ /\.pbc$/ and -f $code;
}
else {
die "Unknown test function: $func";
}
$code_f = File::Spec->rel2abs($code_f);
my $code_basef = basename($code_f);

# native tests are just run, others need to write code first
if ( $code_f !~ /\.pbc$/ ) {
# existing pbc test files are just run, need to write code first
if ( $code_f !~ /\.pbc$/ or ! -f $code_f ) {
write_code_to_file( $code, $code_f );
}

Expand Down Expand Up @@ -796,11 +797,7 @@ sub _generate_test_functions {
my ( $code, $expected, $desc, %extra ) = @_;
my $args = $ENV{TEST_PROG_ARGS} || '';

# Due to ongoing changes in PBC format, all tests in
# t/native_pbc/*.t are currently being SKIPped. This means we
# have no tests on which to model tests of the following block.
# Hence, test coverage will be lacking.
if ( $func =~ /^pbc_output_/ && $args =~ /-r / ) {
if ( $code =~ m|t/native_pbc/| && $func =~ /^pbc_output_/ && $args =~ /-r / ) {
# native tests with --run-pbc don't make sense
return $builder->skip("no native tests with -r");
}
Expand Down
23 changes: 11 additions & 12 deletions t/native_pbc/Test.pm
Expand Up @@ -14,16 +14,16 @@ require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = ('test_native_pbc');

my @archtest = qw(4_le 4_le 4_be 8_le 8_le 8_be 8_be 4_le 4_be);
sub int_arch {
return $PConfig{intvalsize}
. "_"
. (substr($PConfig{byteorder},0,2) eq '12' ? "le" : "be");
}
sub num_arch {
return $PConfig{numvalsize}
return $PConfig{ptrsize}
. "_". $PConfig{numvalsize}
. "_"
. (substr($PConfig{byteorder},0,2) eq '12' ? "le" : "be");
. (substr($PConfig{byteorder},0,2) eq '12' ? "le" : "be");
}

sub pbc_bc_version {
Expand All @@ -50,22 +50,21 @@ sub test_native_pbc {
my $todo = shift;
my $file = "t/native_pbc/${type}_${id}.pbc";
if ($type eq 'number') {
$arch = num_arch();
@archtest = qw(8_le 12_le 8_be 8_le 16_le 8_be 16_be 4_le 4_be);
$arch = num_arch();
}
my $cvt = "$archtest[$id-1]=>$arch";
my $cvt = "$id=>$arch";
my $skip_msg;
# check if this a platform where we can produce the needed file
if ($archtest[$id-1] eq $arch) {
if ($id 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.";
. "Need $id platform.";
}
if ($type eq 'number' and $cvt =~ /^16_[bl]e=>8_/) {
# 16 -> 8 drops some mantissa bits
if ($type eq 'number' and $cvt =~ /^8_16_[bl]e=>4_8_/) {
# 16 -> 8 drops some mantissa bits
$expected =~ s/1\.12589990684262e\+15/1.12589990684058e+15/;
}
# check if skip or todo
Expand All @@ -90,13 +89,13 @@ sub test_native_pbc {
$todo_msg = "$cvt yet untested, GH #394. "
. "Please report success."
}
Parrot::Test::pbc_output_is( undef, $expected, "$cvt $desc",
Parrot::Test::pbc_output_is( $file, $expected, "$cvt $desc",
todo => "$todo_msg" );
}
else {
skip $skip_msg, 1
if ($bc ne pbc_bc_version($file));
Parrot::Test::pbc_output_is( undef, $expected, "$cvt $desc" );
Parrot::Test::pbc_output_is( $file, $expected, "$cvt $desc" );
}
}
}
Expand Down
Binary file removed t/native_pbc/annotations.pbc
Binary file not shown.
69 changes: 16 additions & 53 deletions t/native_pbc/integer.t
Expand Up @@ -30,42 +30,36 @@ native pbcs.
=head1 PLATFORMS
_1 4_le: i386 32 bit opcode_t, 32 bit intval (linux-gcc-ix86, freebsd-gcc, cygwin)
_3 4_be: PPC BE 32 bit opcode_t, 32 bit intval (darwin-ppc, sparc32 or mips32)
_4 8_le: x86_64 double float 64 bit opcode_t (linux-gcc-x86_64, solaris-cc-64int)
_6 8_be: big-endian 64 bit opcode_t, 8 byte double (Sparc64, mips64, ppc64)
The id consists of ptrsize+intvalsize in byte and le/be for
little/big-endian.
Systems with different ptrsize + intvalsize (i.e. perl -V:use64bitint) may not be
used to generate native pbc's.
_2 (skipped) i386 32 bit opcode_t, 32 bit intval, 12 bit long double
_5 (skipped) x86_64 16 bit long double 64 bit opcode_t
_7 (skipped) big-endian 64 bit opcode_t, 16 byte long double
_8 (skipped) i386 32 bit opcode_t, 32 bit intval, 4-byte single float --floatval=float
_9 (skipped) big-endian 32 bit opcode_t, 4 byte intval, 4 byte single float
4_le: i386 32 bit opcode_t, 32 bit intval (linux-gcc-ix86, freebsd-gcc, cygwin)
4_be: PPC BE 32 bit opcode_t, 32 bit intval (darwin-ppc, sparc32 or mips32)
8_le: x86_64 double float 64 bit opcode_t (linux-gcc-x86_64, solaris-cc-64int)
8_be: big-endian 64 bit opcode_t, 8 byte double (Sparc64, mips64, ppc64)
=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.
See tools/dev/mk_native_pbc to create the platform-specific native pbc's.
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
$ parrot -o t/native_pbc/integer_${id}.pbc t/native_pbc/testdata/integer.pasm
The output of
$ pbc_dump -h i.pbc
$ pbc_dump -h t/native_pbc/integer_${id}.pbc
should be included for reference.
On test failures please add the output of
$ ./pbc_dump -h t/native_pbc/integer_${N}.pbc
$ ./pbc_dump -h t/native_pbc/integer_${id}.pbc
into your report. We need your wordsize/floattype/endianess.
Expand All @@ -74,7 +68,6 @@ into your report. We need your wordsize/floattype/endianess.
# expected result
my $output = '270544960';

# (1, "(4_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double");
sub test_pbc_integer {
my $id = shift;
my $desc = shift;
Expand All @@ -93,7 +86,7 @@ sub test_pbc_integer {
# 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");
test_pbc_integer('4_le', "i386 32 bit opcode_t, 4 byte intval, 8 byte double");

# darwin/ppc:
# HEADER => [
Expand All @@ -105,7 +98,7 @@ test_pbc_integer(1, "(4_le) i386 32 bit opcode_t, 4 byte intval, 8 byte double")
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_integer(3, "integer", "(4_be) PPC BE 32 bit opcode_t, 4 byte intval, 8 byte double");
test_pbc_integer('4_be', "big-endian 32 bit opcode_t, 4 byte intval, 8 byte double");

# any ordinary 64-bit intel unix:
# HEADER => [
Expand All @@ -117,19 +110,7 @@ test_pbc_integer(3, "integer", "(4_be) PPC BE 32 bit opcode_t, 4 byte intval, 8
# no endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_integer(4, "integer", "(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");
test_pbc_integer('8_le', "x86_64 64 bit opcode_t, 8 byte intval, 8 byte double");

# sparc64/ppc64/mips64
# HEADER => [
Expand All @@ -141,25 +122,7 @@ test_pbc_integer(4, "integer", "(8_le) i86_64 64 bit opcode_t, 8 byte intval, 8
# *need* endianize, no opcode, no numval transform
# dirformat = 1
# ]
test_pbc_integer(6, "integer", "(8_be) big-endian 64 bit opcode_t, 8 byte intval, 8 byte double");

# sparc64/ppc64/mips64 --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");
test_pbc_integer('8_be', "big-endian 64 bit opcode_t, 8 byte intval, 8 byte double");

# Local Variables:
# mode: cperl
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 02feb07

Please sign in to comment.