modules.t 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. # -*- cperl -*-
  2. # t/modules.t [OPTIONS] [t/mymodules]
  3. # check if some common CPAN modules exist and
  4. # can be compiled successfully. Only B::C is fatal,
  5. # CC and Bytecode optional. Use -all for all three (optional), and
  6. # -log for the reports (now default).
  7. #
  8. # OPTIONS:
  9. # -all - run also B::CC and B::Bytecode
  10. # -subset - run only random 10 of all modules. default if ! -d .svn
  11. # -no-subset - all 100 modules
  12. # -no-date - no date added at the logfile
  13. # -t - run also tests
  14. # -log - save log file. default on test10 and without subset
  15. #
  16. # The list in t/mymodules comes from two bigger projects.
  17. # Recommended general lists are Task::Kensho and http://ali.as/top100/
  18. # We are using 10 problematic modules from the latter.
  19. # We are NOT running the full module testsuite yet with -t, we can do that
  20. # in another author test to burn CPU for a few hours resp. days.
  21. #
  22. # Reports:
  23. # for p in 5.6.2 5.8.9 5.10.1 5.12.2; do make -S clean; perl$p Makefile.PL; make; perl$p -Mblib t/modules.t -log; done
  24. #
  25. # How to installed skip modules:
  26. # grep ^skip log.modules-bla|perl -lane'print $F[1]'| xargs perlbla -S cpan
  27. # or t/testm.sh -s
  28. use strict;
  29. use Test::More;
  30. use File::Temp;
  31. # Try some simple XS module which exists in 5.6.2 and blead
  32. # otherwise we'll get a bogus 40% failure rate
  33. my $staticxs = '';
  34. BEGIN {
  35. $staticxs = '--staticxs';
  36. # check whether linking with xs works at all. Try with and without --staticxs
  37. if ($^O eq 'darwin') { $staticxs = ''; goto BEGIN_END; }
  38. my $X = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  39. my $tmp = File::Temp->new(TEMPLATE => 'pccXXXXX');
  40. my $out = $tmp->filename;
  41. my $result = `$X -Mblib blib/script/perlcc --staticxs -o$out -e"use Data::Dumper;"`;
  42. my $exe = $^O eq 'MSWin32' ? "$out.exe" : $out;
  43. unless (-e $exe or -e 'a.out') {
  44. my $result = `$X -Mblib blib/script/perlcc -o$out -e"use Data::Dumper;"`;
  45. unless (-e $out or -e 'a.out') {
  46. plan skip_all => "perlcc cannot link XS module Data::Dumper. Most likely wrong ldopts.";
  47. unlk$out
  48. exit;
  49. } else {
  50. $staticxs = '';
  51. }
  52. }
  53. BEGIN_END:
  54. unshift @INC, 't';
  55. }
  56. our %modules;
  57. our $keep = '';
  58. our $log = 0;
  59. use modules;
  60. require "test.pl";
  61. my $opts_to_test = 1;
  62. my $do_test;
  63. $opts_to_test = 3 if grep /^-all$/, @ARGV;
  64. $do_test = 1 if grep /^-t$/, @ARGV;
  65. # Determine list of modules to action.
  66. our @modules = get_module_list();
  67. my $test_count = scalar @modules * $opts_to_test * ($do_test ? 5 : 4);
  68. # $test_count -= 4 * $opts_to_test * (scalar @modules - scalar(keys %modules));
  69. plan tests => $test_count;
  70. use Config;
  71. use B::C;
  72. use POSIX qw(strftime);
  73. eval { require IPC::Run; };
  74. my $have_IPC_Run = defined $IPC::Run::VERSION;
  75. log_diag("Warning: IPC::Run is not available. Error trapping will be limited, no timeouts.")
  76. unless $have_IPC_Run;
  77. my @opts = (""); # only B::C
  78. @opts = ("", "-O", "-B") if grep /-all/, @ARGV; # all 3 compilers
  79. my $perlversion = perlversion();
  80. $log = 0 if @ARGV;
  81. $log = 1 if grep /top100$/, @ARGV;
  82. $log = 1 if grep /-log/, @ARGV or $ENV{TEST_LOG};
  83. my $nodate = 1 if grep /-no-date/, @ARGV;
  84. if ($log) {
  85. $log = (@ARGV and !$nodate)
  86. ? "log.modules-$perlversion-".strftime("%Y%m%d-%H%M%S",localtime)
  87. : "log.modules-$perlversion";
  88. if (-e $log) {
  89. use File::Copy;
  90. copy $log, "$log.bak";
  91. }
  92. open(LOG, ">", "$log");
  93. close LOG;
  94. }
  95. unless (is_subset) {
  96. my $svnrev = "";
  97. if (-d '.svn') {
  98. local $ENV{LC_MESSAGES} = "C";
  99. $svnrev = `svn info|grep Revision:`;
  100. chomp $svnrev;
  101. $svnrev =~ s/Revision:\s+/r/;
  102. my $svnstat = `svn status lib/B/C.pm t/test.pl t/*.t`;
  103. chomp $svnstat;
  104. $svnrev .= " M" if $svnstat;
  105. } elsif (-d '.git') {
  106. local $ENV{LC_MESSAGES} = "C";
  107. $svnrev = `git log -1 --pretty=format:"%h %ad | %s" --date=short`;
  108. chomp $svnrev;
  109. my $gitdiff = `git diff lib/B/C.pm t/test.pl t/*.t`;
  110. chomp $gitdiff;
  111. $svnrev .= " M" if $gitdiff;
  112. }
  113. log_diag("B::C::VERSION = $B::C::VERSION $svnrev");
  114. log_diag("perlversion = $perlversion");
  115. log_diag("path = $^X");
  116. my $bits = 8 * $Config{ptrsize};
  117. log_diag("platform = $^O $bits"."bit ".(
  118. $Config{'useithreads'} ? "threaded"
  119. : $Config{'usemultiplicity'} ? "multi"
  120. : "non-threaded").
  121. ($Config{ccflags} =~ m/-DDEBUGGING/ ? " debug" : ""));
  122. }
  123. my $module_count = 0;
  124. my ($skip, $pass, $fail, $todo) = (0,0,0,0);
  125. MODULE:
  126. for my $module (@modules) {
  127. $module_count++;
  128. local($\, $,); # guard against -l and other things that screw with
  129. # print
  130. # Possible binary files.
  131. my $name = $module;
  132. $name =~ s/::/_/g;
  133. $name =~ s{(install|setup|update)}{substr($1,0,4)}ie;
  134. my $out = 'pcc'.$name;
  135. my $out_c = "$out.c";
  136. my $out_pl = "$out.pl";
  137. $out = "$out.exe" if $^O eq 'MSWin32';
  138. SKIP: {
  139. # if is a special module that can't be required like others
  140. unless ($modules{$module}) {
  141. $skip++;
  142. log_pass("skip", "$module", 0);
  143. skip("$module not installed", 4 * scalar @opts);
  144. next MODULE;
  145. }
  146. if (is_skip($module)) { # !$have_IPC_Run is not really helpful here
  147. my $why = is_skip($module);
  148. $skip++;
  149. log_pass("skip", "$module #$why", 0);
  150. skip("$module $why", 4 * scalar @opts);
  151. next MODULE;
  152. }
  153. $module = 'if(1) => "Sys::Hostname"' if $module eq 'if';
  154. TODO: {
  155. my $s = is_todo($module);
  156. local $TODO = $s if $s;
  157. $todo++ if $TODO;
  158. open F, ">", $out_pl or die;
  159. print F "use $module;\nprint 'ok';\n" or die;
  160. close F or die;
  161. my ($result, $stdout, $err);
  162. my $module_passed = 1;
  163. my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  164. foreach my $opt (@opts) {
  165. $opt .= " $keep" if $keep;
  166. # TODO ./a often hangs but perlcc not
  167. my @cmd = grep {!/^$/}
  168. $runperl,"-Mblib","blib/script/perlcc",$opt,$staticxs,"-o$out","-r",$out_pl;
  169. my $cmd = "$runperl -Mblib blib/script/perlcc $opt $staticxs -o$out -r"; # only for the msg
  170. # Esp. darwin-2level has insane link times
  171. ($result, $stdout, $err) = run_cmd(\@cmd, 720); # in secs.
  172. ok(-s $out,
  173. "$module_count: use $module generates non-zero binary")
  174. or $module_passed = 0;
  175. is($result, 0, "$module_count: use $module $opt exits with 0")
  176. or $module_passed = 0;
  177. $err =~ s/^Using .+blib\n//m if $] < 5.007;
  178. like($stdout, qr/ok$/ms, "$module_count: use $module $opt gives expected 'ok' output");
  179. unless ($stdout =~ /ok$/ms) { # crosscheck for a perlcc problem (XXX not needed anymore)
  180. my ($r, $err1);
  181. $module_passed = 0;
  182. @cmd = ($runperl,"-Mblib","-MO=C,-o$out_c",$out_pl);
  183. ($r, $stdout, $err1) = run_cmd(\@cmd, 60); # in secs
  184. @cmd = ($runperl,"-Mblib","script/cc_harness","-o$out",$out_c);
  185. ($r, $stdout, $err1) = run_cmd(\@cmd, 360); # in secs
  186. @cmd = ($^O eq 'MSWin32' ? "$out" : "./$out");
  187. ($r, $stdout, $err1) = run_cmd(\@cmd, 20); # in secs
  188. if ($stdout =~ /ok$/ms) {
  189. $module_passed = 1;
  190. diag "crosscheck that only perlcc $staticxs failed. With -MO=C + cc_harness => ok";
  191. }
  192. }
  193. log_pass($module_passed ? "pass" : "fail", $module, $TODO);
  194. if ($module_passed) {
  195. $pass++;
  196. } else {
  197. diag "Failed: $cmd -e 'use $module; print \"ok\"'";
  198. $fail++;
  199. }
  200. TODO: {
  201. local $TODO = 'STDERR from compiler warnings in work' if $err;
  202. is($err, '', "$module_count: use $module no error output compiling")
  203. && ($module_passed)
  204. or log_err($module, $stdout, $err)
  205. }
  206. }
  207. if ($do_test) {
  208. TODO: {
  209. local $TODO = 'all module tests';
  210. `$runperl -Mblib -It -MCPAN -Mmodules -e "CPAN::Shell->testcc("$module")"`;
  211. }
  212. }
  213. for ($out_pl, $out, $out_c, $out_c.".lst") {
  214. unlink $_ if -f $_ ;
  215. }
  216. }}
  217. }
  218. my $count = scalar @modules - $skip;
  219. log_diag("$count / $module_count modules tested with B-C-${B::C::VERSION} - perl-$perlversion");
  220. log_diag(sprintf("pass %3d / %3d (%s)", $pass, $count, percent($pass,$count)));
  221. log_diag(sprintf("fail %3d / %3d (%s)", $fail, $count, percent($fail,$count)));
  222. log_diag(sprintf("todo %3d / %3d (%s)", $todo, $fail, percent($todo,$fail)));
  223. log_diag(sprintf("skip %3d / %3d (%s not installed)\n",
  224. $skip, $module_count, percent($skip,$module_count)));
  225. exit;
  226. # t/todomod.pl
  227. # for t in $(cat t/top100); do perl -ne"\$ARGV=~s/log.modules-//;print \$ARGV,': ',\$_ if / $t\s/" t/modules.t `ls log.modules-5.0*|grep -v .err`; read; done
  228. sub is_todo {
  229. my $module = shift or die;
  230. my $DEBUGGING = ($Config{ccflags} =~ m/-DDEBUGGING/);
  231. # ---------------------------------------
  232. #foreach(qw(
  233. # ExtUtils::CBuilder
  234. #)) { return 'overlong linking time' if $_ eq $module; }
  235. #if ($] < 5.007) { foreach(qw(
  236. # ExtUtils::CBuilder
  237. #)) { return '5.6' if $_ eq $module; }}
  238. if ($] >= 5.008004 and $] < 5.0080006) { foreach(qw(
  239. Module::Pluggable
  240. )) { return '5.8.5 CopFILE_set' if $_ eq $module; }}
  241. # restricted v_string hash?
  242. if ($] eq '5.010000') { foreach(qw(
  243. IO
  244. Path::Class
  245. DateTime::TimeZone
  246. )) { return '5.10.0 restricted hash/...' if $_ eq $module; }}
  247. # fixed between v5.15.6-210-g5343a61 and v5.15.6-233-gfb7aafe
  248. if ($] > 5.015 and $] < 5.015006) { foreach(qw(
  249. B::Hooks::EndOfScope
  250. )) { return '> 5.15' if $_ eq $module; }}
  251. #if ($] > 5.015) { foreach(qw(
  252. # Moose
  253. # MooseX::Types
  254. # DateTime
  255. #)) { return '> 5.15 (unshare_hek)' if $_ eq $module; }}
  256. # ---------------------------------------
  257. if ($Config{useithreads}) {
  258. if (!$DEBUGGING) { foreach(qw(
  259. Test::Tester
  260. )) { return 'non-debugging with threads' if $_ eq $module; }}
  261. if ($] >= 5.008005 and $] < 5.008006) { foreach(qw(
  262. Module::Build
  263. Test::NoWarnings
  264. Test::Warn
  265. Test::Simple
  266. Test::Exception
  267. Test::Tester
  268. Test::Deep
  269. )) { return '5.8.4-5 shared_scalar n-magic (\156)' if $_ eq $module; }}
  270. if ($] > 5.008001 and $] < 5.008009) { foreach(qw(
  271. Test::Pod
  272. )) { return '5.8.1-5.8.8 with threads' if $_ eq $module; }}
  273. if ($] >= 5.009 and $] < 5.012) { foreach(qw(
  274. Carp::Clan
  275. DateTime
  276. Encode
  277. ExtUtils::Install
  278. Module::Build
  279. MooseX::Types
  280. Pod::Text
  281. Template::Stash
  282. )) { return '5.10 with threads' if $_ eq $module; }}
  283. # XXX 5.12.0 not tested recently
  284. if ($] eq 5.012000) { foreach(qw(
  285. DBI
  286. DateTime
  287. DateTime::Locale
  288. Filter::Util::Call
  289. Storable
  290. Sub::Name
  291. )) { return '5.12.0 with threads' if $_ eq $module; }}
  292. } else { #no threads --------------------------------
  293. # This was related to aelemfast->sv with SPECIAL pads fixed with 033d200
  294. if ($] > 5.008004 and $] <= 5.008005) { foreach(qw(
  295. DateTime
  296. )) { return '5.8.5 without threads' if $_ eq $module; }}
  297. #if ($] > 5.015) { foreach(qw(
  298. # DateTime::TimeZone
  299. #)) { return '> 5.15 without threads' if $_ eq $module; }}
  300. }
  301. # ---------------------------------------
  302. }
  303. sub is_skip {
  304. my $module = shift or die;
  305. if ($] >= 5.011004) {
  306. #foreach (qw(Attribute::Handlers)) {
  307. # return 'fails $] >= 5.011004' if $_ eq $module;
  308. #}
  309. if ($Config{useithreads}) { # hangs and crashes threaded since 5.12
  310. foreach (qw( )) {
  311. # Old: Recursive inheritance detected in package 'Moose::Object' at /usr/lib/perl5/5.13.10/i686-debug-cygwin/DynaLoader.pm line 103
  312. # Update: Moose works ok with r1013
  313. return 'hangs threaded, $] >= 5.011004' if $_ eq $module;
  314. }
  315. }
  316. }
  317. }