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:1112

Definition at line 1183 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
char * str
Definition: initdb.c:92
struct _stringlist * next
Definition: initdb.c:93

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

Referenced by regression_main(), and split_to_stringlist().

◆ bail_out()

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

Definition at line 254 of file pg_regress.c.

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

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

1970 {
1972  _stringlist *sl;
1973 
1974  /*
1975  * We use template0 so that any installation-local cruft in template1 will
1976  * not mess up the tests.
1977  */
1978  if (encoding)
1979  psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0 ENCODING='%s'%s", dbname, encoding,
1980  (nolocale) ? " LOCALE='C'" : "");
1981  else
1982  psql_add_command(buf, "CREATE DATABASE \"%s\" TEMPLATE=template0%s", dbname,
1983  (nolocale) ? " LOCALE='C'" : "");
1985  "ALTER DATABASE \"%s\" SET lc_messages TO 'C';"
1986  "ALTER DATABASE \"%s\" SET lc_monetary TO 'C';"
1987  "ALTER DATABASE \"%s\" SET lc_numeric TO 'C';"
1988  "ALTER DATABASE \"%s\" SET lc_time TO 'C';"
1989  "ALTER DATABASE \"%s\" SET bytea_output TO 'hex';"
1990  "ALTER DATABASE \"%s\" SET timezone_abbreviations TO 'Default';",
1992  psql_end_command(buf, "postgres");
1993 
1994  /*
1995  * Install any requested extensions. We use CREATE IF NOT EXISTS so that
1996  * this will work whether or not the extension is preinstalled.
1997  */
1998  for (sl = loadextension; sl != NULL; sl = sl->next)
1999  psql_command(dbname, "CREATE EXTENSION IF NOT EXISTS \"%s\"", sl->str);
2000 }
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:1124
static void static void psql_end_command(StringInfo buf, const char *database)
Definition: pg_regress.c:1161
static _stringlist * loadextension
Definition: pg_regress.c:105
static char * encoding
Definition: pg_regress.c:108
#define psql_command(database,...)
Definition: pg_regress.c:1183
static char * buf
Definition: pg_test_fsync.c:73
char * dbname
Definition: streamutil.c:51

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

Referenced by regression_main().

◆ create_role()

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

Definition at line 2014 of file pg_regress.c.

2015 {
2017 
2018  psql_add_command(buf, "CREATE ROLE \"%s\" WITH LOGIN", rolename);
2019  for (; granted_dbs != NULL; granted_dbs = granted_dbs->next)
2020  {
2021  psql_add_command(buf, "GRANT ALL ON DATABASE \"%s\" TO \"%s\"",
2022  granted_dbs->str, rolename);
2023  }
2024  psql_end_command(buf, "postgres");
2025 }

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

1959 {
1961 
1962  /* Set warning level so we don't see chatter about nonexistent DB */
1963  psql_add_command(buf, "SET client_min_messages = warning");
1964  psql_add_command(buf, "DROP DATABASE IF EXISTS \"%s\"", dbname);
1965  psql_end_command(buf, "postgres");
1966 }

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

2004 {
2006 
2007  /* Set warning level so we don't see chatter about nonexistent role */
2008  psql_add_command(buf, "SET client_min_messages = warning");
2009  psql_add_command(buf, "DROP ROLE IF EXISTS \"%s\"", rolename);
2010  psql_end_command(buf, "postgres");
2011 }

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

331 {
332  va_list argp;
333 
334  va_start(argp, fmt);
335  emit_tap_output_v(type, fmt, argp);
336  va_end(argp);
337 }
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 340 of file pg_regress.c.

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

