]> granicus.if.org Git - curl/commitdiff
Start using the centralized pidfile and logfile name generation
authorYang Tse <yangsita@gmail.com>
Fri, 8 Jan 2010 15:54:07 +0000 (15:54 +0000)
committerYang Tse <yangsita@gmail.com>
Fri, 8 Jan 2010 15:54:07 +0000 (15:54 +0000)
subroutines for http and tftp test suite servers.

tests/Makefile.am
tests/httpserver.pl
tests/runtests.pl
tests/tftpserver.pl [new file with mode: 0755]

index ba8da787c3a4c13a6241ebe12bc7a988b5cb563e..e5fed714cadae76973cc973808c3d1f9185451c4 100644 (file)
@@ -28,7 +28,7 @@ EXTRA_DIST = ftpserver.pl httpserver.pl httpsserver.pl runtests.pl getpart.pm \
  FILEFORMAT README stunnel.pem memanalyze.pl testcurl.pl valgrind.pm ftp.pm   \
  sshserver.pl sshhelp.pm testcurl.1 runtests.1 $(HTMLPAGES) $(PDFPAGES) \
  CMakeLists.txt certs/scripts/*.sh certs/Server* certs/EdelCurlRoot* \
- serverhelp.pm
+ serverhelp.pm tftpserver.pl
 
 SUBDIRS = data server libtest
 
index 22b79159be5948394e1a3e2885f9105d65c68a73..ae913e7801b6c2d3042dce60671020ddf4b474d8 100755 (executable)
 #!/usr/bin/env perl
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://curl.haxx.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# $Id$
+#***************************************************************************
+
+BEGIN {
+    @INC=(@INC, $ENV{'srcdir'}, '.');
+}
 
 use strict;
+use warnings;
 
-my $verbose=0; # set to 1 for debugging
+use serverhelp qw(
+    server_pidfilename
+    server_logfilename
+    );
 
-my $dir=".";
-my $port = 8999; # just a default
-my $ipv6;
-my $pid=".http.pid"; # name of the pidfile
+my $verbose = 0;     # set to 1 for debugging
+my $port = 8990;     # just a default
+my $ipvnum = 4;      # default IP version of http server
+my $idnum = 1;       # dafault http server instance number
+my $proto = 'http';  # protocol the http server speaks
+my $pidfile;         # http server pid file
+my $logfile;         # http server log file
+my $srcdir;
 my $fork;
 
 my $flags  = "";
+my $path   = '.';
+my $logdir = $path .'/log';
 
-do {
-    if($ARGV[0] eq "-v") {
-        $verbose=1;
+while(@ARGV) {
+    if($ARGV[0] eq '--pidfile') {
+        if($ARGV[1]) {
+            $pidfile = $ARGV[1];
+            shift @ARGV;
+        }
     }
-    elsif($ARGV[0] eq "-d") {
-        $dir=$ARGV[1];
-        shift @ARGV;
+    elsif($ARGV[0] eq '--logfile') {
+        if($ARGV[1]) {
+            $logfile = $ARGV[1];
+            shift @ARGV;
+        }
     }
-    elsif($ARGV[0] eq "-p") {
-        $pid=$ARGV[1];
-        shift @ARGV;
+    elsif($ARGV[0] eq '--srcdir') {
+        if($ARGV[1]) {
+            $srcdir = $ARGV[1];
+            shift @ARGV;
+        }
     }
-    elsif($ARGV[0] eq "--fork") {
-        $fork = $ARGV[0];
-        shift @ARGV;
+    elsif($ARGV[0] eq '--ipv4') {
+        $ipvnum = 4;
+    }
+    elsif($ARGV[0] eq '--ipv6') {
+        $ipvnum = 6;
+    }
+    elsif($ARGV[0] eq '--port') {
+        if($ARGV[1] =~ /^(\d+)$/) {
+            $port = $1;
+            shift @ARGV;
+        }
     }
-    elsif($ARGV[0] =~ /^(\d+)$/) {
-        $port = $1;
+    elsif($ARGV[0] eq '--id') {
+        if($ARGV[1] =~ /^(\d+)$/) {
+            $idnum = $1 if($1 > 0);
+            shift @ARGV;
+        }
     }
-    elsif($ARGV[0] =~ /^ipv6/i) {
-        $ipv6="--ipv6 ";
+    elsif($ARGV[0] eq '--verbose') {
+        $verbose = 1;
     }
-} while(shift @ARGV);
+    elsif($ARGV[0] eq '--fork') {
+        $fork = $ARGV[0];
+    }
+    else {
+        print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
+    }
+    shift @ARGV;
+}
+
+if(!$srcdir) {
+    $srcdir = $ENV{'srcdir'} || '.';
+}
+if(!$pidfile) {
+    $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
+}
+if(!$logfile) {
+    $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
+}
 
-$flags .= "--pidfile \"$pid\" ";
 $flags .= "--fork " if(defined($fork));
-$flags .= "--ipv6 " if(defined($ipv6));
-$flags .= "--port $port --srcdir \"$dir\"";
+$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
+$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
 
 exec("server/sws $flags");
index 3f333063ccb1f127bcc39e1ec186ff526b1e9ac9..20ad732ddb32c1e20976a2544bc0cd6068eda3f6 100755 (executable)
@@ -73,6 +73,8 @@ use Cwd;
 # Subs imported from serverhelp module
 use serverhelp qw(
     servername_str
+    server_pidfilename
+    server_logfilename
     );
 
 # Variables and subs imported from sshhelp module
@@ -803,46 +805,48 @@ sub verifyserver {
 #
 sub runhttpserver {
     my ($verbose, $ipv6) = @_;
-    my $RUNNING;
-    my $pidfile = $HTTPPIDFILE;
     my $port = $HTTPPORT;
     my $ip = $HOSTIP;
     my $proto = 'http';
     my $ipvnum = 4;
     my $idnum = 1;
     my $srvrname;
-    my $fork = $forkserver?"--fork":"";
+    my $pidfile;
+    my $logfile;
+    my $flags = "";
 
     if($ipv6) {
         # if IPv6, use a different setup
         $ipvnum = 6;
-        $pidfile = $HTTP6PIDFILE;
         $port = $HTTP6PORT;
         $ip = $HOST6IP;
     }
 
+    $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
+
     # don't retry if the server doesn't work
     if ($doesntrun{$pidfile}) {
         return (0,0);
     }
 
-    $srvrname = servername_str($proto, $ipvnum, $idnum);
-
     my $pid = processexists($pidfile);
     if($pid > 0) {
         stopserver($pid);
     }
     unlink($pidfile);
 
-    my $flag=$debugprotocol?"-v ":"";
-    my $dir=$ENV{'srcdir'};
-    if($dir) {
-        $flag .= "-d \"$dir\" ";
-    }
+    $srvrname = servername_str($proto, $ipvnum, $idnum);
 
-    my $cmd="$perl $srcdir/httpserver.pl -p $pidfile $fork$flag $port $ipv6";
-    my ($httppid, $pid2) =
-        startnew($cmd, $pidfile, 15, 0); # start the server in a new process
+    $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
+
+    $flags .= "--fork " if($forkserver);
+    $flags .= "--verbose " if($debugprotocol);
+    $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
+    $flags .= "--id $idnum " if($idnum > 1);
+    $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
+
+    my $cmd = "$perl $srcdir/httpserver.pl $flags";
+    my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
 
     if($httppid <= 0 || !kill(0, $httppid)) {
         # it is NOT alive
@@ -854,7 +858,7 @@ sub runhttpserver {
     }
 
     # Server is up. Verify that we can speak to it.
-    my $pid3 = verifyserver("http", $ip, $port);
+    my $pid3 = verifyserver($proto, $ip, $port);
     if(!$pid3) {
         logmsg "RUN: $srvrname server failed verification\n";
         # failed to talk to it properly. Kill the server and return failure
@@ -1132,50 +1136,46 @@ sub runftpsserver {
 #
 sub runtftpserver {
     my ($id, $verbose, $ipv6) = @_;
-    my $STATUS;
-    my $RUNNING;
     my $port = $TFTPPORT;
-    # check for pidfile
-    my $pidfile = $TFTPPIDFILE;
-    my $ip=$HOSTIP;
-    my $cmd;
+    my $ip = $HOSTIP;
     my $proto = 'tftp';
     my $ipvnum = 4;
     my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
     my $srvrname;
+    my $pidfile;
+    my $logfile;
+    my $flags = "";
 
     if($ipv6) {
         # if IPv6, use a different setup
         $ipvnum = 6;
-        $pidfile = $TFTP6PIDFILE;
         $port = $TFTP6PORT;
         $ip = $HOST6IP;
     }
 
+    $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
+
     # don't retry if the server doesn't work
     if ($doesntrun{$pidfile}) {
         return (0,0);
     }
 
-    $srvrname = servername_str($proto, $ipvnum, $idnum);
-
     my $pid = processexists($pidfile);
     if($pid > 0) {
         stopserver($pid);
     }
     unlink($pidfile);
 
-    # start our server:
-    my $flag=$debugprotocol?"-v ":"";
-    $flag .= "--srcdir \"$srcdir\" ";
-    if($idnum > 1) {
-        $flag .="--id $idnum ";
-    }
-    if($ipv6) {
-        $flag .="--ipv6 ";
-    }
+    $srvrname = servername_str($proto, $ipvnum, $idnum);
+
+    $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
 
-    $cmd="./server/tftpd --pidfile $pidfile $flag --port $port";
+    $flags .= "--verbose " if($debugprotocol);
+    $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
+    $flags .= "--id $idnum " if($idnum > 1);
+    $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
+
+    my $cmd = "$perl $srcdir/tftpserver.pl $flags";
     my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
 
     if($tftppid <= 0 || !kill(0, $tftppid)) {
@@ -1188,7 +1188,7 @@ sub runtftpserver {
     }
 
     # Server is up. Verify that we can speak to it.
-    my $pid3 = verifyserver("tftp", $ip, $port);
+    my $pid3 = verifyserver($proto, $ip, $port);
     if(!$pid3) {
         logmsg "RUN: $srvrname server failed verification\n";
         # failed to talk to it properly. Kill the server and return failure
diff --git a/tests/tftpserver.pl b/tests/tftpserver.pl
new file mode 100755 (executable)
index 0000000..78dc99c
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/env perl
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://curl.haxx.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# $Id$
+#***************************************************************************
+
+BEGIN {
+    @INC=(@INC, $ENV{'srcdir'}, '.');
+}
+
+use strict;
+use warnings;
+
+use serverhelp qw(
+    server_pidfilename
+    server_logfilename
+    );
+
+my $verbose = 0;     # set to 1 for debugging
+my $port = 8997;     # just a default
+my $ipvnum = 4;      # default IP version of tftp server
+my $idnum = 1;       # dafault tftp server instance number
+my $proto = 'tftp';  # protocol the tftp server speaks
+my $pidfile;         # tftp server pid file
+my $logfile;         # tftp server log file
+my $srcdir;
+my $fork;
+
+my $flags  = "";
+my $path   = '.';
+my $logdir = $path .'/log';
+
+while(@ARGV) {
+    if($ARGV[0] eq '--pidfile') {
+        if($ARGV[1]) {
+            $pidfile = $ARGV[1];
+            shift @ARGV;
+        }
+    }
+    elsif($ARGV[0] eq '--logfile') {
+        if($ARGV[1]) {
+            $logfile = $ARGV[1];
+            shift @ARGV;
+        }
+    }
+    elsif($ARGV[0] eq '--srcdir') {
+        if($ARGV[1]) {
+            $srcdir = $ARGV[1];
+            shift @ARGV;
+        }
+    }
+    elsif($ARGV[0] eq '--ipv4') {
+        $ipvnum = 4;
+    }
+    elsif($ARGV[0] eq '--ipv6') {
+        $ipvnum = 6;
+    }
+    elsif($ARGV[0] eq '--port') {
+        if($ARGV[1] =~ /^(\d+)$/) {
+            $port = $1;
+            shift @ARGV;
+        }
+    }
+    elsif($ARGV[0] eq '--id') {
+        if($ARGV[1] =~ /^(\d+)$/) {
+            $idnum = $1 if($1 > 0);
+            shift @ARGV;
+        }
+    }
+    elsif($ARGV[0] eq '--verbose') {
+        $verbose = 1;
+    }
+    else {
+        print STDERR "\nWarning: tftpserver.pl unknown parameter: $ARGV[0]\n";
+    }
+    shift @ARGV;
+}
+
+if(!$srcdir) {
+    $srcdir = $ENV{'srcdir'} || '.';
+}
+if(!$pidfile) {
+    $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
+}
+if(!$logfile) {
+    $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
+}
+
+$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
+$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
+
+exec("server/tftpd $flags");