| CODENOTIFIER | HelpYou are not signed inSign in |
Project: lighttpd
Revision: 2262
Author: stbuehler
Date: 31 Jul 2008 12:45:06
Changes:[tests] Use LightyTest.pm from 1.4.x
Files:| ... | ...@@ -42,8 +42,6 @@ | |
| 42 | 42 | $self->{MODULES_PATH} = $self->{BASEDIR}.'/build'; |
| 43 | 43 | } |
| 44 | 44 | $self->{LIGHTTPD_PATH} = $self->{BINDIR}.'/lighttpd'; |
| 45 | $self->{LIGHTTPD_PIDFILE} = $self->{TESTDIR}.'/tmp/lighttpd/lighttpd.pid'; | |
| 46 | $self->{PIDOF_PIDFILE} = $self->{TESTDIR}.'/tmp/lighttpd/pidof.pid'; | |
| 47 | 45 | $self->{PORT} = 2048; |
| 48 | 46 | |
| 49 | 47 | my ($name, $aliases, $addrtype, $net) = gethostbyaddr(inet_aton("127.0.0.1"), AF_INET); |
| ... | ...@@ -72,26 +70,34 @@ | |
| 72 | 70 | sub stop_proc { |
| 73 | 71 | my $self = shift; |
| 74 | 72 | |
| 75 | # open F, $self->{LIGHTTPD_PIDFILE} or return -1; | |
| 76 | # my $pid = <F>; | |
| 77 | # close F; | |
| 78 | ||
| 79 | # if (defined $pid) { | |
| 80 | # kill('TERM',$pid) or return -1; | |
| 81 | # select(undef, undef, undef, 0.5); | |
| 82 | # } | |
| 83 | ||
| 84 | 73 | my $pid = $self->{LIGHTTPD_PID}; |
| 85 | if (defined $pid) { | |
| 74 | if (defined $pid && $pid != -1) { | |
| 86 | 75 | kill('TERM', $pid) or return -1; |
| 87 | 76 | return -1 if ($pid != waitpid($pid, 0)); |
| 88 | 77 | } else { |
| 89 | diag("Nothing to kill\n"); | |
| 78 | diag("Process not started, nothing to stop"); | |
| 79 | return -1; | |
| 90 | 80 | } |
| 91 | 81 | |
| 92 | 82 | return 0; |
| 93 | 83 | } |
| 94 | 84 | |
| 85 | sub wait_for_port_with_proc { | |
| 86 | my $self = shift; | |
| 87 | my $port = shift; | |
| 88 | my $child = shift; | |
| 89 | ||
| 90 | while (0 == $self->listening_on($port)) { | |
| 91 | select(undef, undef, undef, 0.1); | |
| 92 | ||
| 93 | # the process is gone, we failed | |
| 94 | if (0 != waitpid($child, WNOHANG)) { | |
| 95 | return -1; | |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | return 0; | |
| 100 | } | |
| 95 | 101 | |
| 96 | 102 | sub start_proc { |
| 97 | 103 | my $self = shift; |
| ... | ...@@ -104,17 +110,15 @@ | |
| 104 | 110 | $ENV{'SRCDIR'} = $self->{BASEDIR}.'/tests'; |
| 105 | 111 | $ENV{'PORT'} = $self->{PORT}; |
| 106 | 112 | |
| 107 | unlink($self->{LIGHTTPD_PIDFILE}); | |
| 108 | my $cmdargs = " -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH}; | |
| 109 | my $cmdline = $self->{LIGHTTPD_PATH}." ".$cmdargs; | |
| 113 | my $cmdline = $self->{LIGHTTPD_PATH}." -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH}; | |
| 110 | 114 | if (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'strace') { |
| 111 | $cmdline = "strace -tt -s 512 -o strace $cmdline &"; | |
| 115 | $cmdline = "strace -tt -s 512 -o strace ".$cmdline; | |
| 112 | 116 | } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'truss') { |
| 113 | $cmdline = "truss -a -l -w all -v all -o strace $cmdline &"; | |
| 117 | $cmdline = "truss -a -l -w all -v all -o strace ".$cmdline; | |
| 114 | 118 | } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'gdb') { |
| 115 | $cmdline = "gdb --batch --ex 'run' --ex 'bt' --args $cmdline &"; | |
| 119 | $cmdline = "gdb --batch --ex 'run' --ex 'bt' --args ".$cmdline." > gdb.out"; | |
| 116 | 120 | } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'valgrind') { |
| 117 | $cmdline = "valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --log-file=valgrind $cmdline &"; | |
| 121 | $cmdline = "valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --log-file=valgrind ".$cmdline; | |
| 118 | 122 | } |
| 119 | 123 | # diag("starting lighttpd at :".$self->{PORT}.", cmdline: ".$cmdline ); |
| 120 | 124 | my $child = fork(); |
| ... | ...@@ -124,30 +128,14 @@ | |
| 124 | 128 | } |
| 125 | 129 | if ($child == 0) { |
| 126 | 130 | exec $cmdline or die($?); |
| 127 | } else { | |
| 128 | $self->{LIGHTTPD_PID} = $child; | |
| 129 | } | |
| 130 | # system($cmdline) == 0 or die($?); | |
| 131 | ||
| 132 | select(undef, undef, undef, 0.1); | |
| 133 | if (not -e $self->{LIGHTTPD_PIDFILE} or 0 == kill 0, `cat $self->{LIGHTTPD_PIDFILE}`) { | |
| 134 | select(undef, undef, undef, 2); | |
| 135 | 131 | } |
| 136 | 132 | |
| 137 | unlink($self->{TESTDIR}."/tmp/cfg.file"); | |
| 138 | ||
| 139 | # no pidfile, we failed | |
| 140 | if (not -e $self->{LIGHTTPD_PIDFILE}) { | |
| 141 | diag(sprintf('Could not find pidfile: %s', $self->{LIGHTTPD_PIDFILE})); | |
| 133 | if (0 != $self->wait_for_port_with_proc($self->{PORT}, $child)) { | |
| 134 | diag(sprintf('The process %i is not up', $child)); | |
| 142 | 135 | return -1; |
| 143 | 136 | } |
| 144 | 137 | |
| 145 | # the process is gone, we failed | |
| 146 | if (0 != waitpid($child, WNOHANG)) { | |
| 147 | #if (0 == kill 0, `cat $self->{LIGHTTPD_PIDFILE}`) { | |
| 148 | diag(sprintf('the process %i is not up', $child)); | |
| 149 | return -1; | |
| 150 | } | |
| 138 | $self->{LIGHTTPD_PID} = $child; | |
| 151 | 139 | |
| 152 | 140 | 0; |
| 153 | 141 | } |
| ... | ...@@ -225,8 +213,9 @@ | |
| 225 | 213 | (my $h = $1) =~ tr/[A-Z]/[a-z]/; |
| 226 | 214 | |
| 227 | 215 | if (defined $resp_hdr{$h}) { |
| 228 | diag(sprintf("header '%s' is duplicated: '%s' and '%s'\n", | |
| 229 | $h, $resp_hdr{$h}, $2)); | |
| 216 | # diag(sprintf("header '%s' is duplicated: '%s' and '%s'\n", | |
| 217 | # $h, $resp_hdr{$h}, $2)); | |
| 218 | $resp_hdr{$h} .= ', '.$2; | |
| 230 | 219 | } else { |
| 231 | 220 | $resp_hdr{$h} = $2; |
| 232 | 221 | } |
| ... | ...@@ -356,11 +345,10 @@ | |
| 356 | 345 | } |
| 357 | 346 | if ($child == 0) { |
| 358 | 347 | my $cmd = $self->{BINDIR}.'/spawn-fcgi -n -p '.$port.' -f "'.$binary.'"'; |
| 359 | exec $cmd; | |
| 348 | exec $cmd or die($?); | |
| 360 | 349 | } else { |
| 361 | select(undef, undef, undef, 0.5); | |
| 362 | if (0 != waitpid($child, WNOHANG)) { | |
| 363 | diag("Child died\n"); | |
| 350 | if (0 != $self->wait_for_port_with_proc($port, $child)) { | |
| 351 | diag(sprintf('The process %i is not up (port %i, %s)', $child, $port, $binary)); | |
| 364 | 352 | return -1; |
| 365 | 353 | } |
| 366 | 354 | return $child; |
| ... | ...@@ -369,6 +357,7 @@ | |
| 369 | 357 | |
| 370 | 358 | sub endspawnfcgi { |
| 371 | 359 | my ($self, $pid) = @_; |
| 360 | return -1 if (-1 == $pid); | |
| 372 | 361 | kill(2, $pid); |
| 373 | 362 | waitpid($pid, 0); |
| 374 | 363 | return 0; |