bytecode.t 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, (43) if $] >= 5.008004 and $] < 5.008008;
  59. push @todo, (7) if $] >= 5.008004 and $] < 5.008008 and $ITHREADS;
  60. push @todo, (27,42,43) if $] >= 5.010 and $] < 5.013008;
  61. push @todo, (32) if $] > 5.011 and $] < 5.013008; # 2x del_backref fixed with r790
  62. #push @todo, (48) if $] > 5.013; # END block del_backref fixed with r1004
  63. #push @todo, (41) if !$ITHREADS;
  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. push @todo, (46) if $] >= 5.012;
  67. push @todo, (27) if $] >= 5.014;
  68. push @todo, (41..43) if $] >= 5.010; #freebsd
  69. my @skip = ();
  70. #push @skip, (27,32,42..43) if !$ITHREADS;
  71. my %todo = map { $_ => 1 } @todo;
  72. my %skip = map { $_ => 1 } @skip;
  73. my $Mblib = $] >= 5.008 ? "-Mblib" : ""; # test also the CORE B in older perls?
  74. my $backend = "Bytecode";
  75. unless ($Mblib) { # check for -Mblib from the testsuite
  76. if (grep { m{blib(/|\\)arch$} } @INC) {
  77. $Mblib = "-Iblib/arch -Iblib/lib"; # force -Mblib via cmdline, but silent!
  78. }
  79. }
  80. else {
  81. $backend = "-qq,Bytecode" unless $ENV{TEST_VERBOSE};
  82. }
  83. # $backend .= ",-fno-fold,-fno-warnings" if $] >= 5.013005;
  84. $backend .= ",-H" unless $PERL56;
  85. #$Bytecode = $] >= 5.007 ? 'Bytecode' : 'Bytecode56';
  86. #$Mblib = '' if $] < 5.007; # override harness on 5.6. No Bytecode for 5.6 for now.
  87. for (@tests) {
  88. my $todo = $todo{$cnt} ? "#TODO " : "#";
  89. my ($got, @insn);
  90. if ($todo{$cnt} and $skip{$cnt} and !$AUTHOR) {
  91. print sprintf("ok %d # skip\n", $cnt);
  92. next;
  93. }
  94. my ($script, $expect) = split />>>+\n/;
  95. $expect =~ s/\n$//;
  96. $test = "bytecode$cnt.pl";
  97. open T, ">$test"; print T $script; close T;
  98. unlink "${test}c" if -e "${test}c";
  99. $? = 0;
  100. $got = run_perl(switches => [ "$Mblib -MO=$backend,-o${test}c" ],
  101. verbose => $verbose, # for DEBUGGING
  102. nolib => $ENV{PERL_CORE} ? 0 : 1, # include ../lib only in CORE
  103. stderr => $PERL56 ? 1 : 0, # capture "bytecode.pl syntax ok"
  104. timeout => 10,
  105. progfile => $test);
  106. unless ($?) {
  107. # test coverage if -Dv is allowed
  108. if ($do_coverage and $DEBUGGING) {
  109. my $cov = run_perl(progfile => "${test}c", # run the .plc
  110. nolib => $ENV{PERL_CORE} ? 0 : 1,
  111. stderr => 1,
  112. timeout => 20,
  113. switches => [ "$Mblib -Dv".($PERL56 ? " -MByteLoader" : "") ]);
  114. for (map { /\(insn (\d+)\)/ ? $1 : undef }
  115. grep /\(insn (\d+)\)/, split(/\n/, $cov)) {
  116. $insncov{$_}++;
  117. }
  118. }
  119. $? = 0;
  120. $got = run_perl(progfile => "${test}c", # run the .plc
  121. verbose => $ENV{TEST_VERBOSE}, # for debugging
  122. nolib => $ENV{PERL_CORE} ? 0 : 1,
  123. stderr => $PERL56 ? 1 : 0,
  124. timeout => 5,
  125. switches => [ "$Mblib".($PERL56 ? " -MByteLoader" : "") ]);
  126. unless ($?) {
  127. if ($got =~ /^$expect$/) {
  128. print "ok $cnt", $todo eq '#' ? "\n" : "$todo\n";
  129. next;
  130. } else {
  131. # test failed, double check uncompiled
  132. $got = run_perl(verbose => $ENV{TEST_VERBOSE}, # for debugging
  133. nolib => $ENV{PERL_CORE} ? 0 : 1, # include ../lib only in CORE
  134. stderr => 1, # to capture the "ccode.pl syntax ok"
  135. timeout => 5,
  136. progfile => $test);
  137. if (! $? and $got =~ /^$expect$/) {
  138. $keep_plc = $keep_plc_fail unless $keep_plc;
  139. print "not ok $cnt $todo wanted: $expect, got: $got\n";
  140. next;
  141. } else {
  142. print "ok $cnt # skip also fails uncompiled\n";
  143. next;
  144. }
  145. }
  146. }
  147. }
  148. print "not ok $cnt $todo wanted: $expect, \$\? = $?, got: $got\n";
  149. } continue {
  150. 1 while unlink($keep_pl ? () : $test, $keep_plc ? () : "${test}c");
  151. $cnt++;
  152. }
  153. # DEBUGGING coverage test, see STATUS for the missing test ops.
  154. # The real coverage tests are in asmdata.t
  155. if ($do_coverage and $DEBUGGING) {
  156. my $zeros = '';
  157. use B::Asmdata q(@insn_name);
  158. for (0..$#insn_name) { $zeros .= ($insn_name[$_]."($_) ") unless $insncov{$_} };
  159. if ($zeros) { print "not ok ",$cnt++," # TODO no coverage for: $zeros"; }
  160. else { print "ok ",$cnt++," # TODO coverage unexpectedly passed";}
  161. }