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/string.h"
#include "common/username.h"
#include "getopt_long.h"
#include "lib/stringinfo.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 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 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 160 of file pg_regress.c.

◆ bail_noatexit

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

Definition at line 159 of file pg_regress.c.

◆ diag

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

Definition at line 157 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 155 of file pg_regress.c.

◆ note_detail

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

Definition at line 156 of file pg_regress.c.

◆ note_end

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

Definition at line 158 of file pg_regress.c.

◆ plan

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

Definition at line 154 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:1104

Definition at line 1176 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)

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 78 of file pg_regress.c.

79 {
80  DIAG = 0,
81  BAIL,
82  NOTE,
84  NOTE_END,
86  PLAN,
87  NONE
88 } TAPtype;
TAPtype
Definition: pg_regress.c:79
@ PLAN
Definition: pg_regress.c:86
@ NOTE
Definition: pg_regress.c:82
@ DIAG
Definition: pg_regress.c:80
@ NOTE_DETAIL
Definition: pg_regress.c:83
@ NONE
Definition: pg_regress.c:87
@ TEST_STATUS
Definition: pg_regress.c:85
@ BAIL
Definition: pg_regress.c:81
@ NOTE_END
Definition: pg_regress.c:84

Function Documentation

◆ add_stringlist_item()

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

Definition at line 190 of file pg_regress.c.

191 {
192  _stringlist *newentry = pg_malloc(sizeof(_stringlist));
193  _stringlist *oldentry;
194 
195  newentry->str = pg_strdup(str);
196  newentry->next = NULL;
197  if (*listhead == NULL)
198  *listhead = newentry;
199  else
200  {
201  for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
202  /* skip */ ;
203  oldentry->next = newentry;
204  }
205 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * str
Definition: initdb.c:91
struct _stringlist * next
Definition: initdb.c:92

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

Referenced by regression_main(), and split_to_stringlist().

◆ bail_out()

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

Definition at line 246 of file pg_regress.c.

247 {
248  va_list ap;
249 
250  va_start(ap, fmt);
251  emit_tap_output_v(BAIL, fmt, ap);
252  va_end(ap);
253 
254  if (noatexit)
255  _exit(2);
256 
257  exit(2);
258 }
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:332

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 1964 of file pg_regress.c.

1965 {
1967  _stringlist *sl;
1968 
1969  /*
1970  * We use template0 so that any installation-local cruft in template1 will
1971  * not mess up the tests.
1972  */
1973  if (encoding)
1974  psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0 ENCODING='%s'%s", dbname, encoding,
1975  (nolocale) ? " LC_COLLATE='C' LC_CTYPE='C'" : "");
1976  else
1977  psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0%s", dbname,
1978  (nolocale) ? " LC_COLLATE='C' LC_CTYPE='C'" : "");
1980  "ALTER DATABASE \"%s\" SET lc_messages TO 'C';"
1981  "ALTER DATABASE \"%s\" SET lc_monetary TO 'C';"
1982  "ALTER DATABASE \"%s\" SET lc_numeric TO 'C';"
1983  "ALTER DATABASE \"%s\" SET lc_time TO 'C';"
1984  "ALTER DATABASE \"%s\" SET bytea_output TO 'hex';"
1985  "ALTER DATABASE \"%s\" SET timezone_abbreviations TO 'Default';",
1987  psql_end_command(buf, "postgres");
1988 
1989  /*
1990  * Install any requested extensions. We use CREATE IF NOT EXISTS so that
1991  * this will work whether or not the extension is preinstalled.
1992  */
1993  for (sl = loadextension; sl != NULL; sl = sl->next)
1994  psql_command(dbname, "CREATE EXTENSION IF NOT EXISTS \"%s\"", sl->str);
1995 }
static bool nolocale
Definition: pg_regress.c:106
static void psql_add_command(StringInfo buf, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1116
static void static void psql_end_command(StringInfo buf, const char *database)
Definition: pg_regress.c:1153
static _stringlist * loadextension
Definition: pg_regress.c:98
static char * encoding
Definition: pg_regress.c:101
#define psql_command(database,...)
Definition: pg_regress.c:1176
static char * buf
Definition: pg_test_fsync.c:67
char * dbname
Definition: streamutil.c:51

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 2009 of file pg_regress.c.

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

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 1307 of file pg_regress.c.

1308 {
1309  struct stat st;
1310 
1311  if (stat(dir, &st) != 0)
1312  return false;
1313  if (S_ISDIR(st.st_mode))
1314  return true;
1315  return false;
1316 }
#define stat
Definition: win32_port.h:292
#define S_ISDIR(m)
Definition: win32_port.h:333

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 1953 of file pg_regress.c.

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

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 1998 of file pg_regress.c.

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

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 322 of file pg_regress.c.

323 {
324  va_list argp;
325 
326  va_start(argp, fmt);
327  emit_tap_output_v(type, fmt, argp);
328  va_end(argp);
329 }

References emit_tap_output_v(), fmt, generate_unaccent_rules::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 332 of file pg_regress.c.

333 {
334  va_list argp_logfile;
335  FILE *fp;
336 
337  /*
338  * Diagnostic output will be hidden by prove unless printed to stderr. The
339  * Bail message is also printed to stderr to aid debugging under a harness
340  * which might otherwise not emit such an important message.
341  */
342  if (type == DIAG || type == BAIL)
343  fp = stderr;
344  else
345  fp = stdout;
346 
347  /*
348  * If we are ending a note_detail line we can avoid further processing and
349  * immediately return following a newline.
350  */
351  if (type == NOTE_END)
352  {
353  in_note = false;
354  fprintf(fp, "\n");
355  if (logfile)
356  fprintf(logfile, "\n");
357  return;
358  }
359 
360  /* Make a copy of the va args for printing to the logfile */
361  va_copy(argp_logfile, argp);
362 
363  /*
364  * Non-protocol output such as diagnostics or notes must be prefixed by a
365  * '#' character. We print the Bail message like this too.
366  */
367  if ((type == NOTE || type == DIAG || type == BAIL)
368  || (type == NOTE_DETAIL && !in_note))
369  {
370  fprintf(fp, "# ");
371  if (logfile)
372  fprintf(logfile, "# ");
373  }
374  vfprintf(fp, fmt, argp);
375  if (logfile)
376  vfprintf(logfile, fmt, argp_logfile);
377 
378  /*
379  * If we are entering into a note with more details to follow, register
380  * that the leading '#' has been printed such that subsequent details
381  * aren't prefixed as well.
382  */
383  if (type == NOTE_DETAIL)
384  in_note = true;
385 
386  /*
387  * If this was a Bail message, the bail protocol message must go to stdout
388  * separately.
389  */
390  if (type == BAIL)
391  {
392  fprintf(stdout, "Bail out!");
393  if (logfile)
394  fprintf(logfile, "Bail out!");
395  }
396 
397  va_end(argp_logfile);
398 
399  if (type != NOTE_DETAIL)
400  {
401  fprintf(fp, "\n");
402  if (logfile)
403  fprintf(logfile, "\n");
404  }
405  fflush(NULL);
406 }
static void const char fflush(stdout)
vfprintf(stderr, fmt, args)
static bool in_note
Definition: pg_regress.c:126
static FILE * logfile
Definition: pg_regress.c:119
#define fprintf
Definition: port.h:242

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

Referenced by bail_out(), and emit_tap_output().

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1296 of file pg_regress.c.

1297 {
1298  FILE *f = fopen(file, "r");
1299 
1300  if (!f)
1301  return false;
1302  fclose(f);
1303  return true;
1304 }

Referenced by results_differ().

◆ file_line_count()

static int file_line_count ( const char *  file)
static

Definition at line 1274 of file pg_regress.c.

1275 {
1276  int c;
1277  int l = 0;
1278  FILE *f = fopen(file, "r");
1279 
1280  if (!f)
1281  {
1282  diag("could not open file \"%s\" for reading: %s",
1283  file, strerror(errno));
1284  return -1;
1285  }
1286  while ((c = fgetc(f)) != EOF)
1287  {
1288  if (c == '\n')
1289  l++;
1290  }
1291  fclose(f);
1292  return l;
1293 }
#define diag(...)
Definition: pg_regress.c:157
#define strerror
Definition: port.h:251
char * c

References diag, and strerror.

Referenced by results_differ().

◆ file_size()

static long file_size ( const char *  file)
static

Definition at line 1253 of file pg_regress.c.

1254 {
1255  long r;
1256  FILE *f = fopen(file, "r");
1257 
1258  if (!f)
1259  {
1260  diag("could not open file \"%s\" for reading: %s",
1261  file, strerror(errno));
1262  return -1;
1263  }
1264  fseek(f, 0, SEEK_END);
1265  r = ftell(f);
1266  fclose(f);
1267  return r;
1268 }

References diag, and strerror.

Referenced by regression_main(), and run_diff().

◆ free_stringlist()

static void free_stringlist ( _stringlist **  listhead)
static

Definition at line 211 of file pg_regress.c.

212 {
213  if (listhead == NULL || *listhead == NULL)
214  return;
215  if ((*listhead)->next != NULL)
216  free_stringlist(&((*listhead)->next));
217  free((*listhead)->str);
218  free(*listhead);
219  *listhead = NULL;
220 }
#define free(a)
Definition: header.h:65
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:211

References free.

Referenced by regression_main(), and run_schedule().

◆ get_alternative_expectfile()

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

Definition at line 1332 of file pg_regress.c.

1333 {
1334  char *last_dot;
1335  int ssize = strlen(expectfile) + 2 + 1;
1336  char *tmp;
1337  char *s;
1338 
1339  if (!(tmp = (char *) malloc(ssize)))
1340  return NULL;
1341 
1342  if (!(s = (char *) malloc(ssize)))
1343  {
1344  free(tmp);
1345  return NULL;
1346  }
1347 
1348  strcpy(tmp, expectfile);
1349  last_dot = strrchr(tmp, '.');
1350  if (!last_dot)
1351  {
1352  free(tmp);
1353  free(s);
1354  return NULL;
1355  }
1356  *last_dot = '\0';
1357  snprintf(s, ssize, "%s_%d.%s", tmp, i, last_dot + 1);
1358  free(tmp);
1359  return s;
1360 }
#define malloc(a)
Definition: header.h:50
int i
Definition: isn.c:73
#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 673 of file pg_regress.c.

674 {
675  char *file_type;
676  _resultmap *rm;
677 
678  /*
679  * Determine the file type from the file name. This is just what is
680  * following the last dot in the file name.
681  */
682  if (!file || !(file_type = strrchr(file, '.')))
683  return NULL;
684 
685  file_type++;
686 
687  for (rm = resultmap; rm != NULL; rm = rm->next)
688  {
689  if (strcmp(testname, rm->test) == 0 && strcmp(file_type, rm->type) == 0)
690  {
691  return rm->resultfile;
692  }
693  }
694 
695  return NULL;
696 }
static _resultmap * resultmap
Definition: pg_regress.c:128
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 2023 of file pg_regress.c.

2024 {
2025  printf(_("PostgreSQL regression test driver\n"));
2026  printf(_("\n"));
2027  printf(_("Usage:\n %s [OPTION]... [EXTRA-TEST]...\n"), progname);
2028  printf(_("\n"));
2029  printf(_("Options:\n"));
2030  printf(_(" --bindir=BINPATH use BINPATH for programs that are run;\n"));
2031  printf(_(" if empty, use PATH from the environment\n"));
2032  printf(_(" --config-auth=DATADIR update authentication settings for DATADIR\n"));
2033  printf(_(" --create-role=ROLE create the specified role before testing\n"));
2034  printf(_(" --dbname=DB use database DB (default \"regression\")\n"));
2035  printf(_(" --debug turn on debug mode in programs that are run\n"));
2036  printf(_(" --dlpath=DIR look for dynamic libraries in DIR\n"));
2037  printf(_(" --encoding=ENCODING use ENCODING as the encoding\n"));
2038  printf(_(" --expecteddir=DIR take expected files from DIR (default \".\")\n"));
2039  printf(_(" -h, --help show this help, then exit\n"));
2040  printf(_(" --inputdir=DIR take input files from DIR (default \".\")\n"));
2041  printf(_(" --launcher=CMD use CMD as launcher of psql\n"));
2042  printf(_(" --load-extension=EXT load the named extension before running the\n"));
2043  printf(_(" tests; can appear multiple times\n"));
2044  printf(_(" --max-connections=N maximum number of concurrent connections\n"));
2045  printf(_(" (default is 0, meaning unlimited)\n"));
2046  printf(_(" --max-concurrent-tests=N maximum number of concurrent tests in schedule\n"));
2047  printf(_(" (default is 0, meaning unlimited)\n"));
2048  printf(_(" --outputdir=DIR place output files in DIR (default \".\")\n"));
2049  printf(_(" --schedule=FILE use test ordering schedule from FILE\n"));
2050  printf(_(" (can be used multiple times to concatenate)\n"));
2051  printf(_(" --temp-instance=DIR create a temporary instance in DIR\n"));
2052  printf(_(" --use-existing use an existing installation\n"));
2053  printf(_(" -V, --version output version information, then exit\n"));
2054  printf(_("\n"));
2055  printf(_("Options for \"temp-instance\" mode:\n"));
2056  printf(_(" --no-locale use C locale\n"));
2057  printf(_(" --port=PORT start postmaster on PORT\n"));
2058  printf(_(" --temp-config=FILE append contents of FILE to temporary config\n"));
2059  printf(_("\n"));
2060  printf(_("Options for using an existing installation:\n"));
2061  printf(_(" --host=HOST use postmaster running on HOST\n"));
2062  printf(_(" --port=PORT use postmaster running at PORT\n"));
2063  printf(_(" --user=USER connect as USER\n"));
2064  printf(_("\n"));
2065  printf(_("The exit status is 0 if all tests passed, 1 if some tests failed, and 2\n"));
2066  printf(_("if the tests could not be run for some reason.\n"));
2067  printf(_("\n"));
2068  printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2069  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
2070 }
#define _(x)
Definition: elog.c:91
static const char * progname
Definition: pg_regress.c:117
#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 702 of file pg_regress.c.

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

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

Referenced by regression_main().

◆ load_resultmap()

static void load_resultmap ( void  )
static

Definition at line 598 of file pg_regress.c.

599 {
600  char buf[MAXPGPATH];
601  FILE *f;
602 
603  /* scan the file ... */
604  snprintf(buf, sizeof(buf), "%s/resultmap", inputdir);
605  f = fopen(buf, "r");
606  if (!f)
607  {
608  /* OK if it doesn't exist, else complain */
609  if (errno == ENOENT)
610  return;
611  bail("could not open file \"%s\" for reading: %s",
612  buf, strerror(errno));
613  }
614 
615  while (fgets(buf, sizeof(buf), f))
616  {
617  char *platform;
618  char *file_type;
619  char *expected;
620  int i;
621 
622  /* strip trailing whitespace, especially the newline */
623  i = strlen(buf);
624  while (i > 0 && isspace((unsigned char) buf[i - 1]))
625  buf[--i] = '\0';
626 
627  /* parse out the line fields */
628  file_type = strchr(buf, ':');
629  if (!file_type)
630  {
631  bail("incorrectly formatted resultmap entry: %s", buf);
632  }
633  *file_type++ = '\0';
634 
635  platform = strchr(file_type, ':');
636  if (!platform)
637  {
638  bail("incorrectly formatted resultmap entry: %s", buf);
639  }
640  *platform++ = '\0';
641  expected = strchr(platform, '=');
642  if (!expected)
643  {
644  bail("incorrectly formatted resultmap entry: %s", buf);
645  }
646  *expected++ = '\0';
647 
648  /*
649  * if it's for current platform, save it in resultmap list. Note: by
650  * adding at the front of the list, we ensure that in ambiguous cases,
651  * the last match in the resultmap file is used. This mimics the
652  * behavior of the old shell script.
653  */
654  if (string_matches_pattern(host_platform, platform))
655  {
656  _resultmap *entry = pg_malloc(sizeof(_resultmap));
657 
658  entry->test = pg_strdup(buf);
659  entry->type = pg_strdup(file_type);
660  entry->resultfile = pg_strdup(expected);
661  entry->next = resultmap;
662  resultmap = entry;
663  }
664  }
665  fclose(f);
666 }
#define MAXPGPATH
char * host_platform
Definition: pg_regress.c:52
#define bail(...)
Definition: pg_regress.c:160
static bool string_matches_pattern(const char *str, const char *pattern)
Definition: pg_regress.c:524

References bail, buf, host_platform, i, inputdir, MAXPGPATH, _resultmap::next, pg_malloc(), pg_strdup(), _resultmap::resultfile, resultmap, snprintf, strerror, 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 1616 of file pg_regress.c.

1617 {
1618  if (WIFEXITED(exitstatus))
1619  diag("(test process exited with exit code %d)",
1620  WEXITSTATUS(exitstatus));
1621  else if (WIFSIGNALED(exitstatus))
1622  {
1623 #if defined(WIN32)
1624  diag("(test process was terminated by exception 0x%X)",
1625  WTERMSIG(exitstatus));
1626 #else
1627  diag("(test process was terminated by signal %d: %s)",
1628  WTERMSIG(exitstatus), pg_strsignal(WTERMSIG(exitstatus)));
1629 #endif
1630  }
1631  else
1632  diag("(test process exited with unrecognized status %d)", exitstatus);
1633 }
const char * pg_strsignal(int signum)
Definition: pgstrsignal.c:42
#define WIFEXITED(w)
Definition: win32_port.h:160
#define WIFSIGNALED(w)
Definition: win32_port.h:161
#define WTERMSIG(w)
Definition: win32_port.h:163
#define WEXITSTATUS(w)
Definition: win32_port.h:162

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 1320 of file pg_regress.c.

1321 {
1322  if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
1323  {
1324  bail("could not create directory \"%s\": %s", dir, strerror(errno));
1325  }
1326 }
#define S_IRWXG
Definition: win32_port.h:318
#define S_IRWXO
Definition: win32_port.h:330
#define mkdir(a, b)
Definition: win32_port.h:80
#define S_IRWXU
Definition: win32_port.h:306

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

Referenced by open_result_files(), and regression_main().

◆ make_temp_sockdir()

static const char* make_temp_sockdir ( void  )
static

Definition at line 480 of file pg_regress.c.

481 {
482  char *template = psprintf("%s/pg_regress-XXXXXX",
483  getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
484 
485  temp_sockdir = mkdtemp(template);
486  if (temp_sockdir == NULL)
487  {
488  bail("could not create directory \"%s\": %s",
489  template, strerror(errno));
490  }
491 
492  /* Stage file names for remove_temp(). Unsafe in a signal handler. */
494  snprintf(socklock, sizeof(socklock), "%s.lock", sockself);
495 
496  /* Remove the directory during clean exit. */
497  atexit(remove_temp);
498 
499  /*
500  * Remove the directory before dying to the usual signals. Omit SIGQUIT,
501  * preserving it as a quick, untidy exit.
502  */
504  pqsignal(SIGINT, signal_remove_temp);
506  pqsignal(SIGTERM, signal_remove_temp);
507 
508  return temp_sockdir;
509 }
static void signal_remove_temp(SIGNAL_ARGS)
Definition: pg_regress.c:459
static void remove_temp(void)
Definition: pg_regress.c:447
static const char * temp_sockdir
Definition: pg_regress.c:122
static char sockself[MAXPGPATH]
Definition: pg_regress.c:123
static char socklock[MAXPGPATH]
Definition: pg_regress.c:124
pqsigfunc pqsignal(int signo, pqsigfunc func)
char * mkdtemp(char *path)
Definition: mkdtemp.c:286
#define UNIXSOCK_PATH(path, port, sockdir)
Definition: pqcomm.h:38
#define SIGHUP
Definition: win32_port.h:176
#define SIGPIPE
Definition: win32_port.h:181

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

Referenced by initialize_environment().

◆ open_result_files()

static void open_result_files ( void  )
static

Definition at line 1915 of file pg_regress.c.

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

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

Referenced by regression_main().

◆ psql_add_command()

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

Definition at line 1116 of file pg_regress.c.

1117 {
1118  StringInfoData cmdbuf;
1119  const char *cmdptr;
1120 
1121  /* Add each command as a -c argument in the psql call */
1122  appendStringInfoString(buf, " -c \"");
1123 
1124  /* Generate the query with insertion of sprintf arguments */
1125  initStringInfo(&cmdbuf);
1126  for (;;)
1127  {
1128  va_list args;
1129  int needed;
1130 
1131  va_start(args, query);
1132  needed = appendStringInfoVA(&cmdbuf, query, args);
1133  va_end(args);
1134  if (needed == 0)
1135  break; /* success */
1136  enlargeStringInfo(&cmdbuf, needed);
1137  }
1138 
1139  /* Now escape any shell double-quote metacharacters */
1140  for (cmdptr = cmdbuf.data; *cmdptr; cmdptr++)
1141  {
1142  if (strchr("\\\"$`", *cmdptr))
1143  appendStringInfoChar(buf, '\\');
1144  appendStringInfoChar(buf, *cmdptr);
1145  }
1146 
1147  appendStringInfoChar(buf, '"');
1148 
1149  pfree(cmdbuf.data);
1150 }
void pfree(void *pointer)
Definition: mcxt.c:1456
int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
Definition: stringinfo.c:133
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:283
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

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 1153 of file pg_regress.c.

1154 {
1155  /* Add the database name --- assume it needs no extra escaping */
1157  " \"%s\"",
1158  database);
1159 
1160  /* And now we can execute the shell command */
1161  fflush(NULL);
1162  if (system(buf->data) != 0)
1163  {
1164  /* psql probably already reported the error */
1165  bail("command failed: %s", buf->data);
1166  }
1167 
1168  /* Clean up */
1169  pfree(buf->data);
1170  pfree(buf);
1171 }
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91

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

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 1104 of file pg_regress.c.

1105 {
1107 
1109  "\"%s%spsql\" -X -q",
1110  bindir ? bindir : "",
1111  bindir ? "/" : "");
1112  return buf;
1113 }
char * bindir
Definition: pg_regress.c:96
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41

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 2073 of file pg_regress.c.

