Commit b11f0d36 authored by Tom Lane's avatar Tom Lane

Improve pg_regress's error reporting for schedule-file problems.

The previous coding here trashed the line buffer as it scanned it,
making it impossible to print the source line in subsequent error
messages.  With a few save/restore/strdup pushups we can improve
that situation.

In passing, move the free'ing of the various strings that are collected
while processing one set of tests down to the bottom of the loop.
That's simpler, less surprising, and should make valgrind less unhappy
about the strings that were previously leaked by the last iteration.
parent ef73a816
...@@ -1593,6 +1593,7 @@ run_schedule(const char *schedule, test_function tfunc) ...@@ -1593,6 +1593,7 @@ run_schedule(const char *schedule, test_function tfunc)
FILE *scf; FILE *scf;
int line_num = 0; int line_num = 0;
memset(tests, 0, sizeof(tests));
memset(resultfiles, 0, sizeof(resultfiles)); memset(resultfiles, 0, sizeof(resultfiles));
memset(expectfiles, 0, sizeof(expectfiles)); memset(expectfiles, 0, sizeof(expectfiles));
memset(tags, 0, sizeof(tags)); memset(tags, 0, sizeof(tags));
...@@ -1615,16 +1616,6 @@ run_schedule(const char *schedule, test_function tfunc) ...@@ -1615,16 +1616,6 @@ run_schedule(const char *schedule, test_function tfunc)
line_num++; line_num++;
/* clear out string lists left over from previous line */
for (i = 0; i < MAX_PARALLEL_TESTS; i++)
{
if (resultfiles[i] == NULL)
break;
free_stringlist(&resultfiles[i]);
free_stringlist(&expectfiles[i]);
free_stringlist(&tags[i]);
}
/* strip trailing whitespace, especially the newline */ /* strip trailing whitespace, especially the newline */
i = strlen(scbuf); i = strlen(scbuf);
while (i > 0 && isspace((unsigned char) scbuf[i - 1])) while (i > 0 && isspace((unsigned char) scbuf[i - 1]))
...@@ -1657,24 +1648,35 @@ run_schedule(const char *schedule, test_function tfunc) ...@@ -1657,24 +1648,35 @@ run_schedule(const char *schedule, test_function tfunc)
num_tests = 0; num_tests = 0;
inword = false; inword = false;
for (c = test; *c; c++) for (c = test;; c++)
{ {
if (isspace((unsigned char) *c)) if (*c == '\0' || isspace((unsigned char) *c))
{ {
*c = '\0'; if (inword)
inword = false; {
/* Reached end of a test name */
char sav;
if (num_tests >= MAX_PARALLEL_TESTS)
{
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s\n"),
MAX_PARALLEL_TESTS, schedule, line_num, scbuf);
exit(2);
}
sav = *c;
*c = '\0';
tests[num_tests] = pg_strdup(test);
num_tests++;
*c = sav;
inword = false;
}
if (*c == '\0')
break; /* loop exit is here */
} }
else if (!inword) else if (!inword)
{ {
if (num_tests >= MAX_PARALLEL_TESTS) /* Start of a test name */
{ test = c;
/* can't print scbuf here, it's already been trashed */
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d\n"),
MAX_PARALLEL_TESTS, schedule, line_num);
exit(2);
}
tests[num_tests] = c;
num_tests++;
inword = true; inword = true;
} }
} }
...@@ -1695,9 +1697,8 @@ run_schedule(const char *schedule, test_function tfunc) ...@@ -1695,9 +1697,8 @@ run_schedule(const char *schedule, test_function tfunc)
} }
else if (max_concurrent_tests > 0 && max_concurrent_tests < num_tests) else if (max_concurrent_tests > 0 && max_concurrent_tests < num_tests)
{ {
/* can't print scbuf here, it's already been trashed */ fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s\n"),
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d\n"), max_concurrent_tests, schedule, line_num, scbuf);
max_concurrent_tests, schedule, line_num);
exit(2); exit(2);
} }
else if (max_connections > 0 && max_connections < num_tests) else if (max_connections > 0 && max_connections < num_tests)
...@@ -1802,6 +1803,15 @@ run_schedule(const char *schedule, test_function tfunc) ...@@ -1802,6 +1803,15 @@ run_schedule(const char *schedule, test_function tfunc)
status_end(); status_end();
} }
for (i = 0; i < num_tests; i++)
{
pg_free(tests[i]);
tests[i] = NULL;
free_stringlist(&resultfiles[i]);
free_stringlist(&expectfiles[i]);
free_stringlist(&tags[i]);
}
} }
free_stringlist(&ignorelist); free_stringlist(&ignorelist);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment