PostgreSQL Source Code git master
pg_regress.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include "common/logging.h"
#include "common/restricted_token.h"
#include "common/username.h"
#include "getopt_long.h"
#include "lib/stringinfo.h"
#include "libpq-fe.h"
#include "libpq/pqcomm.h"
#include "pg_config_paths.h"
#include "pg_regress.h"
#include "portability/instr_time.h"
Include dependency graph for pg_regress.c:

Go to the source code of this file.

Data Structures

struct  _resultmap
 

Macros

#define TESTNAME_WIDTH   36
 
#define WAIT_TICKS_PER_SECOND   20
 
#define plan(x)   emit_tap_output(PLAN, "1..%i", (x))
 
#define note(...)   emit_tap_output(NOTE, __VA_ARGS__)
 
#define note_detail(...)   emit_tap_output(NOTE_DETAIL, __VA_ARGS__)
 
#define diag(...)   emit_tap_output(DIAG, __VA_ARGS__)
 
#define note_end()   emit_tap_output(NOTE_END, "\n");
 
#define bail_noatexit(...)   bail_out(true, __VA_ARGS__)
 
#define bail(...)   bail_out(false, __VA_ARGS__)
 
#define psql_command(database, ...)
 
#define MAX_PARALLEL_TESTS   100
 
#define ULONGPID(x)   (unsigned long) (x)
 

Typedefs

typedef struct _resultmap _resultmap
 
typedef enum TAPtype TAPtype
 

Enumerations

enum  TAPtype {
  DIAG = 0 , BAIL , NOTE , NOTE_DETAIL ,
  NOTE_END , TEST_STATUS , PLAN , NONE
}
 

Functions

static bool directory_exists (const char *dir)
 
static void make_directory (const char *dir)
 
static void test_status_print (bool ok, const char *testname, double runtime, bool parallel)
 
static void test_status_ok (const char *testname, double runtime, bool parallel)
 
static void test_status_failed (const char *testname, double runtime, bool parallel)
 