2077 {
2078  static struct option long_options[] = {
2079  {"help", no_argument, NULL, 'h'},
2080  {"version", no_argument, NULL, 'V'},
2081  {"dbname", required_argument, NULL, 1},
2082  {"debug", no_argument, NULL, 2},
2083  {"inputdir", required_argument, NULL, 3},
2084  {"max-connections", required_argument, NULL, 5},
2085  {"encoding", required_argument, NULL, 6},
2086  {"outputdir", required_argument, NULL, 7},
2087  {"schedule", required_argument, NULL, 8},
2088  {"temp-instance", required_argument, NULL, 9},
2089  {"no-locale", no_argument, NULL, 10},
2090  {"host", required_argument, NULL, 13},
2091  {"port", required_argument, NULL, 14},
2092  {"user", required_argument, NULL, 15},
2093  {"bindir", required_argument, NULL, 16},
2094  {"dlpath", required_argument, NULL, 17},
2095  {"create-role", required_argument, NULL, 18},
2096  {"temp-config", required_argument, NULL, 19},
2097  {"use-existing", no_argument, NULL, 20},
2098  {"launcher", required_argument, NULL, 21},
2099  {"load-extension", required_argument, NULL, 22},
2100  {"config-auth", required_argument, NULL, 24},
2101  {"max-concurrent-tests", required_argument, NULL, 25},
2102  {"expecteddir", required_argument, NULL, 26},
2103  {NULL, 0, NULL, 0}
2104  };
2105 
2106  bool use_unix_sockets;
2107  _stringlist *sl;
2108  int c;
2109  int i;
2110  int option_index;
2111  char buf[MAXPGPATH * 4];
2112  char buf2[MAXPGPATH * 4];
2113 
2114  pg_logging_init(argv[0]);
2115  progname = get_progname(argv[0]);
2116  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_regress"));
2117 
2119 
2120  atexit(stop_postmaster);
2121 
2122 #if defined(WIN32)
2123 
2124  /*
2125  * We don't use Unix-domain sockets on Windows by default (see comment at
2126  * remove_temp() for a reason). Override at your own risk.
2127  */
2128  use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false;
2129 #else
2130  use_unix_sockets = true;
2131 #endif
2132 
2133  if (!use_unix_sockets)
2134  hostname = "localhost";
2135 
2136  /*
2137  * We call the initialization function here because that way we can set
2138  * default parameters and let them be overwritten by the commandline.
2139  */
2140  ifunc(argc, argv);
2141 
2142  if (getenv("PG_REGRESS_DIFF_OPTS"))
2143  pretty_diff_opts = getenv("PG_REGRESS_DIFF_OPTS");
2144 
2145  while ((c = getopt_long(argc, argv, "hV", long_options, &option_index)) != -1)
2146  {
2147  switch (c)
2148  {
2149  case 'h':
2150  help();
2151  exit(0);
2152  case 'V':
2153  puts("pg_regress (PostgreSQL) " PG_VERSION);
2154  exit(0);
2155  case 1:
2156 
2157  /*
2158  * If a default database was specified, we need to remove it
2159  * before we add the specified one.
2160  */
2163  break;
2164  case 2:
2165  debug = true;
2166  break;
2167  case 3:
2169  break;
2170  case 5:
2171  max_connections = atoi(optarg);
2172  break;
2173  case 6:
2175  break;
2176  case 7:
2178  break;
2179  case 8:
2181  break;
2182  case 9:
2184  break;
2185  case 10:
2186  nolocale = true;
2187  break;
2188  case 13:
2190  break;
2191  case 14:
2192  port = atoi(optarg);
2193  port_specified_by_user = true;
2194  break;
2195  case 15:
2196  user = pg_strdup(optarg);
2197  break;
2198  case 16:
2199  /* "--bindir=" means to use PATH */
2200  if (strlen(optarg))
2201  bindir = pg_strdup(optarg);
2202  else
2203  bindir = NULL;
2204  break;
2205  case 17:
2206  dlpath = pg_strdup(optarg);
2207  break;
2208  case 18:
2210  break;
2211  case 19:
2213  break;
2214  case 20:
2215  use_existing = true;
2216  break;
2217  case 21:
2219  break;
2220  case 22:
2222  break;
2223  case 24:
2225  break;
2226  case 25:
2227  max_concurrent_tests = atoi(optarg);
2228  break;
2229  case 26:
2231  break;
2232  default:
2233  /* getopt_long already emitted a complaint */
2234  pg_log_error_hint("Try \"%s --help\" for more information.",
2235  progname);
2236  exit(2);
2237  }
2238  }
2239 
2240  /*
2241  * if we still have arguments, they are extra tests to run
2242  */
2243  while (argc - optind >= 1)
2244  {
2246  optind++;
2247  }
2248 
2249  /*
2250  * We must have a database to run the tests in; either a default name, or
2251  * one supplied by the --dbname switch.
2252  */
2253  if (!(dblist && dblist->str && dblist->str[0]))
2254  {
2255  bail("no database name was specified");
2256  }
2257 
2258  if (config_auth_datadir)
2259  {
2260 #ifdef ENABLE_SSPI
2261  if (!use_unix_sockets)
2262  config_sspi_auth(config_auth_datadir, user);
2263 #endif
2264  exit(0);
2265  }
2266 
2268 
2269  /*
2270  * To reduce chances of interference with parallel installations, use
2271  * a port number starting in the private range (49152-65535)
2272  * calculated from the version number. This aids non-Unix socket mode
2273  * systems; elsewhere, the use of a private socket directory already
2274  * prevents interference.
2275  */
2276  port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2277 
2282 
2283  /*
2284  * Initialization
2285  */
2287 
2289 
2290 #if defined(HAVE_GETRLIMIT)
2292 #endif
2293 
2294  if (temp_instance)
2295  {
2296  FILE *pg_conf;
2297  const char *env_wait;
2298  int wait_seconds;
2299 
2300  /*
2301  * Prepare the temp instance
2302  */
2303 
2305  {
2306  if (!rmtree(temp_instance, true))
2307  {
2308  bail("could not remove temp instance \"%s\"", temp_instance);
2309  }
2310  }
2311 
2312  /* make the temp instance top directory */
2314 
2315  /* and a directory for log files */
2316  snprintf(buf, sizeof(buf), "%s/log", outputdir);
2317  if (!directory_exists(buf))
2319 
2320  /* initdb */
2321  snprintf(buf, sizeof(buf),
2322  "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync%s%s > \"%s/log/initdb.log\" 2>&1",
2323  bindir ? bindir : "",
2324  bindir ? "/" : "",
2325  temp_instance,
2326  debug ? " --debug" : "",
2327  nolocale ? " --no-locale" : "",
2328  outputdir);
2329  fflush(NULL);
2330  if (system(buf))
2331  {
2332  bail("initdb failed\n"
2333  "# Examine \"%s/log/initdb.log\" for the reason.\n"
2334  "# Command was: %s",
2335  outputdir, buf);
2336  }
2337 
2338  /*
2339  * Adjust the default postgresql.conf for regression testing. The user
2340  * can specify a file to be appended; in any case we expand logging
2341  * and set max_prepared_transactions to enable testing of prepared
2342  * xacts. (Note: to reduce the probability of unexpected shmmax
2343  * failures, don't set max_prepared_transactions any higher than
2344  * actually needed by the prepared_xacts regression test.)
2345  */
2346  snprintf(buf, sizeof(buf), "%s/data/postgresql.conf", temp_instance);
2347  pg_conf = fopen(buf, "a");
2348  if (pg_conf == NULL)
2349  {
2350  bail("could not open \"%s\" for adding extra config: %s",
2351  buf, strerror(errno));
2352  }
2353  fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
2354  fputs("log_autovacuum_min_duration = 0\n", pg_conf);
2355  fputs("log_checkpoints = on\n", pg_conf);
2356  fputs("log_line_prefix = '%m %b[%p] %q%a '\n", pg_conf);
2357  fputs("log_lock_waits = on\n", pg_conf);
2358  fputs("log_temp_files = 128kB\n", pg_conf);
2359  fputs("max_prepared_transactions = 2\n", pg_conf);
2360 
2361  for (sl = temp_configs; sl != NULL; sl = sl->next)
2362  {
2363  char *temp_config = sl->str;
2364  FILE *extra_conf;
2365  char line_buf[1024];
2366 
2367  extra_conf = fopen(temp_config, "r");
2368  if (extra_conf == NULL)
2369  {
2370  bail("could not open \"%s\" to read extra config: %s",
2371  temp_config, strerror(errno));
2372  }
2373  while (fgets(line_buf, sizeof(line_buf), extra_conf) != NULL)
2374  fputs(line_buf, pg_conf);
2375  fclose(extra_conf);
2376  }
2377 
2378  fclose(pg_conf);
2379 
2380 #ifdef ENABLE_SSPI
2381  if (!use_unix_sockets)
2382  {
2383  /*
2384  * Since we successfully used the same buffer for the much-longer
2385  * "initdb" command, this can't truncate.
2386  */
2387  snprintf(buf, sizeof(buf), "%s/data", temp_instance);
2388  config_sspi_auth(buf, NULL);
2389  }
2390 #endif
2391 
2392  /*
2393  * Check if there is a postmaster running already.
2394  */
2395  snprintf(buf2, sizeof(buf2),
2396  "\"%s%spsql\" -X postgres <%s 2>%s",
2397  bindir ? bindir : "",
2398  bindir ? "/" : "",
2399  DEVNULL, DEVNULL);
2400 
2401  for (i = 0; i < 16; i++)
2402  {
2403  fflush(NULL);
2404  if (system(buf2) == 0)
2405  {
2406  char s[16];
2407 
2408  if (port_specified_by_user || i == 15)
2409  {
2410  note("port %d apparently in use", port);
2412  note("could not determine an available port");
2413  bail("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.");
2414  }
2415 
2416  note("port %d apparently in use, trying %d", port, port + 1);
2417  port++;
2418  sprintf(s, "%d", port);
2419  setenv("PGPORT", s, 1);
2420  }
2421  else
2422  break;
2423  }
2424 
2425  /*
2426  * Start the temp postmaster
2427  */
2428  snprintf(buf, sizeof(buf),
2429  "\"%s%spostgres\" -D \"%s/data\" -F%s "
2430  "-c \"listen_addresses=%s\" -k \"%s\" "
2431  "> \"%s/log/postmaster.log\" 2>&1",
2432  bindir ? bindir : "",
2433  bindir ? "/" : "",
2434  temp_instance, debug ? " -d 5" : "",
2435  hostname ? hostname : "", sockdir ? sockdir : "",
2436  outputdir);
2438  if (postmaster_pid == INVALID_PID)
2439  bail("could not spawn postmaster: %s", strerror(errno));
2440 
2441  /*
2442  * Wait till postmaster is able to accept connections; normally this
2443  * is only a second or so, but Cygwin is reportedly *much* slower, and
2444  * test builds using Valgrind or similar tools might be too. Hence,
2445  * allow the default timeout of 60 seconds to be overridden from the
2446  * PGCTLTIMEOUT environment variable.
2447  */
2448  env_wait = getenv("PGCTLTIMEOUT");
2449  if (env_wait != NULL)
2450  {
2451  wait_seconds = atoi(env_wait);
2452  if (wait_seconds <= 0)
2453  wait_seconds = 60;
2454  }
2455  else
2456  wait_seconds = 60;
2457 
2458  for (i = 0; i < wait_seconds; i++)
2459  {
2460  /* Done if psql succeeds */
2461  fflush(NULL);
2462  if (system(buf2) == 0)
2463  break;
2464 
2465  /*
2466  * Fail immediately if postmaster has exited
2467  */
2468 #ifndef WIN32
2469  if (waitpid(postmaster_pid, NULL, WNOHANG) == postmaster_pid)
2470 #else
2471  if (WaitForSingleObject(postmaster_pid, 0) == WAIT_OBJECT_0)
2472 #endif
2473  {
2474  bail("postmaster failed, examine \"%s/log/postmaster.log\" for the reason",
2475  outputdir);
2476  }
2477 
2478  pg_usleep(1000000L);
2479  }
2480  if (i >= wait_seconds)
2481  {
2482  diag("postmaster did not respond within %d seconds, examine \"%s/log/postmaster.log\" for the reason",
2484 
2485  /*
2486  * If we get here, the postmaster is probably wedged somewhere in
2487  * startup. Try to kill it ungracefully rather than leaving a
2488  * stuck postmaster that might interfere with subsequent test
2489  * attempts.
2490  */
2491 #ifndef WIN32
2492  if (kill(postmaster_pid, SIGKILL) != 0 && errno != ESRCH)
2493  bail("could not kill failed postmaster: %s", strerror(errno));
2494 #else
2495  if (TerminateProcess(postmaster_pid, 255) == 0)
2496  bail("could not kill failed postmaster: error code %lu",
2497  GetLastError());
2498 #endif
2499  bail("postmaster failed");
2500  }
2501 
2502  postmaster_running = true;
2503 
2504 #ifdef _WIN64
2505 /* need a series of two casts to convert HANDLE without compiler warning */
2506 #define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2507 #else
2508 #define ULONGPID(x) (unsigned long) (x)
2509 #endif
2510  note("using temp instance on port %d with PID %lu",
2512  }
2513  else
2514  {
2515  /*
2516  * Using an existing installation, so may need to get rid of
2517  * pre-existing database(s) and role(s)
2518  */
2519  if (!use_existing)
2520  {
2521  for (sl = dblist; sl; sl = sl->next)
2523  for (sl = extraroles; sl; sl = sl->next)
2524  drop_role_if_exists(sl->str);
2525  }
2526  }
2527 
2528  /*
2529  * Create the test database(s) and role(s)
2530  */
2531  if (!use_existing)
2532  {
2533  for (sl = dblist; sl; sl = sl->next)
2534  create_database(sl->str);
2535  for (sl = extraroles; sl; sl = sl->next)
2536  create_role(sl->str, dblist);
2537  }
2538 
2539  /*
2540  * Ready to run the tests
2541  */
2542  for (sl = schedulelist; sl != NULL; sl = sl->next)
2543  {
2544  run_schedule(sl->str, startfunc, postfunc);
2545  }
2546 
2547  for (sl = extra_tests; sl != NULL; sl = sl->next)
2548  {
2549  run_single_test(sl->str, startfunc, postfunc);
2550  }
2551 
2552  /*
2553  * Shut down temp installation's postmaster
2554  */
2555  if (temp_instance)
2556  {
2557  stop_postmaster();
2558  }
2559 
2560  /*
2561  * If there were no errors, remove the temp instance immediately to
2562  * conserve disk space. (If there were errors, we leave the instance in
2563  * place for possible manual investigation.)
2564  */
2565  if (temp_instance && fail_count == 0)
2566  {
2567  if (!rmtree(temp_instance, true))
2568  diag("could not remove temp instance \"%s\"",
2569  temp_instance);
2570  }
2571 
2572  /*
2573  * Emit a TAP compliant Plan
2574  */
2576 
2577  /*
2578  * Emit nice-looking summary message
2579  */
2580  if (fail_count == 0)
2581  note("All %d tests passed.", success_count);
2582  else
2583  diag("%d of %d tests failed.", fail_count, success_count + fail_count);
2584 
2585  if (file_size(difffilename) > 0)
2586  {
2587  diag("The differences that caused some tests to fail can be viewed in the file \"%s\".",
2588  difffilename);
2589  diag("A copy of the test summary that you see above is saved in the file \"%s\".",
2590  logfilename);
2591  }
2592  else
2593  {
2594  unlink(difffilename);
2595  unlink(logfilename);
2596  }
2597 
2598  fclose(logfile);
2599  logfile = NULL;
2600 
2601  if (fail_count != 0)
2602  exit(1);
2603 
2604  return 0;
2605 }
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1222
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:436
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
#define no_argument
Definition: getopt_long.h:24
#define required_argument
Definition: getopt_long.h:25
return true
Definition: isn.c:126
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:75
PGDLLIMPORT int optind
Definition: getopt.c:50
PGDLLIMPORT char * optarg
Definition: getopt.c:52
#define plan(x)
Definition: pg_regress.c:154
static bool use_existing
Definition: pg_regress.c:107
static void open_result_files(void)
Definition: pg_regress.c:1915
static int max_connections
Definition: pg_regress.c:99
static bool port_specified_by_user
Definition: pg_regress.c:110
static void stop_postmaster(void)
Definition: pg_regress.c:412
static int max_concurrent_tests
Definition: pg_regress.c:100
static void create_database(const char *dbname)
Definition: pg_regress.c:1964
static void drop_role_if_exists(const char *rolename)
Definition: pg_regress.c:1998
bool debug
Definition: pg_regress.c:92
static void unlimit_core_size(void)
Definition: pg_regress.c:167
static _stringlist * schedulelist
Definition: pg_regress.c:102
static _stringlist * temp_configs
Definition: pg_regress.c:105
static _stringlist * extra_tests
Definition: pg_regress.c:103
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
Definition: pg_regress.c:226
static void run_single_test(const char *test, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:1848
char * launcher
Definition: pg_regress.c:97
const char * pretty_diff_opts
Definition: pg_regress.c:65
char * expecteddir
Definition: pg_regress.c:95
static char * config_auth_datadir
Definition: pg_regress.c:114
static void drop_database_if_exists(const char *dbname)
Definition: pg_regress.c:1953
static void initialize_environment(void)
Definition: pg_regress.c:702
static void help(void)
Definition: pg_regress.c:2023
static long file_size(const char *file)
Definition: pg_regress.c:1253
static bool postmaster_running
Definition: pg_regress.c:131
_stringlist * dblist
Definition: pg_regress.c:91
static _stringlist * extraroles
Definition: pg_regress.c:113
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1189
static void create_role(const char *rolename, const _stringlist *granted_dbs)
Definition: pg_regress.c:2009
static void run_schedule(const char *schedule, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:1639
void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:190
static int success_count
Definition: pg_regress.c:133
#define ULONGPID(x)
static int fail_count
Definition: pg_regress.c:134
static PID_TYPE postmaster_pid
Definition: pg_regress.c:130
#define INVALID_PID
Definition: pg_regress.h:15
char * make_absolute_path(const char *path)
Definition: path.c:729
const char * get_progname(const char *argv0)
Definition: path.c:574
#define DEVNULL
Definition: port.h:160
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:495
#define SIGKILL
Definition: win32_port.h:180

References add_stringlist_item(), bail, bindir, buf, config_auth_datadir, create_database(), create_role(), dblist, debug, DEVNULL, 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(), inputdir, INVALID_PID, 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, pg_log_error_hint, pg_logging_init(), pg_strdup(), PG_TEXTDOMAIN, pg_usleep(), plan, port, port_specified_by_user, postmaster_pid, postmaster_running, 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, strerror, success_count, temp_configs, temp_instance, true, ULONGPID, unlimit_core_size(), use_existing, user, and wait_seconds.

Referenced by main().

◆ remove_temp()

static void remove_temp ( void  )
static

Definition at line 447 of file pg_regress.c.

448 {
450  unlink(sockself);
451  unlink(socklock);
452  rmdir(temp_sockdir);
453 }
Assert(fmt[strlen(fmt) - 1] !='\n')

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 1398 of file pg_regress.c.

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

1367 {
1368  int r;
1369 
1370  fflush(NULL);
1371  r = system(cmd);
1372  if (!WIFEXITED(r) || WEXITSTATUS(r) > 1)
1373  {
1374  bail("diff command failed with status %d: %s", r, cmd);
1375  }
1376 #ifdef WIN32
1377 
1378  /*
1379  * On WIN32, if the 'diff' command cannot be found, system() returns 1,
1380  * but produces nothing to stdout, so we check for that here.
1381  */
1382  if (WEXITSTATUS(r) == 1 && file_size(filename) <= 0)
1383  {
1384  bail("diff command not found: %s", cmd);
1385  }
1386 #endif
1387 
1388  return WEXITSTATUS(r);
1389 }
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 1639 of file pg_regress.c.

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

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

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 459 of file pg_regress.c.

460 {
461  remove_temp();
462 
463  pqsignal(postgres_signal_arg, SIG_DFL);
464  raise(postgres_signal_arg);
465 }
#define SIG_DFL
Definition: win32_port.h:171

References pqsignal(), remove_temp(), and SIG_DFL.

Referenced by make_temp_sockdir().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1189 of file pg_regress.c.

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

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

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 226 of file pg_regress.c.

227 {
228  char *sc = pg_strdup(s);
229  char *token = strtok(sc, delim);
230 
231  while (token)
232  {
233  add_stringlist_item(listhead, token);
234  token = strtok(NULL, delim);
235  }
236  free(sc);
237 }
#define token
Definition: indent_globs.h:126

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

Referenced by regression_main().

◆ stop_postmaster()

static void stop_postmaster ( void  )
static

Definition at line 412 of file pg_regress.c.

413 {
414  if (postmaster_running)
415  {
416  /* We use pg_ctl to issue the kill and wait for stop */
417  char buf[MAXPGPATH * 2];
418  int r;
419 
420  snprintf(buf, sizeof(buf),
421  "\"%s%spg_ctl\" stop -D \"%s/data\" -s",
422  bindir ? bindir : "",
423  bindir ? "/" : "",
424  temp_instance);
425  fflush(NULL);
426  r = system(buf);
427  if (r != 0)
428  {
429  /* Not using the normal bail() as we want _exit */
430  bail_noatexit(_("could not stop postmaster: exit code was %d"), r);
431  }
432 
433  postmaster_running = false;
434  }
435 }

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 524 of file pg_regress.c.

525 {
526  while (*str && *pattern)
527  {
528  if (*pattern == '.' && pattern[1] == '*')
529  {
530  pattern += 2;
531  /* Trailing .* matches everything. */
532  if (*pattern == '\0')
533  return true;
534 
535  /*
536  * Otherwise, scan for a text position at which we can match the
537  * rest of the pattern.
538  */
539  while (*str)
540  {
541  /*
542  * Optimization to prevent most recursion: don't recurse
543  * unless first pattern char might match this text char.
544  */
545  if (*str == *pattern || *pattern == '.')
546  {
547  if (string_matches_pattern(str, pattern))
548  return true;
549  }
550 
551  str++;
552  }
553 
554  /*
555  * End of text with no match.
556  */
557  return false;
558  }
559  else if (*pattern != '.' && *str != *pattern)
560  {
561  /*
562  * Not the single-character wildcard and no explicit match? Then
563  * time to quit...
564  */
565  return false;
566  }
567 
568  str++;
569  pattern++;
570  }
571 
572  if (*pattern == '\0')
573  return true; /* end of pattern, so declare match */
574 
575  /* End of input string. Do we have matching pattern remaining? */
576  while (*pattern == '.' && pattern[1] == '*')
577  pattern += 2;
578  if (*pattern == '\0')
579  return true; /* end of pattern, so declare match */
580 
581  return false;
582 }

References generate_unaccent_rules::str.

Referenced by load_resultmap().

◆ test_status_failed()

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

Definition at line 302 of file pg_regress.c.

303 {
304  /*
305  * Save failed tests in a buffer such that we can print a summary at the
306  * end with diag() to ensure it's shown even under test harnesses.
307  */
308  if (!failed_tests)
310  else
312 
313  appendStringInfo(failed_tests, " %s", testname);
314 
315  fail_count++;
316 
317  test_status_print(false, testname, runtime, parallel);
318 }
static StringInfo failed_tests
Definition: pg_regress.c:125
static void test_status_print(bool ok, const char *testname, double runtime, bool parallel)
Definition: pg_regress.c:271

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 294 of file pg_regress.c.

295 {
296  success_count++;
297 
298  test_status_print(true, testname, runtime, parallel);
299 }

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 271 of file pg_regress.c.

272 {
273  int testnumber = fail_count + success_count;
274 
275  /*
276  * Testnumbers are padded to 5 characters to ensure that testnames align
277  * vertically (assuming at most 9999 tests). Testnames are prefixed with
278  * a leading character to indicate being run in parallel or not. A leading
279  * '+' indicates a parallel test, '-' indicates a single test.
280  */
281  emit_tap_output(TEST_STATUS, "%sok %-5i%*s %c %-*s %8.0f ms",
282  (ok ? "" : "not "),
283  testnumber,
284  /* If ok, indent with four spaces matching "not " */
285  (ok ? (int) strlen("not ") : 0), "",
286  /* Prefix a parallel test '+' and a single test with '-' */
287  (parallel ? '+' : '-'),
288  /* Testnames are padded to align runtimes */
289  TESTNAME_WIDTH, testname,
290  runtime);
291 }
static void static void emit_tap_output(TAPtype type, const char *fmt,...) pg_attribute_printf(2
Definition: pg_regress.c:322
#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 167 of file pg_regress.c.

168 {
169  struct rlimit lim;
170 
171  getrlimit(RLIMIT_CORE, &lim);
172  if (lim.rlim_max == 0)
173  {
174  diag("could not set core size: disallowed by hard limit");
175  return;
176  }
177  else if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
178  {
179  lim.rlim_cur = lim.rlim_max;
180  setrlimit(RLIMIT_CORE, &lim);
181  }
182 }

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 1547 of file pg_regress.c.

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

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

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

Definition at line 96 of file pg_regress.c.

Referenced by psql_start_command(), psql_start_test(), regression_main(), and stop_postmaster().

◆ config_auth_datadir

char* config_auth_datadir = NULL
static

Definition at line 114 of file pg_regress.c.

Referenced by regression_main().

◆ dblist

◆ debug

bool debug = false

Definition at line 92 of file pg_regress.c.

Referenced by regression_main().

◆ difffilename

char* difffilename
static

Definition at line 120 of file pg_regress.c.

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

◆ dlpath

char* dlpath = PKGLIBDIR
static

Definition at line 111 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

◆ encoding

char* encoding = NULL
static

Definition at line 101 of file pg_regress.c.

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

◆ expecteddir

char* expecteddir = "."

Definition at line 95 of file pg_regress.c.

Referenced by ecpg_start_test(), and regression_main().

◆ extra_tests

_stringlist* extra_tests = NULL
static

Definition at line 103 of file pg_regress.c.

Referenced by regression_main().

◆ extraroles

_stringlist* extraroles = NULL
static

Definition at line 113 of file pg_regress.c.

Referenced by regression_main().

◆ fail_count

int fail_count = 0
static

Definition at line 134 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 125 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 126 of file pg_regress.c.

Referenced by emit_tap_output_v().

◆ inputdir

◆ launcher

char* launcher = NULL

Definition at line 97 of file pg_regress.c.

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

◆ loadextension

_stringlist* loadextension = NULL
static

Definition at line 98 of file pg_regress.c.

Referenced by create_database(), and regression_main().

◆ logfile

FILE* logfile
static

◆ logfilename

char* logfilename
static

Definition at line 118 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 100 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

◆ max_connections

int max_connections = 0
static

Definition at line 99 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

◆ nolocale

bool nolocale = false
static

Definition at line 106 of file pg_regress.c.

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

◆ outputdir

◆ port

int port = -1
static

Definition at line 109 of file pg_regress.c.

Referenced by auth_delay_checks(), auth_failed(), auth_peer(), BackendInitialize(), BackendRun(), BackendStartup(), 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_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(), ConnCreate(), ConnFree(), 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(), my_SSL_set_fd(), passwordFromFile(), PerformAuthentication(), PerformRadiusTransaction(), pq_getkeepalivescount(), pq_getkeepalivesidle(), pq_getkeepalivesinterval(), pq_gettcpusertimeout(), pq_setkeepalivescount(), pq_setkeepalivesidle(), pq_setkeepalivesinterval(), pq_settcpusertimeout(), process_startup_options(), ProcessStartupPacket(), read_or_wait(), regression_main(), report_fork_failure_to_client(), 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(), ServerLoop(), set_authn_id(), and StreamConnection().

◆ port_specified_by_user

bool port_specified_by_user = false
static

Definition at line 110 of file pg_regress.c.

Referenced by regression_main().

◆ postmaster_pid

PID_TYPE postmaster_pid = INVALID_PID
static

Definition at line 130 of file pg_regress.c.

Referenced by regression_main().

◆ postmaster_running

bool postmaster_running = false
static

Definition at line 131 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 117 of file pg_regress.c.

Referenced by help(), and regression_main().

◆ resultmap

_resultmap* resultmap = NULL
static

Definition at line 128 of file pg_regress.c.

Referenced by get_expectfile(), and load_resultmap().

◆ schedulelist

_stringlist* schedulelist = NULL
static

Definition at line 102 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 121 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

◆ socklock

char socklock[MAXPGPATH]
static

Definition at line 124 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ sockself

char sockself[MAXPGPATH]
static

Definition at line 123 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ success_count

int success_count = 0
static

Definition at line 133 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 105 of file pg_regress.c.

Referenced by regression_main().

◆ temp_instance

char* temp_instance = NULL
static

Definition at line 104 of file pg_regress.c.

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

◆ temp_sockdir

const char* temp_sockdir
static

Definition at line 122 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ use_existing

bool use_existing = false
static

Definition at line 107 of file pg_regress.c.

Referenced by regression_main().

◆ user