27 #ifdef HAVE_SYS_RESOURCE_H 29 #include <sys/resource.h> 37 #include "pg_config_paths.h" 104 #ifdef HAVE_UNIX_SOCKETS 105 static const char *temp_sockdir;
124 static
void psql_command(const
char *database, const
char *query,...) pg_attribute_printf(2, 3);
129 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) 131 unlimit_core_size(
void)
135 getrlimit(RLIMIT_CORE, &lim);
136 if (lim.rlim_max == 0)
139 _(
"%s: could not set core size: disallowed by hard limit\n"),
143 else if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
145 lim.rlim_cur = lim.rlim_max;
146 setrlimit(RLIMIT_CORE, &lim);
162 newentry->
next = NULL;
163 if (*listhead == NULL)
164 *listhead = newentry;
167 for (oldentry = *listhead; oldentry->
next; oldentry = oldentry->
next)
169 oldentry->
next = newentry;
179 if (listhead == NULL || *listhead == NULL)
181 if ((*listhead)->next != NULL)
183 free((*listhead)->str);
195 char *token = strtok(sc, delim);
200 token = strtok(NULL, delim);
218 fprintf(
stdout,
"============== %-38s ==============\n", tmp);
272 "\"%s%spg_ctl\" stop -D \"%s/data\" -s",
279 fprintf(stderr,
_(
"\n%s: could not stop postmaster: exit code was %d\n"),
288 #ifdef HAVE_UNIX_SOCKETS 311 signal_remove_temp(
int signum)
332 make_temp_sockdir(
void)
334 char *
template =
pg_strdup(
"/tmp/pg_regress-XXXXXX");
336 temp_sockdir =
mkdtemp(
template);
337 if (temp_sockdir == NULL)
339 fprintf(stderr,
_(
"%s: could not create directory \"%s\": %s\n"),
346 snprintf(socklock,
sizeof(socklock),
"%s.lock", sockself);
356 pqsignal(SIGINT, signal_remove_temp);
358 pqsignal(SIGTERM, signal_remove_temp);
379 while (*str && *pattern)
381 if (*pattern ==
'.' && pattern[1] ==
'*')
385 if (*pattern ==
'\0')
398 if (*str == *pattern || *pattern ==
'.')
412 else if (*pattern !=
'.' && *str != *pattern)
425 if (*pattern ==
'\0')
429 while (*pattern ==
'.' && pattern[1] ==
'*')
431 if (*pattern ==
'\0')
446 while ((ptr = strstr(
string, replace)) != NULL)
450 strlcpy(
string, dup, ptr -
string + 1);
451 strcat(
string, replacement);
452 strcat(
string, dup + (ptr -
string) + strlen(replace));
477 ret =
stat(indir, &st);
478 if (ret != 0 || !
S_ISDIR(st.st_mode))
507 if (!
rmtree(testtablespace,
true))
509 fprintf(stderr,
_(
"\n%s: could not remove test tablespace \"%s\"\n"),
517 for (name = names; *
name; name++)
527 if (strlen(*name) < 8)
529 if (strcmp(*name + strlen(*name) - 7,
".source") != 0)
535 snprintf(prefix, strlen(*name) - 6,
"%s", *name);
540 infile = fopen(srcfile,
"r");
543 fprintf(stderr,
_(
"%s: could not open file \"%s\" for reading: %s\n"),
547 outfile = fopen(destfile,
"w");
550 fprintf(stderr,
_(
"%s: could not open file \"%s\" for writing: %s\n"),
554 while (fgets(line,
sizeof(line), infile))
561 fputs(line, outfile);
573 fprintf(stderr,
_(
"%s: no *.source files found in \"%s\"\n"),
616 fprintf(stderr,
_(
"%s: could not open file \"%s\" for reading: %s\n"),
621 while (fgets(buf,
sizeof(buf), f))
630 while (i > 0 && isspace((
unsigned char) buf[i - 1]))
634 file_type = strchr(buf,
':');
637 fprintf(stderr,
_(
"incorrectly formatted resultmap entry: %s\n"),
643 platform = strchr(file_type,
':');
646 fprintf(stderr,
_(
"incorrectly formatted resultmap entry: %s\n"),
651 expected = strchr(platform,
'=');
654 fprintf(stderr,
_(
"incorrectly formatted resultmap entry: %s\n"),
694 if (!file || !(file_type = strrchr(file,
'.')))
699 for (rm = resultmap; rm != NULL; rm = rm->
next)
701 if (strcmp(testname, rm->
test) == 0 && strcmp(file_type, rm->
type) == 0)
732 putenv(
"PGAPPNAME=pg_regress");
754 #if defined(WIN32) || defined(__CYGWIN__) || defined(__darwin__) 781 putenv(
"PGDATESTYLE=Postgres, MDY");
789 const char *my_pgoptions =
"-c intervalstyle=postgres_verbose";
790 const char *old_pgoptions = getenv(
"PGOPTIONS");
795 new_pgoptions =
psprintf(
"PGOPTIONS=%s %s",
796 old_pgoptions, my_pgoptions);
816 #ifdef HAVE_UNIX_SOCKETS 821 sockdir = getenv(
"PG_REGRESS_SOCK_DIR");
874 pghost = getenv(
"PGHOST");
875 pgport = getenv(
"PGPORT");
876 #ifndef HAVE_UNIX_SOCKETS 878 pghost =
"localhost";
881 if (pghost && pgport)
882 printf(
_(
"(using postmaster on %s, port %s)\n"), pghost, pgport);
883 if (pghost && !pgport)
884 printf(
_(
"(using postmaster on %s, default port)\n"), pghost);
885 if (!pghost && pgport)
886 printf(
_(
"(using postmaster on Unix socket, port %s)\n"), pgport);
887 if (!pghost && !pgport)
888 printf(
_(
"(using postmaster on Unix socket, default port)\n"));
899 fmtHba(
const char *raw)
905 wp = ret =
realloc(ret, 3 + strlen(raw) * 2);
908 for (rp = raw; *rp; rp++)
925 current_windows_user(
const char **acct,
const char **dom)
930 TOKEN_USER *tokenuser;
932 DWORD accountnamesize =
sizeof(accountname);
933 DWORD domainnamesize =
sizeof(domainname);
934 SID_NAME_USE accountnameuse;
936 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token))
939 _(
"%s: could not open process token: error code %lu\n"),
944 if (!GetTokenInformation(token, TokenUser, NULL, 0, &retlen) && GetLastError() != 122)
947 _(
"%s: could not get token information buffer size: error code %lu\n"),
952 if (!GetTokenInformation(token, TokenUser, tokenuser, retlen, &retlen))
955 _(
"%s: could not get token information: error code %lu\n"),
960 if (!LookupAccountSid(NULL, tokenuser->User.Sid, accountname, &accountnamesize,
961 domainname, &domainnamesize, &accountnameuse))
964 _(
"%s: could not look up account SID: error code %lu\n"),
984 config_sspi_auth(
const char *pgdata,
const char *superuser_name)
986 const char *accountname,
997 current_windows_user(&accountname, &domainname);
1000 if (superuser_name == NULL)
1010 if (superuser_name == NULL)
1035 have_ipv6 = (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0 &&
1036 getaddrinfo(
"::1", NULL, &hints, &gai_result) == 0);
1044 fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"), \ 1045 progname, fname, strerror(errno)); \ 1050 res =
snprintf(fname,
sizeof(fname),
"%s/pg_hba.conf", pgdata);
1051 if (res < 0 || res >=
sizeof(fname))
1060 hba = fopen(fname,
"w");
1063 fprintf(stderr,
_(
"%s: could not open file \"%s\" for writing: %s\n"),
1067 CW(fputs(
"# Configuration written by config_sspi_auth()\n", hba) >= 0);
1068 CW(fputs(
"host all all 127.0.0.1/32 sspi include_realm=1 map=regress\n",
1071 CW(fputs(
"host all all ::1/128 sspi include_realm=1 map=regress\n",
1073 CW(fclose(hba) == 0);
1075 snprintf(fname,
sizeof(fname),
"%s/pg_ident.conf", pgdata);
1076 ident = fopen(fname,
"w");
1079 fprintf(stderr,
_(
"%s: could not open file \"%s\" for writing: %s\n"),
1083 CW(fputs(
"# Configuration written by config_sspi_auth()\n", ident) >= 0);
1090 CW(
fprintf(ident,
"regress \"%s@%s\" %s\n",
1091 accountname, domainname, fmtHba(superuser_name)) >= 0);
1092 for (sl = extraroles; sl; sl = sl->
next)
1093 CW(
fprintf(ident,
"regress \"%s@%s\" %s\n",
1094 accountname, domainname, fmtHba(sl->
str)) >= 0);
1095 CW(fclose(ident) == 0);
1108 char query_formatted[1024];
1109 char query_escaped[2048];
1116 va_start(args, query);
1117 vsnprintf(query_formatted,
sizeof(query_formatted), query, args);
1122 for (s = query_formatted; *s; s++)
1124 if (strchr(
"\\\"$`", *s))
1131 snprintf(psql_cmd,
sizeof(psql_cmd),
1132 "\"%s%spsql\" -X -c \"%s\" \"%s\"",
1138 if (system(psql_cmd) != 0)
1141 fprintf(stderr,
_(
"command failed: %s\n"), psql_cmd);
1169 fprintf(stderr,
_(
"%s: could not fork: %s\n"),
1184 cmdline2 =
psprintf(
"exec %s", cmdline);
1186 fprintf(stderr,
_(
"%s: could not exec \"%s\": %s\n"),
1193 PROCESS_INFORMATION pi;
1195 HANDLE restrictedToken;
1196 const char *comspec;
1199 comspec = getenv(
"COMSPEC");
1200 if (comspec == NULL)
1203 memset(&pi, 0,
sizeof(pi));
1204 cmdline2 =
psprintf(
"\"%s\" /c \"%s\"", comspec, cmdline);
1206 if ((restrictedToken =
1207 CreateRestrictedProcess(cmdline2, &pi)) == 0)
1210 CloseHandle(pi.hThread);
1222 FILE *f = fopen(file,
"r");
1226 fprintf(stderr,
_(
"%s: could not open file \"%s\" for reading: %s\n"),
1230 fseek(f, 0, SEEK_END);
1244 FILE *f = fopen(file,
"r");
1248 fprintf(stderr,
_(
"%s: could not open file \"%s\" for reading: %s\n"),
1252 while ((c = fgetc(f)) != EOF)
1264 FILE *f = fopen(file,
"r");
1277 if (
stat(dir, &st) != 0)
1290 fprintf(stderr,
_(
"%s: could not create directory \"%s\": %s\n"),
1303 int ssize = strlen(expectfile) + 2 + 1;
1307 if (!(tmp = (
char *)
malloc(ssize)))
1310 if (!(s = (
char *)
malloc(ssize)))
1316 strcpy(tmp, expectfile);
1317 last_dot = strrchr(tmp,
'.');
1325 snprintf(s, ssize,
"%s_%d.%s", tmp, i, last_dot + 1);
1341 fprintf(stderr,
_(
"diff command failed with status %d: %s\n"), r, cmd);
1352 fprintf(stderr,
_(
"diff command not found: %s\n"), cmd);
1367 results_differ(
const char *testname,
const char *resultsfile,
const char *default_expectfile)
1374 int best_line_count;
1377 const char *platform_expectfile;
1385 strlcpy(expectfile, default_expectfile,
sizeof(expectfile));
1386 if (platform_expectfile)
1392 char *p = strrchr(expectfile,
'/');
1395 strcpy(++p, platform_expectfile);
1399 snprintf(diff,
sizeof(diff),
"%s.diff", resultsfile);
1403 "diff %s \"%s\" \"%s\" > \"%s\"",
1415 strcpy(best_expect_file, expectfile);
1417 for (i = 0; i <= 9; i++)
1419 char *alt_expectfile;
1422 if (!alt_expectfile)
1424 fprintf(stderr,
_(
"Unable to check secondary comparison files: %s\n"),
1431 free(alt_expectfile);
1436 "diff %s \"%s\" \"%s\" > \"%s\"",
1442 free(alt_expectfile);
1447 if (l < best_line_count)
1450 best_line_count = l;
1451 strlcpy(best_expect_file, alt_expectfile,
sizeof(best_expect_file));
1453 free(alt_expectfile);
1461 if (platform_expectfile)
1464 "diff %s \"%s\" \"%s\" > \"%s\"",
1475 if (l < best_line_count)
1478 best_line_count = l;
1479 strlcpy(best_expect_file, default_expectfile,
sizeof(best_expect_file));
1500 "diff %s \"%s\" \"%s\" >> \"%s\"",
1518 char **names,
int num_tests)
1526 memcpy(active_pids, pids, num_tests *
sizeof(
PID_TYPE));
1529 tests_left = num_tests;
1530 while (tests_left > 0)
1537 p = wait(&exit_status);
1541 fprintf(stderr,
_(
"failed to wait for subprocesses: %s\n"),
1549 r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE);
1550 if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left)
1552 fprintf(stderr,
_(
"failed to wait for subprocesses: error code %lu\n"),
1556 p = active_pids[r - WAIT_OBJECT_0];
1558 active_pids[r - WAIT_OBJECT_0] = active_pids[tests_left - 1];
1561 for (i = 0; i < num_tests; i++)
1566 GetExitCodeProcess(pids[i], &exit_status);
1567 CloseHandle(pids[i]);
1570 statuses[
i] = (int) exit_status;
1592 status(
_(
" (test process exited with exit code %d)"),
1597 status(
_(
" (test process was terminated by exception 0x%X)"),
1600 status(
_(
" (test process was terminated by signal %d: %s)"),
1605 status(
_(
" (test process exited with unrecognized status %d)"),
1615 #define MAX_PARALLEL_TESTS 100 1629 memset(tests, 0,
sizeof(tests));
1630 memset(resultfiles, 0,
sizeof(resultfiles));
1631 memset(expectfiles, 0,
sizeof(expectfiles));
1632 memset(tags, 0,
sizeof(tags));
1634 scf = fopen(schedule,
"r");
1637 fprintf(stderr,
_(
"%s: could not open file \"%s\" for reading: %s\n"),
1642 while (fgets(scbuf,
sizeof(scbuf), scf))
1654 while (i > 0 && isspace((
unsigned char) scbuf[i - 1]))
1657 if (scbuf[0] ==
'\0' || scbuf[0] ==
'#')
1659 if (strncmp(scbuf,
"test: ", 6) == 0)
1661 else if (strncmp(scbuf,
"ignore: ", 8) == 0)
1664 while (*c && isspace((
unsigned char) *c))
1677 fprintf(stderr,
_(
"syntax error in schedule file \"%s\" line %d: %s\n"),
1678 schedule, line_num, scbuf);
1684 for (c = test;; c++)
1686 if (*c ==
'\0' || isspace((
unsigned char) *c))
1695 fprintf(stderr,
_(
"too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s\n"),
1719 fprintf(stderr,
_(
"syntax error in schedule file \"%s\" line %d: %s\n"),
1720 schedule, line_num, scbuf);
1726 status(
_(
"test %-28s ... "), tests[0]);
1727 pids[0] = (tfunc) (tests[0], &resultfiles[0], &expectfiles[0], &tags[0]);
1734 fprintf(stderr,
_(
"too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s\n"),
1742 status(
_(
"parallel group (%d tests, in groups of %d): "),
1744 for (i = 0; i < num_tests; i++)
1750 tests + oldest, i - oldest);
1753 pids[
i] = (tfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1758 tests + oldest, i - oldest);
1763 status(
_(
"parallel group (%d tests): "), num_tests);
1764 for (i = 0; i < num_tests; i++)
1766 pids[
i] = (tfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1774 for (i = 0; i < num_tests; i++)
1779 bool differ =
false;
1782 status(
_(
" %-28s ... "), tests[i]);
1791 for (rl = resultfiles[i], el = expectfiles[i], tl = tags[i];
1794 tl = tl ? tl->
next : NULL)
1808 bool ignore =
false;
1811 for (sl = ignorelist; sl != NULL; sl = sl->
next)
1813 if (strcmp(tests[i], sl->
str) == 0)
1821 status(
_(
"failed (ignored)"));
1836 if (statuses[i] != 0)
1845 for (i = 0; i < num_tests; i++)
1876 bool differ =
false;
1878 status(
_(
"test %-28s ... "), test);
1879 pid = (tfunc) (test, &resultfiles, &expectfiles, &tags);
1890 for (rl = resultfiles, el = expectfiles, tl = tags;
1893 tl = tl ? tl->
next : NULL)
1916 if (exit_status != 0)
1944 fprintf(stderr,
_(
"%s: could not open file \"%s\" for writing: %s\n"),
1955 fprintf(stderr,
_(
"%s: could not open file \"%s\" for writing: %s\n"),
1971 header(
_(
"dropping database \"%s\""), dbname);
1972 psql_command(
"postgres",
"DROP DATABASE IF EXISTS \"%s\"", dbname);
1984 header(
_(
"creating database \"%s\""), dbname);
1986 psql_command(
"postgres",
"CREATE DATABASE \"%s\" TEMPLATE=template0 ENCODING='%s'%s", dbname,
encoding,
1987 (
nolocale) ?
" LC_COLLATE='C' LC_CTYPE='C'" :
"");
1989 psql_command(
"postgres",
"CREATE DATABASE \"%s\" TEMPLATE=template0%s", dbname,
1990 (
nolocale) ?
" LC_COLLATE='C' LC_CTYPE='C'" :
"");
1992 "ALTER DATABASE \"%s\" SET lc_messages TO 'C';" 1993 "ALTER DATABASE \"%s\" SET lc_monetary TO 'C';" 1994 "ALTER DATABASE \"%s\" SET lc_numeric TO 'C';" 1995 "ALTER DATABASE \"%s\" SET lc_time TO 'C';" 1996 "ALTER DATABASE \"%s\" SET bytea_output TO 'hex';" 1997 "ALTER DATABASE \"%s\" SET timezone_abbreviations TO 'Default';",
1998 dbname, dbname, dbname, dbname, dbname, dbname);
2004 for (sl = loadlanguage; sl != NULL; sl = sl->
next)
2014 for (sl = loadextension; sl != NULL; sl = sl->
next)
2017 psql_command(dbname,
"CREATE EXTENSION IF NOT EXISTS \"%s\"", sl->
str);
2024 header(
_(
"dropping role \"%s\""), rolename);
2025 psql_command(
"postgres",
"DROP ROLE IF EXISTS \"%s\"", rolename);
2031 header(
_(
"creating role \"%s\""), rolename);
2032 psql_command(
"postgres",
"CREATE ROLE \"%s\" WITH LOGIN", rolename);
2033 for (; granted_dbs != NULL; granted_dbs = granted_dbs->
next)
2035 psql_command(
"postgres",
"GRANT ALL ON DATABASE \"%s\" TO \"%s\"",
2036 granted_dbs->
str, rolename);
2043 printf(
_(
"PostgreSQL regression test driver\n"));
2048 printf(
_(
" --bindir=BINPATH use BINPATH for programs that are run;\n"));
2049 printf(
_(
" if empty, use PATH from the environment\n"));
2050 printf(
_(
" --config-auth=DATADIR update authentication settings for DATADIR\n"));
2051 printf(
_(
" --create-role=ROLE create the specified role before testing\n"));
2052 printf(
_(
" --dbname=DB use database DB (default \"regression\")\n"));
2053 printf(
_(
" --debug turn on debug mode in programs that are run\n"));
2054 printf(
_(
" --dlpath=DIR look for dynamic libraries in DIR\n"));
2055 printf(
_(
" --encoding=ENCODING use ENCODING as the encoding\n"));
2056 printf(
_(
" -h, --help show this help, then exit\n"));
2057 printf(
_(
" --inputdir=DIR take input files from DIR (default \".\")\n"));
2058 printf(
_(
" --launcher=CMD use CMD as launcher of psql\n"));
2059 printf(
_(
" --load-extension=EXT load the named extension before running the\n"));
2060 printf(
_(
" tests; can appear multiple times\n"));
2061 printf(
_(
" --load-language=LANG load the named language before running the\n"));
2062 printf(
_(
" tests; can appear multiple times\n"));
2063 printf(
_(
" --max-connections=N maximum number of concurrent connections\n"));
2064 printf(
_(
" (default is 0, meaning unlimited)\n"));
2065 printf(
_(
" --max-concurrent-tests=N maximum number of concurrent tests in schedule\n"));
2066 printf(
_(
" (default is 0, meaning unlimited)\n"));
2067 printf(
_(
" --outputdir=DIR place output files in DIR (default \".\")\n"));
2068 printf(
_(
" --schedule=FILE use test ordering schedule from FILE\n"));
2069 printf(
_(
" (can be used multiple times to concatenate)\n"));
2070 printf(
_(
" --temp-instance=DIR create a temporary instance in DIR\n"));
2071 printf(
_(
" --use-existing use an existing installation\n"));
2072 printf(
_(
" -V, --version output version information, then exit\n"));
2074 printf(
_(
"Options for \"temp-instance\" mode:\n"));
2075 printf(
_(
" --no-locale use C locale\n"));
2076 printf(
_(
" --port=PORT start postmaster on PORT\n"));
2077 printf(
_(
" --temp-config=FILE append contents of FILE to temporary config\n"));
2079 printf(
_(
"Options for using an existing installation:\n"));
2080 printf(
_(
" --host=HOST use postmaster running on HOST\n"));
2081 printf(
_(
" --port=PORT use postmaster running at PORT\n"));
2082 printf(
_(
" --user=USER connect as USER\n"));
2084 printf(
_(
"The exit status is 0 if all tests passed, 1 if some tests failed, and 2\n"));
2085 printf(
_(
"if the tests could not be run for some reason.\n"));
2087 printf(
_(
"Report bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
2093 static struct option long_options[] = {
2136 #ifndef HAVE_UNIX_SOCKETS 2147 if (getenv(
"PG_REGRESS_DIFF_OPTS"))
2150 while ((c =
getopt_long(argc, argv,
"hV", long_options, &option_index)) != -1)
2158 puts(
"pg_regress (PostgreSQL) " PG_VERSION);
2239 fprintf(stderr,
_(
"\nTry \"%s -h\" for more information.\n"),
2248 while (argc -
optind >= 1)
2271 port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2284 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) 2285 unlimit_core_size();
2291 const char *env_wait;
2300 header(
_(
"removing existing temp instance"));
2303 fprintf(stderr,
_(
"\n%s: could not remove temp instance \"%s\"\n"),
2309 header(
_(
"creating temporary instance"));
2320 header(
_(
"initializing database system"));
2322 "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync%s%s > \"%s/log/initdb.log\" 2>&1",
2326 debug ?
" --debug" :
"",
2331 fprintf(stderr,
_(
"\n%s: initdb failed\nExamine %s/log/initdb.log for the reason.\nCommand was: %s\n"),
progname,
outputdir, buf);
2344 pg_conf = fopen(buf,
"a");
2345 if (pg_conf == NULL)
2350 fputs(
"\n# Configuration added by pg_regress\n\n", pg_conf);
2351 fputs(
"log_autovacuum_min_duration = 0\n", pg_conf);
2352 fputs(
"log_checkpoints = on\n", pg_conf);
2353 fputs(
"log_line_prefix = '%m [%p] %q%a '\n", pg_conf);
2354 fputs(
"log_lock_waits = on\n", pg_conf);
2355 fputs(
"log_temp_files = 128kB\n", pg_conf);
2356 fputs(
"max_prepared_transactions = 2\n", pg_conf);
2358 for (sl = temp_configs; sl != NULL; sl = sl->
next)
2360 char *temp_config = sl->
str;
2362 char line_buf[1024];
2364 extra_conf = fopen(temp_config,
"r");
2365 if (extra_conf == NULL)
2367 fprintf(stderr,
_(
"\n%s: could not open \"%s\" to read extra config: %s\n"),
progname, temp_config,
strerror(errno));
2370 while (fgets(line_buf,
sizeof(line_buf), extra_conf) != NULL)
2371 fputs(line_buf, pg_conf);
2384 config_sspi_auth(buf, NULL);
2385 #elif !defined(HAVE_UNIX_SOCKETS) 2386 #error Platform has no means to secure the test installation. 2393 "\"%s%spsql\" -X postgres <%s 2>%s",
2394 bindir ? bindir :
"",
2398 for (i = 0; i < 16; i++)
2400 if (system(buf2) == 0)
2406 fprintf(stderr,
_(
"port %d apparently in use\n"),
port);
2408 fprintf(stderr,
_(
"%s: could not determine an available port\n"),
progname);
2409 fprintf(stderr,
_(
"Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.\n"));
2413 fprintf(stderr,
_(
"port %d apparently in use, trying %d\n"),
port,
port + 1);
2425 header(
_(
"starting postmaster"));
2427 "\"%s%spostgres\" -D \"%s/data\" -F%s " 2428 "-c \"listen_addresses=%s\" -k \"%s\" " 2429 "> \"%s/log/postmaster.log\" 2>&1",
2430 bindir ? bindir :
"",
2438 fprintf(stderr,
_(
"\n%s: could not spawn postmaster: %s\n"),
2450 env_wait = getenv(
"PGCTLTIMEOUT");
2451 if (env_wait != NULL)
2453 wait_seconds = atoi(env_wait);
2454 if (wait_seconds <= 0)
2463 if (system(buf2) == 0)
2481 if (i >= wait_seconds)
2483 fprintf(stderr,
_(
"\n%s: postmaster did not respond within %d seconds\nExamine %s/log/postmaster.log for the reason\n"),
2495 fprintf(stderr,
_(
"\n%s: could not kill failed postmaster: %s\n"),
2499 fprintf(stderr,
_(
"\n%s: could not kill failed postmaster: error code %lu\n"),
2510 #define ULONGPID(x) (unsigned long) (unsigned long long) (x) 2512 #define ULONGPID(x) (unsigned long) (x) 2514 printf(
_(
"running on port %d with PID %lu\n"),
2525 for (sl = dblist; sl; sl = sl->
next)
2527 for (sl = extraroles; sl; sl = sl->
next)
2537 for (sl = dblist; sl; sl = sl->
next)
2539 for (sl = extraroles; sl; sl = sl->
next)
2546 header(
_(
"running regression test queries"));
2548 for (sl = schedulelist; sl != NULL; sl = sl->
next)
2553 for (sl = extra_tests; sl != NULL; sl = sl->
next)
2563 header(
_(
"shutting down postmaster"));
2574 header(
_(
"removing temporary instance"));
2576 fprintf(stderr,
_(
"\n%s: could not remove temp instance \"%s\"\n"),
2587 _(
" All %d tests passed. "),
2591 _(
" %d of %d tests passed, %d failed test(s) ignored. "),
2597 _(
" %d of %d tests failed. "),
2603 _(
" %d of %d tests failed, %d of these failures ignored. "),
2609 for (i = strlen(buf); i > 0; i--)
2612 for (i = strlen(buf); i > 0; i--)
2619 printf(
_(
"The differences that caused some tests to fail can be viewed in the\n" 2620 "file \"%s\". A copy of the test summary that you see\n" 2621 "above is saved in the file \"%s\".\n\n"),
char * make_absolute_path(const char *path)
static char * get_alternative_expectfile(const char *expectfile, int i)
static bool directory_exists(const char *dir)
static void drop_role_if_exists(const char *rolename)
PID_TYPE(* test_function)(const char *, _stringlist **, _stringlist **, _stringlist **)
static void drop_database_if_exists(const char *dbname)
#define UNIXSOCK_PATH(path, port, sockdir)
char ** pgfnames(const char *path)
static int max_concurrent_tests
static const char * sockdir
static _stringlist * extra_tests
static void log_child_failure(int exitstatus)
void * pg_malloc(size_t size)
static void initialize_environment(void)
static void run_single_test(const char *test, test_function tfunc)
const char * get_progname(const char *argv0)
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
void get_restricted_token(void)
void pg_logging_init(const char *argv0)
char * psprintf(const char *fmt,...)
static void run_schedule(const char *schedule, test_function tfunc)
#define INSTR_TIME_GET_MILLISEC(t)
struct timeval instr_time
static const char * progname
static void make_directory(const char *dir)
static void status_end(void)
static bool postmaster_running
static bool string_matches_pattern(const char *str, const char *pattern)
static void stop_postmaster(void)
static char * temp_instance
static void convert_sourcefiles(void)
static bool results_differ(const char *testname, const char *resultsfile, const char *default_expectfile)
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
void(* init_function)(int argc, char **argv)
static void convert_sourcefiles_in(const char *source_subdir, const char *dest_dir, const char *dest_subdir, const char *suffix)
#define pg_attribute_printf(f, a)
static void free_stringlist(_stringlist **listhead)
static _stringlist * loadlanguage
PID_TYPE spawn_process(const char *cmdline)
const char * get_user_name(char **errstr)
static char * difffilename
void pg_usleep(long microsec)
#define required_argument
static _resultmap * resultmap
static _stringlist * loadextension
#define INSTR_TIME_SUBTRACT(x, y)
void replace_string(char *string, const char *replace, const char *replacement)
static void static void static void psql_command(const char *database, const char *query,...) pg_attribute_printf(2
static _stringlist * extraroles
static _stringlist * temp_configs
const char * pretty_diff_opts
#define MAX_PARALLEL_TESTS
static void create_role(const char *rolename, const _stringlist *granted_dbs)
char * pg_strdup(const char *in)
static int run_diff(const char *cmd, const char *filename)
static int max_connections
static PID_TYPE postmaster_pid
bool rmtree(const char *path, bool rmtopdir)
static char * config_auth_datadir
#define PG_TEXTDOMAIN(domain)
static int fail_ignore_count
static char * logfilename
static void infile(const char *filename)
pqsigfunc pqsignal(int signum, pqsigfunc handler)
size_t strlcpy(char *dst, const char *src, size_t siz)
static long file_size(const char *file)
#define Assert(condition)
void pgfnames_cleanup(char **filenames)
static bool port_specified_by_user
static const char * get_expectfile(const char *testname, const char *file)
const char * pg_strsignal(int signum)
static int file_line_count(const char *file)
static void load_resultmap(void)
char * mkdtemp(char *path)
static void header(const char *fmt,...) pg_attribute_printf(1
#define INSTR_TIME_SET_CURRENT(t)
static void doputenv(const char *var, const char *val)
struct _resultmap _resultmap
struct addrinfo * ai_next
void set_pglocale_pgservice(const char *argv0, const char *app)
static _stringlist * schedulelist
bool file_exists(const char *file)
struct _stringlist * next
const char * basic_diff_opts
static void open_result_files(void)
static void static void status(const char *fmt,...) pg_attribute_printf(1
struct sockaddr * ai_addr
static void wait_for_tests(PID_TYPE *pids, int *statuses, instr_time *stoptimes, char **names, int num_tests)
static void create_database(const char *dbname)
int regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc)