testplc.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. #!/bin/bash
  2. # Usage:
  3. # for p in 5.6.2 5.8.9d 5.10.1 5.11.2; do make -q clean >/dev/null; perl$p Makefile.PL; t/testplc.sh -q -c; done
  4. # use the actual perl from the Makefile (perld, perl5.10.0, perl5.8.8, perl5.11.0, ...)
  5. function help {
  6. echo "t/testplc.sh [OPTIONS] [1-$ntests]"
  7. echo " -s skip all B:Debug, roundtrips and options"
  8. echo " -S skip all roundtrips and options but -S and Concise"
  9. echo " -c continue on errors"
  10. echo " -o orig. no -Mblib. only for 5.6 and 5.8"
  11. echo " -q quiet"
  12. echo " -h help"
  13. echo "t/testplc.sh -q -s -c <=> perl -Mblib t/bytecode.t"
  14. echo "Without arguments try all $ntests tests. Else the given test numbers."
  15. }
  16. PERL=`grep "^PERL =" Makefile|cut -c8-`
  17. PERL=${PERL:-perl}
  18. #PERL=perl5.11.0
  19. VERS=`echo $PERL|sed -e's,.*perl,,' -e's,.exe$,,'`
  20. D="`$PERL -e'print (($] < 5.007) ? q(256) : q(v))'`"
  21. function init {
  22. # test what? core or our module?
  23. Mblib="`$PERL -e'print (($] < 5.008) ? q() : q(-Iblib/arch -Iblib/lib))'`"
  24. #Mblib=${Mblib:--Mblib} # B::C is now fully 5.6+5.8 backwards compatible
  25. OCMD="$PERL $Mblib -MO=Bytecode,"
  26. QOCMD="$PERL $Mblib -MO=-qq,Bytecode,"
  27. ICMD="$PERL $Mblib -MByteLoader"
  28. if [ "$D" = "256" ]; then QOCMD=$OCMD; fi
  29. if [ "$Mblib" = " " ]; then VERS="${VERS}_global"; fi
  30. v513="`$PERL -e'print (($] < 5.013005) ? q() : q(-fno-fold,-fno-warnings,))'`"
  31. OCMD=${OCMD}${v513}
  32. QOCMD=${QOCMD}${v513}
  33. }
  34. function pass {
  35. echo -e -n "\033[1;32mPASS \033[0;0m"
  36. echo $*
  37. }
  38. function fail {
  39. echo -e -n "\033[1;31mFAIL \033[0;0m"
  40. echo $*
  41. }
  42. function bcall {
  43. o=$1
  44. opt=${2:-s}
  45. ext=${3:-plc}
  46. optf=$(echo $opt|sed 's/,-//')
  47. [ -n "$Q" ] || echo ${QOCMD}-$opt,-o${o}${optf}_${VERS}.${ext} ${o}.pl
  48. ${QOCMD}-$opt,-o${o}${optf}_${VERS}.${ext} ${o}.pl
  49. }
  50. function btest {
  51. n=$1
  52. o="bytecode$n"
  53. if [ -z "$2" ]; then
  54. if [ "$n" = "08" ]; then n=8; fi
  55. if [ "$n" = "09" ]; then n=9; fi
  56. echo "${tests[${n}]}" > ${o}.pl
  57. test -z "${tests[${n}]}" && exit
  58. str="${tests[${n}]}"
  59. else
  60. echo "$2" > ${o}.pl
  61. fi
  62. #bcall ${o} O6
  63. rm ${o}_s_${VERS}.plc 2>/dev/null
  64. # annotated assembler
  65. if [ -z "$SKIP" -o -n "$SKI" ]; then
  66. if [ "$Mblib" != " " ]; then
  67. bcall ${o} S,-s asm 1
  68. bcall ${o} S,-k asm 1
  69. bcall ${o} S,-i asm 1
  70. fi
  71. fi
  72. if [ "$Mblib" != " " -a -z "$SKIP" ]; then
  73. m=${o}s_${VERS}
  74. rm ${m}.disasm ${o}_${VERS}.concise ${o}_${VERS}.dbg 2>/dev/null
  75. bcall ${o} s
  76. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble $m.plc \> ${m}.disasm
  77. $PERL $Mblib script/disassemble $m.plc > ${m}.disasm
  78. [ -n "$Q" ] || echo ${ICMD} ${m}.plc
  79. res=$(${ICMD} ${m}.plc)
  80. if [ "X$res" != "X${result[$n]}" ]; then
  81. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  82. fi
  83. # understand annotations
  84. m=${o}S_${VERS}
  85. [ -n "$Q" ] || echo $PERL $Mblib script/assemble ${o}s_${VERS}.disasm \> $m.plc
  86. $PERL $Mblib script/assemble ${o}s_${VERS}.disasm > $m.plc
  87. # full assembler roundtrips
  88. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble $m.plc \> $m.disasm
  89. $PERL $Mblib script/disassemble $m.plc > $m.disasm
  90. md=${o}SD_${VERS}
  91. [ -n "$Q" ] || echo $PERL $Mblib script/assemble $m.disasm \> ${md}.plc
  92. $PERL $Mblib script/assemble $m.disasm > ${md}.plc
  93. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble ${md}.plc \> ${o}SDS_${VERS}.disasm
  94. $PERL $Mblib script/disassemble ${md}.plc > ${o}SDS_${VERS}.disasm
  95. bcall ${o} i
  96. m=${o}i_${VERS}
  97. $PERL $Mblib script/disassemble ${m}.plc > ${m}.disasm
  98. [ -n "$Q" ] || echo ${ICMD} ${m}.plc
  99. res=$(${ICMD} ${m}.plc)
  100. if [ "X$res" = "X${result[$n]}" ]; then
  101. pass "./${m}.plc" "=> '$res'"
  102. else
  103. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  104. fi
  105. bcall ${o} k
  106. m=${o}k_${VERS}
  107. $PERL $Mblib script/disassemble ${m}.plc > ${m}.disasm
  108. [ -n "$Q" ] || echo ${ICMD} ${m}.plc
  109. res=$(${ICMD} ${m}.plc)
  110. if [ "X$res" != "X${result[$n]}" ]; then
  111. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  112. fi
  113. [ -n "$Q" ] || echo $PERL $Mblib -MO=${qq}Debug,-exec ${o}.pl -o ${o}_${VERS}.dbg
  114. [ -n "$Q" ] || $PERL $Mblib -MO=${qq}Debug,-exec ${o}.pl > ${o}_${VERS}.dbg
  115. fi
  116. if [ -z "$SKIP" -o -n "$SKI" ]; then
  117. # 5.8 has a bad concise
  118. [ -n "$Q" ] || echo $PERL $Mblib -MO=${qq}Concise,-exec ${o}.pl -o ${o}_${VERS}.concise
  119. $PERL $Mblib -MO=${qq}Concise,-exec ${o}.pl > ${o}_${VERS}.concise
  120. fi
  121. if [ -z "$SKIP" ]; then
  122. if [ "$Mblib" != " " ]; then
  123. #bcall ${o} TI
  124. bcall ${o} H
  125. m="${o}H_${VERS}"
  126. [ -n "$Q" ] || echo $PERL $Mblib ${m}.plc
  127. res=$($PERL $Mblib ${m}.plc)
  128. if [ "X$res" != "X${result[$n]}" ]; then
  129. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  130. fi
  131. fi
  132. fi
  133. if [ "$Mblib" != " " ]; then
  134. # -s ("scan") should be the new default
  135. [ -n "$Q" ] || echo ${OCMD}-s,-o${o}.plc ${o}.pl
  136. ${OCMD}-s,-o${o}.plc ${o}.pl || (test -z $CONT && exit)
  137. else
  138. # No -s with 5.6
  139. [ -n "$Q" ] || echo ${OCMD}-o${o}.plc ${o}.pl
  140. ${OCMD}-o${o}.plc ${o}.pl || (test -z $CONT && exit)
  141. fi
  142. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble ${o}.plc -o ${o}.disasm
  143. $PERL $Mblib script/disassemble ${o}.plc > ${o}.disasm
  144. [ -n "$Q" ] || echo ${ICMD} ${o}.plc
  145. res=$(${ICMD} ${o}.plc)
  146. if [ "X$res" = "X${result[$n]}" ]; then
  147. pass "./${o}.plc" "=> '$res'"
  148. else
  149. fail "./${o}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  150. if [ -z "$Q" ]; then
  151. echo -n "Again with -Dv? (or Ctrl-Break)"
  152. read
  153. echo ${ICMD} -D$D ${o}.plc; ${ICMD} -D$D ${o}.plc
  154. fi
  155. test -z $CONT && exit
  156. fi
  157. }
  158. ntests=50
  159. declare -a tests[$ntests]
  160. declare -a result[$ntests]
  161. tests[1]="print 'hi'"
  162. result[1]='hi';
  163. tests[2]="for (1,2,3) { print if /\d/ }"
  164. result[2]='123';
  165. tests[3]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/ge; print $_'
  166. result[3]='zzz2y2y2';
  167. tests[4]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/g; print $_'
  168. result[4]='z2y2y2';
  169. tests[5]='print split /a/,"bananarama"'
  170. result[5]='bnnrm';
  171. tests[6]="{package P; sub x {print 'ya'} x}"
  172. result[6]='ya';
  173. tests[7]='@z = split /:/,"b:r:n:f:g"; print @z'
  174. result[7]='brnfg';
  175. tests[8]='sub AUTOLOAD { print 1 } &{"a"}()'
  176. result[8]='1';
  177. tests[9]='my $l = 3; $x = sub { print $l }; &$x'
  178. result[9]='3';
  179. tests[10]='my $i = 1;
  180. my $foo = sub {
  181. $i = shift if @_
  182. }; print $i;
  183. print &$foo(3),$i;'
  184. result[10]='133';
  185. tests[11]='$x="Cannot use"; print index $x, "Can"'
  186. result[11]='0';
  187. tests[12]='my $i=6; eval "print \$i\n"'
  188. result[12]='6';
  189. tests[13]='BEGIN { %h=(1=>2,3=>4) } print $h{3}'
  190. result[13]='4';
  191. tests[14]='open our $T,"a"; print "ok";'
  192. result[14]='ok';
  193. tests[15]='print <DATA>
  194. __DATA__
  195. a
  196. b'
  197. result[15]='a
  198. b';
  199. tests[16]='BEGIN{tie @a, __PACKAGE__;sub TIEARRAY {bless{}} sub FETCH{1}}; print $a[1]'
  200. result[16]='1';
  201. tests[17]='my $i=3; print 1 .. $i'
  202. result[17]='123';
  203. tests[18]='my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h'
  204. result[18]='ba';
  205. tests[19]='print sort { my $p; $b <=> $a } 1,4,3'
  206. result[19]='431';
  207. tests[20]='$a="abcd123";$r=qr/\d/;print $a=~$r;'
  208. result[20]='1';
  209. # broken on early alpha and 5.10
  210. tests[21]='sub skip_on_odd{next NUMBER if $_[0]% 2}NUMBER:for($i=0;$i<5;$i++){skip_on_odd($i);print $i;}'
  211. result[21]='024';
  212. # broken in original perl 5.6
  213. tests[22]='my $fh; BEGIN { open($fh,"<","/dev/null"); } print "ok";';
  214. result[22]='ok';
  215. # broken in perl 5.8
  216. tests[23]='package MyMod; our $VERSION = 1.3; print "ok";'
  217. result[23]='ok'
  218. # works in original perl 5.6, broken with B::C in 5.6, 5.8
  219. tests[24]='sub level1{return(level2()?"fail":"ok")} sub level2{0} print level1();'
  220. result[24]='ok'
  221. # enforce custom ncmp sort and count it. fails as CC in all. How to enforce icmp?
  222. # <=5.6 qsort needs two more passes here than >=5.8 merge_sort
  223. tests[25]='print sort { print $i++," "; $b <=> $a } 1..4'
  224. result[25]="0 1 2 3`$PERL -e'print (($] < 5.007) ? q( 4 5) : q())'` 4321";
  225. # lvalue fails with CC -O1, and with -O2 differently
  226. tests[26]='sub a:lvalue{my $a=26; ${\(bless \$a)}}sub b:lvalue{${\shift}}; print ${a(b)}';
  227. result[26]="26";
  228. # import test
  229. tests[27]='use Fcntl (); print "ok" if ( Fcntl::O_CREAT() >= 64 && &Fcntl::O_CREAT >= 64 );'
  230. result[27]='ok'
  231. # require test
  232. tests[28]='my($fname,$tmp_fh);while(!open($tmp_fh,">",($fname=q{cctest28_} . rand(999999999999)))){$bail++;die "Failed to create a tmp file after 500 tries" if $bail>500;}print {$tmp_fh} q{$x="ok";1;};close($tmp_fh);sleep 1;require $fname;unlink($fname);print $x;'
  233. result[28]='ok'
  234. # use test
  235. tests[29]='use IO;print "ok"'
  236. result[29]='ok'
  237. # run-time context of ..
  238. tests[30]='@a=(4,6,1,0,0,1);sub range{(shift @a)..(shift @a)}print range();while(@a){print scalar(range())}'
  239. result[30]='456123E0'
  240. # AUTOLOAD w/o goto
  241. tests[31]='package DummyShell;sub AUTOLOAD{my $p=$AUTOLOAD;$p=~s/.*:://;print(join(" ",$p,@_),";");} date();who("am","i");ls("-l");'
  242. result[31]='date;who am i;ls -l;'
  243. # CC entertry/jmpenv_jump/leavetry
  244. tests[32]='eval{print "1"};eval{die 1};print "2"'
  245. result[32]='12'
  246. # C qr test was broken in 5.6 -- needs to load an actual file to test. See test 20.
  247. # used to error with Can't locate object method "save" via package "U??WVS?-" (perhaps you forgot to load "U??WVS?-"?) at /usr/lib/perl5/5.6.2/i686-linux/B/C.pm line 676.
  248. # fails with new constant only. still not repro
  249. tests[33]='BEGIN{unshift @INC,("t");} use qr_loaded_module; print "ok";'
  250. result[33]='ok'
  251. # init of magic hashes. %ENV has e magic since a0714e2c perl.c
  252. # (Steven Schubiger 2006-02-03 17:24:49 +0100 3967) i.e. 5.8.9 but not 5.8.8
  253. tests[34]='my $x=$ENV{TMPDIR};print "ok"'
  254. result[34]='ok'
  255. # methodcall syntax
  256. tests[35]='package dummy;sub meth{print "ok"};package main;dummy->meth(1)'
  257. result[35]='ok'
  258. # HV self-ref
  259. tests[36]='my ($rv, %hv); %hv = ( key => \$rv ); $rv = \%hv; print "ok";'
  260. result[36]='ok'
  261. # AV self-ref
  262. tests[37]='my ($rv, @av); @av = ( \$rv ); $rv = \@av; print "ok";'
  263. result[37]='ok'
  264. # constant autoload loop crash test
  265. tests[38]='for(1 .. 1024) { if (open(my $null_fh,"<","/dev/null")) { seek($null_fh,0,SEEK_SET); close($null_fh); $ok++; } }if ($ok == 1024) { print "ok"; }'
  266. result[38]='ok'
  267. # check re::is_regexp, and on 5.12 if being upgraded to SVt_REGEXP
  268. usere="`$PERL -e'print (($] < 5.011) ? q(use re;) : q())'`"
  269. tests[39]=$usere'$a=qr/x/;print ($] < 5.010?1:re::is_regexp($a))'
  270. result[39]='1'
  271. # => Undefined subroutine &re::is_regexp with B-C-1.19, even with -ure
  272. # String with a null byte -- used to generate broken .c on 5.6.2 with static pvs
  273. tests[40]='my $var="this string has a null \\000 byte in it";print "ok";'
  274. result[40]='ok'
  275. # Shared scalar, n magic. => Don't know how to handle magic of type \156.
  276. usethreads="`$PERL -MConfig -e'print ($Config{useithreads} ? q(use threads;) : q())'`"
  277. #usethreads='BEGIN{use Config; unless ($Config{useithreads}) {print "ok"; exit}} '
  278. #;threads->create(sub{$s="ok"})->join;
  279. # not yet testing n, only P
  280. tests[41]=$usethreads'use threads::shared;{my $s="ok";share($s);print $s}'
  281. result[41]='ok'
  282. # Shared aggregate, P magic
  283. tests[42]=$usethreads'use threads::shared;my %h : shared; print "ok"'
  284. result[42]='ok'
  285. # Aggregate element, n + p magic
  286. tests[43]=$usethreads'use threads::shared;my @a : shared; $a[0]="ok"; print $a[0]'
  287. result[43]='ok'
  288. # perl #72922 (5.11.4 fails with magic_killbackrefs)
  289. tests[44]='use Scalar::Util "weaken";my $re1=qr/foo/;my $re2=$re1;weaken($re2);print "ok" if $re3=qr/$re1/;'
  290. result[44]='ok'
  291. # test dynamic loading
  292. tests[45]='use Data::Dumper ();Data::Dumper::Dumpxs({});print "ok";'
  293. result[45]='ok'
  294. # issue 79: Exporter:: stash missing in main::
  295. #tests[46]='use Exporter; if (exists $main::{"Exporter::"}) { print "ok"; }'
  296. tests[46]='use Exporter; print "ok" if %main::Exporter::'
  297. #tests[46]='use Exporter; print "ok" if scalar(keys(%main::Exporter::))'
  298. result[46]='ok'
  299. # non-tied av->MAGICAL
  300. tests[47]='@ISA=(q(ok));print $ISA[0];'
  301. result[47]='ok'
  302. # END block del_backref
  303. tests[48]='my $s=q{ok};END{print $s}'
  304. result[48]='ok'
  305. # even this failed until r1000, overlarge AvFILL=3 endav
  306. #tests[48]='print q(ok);END{}'
  307. #result[48]='ok
  308. # no-fold
  309. tests[49]='print q(ok) if "test" =~ /es/i;'
  310. result[49]='ok'
  311. # @ISA issue 64
  312. tests[50]='package Top;sub top{q(ok)};package Next;our @ISA=qw(Top);package main;print Next->top();'
  313. result[50]='ok'
  314. #-------------
  315. tests[68]='package A;
  316. sub test {
  317. use Data::Dumper (); /^(.*?)\d+$/;
  318. "Some::Package"->new();}
  319. print "ok"'
  320. result[68]='ok'
  321. # issue27
  322. tests[70]='require LWP::UserAgent;print q(ok);'
  323. result[70]='ok'
  324. # issue24
  325. tests[71]='dbmopen(%H,q(f),0644);print q(ok);'
  326. result[71]='ok'
  327. tests[81]='sub int::check {1} #create int package for types
  328. sub x(int,int) { @_ } #cvproto
  329. print "o" if prototype \&x eq "int,int";
  330. sub y($) { @_ } #cvproto
  331. print "k" if prototype \&y eq "\$";'
  332. result[81]='12'
  333. tests[90]='my $s = q(test string);
  334. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  335. print q(o) if $s eq q(string test);
  336. q(test string) =~ /(?<first>\w+) (?<second>\w+)/;
  337. print q(k) if $+{first} eq q(test);'
  338. result[90]='ok'
  339. # IO handles
  340. tests[93]='
  341. my ($pid, $out, $in);
  342. BEGIN {
  343. local(*FPID);
  344. $pid = open(FPID, "echo <<EOF |"); # DIE
  345. open($out, ">&STDOUT"); # EASY
  346. open(my $tmp, ">", "pcc.tmp"); # HARD to get filename, WARN
  347. print $tmp "test\n";
  348. close $tmp; # OK closed
  349. open($in, "<", "pcc.tmp"); # HARD to get filename, WARN
  350. }
  351. # === run-time ===
  352. print $out "o";
  353. kill 0, $pid; # BAD! warn? die?
  354. print "k" if "test" eq read $in, my $x, 4;
  355. unlink "pcc.tmp";
  356. '
  357. result[93]='ok'
  358. tests[931]='my $f;BEGIN{open($f,"<README");}read $f,my $in, 2; print "ok"'
  359. result[931]='ok'
  360. tests[932]='my $f;BEGIN{open($f,">&STDOUT");}print $f "ok"'
  361. result[932]='ok'
  362. tests[97]='use v5.12; print q(ok);'
  363. result[97]='ok'
  364. init
  365. while getopts "qsScoh" opt
  366. do
  367. if [ "$opt" = "q" ]; then
  368. Q=1
  369. OCMD="$QOCMD"
  370. qq="-qq,"
  371. if [ "$VERS" = "5.6.2" ]; then QOCMD=$OCMD; qq=""; fi
  372. fi
  373. if [ "$opt" = "s" ]; then SKIP=1; fi
  374. if [ "$opt" = "o" ]; then Mblib=" "; SKIP=1; SKI=1; init; fi
  375. if [ "$opt" = "S" ]; then SKIP=1; SKI=1; fi
  376. if [ "$opt" = "c" ]; then CONT=1; shift; fi
  377. if [ "$opt" = "h" ]; then help; exit; fi
  378. done
  379. if [ -z "$Q" ]; then
  380. make
  381. else
  382. make -s >/dev/null
  383. fi
  384. # need to shift the options
  385. while [ -n "$1" -a "${1:0:1}" = "-" ]; do shift; done
  386. if [ -n "$1" ]; then
  387. while [ -n "$1" ]; do
  388. btest $1
  389. shift
  390. done
  391. else
  392. for b in $(seq $ntests); do
  393. btest $b
  394. done
  395. fi
  396. # 5.8: all PASS
  397. # 5.10: FAIL: 2-5, 7, 11, 15. With -D 9-12 fail also.
  398. # 5.11: FAIL: 2-5, 7, 11, 15-16 (all segfaulting in REGEX). With -D 9-12 fail also.
  399. # 5.11d: WRONG 4, FAIL: 9-11, 15-16
  400. # 5.11d linux: WRONG 4, FAIL: 11, 16
  401. #only if ByteLoader installed in @INC
  402. if false; then
  403. echo ${OCMD}-H,-obytecode2.plc bytecode2.pl
  404. ${OCMD}-H,-obytecode2.plc bytecode2.pl
  405. chmod +x bytecode2.plc
  406. echo ./bytecode2.plc
  407. ./bytecode2.plc
  408. fi
  409. # package pmc
  410. if false; then
  411. echo "package MY::Test;" > bytecode1.pm
  412. echo "print 'hi'" >> bytecode1.pm
  413. echo ${OCMD}-m,-obytecode1.pmc bytecode1.pm
  414. ${OCMD}-obytecode1.pmc bytecode1.pm
  415. fi