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.
This commit is contained in:
Daniel Stenberg 2020-04-17 09:58:42 +02:00
parent 5e2f4a33fe
commit d009bc2e56
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
10 changed files with 171 additions and 177 deletions

View file

@ -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");