bytecode.t 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #! /usr/bin/env perl
  2. my $keep_pl = 0; # set it to keep the src pl files
  3. my $keep_plc = 0; # set it to keep the bytecode files
  4. my $keep_plc_fail = 1; # set it to keep the bytecode files on failures
  5. my $do_coverage = $ENV{TEST_COVERAGE}; # do bytecode insn coverage
  6. my $verbose = $ENV{TEST_VERBOSE}; # better use t/testplc.sh for debugging
  7. use Config;
  8. # Debugging Note: perl5.6.2 has no -Dvl, use -D260 (256+4) instead. v mapped to f
  9. BEGIN {
  10. if ($^O eq 'VMS') {
  11. print "1..0 # skip - Bytecode/ByteLoader doesn't work on VMS\n";
  12. exit 0;
  13. }
  14. if ($ENV{PERL_CORE}){
  15. chdir('t') if -d 't';
  16. @INC = ('.', '../lib');
  17. } else {
  18. unshift @INC, 't';
  19. push @INC, "blib/arch", "blib/lib";
  20. }
  21. if (($Config{'extensions'} !~ /\bB\b/) ){
  22. print "1..0 # Skip -- Perl configured without B module\n";
  23. exit 0;
  24. }
  25. require 'test.pl'; # for run_perl()
  26. }
  27. use strict;
  28. my $PERL56 = ( $] < 5.008001 );
  29. my $PERL518 = ( $] > 5.017006 );
  30. my $DEBUGGING = ($Config{ccflags} =~ m/-DDEBUGGING/);
  31. my $ITHREADS = $Config{useithreads};
  32. my $MULTI = $Config{usemultiplicity};
  33. my $AUTHOR = -d '.svn' or -d '.git';
  34. my @tests = tests();
  35. my $numtests = $#tests+1;
  36. $numtests++ if $DEBUGGING and $do_coverage;
  37. print "1..$numtests\n";
  38. my $cnt = 1;
  39. my $test;
  40. my %insncov; # insn coverage
  41. if ($DEBUGGING) {
  42. # op coverage either via Assembler debug, or via ByteLoader -Dv on a -DDEBUGGING perl
  43. if ($do_coverage) {
  44. use B::Asmdata q(@insn_name);
  45. $insncov{$_} = 0 for 0..@insn_name;
  46. }
  47. }
  48. my @todo = (); # 33 fixed with r802, 44 <5.10 fixed later, 27 fixed with r989
  49. @todo = (3,6,8..10,12,15,16,18,26..28,31,33,35,38,41..43,46,50)
  50. if $] < 5.007; # CORE failures, our Bytecode 56 compiler not yet backported
  51. #44 fixed by moving push_begin upfront
  52. push @todo, (21,24..26,28,33,38..39) if $^O eq 'solaris' and $] eq '5.008008';
  53. push @todo, (43) if $] >= 5.008004 and $] <= 5.008008;
  54. push @todo, (7) if $] >= 5.008004 and $] < 5.008008 and $ITHREADS;
  55. push @todo, (11) if $] > 5.008005 and $] < 5.010;
  56. push @todo, (27) if $] >= 5.010 and !$ITHREADS;
  57. push @todo, (32) if $] > 5.011 and $] < 5.013008; # 2x del_backref fixed with r790
  58. # cannot store labels on windows 5.12: 21
  59. push @todo, (21) if $^O =~ /MSWin32|cygwin|AIX/ and $] > 5.011003 and $] < 5.013;
  60. push @todo, (46) if $] >= 5.012 and $] < 5.018;
  61. #push @todo, (41..43) if $] >= 5.010; #freebsd
  62. #push @todo, (7, 17..18, 21, 30, 35) if $] >= 5.018 and $ITHREADS;
  63. my @skip = ();
  64. #push @skip, (27,32,42..43) if !$ITHREADS;
  65. my %todo = map { $_ => 1 } @todo;
  66. my %skip = map { $_ => 1 } @skip;
  67. my $Mblib = $] >= 5.008 ? "-Iblib/arch -Iblib/lib" : ""; # test also the CORE B in older perls?
  68. my $backend = $PERL56 ? 'Bytecode56' : 'Bytecode,-H';
  69. unless ($Mblib) { # check for -Mblib from the testsuite
  70. if (grep { m{blib(/|\\)arch$} } @INC) {
  71. $Mblib = "-Iblib/arch -Iblib/lib"; # force -Mblib via cmdline, but silent!
  72. }
  73. }
  74. else {
  75. $backend = "-qq,$backend" if !$ENV{TEST_VERBOSE} and !$PERL56;
  76. }
  77. # $backend .= ",-fno-fold,-fno-warnings" if $] >= 5.013005;
  78. #$Mblib = '' if $] < 5.007; # override harness on 5.6. No Bytecode for 5.6 for now.
  79. for (@tests) {
  80. my $todo = $todo{$cnt} ? "#TODO " : "#";
  81. my ($got, @insn);
  82. if ($todo{$cnt} and $skip{$cnt} and !$AUTHOR) {
  83. print sprintf("ok %d # skip\n", $cnt);
  84. next;
  85. }
  86. my ($script, $expect) = split />>>+\n/;
  87. $expect =~ s/\n$//;
  88. if ($cnt == 4 and $] >= 5.018) {
  89. $expect = "zz" . $expect;
  90. }
  91. $test = "bytecode$cnt.pl";
  92. open T, ">", $test; print T $script; print T "\n"; close T;
  93. unlink "${test}c" if -e "${test}c";
  94. $? = 0;
  95. $got = run_perl(switches => [ "$Mblib -MO=$backend,-o${test}c" ],
  96. verbose => $verbose, # for DEBUGGING
  97. nolib => $ENV{PERL_CORE} ? 0 : 1, # include ../lib only in CORE
  98. stderr => $PERL56 ? 1 : 0, # capture "bytecode.pl syntax ok"
  99. timeout => 10,
  100. progfile => $test);
  101. my $Byteloader = $PERL56 ? " -MByteLoader" : "";
  102. unless ($?) {
  103. # test coverage if -Dv is allowed
  104. if ($do_coverage and $DEBUGGING) {
  105. my $cov = run_perl(progfile => "${test}c", # run the .plc
  106. nolib => $ENV{PERL_CORE} ? 0 : 1,
  107. stderr => 1,
  108. timeout => 20,
  109. switches => [ "$Mblib -Dv $Byteloader" ]);
  110. for (map { /\(insn (\d+)\)/ ? $1 : undef }
  111. grep /\(insn (\d+)\)/, split(/\n/, $cov)) {
  112. $insncov{$_}++;
  113. }
  114. }
  115. $? = 0;
  116. $got = run_perl(progfile => "${test}c", # run the .plc
  117. verbose => $ENV{TEST_VERBOSE}, # for debugging
  118. nolib => $ENV{PERL_CORE} ? 0 : 1,
  119. stderr => $PERL56 ? 1 : 0,
  120. timeout => 5,
  121. switches => [ "$Mblib $Byteloader" ]);
  122. unless ($?) {
  123. if ($got =~ /^$expect$/) {
  124. print "ok $cnt", $todo eq '#' ? "\n" : "$todo\n";
  125. next;
  126. } else {
  127. # test failed, double check uncompiled
  128. $got = run_perl(verbose => $ENV{TEST_VERBOSE}, # for debugging
  129. nolib => $ENV{PERL_CORE} ? 0 : 1, # include ../lib only in CORE
  130. stderr => 1, # to capture the "ccode.pl syntax ok"
  131. timeout => 5,
  132. progfile => $test);
  133. if (! $? and $got =~ /^$expect$/) {
  134. $keep_plc = $keep_plc_fail unless $keep_plc;
  135. print "not ok $cnt $todo wanted: $expect, got: $got\n";
  136. next;
  137. } else {
  138. print "ok $cnt # skip also fails uncompiled\n";
  139. next;
  140. }
  141. }
  142. }
  143. }
  144. print "not ok $cnt $todo wanted: $expect, \$\? = $?, got: $got\n";
  145. } continue {
  146. 1 while unlink($keep_pl ? () : $test, $keep_plc ? () : "${test}c");
  147. $cnt++;
  148. }
  149. # DEBUGGING coverage test, see STATUS for the missing test ops.
  150. # The real coverage tests are in asmdata.t
  151. if ($do_coverage and $DEBUGGING) {
  152. my $zeros = '';
  153. use B::Asmdata q(@insn_name);
  154. for (0..$#insn_name) { $zeros .= ($insn_name[$_]."($_) ") unless $insncov{$_} };
  155. if ($zeros) { print "not ok ",$cnt++," # TODO no coverage for: $zeros"; }
  156. else { print "ok ",$cnt++," # TODO coverage unexpectedly passed";}
  157. }