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-fe.h"
#include "libpq/pqcomm.h"
#include "pg_config_paths.h"
#include "pg_regress.h"
#include "portability/instr_time.h"
Include dependency graph for pg_regress.c:

Go to the source code of this file.

Data Structures

struct  _resultmap
 

Macros

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

Typedefs

typedef struct _resultmap _resultmap
 
typedef enum TAPtype TAPtype
 

Enumerations

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

Functions

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

Variables

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

Macro Definition Documentation

◆ bail

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

Definition at line 168 of file pg_regress.c.

◆ bail_noatexit

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

Definition at line 167 of file pg_regress.c.

◆ diag

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

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

◆ note_detail

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

Definition at line 164 of file pg_regress.c.

◆ note_end

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

Definition at line 166 of file pg_regress.c.

◆ plan

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

Definition at line 162 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:1114

Definition at line 1185 of file pg_regress.c.

◆ TESTNAME_WIDTH

#define TESTNAME_WIDTH   36

Definition at line 77 of file pg_regress.c.

◆ ULONGPID

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

◆ WAIT_TICKS_PER_SECOND

#define WAIT_TICKS_PER_SECOND   20

Definition at line 83 of file pg_regress.c.

Typedef Documentation

◆ _resultmap

typedef struct _resultmap _resultmap

◆ TAPtype

typedef enum TAPtype TAPtype

Enumeration Type Documentation

◆ TAPtype

enum TAPtype
Enumerator
DIAG 
BAIL 
NOTE 
NOTE_DETAIL 
NOTE_END 
TEST_STATUS 
PLAN 
NONE 

Definition at line 85 of file pg_regress.c.

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

Function Documentation

◆ add_stringlist_item()

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

Definition at line 198 of file pg_regress.c.

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

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

Referenced by regression_main(), and split_to_stringlist().

◆ bail_out()

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

Definition at line 253 of file pg_regress.c.

254 {
255  va_list ap;
256 
257  va_start(ap, fmt);
258  emit_tap_output_v(BAIL, fmt, ap);
259  va_end(ap);
260 
261  if (noatexit)
262  _exit(2);
263 
264  exit(2);
265 }
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:339

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

1955 {
1957  _stringlist *sl;
1958 
1959  /*
1960  * We use template0 so that any installation-local cruft in template1 will
1961  * not mess up the tests.
1962  */
1963  if (encoding)
1964  psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0 ENCODING='%s'%s", dbname, encoding,
1965  (nolocale) ? " LOCALE='C'" : "");
1966  else
1967  psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0%s", dbname,
1968  (nolocale) ? " LOCALE='C'" : "");
1970  "ALTER DATABASE \"%s\" SET lc_messages TO 'C';"
1971  "ALTER DATABASE \"%s\" SET lc_monetary TO 'C';"
1972  "ALTER DATABASE \"%s\" SET lc_numeric TO 'C';"
1973  "ALTER DATABASE \"%s\" SET lc_time TO 'C';"
1974  "ALTER DATABASE \"%s\" SET bytea_output TO 'hex';"
1975  "ALTER DATABASE \"%s\" SET timezone_abbreviations TO 'Default';",
1977  psql_end_command(buf, "postgres");
1978 
1979  /*
1980  * Install any requested extensions. We use CREATE IF NOT EXISTS so that
1981  * this will work whether or not the extension is preinstalled.
1982  */
1983  for (sl = loadextension; sl != NULL; sl = sl->next)
1984  psql_command(dbname, "CREATE EXTENSION IF NOT EXISTS \"%s\"", sl->str);
1985 }
static bool nolocale
Definition: pg_regress.c:113
static void psql_add_command(StringInfo buf, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1126
static void static void psql_end_command(StringInfo buf, const char *database)
Definition: pg_regress.c:1163
static _stringlist * loadextension
Definition: pg_regress.c:105
static char * encoding
Definition: pg_regress.c:108
#define psql_command(database,...)
Definition: pg_regress.c:1185
static char * buf
Definition: pg_test_fsync.c:73
char * dbname
Definition: streamutil.c:52

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

2000 {
2002 
2003  psql_add_command(buf, "CREATE ROLE \"%s\" WITH LOGIN", rolename);
2004  for (; granted_dbs != NULL; granted_dbs = granted_dbs->next)
2005  {
2006  psql_add_command(buf, "GRANT ALL ON DATABASE \"%s\" TO \"%s\"",
2007  granted_dbs->str, rolename);
2008  }
2009  psql_end_command(buf, "postgres");
2010 }

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

1313 {
1314  struct stat st;
1315 
1316  if (stat(dir, &st) != 0)
1317  return false;
1318  if (S_ISDIR(st.st_mode))
1319  return true;
1320  return false;
1321 }
#define stat
Definition: win32_port.h:284
#define S_ISDIR(m)
Definition: win32_port.h:325

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

1944 {
1946 
1947  /* Set warning level so we don't see chatter about nonexistent DB */
1948  psql_add_command(buf, "SET client_min_messages = warning");
1949  psql_add_command(buf, "DROP DATABASE IF EXISTS \"%s\"", dbname);
1950  psql_end_command(buf, "postgres");
1951 }

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

1989 {
1991 
1992  /* Set warning level so we don't see chatter about nonexistent role */
1993  psql_add_command(buf, "SET client_min_messages = warning");
1994  psql_add_command(buf, "DROP ROLE IF EXISTS \"%s\"", rolename);
1995  psql_end_command(buf, "postgres");
1996 }

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

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

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

Referenced by test_status_print().

◆ emit_tap_output_v()

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

Definition at line 339 of file pg_regress.c.

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

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

Referenced by bail_out(), and emit_tap_output().

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1301 of file pg_regress.c.

1302 {
1303  FILE *f = fopen(file, "r");
1304 
1305  if (!f)
1306  return false;
1307  fclose(f);
1308  return true;
1309 }

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

◆ file_line_count()

static int file_line_count ( const char *  file)
static

Definition at line 1280 of file pg_regress.c.

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

References diag.

Referenced by results_differ().

◆ file_size()

static long file_size ( const char *  file)
static

Definition at line 1260 of file pg_regress.c.

1261 {
1262  long r;
1263  FILE *f = fopen(file, "r");
1264 
1265  if (!f)
1266  {
1267  diag("could not open file \"%s\" for reading: %m", file);
1268  return -1;
1269  }
1270  fseek(f, 0, SEEK_END);
1271  r = ftell(f);
1272  fclose(f);
1273  return r;
1274 }

References diag.

Referenced by regression_main(), and run_diff().

◆ free_stringlist()

static void free_stringlist ( _stringlist **  listhead)
static

Definition at line 219 of file pg_regress.c.

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

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

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

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

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

Referenced by results_differ().

◆ help()

static void help ( void  )
static

Definition at line 2013 of file pg_regress.c.

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

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

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

Referenced by regression_main().

◆ load_resultmap()

static void load_resultmap ( void  )
static

Definition at line 614 of file pg_regress.c.

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

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

Referenced by initialize_environment().

◆ log_child_failure()

static void log_child_failure ( int  exitstatus)
static

Definition at line 1614 of file pg_regress.c.

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

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

1326 {
1327  if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
1328  bail("could not create directory \"%s\": %m", dir);
1329 }
#define S_IRWXG
Definition: win32_port.h:310
#define S_IRWXO
Definition: win32_port.h:322
#define mkdir(a, b)
Definition: win32_port.h:80
#define S_IRWXU
Definition: win32_port.h:298

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

Referenced by open_result_files(), and regression_main().

◆ make_temp_sockdir()

static const char* make_temp_sockdir ( void  )
static

Definition at line 499 of file pg_regress.c.

500 {
501  char *template = psprintf("%s/pg_regress-XXXXXX",
502  getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
503 
504  temp_sockdir = mkdtemp(template);
505  if (temp_sockdir == NULL)
506  bail("could not create directory \"%s\": %m", template);
507 
508  /* Stage file names for remove_temp(). Unsafe in a signal handler. */
510  snprintf(socklock, sizeof(socklock), "%s.lock", sockself);
511 
512  /* Remove the directory during clean exit. */
513  atexit(remove_temp);
514 
515  /*
516  * Remove the directory before dying to the usual signals. Omit SIGQUIT,
517  * preserving it as a quick, untidy exit.
518  */
520  pqsignal(SIGINT, signal_remove_temp);
522  pqsignal(SIGTERM, signal_remove_temp);
523 
524  return temp_sockdir;
525 }
static void signal_remove_temp(SIGNAL_ARGS)
Definition: pg_regress.c:478
static void remove_temp(void)
Definition: pg_regress.c:466
static const char * temp_sockdir
Definition: pg_regress.c:130
static char sockself[MAXPGPATH]
Definition: pg_regress.c:131
static char socklock[MAXPGPATH]
Definition: pg_regress.c:132
pqsigfunc pqsignal(int signo, pqsigfunc func)
char * mkdtemp(char *path)
Definition: mkdtemp.c:286
#define UNIXSOCK_PATH(path, port, sockdir)
Definition: pqcomm.h:44
#define SIGHUP
Definition: win32_port.h:168
#define SIGPIPE
Definition: win32_port.h:173

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

Referenced by initialize_environment().

◆ open_result_files()

static void open_result_files ( void  )
static

Definition at line 1910 of file pg_regress.c.

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

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

Referenced by regression_main().

◆ psql_add_command()

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

Definition at line 1126 of file pg_regress.c.

1127 {
1128  StringInfoData cmdbuf;
1129  const char *cmdptr;
1130 
1131  /* Add each command as a -c argument in the psql call */
1132  appendStringInfoString(buf, " -c \"");
1133 
1134  /* Generate the query with insertion of sprintf arguments */
1135  initStringInfo(&cmdbuf);
1136  for (;;)
1137  {
1138  va_list args;
1139  int needed;
1140 
1141  va_start(args, query);
1142  needed = appendStringInfoVA(&cmdbuf, query, args);
1143  va_end(args);
1144  if (needed == 0)
1145  break; /* success */
1146  enlargeStringInfo(&cmdbuf, needed);
1147  }
1148 
1149  /* Now escape any shell double-quote metacharacters */
1150  for (cmdptr = cmdbuf.data; *cmdptr; cmdptr++)
1151  {
1152  if (strchr("\\\"$`", *cmdptr))
1153  appendStringInfoChar(buf, '\\');
1154  appendStringInfoChar(buf, *cmdptr);
1155  }
1156 
1157  appendStringInfoChar(buf, '"');
1158 
1159  pfree(cmdbuf.data);
1160 }
void pfree(void *pointer)
Definition: mcxt.c:1521
int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
Definition: stringinfo.c:139
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:289
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:194
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 1163 of file pg_regress.c.

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

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

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

◆ psql_start_command()

static StringInfo psql_start_command ( void  )
static

Definition at line 1114 of file pg_regress.c.

1115 {
1117 
1119  "\"%s%spsql\" -X -q",
1120  bindir ? bindir : "",
1121  bindir ? "/" : "");
1122  return buf;
1123 }
char * bindir
Definition: pg_regress.c:103
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 2063 of file pg_regress.c.

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

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

Referenced by main().

◆ remove_temp()

static void remove_temp ( void  )
static

Definition at line 466 of file pg_regress.c.

467 {
469  unlink(sockself);
470  unlink(socklock);
471  rmdir(temp_sockdir);
472 }
#define Assert(condition)
Definition: c.h:858

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

1402 {
1403  char expectfile[MAXPGPATH];
1404  char diff[MAXPGPATH];
1405  char cmd[MAXPGPATH * 3];
1406  char best_expect_file[MAXPGPATH];
1407  FILE *difffile;
1408  int best_line_count;
1409  int i;
1410  int l;
1411  const char *platform_expectfile;
1412 
1413  /*
1414  * We can pass either the resultsfile or the expectfile, they should have
1415  * the same type (filename.type) anyway.
1416  */
1417  platform_expectfile = get_expectfile(testname, resultsfile);
1418 
1419  strlcpy(expectfile, default_expectfile, sizeof(expectfile));
1420  if (platform_expectfile)
1421  {
1422  /*
1423  * Replace everything after the last slash in expectfile with what the
1424  * platform_expectfile contains.
1425  */
1426  char *p = strrchr(expectfile, '/');
1427 
1428  if (p)
1429  strcpy(++p, platform_expectfile);
1430  }
1431 
1432  /* Name to use for temporary diff file */
1433  snprintf(diff, sizeof(diff), "%s.diff", resultsfile);
1434 
1435  /* OK, run the diff */
1436  snprintf(cmd, sizeof(cmd),
1437  "diff %s \"%s\" \"%s\" > \"%s\"",
1438  basic_diff_opts, expectfile, resultsfile, diff);
1439 
1440  /* Is the diff file empty? */
1441  if (run_diff(cmd, diff) == 0)
1442  {
1443  unlink(diff);
1444  return false;
1445  }
1446 
1447  /* There may be secondary comparison files that match better */
1448  best_line_count = file_line_count(diff);
1449  strcpy(best_expect_file, expectfile);
1450 
1451  for (i = 0; i <= 9; i++)
1452  {
1453  char *alt_expectfile;
1454 
1455  alt_expectfile = get_alternative_expectfile(expectfile, i);
1456  if (!alt_expectfile)
1457  bail("Unable to check secondary comparison files: %m");
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:1280
bool file_exists(const char *file)
Definition: pg_regress.c:1301
static int run_diff(const char *cmd, const char *filename)
Definition: pg_regress.c:1369
static const char * get_expectfile(const char *testname, const char *file)
Definition: pg_regress.c:688
const char * basic_diff_opts
Definition: pg_regress.c:65
static char * get_alternative_expectfile(const char *expectfile, int i)
Definition: pg_regress.c:1335
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

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

Referenced by run_schedule(), and run_single_test().

◆ run_diff()

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

Definition at line 1369 of file pg_regress.c.

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

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

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

Referenced by regression_main().

◆ run_single_test()

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

Definition at line 1843 of file pg_regress.c.

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

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

479 {
480  remove_temp();
481 
482  pqsignal(postgres_signal_arg, SIG_DFL);
483  raise(postgres_signal_arg);
484 }
#define SIG_DFL
Definition: win32_port.h:163

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

Referenced by make_temp_sockdir().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1198 of file pg_regress.c.

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

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

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

◆ split_to_stringlist()

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

Definition at line 234 of file pg_regress.c.

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

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

Referenced by regression_main().

◆ stop_postmaster()

static void stop_postmaster ( void  )
static

Definition at line 431 of file pg_regress.c.

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

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

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

References str.

Referenced by load_resultmap().

◆ test_status_failed()

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

Definition at line 309 of file pg_regress.c.

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

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

302 {
303  success_count++;
304 
305  test_status_print(true, testname, runtime, parallel);
306 }

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

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

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

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

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  bail("failed to wait for subprocesses: %m");
1571 #else
1572  DWORD exit_status;
1573  int r;
1574 
1575  r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE);
1576  if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left)
1577  {
1578  bail("failed to wait for subprocesses: error code %lu",
1579  GetLastError());
1580  }
1581  p = active_pids[r - WAIT_OBJECT_0];
1582  /* compact the active_pids array */
1583  active_pids[r - WAIT_OBJECT_0] = active_pids[tests_left - 1];
1584 #endif /* WIN32 */
1585 
1586  for (i = 0; i < num_tests; i++)
1587  {
1588  if (p == pids[i])
1589  {
1590 #ifdef WIN32
1591  GetExitCodeProcess(pids[i], &exit_status);
1592  CloseHandle(pids[i]);
1593 #endif
1594  pids[i] = INVALID_PID;
1595  statuses[i] = (int) exit_status;
1596  INSTR_TIME_SET_CURRENT(stoptimes[i]);
1597  if (names)
1598  note_detail(" %s", names[i]);
1599  tests_left--;
1600  break;
1601  }
1602  }
1603  }
1604 
1605 #ifdef WIN32
1606  free(active_pids);
1607 #endif
1608 }

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

Referenced by run_schedule(), and run_single_test().

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts = ""

Definition at line 65 of file pg_regress.c.

Referenced by results_differ().

◆ bindir

char* bindir = PGBINDIR

◆ config_auth_datadir

char* config_auth_datadir = NULL
static

Definition at line 122 of file pg_regress.c.

Referenced by regression_main().

◆ dblist

◆ debug

bool debug = false

Definition at line 99 of file pg_regress.c.

Referenced by regression_main().

◆ difffilename

char* difffilename
static

Definition at line 128 of file pg_regress.c.

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

◆ dlpath

char* dlpath = PKGLIBDIR
static

Definition at line 119 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

◆ encoding

char* encoding = NULL
static

Definition at line 108 of file pg_regress.c.

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

◆ expecteddir

char* expecteddir = "."

Definition at line 102 of file pg_regress.c.

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

◆ extra_tests

_stringlist* extra_tests = NULL
static

Definition at line 110 of file pg_regress.c.

Referenced by regression_main().

◆ extraroles

_stringlist* extraroles = NULL
static

Definition at line 121 of file pg_regress.c.

Referenced by regression_main().

◆ fail_count

int fail_count = 0
static

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

Referenced by test_status_failed().

◆ host_platform

char* host_platform = HOST_TUPLE

Definition at line 53 of file pg_regress.c.

Referenced by load_resultmap().

◆ hostname

char* hostname = NULL
static

◆ in_note

bool in_note = false
static

Definition at line 134 of file pg_regress.c.

Referenced by emit_tap_output_v().

◆ inputdir

◆ launcher

char* launcher = NULL

Definition at line 104 of file pg_regress.c.

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

◆ loadextension

_stringlist* loadextension = NULL
static

Definition at line 105 of file pg_regress.c.

Referenced by create_database(), and regression_main().

◆ logfile

FILE* logfile
static

◆ logfilename

char* logfilename
static

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

Referenced by regression_main(), and run_schedule().

◆ max_connections

int max_connections = 0
static

Definition at line 106 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

◆ nolocale

bool nolocale = false
static

Definition at line 113 of file pg_regress.c.

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

◆ outputdir

◆ port

int port = -1
static

Definition at line 116 of file pg_regress.c.

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

◆ port_specified_by_user

bool port_specified_by_user = false
static

Definition at line 118 of file pg_regress.c.

Referenced by regression_main().

◆ portstr

char portstr[16]
static

Definition at line 117 of file pg_regress.c.

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

◆ postmaster_pid

PID_TYPE postmaster_pid = INVALID_PID
static

Definition at line 138 of file pg_regress.c.

Referenced by regression_main().

◆ postmaster_running

bool postmaster_running = false
static

Definition at line 139 of file pg_regress.c.

Referenced by regression_main(), and stop_postmaster().

◆ pretty_diff_opts

const char* pretty_diff_opts = "-U3"

Definition at line 66 of file pg_regress.c.

Referenced by regression_main(), and results_differ().

◆ progname

const char* progname
static

Definition at line 125 of file pg_regress.c.

Referenced by help(), and regression_main().

◆ resultmap

_resultmap* resultmap = NULL
static

Definition at line 136 of file pg_regress.c.

Referenced by get_expectfile(), and load_resultmap().

◆ schedulelist

_stringlist* schedulelist = NULL
static

Definition at line 109 of file pg_regress.c.

Referenced by regression_main().

◆ shellprog

char* shellprog = SHELLPROG
static

Definition at line 56 of file pg_regress.c.

Referenced by spawn_process().

◆ sockdir

const char* sockdir
static

Definition at line 129 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

◆ socklock

char socklock[MAXPGPATH]
static

Definition at line 132 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ sockself

char sockself[MAXPGPATH]
static

Definition at line 131 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ success_count

int success_count = 0
static

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

Referenced by regression_main().

◆ temp_instance

char* temp_instance = NULL
static

Definition at line 111 of file pg_regress.c.

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

◆ temp_sockdir

const char* temp_sockdir
static

Definition at line 130 of file pg_regress.c.

Referenced by make_temp_sockdir(), and remove_temp().

◆ use_existing

bool use_existing = false
static

Definition at line 114 of file pg_regress.c.

Referenced by regression_main().

◆ user