bytecode.t 6.0 KB

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