1280 {
1281  int c;
1282  int l = 0;
1283  FILE *f = fopen(file, "r");
1284 
1285  if (!f)
1286  {
1287  diag("could not open file \"%s\" for reading: %s",
1288  file, strerror(errno));
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
#define strerror
Definition: port.h:251
char * c

References diag, and strerror.

Referenced by results_differ().

◆ file_size()

static long file_size ( const char *  file)
static

Definition at line 1258 of file pg_regress.c.

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

References diag, and strerror.

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

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

682 {
683  char *file_type;
684  _resultmap *rm;
685 
686  /*
687  * Determine the file type from the file name. This is just what is
688  * following the last dot in the file name.
689  */
690  if (!file || !(file_type = strrchr(file, '.')))
691  return NULL;
692 
693  file_type++;
694 
695  for (rm = resultmap; rm != NULL; rm = rm->next)
696  {
697  if (strcmp(testname, rm->test) == 0 && strcmp(file_type, rm->type) == 0)
698  {
699  return rm->resultfile;
700  }
701  }
702 
703  return NULL;
704 }
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 2028 of file pg_regress.c.

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

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

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

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

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

Referenced by initialize_environment().

◆ log_child_failure()

static void log_child_failure ( int  exitstatus)
static

Definition at line 1621 of file pg_regress.c.

1622 {
1623  if (WIFEXITED(exitstatus))
1624  diag("(test process exited with exit code %d)",
1625  WEXITSTATUS(exitstatus));
1626  else if (WIFSIGNALED(exitstatus))
1627  {
1628 #if defined(WIN32)
1629  diag("(test process was terminated by exception 0x%X)",
1630  WTERMSIG(exitstatus));
1631 #else
1632  diag("(test process was terminated by signal %d: %s)",
1633  WTERMSIG(exitstatus), pg_strsignal(WTERMSIG(exitstatus)));
1634 #endif
1635  }
1636  else
1637  diag("(test process exited with unrecognized status %d)", exitstatus);
1638 }
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  {
1329  bail("could not create directory \"%s\": %s", dir, strerror(errno));
1330  }
1331 }
#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, S_IRWXU, and strerror.

Referenced by open_result_files(), and regression_main().

◆ make_temp_sockdir()

static const char* make_temp_sockdir ( void  )
static

Definition at line 488 of file pg_regress.c.

489 {
490  char *template = psprintf("%s/pg_regress-XXXXXX",
491  getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
492 
493  temp_sockdir = mkdtemp(template);
494  if (temp_sockdir == NULL)
495  {
496  bail("could not create directory \"%s\": %s",
497  template, strerror(errno));
498  }
499 
500  /* Stage file names for remove_temp(). Unsafe in a signal handler. */
502  snprintf(socklock, sizeof(socklock), "%s.lock", sockself);
503 
504  /* Remove the directory during clean exit. */
505  atexit(remove_temp);
506 
507  /*
508  * Remove the directory before dying to the usual signals. Omit SIGQUIT,
509  * preserving it as a quick, untidy exit.
510  */
512  pqsignal(SIGINT, signal_remove_temp);
514  pqsignal(SIGTERM, signal_remove_temp);
515 
516  return temp_sockdir;
517 }
static void signal_remove_temp(SIGNAL_ARGS)
Definition: pg_regress.c:467
static void remove_temp(void)
Definition: pg_regress.c:455
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, strerror, temp_sockdir, and UNIXSOCK_PATH.

Referenced by initialize_environment().

◆ open_result_files()

static void open_result_files ( void  )
static

Definition at line 1920 of file pg_regress.c.

1921 {
1922  char file[MAXPGPATH];
1923  FILE *difffile;
1924 
1925  /* create outputdir directory if not present */
1928 
1929  /* create the log file (copy of running status output) */
1930  snprintf(file, sizeof(file), "%s/regression.out", outputdir);
1931  logfilename = pg_strdup(file);
1932  logfile = fopen(logfilename, "w");
1933  if (!logfile)
1934  {
1935  bail("could not open file \"%s\" for writing: %s",
1936  logfilename, strerror(errno));
1937  }
1938 
1939  /* create the diffs file as empty */
1940  snprintf(file, sizeof(file), "%s/regression.diffs", outputdir);
1941  difffilename = pg_strdup(file);
1942  difffile = fopen(difffilename, "w");
1943  if (!difffile)
1944  {
1945  bail("could not open file \"%s\" for writing: %s",
1946  difffilename, strerror(errno));
1947  }
1948  /* we don't keep the diffs file open continuously */
1949  fclose(difffile);
1950 
1951  /* also create the results directory if not present */
1952  snprintf(file, sizeof(file), "%s/results", outputdir);
1953  if (!directory_exists(file))
1954  make_directory(file);
1955 }
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(), snprintf, and strerror.

Referenced by regression_main().

◆ psql_add_command()

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

Definition at line 1124 of file pg_regress.c.

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

1162 {
1163  /* Add the database name --- assume it needs no extra escaping */
1165  " \"%s\"",
1166  database);
1167 
1168  /* And now we can execute the shell command */
1169  fflush(NULL);
1170  if (system(buf->data) != 0)
1171  {
1172  /* psql probably already reported the error */
1173  bail("command failed: %s", buf->data);
1174  }
1175 
1176  /* Clean up */
1178 }
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 1112 of file pg_regress.c.

1113 {
1115 
1117  "\"%s%spsql\" -X -q",
1118  bindir ? bindir : "",
1119  bindir ? "/" : "");
1120  return buf;
1121 }
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 2078 of file pg_regress.c.

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

456 {
458  unlink(sockself);
459  unlink(socklock);
460  rmdir(temp_sockdir);
461 }
Assert(fmt[strlen(fmt) - 1] !='\n')

References Assert(), socklock, sockself, and temp_sockdir.

Referenced by make_temp_sockdir(), and signal_remove_temp().

◆ results_differ()

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

Definition at line 1403 of file pg_regress.c.

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

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

Referenced by run_schedule(), and run_single_test().

◆ run_diff()

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

Definition at line 1371 of file pg_regress.c.

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

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

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

Referenced by regression_main().

◆ run_single_test()

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

Definition at line 1853 of file pg_regress.c.

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

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

468 {
469  remove_temp();
470 
471  pqsignal(postgres_signal_arg, SIG_DFL);
472  raise(postgres_signal_arg);
473 }
#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 1196 of file pg_regress.c.

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

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

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

◆ split_to_stringlist()

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

Definition at line 234 of file pg_regress.c.

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

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

Referenced by regression_main().

◆ stop_postmaster()

static void stop_postmaster ( void  )
static

Definition at line 420 of file pg_regress.c.

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

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

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

References generate_unaccent_rules::str.

Referenced by load_resultmap().

◆ test_status_failed()

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

Definition at line 310 of file pg_regress.c.

311 {
312  /*
313  * Save failed tests in a buffer such that we can print a summary at the
314  * end with diag() to ensure it's shown even under test harnesses.
315  */
316  if (!failed_tests)
318  else
320 
321  appendStringInfo(failed_tests, " %s", testname);
322 
323  fail_count++;
324 
325  test_status_print(false, testname, runtime, parallel);
326 }
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:279

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

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

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

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

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

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

Referenced by run_schedule(), and run_single_test().

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts = ""

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