testcore.pl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. # -*- cperl -*-
  2. # t/testcore.t - run the core testsuite with the compilers C, CC and ByteCode
  3. # Usage:
  4. # t/testcore.t -fail known failing tests only
  5. # t/testcore.t -c run C compiler tests only (also -bc or -cc)
  6. # t/testcore.t t/CORE/op/goto.t run this test only
  7. #
  8. # Prereq:
  9. # Copy your matching CORE t dirs into t/CORE.
  10. # For now we test qw(base comp lib op run)
  11. # Then fixup the @INC setters, and various require ./test.pl calls.
  12. #
  13. # perl -pi -e 's/^(\s*\@INC = )/# $1/' t/CORE/*/*.t
  14. # perl -pi -e "s|^(\s*)chdir 't' if -d|\$1chdir 't/CORE' if -d|" t/CORE/*/*.t
  15. # perl -pi -e "s|require './|use lib "CORE"; require '|" `grep -l "require './" t/CORE/*/*.t`
  16. #
  17. # See TESTS for recent results
  18. use Cwd;
  19. use File::Copy;
  20. BEGIN {
  21. unless (-d "t/CORE" or $ENV{NO_AUTHOR}) {
  22. print "1..0 #skip t/CORE missing. Read t/testcore.t how to setup.\n";
  23. exit 0;
  24. }
  25. unshift @INC, ("t");
  26. }
  27. require "test.pl";
  28. sub vcmd {
  29. my $cmd = join "", @_;
  30. print "#",$cmd,"\n";
  31. run_cmd($cmd, 120); # timeout 2min
  32. }
  33. my $dir = getcwd();
  34. #unlink ("t/perl", "t/CORE/perl", "t/CORE/test.pl", "t/CORE/harness");
  35. #symlink "t/perl", $^X;
  36. #symlink "t/CORE/perl", $^X;
  37. #symlink "t/CORE/test.pl", "t/test.pl" unless -e "t/CORE/test.pl";
  38. #symlink "t/CORE/harness", "t/test.pl" unless -e "t/CORE/harness";
  39. `ln -sf $^X t/perl`;
  40. `ln -sf $^X t/CORE/perl`;
  41. # CORE t/test.pl would be better, but this fails only on 2 tests
  42. -e "t/CORE/test.pl" or `ln -s $dir/t/test.pl t/CORE/test.pl`;
  43. -e "t/CORE/harness" or `ln -s test.pl t/CORE/harness`; # better than nothing
  44. #`ln -s $dir/t/test.pl harness`; # base/term
  45. #`ln -s $dir/t/test.pl TEST`; # cmd/mod 8
  46. my %ALLOW_PERL_OPTIONS;
  47. for (qw(
  48. comp/cpp.t
  49. run/runenv.t
  50. )) {
  51. $ALLOW_PERL_OPTIONS{"t/CORE/$_"} = 1;
  52. }
  53. my $SKIP = { "CC" =>
  54. { "t/CORE/op/bop.t" => "hangs",
  55. "t/CORE/op/die.t" => "hangs",
  56. }
  57. };
  58. my @fail = map { "t/CORE/$_" }
  59. qw{
  60. base/rs.t
  61. base/term.t
  62. cmd/for.t
  63. cmd/subval.t
  64. cmd/while.t
  65. comp/colon.t
  66. comp/hints.t
  67. comp/multiline.t
  68. comp/packagev.t
  69. comp/parser.t
  70. comp/require.t
  71. comp/retainedlines.t
  72. comp/script.t
  73. comp/uproto.t
  74. comp/use.t
  75. io/argv.t
  76. io/binmode.t
  77. io/crlf.t
  78. io/crlf_through.t
  79. io/errno.t
  80. io/fflush.t
  81. io/fs.t
  82. io/inplace.t
  83. io/iprefix.t
  84. io/layers.t
  85. io/nargv.t
  86. io/open.t
  87. io/openpid.t
  88. io/perlio.t
  89. io/perlio_fail.t
  90. io/perlio_leaks.t
  91. io/perlio_open.t
  92. io/pipe.t
  93. io/print.t
  94. io/pvbm.t
  95. io/read.t
  96. io/say.t
  97. io/tell.t
  98. io/through.t
  99. io/utf8.t
  100. op/anonsub.t
  101. op/array.t
  102. op/attrs.t
  103. op/avhv.t
  104. op/bop.t
  105. op/chop.t
  106. op/closure.t
  107. op/concat.t
  108. op/defins.t
  109. op/do.t
  110. op/eval.t
  111. op/filetest.t
  112. op/flip.t
  113. op/fork.t
  114. op/goto.t
  115. op/goto_xs.t
  116. op/grent.t
  117. op/gv.t
  118. op/hashwarn.t
  119. op/index.t
  120. op/join.t
  121. op/length.t
  122. op/local.t
  123. op/lfs.t
  124. op/magic.t
  125. op/method.t
  126. op/misc.t
  127. op/mkdir.t
  128. op/my_stash.t
  129. op/numconvert.t
  130. op/pwent.t
  131. op/regmesg.t
  132. op/runlevel.t
  133. op/sort.t
  134. op/split.t
  135. op/sprintf.t
  136. op/stat.t
  137. op/study.t
  138. op/subst.t
  139. op/substr.t
  140. op/tie.t
  141. op/tr.t
  142. op/universal.t
  143. op/utf8decode.t
  144. op/vec.t
  145. op/ver.t
  146. uni/cache.t
  147. uni/chomp.t
  148. uni/chr.t
  149. uni/class.t
  150. uni/fold.t
  151. uni/greek.t
  152. uni/latin2.t
  153. uni/lex_utf8.t
  154. uni/lower.t
  155. uni/sprintf.t
  156. uni/tie.t
  157. uni/title.t
  158. uni/tr_7jis.t
  159. uni/tr_eucjp.t
  160. uni/tr_sjis.t
  161. uni/tr_utf8.t
  162. uni/upper.t
  163. uni/write.t
  164. };
  165. my @tests = $ARGV[0] eq '-fail'
  166. ? @fail
  167. : ((@ARGV and $ARGV[0] !~ /^-/)
  168. ? @ARGV
  169. : <t/CORE/*/*.t>);
  170. shift if $ARGV[0] eq '-fail';
  171. my $Mblib = $^O eq 'MSWin32' ? '-Iblib\arch -Iblib\lib' : "-Iblib/arch -Iblib/lib";
  172. sub run_c {
  173. my ($t, $backend) = @_;
  174. chdir $dir;
  175. my $result = $t; $result =~ s/\.t$/-c.result/;
  176. $result =~ s/-c.result$/-cc.result/ if $backend eq 'CC';
  177. my $a = $result; $a =~ s/\.result$//;
  178. unlink ($a, "$a.c", "t/$a.c", "t/CORE/$a.c", $result);
  179. # perlcc 2.06 should now work also: omit unneeded B::Stash -u<> and fixed linking
  180. # see t/c_argv.t
  181. my $backopts = $backend eq 'C' ? "-qq,C,-O3" : "-qq,CC";
  182. $backopts .= ",-fno-warnings" if $backend =~ /^C/ and $] >= 5.013005;
  183. $backopts .= ",-fno-fold" if $backend =~ /^C/ and $] >= 5.013009;
  184. vcmd "$^X $Mblib -MO=$backopts,-o$a.c $t";
  185. # CORE often does BEGIN chdir "t", patched to chdir "t/CORE"
  186. chdir $dir;
  187. move ("t/$a.c", "$a.c") if -e "t/$a.c";
  188. move ("t/CORE/$a.c", "$a.c") if -e "t/CORE/$a.c";
  189. my $d = "";
  190. $d = "-DALLOW_PERL_OPTIONS" if $ALLOW_PERL_OPTIONS{$t};
  191. vcmd "$^X $Mblib script/cc_harness -q $d $a.c -o $a" if -e "$a.c";
  192. vcmd "./$a | tee $result" if -e "$a";
  193. prove ($a, $result, $i, $t, $backend);
  194. $i++;
  195. }
  196. sub prove {
  197. my ($a, $result, $i, $t, $backend) = @_;
  198. if ( -e "$a" and -s $result) {
  199. system(qq[prove -Q --exec cat $result || echo -n "n";echo "ok $i - $backend $t"]);
  200. } else {
  201. print "not ok $i - $backend $t\n";
  202. }
  203. }
  204. my @runtests = qw(C CC BC);
  205. if ($ARGV[0] and $ARGV[0] =~ /^-(c|cc|bc)$/i) {
  206. @runtests = ( uc(substr($ARGV[0],1) ) );
  207. }
  208. my $numtests = scalar @tests * scalar @runtests;
  209. my %runtests = map {$_ => 1} @runtests;
  210. print "1..", $numtests, "\n";
  211. my $i = 1;
  212. for my $t (@tests) {
  213. C:
  214. if ($runtests{C}) {
  215. (print "ok $i #skip $SKIP->{C}->{$t}\n" and goto CC)
  216. if exists $SKIP->{C}->{$t};
  217. run_c($t, "C");
  218. }
  219. CC:
  220. if ($runtests{CC}) {
  221. (print "ok $i #skip $SKIP->{CC}->{$t}\n" and goto BC)
  222. if exists $SKIP->{CC}->{$t};
  223. run_c($t, "CC");
  224. }
  225. BC:
  226. if ($runtests{BC}) {
  227. (print "ok $i #skip $SKIP->{BC}->{$t}\n" and next)
  228. if exists $SKIP->{BC}->{$t};
  229. my $backend = 'Bytecode';
  230. chdir $dir;
  231. $result = $t; $result =~ s/\.t$/-bc.result/;
  232. unlink ("b.plc", "t/b.plc", "t/CORE/b.plc", $result);
  233. vcmd "$^X $Mblib -MO=-qq,Bytecode,-H,-s,-ob.plc $t";
  234. chdir $dir;
  235. move ("t/b.plc", "b.plc") if -e "t/b.plc";
  236. move ("t/CORE/b.plc", "b.plc") if -e "t/CORE/b.plc";
  237. vcmd "$^X $Mblib b.plc > $result" if -e "b.plc";
  238. prove ("b.plc", $result, $i, $t, $backend);
  239. $i++;
  240. }
  241. }
  242. END {
  243. unlink ( "t/perl", "t/CORE/perl", "harness", "TEST" );
  244. unlink ("a","a.c","t/a.c","t/CORE/a.c","aa.c","aa","t/aa.c","t/CORE/aa.c","b.plc");
  245. }