1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Test suite support for RTSP

This commit is contained in:
Yang Tse 2010-02-01 12:05:08 +00:00
parent 715e3a806f
commit 35fbeda003
8 changed files with 1720 additions and 10 deletions

View File

@ -128,6 +128,10 @@ pipe: [num] tell the server to expect this many HTTP requests before
sending back anything, to allow pipelining tests
skip: [num] instructs the server to ignore reading this many bytes from a PUT
or POST request
rtp: part [num] channel [num] size [num]
stream a fake RTP packet for the given part on a chosen channel
with the given payload size
</servercmd>
</reply>
@ -148,6 +152,8 @@ scp
sftp
socks4
socks5
rtsp
rtsp-ipv6
Give only one per line. This subsection is mandatory.
</server>
@ -262,6 +268,8 @@ Available substitute variables include:
%TFTP6PORT - IPv6 port number of the TFTP server
%SSHPORT - Port number of the SCP/SFTP server
%SOCKSPORT - Port number of the SOCKS4/5 server
%RTSPPORT - Port number of the RTSP server
%RTSP6PORT - IPv6 port number of the RTSP server
%SRCDIR - Full path to the source dir
%PWD - Current directory
%CURL - Path to the curl executable

View File

@ -28,7 +28,7 @@ EXTRA_DIST = ftpserver.pl httpserver.pl secureserver.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 tftpserver.pl
serverhelp.pm tftpserver.pl rtspserver.pl
SUBDIRS = data server libtest

View File

@ -7,8 +7,3 @@
564
802
803
567
568
569
570
571

109
tests/rtspserver.pl Executable file
View File

@ -0,0 +1,109 @@
#!/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 = 8990; # just a default
my $ipvnum = 4; # default IP version of rtsp server
my $idnum = 1; # dafault rtsp server instance number
my $proto = 'rtsp'; # protocol the rtsp server speaks
my $pidfile; # rtsp server pid file
my $logfile; # rtsp server log file
my $srcdir;
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: rtspserver.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/rtspd $flags");

View File

@ -132,6 +132,8 @@ my $IMAPPORT; # IMAP
my $IMAP6PORT; # IMAP IPv6 server port
my $SMTPPORT; # SMTP
my $SMTP6PORT; # SMTP IPv6 server port
my $RTSPPORT; # RTSP
my $RTSP6PORT; # RTSP IPv6 server port
my $srcdir = $ENV{'srcdir'} || '.';
my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
@ -323,7 +325,7 @@ sub init_serverpidfile_hash {
}
}
}
for my $proto (('tftp', 'sftp', 'socks', 'ssh')) {
for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp')) {
for my $ipvnum ((4, 6)) {
for my $idnum ((1, 2)) {
my $serv = servername_id($proto, $ipvnum, $idnum);
@ -802,6 +804,79 @@ sub verifyftp {
return $pid;
}
#######################################################################
# Verify that the server that runs on $ip, $port is our server. This also
# implies that we can speak with it, as there might be occasions when the
# server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
# assign requested address" #
sub verifyrtsp {
my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
my $server = servername_id($proto, $ipvnum, $idnum);
my $pid = 0;
my $verifyout = "$LOGDIR/".
servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
unlink($verifyout) if(-f $verifyout);
my $verifylog = "$LOGDIR/".
servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
unlink($verifylog) if(-f $verifylog);
my $flags = "--max-time $server_response_maxtime ";
$flags .= "--output $verifyout ";
$flags .= "--silent ";
$flags .= "--verbose ";
$flags .= "--globoff ";
# currently verification is done using http
$flags .= "\"http://$ip:$port/verifiedserver\"";
my $cmd = "$VCURL $flags 2>$verifylog";
# verify if our/any server is running on this port
logmsg "RUN: $cmd\n" if($verbose);
my $res = runclient($cmd);
$res >>= 8; # rotate the result
if($res & 128) {
logmsg "RUN: curl command died with a coredump\n";
return -1;
}
if($res && $verbose) {
logmsg "RUN: curl command returned $res\n";
if(open(FILE, "<$verifylog")) {
while(my $string = <FILE>) {
logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
}
close(FILE);
}
}
my $data;
if(open(FILE, "<$verifyout")) {
while(my $string = <FILE>) {
$data = $string;
last; # only want first line
}
close(FILE);
}
if($data && ($data =~ /RTSP_SERVER WE ROOLZ: (\d+)/)) {
$pid = 0+$1;
}
elsif($res == 6) {
# curl: (6) Couldn't resolve host '::1'
logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
return -1;
}
elsif($data || ($res != 7)) {
logmsg "RUN: Unknown server on our $server port: $port\n";
return -1;
}
return $pid;
}
#######################################################################
# Verify that the ssh server has written out its pidfile, recovering
# the pid from the file and returning it if a process with that pid is
@ -901,6 +976,7 @@ sub verifysocks {
my %protofunc = ('http' => \&verifyhttp,
'https' => \&verifyhttp,
'rtsp' => \&verifyrtsp,
'ftp' => \&verifyftp,
'pop3' => \&verifyftp,
'imap' => \&verifyftp,
@ -1358,6 +1434,87 @@ sub runtftpserver {
}
#######################################################################
# start the rtsp server
#
sub runrtspserver {
my ($verbose, $ipv6) = @_;
my $port = $RTSPPORT;
my $ip = $HOSTIP;
my $proto = 'rtsp';
my $ipvnum = 4;
my $idnum = 1;
my $server;
my $srvrname;
my $pidfile;
my $logfile;
my $flags = "";
if($ipv6) {
# if IPv6, use a different setup
$ipvnum = 6;
$port = $RTSP6PORT;
$ip = $HOST6IP;
}
$server = servername_id($proto, $ipvnum, $idnum);
$pidfile = $serverpidfile{$server};
# don't retry if the server doesn't work
if ($doesntrun{$pidfile}) {
return (0,0);
}
my $pid = processexists($pidfile);
if($pid > 0) {
stopserver($server, "$pid");
}
unlink($pidfile) if(-f $pidfile);
$srvrname = servername_str($proto, $ipvnum, $idnum);
$logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
$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/rtspserver.pl $flags";
my ($rtsppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
if($rtsppid <= 0 || !kill(0, $rtsppid)) {
# it is NOT alive
logmsg "RUN: failed to start the $srvrname server\n";
stopserver($server, "$pid2");
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
return (0,0);
}
# Server is up. Verify that we can speak to it.
my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
if(!$pid3) {
logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver($server, "$rtsppid $pid2");
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
return (0,0);
}
$pid2 = $pid3;
if($verbose) {
logmsg "RUN: $srvrname server is now running PID $rtsppid\n";
}
sleep(1);
return ($rtsppid, $pid2);
}
#######################################################################
# Start the ssh (scp/sftp) server
#
@ -1912,6 +2069,7 @@ sub checksystem {
logmsg sprintf("* HTTP/%d ", $HTTPPORT);
logmsg sprintf("FTP/%d ", $FTPPORT);
logmsg sprintf("FTP2/%d ", $FTP2PORT);
logmsg sprintf("RTSP/%d ", $RTSPPORT);
if($stunnel) {
logmsg sprintf("FTPS/%d ", $FTPSPORT);
logmsg sprintf("HTTPS/%d ", $HTTPSPORT);
@ -1919,6 +2077,7 @@ sub checksystem {
logmsg sprintf("\n* TFTP/%d ", $TFTPPORT);
if($http_ipv6) {
logmsg sprintf("HTTP-IPv6/%d ", $HTTP6PORT);
logmsg sprintf("RTSP-IPv6/%d ", $RTSP6PORT);
}
if($ftp_ipv6) {
logmsg sprintf("FTP-IPv6/%d ", $FTP6PORT);
@ -1973,6 +2132,8 @@ sub subVariables {
$$thing =~ s/%USER/$USER/g;
$$thing =~ s/%CLIENTIP/$CLIENTIP/g;
$$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
$$thing =~ s/%RTSPPORT/$RTSPPORT/g;
$$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
# The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
# used for time-out tests and that whould work on most hosts as these
@ -3053,6 +3214,28 @@ sub startservers {
$run{'http-ipv6'}="$pid $pid2";
}
}
elsif($what eq "rtsp") {
if(!$run{'rtsp'}) {
($pid, $pid2) = runrtspserver($verbose);
if($pid <= 0) {
return "failed starting RTSP server";
}
printf ("* pid rtsp => %d %d\n", $pid, $pid2) if($verbose);
$run{'rtsp'}="$pid $pid2";
}
}
elsif($what eq "rtsp-ipv6") {
if(!$run{'rtsp-ipv6'}) {
($pid, $pid2) = runrtspserver($verbose, "IPv6");
if($pid <= 0) {
return "failed starting RTSP-IPv6 server";
}
logmsg sprintf("* pid rtsp-ipv6 => %d %d\n", $pid, $pid2)
if($verbose);
$run{'rtsp-ipv6'}="$pid $pid2";
}
}
elsif($what eq "ftps") {
if(!$stunnel) {
# we can't run ftps tests without stunnel
@ -3587,6 +3770,8 @@ $IMAPPORT = $base++;
$IMAP6PORT = $base++;
$SMTPPORT = $base++;
$SMTP6PORT = $base++;
$RTSPPORT = $base++;
$RTSP6PORT = $base++;
#######################################################################
# clear and create logging directory:

View File

@ -1,4 +1,4 @@
noinst_PROGRAMS = sws getpart sockfilt resolve tftpd
noinst_PROGRAMS = sws getpart sockfilt resolve tftpd rtspd
useful = getpart.c getpart.h $(top_srcdir)/lib/strequal.c \
$(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c \
@ -20,3 +20,6 @@ getpart_LDADD = @TEST_SERVER_LIBS@
tftpd_SOURCES = tftpd.c util.c util.h $(useful) tftp.h
tftpd_LDADD = @TEST_SERVER_LIBS@
rtspd_SOURCES = rtspd.c util.c util.h $(useful)
rtspd_LDADD = @TEST_SERVER_LIBS@

1410
tests/server/rtspd.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -77,7 +77,7 @@ sub serverfactors {
$idnum = ($3 && ($3 > 1)) ? $3 : 1;
$ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4;
}
elsif($server =~ /^(tftp|sftp|socks|ssh)(\d*)(-ipv6|)$/) {
elsif($server =~ /^(tftp|sftp|socks|ssh|rtsp)(\d*)(-ipv6|)$/) {
$proto = $1;
$idnum = ($2 && ($2 > 1)) ? $2 : 1;
$ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
@ -97,7 +97,7 @@ sub servername_str {
$proto = uc($proto) if($proto);
die "unsupported protocol: $proto" unless($proto &&
($proto =~ /^(((FTP|HTTP|IMAP|POP3|SMTP)S?)|(TFTP|SFTP|SOCKS|SSH))$/));
($proto =~ /^(((FTP|HTTP|IMAP|POP3|SMTP)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP))$/));
$ipver = (not $ipver) ? 'ipv4' : lc($ipver);
die "unsupported IP version: $ipver" unless($ipver &&