bytecode.t 5.9 KB

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