36#include "pg_config_paths.h"
76#define TESTNAME_WIDTH 36
82#define WAIT_TICKS_PER_SECOND 20
161#define plan(x) emit_tap_output(PLAN, "1..%i", (x))
162#define note(...) emit_tap_output(NOTE, __VA_ARGS__)
163#define note_detail(...) emit_tap_output(NOTE_DETAIL, __VA_ARGS__)
164#define diag(...) emit_tap_output(DIAG, __VA_ARGS__)
165#define note_end() emit_tap_output(NOTE_END, "\n");
166#define bail_noatexit(...) bail_out(true, __VA_ARGS__)
167#define bail(...) bail_out(false, __VA_ARGS__)
172#if defined(HAVE_GETRLIMIT)
179 if (
lim.rlim_max == 0)
181 diag(
"could not set core size: disallowed by hard limit");
186 lim.rlim_cur =
lim.rlim_max;
222 if ((*listhead)->next !=
NULL)
224 free((*listhead)->str);
294 (
ok ? (
int)
strlen(
"not ") : 0),
"",
442 "\"%s%spg_ctl\" stop -D \"%s/data\" -s",
451 bail_noatexit(
_(
"could not stop postmaster: exit code was %d"), r);
503 char *
template =
psprintf(
"%s/pg_regress-XXXXXX",
508 bail(
"could not create directory \"%s\": %m",
template);
548 while (*
str && *pattern)
550 if (*pattern ==
'.' && pattern[1] ==
'*')
554 if (*pattern ==
'\0')
567 if (*
str == *pattern || *pattern ==
'.')
581 else if (*pattern !=
'.' && *
str != *pattern)
594 if (*pattern ==
'\0')
598 while (*pattern ==
'.' && pattern[1] ==
'*')
600 if (*pattern ==
'\0')
633 bail(
"could not open file \"%s\" for reading: %m",
buf);
652 bail(
"incorrectly formatted resultmap entry: %s",
buf);
659 bail(
"incorrectly formatted resultmap entry: %s",
buf);
665 bail(
"incorrectly formatted resultmap entry: %s",
buf);
729 setenv(
"PGAPPNAME",
"pg_regress", 1);
759#if defined(WIN32) || defined(__CYGWIN__) || defined(__darwin__)
772 setenv(
"LC_MESSAGES",
"C", 1);
785 setenv(
"PGTZ",
"America/Los_Angeles", 1);
786 setenv(
"PGDATESTYLE",
"Postgres, MDY", 1);
794 const char *
my_pgoptions =
"-c intervalstyle=postgres_verbose";
837 unsetenv(
"PGSSLMAXPROTOCOLVERSION");
838 unsetenv(
"PGSSLMINPROTOCOLVERSION");
914 note(
"using postmaster on %s, default port",
pghost);
916 note(
"using postmaster on Unix socket, port %s",
pgport);
918 note(
"using postmaster on Unix socket, default port");
972 bail(
"could not get token information buffer size: error code %lu",
978 bail(
"could not get token information: error code %lu",
985 bail(
"could not look up account SID: error code %lu",
1047 hints.ai_socktype = 0;
1048 hints.ai_protocol = 0;
1049 hints.ai_addrlen = 0;
1062 bail("could not write to file \"%s\": %m", fname); \
1065 res =
snprintf(fname,
sizeof(fname),
"%s/pg_hba.conf", pgdata);
1072 bail(
"directory name too long");
1074 hba =
fopen(fname,
"w");
1077 bail(
"could not open file \"%s\" for writing: %m", fname);
1079 CW(
fputs(
"# Configuration written by config_sspi_auth()\n", hba) >= 0);
1080 CW(
fputs(
"host all all 127.0.0.1/32 sspi include_realm=1 map=regress\n",
1083 CW(
fputs(
"host all all ::1/128 sspi include_realm=1 map=regress\n",
1087 snprintf(fname,
sizeof(fname),
"%s/pg_ident.conf", pgdata);
1091 bail(
"could not open file \"%s\" for writing: %m", fname);
1093 CW(
fputs(
"# Configuration written by config_sspi_auth()\n",
ident) >= 0);
1125 "\"%s%spsql\" -X -q",
1181 bail(
"command failed: %s",
buf->data);
1191#define psql_command(database, ...) \
1193 StringInfo cmdbuf = psql_start_command(); \
1194 psql_add_command(cmdbuf, __VA_ARGS__); \
1195 psql_end_command(cmdbuf, database); \
1221 bail(
"could not fork: %m");
1273 diag(
"could not open file \"%s\" for reading: %m", file);
1294 diag(
"could not open file \"%s\" for reading: %m", file);
1322 if (
stat(dir, &st) != 0)
1334 bail(
"could not create directory \"%s\": %m", dir);
1348 if (!(tmp = (
char *)
malloc(ssize)))
1351 if (!(s = (
char *)
malloc(ssize)))
1383 bail(
"diff command failed with status %d: %s", r, cmd);
1393 bail(
"diff command not found: %s", cmd);
1443 "diff %s \"%s\" \"%s\" > \"%s\"",
1457 for (
i = 0;
i <= 9;
i++)
1463 bail(
"Unable to check secondary comparison files: %m");
1472 "diff %s \"%s\" \"%s\" > \"%s\"",
1500 "diff %s \"%s\" \"%s\" > \"%s\"",
1536 "diff %s \"%s\" \"%s\" >> \"%s\"",
1576 bail(
"failed to wait for subprocesses: %m");
1584 bail(
"failed to wait for subprocesses: error code %lu",
1623 diag(
"(test process exited with exit code %d)",
1628 diag(
"(test process was terminated by exception 0x%X)",
1631 diag(
"(test process was terminated by signal %d: %s)",
1636 diag(
"(test process exited with unrecognized status %d)",
exitstatus);
1646#define MAX_PARALLEL_TESTS 100
1666 bail(
"could not open file \"%s\" for reading: %m",
schedule);
1689 bail(
"syntax error in schedule file \"%s\" line %d: %s",
1697 if (*
c ==
'\0' ||
isspace((
unsigned char) *
c))
1706 bail(
"too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s",
1729 bail(
"syntax error in schedule file \"%s\" line %d: %s",
1742 bail(
"too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s",
1749 note_detail(
"parallel group (%d tests, in groups of %d): ",
1805 (*postfunc) (
rl->str);
1809 diag(
"tag: %s",
tl->str);
1883 (*postfunc) (
rl->str);
1887 diag(
"tag: %s",
tl->str);
1971 (
nolocale) ?
" LOCALE='C' LOCALE_PROVIDER='builtin'" :
"");
1974 (
nolocale) ?
" LOCALE='C' LOCALE_PROVIDER='builtin'" :
"");
1976 "ALTER DATABASE \"%s\" SET lc_messages TO 'C';"
1977 "ALTER DATABASE \"%s\" SET lc_monetary TO 'C';"
1978 "ALTER DATABASE \"%s\" SET lc_numeric TO 'C';"
1979 "ALTER DATABASE \"%s\" SET lc_time TO 'C';"
1980 "ALTER DATABASE \"%s\" SET bytea_output TO 'hex';"
1981 "ALTER DATABASE \"%s\" SET timezone_abbreviations TO 'Default';",
2021 printf(
_(
"PostgreSQL regression test driver\n"));
2026 printf(
_(
" --bindir=BINPATH use BINPATH for programs that are run;\n"));
2027 printf(
_(
" if empty, use PATH from the environment\n"));
2028 printf(
_(
" --config-auth=DATADIR update authentication settings for DATADIR\n"));
2029 printf(
_(
" --create-role=ROLE create the specified role before testing\n"));
2030 printf(
_(
" --dbname=DB use database DB (default \"regression\")\n"));
2031 printf(
_(
" --debug turn on debug mode in programs that are run\n"));
2032 printf(
_(
" --dlpath=DIR look for dynamic libraries in DIR\n"));
2033 printf(
_(
" --encoding=ENCODING use ENCODING as the encoding\n"));
2034 printf(
_(
" --expecteddir=DIR take expected files from DIR (default \".\")\n"));
2035 printf(
_(
" -h, --help show this help, then exit\n"));
2036 printf(
_(
" --inputdir=DIR take input files from DIR (default \".\")\n"));
2037 printf(
_(
" --launcher=CMD use CMD as launcher of psql\n"));
2038 printf(
_(
" --load-extension=EXT load the named extension before running the\n"));
2039 printf(
_(
" tests; can appear multiple times\n"));
2040 printf(
_(
" --max-connections=N maximum number of concurrent connections\n"));
2041 printf(
_(
" (default is 0, meaning unlimited)\n"));
2042 printf(
_(
" --max-concurrent-tests=N maximum number of concurrent tests in schedule\n"));
2043 printf(
_(
" (default is 0, meaning unlimited)\n"));
2044 printf(
_(
" --outputdir=DIR place output files in DIR (default \".\")\n"));
2045 printf(
_(
" --schedule=FILE use test ordering schedule from FILE\n"));
2046 printf(
_(
" (can be used multiple times to concatenate)\n"));
2047 printf(
_(
" --temp-instance=DIR create a temporary instance in DIR\n"));
2048 printf(
_(
" --use-existing use an existing installation\n"));
2049 printf(
_(
" -V, --version output version information, then exit\n"));
2051 printf(
_(
"Options for \"temp-instance\" mode:\n"));
2052 printf(
_(
" --no-locale use C locale\n"));
2053 printf(
_(
" --port=PORT start postmaster on PORT\n"));
2054 printf(
_(
" --temp-config=FILE append contents of FILE to temporary config\n"));
2056 printf(
_(
"Options for using an existing installation:\n"));
2057 printf(
_(
" --host=HOST use postmaster running on HOST\n"));
2058 printf(
_(
" --port=PORT use postmaster running at PORT\n"));
2059 printf(
_(
" --user=USER connect as USER\n"));
2061 printf(
_(
"The exit status is 0 if all tests passed, 1 if some tests failed, and 2\n"));
2062 printf(
_(
"if the tests could not be run for some reason.\n"));
2137 if (
getenv(
"PG_REGRESS_DIFF_OPTS"))
2238 while (argc -
optind >= 1)
2250 bail(
"no database name was specified");
2285#if defined(HAVE_GETRLIMIT)
2337 note(
"initializing database system by running initdb");
2340 "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync",
2354 bail(
"initdb failed\n"
2355 "# Examine \"%s/log/initdb.log\" for the reason.\n"
2356 "# Command was: %s",
2363 const char *
copycmd =
"cp -RPp \"%s\" \"%s/data\"";
2366 const char *
copycmd =
"robocopy /E /NJS /NJH /NFL /NDL /NP \"%s\" \"%s/data\"";
2370 note(
"initializing database system by copying initdb template");
2380 bail(
"copying of initdb template failed\n"
2381 "# Examine \"%s/log/initdb.log\" for the reason.\n"
2382 "# Command was: %s",
2400 bail(
"could not open \"%s\" for adding extra config: %m",
buf);
2402 fputs(
"\n# Configuration added by pg_regress\n\n",
pg_conf);
2406 fputs(
"log_line_prefix = '%m %b[%p] %q%a '\n",
pg_conf);
2415 char line_buf[1024];
2420 bail(
"could not open \"%s\" to read extra config: %m",
2459 for (
i = 0;
i < 16;
i++)
2467 note(
"port %d apparently in use",
port);
2469 note(
"could not determine an available port");
2470 bail(
"Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.");
2473 note(
"port %d apparently in use, trying %d",
port,
port + 1);
2486 "\"%s%spostgres\" -D \"%s/data\" -F%s "
2487 "-c \"listen_addresses=%s\" -k \"%s\" "
2488 "> \"%s/log/postmaster.log\" 2>&1",
2496 bail(
"could not spawn postmaster: %m");
2531 bail(
"attempting to connect to postmaster failed");
2542 bail(
"postmaster failed, examine \"%s/log/postmaster.log\" for the reason",
2548 diag(
"postmaster did not respond within %d seconds, examine \"%s/log/postmaster.log\" for the reason",
2559 bail(
"could not kill failed postmaster: %m");
2562 bail(
"could not kill failed postmaster: error code %lu",
2565 bail(
"postmaster failed");
2572#define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2574#define ULONGPID(x) (unsigned long) (x)
2576 note(
"using temp instance on port %d with PID %lu",
2634 diag(
"could not remove temp instance \"%s\"",
2653 diag(
"The differences that caused some tests to fail can be viewed in the file \"%s\".",
2655 diag(
"A copy of the test summary that you see above is saved in the file \"%s\".",
static Datum values[MAXATTR]
#define Assert(condition)
#define PG_TEXTDOMAIN(domain)
#define pg_attribute_printf(f, a)
void set_pglocale_pgservice(const char *argv0, const char *app)
#define fprintf(file, fmt, msg)
PGPing PQpingParams(const char *const *keywords, const char *const *values, int expand_dbname)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
void * pg_realloc(void *ptr, size_t size)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
#define INSTR_TIME_SET_CURRENT(t)
#define INSTR_TIME_SUBTRACT(x, y)
#define INSTR_TIME_GET_MILLISEC(t)
static const JsonPathKeyword keywords[]
void pg_logging_init(const char *argv0)
#define pg_log_error_hint(...)
void pfree(void *pointer)
#define DEFAULT_PGSOCKET_DIR
PGDLLIMPORT char * optarg
static void open_result_files(void)
static int max_connections
static bool port_specified_by_user
static int file_line_count(const char *file)
static char * get_alternative_expectfile(const char *expectfile, int i)
static void load_resultmap(void)
static void psql_add_command(StringInfo buf, const char *query,...) pg_attribute_printf(2
static void static void static void static StringInfo psql_start_command(void)
bool file_exists(const char *file)
static void signal_remove_temp(SIGNAL_ARGS)
static void remove_temp(void)
static void stop_postmaster(void)
static int max_concurrent_tests
static void create_database(const char *dbname)
static void free_stringlist(_stringlist **listhead)
static void drop_role_if_exists(const char *rolename)
#define MAX_PARALLEL_TESTS
static const char * get_expectfile(const char *testname, const char *file)
static void static void psql_end_command(StringInfo buf, const char *database)
static void static void emit_tap_output(TAPtype type, const char *fmt,...) pg_attribute_printf(2
static StringInfo failed_tests
static void unlimit_core_size(void)
static const char * temp_sockdir
static bool directory_exists(const char *dir)
static _stringlist * schedulelist
#define WAIT_TICKS_PER_SECOND
static _stringlist * loadextension
static char * logfilename
static _stringlist * temp_configs
static _stringlist * extra_tests
static void test_status_ok(const char *testname, double runtime, bool parallel)
static void make_directory(const char *dir)
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
static int run_diff(const char *cmd, const char *filename)
static void run_single_test(const char *test, test_start_function startfunc, postprocess_result_function postfunc)
const char * pretty_diff_opts
static void log_child_failure(int exitstatus)
int regression_main(int argc, char *argv[], init_function ifunc, test_start_function startfunc, postprocess_result_function postfunc)
#define bail_noatexit(...)
static char * difffilename
static void bail_out(bool noatexit, const char *fmt,...) pg_attribute_printf(2
static const char * make_temp_sockdir(void)
static _resultmap * resultmap
static char * config_auth_datadir
static void drop_database_if_exists(const char *dbname)
static void test_status_failed(const char *testname, double runtime, bool parallel)
const char * basic_diff_opts
static void initialize_environment(void)
static char * temp_instance
static char sockself[MAXPGPATH]
static void wait_for_tests(PID_TYPE *pids, int *statuses, instr_time *stoptimes, char **names, int num_tests)
static const char * sockdir
static long file_size(const char *file)
static bool postmaster_running
static char socklock[MAXPGPATH]
static const char * progname
static _stringlist * extraroles
static bool results_differ(const char *testname, const char *resultsfile, const char *default_expectfile)
PID_TYPE spawn_process(const char *cmdline)
static void test_status_print(bool ok, const char *testname, double runtime, bool parallel)
static void create_role(const char *rolename, const _stringlist *granted_dbs)
static void run_schedule(const char *schedule, test_start_function startfunc, postprocess_result_function postfunc)
void add_stringlist_item(_stringlist **listhead, const char *str)
static bool string_matches_pattern(const char *str, const char *pattern)
static void static void static void emit_tap_output_v(TAPtype type, const char *fmt, va_list argp) pg_attribute_printf(2
#define psql_command(database,...)
static PID_TYPE postmaster_pid
void(* init_function)(int argc, char **argv)
PID_TYPE(* test_start_function)(const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
void(* postprocess_result_function)(const char *filename)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static const char * pghost
static const char * pgport
char * strsep(char **stringp, const char *delim)
const char * pg_strsignal(int signum)
char * make_absolute_path(const char *path)
char * mkdtemp(char *path)
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define UNIXSOCK_PATH(path, port, sockdir)
char * psprintf(const char *fmt,...)
void get_restricted_token(void)
bool rmtree(const char *path, bool rmtopdir)
void pg_usleep(long microsec)
int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
void destroyStringInfo(StringInfo str)
StringInfo makeStringInfo(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void enlargeStringInfo(StringInfo str, int needed)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
struct _stringlist * next
const char * get_user_name(char **errstr)