aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-04-17 09:58:42 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-04-18 22:46:04 +0200
commitd009bc2e565844db030d7098624b39b2903a808d (patch)
tree1ccef4e0c1a22960befd8bd413d6fc34e264e806 /tests
parent5e2f4a33fe663c2ae8cc92c02193a7261c524867 (diff)
tests: introduce preprocessed test cases
The runtests script now always performs variable replacement on the entire test source file before the test gets executed, and saves the updated version in a temporary file (log/test[num]) so that all test case readers/servers can use that version (if present) and thus enjoy the powers of test case variable substitution. This is necessary to allow complete port number freedom. Test 309 is updated to work with a non-fixed port number thanks to this.
Diffstat (limited to 'tests')
-rw-r--r--tests/data/test3098
-rw-r--r--tests/getpart.pm25
-rwxr-xr-xtests/runtests.pl216
-rw-r--r--tests/server/fake_ntlm.c17
-rw-r--r--tests/server/mqttd.c4
-rw-r--r--tests/server/rtspd.c15
-rw-r--r--tests/server/sws.c12
-rw-r--r--tests/server/tftpd.c53
-rw-r--r--tests/server/util.c16
-rw-r--r--tests/server/util.h6
10 files changed, 183 insertions, 189 deletions
diff --git a/tests/data/test309 b/tests/data/test309
index dd0431206..80246a9c0 100644
--- a/tests/data/test309
+++ b/tests/data/test309
@@ -14,7 +14,7 @@ followlocation
HTTP/1.1 301 This is a weirdo text message swsclose
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
-Location: https://127.0.0.1:8991/data/3090002.txt?coolsite=yes
+Location: https://127.0.0.1:%HTTPSPORT/data/3090002.txt?coolsite=yes
Connection: close
This server reply is for testing a simple Location: following to HTTPS URL
@@ -33,7 +33,7 @@ If this is received, the location following worked
HTTP/1.1 301 This is a weirdo text message swsclose
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
-Location: https://127.0.0.1:8991/data/3090002.txt?coolsite=yes
+Location: https://127.0.0.1:%HTTPSPORT/data/3090002.txt?coolsite=yes
Connection: close
HTTP/1.1 200 Followed here fine swsclose
@@ -61,10 +61,6 @@ HTTP Location: redirect to HTTPS URL
<command>
-k http://%HOSTIP:%HTTPPORT/want/309 -L
</command>
-# The data section doesn't do variable substitution, so we must assert this
-<precheck>
-perl -e "print 'Test requires default test server host and port' if ( '%HOSTIP' ne '127.0.0.1' || '%HTTPSPORT' ne '8991' );"
-</precheck>
</client>
# Verify data after the test has been "shot"
diff --git a/tests/getpart.pm b/tests/getpart.pm
index 35ab30cb5..9519888ee 100644
--- a/tests/getpart.pm
+++ b/tests/getpart.pm
@@ -209,6 +209,31 @@ sub loadtest {
return 0;
}
+sub fulltest {
+ return @xml;
+}
+
+# write the test to the given file
+sub savetest {
+ my ($file)=@_;
+
+ if(open(XML, ">$file")) {
+ binmode XML; # for crapage systems, use binary
+ for(@xml) {
+ print XML $_;
+ }
+ close(XML);
+ }
+ else {
+ # failure
+ if($warning) {
+ print STDERR "file $file wouldn't open!\n";
+ }
+ return 1;
+ }
+ return 0;
+}
+
#
# Strip off all lines that match the specified pattern and return
# the new array.
diff --git a/tests/runtests.pl b/tests/runtests.pl
index 549db529f..2feb5ae56 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -156,7 +156,7 @@ my $SMBPORT; # SMB server port
my $SMBSPORT; # SMBS server port
my $NEGTELNETPORT; # TELNET server port with negotiation
-my $SSHSRVMD5; # MD5 of ssh server public key
+my $SSHSRVMD5 = "[uninitialized]"; # MD5 of ssh server public key
my $srcdir = $ENV{'srcdir'} || '.';
my $CURL="../src/curl".exe_ext('TOOL'); # what curl executable to run on the tests
@@ -1559,7 +1559,7 @@ sub runhttpserver {
$pid2 = $pid3;
if($verbose) {
- logmsg "RUN: $srvrname server is now running PID $httppid\n";
+ logmsg "RUN: $srvrname server is on PID $httppid port $port\n";
}
sleep(1);
@@ -3119,9 +3119,7 @@ sub checksystem {
logmsg ("* Port range: $minport-$maxport\n");
if($verbose) {
- logmsg "* Ports:\n";
-
- logmsg sprintf("* HTTP/%d ", $HTTPPORT);
+ logmsg "* Ports: ";
logmsg sprintf("FTP/%d ", $FTPPORT);
logmsg sprintf("FTP2/%d ", $FTP2PORT);
logmsg sprintf("RTSP/%d ", $RTSPPORT);
@@ -3131,7 +3129,6 @@ 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) {
@@ -3140,10 +3137,6 @@ sub checksystem {
if($tftp_ipv6) {
logmsg sprintf("TFTP-IPv6/%d ", $TFTP6PORT);
}
- logmsg sprintf("\n* GOPHER/%d ", $GOPHERPORT);
- if($gopher_ipv6) {
- logmsg sprintf("GOPHER-IPv6/%d", $GOPHER6PORT);
- }
logmsg sprintf("\n* SSH/%d ", $SSHPORT);
logmsg sprintf("SOCKS/%d ", $SOCKSPORT);
logmsg sprintf("POP3/%d ", $POP3PORT);
@@ -3184,105 +3177,83 @@ sub checksystem {
# a command, in either case passed by reference
#
sub subVariables {
- my ($thing) = @_;
-
- # ports
-
- $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
- $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
- $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
- $$thing =~ s/%FTPPORT/$FTPPORT/g;
-
- $$thing =~ s/%GOPHER6PORT/$GOPHER6PORT/g;
- $$thing =~ s/%GOPHERPORT/$GOPHERPORT/g;
-
- $$thing =~ s/%HTTPTLS6PORT/$HTTPTLS6PORT/g;
- $$thing =~ s/%HTTPTLSPORT/$HTTPTLSPORT/g;
- $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
- $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
- $$thing =~ s/%HTTP2PORT/$HTTP2PORT/g;
- $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
- $$thing =~ s/%PROXYPORT/$HTTPPROXYPORT/g;
- $$thing =~ s/%MQTTPORT/$MQTTPORT/g;
-
- $$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
- $$thing =~ s/%IMAPPORT/$IMAPPORT/g;
-
- $$thing =~ s/%POP36PORT/$POP36PORT/g;
- $$thing =~ s/%POP3PORT/$POP3PORT/g;
-
- $$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
- $$thing =~ s/%RTSPPORT/$RTSPPORT/g;
-
- $$thing =~ s/%SMTP6PORT/$SMTP6PORT/g;
- $$thing =~ s/%SMTPPORT/$SMTPPORT/g;
-
- $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
- $$thing =~ s/%SSHPORT/$SSHPORT/g;
-
- $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
- $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
-
- $$thing =~ s/%DICTPORT/$DICTPORT/g;
-
- $$thing =~ s/%SMBPORT/$SMBPORT/g;
- $$thing =~ s/%SMBSPORT/$SMBSPORT/g;
-
- $$thing =~ s/%NEGTELNETPORT/$NEGTELNETPORT/g;
-
- # server Unix domain socket paths
-
- $$thing =~ s/%HTTPUNIXPATH/$HTTPUNIXPATH/g;
-
- # client IP addresses
-
- $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
- $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
-
- # server IP addresses
-
- $$thing =~ s/%HOST6IP/$HOST6IP/g;
- $$thing =~ s/%HOSTIP/$HOSTIP/g;
-
- # misc
-
- $$thing =~ s/%CURL/$CURL/g;
- $$thing =~ s/%PWD/$pwd/g;
- $$thing =~ s/%POSIX_PWD/$posix_pwd/g;
-
- my $file_pwd = $pwd;
- if($file_pwd !~ /^\//) {
- $file_pwd = "/$file_pwd";
- }
-
- $$thing =~ s/%FILE_PWD/$file_pwd/g;
- $$thing =~ s/%SRCDIR/$srcdir/g;
- $$thing =~ s/%USER/$USER/g;
-
- if($$thing =~ /%SSHSRVMD5/) {
- if(!$SSHSRVMD5) {
- my $msg = "Fatal: Missing SSH server pubkey MD5. Is server running?";
- logmsg "$msg\n";
- stopservers($verbose);
- die $msg;
- }
- $$thing =~ s/%SSHSRVMD5/$SSHSRVMD5/g;
- }
-
- # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
- # used for time-out tests and that would work on most hosts as these
- # adjust for the startup/check time for this particular host. We needed
- # to do this to make the test suite run better on very slow hosts.
-
- my $ftp2 = $ftpchecktime * 2;
- my $ftp3 = $ftpchecktime * 3;
-
- $$thing =~ s/%FTPTIME2/$ftp2/g;
- $$thing =~ s/%FTPTIME3/$ftp3/g;
-
- # HTTP2
-
- $$thing =~ s/%H2CVER/$h2cver/g;
+ my ($thing, $prefix) = @_;
+
+ if(!$prefix) {
+ $prefix = "%";
+ }
+
+ # test server ports
+ $$thing =~ s/${prefix}FTP6PORT/$FTP6PORT/g;
+ $$thing =~ s/${prefix}FTP2PORT/$FTP2PORT/g;
+ $$thing =~ s/${prefix}FTPSPORT/$FTPSPORT/g;
+ $$thing =~ s/${prefix}FTPPORT/$FTPPORT/g;
+ $$thing =~ s/${prefix}GOPHER6PORT/$GOPHER6PORT/g;
+ $$thing =~ s/${prefix}GOPHERPORT/$GOPHERPORT/g;
+ $$thing =~ s/${prefix}HTTPTLS6PORT/$HTTPTLS6PORT/g;
+ $$thing =~ s/${prefix}HTTPTLSPORT/$HTTPTLSPORT/g;
+ $$thing =~ s/${prefix}HTTP6PORT/$HTTP6PORT/g;
+ $$thing =~ s/${prefix}HTTPSPORT/$HTTPSPORT/g;
+ $$thing =~ s/${prefix}HTTP2PORT/$HTTP2PORT/g;
+ $$thing =~ s/${prefix}HTTPPORT/$HTTPPORT/g;
+ $$thing =~ s/${prefix}PROXYPORT/$HTTPPROXYPORT/g;
+ $$thing =~ s/${prefix}MQTTPORT/$MQTTPORT/g;
+ $$thing =~ s/${prefix}IMAP6PORT/$IMAP6PORT/g;
+ $$thing =~ s/${prefix}IMAPPORT/$IMAPPORT/g;
+ $$thing =~ s/${prefix}POP36PORT/$POP36PORT/g;
+ $$thing =~ s/${prefix}POP3PORT/$POP3PORT/g;
+ $$thing =~ s/${prefix}RTSP6PORT/$RTSP6PORT/g;
+ $$thing =~ s/${prefix}RTSPPORT/$RTSPPORT/g;
+ $$thing =~ s/${prefix}SMTP6PORT/$SMTP6PORT/g;
+ $$thing =~ s/${prefix}SMTPPORT/$SMTPPORT/g;
+ $$thing =~ s/${prefix}SOCKSPORT/$SOCKSPORT/g;
+ $$thing =~ s/${prefix}SSHPORT/$SSHPORT/g;
+ $$thing =~ s/${prefix}TFTP6PORT/$TFTP6PORT/g;
+ $$thing =~ s/${prefix}TFTPPORT/$TFTPPORT/g;
+ $$thing =~ s/${prefix}DICTPORT/$DICTPORT/g;
+ $$thing =~ s/${prefix}SMBPORT/$SMBPORT/g;
+ $$thing =~ s/${prefix}SMBSPORT/$SMBSPORT/g;
+ $$thing =~ s/${prefix}NEGTELNETPORT/$NEGTELNETPORT/g;
+
+ # server Unix domain socket paths
+ $$thing =~ s/${prefix}HTTPUNIXPATH/$HTTPUNIXPATH/g;
+
+ # client IP addresses
+ $$thing =~ s/${prefix}CLIENT6IP/$CLIENT6IP/g;
+ $$thing =~ s/${prefix}CLIENTIP/$CLIENTIP/g;
+
+ # server IP addresses
+ $$thing =~ s/${prefix}HOST6IP/$HOST6IP/g;
+ $$thing =~ s/${prefix}HOSTIP/$HOSTIP/g;
+
+ # misc
+ $$thing =~ s/${prefix}CURL/$CURL/g;
+ $$thing =~ s/${prefix}PWD/$pwd/g;
+ $$thing =~ s/${prefix}POSIX_PWD/$posix_pwd/g;
+
+ my $file_pwd = $pwd;
+ if($file_pwd !~ /^\//) {
+ $file_pwd = "/$file_pwd";
+ }
+
+ $$thing =~ s/${prefix}FILE_PWD/$file_pwd/g;
+ $$thing =~ s/${prefix}SRCDIR/$srcdir/g;
+ $$thing =~ s/${prefix}USER/$USER/g;
+
+ $$thing =~ s/${prefix}SSHSRVMD5/$SSHSRVMD5/g;
+
+ # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
+ # used for time-out tests and that would work on most hosts as these
+ # adjust for the startup/check time for this particular host. We needed to
+ # do this to make the test suite run better on very slow hosts.
+ my $ftp2 = $ftpchecktime * 2;
+ my $ftp3 = $ftpchecktime * 3;
+
+ $$thing =~ s/${prefix}FTPTIME2/$ftp2/g;
+ $$thing =~ s/${prefix}FTPTIME3/$ftp3/g;
+
+ # HTTP2
+ $$thing =~ s/${prefix}H2CVER/$h2cver/g;
}
sub fixarray {
@@ -3498,6 +3469,25 @@ sub singletest {
$why = serverfortest($testnum);
}
+ # Save a preprocessed version of the entire test file. This allows more
+ # "basic" test case readers to enjoy variable replacements.
+ my @entiretest = fulltest();
+ my $otest = "log/test$testnum";
+ open(D, ">$otest");
+ my $diff;
+ for my $s (@entiretest) {
+ my $f = $s;
+ subVariables(\$s, "%");
+ if($f ne $s) {
+ $diff++;
+ }
+ print D $s;
+ }
+ close(D);
+ # remove the separate test file again if nothing was updated to keep
+ # things simpler
+ unlink($otest) if(!$diff);
+
# timestamp required servers verification end
$timesrvrend{$testnum} = Time::HiRes::time();
@@ -3616,6 +3606,9 @@ sub singletest {
map s/\n/\r\n/g, @reply;
}
}
+ for my $r (@reply) {
+ subVariables(\$r);
+ }
# this is the valid protocol blurb curl should generate
my @protocol= fixarray ( getpart("verify", "protocol") );
@@ -4462,7 +4455,7 @@ sub singletest {
$ok .= "v";
}
else {
- if(!$short && !$disablevalgrind) {
+ if($verbose && !$disablevalgrind) {
logmsg " valgrind SKIPPED\n";
}
$ok .= "-"; # skipped
@@ -5662,6 +5655,9 @@ sub displaylogs {
if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(\..*|)$/)) {
next; # skip valgrindNnn of other tests
}
+ if(($log =~ /^test$testnum$/)) {
+ next; # skip test$testnum since it can be very big
+ }
logmsg "=== Start of file $log\n";
displaylogcontent("$LOGDIR/$log");
logmsg "=== End of file $log\n";
diff --git a/tests/server/fake_ntlm.c b/tests/server/fake_ntlm.c
index c6e36b6f6..c9211f7ea 100644
--- a/tests/server/fake_ntlm.c
+++ b/tests/server/fake_ntlm.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2010, Mandy Wu, <mandy.wu@intel.com>
- * Copyright (C) 2011 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2011 - 2020, 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
@@ -112,7 +112,6 @@ int main(int argc, char *argv[])
char buf[1024];
char logfilename[256];
FILE *stream;
- char *filename;
int error;
char *type1_input = NULL, *type3_input = NULL;
char *type1_output = NULL, *type3_output = NULL;
@@ -186,12 +185,10 @@ int main(int argc, char *argv[])
path = env;
}
- filename = test2file(testnum);
- stream = fopen(filename, "rb");
+ stream = test2fopen(testnum);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
exit(1);
}
@@ -205,13 +202,11 @@ int main(int argc, char *argv[])
}
}
- stream = fopen(filename, "rb");
+ stream = test2fopen(testnum);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
- exit(1);
}
else {
size = 0;
@@ -225,11 +220,10 @@ int main(int argc, char *argv[])
while(fgets(buf, sizeof(buf), stdin)) {
if(strcmp(buf, type1_input) == 0) {
- stream = fopen(filename, "rb");
+ stream = test2fopen(testnum);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
exit(1);
}
@@ -247,11 +241,10 @@ int main(int argc, char *argv[])
fflush(stdout);
}
else if(strncmp(buf, type3_input, strlen(type3_input)) == 0) {
- stream = fopen(filename, "rb");
+ stream = test2fopen(testnum);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
exit(1);
}
diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c
index d9ad5923e..db5723cdd 100644
--- a/tests/server/mqttd.c
+++ b/tests/server/mqttd.c
@@ -446,7 +446,6 @@ static curl_socket_t mqttit(curl_socket_t fd)
size_t remaining_length = 0;
size_t bytes = 0; /* remaining length field size in bytes */
char client_id[MAX_CLIENT_ID_LENGTH];
- char *filename;
long testno;
static const char protocol[7] = {
@@ -550,8 +549,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
char *data;
size_t datalen;
logmsg("Found test number %ld", testno);
- filename = test2file(testno);
- stream = fopen(filename, "rb");
+ stream = test2fopen(testno);
error = getpart(&data, &datalen, "reply", "data", stream);
if(!error)
publish(dump, fd, packet_id, topic, data, datalen);
diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c
index c784fc8ca..2d95d8359 100644
--- a/tests/server/rtspd.c
+++ b/tests/server/rtspd.c
@@ -247,8 +247,6 @@ static int ProcessRequest(struct httprequest *req)
/* get the number after it */
if(ptr) {
FILE *stream;
- char *filename;
-
if((strlen(doc) + strlen(request)) < 200)
msnprintf(logbuf, sizeof(logbuf), "Got request: %s %s %s/%d.%d",
request, doc, prot_str, prot_major, prot_minor);
@@ -288,13 +286,11 @@ static int ProcessRequest(struct httprequest *req)
req->testno, req->partno);
logmsg("%s", logbuf);
- filename = test2file(req->testno);
+ stream = test2fopen(req->testno);
- stream = fopen(filename, "rb");
if(!stream) {
int error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", req->testno);
req->open = FALSE; /* closes connection */
return 1; /* done */
@@ -849,17 +845,13 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
count = strlen(buffer);
}
else {
- char *filename = test2file(req->testno);
+ FILE *stream = test2fopen(req->testno);
char partbuf[80]="data";
- FILE *stream;
if(0 != req->partno)
msnprintf(partbuf, sizeof(partbuf), "data%ld", req->partno);
-
- stream = fopen(filename, "rb");
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file");
return 0;
}
@@ -879,11 +871,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
/* re-open the same file again */
- stream = fopen(filename, "rb");
+ stream = test2fopen(req->testno);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file");
free(ptr);
return 0;
diff --git a/tests/server/sws.c b/tests/server/sws.c
index faa1143d9..48ea26d5e 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -235,18 +235,15 @@ static bool socket_domain_is_ip(void)
static int parse_servercmd(struct httprequest *req)
{
FILE *stream;
- char *filename;
int error;
- filename = test2file(req->testno);
+ stream = test2fopen(req->testno);
req->close = FALSE;
req->connmon = FALSE;
- stream = fopen(filename, "rb");
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg(" [1] Error opening file: %s", filename);
logmsg(" Couldn't open test file %ld", req->testno);
req->open = FALSE; /* closes connection */
return 1; /* done */
@@ -991,7 +988,6 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
else {
char partbuf[80];
- char *filename = test2file(req->testno);
/* select the <data> tag for "normal" requests and the <connect> one
for CONNECT requests (within the <reply> section) */
@@ -1004,11 +1000,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
logmsg("Send response test%ld section <%s>", req->testno, partbuf);
- stream = fopen(filename, "rb");
+ stream = test2fopen(req->testno);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg(" [3] Error opening file: %s", filename);
return 0;
}
else {
@@ -1027,11 +1022,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
/* re-open the same file again */
- stream = fopen(filename, "rb");
+ stream = test2fopen(req->testno);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg(" [4] Error opening file: %s", filename);
free(ptr);
return 0;
}
diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c
index 0c94e1cb7..9972ab0e4 100644
--- a/tests/server/tftpd.c
+++ b/tests/server/tftpd.c
@@ -944,16 +944,12 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
static int parse_servercmd(struct testcase *req)
{
FILE *stream;
- char *filename;
int error;
- filename = test2file(req->testno);
-
- stream = fopen(filename, "rb");
+ stream = test2fopen(req->testno);
if(!stream) {
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg(" [1] Error opening file: %s", filename);
logmsg(" Couldn't open test file %ld", req->testno);
return 1; /* done */
}
@@ -1036,7 +1032,7 @@ static int validate_access(struct testcase *test,
char partbuf[80]="data";
long partno;
long testno;
- char *file;
+ FILE *stream;
ptr++; /* skip the slash */
@@ -1061,40 +1057,33 @@ static int validate_access(struct testcase *test,
(void)parse_servercmd(test);
- file = test2file(testno);
+ stream = test2fopen(testno);
if(0 != partno)
msnprintf(partbuf, sizeof(partbuf), "data%ld", partno);
- if(file) {
- FILE *stream = fopen(file, "rb");
- if(!stream) {
- int error = errno;
- logmsg("fopen() failed with error: %d %s", error, strerror(error));
- logmsg("Error opening file: %s", file);
- logmsg("Couldn't open test file: %s", file);
+ if(!stream) {
+ int error = errno;
+ logmsg("fopen() failed with error: %d %s", error, strerror(error));
+ logmsg("Couldn't open test file for test : %d", testno);
+ return EACCESS;
+ }
+ else {
+ size_t count;
+ int error = getpart(&test->buffer, &count, "reply", partbuf, stream);
+ fclose(stream);
+ if(error) {
+ logmsg("getpart() failed with error: %d", error);
return EACCESS;
}
- else {
- size_t count;
- int error = getpart(&test->buffer, &count, "reply", partbuf, stream);
- fclose(stream);
- if(error) {
- logmsg("getpart() failed with error: %d", error);
- return EACCESS;
- }
- if(test->buffer) {
- test->rptr = test->buffer; /* set read pointer */
- test->bufsize = count; /* set total count */
- test->rcount = count; /* set data left to read */
- }
- else
- return EACCESS;
+ if(test->buffer) {
+ test->rptr = test->buffer; /* set read pointer */
+ test->bufsize = count; /* set total count */
+ test->rcount = count; /* set data left to read */
}
-
+ else
+ return EACCESS;
}
- else
- return EACCESS;
}
else {
logmsg("no slash found in path");
diff --git a/tests/server/util.c b/tests/server/util.c
index 169ca5bcb..f576b9c23 100644
--- a/tests/server/util.c
+++ b/tests/server/util.c
@@ -194,11 +194,21 @@ void win32_cleanup(void)
/* set by the main code to point to where the test dir is */
const char *path = ".";
-char *test2file(long testno)
+FILE *test2fopen(long testno)
{
- static char filename[256];
+ FILE *stream;
+ char filename[256];
+ /* first try the alternative, preprocessed, file */
+ msnprintf(filename, sizeof(filename), ALTTEST_DATA_PATH, path, testno);
+ stream = fopen(filename, "rb");
+ if(stream)
+ return stream;
+
+ /* then try the source version */
msnprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno);
- return filename;
+ stream = fopen(filename, "rb");
+
+ return stream;
}
/*
diff --git a/tests/server/util.h b/tests/server/util.h
index 9c3fb9f32..73f5f45f6 100644
--- a/tests/server/util.h
+++ b/tests/server/util.h
@@ -28,6 +28,7 @@ void logmsg(const char *msg, ...);
long timediff(struct timeval newer, struct timeval older);
#define TEST_DATA_PATH "%s/data/test%ld"
+#define ALTTEST_DATA_PATH "%s/log/test%ld"
#define SERVERLOGS_LOCK "log/serverlogs.lock"
@@ -53,8 +54,9 @@ void win32_init(void);
void win32_cleanup(void);
#endif /* USE_WINSOCK */
-/* returns the path name to the test case file */
-char *test2file(long testno);
+/* fopens the test case file */
+FILE *test2fopen(long testno);
+
int wait_ms(int timeout_ms);
int write_pidfile(const char *filename);
int write_portfile(const char *filename, int port);