static void bail_out (bool noatexit, const char *fmt,...) pg_attribute_printf(2
 
static void static void emit_tap_output (TAPtype type, const char *fmt,...) pg_attribute_printf(2
 
static void static void static void emit_tap_output_v (TAPtype type, const char *fmt, va_list argp) pg_attribute_printf(2
 
static void static void static void static StringInfo psql_start_command (void)
 
static void psql_add_command (StringInfo buf, const char *query,...) pg_attribute_printf(2
 
static void static void psql_end_command (StringInfo buf, const char *database)
 
static void unlimit_core_size (void)
 
void add_stringlist_item (_stringlist **listhead, const char *str)
 
static void free_stringlist (_stringlist **listhead)
 
static void split_to_stringlist (const char *s, const char *delim, _stringlist **listhead)
 
static void stop_postmaster (void)
 
static void remove_temp (void)
 
static void signal_remove_temp (SIGNAL_ARGS)
 
static const char * make_temp_sockdir (void)
 
static bool string_matches_pattern (const char *str, const char *pattern)
 
static void load_resultmap (void)
 
static const char * get_expectfile (const char *testname, const char *file)
 
static void initialize_environment (void)
 
PID_TYPE spawn_process (const char *cmdline)
 
static long file_size (const char *file)
 
static int file_line_count (const char *file)
 
bool file_exists (const char *file)
 
static char * get_alternative_expectfile (const char *expectfile, int i)
 
static int run_diff (const char *cmd, const char *filename)
 
static bool results_differ (const char *testname, const char *resultsfile, const char *default_expectfile)
 
static void wait_for_tests (PID_TYPE *pids, int *statuses, instr_time *stoptimes, char **names, int num_tests)
 
static void log_child_failure (int exitstatus)
 
static void run_schedule (const char *schedule, test_start_function startfunc, postprocess_result_function postfunc)
 
static void run_single_test (const char *test, test_start_function startfunc, postprocess_result_function postfunc)
 
static void open_result_files (void)
 
static void drop_database_if_exists (const char *dbname)
 
static void create_database (const char *dbname)
 
static void drop_role_if_exists (const char *rolename)
 
static void create_role (const char *rolename, const _stringlist *granted_dbs)
 
static void help (void)
 
int regression_main (int argc, char *argv[], init_function ifunc, test_start_function startfunc, postprocess_result_function postfunc)
 

Variables

char * host_platform = HOST_TUPLE
 
static char * shellprog = SHELLPROG
 
const char * basic_diff_opts = ""
 
const char * pretty_diff_opts = "-U3"
 
_stringlistdblist = NULL
 
bool debug = false
 
char * inputdir = "."
 
char * outputdir = "."
 
char * expecteddir = "."
 
char * bindir = PGBINDIR
 
char * launcher = NULL
 
static _stringlistloadextension = NULL
 
static int max_connections = 0
 
static int max_concurrent_tests = 0
 
static char * encoding = NULL
 
static _stringlistschedulelist = NULL
 
static _stringlistextra_tests = NULL
 
static char * temp_instance = NULL
 
static _stringlisttemp_configs = NULL
 
static bool nolocale = false
 
static bool use_existing = false
 
static char * hostname = NULL
 
static int port = -1
 
static char portstr [16]
 
static bool port_specified_by_user = false
 
static char * dlpath = PKGLIBDIR
 
static char * user = NULL
 
static _stringlistextraroles = NULL
 
static char * config_auth_datadir = NULL
 
static const char * progname
 
static char * logfilename
 
static FILE * logfile
 
static char * difffilename
 
static const char * sockdir
 
static const char * temp_sockdir
 
static char sockself [MAXPGPATH]
 
static char socklock [MAXPGPATH]
 
static StringInfo failed_tests = NULL
 
static bool in_note = false
 
static _resultmapresultmap = NULL
 
static PID_TYPE postmaster_pid = INVALID_PID
 
static bool postmaster_running = false
 
static int success_count = 0
 
static int fail_count = 0
 

Macro Definition Documentation

◆ bail

#define bail (   ...)    bail_out(false, __VA_ARGS__)

Definition at line 167 of file pg_regress.c.

◆ bail_noatexit

#define bail_noatexit (   ...)    bail_out(true, __VA_ARGS__)

Definition at line 166 of file pg_regress.c.

◆ diag

#define diag (   ...)    emit_tap_output(DIAG, __VA_ARGS__)

Definition at line 164 of file pg_regress.c.

◆ MAX_PARALLEL_TESTS

#define MAX_PARALLEL_TESTS   100

◆ note

#define note (   ...)    emit_tap_output(NOTE, __VA_ARGS__)

Definition at line 162 of file pg_regress.c.

◆ note_detail

#define note_detail (   ...)    emit_tap_output(NOTE_DETAIL, __VA_ARGS__)

Definition at line 163 of file pg_regress.c.

◆ note_end

#define note_end ( )    emit_tap_output(NOTE_END, "\n");

Definition at line 165 of file pg_regress.c.

◆ plan

#define plan (   x)    emit_tap_output(PLAN, "1..%i", (x))

Definition at line 161 of file pg_regress.c.

◆ psql_command

#define psql_command (   database,
  ... 
)
Value:
do { \
StringInfo cmdbuf = psql_start_command(); \
psql_add_command(cmdbuf, __VA_ARGS__); \
psql_end_command(cmdbuf, database); \
} while (0)
static void static void static void static StringInfo psql_start_command(void)
Definition: pg_regress.c:1120

Definition at line 1191 of file pg_regress.c.

◆ TESTNAME_WIDTH

#define TESTNAME_WIDTH   36

Definition at line 76 of file pg_regress.c.

◆ ULONGPID

#define ULONGPID (   x)    (unsigned long) (x)

◆ WAIT_TICKS_PER_SECOND

#define WAIT_TICKS_PER_SECOND   20

Definition at line 82 of file pg_regress.c.

Typedef Documentation

◆ _resultmap

typedef struct _resultmap _resultmap

◆ TAPtype

typedef enum TAPtype TAPtype

Enumeration Type Documentation

◆ TAPtype

enum TAPtype
Enumerator
DIAG 
BAIL 
NOTE 
NOTE_DETAIL 
NOTE_END 
TEST_STATUS 
PLAN 
NONE 

Definition at line 84 of file pg_regress.c.

85{
86 DIAG = 0,
87 BAIL,
88 NOTE,
92 PLAN,
93 NONE,
94} TAPtype;
TAPtype
Definition: pg_regress.c:85
@ PLAN
Definition: pg_regress.c:92
@ NOTE
Definition: pg_regress.c:88
@ DIAG
Definition: pg_regress.c:86
@ NOTE_DETAIL
Definition: pg_regress.c:89
@ NONE
Definition: pg_regress.c:93
@ TEST_STATUS
Definition: pg_regress.c:91
@ BAIL
Definition: pg_regress.c:87
@ NOTE_END
Definition: pg_regress.c:90

Function Documentation

◆ add_stringlist_item()

void add_stringlist_item ( _stringlist **  listhead,
const char *  str 
)

Definition at line 197 of file pg_regress.c.

198{
199 _stringlist *newentry = pg_malloc(sizeof(_stringlist));
200 _stringlist *oldentry;
201
202 newentry->str = pg_strdup(str);
203 newentry->next = NULL;
204 if (*listhead == NULL)
205 *listhead = newentry;
206 else
207 {
208 for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
209 /* skip */ ;
210 oldentry->next = newentry;
211 }
212}
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
const char * str
char * str
Definition: initdb.c:92
struct _stringlist * next
Definition: initdb.c:93

References _stringlist::next, pg_malloc(), pg_strdup(), _stringlist::str, and str.

Referenced by regression_main(), and split_to_stringlist().

◆ bail_out()

static void bail_out ( bool  noatexit,
const char *  fmt,
  ... 
)
static

Definition at line 255 of file pg_regress.c.

256{
257 va_list ap;
258
259 va_start(ap, fmt);
261 va_end(ap);
262
263 if (noatexit)
264 _exit(2);
265
266 exit(2);
267}
static void const char * fmt
va_end(args)
exit(1)
va_start(args, fmt)
static void static void static void emit_tap_output_v(TAPtype type, const char *fmt, va_list argp) pg_attribute_printf(2
Definition: pg_regress.c:341

References BAIL, emit_tap_output_v(), exit(), fmt, va_end(), and va_start().

Referenced by ProcessConfigFileInternal().

◆ create_database()

static void create_database ( const char *  dbname)
static

Definition at line 1960 of file pg_regress.c.

1961{
1963 _stringlist *sl;
1964
1965 /*
1966 * We use template0 so that any installation-local cruft in template1 will
1967 * not mess up the tests.
1968 */
1969 if (encoding)
1970 psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0 ENCODING='%s'%s", dbname, encoding,
1971 (nolocale) ? " LOCALE='C'" : "");
1972 else
1973 psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0%s", dbname,
1974 (nolocale) ? " LOCALE='C'" : "");
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';",
1983 psql_end_command(buf, "postgres");
1984
1985 /*
1986 * Install any requested extensions. We use CREATE IF NOT EXISTS so that
1987 * this will work whether or not the extension is preinstalled.
1988 */
1989 for (sl = loadextension; sl != NULL; sl = sl->next)
1990 psql_command(dbname, "CREATE EXTENSION IF NOT EXISTS \"%s\"", sl->str);
1991}
static bool nolocale
Definition: pg_regress.c:112
static void psql_add_command(StringInfo buf, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1132
static void static void psql_end_command(StringInfo buf, const char *database)
Definition: pg_regress.c:1169
static _stringlist * loadextension
Definition: pg_regress.c:104
static char * encoding
Definition: pg_regress.c:107
#define psql_command(database,...)
Definition: pg_regress.c:1191
static char * buf
Definition: pg_test_fsync.c:72
char * dbname
Definition: streamutil.c:50

References buf, dbname, encoding, loadextension, _stringlist::next, nolocale, psql_add_command(), psql_command, psql_end_command(), psql_start_command(), and _stringlist::str.

Referenced by regression_main().

◆ create_role()

static void create_role ( const char *  rolename,
const _stringlist granted_dbs 
)
static

Definition at line 2005 of file pg_regress.c.

2006{
2008
2009 psql_add_command(buf, "CREATE ROLE \"%s\" WITH LOGIN", rolename);
2010 for (; granted_dbs != NULL; granted_dbs = granted_dbs->next)
2011 {
2012 psql_add_command(buf, "GRANT ALL ON DATABASE \"%s\" TO \"%s\"",
2013 granted_dbs->str, rolename);
2014 }
2015 psql_end_command(buf, "postgres");
2016}

References buf, _stringlist::next, psql_add_command(), psql_end_command(), psql_start_command(), and _stringlist::str.

Referenced by regression_main().

◆ directory_exists()

static bool directory_exists ( const char *  dir)
static

Definition at line 1318 of file pg_regress.c.

1319{
1320 struct stat st;
1321
1322 if (stat(dir, &st) != 0)
1323 return false;
1324 if (S_ISDIR(st.st_mode))
1325 return true;
1326 return false;
1327}
#define stat
Definition: win32_port.h:274
#define S_ISDIR(m)
Definition: win32_port.h:315

References S_ISDIR, stat::st_mode, and stat.

Referenced by open_result_files(), and regression_main().

◆ drop_database_if_exists()

static void drop_database_if_exists ( const char *  dbname)
static

Definition at line 1949 of file pg_regress.c.

1950{
1952
1953 /* Set warning level so we don't see chatter about nonexistent DB */
1954 psql_add_command(buf, "SET client_min_messages = warning");
1955 psql_add_command(buf, "DROP DATABASE IF EXISTS \"%s\"", dbname);
1956 psql_end_command(buf, "postgres");
1957}

References buf, dbname, psql_add_command(), psql_end_command(), and psql_start_command().

Referenced by regression_main().

◆ drop_role_if_exists()

static void drop_role_if_exists ( const char *  rolename)
static

Definition at line 1994 of file pg_regress.c.

1995{
1997
1998 /* Set warning level so we don't see chatter about nonexistent role */
1999 psql_add_command(buf, "SET client_min_messages = warning");
2000 psql_add_command(buf, "DROP ROLE IF EXISTS \"%s\"", rolename);
2001 psql_end_command(buf, "postgres");
2002}

References buf, psql_add_command(), psql_end_command(), and psql_start_command().

Referenced by regression_main().

◆ emit_tap_output()

static void emit_tap_output ( TAPtype  type,
const char *  fmt,
  ... 
)
static

Definition at line 331 of file pg_regress.c.

332{
333 va_list argp;
334
335 va_start(argp, fmt);
336 emit_tap_output_v(type, fmt, argp);
337 va_end(argp);
338}
const char * type

References emit_tap_output_v(), fmt, type, va_end(), and va_start().

Referenced by test_status_print().

◆ emit_tap_output_v()

static void emit_tap_output_v ( TAPtype  type,
const char *  fmt,
va_list  argp 
)
static

Definition at line 341 of file pg_regress.c.

342{
343 va_list argp_logfile;
344 FILE *fp;
345 int save_errno;
346
347 /*
348 * The fprintf() calls used to output TAP-protocol elements might clobber
349 * errno, so save it here and restore it before vfprintf()-ing the user's
350 * format string, in case it contains %m placeholders.
351 */
352 save_errno = errno;
353
354 /*
355 * Diagnostic output will be hidden by prove unless printed to stderr. The
356 * Bail message is also printed to stderr to aid debugging under a harness
357 * which might otherwise not emit such an important message.
358 */
359 if (type == DIAG || type == BAIL)
360 fp = stderr;
361 else
362 fp = stdout;
363
364 /*
365 * If we are ending a note_detail line we can avoid further processing and
366 * immediately return following a newline.
367 */
368 if (type == NOTE_END)
369 {
370 in_note = false;
371 fprintf(fp, "\n");
372 if (logfile)
373 fprintf(logfile, "\n");
374 return;
375 }
376
377 /* Make a copy of the va args for printing to the logfile */
378 va_copy(argp_logfile, argp);
379
380 /*
381 * Non-protocol output such as diagnostics or notes must be prefixed by a
382 * '#' character. We print the Bail message like this too.
383 */
384 if ((type == NOTE || type == DIAG || type == BAIL)
385 || (type == NOTE_DETAIL && !in_note))
386 {
387 fprintf(fp, "# ");
388 if (logfile)
389 fprintf(logfile, "# ");
390 }
391 errno = save_errno;
392 vfprintf(fp, fmt, argp);
393 if (logfile)
394 {
395 errno = save_errno;
396 vfprintf(logfile, fmt, argp_logfile);
397 }
398
399 /*
400 * If we are entering into a note with more details to follow, register
401 * that the leading '#' has been printed such that subsequent details
402 * aren't prefixed as well.
403 */
404 if (type == NOTE_DETAIL)
405 in_note = true;
406
407 /*
408 * If this was a Bail message, the bail protocol message must go to stdout
409 * separately.
410 */
411 if (type == BAIL)
412 {
413 fprintf(stdout, "Bail out!");
414 if (logfile)
415 fprintf(logfile, "Bail out!");
416 }
417
418 va_end(argp_logfile);
419
420 if (type != NOTE_DETAIL)
421 {
422 fprintf(fp, "\n");
423 if (logfile)
424 fprintf(logfile, "\n");
425 }
426 fflush(NULL);
427}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
static void const char fflush(stdout)
vfprintf(stderr, fmt, args)
static bool in_note
Definition: pg_regress.c:133
static FILE * logfile
Definition: pg_regress.c:126

References BAIL, DIAG, fflush(), fmt, fprintf, in_note, logfile, NOTE, NOTE_DETAIL, NOTE_END, generate_unaccent_rules::stdout, type, va_end(), and vfprintf().

Referenced by bail_out(), and emit_tap_output().

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1307 of file pg_regress.c.

1308{
1309 FILE *f = fopen(file, "r");
1310
1311 if (!f)
1312 return false;
1313 fclose(f);
1314 return true;
1315}

Referenced by isolation_start_test(), psql_start_test(), and results_differ().

◆ file_line_count()

static int file_line_count ( const char *  file)
static

Definition at line 1286 of file pg_regress.c.

1287{
1288 int c;
1289 int l = 0;
1290 FILE *f = fopen(file, "r");
1291
1292 if (!f)
1293 {
1294 diag("could not open file \"%s\" for reading: %m", file);
1295 return -1;
1296 }
1297 while ((c = fgetc(f)) != EOF)
1298 {
1299 if (c == '\n')
1300 l++;
1301 }
1302 fclose(f);
1303 return l;
1304}
#define diag(...)
Definition: pg_regress.c:164
char * c

References diag.

Referenced by results_differ().

◆ file_size()

static long file_size ( const char *  file)
static

Definition at line 1266 of file pg_regress.c.

1267{
1268 long r;
1269 FILE *f = fopen(file, "r");
1270
1271 if (!f)
1272 {
1273 diag("could not open file \"%s\" for reading: %m", file);
1274 return -1;
1275 }
1276 fseek(f, 0, SEEK_END);
1277 r = ftell(f);
1278 fclose(f);
1279 return r;
1280}

References diag.

Referenced by regression_main(), and run_diff().

◆ free_stringlist()

static void free_stringlist ( _stringlist **  listhead)
static

Definition at line 218 of file pg_regress.c.

219{
220 if (listhead == NULL || *listhead == NULL)
221 return;
222 if ((*listhead)->next != NULL)
223 free_stringlist(&((*listhead)->next));
224 free((*listhead)->str);
225 free(*listhead);
226 *listhead = NULL;
227}
#define free(a)
Definition: header.h:65
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:218

References free, and free_stringlist().

Referenced by free_stringlist(), regression_main(), and run_schedule().

◆ get_alternative_expectfile()

static char * get_alternative_expectfile ( const char *  expectfile,
int  i 
)
static

Definition at line 1341 of file pg_regress.c.

1342{
1343 char *last_dot;
1344 int ssize = strlen(expectfile) + 2 + 1;
1345 char *tmp;
1346 char *s;
1347
1348 if (!(tmp = (char *) malloc(ssize)))
1349 return NULL;
1350
1351 if (!(s = (char *) malloc(ssize)))
1352 {
1353 free(tmp);
1354 return NULL;
1355 }
1356
1357 strcpy(tmp, expectfile);
1358 last_dot = strrchr(tmp, '.');
1359 if (!last_dot)
1360 {
1361 free(tmp);
1362 free(s);
1363 return NULL;
1364 }
1365 *last_dot = '\0';
1366 snprintf(s, ssize, "%s_%d.%s", tmp, i, last_dot + 1);
1367 free(tmp);
1368 return s;
1369}
#define malloc(a)
Definition: header.h:50
int i
Definition: isn.c:72
#define snprintf
Definition: port.h:238

References free, i, malloc, and snprintf.

Referenced by results_differ().

◆ get_expectfile()

static const char * get_expectfile ( const char *  testname,
const char *  file 
)
static

Definition at line 694 of file pg_regress.c.

695{
696 char *file_type;
697 _resultmap *rm;
698
699 /*
700 * Determine the file type from the file name. This is just what is
701 * following the last dot in the file name.
702 */
703 if (!file || !(file_type = strrchr(file, '.')))
704 return NULL;
705
706 file_type++;
707
708 for (rm = resultmap; rm != NULL; rm = rm->next)
709 {
710 if (strcmp(testname, rm->test) == 0 && strcmp(file_type, rm->type) == 0)
711 {
712 return rm->resultfile;
713 }
714 }
715
716 return NULL;
717}
static _resultmap * resultmap
Definition: pg_regress.c:135
char * resultfile
Definition: pg_regress.c:45
struct _resultmap * next
Definition: pg_regress.c:46
char * test
Definition: pg_regress.c:43
char * type
Definition: pg_regress.c:44

References _resultmap::next, _resultmap::resultfile, resultmap, _resultmap::test, and _resultmap::type.

Referenced by results_differ().

◆ help()

static void help ( void  )
static

Definition at line 2019 of file pg_regress.c.

2020{
2021 printf(_("PostgreSQL regression test driver\n"));
2022 printf(_("\n"));
2023 printf(_("Usage:\n %s [OPTION]... [EXTRA-TEST]...\n"), progname);
2024 printf(_("\n"));
2025 printf(_("Options:\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"));
2050 printf(_("\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"));
2055 printf(_("\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"));
2060 printf(_("\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"));
2063 printf(_("\n"));
2064 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2065 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
2066}
#define _(x)
Definition: elog.c:90
static const char * progname
Definition: pg_regress.c:124
#define printf(...)
Definition: port.h:244

References _, printf, and progname.

Referenced by regression_main().

◆ initialize_environment()

static void initialize_environment ( void  )
static

Definition at line 723 of file pg_regress.c.

724{
725 /*
726 * Set default application_name. (The test_start_function may choose to
727 * override this, but if it doesn't, we have something useful in place.)
728 */
729 setenv("PGAPPNAME", "pg_regress", 1);
730
731 /*
732 * Set variables that the test scripts may need to refer to.
733 */
734 setenv("PG_ABS_SRCDIR", inputdir, 1);
735 setenv("PG_ABS_BUILDDIR", outputdir, 1);
736 setenv("PG_LIBDIR", dlpath, 1);
737 setenv("PG_DLSUFFIX", DLSUFFIX, 1);
738
739 if (nolocale)
740 {
741 /*
742 * Clear out any non-C locale settings
743 */
744 unsetenv("LC_COLLATE");
745 unsetenv("LC_CTYPE");
746 unsetenv("LC_MONETARY");
747 unsetenv("LC_NUMERIC");
748 unsetenv("LC_TIME");
749 unsetenv("LANG");
750
751 /*
752 * Most platforms have adopted the POSIX locale as their
753 * implementation-defined default locale. Exceptions include native
754 * Windows, macOS with --enable-nls, and Cygwin with --enable-nls.
755 * (Use of --enable-nls matters because libintl replaces setlocale().)
756 * Also, PostgreSQL does not support macOS with locale environment
757 * variables unset; see PostmasterMain().
758 */
759#if defined(WIN32) || defined(__CYGWIN__) || defined(__darwin__)
760 setenv("LANG", "C", 1);
761#endif
762 }
763
764 /*
765 * Set translation-related settings to English; otherwise psql will
766 * produce translated messages and produce diffs. (XXX If we ever support
767 * translation of pg_regress, this needs to be moved elsewhere, where psql
768 * is actually called.)
769 */
770 unsetenv("LANGUAGE");
771 unsetenv("LC_ALL");
772 setenv("LC_MESSAGES", "C", 1);
773
774 /*
775 * Set encoding as requested
776 */
777 if (encoding)
778 setenv("PGCLIENTENCODING", encoding, 1);
779 else
780 unsetenv("PGCLIENTENCODING");
781
782 /*
783 * Set timezone and datestyle for datetime-related tests
784 */
785 setenv("PGTZ", "America/Los_Angeles", 1);
786 setenv("PGDATESTYLE", "Postgres, MDY", 1);
787
788 /*
789 * Likewise set intervalstyle to ensure consistent results. This is a bit
790 * more painful because we must use PGOPTIONS, and we want to preserve the
791 * user's ability to set other variables through that.
792 */
793 {
794 const char *my_pgoptions = "-c intervalstyle=postgres_verbose";
795 const char *old_pgoptions = getenv("PGOPTIONS");
796 char *new_pgoptions;
797
798 if (!old_pgoptions)
799 old_pgoptions = "";
800 new_pgoptions = psprintf("%s %s",
801 old_pgoptions, my_pgoptions);
802 setenv("PGOPTIONS", new_pgoptions, 1);
803 free(new_pgoptions);
804 }
805
806 if (temp_instance)
807 {
808 /*
809 * Clear out any environment vars that might cause psql to connect to
810 * the wrong postmaster, or otherwise behave in nondefault ways. (Note
811 * we also use psql's -X switch consistently, so that ~/.psqlrc files
812 * won't mess things up.) Also, set PGPORT to the temp port, and set
813 * PGHOST depending on whether we are using TCP or Unix sockets.
814 *
815 * This list should be kept in sync with PostgreSQL/Test/Utils.pm.
816 */
817 unsetenv("PGCHANNELBINDING");
818 /* PGCLIENTENCODING, see above */
819 unsetenv("PGCONNECT_TIMEOUT");
820 unsetenv("PGDATA");
821 unsetenv("PGDATABASE");
822 unsetenv("PGGSSDELEGATION");
823 unsetenv("PGGSSENCMODE");
824 unsetenv("PGGSSLIB");
825 /* PGHOSTADDR, see below */
826 unsetenv("PGKRBSRVNAME");
827 unsetenv("PGPASSFILE");
828 unsetenv("PGPASSWORD");
829 unsetenv("PGREQUIREPEER");
830 unsetenv("PGREQUIRESSL");
831 unsetenv("PGSERVICE");
832 unsetenv("PGSERVICEFILE");
833 unsetenv("PGSSLCERT");
834 unsetenv("PGSSLCRL");
835 unsetenv("PGSSLCRLDIR");
836 unsetenv("PGSSLKEY");
837 unsetenv("PGSSLMAXPROTOCOLVERSION");
838 unsetenv("PGSSLMINPROTOCOLVERSION");
839 unsetenv("PGSSLMODE");
840 unsetenv("PGSSLROOTCERT");
841 unsetenv("PGSSLSNI");
842 unsetenv("PGTARGETSESSIONATTRS");
843 unsetenv("PGUSER");
844 /* PGPORT, see below */
845 /* PGHOST, see below */
846
847 if (hostname != NULL)
848 setenv("PGHOST", hostname, 1);
849 else
850 {
851 sockdir = getenv("PG_REGRESS_SOCK_DIR");
852 if (!sockdir)
854 setenv("PGHOST", sockdir, 1);
855 }
856 unsetenv("PGHOSTADDR");
857 if (port != -1)
858 {
859 char s[16];
860
861 snprintf(s, sizeof(s), "%d", port);
862 setenv("PGPORT", s, 1);
863 }
864 }
865 else
866 {
867 const char *pghost;
868 const char *pgport;
869
870 /*
871 * When testing an existing install, we honor existing environment
872 * variables, except if they're overridden by command line options.
873 */
874 if (hostname != NULL)
875 {
876 setenv("PGHOST", hostname, 1);
877 unsetenv("PGHOSTADDR");
878 }
879 if (port != -1)
880 {
881 char s[16];
882
883 snprintf(s, sizeof(s), "%d", port);
884 setenv("PGPORT", s, 1);
885 }
886 if (user != NULL)
887 setenv("PGUSER", user, 1);
888
889 /*
890 * However, we *don't* honor PGDATABASE, since we certainly don't wish
891 * to connect to whatever database the user might like as default.
892 * (Most tests override PGDATABASE anyway, but there are some ECPG
893 * test cases that don't.)
894 */
895 unsetenv("PGDATABASE");
896
897 /*
898 * Report what we're connecting to
899 */
900 pghost = getenv("PGHOST");
901 pgport = getenv("PGPORT");
902 if (!pghost)
903 {
904 /* Keep this bit in sync with libpq's default host location: */
906 /* do nothing, we'll print "Unix socket" below */ ;
907 else
908 pghost = "localhost"; /* DefaultHost in fe-connect.c */
909 }
910
911 if (pghost && pgport)
912 note("using postmaster on %s, port %s", pghost, pgport);
913 if (pghost && !pgport)
914 note("using postmaster on %s, default port", pghost);
915 if (!pghost && pgport)
916 note("using postmaster on Unix socket, port %s", pgport);
917 if (!pghost && !pgport)
918 note("using postmaster on Unix socket, default port");
919 }
920
922}
#define DEFAULT_PGSOCKET_DIR
static char * user
Definition: pg_regress.c:119
static void load_resultmap(void)
Definition: pg_regress.c:620
static int port
Definition: pg_regress.c:115
char * outputdir
Definition: pg_regress.c:100
#define note(...)
Definition: pg_regress.c:162
char * inputdir
Definition: pg_regress.c:99
static const char * make_temp_sockdir(void)
Definition: pg_regress.c:501
static char * temp_instance
Definition: pg_regress.c:110
static const char * sockdir
Definition: pg_regress.c:128
static char * dlpath
Definition: pg_regress.c:118
static char * hostname
Definition: pg_regress.c:114
static const char * pghost
Definition: pgbench.c:294
static const char * pgport
Definition: pgbench.c:295
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
#define unsetenv(x)
Definition: win32_port.h:546
#define setenv(x, y, z)
Definition: win32_port.h:545

References DEFAULT_PGSOCKET_DIR, dlpath, encoding, free, hostname, inputdir, load_resultmap(), make_temp_sockdir(), nolocale, note, outputdir, pghost, pgport, port, psprintf(), setenv, snprintf, sockdir, temp_instance, unsetenv, and user.

Referenced by regression_main().

◆ load_resultmap()

static void load_resultmap ( void  )
static

Definition at line 620 of file pg_regress.c.

621{
622 char buf[MAXPGPATH];
623 FILE *f;
624
625 /* scan the file ... */
626 snprintf(buf, sizeof(buf), "%s/resultmap", inputdir);
627 f = fopen(buf, "r");
628 if (!f)
629 {
630 /* OK if it doesn't exist, else complain */
631 if (errno == ENOENT)
632 return;
633 bail("could not open file \"%s\" for reading: %m", buf);
634 }
635
636 while (fgets(buf, sizeof(buf), f))
637 {
638 char *platform;
639 char *file_type;
640 char *expected;
641 int i;
642
643 /* strip trailing whitespace, especially the newline */
644 i = strlen(buf);
645 while (i > 0 && isspace((unsigned char) buf[i - 1]))
646 buf[--i] = '\0';
647
648 /* parse out the line fields */
649 file_type = strchr(buf, ':');
650 if (!file_type)
651 {
652 bail("incorrectly formatted resultmap entry: %s", buf);
653 }
654 *file_type++ = '\0';
655
656 platform = strchr(file_type, ':');
657 if (!platform)
658 {
659 bail("incorrectly formatted resultmap entry: %s", buf);
660 }
661 *platform++ = '\0';
662 expected = strchr(platform, '=');
663 if (!expected)
664 {
665 bail("incorrectly formatted resultmap entry: %s", buf);
666 }
667 *expected++ = '\0';
668
669 /*
670 * if it's for current platform, save it in resultmap list. Note: by
671 * adding at the front of the list, we ensure that in ambiguous cases,
672 * the last match in the resultmap file is used. This mimics the
673 * behavior of the old shell script.
674 */
676 {
677 _resultmap *entry = pg_malloc(sizeof(_resultmap));
678
679 entry->test = pg_strdup(buf);
680 entry->type = pg_strdup(file_type);
681 entry->resultfile = pg_strdup(expected);
682 entry->next = resultmap;
683 resultmap = entry;
684 }
685 }
686 fclose(f);
687}
#define MAXPGPATH
char * host_platform
Definition: pg_regress.c:52
#define bail(...)
Definition: pg_regress.c:167
static bool string_matches_pattern(const char *str, const char *pattern)
Definition: pg_regress.c:546

References bail, buf, host_platform, i, inputdir, MAXPGPATH, _resultmap::next, pg_malloc(), pg_strdup(), _resultmap::resultfile, resultmap, snprintf, string_matches_pattern(), _resultmap::test, and _resultmap::type.

Referenced by initialize_environment().

◆ log_child_failure()

static void log_child_failure ( int  exitstatus)
static

Definition at line 1620 of file pg_regress.c.

1621{
1622 if (WIFEXITED(exitstatus))
1623 diag("(test process exited with exit code %d)",
1624 WEXITSTATUS(exitstatus));
1625 else if (WIFSIGNALED(exitstatus))
1626 {
1627#if defined(WIN32)
1628 diag("(test process was terminated by exception 0x%X)",
1629 WTERMSIG(exitstatus));
1630#else
1631 diag("(test process was terminated by signal %d: %s)",
1632 WTERMSIG(exitstatus), pg_strsignal(WTERMSIG(exitstatus)));
1633#endif
1634 }
1635 else
1636 diag("(test process exited with unrecognized status %d)", exitstatus);
1637}
const char * pg_strsignal(int signum)
Definition: pgstrsignal.c:39
#define WIFEXITED(w)
Definition: win32_port.h:150
#define WIFSIGNALED(w)
Definition: win32_port.h:151
#define WTERMSIG(w)
Definition: win32_port.h:153
#define WEXITSTATUS(w)
Definition: win32_port.h:152

References diag, pg_strsignal(), WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.

Referenced by run_schedule(), and run_single_test().

◆ make_directory()

static void make_directory ( const char *  dir)
static

Definition at line 1331 of file pg_regress.c.

1332{
1333 if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
1334 bail("could not create directory \"%s\": %m", dir);
1335}
#define S_IRWXG
Definition: win32_port.h:300
#define S_IRWXO
Definition: win32_port.h:312
#define mkdir(a, b)
Definition: win32_port.h:80
#define S_IRWXU
Definition: win32_port.h:288

References bail, mkdir, S_IRWXG, S_IRWXO, and S_IRWXU.

Referenced by open_result_files(), and regression_main().

◆ make_temp_sockdir()

static const char * make_temp_sockdir ( void  )
static

Definition at line 501 of file pg_regress.c.

502{
503 char *template = psprintf("%s/pg_regress-XXXXXX",
504 getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
505
506 temp_sockdir = mkdtemp(template);
507 if (temp_sockdir == NULL)
508 bail("could not create directory \"%s\": %m", template);
509
510 /* Stage file names for remove_temp(). Unsafe in a signal handler. */
512 snprintf(socklock, sizeof(socklock), "%s.lock", sockself);
513
514 /* Remove the directory during clean exit. */
515 atexit(remove_temp);
516
517 /*
518 * Remove the directory before dying to the usual signals. Omit SIGQUIT,
519 * preserving it as a quick, untidy exit.
520 */
523
524 /* the following are not valid on Windows */
525#ifndef WIN32
528#endif
529
530 return temp_sockdir;
531}
static void signal_remove_temp(SIGNAL_ARGS)
Definition: pg_regress.c:480
static void remove_temp(void)
Definition: pg_regress.c:468
static const char * temp_sockdir
Definition: pg_regress.c:129
static char sockself[MAXPGPATH]
Definition: pg_regress.c:130
static char socklock[MAXPGPATH]
Definition: pg_regress.c:131
#define pqsignal
Definition: port.h:520
char * mkdtemp(char *path)
Definition: mkdtemp.c:286
#define UNIXSOCK_PATH(path, port, sockdir)
Definition: pqcomm.h:44
#define SIGHUP
Definition: win32_port.h:158
#define SIGPIPE
Definition: win32_port.h:163

References bail, mkdtemp(), port, pqsignal, psprintf(), remove_temp(), SIGHUP, signal_remove_temp(), SIGPIPE, snprintf, socklock, sockself, temp_sockdir, and UNIXSOCK_PATH.

Referenced by initialize_environment().

◆ open_result_files()

static void open_result_files ( void  )
static

Definition at line 1916 of file pg_regress.c.

1917{
1918 char file[MAXPGPATH];
1919 FILE *difffile;
1920
1921 /* create outputdir directory if not present */
1924
1925 /* create the log file (copy of running status output) */
1926 snprintf(file, sizeof(file), "%s/regression.out", outputdir);
1927 logfilename = pg_strdup(file);
1928 logfile = fopen(logfilename, "w");
1929 if (!logfile)
1930 bail("could not open file \"%s\" for writing: %m", logfilename);
1931
1932 /* create the diffs file as empty */
1933 snprintf(file, sizeof(file), "%s/regression.diffs", outputdir);
1934 difffilename = pg_strdup(file);
1935 difffile = fopen(difffilename, "w");
1936 if (!difffile)
1937 bail("could not open file \"%s\" for writing: %m", difffilename);
1938
1939 /* we don't keep the diffs file open continuously */
1940 fclose(difffile);
1941
1942 /* also create the results directory if not present */
1943 snprintf(file, sizeof(file), "%s/results", outputdir);
1944 if (!directory_exists(file))
1945 make_directory(file);
1946}
static bool directory_exists(const char *dir)
Definition: pg_regress.c:1318
static char * logfilename
Definition: pg_regress.c:125
static void make_directory(const char *dir)
Definition: pg_regress.c:1331
static char * difffilename
Definition: pg_regress.c:127

References bail, difffilename, directory_exists(), logfile, logfilename, make_directory(), MAXPGPATH, outputdir, pg_strdup(), and snprintf.

Referenced by regression_main().

◆ psql_add_command()

static void psql_add_command ( StringInfo  buf,
const char *  query,
  ... 
)
static

Definition at line 1132 of file pg_regress.c.

1133{
1134 StringInfoData cmdbuf;
1135 const char *cmdptr;
1136
1137 /* Add each command as a -c argument in the psql call */
1138 appendStringInfoString(buf, " -c \"");
1139
1140 /* Generate the query with insertion of sprintf arguments */
1141 initStringInfo(&cmdbuf);
1142 for (;;)
1143 {
1144 va_list args;
1145 int needed;
1146
1147 va_start(args, query);
1148 needed = appendStringInfoVA(&cmdbuf, query, args);
1149 va_end(args);
1150 if (needed == 0)
1151 break; /* success */
1152 enlargeStringInfo(&cmdbuf, needed);
1153 }
1154
1155 /* Now escape any shell double-quote metacharacters */
1156 for (cmdptr = cmdbuf.data; *cmdptr; cmdptr++)
1157 {
1158 if (strchr("\\\"$`", *cmdptr))
1160 appendStringInfoChar(buf, *cmdptr);
1161 }
1162
1164
1165 pfree(cmdbuf.data);
1166}
void pfree(void *pointer)
Definition: mcxt.c:1521
int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
Definition: stringinfo.c:187
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:337
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97

References appendStringInfoChar(), appendStringInfoString(), appendStringInfoVA(), generate_unaccent_rules::args, buf, StringInfoData::data, enlargeStringInfo(), initStringInfo(), pfree(), va_end(), and va_start().

Referenced by create_database(), create_role(), drop_database_if_exists(), and drop_role_if_exists().

◆ psql_end_command()

static void psql_end_command ( StringInfo  buf,
const char *  database 
)
static

Definition at line 1169 of file pg_regress.c.

1170{
1171 /* Add the database name --- assume it needs no extra escaping */
1173 " \"%s\"",
1174 database);
1175
1176 /* And now we can execute the shell command */
1177 fflush(NULL);
1178 if (system(buf->data) != 0)
1179 {
1180 /* psql probably already reported the error */
1181 bail("command failed: %s", buf->data);
1182 }
1183
1184 /* Clean up */
1186}
void destroyStringInfo(StringInfo str)
Definition: stringinfo.c:409
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145

References appendStringInfo(), bail, buf, destroyStringInfo(), and fflush().

Referenced by create_database(), create_role(), drop_database_if_exists(), and drop_role_if_exists().

◆ psql_start_command()

static StringInfo psql_start_command ( void  )
static

Definition at line 1120 of file pg_regress.c.

1121{
1123
1125 "\"%s%spsql\" -X -q",
1126 bindir ? bindir : "",
1127 bindir ? "/" : "");
1128 return buf;
1129}
char * bindir
Definition: pg_regress.c:102
StringInfo makeStringInfo(void)
Definition: stringinfo.c:72

References appendStringInfo(), bindir, buf, and makeStringInfo().

Referenced by create_database(), create_role(), drop_database_if_exists(), and drop_role_if_exists().

◆ regression_main()

int regression_main ( int  argc,
char *  argv[],
init_function  ifunc,
test_start_function  startfunc,
postprocess_result_function  postfunc 
)

Definition at line 2069 of file pg_regress.c.

2073{
2074 static struct option long_options[] = {
2075 {"help", no_argument, NULL, 'h'},
2076 {"version", no_argument, NULL, 'V'},
2077 {"dbname", required_argument, NULL, 1},
2078 {"debug", no_argument, NULL, 2},
2079 {"inputdir", required_argument, NULL, 3},
2080 {"max-connections", required_argument, NULL, 5},
2081 {"encoding", required_argument, NULL, 6},
2082 {"outputdir", required_argument, NULL, 7},
2083 {"schedule", required_argument, NULL, 8},
2084 {"temp-instance", required_argument, NULL, 9},
2085 {"no-locale", no_argument, NULL, 10},
2086 {"host", required_argument, NULL, 13},
2087 {"port", required_argument, NULL, 14},
2088 {"user", required_argument, NULL, 15},
2089 {"bindir", required_argument, NULL, 16},
2090 {"dlpath", required_argument, NULL, 17},
2091 {"create-role", required_argument, NULL, 18},
2092 {"temp-config", required_argument, NULL, 19},
2093 {"use-existing", no_argument, NULL, 20},
2094 {"launcher", required_argument, NULL, 21},
2095 {"load-extension", required_argument, NULL, 22},
2096 {"config-auth", required_argument, NULL, 24},
2097 {"max-concurrent-tests", required_argument, NULL, 25},
2098 {"expecteddir", required_argument, NULL, 26},
2099 {NULL, 0, NULL, 0}
2100 };
2101
2102 bool use_unix_sockets;
2103 _stringlist *sl;
2104 int c;
2105 int i;
2106 int option_index;
2107 char buf[MAXPGPATH * 4];
2108
2109 pg_logging_init(argv[0]);
2110 progname = get_progname(argv[0]);
2111 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_regress"));
2112
2114
2115 atexit(stop_postmaster);
2116
2117#if defined(WIN32)
2118
2119 /*
2120 * We don't use Unix-domain sockets on Windows by default (see comment at
2121 * remove_temp() for a reason). Override at your own risk.
2122 */
2123 use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false;
2124#else
2125 use_unix_sockets = true;
2126#endif
2127
2128 if (!use_unix_sockets)
2129 hostname = "localhost";
2130
2131 /*
2132 * We call the initialization function here because that way we can set
2133 * default parameters and let them be overwritten by the commandline.
2134 */
2135 ifunc(argc, argv);
2136
2137 if (getenv("PG_REGRESS_DIFF_OPTS"))
2138 pretty_diff_opts = getenv("PG_REGRESS_DIFF_OPTS");
2139
2140 while ((c = getopt_long(argc, argv, "hV", long_options, &option_index)) != -1)
2141 {
2142 switch (c)
2143 {
2144 case 'h':
2145 help();
2146 exit(0);
2147 case 'V':
2148 puts("pg_regress (PostgreSQL) " PG_VERSION);
2149 exit(0);
2150 case 1:
2151
2152 /*
2153 * If a default database was specified, we need to remove it
2154 * before we add the specified one.
2155 */
2158 break;
2159 case 2:
2160 debug = true;
2161 break;
2162 case 3:
2164 break;
2165 case 5:
2166 max_connections = atoi(optarg);
2167 break;
2168 case 6:
2170 break;
2171 case 7:
2173 break;
2174 case 8:
2176 break;
2177 case 9:
2179 break;
2180 case 10:
2181 nolocale = true;
2182 break;
2183 case 13:
2185 break;
2186 case 14:
2187 port = atoi(optarg);
2189 break;
2190 case 15:
2192 break;
2193 case 16:
2194 /* "--bindir=" means to use PATH */
2195 if (strlen(optarg))
2197 else
2198 bindir = NULL;
2199 break;
2200 case 17:
2202 break;
2203 case 18:
2205 break;
2206 case 19:
2208 break;
2209 case 20:
2210 use_existing = true;
2211 break;
2212 case 21:
2214 break;
2215 case 22:
2217 break;
2218 case 24:
2220 break;
2221 case 25:
2223 break;
2224 case 26:
2226 break;
2227 default:
2228 /* getopt_long already emitted a complaint */
2229 pg_log_error_hint("Try \"%s --help\" for more information.",
2230 progname);
2231 exit(2);
2232 }
2233 }
2234
2235 /*
2236 * if we still have arguments, they are extra tests to run
2237 */
2238 while (argc - optind >= 1)
2239 {
2241 optind++;
2242 }
2243
2244 /*
2245 * We must have a database to run the tests in; either a default name, or
2246 * one supplied by the --dbname switch.
2247 */
2248 if (!(dblist && dblist->str && dblist->str[0]))
2249 {
2250 bail("no database name was specified");
2251 }
2252
2254 {
2255#ifdef ENABLE_SSPI
2256 if (!use_unix_sockets)
2257 config_sspi_auth(config_auth_datadir, user);
2258#endif
2259 exit(0);
2260 }
2261
2263
2264 /*
2265 * To reduce chances of interference with parallel installations, use
2266 * a port number starting in the private range (49152-65535)
2267 * calculated from the version number. This aids non-Unix socket mode
2268 * systems; elsewhere, the use of a private socket directory already
2269 * prevents interference.
2270 */
2271 port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2272
2277
2278 /*
2279 * Initialization
2280 */
2282
2284
2285#if defined(HAVE_GETRLIMIT)
2287#endif
2288
2289 if (temp_instance)
2290 {
2291 StringInfoData cmd;
2292 FILE *pg_conf;
2293 const char *env_wait;
2294 int wait_seconds;
2295 const char *initdb_template_dir;
2296 const char *keywords[4];
2297 const char *values[4];
2298 PGPing rv;
2299 const char *initdb_extra_opts_env;
2300
2301 /*
2302 * Prepare the temp instance
2303 */
2304
2306 {
2307 if (!rmtree(temp_instance, true))
2308 {
2309 bail("could not remove temp instance \"%s\"", temp_instance);
2310 }
2311 }
2312
2313 /* make the temp instance top directory */
2315
2316 /* and a directory for log files */
2317 snprintf(buf, sizeof(buf), "%s/log", outputdir);
2318 if (!directory_exists(buf))
2320
2321 initdb_extra_opts_env = getenv("PG_TEST_INITDB_EXTRA_OPTS");
2322
2323 initStringInfo(&cmd);
2324
2325 /*
2326 * Create data directory.
2327 *
2328 * If available, use a previously initdb'd cluster as a template by
2329 * copying it. For a lot of tests, that's substantially cheaper.
2330 *
2331 * There's very similar code in Cluster.pm, but we can't easily de
2332 * duplicate it until we require perl at build time.
2333 */
2334 initdb_template_dir = getenv("INITDB_TEMPLATE");
2335 if (initdb_template_dir == NULL || nolocale || debug || initdb_extra_opts_env)
2336 {
2337 note("initializing database system by running initdb");
2338
2339 appendStringInfo(&cmd,
2340 "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync",
2341 bindir ? bindir : "",
2342 bindir ? "/" : "",
2344 if (debug)
2345 appendStringInfoString(&cmd, " --debug");
2346 if (nolocale)
2347 appendStringInfoString(&cmd, " --no-locale");
2348 if (initdb_extra_opts_env)
2349 appendStringInfo(&cmd, " %s", initdb_extra_opts_env);
2350 appendStringInfo(&cmd, " > \"%s/log/initdb.log\" 2>&1", outputdir);
2351 fflush(NULL);
2352 if (system(cmd.data))
2353 {
2354 bail("initdb failed\n"
2355 "# Examine \"%s/log/initdb.log\" for the reason.\n"
2356 "# Command was: %s",
2357 outputdir, cmd.data);
2358 }
2359 }
2360 else
2361 {
2362#ifndef WIN32
2363 const char *copycmd = "cp -RPp \"%s\" \"%s/data\"";
2364 int expected_exitcode = 0;
2365#else
2366 const char *copycmd = "robocopy /E /NJS /NJH /NFL /NDL /NP \"%s\" \"%s/data\"";
2367 int expected_exitcode = 1; /* 1 denotes files were copied */
2368#endif
2369
2370 note("initializing database system by copying initdb template");
2371
2372 appendStringInfo(&cmd,
2373 copycmd,
2374 initdb_template_dir,
2376 appendStringInfo(&cmd, " > \"%s/log/initdb.log\" 2>&1", outputdir);
2377 fflush(NULL);
2378 if (system(cmd.data) != expected_exitcode)
2379 {
2380 bail("copying of initdb template failed\n"
2381 "# Examine \"%s/log/initdb.log\" for the reason.\n"
2382 "# Command was: %s",
2383 outputdir, cmd.data);
2384 }
2385 }
2386
2387 pfree(cmd.data);
2388
2389 /*
2390 * Adjust the default postgresql.conf for regression testing. The user
2391 * can specify a file to be appended; in any case we expand logging
2392 * and set max_prepared_transactions to enable testing of prepared
2393 * xacts. (Note: to reduce the probability of unexpected shmmax
2394 * failures, don't set max_prepared_transactions any higher than
2395 * actually needed by the prepared_xacts regression test.)
2396 */
2397 snprintf(buf, sizeof(buf), "%s/data/postgresql.conf", temp_instance);
2398 pg_conf = fopen(buf, "a");
2399 if (pg_conf == NULL)
2400 bail("could not open \"%s\" for adding extra config: %m", buf);
2401
2402 fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
2403 fputs("log_autovacuum_min_duration = 0\n", pg_conf);
2404 fputs("log_checkpoints = on\n", pg_conf);
2405 fputs("log_line_prefix = '%m %b[%p] %q%a '\n", pg_conf);
2406 fputs("log_lock_waits = on\n", pg_conf);
2407 fputs("log_temp_files = 128kB\n", pg_conf);
2408 fputs("max_prepared_transactions = 2\n", pg_conf);
2409
2410 for (sl = temp_configs; sl != NULL; sl = sl->next)
2411 {
2412 char *temp_config = sl->str;
2413 FILE *extra_conf;
2414 char line_buf[1024];
2415
2416 extra_conf = fopen(temp_config, "r");
2417 if (extra_conf == NULL)
2418 {
2419 bail("could not open \"%s\" to read extra config: %m",
2420 temp_config);
2421 }
2422 while (fgets(line_buf, sizeof(line_buf), extra_conf) != NULL)
2423 fputs(line_buf, pg_conf);
2424 fclose(extra_conf);
2425 }
2426
2427 fclose(pg_conf);
2428
2429#ifdef ENABLE_SSPI
2430 if (!use_unix_sockets)
2431 {
2432 /*
2433 * Since we successfully used the same buffer for the much-longer
2434 * "initdb" command, this can't truncate.
2435 */
2436 snprintf(buf, sizeof(buf), "%s/data", temp_instance);
2437 config_sspi_auth(buf, NULL);
2438 }
2439#endif
2440
2441 /*
2442 * Prepare the connection params for checking the state of the server
2443 * before starting the tests.
2444 */
2445 sprintf(portstr, "%d", port);
2446 keywords[0] = "dbname";
2447 values[0] = "postgres";
2448 keywords[1] = "port";
2449 values[1] = portstr;
2450 keywords[2] = "host";
2452 keywords[3] = NULL;
2453 values[3] = NULL;
2454
2455 /*
2456 * Check if there is a postmaster running already.
2457 */
2458 for (i = 0; i < 16; i++)
2459 {
2460 rv = PQpingParams(keywords, values, 1);
2461
2462 if (rv == PQPING_OK)
2463 {
2464 if (port_specified_by_user || i == 15)
2465 {
2466 note("port %d apparently in use", port);
2468 note("could not determine an available port");
2469 bail("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.");
2470 }
2471
2472 note("port %d apparently in use, trying %d", port, port + 1);
2473 port++;
2474 sprintf(portstr, "%d", port);
2475 setenv("PGPORT", portstr, 1);
2476 }
2477 else
2478 break;
2479 }
2480
2481 /*
2482 * Start the temp postmaster
2483 */
2484 snprintf(buf, sizeof(buf),
2485 "\"%s%spostgres\" -D \"%s/data\" -F%s "
2486 "-c \"listen_addresses=%s\" -k \"%s\" "
2487 "> \"%s/log/postmaster.log\" 2>&1",
2488 bindir ? bindir : "",
2489 bindir ? "/" : "",
2490 temp_instance, debug ? " -d 5" : "",
2491 hostname ? hostname : "", sockdir ? sockdir : "",
2492 outputdir);
2495 bail("could not spawn postmaster: %m");
2496
2497 /*
2498 * Wait till postmaster is able to accept connections; normally takes
2499 * only a fraction of a second or so, but Cygwin is reportedly *much*
2500 * slower, and test builds using Valgrind or similar tools might be
2501 * too. Hence, allow the default timeout of 60 seconds to be
2502 * overridden from the PGCTLTIMEOUT environment variable.
2503 */
2504 env_wait = getenv("PGCTLTIMEOUT");
2505 if (env_wait != NULL)
2506 {
2507 wait_seconds = atoi(env_wait);
2508 if (wait_seconds <= 0)
2509 wait_seconds = 60;
2510 }
2511 else
2512 wait_seconds = 60;
2513
2514 for (i = 0; i < wait_seconds * WAIT_TICKS_PER_SECOND; i++)
2515 {
2516 /*
2517 * It's fairly unlikely that the server is responding immediately
2518 * so we start with sleeping before checking instead of the other
2519 * way around.
2520 */
2521 pg_usleep(1000000L / WAIT_TICKS_PER_SECOND);
2522
2523 rv = PQpingParams(keywords, values, 1);
2524
2525 /* Done if the server is running and accepts connections */
2526 if (rv == PQPING_OK)
2527 break;
2528
2529 if (rv == PQPING_NO_ATTEMPT)
2530 bail("attempting to connect to postmaster failed");
2531
2532 /*
2533 * Fail immediately if postmaster has exited
2534 */
2535#ifndef WIN32
2536 if (waitpid(postmaster_pid, NULL, WNOHANG) == postmaster_pid)
2537#else
2538 if (WaitForSingleObject(postmaster_pid, 0) == WAIT_OBJECT_0)
2539#endif
2540 {
2541 bail("postmaster failed, examine \"%s/log/postmaster.log\" for the reason",
2542 outputdir);
2543 }
2544 }
2546 {
2547 diag("postmaster did not respond within %d seconds, examine \"%s/log/postmaster.log\" for the reason",
2549
2550 /*
2551 * If we get here, the postmaster is probably wedged somewhere in
2552 * startup. Try to kill it ungracefully rather than leaving a
2553 * stuck postmaster that might interfere with subsequent test
2554 * attempts.
2555 */
2556#ifndef WIN32
2557 if (kill(postmaster_pid, SIGKILL) != 0 && errno != ESRCH)
2558 bail("could not kill failed postmaster: %m");
2559#else
2560 if (TerminateProcess(postmaster_pid, 255) == 0)
2561 bail("could not kill failed postmaster: error code %lu",
2562 GetLastError());
2563#endif
2564 bail("postmaster failed");
2565 }
2566
2567 postmaster_running = true;
2568
2569#ifdef _WIN64
2570/* need a series of two casts to convert HANDLE without compiler warning */
2571#define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2572#else
2573#define ULONGPID(x) (unsigned long) (x)
2574#endif
2575 note("using temp instance on port %d with PID %lu",
2577 }
2578 else
2579 {
2580 /*
2581 * Using an existing installation, so may need to get rid of
2582 * pre-existing database(s) and role(s)
2583 */
2584 if (!use_existing)
2585 {
2586 for (sl = dblist; sl; sl = sl->next)
2588 for (sl = extraroles; sl; sl = sl->next)
2590 }
2591 }
2592
2593 /*
2594 * Create the test database(s) and role(s)
2595 */
2596 if (!use_existing)
2597 {
2598 for (sl = dblist; sl; sl = sl->next)
2599 create_database(sl->str);
2600 for (sl = extraroles; sl; sl = sl->next)
2601 create_role(sl->str, dblist);
2602 }
2603
2604 /*
2605 * Ready to run the tests
2606 */
2607 for (sl = schedulelist; sl != NULL; sl = sl->next)
2608 {
2609 run_schedule(sl->str, startfunc, postfunc);
2610 }
2611
2612 for (sl = extra_tests; sl != NULL; sl = sl->next)
2613 {
2614 run_single_test(sl->str, startfunc, postfunc);
2615 }
2616
2617 /*
2618 * Shut down temp installation's postmaster
2619 */
2620 if (temp_instance)
2621 {
2623 }
2624
2625 /*
2626 * If there were no errors, remove the temp instance immediately to
2627 * conserve disk space. (If there were errors, we leave the instance in
2628 * place for possible manual investigation.)
2629 */
2630 if (temp_instance && fail_count == 0)
2631 {
2632 if (!rmtree(temp_instance, true))
2633 diag("could not remove temp instance \"%s\"",
2635 }
2636
2637 /*
2638 * Emit a TAP compliant Plan
2639 */
2641
2642 /*
2643 * Emit nice-looking summary message
2644 */
2645 if (fail_count == 0)
2646 note("All %d tests passed.", success_count);
2647 else
2648 diag("%d of %d tests failed.", fail_count, success_count + fail_count);
2649
2650 if (file_size(difffilename) > 0)
2651 {
2652 diag("The differences that caused some tests to fail can be viewed in the file \"%s\".",
2653 difffilename);
2654 diag("A copy of the test summary that you see above is saved in the file \"%s\".",
2655 logfilename);
2656 }
2657 else
2658 {
2659 unlink(difffilename);
2660 unlink(logfilename);
2661 }
2662
2663 fclose(logfile);
2664 logfile = NULL;
2665
2666 if (fail_count != 0)
2667 exit(1);
2668
2669 return 0;
2670}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1171
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:429
PGPing PQpingParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:716
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:60
#define no_argument
Definition: getopt_long.h:25
#define required_argument
Definition: getopt_long.h:26
return true
Definition: isn.c:125
static const JsonPathKeyword keywords[]
PGPing
Definition: libpq-fe.h:170
@ PQPING_OK
Definition: libpq-fe.h:171
@ PQPING_NO_ATTEMPT
Definition: libpq-fe.h:174
void pg_logging_init(const char *argv0)
Definition: logging.c:83
#define pg_log_error_hint(...)
Definition: logging.h:112
static int wait_seconds
Definition: pg_ctl.c:76
PGDLLIMPORT int optind
Definition: getopt.c:51
PGDLLIMPORT char * optarg
Definition: getopt.c:53
#define plan(x)
Definition: pg_regress.c:161
static bool use_existing
Definition: pg_regress.c:113
static void open_result_files(void)
Definition: pg_regress.c:1916
static int max_connections
Definition: pg_regress.c:105
static bool port_specified_by_user
Definition: pg_regress.c:117
static void stop_postmaster(void)
Definition: pg_regress.c:433
static int max_concurrent_tests
Definition: pg_regress.c:106
static void create_database(const char *dbname)
Definition: pg_regress.c:1960
static void drop_role_if_exists(const char *rolename)
Definition: pg_regress.c:1994
bool debug
Definition: pg_regress.c:98
static void unlimit_core_size(void)
Definition: pg_regress.c:174
static _stringlist * schedulelist
Definition: pg_regress.c:108
#define WAIT_TICKS_PER_SECOND
Definition: pg_regress.c:82
static _stringlist * temp_configs
Definition: pg_regress.c:111
static _stringlist * extra_tests
Definition: pg_regress.c:109
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
Definition: pg_regress.c:233
static void run_single_test(const char *test, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:1849
char * launcher
Definition: pg_regress.c:103
const char * pretty_diff_opts
Definition: pg_regress.c:65
char * expecteddir
Definition: pg_regress.c:101
static char * config_auth_datadir
Definition: pg_regress.c:121
static void drop_database_if_exists(const char *dbname)
Definition: pg_regress.c:1949
static char portstr[16]
Definition: pg_regress.c:116
static void initialize_environment(void)
Definition: pg_regress.c:723
static void help(void)
Definition: pg_regress.c:2019
static long file_size(const char *file)
Definition: pg_regress.c:1266
static bool postmaster_running
Definition: pg_regress.c:138
_stringlist * dblist
Definition: pg_regress.c:97
static _stringlist * extraroles
Definition: pg_regress.c:120
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1204
static void create_role(const char *rolename, const _stringlist *granted_dbs)
Definition: pg_regress.c:2005
static void run_schedule(const char *schedule, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:1643
void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:197
static int success_count
Definition: pg_regress.c:140
#define ULONGPID(x)
static int fail_count
Definition: pg_regress.c:141
static PID_TYPE postmaster_pid
Definition: pg_regress.c:137
#define INVALID_PID
Definition: pg_regress.h:15
#define sprintf
Definition: port.h:240
char * make_absolute_path(const char *path)
Definition: path.c:730
const char * get_progname(const char *argv0)
Definition: path.c:575
void get_restricted_token(void)
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:50
void pg_usleep(long microsec)
Definition: signal.c:53
#define kill(pid, sig)
Definition: win32_port.h:493
#define SIGKILL
Definition: win32_port.h:162

References add_stringlist_item(), appendStringInfo(), appendStringInfoString(), bail, bindir, buf, config_auth_datadir, create_database(), create_role(), StringInfoData::data, dblist, debug, diag, difffilename, directory_exists(), dlpath, drop_database_if_exists(), drop_role_if_exists(), encoding, exit(), expecteddir, extra_tests, extraroles, fail_count, fflush(), file_size(), free_stringlist(), get_progname(), get_restricted_token(), getopt_long(), help(), hostname, i, initialize_environment(), initStringInfo(), inputdir, INVALID_PID, keywords, kill, launcher, loadextension, logfile, logfilename, make_absolute_path(), make_directory(), max_concurrent_tests, max_connections, MAXPGPATH, _stringlist::next, no_argument, nolocale, note, open_result_files(), optarg, optind, outputdir, pfree(), pg_log_error_hint, pg_logging_init(), pg_strdup(), PG_TEXTDOMAIN, pg_usleep(), plan, port, port_specified_by_user, portstr, postmaster_pid, postmaster_running, PQPING_NO_ATTEMPT, PQPING_OK, PQpingParams(), pretty_diff_opts, progname, required_argument, rmtree(), run_schedule(), run_single_test(), schedulelist, set_pglocale_pgservice(), setenv, SIGKILL, snprintf, sockdir, spawn_process(), split_to_stringlist(), sprintf, stop_postmaster(), _stringlist::str, success_count, temp_configs, temp_instance, true, ULONGPID, unlimit_core_size(), use_existing, user, values, wait_seconds, and WAIT_TICKS_PER_SECOND.

Referenced by main().

◆ remove_temp()

static void remove_temp ( void  )
static

Definition at line 468 of file pg_regress.c.

469{
471 unlink(sockself);
472 unlink(socklock);
473 rmdir(temp_sockdir);
474}
#define Assert(condition)
Definition: c.h:815

References Assert, socklock, sockself, and temp_sockdir.

Referenced by make_temp_sockdir(), and signal_remove_temp().

◆ results_differ()

static bool results_differ ( const char *  testname,
const char *  resultsfile,
const char *  default_expectfile 
)
static

Definition at line 1407 of file pg_regress.c.

1408{
1409 char expectfile[MAXPGPATH];
1410 char diff[MAXPGPATH];
1411 char cmd[MAXPGPATH * 3];
1412 char best_expect_file[MAXPGPATH];
1413 FILE *difffile;
1414 int best_line_count;
1415 int i;
1416 int l;
1417 const char *platform_expectfile;
1418
1419 /*
1420 * We can pass either the resultsfile or the expectfile, they should have
1421 * the same type (filename.type) anyway.
1422 */
1423 platform_expectfile = get_expectfile(testname, resultsfile);
1424
1425 strlcpy(expectfile, default_expectfile, sizeof(expectfile));
1426 if (platform_expectfile)
1427 {
1428 /*
1429 * Replace everything after the last slash in expectfile with what the
1430 * platform_expectfile contains.
1431 */
1432 char *p = strrchr(expectfile, '/');
1433
1434 if (p)
1435 strcpy(++p, platform_expectfile);
1436 }
1437
1438 /* Name to use for temporary diff file */
1439 snprintf(diff, sizeof(diff), "%s.diff", resultsfile);
1440
1441 /* OK, run the diff */
1442 snprintf(cmd, sizeof(cmd),
1443 "diff %s \"%s\" \"%s\" > \"%s\"",
1444 basic_diff_opts, expectfile, resultsfile, diff);
1445
1446 /* Is the diff file empty? */
1447 if (run_diff(cmd, diff) == 0)
1448 {
1449 unlink(diff);
1450 return false;
1451 }
1452
1453 /* There may be secondary comparison files that match better */
1454 best_line_count = file_line_count(diff);
1455 strcpy(best_expect_file, expectfile);
1456
1457 for (i = 0; i <= 9; i++)
1458 {
1459 char *alt_expectfile;
1460
1461 alt_expectfile = get_alternative_expectfile(expectfile, i);
1462 if (!alt_expectfile)
1463 bail("Unable to check secondary comparison files: %m");
1464
1465 if (!file_exists(alt_expectfile))
1466 {
1467 free(alt_expectfile);
1468 continue;
1469 }
1470
1471 snprintf(cmd, sizeof(cmd),
1472 "diff %s \"%s\" \"%s\" > \"%s\"",
1473 basic_diff_opts, alt_expectfile, resultsfile, diff);
1474
1475 if (run_diff(cmd, diff) == 0)
1476 {
1477 unlink(diff);
1478 free(alt_expectfile);
1479 return false;
1480 }
1481
1482 l = file_line_count(diff);
1483 if (l < best_line_count)
1484 {
1485 /* This diff was a better match than the last one */
1486 best_line_count = l;
1487 strlcpy(best_expect_file, alt_expectfile, sizeof(best_expect_file));
1488 }
1489 free(alt_expectfile);
1490 }
1491
1492 /*
1493 * fall back on the canonical results file if we haven't tried it yet and
1494 * haven't found a complete match yet.
1495 */
1496
1497 if (platform_expectfile)
1498 {
1499 snprintf(cmd, sizeof(cmd),
1500 "diff %s \"%s\" \"%s\" > \"%s\"",
1501 basic_diff_opts, default_expectfile, resultsfile, diff);
1502
1503 if (run_diff(cmd, diff) == 0)
1504 {
1505 /* No diff = no changes = good */
1506 unlink(diff);
1507 return false;
1508 }
1509
1510 l = file_line_count(diff);
1511 if (l < best_line_count)
1512 {
1513 /* This diff was a better match than the last one */
1514 best_line_count = l;
1515 strlcpy(best_expect_file, default_expectfile, sizeof(best_expect_file));
1516 }
1517 }
1518
1519 /*
1520 * Use the best comparison file to generate the "pretty" diff, which we
1521 * append to the diffs summary file.
1522 */
1523
1524 /* Write diff header */
1525 difffile = fopen(difffilename, "a");
1526 if (difffile)
1527 {
1528 fprintf(difffile,
1529 "diff %s %s %s\n",
1530 pretty_diff_opts, best_expect_file, resultsfile);
1531 fclose(difffile);
1532 }
1533
1534 /* Run diff */
1535 snprintf(cmd, sizeof(cmd),
1536 "diff %s \"%s\" \"%s\" >> \"%s\"",
1537 pretty_diff_opts, best_expect_file, resultsfile, difffilename);
1538 run_diff(cmd, difffilename);
1539
1540 unlink(diff);
1541 return true;
1542}
static int file_line_count(const char *file)
Definition: pg_regress.c:1286
static char * get_alternative_expectfile(const char *expectfile, int i)
Definition: pg_regress.c:1341
bool file_exists(const char *file)
Definition: pg_regress.c:1307
static const char * get_expectfile(const char *testname, const char *file)
Definition: pg_regress.c:694
static int run_diff(const char *cmd, const char *filename)
Definition: pg_regress.c:1375
const char * basic_diff_opts
Definition: pg_regress.c:64
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

References bail, basic_diff_opts, difffilename, file_exists(), file_line_count(), fprintf, free, get_alternative_expectfile(), get_expectfile(), i, MAXPGPATH, pretty_diff_opts, run_diff(), snprintf, and strlcpy().

Referenced by run_schedule(), and run_single_test().

◆ run_diff()

static int run_diff ( const char *  cmd,
const char *  filename 
)
static

Definition at line 1375 of file pg_regress.c.

1376{
1377 int r;
1378
1379 fflush(NULL);
1380 r = system(cmd);
1381 if (!WIFEXITED(r) || WEXITSTATUS(r) > 1)
1382 {
1383 bail("diff command failed with status %d: %s", r, cmd);
1384 }
1385#ifdef WIN32
1386
1387 /*
1388 * On WIN32, if the 'diff' command cannot be found, system() returns 1,
1389 * but produces nothing to stdout, so we check for that here.
1390 */
1391 if (WEXITSTATUS(r) == 1 && file_size(filename) <= 0)
1392 {
1393 bail("diff command not found: %s", cmd);
1394 }
1395#endif
1396
1397 return WEXITSTATUS(r);
1398}
static char * filename
Definition: pg_dumpall.c:119

References bail, fflush(), file_size(), filename, WEXITSTATUS, and WIFEXITED.

Referenced by results_differ().

◆ run_schedule()

static void run_schedule ( const char *  schedule,
test_start_function  startfunc,
postprocess_result_function  postfunc 
)
static

Definition at line 1643 of file pg_regress.c.

1645{
1646#define MAX_PARALLEL_TESTS 100
1647 char *tests[MAX_PARALLEL_TESTS];
1648 _stringlist *resultfiles[MAX_PARALLEL_TESTS];
1649 _stringlist *expectfiles[MAX_PARALLEL_TESTS];
1652 instr_time starttimes[MAX_PARALLEL_TESTS];
1653 instr_time stoptimes[MAX_PARALLEL_TESTS];
1654 int statuses[MAX_PARALLEL_TESTS];
1655 char scbuf[1024];
1656 FILE *scf;
1657 int line_num = 0;
1658
1659 memset(tests, 0, sizeof(tests));
1660 memset(resultfiles, 0, sizeof(resultfiles));
1661 memset(expectfiles, 0, sizeof(expectfiles));
1662 memset(tags, 0, sizeof(tags));
1663
1664 scf = fopen(schedule, "r");
1665 if (!scf)
1666 bail("could not open file \"%s\" for reading: %m", schedule);
1667
1668 while (fgets(scbuf, sizeof(scbuf), scf))
1669 {
1670 char *test = NULL;
1671 char *c;
1672 int num_tests;
1673 bool inword;
1674 int i;
1675
1676 line_num++;
1677
1678 /* strip trailing whitespace, especially the newline */
1679 i = strlen(scbuf);
1680 while (i > 0 && isspace((unsigned char) scbuf[i - 1]))
1681 scbuf[--i] = '\0';
1682
1683 if (scbuf[0] == '\0' || scbuf[0] == '#')
1684 continue;
1685 if (strncmp(scbuf, "test: ", 6) == 0)
1686 test = scbuf + 6;
1687 else
1688 {
1689 bail("syntax error in schedule file \"%s\" line %d: %s",
1690 schedule, line_num, scbuf);
1691 }
1692
1693 num_tests = 0;
1694 inword = false;
1695 for (c = test;; c++)
1696 {
1697 if (*c == '\0' || isspace((unsigned char) *c))
1698 {
1699 if (inword)
1700 {
1701 /* Reached end of a test name */
1702 char sav;
1703
1704 if (num_tests >= MAX_PARALLEL_TESTS)
1705 {
1706 bail("too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s",
1707 MAX_PARALLEL_TESTS, schedule, line_num, scbuf);
1708 }
1709 sav = *c;
1710 *c = '\0';
1711 tests[num_tests] = pg_strdup(test);
1712 num_tests++;
1713 *c = sav;
1714 inword = false;
1715 }
1716 if (*c == '\0')
1717 break; /* loop exit is here */
1718 }
1719 else if (!inword)
1720 {
1721 /* Start of a test name */
1722 test = c;
1723 inword = true;
1724 }
1725 }
1726
1727 if (num_tests == 0)
1728 {
1729 bail("syntax error in schedule file \"%s\" line %d: %s",
1730 schedule, line_num, scbuf);
1731 }
1732
1733 if (num_tests == 1)
1734 {
1735 pids[0] = (startfunc) (tests[0], &resultfiles[0], &expectfiles[0], &tags[0]);
1736 INSTR_TIME_SET_CURRENT(starttimes[0]);
1737 wait_for_tests(pids, statuses, stoptimes, NULL, 1);
1738 /* status line is finished below */
1739 }
1740 else if (max_concurrent_tests > 0 && max_concurrent_tests < num_tests)
1741 {
1742 bail("too many parallel tests (more than %d) in schedule file \"%s\" line %d: %s",
1743 max_concurrent_tests, schedule, line_num, scbuf);
1744 }
1745 else if (max_connections > 0 && max_connections < num_tests)
1746 {
1747 int oldest = 0;
1748
1749 note_detail("parallel group (%d tests, in groups of %d): ",
1750 num_tests, max_connections);
1751 for (i = 0; i < num_tests; i++)
1752 {
1753 if (i - oldest >= max_connections)
1754 {
1755 wait_for_tests(pids + oldest, statuses + oldest,
1756 stoptimes + oldest,
1757 tests + oldest, i - oldest);
1758 oldest = i;
1759 }
1760 pids[i] = (startfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1761 INSTR_TIME_SET_CURRENT(starttimes[i]);
1762 }
1763 wait_for_tests(pids + oldest, statuses + oldest,
1764 stoptimes + oldest,
1765 tests + oldest, i - oldest);
1766 note_end();
1767 }
1768 else
1769 {
1770 note_detail("parallel group (%d tests): ", num_tests);
1771 for (i = 0; i < num_tests; i++)
1772 {
1773 pids[i] = (startfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1774 INSTR_TIME_SET_CURRENT(starttimes[i]);
1775 }
1776 wait_for_tests(pids, statuses, stoptimes, tests, num_tests);
1777 note_end();
1778 }
1779
1780 /* Check results for all tests */
1781 for (i = 0; i < num_tests; i++)
1782 {
1783 _stringlist *rl,
1784 *el,
1785 *tl;
1786 bool differ = false;
1787
1788 INSTR_TIME_SUBTRACT(stoptimes[i], starttimes[i]);
1789
1790 /*
1791 * Advance over all three lists simultaneously.
1792 *
1793 * Compare resultfiles[j] with expectfiles[j] always. Tags are
1794 * optional but if there are tags, the tag list has the same
1795 * length as the other two lists.
1796 */
1797 for (rl = resultfiles[i], el = expectfiles[i], tl = tags[i];
1798 rl != NULL; /* rl and el have the same length */
1799 rl = rl->next, el = el->next,
1800 tl = tl ? tl->next : NULL)
1801 {
1802 bool newdiff;
1803
1804 if (postfunc)
1805 (*postfunc) (rl->str);
1806 newdiff = results_differ(tests[i], rl->str, el->str);
1807 if (newdiff && tl)
1808 {
1809 diag("tag: %s", tl->str);
1810 }
1811 differ |= newdiff;
1812 }
1813
1814 if (statuses[i] != 0)
1815 {
1816 test_status_failed(tests[i], INSTR_TIME_GET_MILLISEC(stoptimes[i]), (num_tests > 1));
1817 log_child_failure(statuses[i]);
1818 }
1819 else
1820 {
1821 if (differ)
1822 {
1823 test_status_failed(tests[i], INSTR_TIME_GET_MILLISEC(stoptimes[i]), (num_tests > 1));
1824 }
1825 else
1826 {
1827 test_status_ok(tests[i], INSTR_TIME_GET_MILLISEC(stoptimes[i]), (num_tests > 1));
1828 }
1829 }
1830 }
1831
1832 for (i = 0; i < num_tests; i++)
1833 {
1834 pg_free(tests[i]);
1835 tests[i] = NULL;
1836 free_stringlist(&resultfiles[i]);
1837 free_stringlist(&expectfiles[i]);
1838 free_stringlist(&tags[i]);
1839 }
1840 }
1841
1842 fclose(scf);
1843}
void pg_free(void *ptr)
Definition: fe_memutils.c:105
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:122
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:181
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:191
#define note_detail(...)
Definition: pg_regress.c:163
#define MAX_PARALLEL_TESTS
static void test_status_ok(const char *testname, double runtime, bool parallel)
Definition: pg_regress.c:303
static void log_child_failure(int exitstatus)
Definition: pg_regress.c:1620
static void test_status_failed(const char *testname, double runtime, bool parallel)
Definition: pg_regress.c:311
static void wait_for_tests(PID_TYPE *pids, int *statuses, instr_time *stoptimes, char **names, int num_tests)
Definition: pg_regress.c:1553
static bool results_differ(const char *testname, const char *resultsfile, const char *default_expectfile)
Definition: pg_regress.c:1407
#define note_end()
Definition: pg_regress.c:165
#define PID_TYPE
Definition: pg_regress.h:14
static void test(void)

References bail, diag, free_stringlist(), i, INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, log_child_failure(), max_concurrent_tests, max_connections, MAX_PARALLEL_TESTS, _stringlist::next, note_detail, note_end, pg_free(), pg_strdup(), PID_TYPE, results_differ(), _stringlist::str, test(), test_status_failed(), test_status_ok(), and wait_for_tests().

Referenced by regression_main().

◆ run_single_test()

static void run_single_test ( const char *  test,
test_start_function  startfunc,
postprocess_result_function  postfunc 
)
static

Definition at line 1849 of file pg_regress.c.

1851{
1852 PID_TYPE pid;
1853 instr_time starttime;
1854 instr_time stoptime;
1855 int exit_status;
1856 _stringlist *resultfiles = NULL;
1857 _stringlist *expectfiles = NULL;
1858 _stringlist *tags = NULL;
1859 _stringlist *rl,
1860 *el,
1861 *tl;
1862 bool differ = false;
1863
1864 pid = (startfunc) (test, &resultfiles, &expectfiles, &tags);
1865 INSTR_TIME_SET_CURRENT(starttime);
1866 wait_for_tests(&pid, &exit_status, &stoptime, NULL, 1);
1867
1868 /*
1869 * Advance over all three lists simultaneously.
1870 *
1871 * Compare resultfiles[j] with expectfiles[j] always. Tags are optional
1872 * but if there are tags, the tag list has the same length as the other
1873 * two lists.
1874 */
1875 for (rl = resultfiles, el = expectfiles, tl = tags;
1876 rl != NULL; /* rl and el have the same length */
1877 rl = rl->next, el = el->next,
1878 tl = tl ? tl->next : NULL)
1879 {
1880 bool newdiff;
1881
1882 if (postfunc)
1883 (*postfunc) (rl->str);
1884 newdiff = results_differ(test, rl->str, el->str);
1885 if (newdiff && tl)
1886 {
1887 diag("tag: %s", tl->str);
1888 }
1889 differ |= newdiff;
1890 }
1891
1892 INSTR_TIME_SUBTRACT(stoptime, starttime);
1893
1894 if (exit_status != 0)
1895 {
1897 log_child_failure(exit_status);
1898 }
1899 else
1900 {
1901 if (differ)
1902 {
1904 }
1905 else
1906 {
1907 test_status_ok(test, INSTR_TIME_GET_MILLISEC(stoptime), false);
1908 }
1909 }
1910}

References diag, INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, log_child_failure(), _stringlist::next, PID_TYPE, results_differ(), _stringlist::str, test(), test_status_failed(), test_status_ok(), and wait_for_tests().

Referenced by regression_main().

◆ signal_remove_temp()

static void signal_remove_temp ( SIGNAL_ARGS  )
static

Definition at line 480 of file pg_regress.c.

481{
482 remove_temp();
483
484 pqsignal(postgres_signal_arg, SIG_DFL);
485 raise(postgres_signal_arg);
486}

References pqsignal, and remove_temp().

Referenced by make_temp_sockdir().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1204 of file pg_regress.c.

1205{
1206#ifndef WIN32
1207 pid_t pid;
1208
1209 /*
1210 * Must flush I/O buffers before fork.
1211 */
1212 fflush(NULL);
1213
1214#ifdef EXEC_BACKEND
1215 pg_disable_aslr();
1216#endif
1217
1218 pid = fork();
1219 if (pid == -1)
1220 {
1221 bail("could not fork: %m");
1222 }
1223 if (pid == 0)
1224 {
1225 /*
1226 * In child
1227 *
1228 * Instead of using system(), exec the shell directly, and tell it to
1229 * "exec" the command too. This saves two useless processes per
1230 * parallel test case.
1231 */
1232 char *cmdline2;
1233
1234 cmdline2 = psprintf("exec %s", cmdline);
1235 execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1236 /* Not using the normal bail() here as we want _exit */
1237 bail_noatexit("could not exec \"%s\": %m", shellprog);
1238 }
1239 /* in parent */
1240 return pid;
1241#else
1242 PROCESS_INFORMATION pi;
1243 char *cmdline2;
1244 const char *comspec;
1245
1246 /* Find CMD.EXE location using COMSPEC, if it's set */
1247 comspec = getenv("COMSPEC");
1248 if (comspec == NULL)
1249 comspec = "CMD";
1250
1251 memset(&pi, 0, sizeof(pi));
1252 cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
1253
1254 if (!CreateRestrictedProcess(cmdline2, &pi))
1255 exit(2);
1256
1257 CloseHandle(pi.hThread);
1258 return pi.hProcess;
1259#endif
1260}
static char * shellprog
Definition: pg_regress.c:55
#define bail_noatexit(...)
Definition: pg_regress.c:166

References bail, bail_noatexit, exit(), fflush(), psprintf(), and shellprog.

Referenced by ecpg_start_test(), isolation_start_test(), psql_start_test(), and regression_main().

◆ split_to_stringlist()

static void split_to_stringlist ( const char *  s,
const char *  delim,
_stringlist **  listhead 
)
static

Definition at line 233 of file pg_regress.c.

234{
235 char *token;
236 char *sc;
237 char *tofree;
238
239 tofree = sc = pg_strdup(s);
240
241 while ((token = strsep(&sc, delim)))
242 {
243 add_stringlist_item(listhead, token);
244 }
245 free(tofree);
246}
#define token
Definition: indent_globs.h:126
char * strsep(char **stringp, const char *delim)
Definition: strsep.c:49

References add_stringlist_item(), free, pg_strdup(), strsep(), and token.

Referenced by regression_main().

◆ stop_postmaster()

static void stop_postmaster ( void  )
static

Definition at line 433 of file pg_regress.c.

434{
436 {
437 /* We use pg_ctl to issue the kill and wait for stop */
438 char buf[MAXPGPATH * 2];
439 int r;
440
441 snprintf(buf, sizeof(buf),
442 "\"%s%spg_ctl\" stop -D \"%s/data\" -s",
443 bindir ? bindir : "",
444 bindir ? "/" : "",
446 fflush(NULL);
447 r = system(buf);
448 if (r != 0)
449 {
450 /* Not using the normal bail() as we want _exit */
451 bail_noatexit(_("could not stop postmaster: exit code was %d"), r);
452 }
453
454 postmaster_running = false;
455 }
456}

References _, bail_noatexit, bindir, buf, fflush(), MAXPGPATH, postmaster_running, snprintf, and temp_instance.

Referenced by regression_main().

◆ string_matches_pattern()

static bool string_matches_pattern ( const char *  str,
const char *  pattern 
)
static

Definition at line 546 of file pg_regress.c.

547{
548 while (*str && *pattern)
549 {
550 if (*pattern == '.' && pattern[1] == '*')
551 {
552 pattern += 2;
553 /* Trailing .* matches everything. */
554 if (*pattern == '\0')
555 return true;
556
557 /*
558 * Otherwise, scan for a text position at which we can match the
559 * rest of the pattern.
560 */
561 while (*str)
562 {
563 /*
564 * Optimization to prevent most recursion: don't recurse
565 * unless first pattern char might match this text char.
566 */
567 if (*str == *pattern || *pattern == '.')
568 {
569 if (string_matches_pattern(str, pattern))
570 return true;
571 }
572
573 str++;
574 }
575
576 /*
577 * End of text with no match.
578 */
579 return false;
580 }
581 else if (*pattern != '.' && *str != *pattern)
582 {
583 /*
584 * Not the single-character wildcard and no explicit match? Then
585 * time to quit...
586 */
587 return false;
588 }
589
590 str++;
591 pattern++;
592 }
593
594 if (*pattern == '\0')
595 return true; /* end of pattern, so declare match */
596
597 /* End of input string. Do we have matching pattern remaining? */
598 while (*pattern == '.' && pattern[1] == '*')
599 pattern += 2;
600 if (*pattern == '\0')
601 return true; /* end of pattern, so declare match */
602
603 return false;
604}

References str, and string_matches_pattern().

Referenced by load_resultmap(), and string_matches_pattern().

◆ test_status_failed()

static void test_status_failed ( const char *  testname,
double  runtime,
bool  parallel 
)
static

Definition at line 311 of file pg_regress.c.

312{
313 /*
314 * Save failed tests in a buffer such that we can print a summary at the
315 * end with diag() to ensure it's shown even under test harnesses.
316 */
317 if (!failed_tests)
319 else
321
322 appendStringInfo(failed_tests, " %s", testname);
323
324 fail_count++;
325
326 test_status_print(false, testname, runtime, parallel);
327}
static StringInfo failed_tests
Definition: pg_regress.c:132
static void test_status_print(bool ok, const char *testname, double runtime, bool parallel)
Definition: pg_regress.c:280

References appendStringInfo(), appendStringInfoChar(), fail_count, failed_tests, makeStringInfo(), and test_status_print().

Referenced by run_schedule(), and run_single_test().

◆ test_status_ok()

static void test_status_ok ( const char *  testname,
double  runtime,
bool  parallel 
)
static

Definition at line 303 of file pg_regress.c.

304{
306
307 test_status_print(true, testname, runtime, parallel);
308}

References success_count, and test_status_print().

Referenced by run_schedule(), and run_single_test().

◆ test_status_print()

static void test_status_print ( bool  ok,
const char *  testname,
double  runtime,
bool  parallel 
)
static

Definition at line 280 of file pg_regress.c.

281{
282 int testnumber = fail_count + success_count;
283
284 /*
285 * Testnumbers are padded to 5 characters to ensure that testnames align
286 * vertically (assuming at most 9999 tests). Testnames are prefixed with
287 * a leading character to indicate being run in parallel or not. A leading
288 * '+' indicates a parallel test, '-' indicates a single test.
289 */
290 emit_tap_output(TEST_STATUS, "%sok %-5i%*s %c %-*s %8.0f ms",
291 (ok ? "" : "not "),
292 testnumber,
293 /* If ok, indent with four spaces matching "not " */
294 (ok ? (int) strlen("not ") : 0), "",
295 /* Prefix a parallel test '+' and a single test with '-' */
296 (parallel ? '+' : '-'),
297 /* Testnames are padded to align runtimes */
298 TESTNAME_WIDTH, testname,
299 runtime);
300}
static void static void emit_tap_output(TAPtype type, const char *fmt,...) pg_attribute_printf(2
Definition: pg_regress.c:331
#define TESTNAME_WIDTH
Definition: pg_regress.c:76

References emit_tap_output(), fail_count, success_count, TEST_STATUS, and TESTNAME_WIDTH.

Referenced by test_status_failed(), and test_status_ok().

◆ unlimit_core_size()

static void unlimit_core_size ( void  )
static

Definition at line 174 of file pg_regress.c.

175{
176 struct rlimit lim;
177
178 getrlimit(RLIMIT_CORE, &lim);
179 if (lim.rlim_max == 0)
180 {
181 diag("could not set core size: disallowed by hard limit");
182 return;
183 }
184 else if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
185 {
186 lim.rlim_cur = lim.rlim_max;
187 setrlimit(RLIMIT_CORE, &lim);
188 }
189}

References diag.

Referenced by regression_main().

◆ wait_for_tests()

static void wait_for_tests ( PID_TYPE pids,
int *  statuses,
instr_time stoptimes,
char **  names,
int  num_tests 
)
static

Definition at line 1553 of file pg_regress.c.

1555{
1556 int tests_left;
1557 int i;
1558
1559#ifdef WIN32
1560 PID_TYPE *active_pids = pg_malloc(num_tests * sizeof(PID_TYPE));
1561
1562 memcpy(active_pids, pids, num_tests * sizeof(PID_TYPE));
1563#endif
1564
1565 tests_left = num_tests;
1566 while (tests_left > 0)
1567 {
1568 PID_TYPE p;
1569
1570#ifndef WIN32
1571 int exit_status;
1572
1573 p = wait(&exit_status);
1574
1575 if (p == INVALID_PID)
1576 bail("failed to wait for subprocesses: %m");
1577#else
1578 DWORD exit_status;
1579 int r;
1580
1581 r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE);
1582 if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left)
1583 {
1584 bail("failed to wait for subprocesses: error code %lu",
1585 GetLastError());
1586 }
1587 p = active_pids[r - WAIT_OBJECT_0];
1588 /* compact the active_pids array */
1589 active_pids[r - WAIT_OBJECT_0] = active_pids[tests_left - 1];
1590#endif /* WIN32 */
1591
1592 for (i = 0; i < num_tests; i++)
1593 {
1594 if (p == pids[i])
1595 {
1596#ifdef WIN32
1597 GetExitCodeProcess(pids[i], &exit_status);
1598 CloseHandle(pids[i]);
1599#endif
1600 pids[i] = INVALID_PID;
1601 statuses[i] = (int) exit_status;
1602 INSTR_TIME_SET_CURRENT(stoptimes[i]);
1603 if (names)
1604 note_detail(" %s", names[i]);
1605 tests_left--;
1606 break;
1607 }
1608 }
1609 }
1610
1611#ifdef WIN32
1612 free(active_pids);
1613#endif
1614}

References bail, free, i, INSTR_TIME_SET_CURRENT, INVALID_PID, note_detail, pg_malloc(), and PID_TYPE.

Referenced by run_schedule(), and run_single_test().

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts = ""

Definition at line 64 of file pg_regress.c.

Referenced by results_differ().

◆ bindir

char* bindir = PGBINDIR

◆ config_auth_datadir

char* config_auth_datadir = NULL
static

Definition at line 121 of file pg_regress.c.

Referenced by regression_main().

◆ dblist

◆ debug

bool debug = false

Definition at line 98 of file pg_regress.c.

Referenced by regression_main().

◆ difffilename

char* difffilename
static

Definition at line 127 of file pg_regress.c.

Referenced by open_result_files(), regression_main(), and results_differ().

◆ dlpath

char* dlpath = PKGLIBDIR
static

Definition at line 118 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

◆ encoding

char* encoding = NULL
static

Definition at line 107 of file pg_regress.c.

Referenced by create_database(), initialize_environment(), and regression_main().

◆ expecteddir

char* expecteddir = "."

Definition at line 101 of file pg_regress.c.

Referenced by ecpg_start_test(), psql_start_test(), and regression_main().

◆ extra_tests

_stringlist* extra_tests = NULL
static

Definition at line 109 of file pg_regress.c.

Referenced by regression_main().

◆ extraroles

_stringlist* extraroles = NULL
static

Definition at line 120 of file pg_regress.c.

Referenced by regression_main().

◆ fail_count

int fail_count = 0
static

Definition at line 141 of file pg_regress.c.

Referenced by regression_main(), test_status_failed(), and test_status_print().

◆ failed_tests

StringInfo failed_tests = NULL
static

Definition at line 132 of file pg_regress.c.

Referenced by test_status_failed().

◆ host_platform

char* host_platform = HOST_TUPLE

Definition at line 52 of file pg_regress.c.

Referenced by load_resultmap().

◆ hostname

char* hostname = NULL
static

◆ in_note

bool in_note = false
static

Definition at line 133 of file pg_regress.c.

Referenced by emit_tap_output_v().

◆ inputdir

◆ launcher

char* launcher = NULL

Definition at line 103 of file pg_regress.c.

Referenced by isolation_start_test(), psql_start_test(), and regression_main().

◆ loadextension

_stringlist* loadextension = NULL
static

Definition at line 104 of file pg_regress.c.

Referenced by create_database(), and regression_main().

◆ logfile

FILE* logfile
static

◆ logfilename

char* logfilename
static

Definition at line 125 of file pg_regress.c.

Referenced by open_result_files(), and regression_main().

◆ max_concurrent_tests

int max_concurrent_tests = 0
static

Definition at line 106 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

◆ max_connections

int max_connections = 0
static

Definition at line 105 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

◆ nolocale

bool nolocale = false
static

Definition at line 112 of file pg_regress.c.

Referenced by create_database(), initialize_environment(), and regression_main().

◆ outputdir

◆ port

int port = -1
static

Definition at line 115 of file pg_regress.c.

Referenced by auth_delay_checks(), auth_failed(), auth_peer(), BackendInitialize(), be_gssapi_get_auth(), be_gssapi_get_delegation(), be_gssapi_get_enc(), be_gssapi_get_princ(), be_gssapi_read(), be_gssapi_write(), be_tls_close(), be_tls_get_certificate_hash(), be_tls_get_cipher(), be_tls_get_cipher_bits(), be_tls_get_peer_issuer_name(), be_tls_get_peer_serial(), be_tls_get_peer_subject_name(), be_tls_get_version(), be_tls_open_server(), be_tls_read(), be_tls_write(), check_hba(), check_hostname(), CheckMD5Auth(), CheckPasswordAuth(), CheckPWChallengeAuth(), CheckRADIUSAuth(), CheckSASLAuth(), ClientAuthentication(), conninfo_uri_parse_options(), do_connect(), ECPGconnect(), hba_getauthmethod(), ident_inet(), inet_client_addr(), inet_client_port(), inet_server_addr(), inet_server_port(), initialize_environment(), log_disconnections(), main(), make_temp_sockdir(), passwordFromFile(), PerformAuthentication(), PerformRadiusTransaction(), port_bio_ctrl(), port_bio_read(), pq_getkeepalivescount(), pq_getkeepalivesidle(), pq_getkeepalivesinterval(), pq_gettcpusertimeout(), pq_init(), pq_setkeepalivescount(), pq_setkeepalivesidle(), pq_setkeepalivesinterval(), pq_settcpusertimeout(), process_startup_options(), ProcessSSLStartup(), ProcessStartupPacket(), read_or_wait(), regression_main(), scram_get_mechanisms(), scram_init(), secure_close(), secure_open_gssapi(), secure_open_server(), secure_raw_read(), secure_raw_write(), secure_read(), secure_write(), sepgsql_client_auth(), set_authn_id(), and ssl_set_port_bio().

◆ port_specified_by_user

bool port_specified_by_user = false
static

Definition at line 117 of file pg_regress.c.

Referenced by regression_main().

◆ portstr

char portstr[16]
static

Definition at line 116 of file pg_regress.c.

Referenced by PerformRadiusTransaction(), PQconnectPoll(), and regression_main().

◆ postmaster_pid

PID_TYPE postmaster_pid = INVALID_PID
static

Definition at line 137 of file pg_regress.c.

Referenced by regression_main().

◆ postmaster_running

bool postmaster_running = false
static

Definition at line 138 of file pg_regress.c.

Referenced by regression_main(), and stop_postmaster().

◆ pretty_diff_opts

const char* pretty_diff_opts = "-U3"

Definition at line 65 of file pg_regress.c.

Referenced by regression_main(), and results_differ().

◆ progname

const char* progname
static

Definition at line 124 of file pg_regress.c.

Referenced by help(), and regression_main().

◆ resultmap

_resultmap* resultmap = NULL
static

Definition at line 135 of file pg_regress.c.

Referenced by get_expectfile(), and load_resultmap().

◆ schedulelist

_stringlist* schedulelist = NULL
static

Definition at line 108 of file pg_regress.c.

Referenced by regression_main().

◆ shellprog

char* shellprog = SHELLPROG
static

Definition at line 55 of file pg_regress.c.

Referenced by spawn_process().

◆ sockdir

const char* sockdir
static

Definition at line 128 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

◆ socklock

char socklock[MAXPGPATH]
static

Definition at line 131 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ sockself

char sockself[MAXPGPATH]
static

Definition at line 130 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ success_count

int success_count = 0
static

Definition at line 140 of file pg_regress.c.

Referenced by regression_main(), test_status_ok(), and test_status_print().

◆ temp_configs

_stringlist* temp_configs = NULL
static

Definition at line 111 of file pg_regress.c.

Referenced by regression_main().

◆ temp_instance

char* temp_instance = NULL
static

Definition at line 110 of file pg_regress.c.

Referenced by initialize_environment(), regression_main(), and stop_postmaster().

◆ temp_sockdir

const char* temp_sockdir
static

Definition at line 129 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ use_existing

bool use_existing = false
static

Definition at line 113 of file pg_regress.c.

Referenced by regression_main().

◆ user