Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b11f0d3

Browse files
committed
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.
1 parent ef73a81 commit b11f0d3

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

src/test/regress/pg_regress.c

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ run_schedule(const char *schedule, test_function tfunc)
15931593
FILE *scf;
15941594
int line_num = 0;
15951595

1596+
memset(tests, 0, sizeof(tests));
15961597
memset(resultfiles, 0, sizeof(resultfiles));
15971598
memset(expectfiles, 0, sizeof(expectfiles));
15981599
memset(tags, 0, sizeof(tags));
@@ -1615,16 +1616,6 @@ run_schedule(const char *schedule, test_function tfunc)
16151616

16161617
line_num++;
16171618

1618-
/* clear out string lists left over from previous line */
1619-
for (i = 0; i < MAX_PARALLEL_TESTS; i++)
1620-
{
1621-
if (resultfiles[i] == NULL)
1622-
break;
1623-
free_stringlist(&resultfiles[i]);
1624-
free_stringlist(&expectfiles[i]);
1625-
free_stringlist(&tags[i]);
1626-
}
1627-
16281619
/* strip trailing whitespace, especially the newline */
16291620
i = strlen(scbuf);
16301621
while (i > 0 && isspace((unsigned char) scbuf[i - 1]))
@@ -1657,24 +1648,35 @@ run_schedule(const char *schedule, test_function tfunc)
16571648

16581649
num_tests = 0;
16591650
inword = false;
1660-
for (c = test; *c; c++)
1651+
for (c = test;; c++)
16611652
{
1662-
if (isspace((unsigned char) *c))
1653+
if (*c == '\0' || isspace((unsigned char) *c))
16631654
{
1664-
*c = '\0';
1665-
inword = false;
1655+
if (inword)
1656+
{
1657+
/* Reached end of a test name */
1658+
char sav;
1659+
1660+
if (num_tests >= MAX_PARALLEL_TESTS)
1661+
{
1662+
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s\n"),
1663+
MAX_PARALLEL_TESTS, schedule, line_num, scbuf);
1664+
exit(2);
1665+
}
1666+
sav = *c;
1667+
*c = '\0';
1668+
tests[num_tests] = pg_strdup(test);
1669+
num_tests++;
1670+
*c = sav;
1671+
inword = false;
1672+
}
1673+
if (*c == '\0')
1674+
break; /* loop exit is here */
16661675
}
16671676
else if (!inword)
16681677
{
1669-
if (num_tests >= MAX_PARALLEL_TESTS)
1670-
{
1671-
/* can't print scbuf here, it's already been trashed */
1672-
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d\n"),
1673-
MAX_PARALLEL_TESTS, schedule, line_num);
1674-
exit(2);
1675-
}
1676-
tests[num_tests] = c;
1677-
num_tests++;
1678+
/* Start of a test name */
1679+
test = c;
16781680
inword = true;
16791681
}
16801682
}
@@ -1695,9 +1697,8 @@ run_schedule(const char *schedule, test_function tfunc)
16951697
}
16961698
else if (max_concurrent_tests > 0 && max_concurrent_tests < num_tests)
16971699
{
1698-
/* can't print scbuf here, it's already been trashed */
1699-
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d\n"),
1700-
max_concurrent_tests, schedule, line_num);
1700+
fprintf(stderr, _("too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s\n"),
1701+
max_concurrent_tests, schedule, line_num, scbuf);
17011702
exit(2);
17021703
}
17031704
else if (max_connections > 0 && max_connections < num_tests)
@@ -1802,6 +1803,15 @@ run_schedule(const char *schedule, test_function tfunc)
18021803

18031804
status_end();
18041805
}
1806+
1807+
for (i = 0; i < num_tests; i++)
1808+
{
1809+
pg_free(tests[i]);
1810+
tests[i] = NULL;
1811+
free_stringlist(&resultfiles[i]);
1812+
free_stringlist(&expectfiles[i]);
1813+
free_stringlist(&tags[i]);
1814+
}
18051815
}
18061816

18071817
free_stringlist(&ignorelist);

0 commit comments

Comments
 (0)