This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [PATCH] make -f invalid when USE_SITECUSTOMIZE isn't set
[perl5.git] / ext / Devel / DProf / t / DProf.t
CommitLineData
95667ae4 1#!perl
583a019e 2
95667ae4
GS
3BEGIN {
4 chdir( 't' ) if -d 't';
20822f61 5 @INC = '../lib';
38080423 6 require './test.pl'; # for which_perl() etc
be3174d2
GS
7 require Config; import Config;
8 if ($Config{'extensions'} !~ /\bDevel\/DProf\b/){
9 print "1..0 # Skip: Devel::DProf was not built\n";
10 exit 0;
11 }
95667ae4 12}
583a019e 13
70b836b3 14END {
ef060a86
CL
15 while(-e 'tmon.out' && unlink 'tmon.out') {}
16 while(-e 'err' && unlink 'err') {}
70b836b3
JT
17}
18
583a019e 19use Benchmark qw( timediff timestr );
ab019eaa 20use Config;
583a019e 21use Getopt::Std 'getopts';
583a019e
GS
22getopts('vI:p:');
23
24# -v Verbose
25# -I Add to @INC
26# -p Name of perl binary
27
ef060a86 28@tests = @ARGV ? @ARGV : sort (<lib/dprof/*_t>, <lib/dprof/*_v>); # glob-sort, for OS/2
583a019e
GS
29
30$path_sep = $Config{path_sep} || ':';
583a019e 31$perl5lib = $opt_I || join( $path_sep, @INC );
38080423 32$perl = $opt_p || which_perl();
583a019e
GS
33
34if( $opt_v ){
35 print "tests: @tests\n";
36 print "perl: $perl\n";
37 print "perl5lib: $perl5lib\n";
38}
39if( $perl =~ m|^\./| ){
40 # turn ./perl into ../perl, because of chdir(t) above.
41 $perl = ".$perl";
42}
43if( ! -f $perl ){ die "Where's Perl?" }
44
45sub profile {
46 my $test = shift;
47 my @results;
48 local $ENV{PERL5LIB} = $perl5lib;
ab019eaa 49 my $opt_f = $Config{ccflags} =~ /USE_SITECUSTOMIZE/ ? '-f' : '';
583a019e
GS
50 my $opt_d = '-d:DProf';
51
52 my $t_start = new Benchmark;
ab019eaa 53 open( R, "$perl $opt_f \"$opt_d\" $test |" ) || warn "$0: Can't run. $!\n";
583a019e 54 @results = <R>;
d1e4d418 55 close R or warn "Could not close: $!";
583a019e
GS
56 my $t_total = timediff( new Benchmark, $t_start );
57
58 if( $opt_v ){
59 print "\n";
60 print @results
61 }
62
44d95355 63 print '# ' . timestr( $t_total, 'nop' ), "\n";
583a019e
GS
64}
65
66
67sub verify {
68 my $test = shift;
69
d1ee8ea9
CL
70 my $command = $perl.' "-I../lib" "-I./lib/dprof" '.$test;
71 $command .= ' -v' if $opt_v;
72 $command .= ' -p '. $perl;
73 system $command;
583a019e
GS
74}
75
76
77$| = 1;
7619c85e 78print "1..20\n";
583a019e
GS
79while( @tests ){
80 $test = shift @tests;
ab019eaa 81 $test =~ s/\.$// if $^O eq 'VMS';
95667ae4
GS
82 if( $test =~ /_t$/i ){
83 print "# $test" . '.' x (20 - length $test);
583a019e
GS
84 profile $test;
85 }
86 else{
87 verify $test;
88 }
89}
9394203c
JH
90
91unlink("tmon.out");