PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_regress.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include "pg_regress.h"
#include "common/restricted_token.h"
#include "common/username.h"
#include "getopt_long.h"
#include "libpq/pqcomm.h"
#include "pg_config_paths.h"
Include dependency graph for pg_regress.c:

Go to the source code of this file.

Data Structures

struct  _resultmap
 

Macros

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

Typedefs

typedef struct _resultmap _resultmap
 

Functions

static bool directory_exists (const char *dir)
 
static void make_directory (const char *dir)
 
static void header (const char *fmt,...) pg_attribute_printf(1
 
static void static void status (const char *fmt,...) pg_attribute_printf(1
 
static void static void static void psql_command (const char *database, const char *query,...) pg_attribute_printf(2
 
static void static void static
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 status_end (void)
 
static void stop_postmaster (void)
 
static bool string_matches_pattern (const char *str, const char *pattern)
 
void replace_string (char *string, char *replace, char *replacement)
 
static void convert_sourcefiles_in (char *source_subdir, char *dest_dir, char *dest_subdir, char *suffix)
 
static void convert_sourcefiles (void)
 
static void load_resultmap (void)
 
static const char * get_expectfile (const char *testname, const char *file)
 
static void doputenv (const char *var, const char *val)
 
static void initialize_environment (void)
 
 pg_attribute_unused ()
 
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, char **names, int num_tests)
 
static void log_child_failure (int exitstatus)
 
static void run_schedule (const char *schedule, test_function tfunc)
 
static void run_single_test (const char *test, test_function tfunc)
 
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_function tfunc)
 

Variables

char * host_platform = HOST_TUPLE
 
static char * shellprog = SHELLPROG
 
const char * basic_diff_opts = ""
 
const char * pretty_diff_opts = "-C3"
 
_stringlistdblist = NULL
 
bool debug = false
 
char * inputdir = "."
 
char * outputdir = "."
 
char * bindir = PGBINDIR
 
char * launcher = NULL
 
static _stringlistloadlanguage = NULL
 
static _stringlistloadextension = NULL
 
static int max_connections = 0
 
static char * encoding = NULL
 
static _stringlistschedulelist = NULL
 
static _stringlistextra_tests = NULL
 
static char * temp_instance = NULL
 
static _stringlisttemp_configs = NULL
 
static bool nolocale = false
 
static bool use_existing = false
 
static char * hostname = NULL
 
static int port = -1
 
static bool port_specified_by_user = false
 
static char * dlpath = PKGLIBDIR
 
static char * user = NULL
 
static _stringlistextraroles = NULL
 
static char * config_auth_datadir = NULL
 
static const char * progname
 
static char * logfilename
 
static FILE * logfile
 
static char * difffilename
 
static const char * sockdir
 
static _resultmapresultmap = NULL
 
static PID_TYPE postmaster_pid = INVALID_PID
 
static bool postmaster_running = false
 
static int success_count = 0
 
static int fail_count = 0
 
static int fail_ignore_count = 0
 

Macro Definition Documentation

#define MAX_PARALLEL_TESTS   100

Referenced by run_schedule().

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

Referenced by regression_main().

Typedef Documentation

Function Documentation

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

Definition at line 154 of file pg_regress.c.

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

Referenced by ecpg_start_test(), isolation_init(), isolation_start_test(), psql_init(), psql_start_test(), regression_main(), run_schedule(), and split_to_stringlist().

155 {
156  _stringlist *newentry = pg_malloc(sizeof(_stringlist));
157  _stringlist *oldentry;
158 
159  newentry->str = pg_strdup(str);
160  newentry->next = NULL;
161  if (*listhead == NULL)
162  *listhead = newentry;
163  else
164  {
165  for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
166  /* skip */ ;
167  oldentry->next = newentry;
168  }
169 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * str
Definition: pg_regress.h:24
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define NULL
Definition: c.h:229
struct _stringlist * next
Definition: pg_regress.h:25
static void convert_sourcefiles ( void  )
static

Definition at line 581 of file pg_regress.c.

References convert_sourcefiles_in(), and outputdir.

Referenced by initialize_environment().

582 {
583  convert_sourcefiles_in("input", outputdir, "sql", "sql");
584  convert_sourcefiles_in("output", outputdir, "expected", "out");
585 }
char * outputdir
Definition: pg_regress.c:75
static void convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, char *suffix)
Definition: pg_regress.c:462
static void convert_sourcefiles_in ( char *  source_subdir,
char *  dest_dir,
char *  dest_subdir,
char *  suffix 
)
static

Definition at line 462 of file pg_regress.c.

References _, directory_exists(), dlpath, infile(), inputdir, make_directory(), MAXPGPATH, name, outfile, outputdir, pgfnames(), pgfnames_cleanup(), progname, replace_string(), rmtree(), snprintf(), and strerror().

Referenced by convert_sourcefiles().

463 {
464  char testtablespace[MAXPGPATH];
465  char indir[MAXPGPATH];
466  struct stat st;
467  int ret;
468  char **name;
469  char **names;
470  int count = 0;
471 
472  snprintf(indir, MAXPGPATH, "%s/%s", inputdir, source_subdir);
473 
474  /* Check that indir actually exists and is a directory */
475  ret = stat(indir, &st);
476  if (ret != 0 || !S_ISDIR(st.st_mode))
477  {
478  /*
479  * No warning, to avoid noise in tests that do not have these
480  * directories; for example, ecpg, contrib and src/pl.
481  */
482  return;
483  }
484 
485  names = pgfnames(indir);
486  if (!names)
487  /* Error logged in pgfnames */
488  exit(2);
489 
490  snprintf(testtablespace, MAXPGPATH, "%s/testtablespace", outputdir);
491 
492 #ifdef WIN32
493 
494  /*
495  * On Windows only, clean out the test tablespace dir, or create it if it
496  * doesn't exist. On other platforms we expect the Makefile to take care
497  * of that. (We don't migrate that functionality in here because it'd be
498  * harder to cope with platform-specific issues such as SELinux.)
499  *
500  * XXX it would be better if pg_regress.c had nothing at all to do with
501  * testtablespace, and this were handled by a .BAT file or similar on
502  * Windows. See pgsql-hackers discussion of 2008-01-18.
503  */
504  if (directory_exists(testtablespace))
505  if (!rmtree(testtablespace, true))
506  {
507  fprintf(stderr, _("\n%s: could not remove test tablespace \"%s\"\n"),
508  progname, testtablespace);
509  exit(2);
510  }
511  make_directory(testtablespace);
512 #endif
513 
514  /* finally loop on each file and do the replacement */
515  for (name = names; *name; name++)
516  {
517  char srcfile[MAXPGPATH];
518  char destfile[MAXPGPATH];
519  char prefix[MAXPGPATH];
520  FILE *infile,
521  *outfile;
522  char line[1024];
523 
524  /* reject filenames not finishing in ".source" */
525  if (strlen(*name) < 8)
526  continue;
527  if (strcmp(*name + strlen(*name) - 7, ".source") != 0)
528  continue;
529 
530  count++;
531 
532  /* build the full actual paths to open */
533  snprintf(prefix, strlen(*name) - 6, "%s", *name);
534  snprintf(srcfile, MAXPGPATH, "%s/%s", indir, *name);
535  snprintf(destfile, MAXPGPATH, "%s/%s/%s.%s", dest_dir, dest_subdir,
536  prefix, suffix);
537 
538  infile = fopen(srcfile, "r");
539  if (!infile)
540  {
541  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
542  progname, srcfile, strerror(errno));
543  exit(2);
544  }
545  outfile = fopen(destfile, "w");
546  if (!outfile)
547  {
548  fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
549  progname, destfile, strerror(errno));
550  exit(2);
551  }
552  while (fgets(line, sizeof(line), infile))
553  {
554  replace_string(line, "@abs_srcdir@", inputdir);
555  replace_string(line, "@abs_builddir@", outputdir);
556  replace_string(line, "@testtablespace@", testtablespace);
557  replace_string(line, "@libdir@", dlpath);
558  replace_string(line, "@DLSUFFIX@", DLSUFFIX);
559  fputs(line, outfile);
560  }
561  fclose(infile);
562  fclose(outfile);
563  }
564 
565  /*
566  * If we didn't process any files, complain because it probably means
567  * somebody neglected to pass the needed --inputdir argument.
568  */
569  if (count <= 0)
570  {
571  fprintf(stderr, _("%s: no *.source files found in \"%s\"\n"),
572  progname, indir);
573  exit(2);
574  }
575 
576  pgfnames_cleanup(names);
577 }
static bool directory_exists(const char *dir)
Definition: pg_regress.c:1241
char ** pgfnames(const char *path)
Definition: pgfnames.c:31
static const char * progname
Definition: pg_regress.c:97
static void make_directory(const char *dir)
Definition: pg_regress.c:1254
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void replace_string(char *string, char *replace, char *replacement)
Definition: pg_regress.c:440
#define MAXPGPATH
static char * dlpath
Definition: pg_regress.c:91
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:36
char * outputdir
Definition: pg_regress.c:75
char * inputdir
Definition: pg_regress.c:74
static void infile(const char *filename)
Definition: zic.c:1150
void pgfnames_cleanup(char **filenames)
Definition: pgfnames.c:99
const char * name
Definition: encode.c:521
const char * strerror(int errnum)
Definition: strerror.c:19
static char * outfile
#define _(x)
Definition: elog.c:84
static void create_database ( const char *  dbname)
static

Definition at line 1916 of file pg_regress.c.

References _, encoding, header(), _stringlist::next, nolocale, NULL, psql_command(), and _stringlist::str.

Referenced by regression_main().

1917 {
1918  _stringlist *sl;
1919 
1920  /*
1921  * We use template0 so that any installation-local cruft in template1 will
1922  * not mess up the tests.
1923  */
1924  header(_("creating database \"%s\""), dbname);
1925  if (encoding)
1926  psql_command("postgres", "CREATE DATABASE \"%s\" TEMPLATE=template0 ENCODING='%s'%s", dbname, encoding,
1927  (nolocale) ? " LC_COLLATE='C' LC_CTYPE='C'" : "");
1928  else
1929  psql_command("postgres", "CREATE DATABASE \"%s\" TEMPLATE=template0%s", dbname,
1930  (nolocale) ? " LC_COLLATE='C' LC_CTYPE='C'" : "");
1932  "ALTER DATABASE \"%s\" SET lc_messages TO 'C';"
1933  "ALTER DATABASE \"%s\" SET lc_monetary TO 'C';"
1934  "ALTER DATABASE \"%s\" SET lc_numeric TO 'C';"
1935  "ALTER DATABASE \"%s\" SET lc_time TO 'C';"
1936  "ALTER DATABASE \"%s\" SET bytea_output TO 'hex';"
1937  "ALTER DATABASE \"%s\" SET timezone_abbreviations TO 'Default';",
1939 
1940  /*
1941  * Install any requested procedural languages. We use CREATE OR REPLACE
1942  * so that this will work whether or not the language is preinstalled.
1943  */
1944  for (sl = loadlanguage; sl != NULL; sl = sl->next)
1945  {
1946  header(_("installing %s"), sl->str);
1947  psql_command(dbname, "CREATE OR REPLACE LANGUAGE \"%s\"", sl->str);
1948  }
1949 
1950  /*
1951  * Install any requested extensions. We use CREATE IF NOT EXISTS so that
1952  * this will work whether or not the extension is preinstalled.
1953  */
1954  for (sl = loadextension; sl != NULL; sl = sl->next)
1955  {
1956  header(_("installing %s"), sl->str);
1957  psql_command(dbname, "CREATE EXTENSION IF NOT EXISTS \"%s\"", sl->str);
1958  }
1959 }
char * str
Definition: pg_regress.h:24
static char * encoding
Definition: pg_regress.c:81
static _stringlist * loadlanguage
Definition: pg_regress.c:78
static _stringlist * loadextension
Definition: pg_regress.c:79
static void static void static void psql_command(const char *database, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1080
#define NULL
Definition: c.h:229
char * dbname
Definition: streamutil.c:38
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
struct _stringlist * next
Definition: pg_regress.h:25
static bool nolocale
Definition: pg_regress.c:86
#define _(x)
Definition: elog.c:84
static void create_role ( const char *  rolename,
const _stringlist granted_dbs 
)
static

Definition at line 1969 of file pg_regress.c.

References _, header(), _stringlist::next, NULL, psql_command(), and _stringlist::str.

Referenced by regression_main().

1970 {
1971  header(_("creating role \"%s\""), rolename);
1972  psql_command("postgres", "CREATE ROLE \"%s\" WITH LOGIN", rolename);
1973  for (; granted_dbs != NULL; granted_dbs = granted_dbs->next)
1974  {
1975  psql_command("postgres", "GRANT ALL ON DATABASE \"%s\" TO \"%s\"",
1976  granted_dbs->str, rolename);
1977  }
1978 }
char * str
Definition: pg_regress.h:24
static void static void static void psql_command(const char *database, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1080
#define NULL
Definition: c.h:229
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
struct _stringlist * next
Definition: pg_regress.h:25
#define _(x)
Definition: elog.c:84
static bool directory_exists ( const char *  dir)
static

Definition at line 1241 of file pg_regress.c.

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

1242 {
1243  struct stat st;
1244 
1245  if (stat(dir, &st) != 0)
1246  return false;
1247  if (S_ISDIR(st.st_mode))
1248  return true;
1249  return false;
1250 }
static void doputenv ( const char *  var,
const char *  val 
)
static

Definition at line 712 of file pg_regress.c.

References psprintf(), and putenv.

Referenced by initialize_environment(), and regression_main().

713 {
714  char *s;
715 
716  s = psprintf("%s=%s", var, val);
717  putenv(s);
718 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define putenv(x)
Definition: win32.h:411
long val
Definition: informix.c:689
static void drop_database_if_exists ( const char *  dbname)
static

Definition at line 1909 of file pg_regress.c.

References _, header(), and psql_command().

Referenced by regression_main().

1910 {
1911  header(_("dropping database \"%s\""), dbname);
1912  psql_command("postgres", "DROP DATABASE IF EXISTS \"%s\"", dbname);
1913 }
static void static void static void psql_command(const char *database, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1080
char * dbname
Definition: streamutil.c:38
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
#define _(x)
Definition: elog.c:84
static void drop_role_if_exists ( const char *  rolename)
static

Definition at line 1962 of file pg_regress.c.

References _, header(), and psql_command().

Referenced by regression_main().

1963 {
1964  header(_("dropping role \"%s\""), rolename);
1965  psql_command("postgres", "DROP ROLE IF EXISTS \"%s\"", rolename);
1966 }
static void static void static void psql_command(const char *database, const char *query,...) pg_attribute_printf(2
Definition: pg_regress.c:1080
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
#define _(x)
Definition: elog.c:84
bool file_exists ( const char *  file)

Definition at line 1230 of file pg_regress.c.

Referenced by results_differ().

1231 {
1232  FILE *f = fopen(file, "r");
1233 
1234  if (!f)
1235  return false;
1236  fclose(f);
1237  return true;
1238 }
static int file_line_count ( const char *  file)
static

Definition at line 1208 of file pg_regress.c.

References _, progname, and strerror().

Referenced by results_differ().

1209 {
1210  int c;
1211  int l = 0;
1212  FILE *f = fopen(file, "r");
1213 
1214  if (!f)
1215  {
1216  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
1217  progname, file, strerror(errno));
1218  return -1;
1219  }
1220  while ((c = fgetc(f)) != EOF)
1221  {
1222  if (c == '\n')
1223  l++;
1224  }
1225  fclose(f);
1226  return l;
1227 }
static const char * progname
Definition: pg_regress.c:97
char * c
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static long file_size ( const char *  file)
static

Definition at line 1187 of file pg_regress.c.

References _, progname, and strerror().

Referenced by regression_main(), and run_diff().

1188 {
1189  long r;
1190  FILE *f = fopen(file, "r");
1191 
1192  if (!f)
1193  {
1194  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
1195  progname, file, strerror(errno));
1196  return -1;
1197  }
1198  fseek(f, 0, SEEK_END);
1199  r = ftell(f);
1200  fclose(f);
1201  return r;
1202 }
static const char * progname
Definition: pg_regress.c:97
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static void free_stringlist ( _stringlist **  listhead)
static

Definition at line 175 of file pg_regress.c.

References free, and NULL.

Referenced by regression_main(), and run_schedule().

176 {
177  if (listhead == NULL || *listhead == NULL)
178  return;
179  if ((*listhead)->next != NULL)
180  free_stringlist(&((*listhead)->next));
181  free((*listhead)->str);
182  free(*listhead);
183  *listhead = NULL;
184 }
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:175
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static char* get_alternative_expectfile ( const char *  expectfile,
int  i 
)
static

Definition at line 1268 of file pg_regress.c.

References free, malloc, NULL, and snprintf().

Referenced by results_differ().

1269 {
1270  char *last_dot;
1271  int ssize = strlen(expectfile) + 2 + 1;
1272  char *tmp;
1273  char *s;
1274 
1275  if (!(tmp = (char *) malloc(ssize)))
1276  return NULL;
1277 
1278  if (!(s = (char *) malloc(ssize)))
1279  {
1280  free(tmp);
1281  return NULL;
1282  }
1283 
1284  strcpy(tmp, expectfile);
1285  last_dot = strrchr(tmp, '.');
1286  if (!last_dot)
1287  {
1288  free(tmp);
1289  free(s);
1290  return NULL;
1291  }
1292  *last_dot = '\0';
1293  snprintf(s, ssize, "%s_%d.%s", tmp, i, last_dot + 1);
1294  free(tmp);
1295  return s;
1296 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define malloc(a)
Definition: header.h:50
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
int i
static const char* get_expectfile ( const char *  testname,
const char *  file 
)
static

Definition at line 683 of file pg_regress.c.

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

Referenced by results_differ().

684 {
685  char *file_type;
686  _resultmap *rm;
687 
688  /*
689  * Determine the file type from the file name. This is just what is
690  * following the last dot in the file name.
691  */
692  if (!file || !(file_type = strrchr(file, '.')))
693  return NULL;
694 
695  file_type++;
696 
697  for (rm = resultmap; rm != NULL; rm = rm->next)
698  {
699  if (strcmp(testname, rm->test) == 0 && strcmp(file_type, rm->type) == 0)
700  {
701  return rm->resultfile;
702  }
703  }
704 
705  return NULL;
706 }
struct _resultmap * next
Definition: pg_regress.c:46
static _resultmap * resultmap
Definition: pg_regress.c:108
char * test
Definition: pg_regress.c:43
char * type
Definition: pg_regress.c:44
#define NULL
Definition: c.h:229
char * resultfile
Definition: pg_regress.c:45
static void header ( const char *  fmt,
  ... 
)
static

Definition at line 207 of file pg_regress.c.

References vsnprintf().

Referenced by _tarPositionTo(), convertJsonbArray(), convertJsonbObject(), create_database(), create_role(), datumRestore(), datumSerialize(), DecodeMultiInsert(), DecodeXLogTuple(), drop_database_if_exists(), drop_role_if_exists(), ExecHashJoinGetSavedTuple(), pgss_shmem_startup(), printTableAddHeader(), ReceiveTarFile(), refresh_utf8format(), regression_main(), and tar_close().

208 {
209  char tmp[64];
210  va_list ap;
211 
212  va_start(ap, fmt);
213  vsnprintf(tmp, sizeof(tmp), fmt, ap);
214  va_end(ap);
215 
216  fprintf(stdout, "============== %-38s ==============\n", tmp);
217  fflush(stdout);
218 }
int int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
static void help ( void  )
static

Definition at line 1981 of file pg_regress.c.

References _, and progname.

Referenced by regression_main().

1982 {
1983  printf(_("PostgreSQL regression test driver\n"));
1984  printf(_("\n"));
1985  printf(_("Usage:\n %s [OPTION]... [EXTRA-TEST]...\n"), progname);
1986  printf(_("\n"));
1987  printf(_("Options:\n"));
1988  printf(_(" --config-auth=DATADIR update authentication settings for DATADIR\n"));
1989  printf(_(" --create-role=ROLE create the specified role before testing\n"));
1990  printf(_(" --dbname=DB use database DB (default \"regression\")\n"));
1991  printf(_(" --debug turn on debug mode in programs that are run\n"));
1992  printf(_(" --dlpath=DIR look for dynamic libraries in DIR\n"));
1993  printf(_(" --encoding=ENCODING use ENCODING as the encoding\n"));
1994  printf(_(" --inputdir=DIR take input files from DIR (default \".\")\n"));
1995  printf(_(" --launcher=CMD use CMD as launcher of psql\n"));
1996  printf(_(" --load-extension=EXT load the named extension before running the\n"));
1997  printf(_(" tests; can appear multiple times\n"));
1998  printf(_(" --load-language=LANG load the named language before running the\n"));
1999  printf(_(" tests; can appear multiple times\n"));
2000  printf(_(" --max-connections=N maximum number of concurrent connections\n"));
2001  printf(_(" (default is 0, meaning unlimited)\n"));
2002  printf(_(" --outputdir=DIR place output files in DIR (default \".\")\n"));
2003  printf(_(" --schedule=FILE use test ordering schedule from FILE\n"));
2004  printf(_(" (can be used multiple times to concatenate)\n"));
2005  printf(_(" --temp-instance=DIR create a temporary instance in DIR\n"));
2006  printf(_(" --use-existing use an existing installation\n"));
2007  printf(_("\n"));
2008  printf(_("Options for \"temp-instance\" mode:\n"));
2009  printf(_(" --no-locale use C locale\n"));
2010  printf(_(" --port=PORT start postmaster on PORT\n"));
2011  printf(_(" --temp-config=FILE append contents of FILE to temporary config\n"));
2012  printf(_("\n"));
2013  printf(_("Options for using an existing installation:\n"));
2014  printf(_(" --host=HOST use postmaster running on HOST\n"));
2015  printf(_(" --port=PORT use postmaster running at PORT\n"));
2016  printf(_(" --user=USER connect as USER\n"));
2017  printf(_("\n"));
2018  printf(_("The exit status is 0 if all tests passed, 1 if some tests failed, and 2\n"));
2019  printf(_("if the tests could not be run for some reason.\n"));
2020  printf(_("\n"));
2021  printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
2022 }
static const char * progname
Definition: pg_regress.c:97
#define _(x)
Definition: elog.c:84
static void initialize_environment ( void  )
static

Definition at line 724 of file pg_regress.c.

References _, Assert, convert_sourcefiles(), doputenv(), encoding, hostname, load_resultmap(), nolocale, NULL, pghost, pgport, port, psprintf(), putenv, sockdir, temp_instance, unsetenv, and user.

Referenced by regression_main().

725 {
726  putenv("PGAPPNAME=pg_regress");
727 
728  if (nolocale)
729  {
730  /*
731  * Clear out any non-C locale settings
732  */
733  unsetenv("LC_COLLATE");
734  unsetenv("LC_CTYPE");
735  unsetenv("LC_MONETARY");
736  unsetenv("LC_NUMERIC");
737  unsetenv("LC_TIME");
738  unsetenv("LANG");
739 
740  /*
741  * Most platforms have adopted the POSIX locale as their
742  * implementation-defined default locale. Exceptions include native
743  * Windows, macOS with --enable-nls, and Cygwin with --enable-nls.
744  * (Use of --enable-nls matters because libintl replaces setlocale().)
745  * Also, PostgreSQL does not support macOS with locale environment
746  * variables unset; see PostmasterMain().
747  */
748 #if defined(WIN32) || defined(__CYGWIN__) || defined(__darwin__)
749  putenv("LANG=C");
750 #endif
751  }
752 
753  /*
754  * Set translation-related settings to English; otherwise psql will
755  * produce translated messages and produce diffs. (XXX If we ever support
756  * translation of pg_regress, this needs to be moved elsewhere, where psql
757  * is actually called.)
758  */
759  unsetenv("LANGUAGE");
760  unsetenv("LC_ALL");
761  putenv("LC_MESSAGES=C");
762 
763  /*
764  * Set encoding as requested
765  */
766  if (encoding)
767  doputenv("PGCLIENTENCODING", encoding);
768  else
769  unsetenv("PGCLIENTENCODING");
770 
771  /*
772  * Set timezone and datestyle for datetime-related tests
773  */
774  putenv("PGTZ=PST8PDT");
775  putenv("PGDATESTYLE=Postgres, MDY");
776 
777  /*
778  * Likewise set intervalstyle to ensure consistent results. This is a bit
779  * more painful because we must use PGOPTIONS, and we want to preserve the
780  * user's ability to set other variables through that.
781  */
782  {
783  const char *my_pgoptions = "-c intervalstyle=postgres_verbose";
784  const char *old_pgoptions = getenv("PGOPTIONS");
785  char *new_pgoptions;
786 
787  if (!old_pgoptions)
788  old_pgoptions = "";
789  new_pgoptions = psprintf("PGOPTIONS=%s %s",
790  old_pgoptions, my_pgoptions);
791  putenv(new_pgoptions);
792  }
793 
794  if (temp_instance)
795  {
796  /*
797  * Clear out any environment vars that might cause psql to connect to
798  * the wrong postmaster, or otherwise behave in nondefault ways. (Note
799  * we also use psql's -X switch consistently, so that ~/.psqlrc files
800  * won't mess things up.) Also, set PGPORT to the temp port, and set
801  * PGHOST depending on whether we are using TCP or Unix sockets.
802  */
803  unsetenv("PGDATABASE");
804  unsetenv("PGUSER");
805  unsetenv("PGSERVICE");
806  unsetenv("PGSSLMODE");
807  unsetenv("PGREQUIRESSL");
808  unsetenv("PGCONNECT_TIMEOUT");
809  unsetenv("PGDATA");
810 #ifdef HAVE_UNIX_SOCKETS
811  if (hostname != NULL)
812  doputenv("PGHOST", hostname);
813  else
814  {
815  sockdir = getenv("PG_REGRESS_SOCK_DIR");
816  if (!sockdir)
817  sockdir = make_temp_sockdir();
818  doputenv("PGHOST", sockdir);
819  }
820 #else
821  Assert(hostname != NULL);
822  doputenv("PGHOST", hostname);
823 #endif
824  unsetenv("PGHOSTADDR");
825  if (port != -1)
826  {
827  char s[16];
828 
829  sprintf(s, "%d", port);
830  doputenv("PGPORT", s);
831  }
832  }
833  else
834  {
835  const char *pghost;
836  const char *pgport;
837 
838  /*
839  * When testing an existing install, we honor existing environment
840  * variables, except if they're overridden by command line options.
841  */
842  if (hostname != NULL)
843  {
844  doputenv("PGHOST", hostname);
845  unsetenv("PGHOSTADDR");
846  }
847  if (port != -1)
848  {
849  char s[16];
850 
851  sprintf(s, "%d", port);
852  doputenv("PGPORT", s);
853  }
854  if (user != NULL)
855  doputenv("PGUSER", user);
856 
857  /*
858  * Report what we're connecting to
859  */
860  pghost = getenv("PGHOST");
861  pgport = getenv("PGPORT");
862 #ifndef HAVE_UNIX_SOCKETS
863  if (!pghost)
864  pghost = "localhost";
865 #endif
866 
867  if (pghost && pgport)
868  printf(_("(using postmaster on %s, port %s)\n"), pghost, pgport);
869  if (pghost && !pgport)
870  printf(_("(using postmaster on %s, default port)\n"), pghost);
871  if (!pghost && pgport)
872  printf(_("(using postmaster on Unix socket, port %s)\n"), pgport);
873  if (!pghost && !pgport)
874  printf(_("(using postmaster on Unix socket, default port)\n"));
875  }
876 
878  load_resultmap();
879 }
static const char * sockdir
Definition: pg_regress.c:101
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static char * encoding
Definition: pg_regress.c:81
#define putenv(x)
Definition: win32.h:411
static char * temp_instance
Definition: pg_regress.c:84
static void convert_sourcefiles(void)
Definition: pg_regress.c:581
static int port
Definition: pg_regress.c:89
char * pghost
Definition: pgbench.c:180
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static void load_resultmap(void)
Definition: pg_regress.c:601
#define unsetenv(x)
Definition: win32.h:412
static void doputenv(const char *var, const char *val)
Definition: pg_regress.c:712
static char * user
Definition: pg_regress.c:92
static bool nolocale
Definition: pg_regress.c:86
static char * hostname
Definition: pg_regress.c:88
#define _(x)
Definition: elog.c:84
char * pgport
Definition: pgbench.c:181
static void load_resultmap ( void  )
static

Definition at line 601 of file pg_regress.c.

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

Referenced by initialize_environment().

602 {
603  char buf[MAXPGPATH];
604  FILE *f;
605 
606  /* scan the file ... */
607  snprintf(buf, sizeof(buf), "%s/resultmap", inputdir);
608  f = fopen(buf, "r");
609  if (!f)
610  {
611  /* OK if it doesn't exist, else complain */
612  if (errno == ENOENT)
613  return;
614  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
615  progname, buf, strerror(errno));
616  exit(2);
617  }
618 
619  while (fgets(buf, sizeof(buf), f))
620  {
621  char *platform;
622  char *file_type;
623  char *expected;
624  int i;
625 
626  /* strip trailing whitespace, especially the newline */
627  i = strlen(buf);
628  while (i > 0 && isspace((unsigned char) buf[i - 1]))
629  buf[--i] = '\0';
630 
631  /* parse out the line fields */
632  file_type = strchr(buf, ':');
633  if (!file_type)
634  {
635  fprintf(stderr, _("incorrectly formatted resultmap entry: %s\n"),
636  buf);
637  exit(2);
638  }
639  *file_type++ = '\0';
640 
641  platform = strchr(file_type, ':');
642  if (!platform)
643  {
644  fprintf(stderr, _("incorrectly formatted resultmap entry: %s\n"),
645  buf);
646  exit(2);
647  }
648  *platform++ = '\0';
649  expected = strchr(platform, '=');
650  if (!expected)
651  {
652  fprintf(stderr, _("incorrectly formatted resultmap entry: %s\n"),
653  buf);
654  exit(2);
655  }
656  *expected++ = '\0';
657 
658  /*
659  * if it's for current platform, save it in resultmap list. Note: by
660  * adding at the front of the list, we ensure that in ambiguous cases,
661  * the last match in the resultmap file is used. This mimics the
662  * behavior of the old shell script.
663  */
664  if (string_matches_pattern(host_platform, platform))
665  {
666  _resultmap *entry = pg_malloc(sizeof(_resultmap));
667 
668  entry->test = pg_strdup(buf);
669  entry->type = pg_strdup(file_type);
670  entry->resultfile = pg_strdup(expected);
671  entry->next = resultmap;
672  resultmap = entry;
673  }
674  }
675  fclose(f);
676 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * host_platform
Definition: pg_regress.c:52
static const char * progname
Definition: pg_regress.c:97
struct _resultmap * next
Definition: pg_regress.c:46
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static bool string_matches_pattern(const char *str, const char *pattern)
Definition: pg_regress.c:375
static _resultmap * resultmap
Definition: pg_regress.c:108
#define MAXPGPATH
static char * buf
Definition: pg_test_fsync.c:66
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
char * test
Definition: pg_regress.c:43
char * type
Definition: pg_regress.c:44
char * inputdir
Definition: pg_regress.c:74
char * resultfile
Definition: pg_regress.c:45
int i
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static void log_child_failure ( int  exitstatus)
static

Definition at line 1552 of file pg_regress.c.

References _, status(), WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.

Referenced by run_schedule(), and run_single_test().

1553 {
1554  if (WIFEXITED(exitstatus))
1555  status(_(" (test process exited with exit code %d)"),
1556  WEXITSTATUS(exitstatus));
1557  else if (WIFSIGNALED(exitstatus))
1558  {
1559 #if defined(WIN32)
1560  status(_(" (test process was terminated by exception 0x%X)"),
1561  WTERMSIG(exitstatus));
1562 #elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
1563  status(_(" (test process was terminated by signal %d: %s)"),
1564  WTERMSIG(exitstatus),
1565  WTERMSIG(exitstatus) < NSIG ?
1566  sys_siglist[WTERMSIG(exitstatus)] : "(unknown))");
1567 #else
1568  status(_(" (test process was terminated by signal %d)"),
1569  WTERMSIG(exitstatus));
1570 #endif
1571  }
1572  else
1573  status(_(" (test process exited with unrecognized status %d)"),
1574  exitstatus);
1575 }
#define WIFEXITED(w)
Definition: win32.h:172
#define WIFSIGNALED(w)
Definition: win32.h:173
#define WEXITSTATUS(w)
Definition: win32.h:174
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
#define WTERMSIG(w)
Definition: win32.h:175
#define _(x)
Definition: elog.c:84
static void make_directory ( const char *  dir)
static

Definition at line 1254 of file pg_regress.c.

References _, mkdir, progname, S_IRWXG, S_IRWXO, and strerror().

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

1255 {
1256  if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
1257  {
1258  fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
1259  progname, dir, strerror(errno));
1260  exit(2);
1261  }
1262 }
#define mkdir(a, b)
Definition: win32.h:57
static const char * progname
Definition: pg_regress.c:97
#define S_IRWXO
Definition: win32.h:455
#define S_IRWXG
Definition: win32.h:451
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static void open_result_files ( void  )
static

Definition at line 1869 of file pg_regress.c.

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

Referenced by regression_main().

1870 {
1871  char file[MAXPGPATH];
1872  FILE *difffile;
1873 
1874  /* create outputdir directory if not present */
1877 
1878  /* create the log file (copy of running status output) */
1879  snprintf(file, sizeof(file), "%s/regression.out", outputdir);
1880  logfilename = pg_strdup(file);
1881  logfile = fopen(logfilename, "w");
1882  if (!logfile)
1883  {
1884  fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
1885  progname, logfilename, strerror(errno));
1886  exit(2);
1887  }
1888 
1889  /* create the diffs file as empty */
1890  snprintf(file, sizeof(file), "%s/regression.diffs", outputdir);
1891  difffilename = pg_strdup(file);
1892  difffile = fopen(difffilename, "w");
1893  if (!difffile)
1894  {
1895  fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
1896  progname, difffilename, strerror(errno));
1897  exit(2);
1898  }
1899  /* we don't keep the diffs file open continuously */
1900  fclose(difffile);
1901 
1902  /* also create the results directory if not present */
1903  snprintf(file, sizeof(file), "%s/results", outputdir);
1904  if (!directory_exists(file))
1905  make_directory(file);
1906 }
static bool directory_exists(const char *dir)
Definition: pg_regress.c:1241
static const char * progname
Definition: pg_regress.c:97
static void make_directory(const char *dir)
Definition: pg_regress.c:1254
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static FILE * logfile
Definition: pg_regress.c:99
static char * difffilename
Definition: pg_regress.c:100
#define MAXPGPATH
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
char * outputdir
Definition: pg_regress.c:75
static char * logfilename
Definition: pg_regress.c:98
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
pg_attribute_unused ( )

Definition at line 881 of file pg_regress.c.

References realloc.

884 {
885  static char *ret;
886  const char *rp;
887  char *wp;
888 
889  wp = ret = realloc(ret, 3 + strlen(raw) * 2);
890 
891  *wp++ = '"';
892  for (rp = raw; *rp; rp++)
893  {
894  if (*rp == '"')
895  *wp++ = '"';
896  *wp++ = *rp;
897  }
898  *wp++ = '"';
899  *wp++ = '\0';
900 
901  return ret;
902 }
#define realloc(a, b)
Definition: header.h:60
static void psql_command ( const char *  database,
const char *  query,
  ... 
)
static

Definition at line 1080 of file pg_regress.c.

References _, generate_unaccent_rules::args, bindir, MAXPGPATH, snprintf(), and vsnprintf().

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

1081 {
1082  char query_formatted[1024];
1083  char query_escaped[2048];
1084  char psql_cmd[MAXPGPATH + 2048];
1085  va_list args;
1086  char *s;
1087  char *d;
1088 
1089  /* Generate the query with insertion of sprintf arguments */
1090  va_start(args, query);
1091  vsnprintf(query_formatted, sizeof(query_formatted), query, args);
1092  va_end(args);
1093 
1094  /* Now escape any shell double-quote metacharacters */
1095  d = query_escaped;
1096  for (s = query_formatted; *s; s++)
1097  {
1098  if (strchr("\\\"$`", *s))
1099  *d++ = '\\';
1100  *d++ = *s;
1101  }
1102  *d = '\0';
1103 
1104  /* And now we can build and execute the shell command */
1105  snprintf(psql_cmd, sizeof(psql_cmd),
1106  "\"%s%spsql\" -X -c \"%s\" \"%s\"",
1107  bindir ? bindir : "",
1108  bindir ? "/" : "",
1109  query_escaped,
1110  database);
1111 
1112  if (system(psql_cmd) != 0)
1113  {
1114  /* psql probably already reported the error */
1115  fprintf(stderr, _("command failed: %s\n"), psql_cmd);
1116  exit(2);
1117  }
1118 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
int int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
#define MAXPGPATH
char * bindir
Definition: pg_regress.c:76
#define _(x)
Definition: elog.c:84
int regression_main ( int  argc,
char *  argv[],
init_function  ifunc,
test_function  tfunc 
)

Definition at line 2025 of file pg_regress.c.

References _, add_stringlist_item(), bindir, buf, config_auth_datadir, create_database(), create_role(), debug, DEVNULL, difffilename, directory_exists(), dlpath, doputenv(), drop_database_if_exists(), drop_role_if_exists(), encoding, fail_count, fail_ignore_count, file_size(), free_stringlist(), get_progname(), getopt_long(), header(), help(), hostname, i, initialize_environment(), inputdir, INVALID_PID, launcher, logfile, logfilename, make_absolute_path(), make_directory(), max_connections, MAXPGPATH, _stringlist::next, no_argument, nolocale, NULL, open_result_files(), optarg, optind, outputdir, pg_strdup(), PG_TEXTDOMAIN, pg_usleep(), port, port_specified_by_user, postmaster_pid, postmaster_running, pretty_diff_opts, progname, required_argument, rmtree(), run_schedule(), run_single_test(), set_pglocale_pgservice(), SIGKILL, snprintf(), sockdir, spawn_process(), split_to_stringlist(), stop_postmaster(), _stringlist::str, strerror(), success_count, temp_instance, ULONGPID, unlink(), use_existing, user, and wait_seconds.

Referenced by main().

2026 {
2027  static struct option long_options[] = {
2028  {"help", no_argument, NULL, 'h'},
2029  {"version", no_argument, NULL, 'V'},
2030  {"dbname", required_argument, NULL, 1},
2031  {"debug", no_argument, NULL, 2},
2032  {"inputdir", required_argument, NULL, 3},
2033  {"load-language", required_argument, NULL, 4},
2034  {"max-connections", required_argument, NULL, 5},
2035  {"encoding", required_argument, NULL, 6},
2036  {"outputdir", required_argument, NULL, 7},
2037  {"schedule", required_argument, NULL, 8},
2038  {"temp-instance", required_argument, NULL, 9},
2039  {"no-locale", no_argument, NULL, 10},
2040  {"host", required_argument, NULL, 13},
2041  {"port", required_argument, NULL, 14},
2042  {"user", required_argument, NULL, 15},
2043  {"bindir", required_argument, NULL, 16},
2044  {"dlpath", required_argument, NULL, 17},
2045  {"create-role", required_argument, NULL, 18},
2046  {"temp-config", required_argument, NULL, 19},
2047  {"use-existing", no_argument, NULL, 20},
2048  {"launcher", required_argument, NULL, 21},
2049  {"load-extension", required_argument, NULL, 22},
2050  {"config-auth", required_argument, NULL, 24},
2051  {NULL, 0, NULL, 0}
2052  };
2053 
2054  _stringlist *sl;
2055  int c;
2056  int i;
2057  int option_index;
2058  char buf[MAXPGPATH * 4];
2059  char buf2[MAXPGPATH * 4];
2060 
2061  progname = get_progname(argv[0]);
2062  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_regress"));
2063 
2064  atexit(stop_postmaster);
2065 
2066 #ifndef HAVE_UNIX_SOCKETS
2067  /* no unix domain sockets available, so change default */
2068  hostname = "localhost";
2069 #endif
2070 
2071  /*
2072  * We call the initialization function here because that way we can set
2073  * default parameters and let them be overwritten by the commandline.
2074  */
2075  ifunc(argc, argv);
2076 
2077  if (getenv("PG_REGRESS_DIFF_OPTS"))
2078  pretty_diff_opts = getenv("PG_REGRESS_DIFF_OPTS");
2079 
2080  while ((c = getopt_long(argc, argv, "hV", long_options, &option_index)) != -1)
2081  {
2082  switch (c)
2083  {
2084  case 'h':
2085  help();
2086  exit(0);
2087  case 'V':
2088  puts("pg_regress (PostgreSQL) " PG_VERSION);
2089  exit(0);
2090  case 1:
2091 
2092  /*
2093  * If a default database was specified, we need to remove it
2094  * before we add the specified one.
2095  */
2098  break;
2099  case 2:
2100  debug = true;
2101  break;
2102  case 3:
2104  break;
2105  case 4:
2107  break;
2108  case 5:
2109  max_connections = atoi(optarg);
2110  break;
2111  case 6:
2113  break;
2114  case 7:
2116  break;
2117  case 8:
2119  break;
2120  case 9:
2122  break;
2123  case 10:
2124  nolocale = true;
2125  break;
2126  case 13:
2128  break;
2129  case 14:
2130  port = atoi(optarg);
2131  port_specified_by_user = true;
2132  break;
2133  case 15:
2134  user = pg_strdup(optarg);
2135  break;
2136  case 16:
2137  /* "--bindir=" means to use PATH */
2138  if (strlen(optarg))
2139  bindir = pg_strdup(optarg);
2140  else
2141  bindir = NULL;
2142  break;
2143  case 17:
2144  dlpath = pg_strdup(optarg);
2145  break;
2146  case 18:
2148  break;
2149  case 19:
2151  break;
2152  case 20:
2153  use_existing = true;
2154  break;
2155  case 21:
2157  break;
2158  case 22:
2160  break;
2161  case 24:
2163  break;
2164  default:
2165  /* getopt_long already emitted a complaint */
2166  fprintf(stderr, _("\nTry \"%s -h\" for more information.\n"),
2167  progname);
2168  exit(2);
2169  }
2170  }
2171 
2172  /*
2173  * if we still have arguments, they are extra tests to run
2174  */
2175  while (argc - optind >= 1)
2176  {
2178  optind++;
2179  }
2180 
2181  if (config_auth_datadir)
2182  {
2183 #ifdef ENABLE_SSPI
2184  config_sspi_auth(config_auth_datadir);
2185 #endif
2186  exit(0);
2187  }
2188 
2190 
2191  /*
2192  * To reduce chances of interference with parallel installations, use
2193  * a port number starting in the private range (49152-65535)
2194  * calculated from the version number. This aids !HAVE_UNIX_SOCKETS
2195  * systems; elsewhere, the use of a private socket directory already
2196  * prevents interference.
2197  */
2198  port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2199 
2203 
2204  /*
2205  * Initialization
2206  */
2208 
2210 
2211 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE)
2212  unlimit_core_size();
2213 #endif
2214 
2215  if (temp_instance)
2216  {
2217  FILE *pg_conf;
2218  const char *env_wait;
2219  int wait_seconds;
2220 
2221  /*
2222  * Prepare the temp instance
2223  */
2224 
2226  {
2227  header(_("removing existing temp instance"));
2228  if (!rmtree(temp_instance, true))
2229  {
2230  fprintf(stderr, _("\n%s: could not remove temp instance \"%s\"\n"),
2232  exit(2);
2233  }
2234  }
2235 
2236  header(_("creating temporary instance"));
2237 
2238  /* make the temp instance top directory */
2240 
2241  /* and a directory for log files */
2242  snprintf(buf, sizeof(buf), "%s/log", outputdir);
2243  if (!directory_exists(buf))
2244  make_directory(buf);
2245 
2246  /* initdb */
2247  header(_("initializing database system"));
2248  snprintf(buf, sizeof(buf),
2249  "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync%s%s > \"%s/log/initdb.log\" 2>&1",
2250  bindir ? bindir : "",
2251  bindir ? "/" : "",
2252  temp_instance,
2253  debug ? " --debug" : "",
2254  nolocale ? " --no-locale" : "",
2255  outputdir);
2256  if (system(buf))
2257  {
2258  fprintf(stderr, _("\n%s: initdb failed\nExamine %s/log/initdb.log for the reason.\nCommand was: %s\n"), progname, outputdir, buf);
2259  exit(2);
2260  }
2261 
2262  /*
2263  * Adjust the default postgresql.conf for regression testing. The user
2264  * can specify a file to be appended; in any case we expand logging
2265  * and set max_prepared_transactions to enable testing of prepared
2266  * xacts. (Note: to reduce the probability of unexpected shmmax
2267  * failures, don't set max_prepared_transactions any higher than
2268  * actually needed by the prepared_xacts regression test.)
2269  */
2270  snprintf(buf, sizeof(buf), "%s/data/postgresql.conf", temp_instance);
2271  pg_conf = fopen(buf, "a");
2272  if (pg_conf == NULL)
2273  {
2274  fprintf(stderr, _("\n%s: could not open \"%s\" for adding extra config: %s\n"), progname, buf, strerror(errno));
2275  exit(2);
2276  }
2277  fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
2278  fputs("log_autovacuum_min_duration = 0\n", pg_conf);
2279  fputs("log_checkpoints = on\n", pg_conf);
2280  fputs("log_line_prefix = '%m [%p] %q%a '\n", pg_conf);
2281  fputs("log_lock_waits = on\n", pg_conf);
2282  fputs("log_temp_files = 128kB\n", pg_conf);
2283  fputs("max_prepared_transactions = 2\n", pg_conf);
2284 
2285  for (sl = temp_configs; sl != NULL; sl = sl->next)
2286  {
2287  char *temp_config = sl->str;
2288  FILE *extra_conf;
2289  char line_buf[1024];
2290 
2291  extra_conf = fopen(temp_config, "r");
2292  if (extra_conf == NULL)
2293  {
2294  fprintf(stderr, _("\n%s: could not open \"%s\" to read extra config: %s\n"), progname, temp_config, strerror(errno));
2295  exit(2);
2296  }
2297  while (fgets(line_buf, sizeof(line_buf), extra_conf) != NULL)
2298  fputs(line_buf, pg_conf);
2299  fclose(extra_conf);
2300  }
2301 
2302  fclose(pg_conf);
2303 
2304 #ifdef ENABLE_SSPI
2305 
2306  /*
2307  * Since we successfully used the same buffer for the much-longer
2308  * "initdb" command, this can't truncate.
2309  */
2310  snprintf(buf, sizeof(buf), "%s/data", temp_instance);
2311  config_sspi_auth(buf);
2312 #elif !defined(HAVE_UNIX_SOCKETS)
2313 #error Platform has no means to secure the test installation.
2314 #endif
2315 
2316  /*
2317  * Check if there is a postmaster running already.
2318  */
2319  snprintf(buf2, sizeof(buf2),
2320  "\"%s%spsql\" -X postgres <%s 2>%s",
2321  bindir ? bindir : "",
2322  bindir ? "/" : "",
2323  DEVNULL, DEVNULL);
2324 
2325  for (i = 0; i < 16; i++)
2326  {
2327  if (system(buf2) == 0)
2328  {
2329  char s[16];
2330 
2331  if (port_specified_by_user || i == 15)
2332  {
2333  fprintf(stderr, _("port %d apparently in use\n"), port);
2335  fprintf(stderr, _("%s: could not determine an available port\n"), progname);
2336  fprintf(stderr, _("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.\n"));
2337  exit(2);
2338  }
2339 
2340  fprintf(stderr, _("port %d apparently in use, trying %d\n"), port, port + 1);
2341  port++;
2342  sprintf(s, "%d", port);
2343  doputenv("PGPORT", s);
2344  }
2345  else
2346  break;
2347  }
2348 
2349  /*
2350  * Start the temp postmaster
2351  */
2352  header(_("starting postmaster"));
2353  snprintf(buf, sizeof(buf),
2354  "\"%s%spostgres\" -D \"%s/data\" -F%s "
2355  "-c \"listen_addresses=%s\" -k \"%s\" "
2356  "> \"%s/log/postmaster.log\" 2>&1",
2357  bindir ? bindir : "",
2358  bindir ? "/" : "",
2359  temp_instance, debug ? " -d 5" : "",
2360  hostname ? hostname : "", sockdir ? sockdir : "",
2361  outputdir);
2363  if (postmaster_pid == INVALID_PID)
2364  {
2365  fprintf(stderr, _("\n%s: could not spawn postmaster: %s\n"),
2366  progname, strerror(errno));
2367  exit(2);
2368  }
2369 
2370  /*
2371  * Wait till postmaster is able to accept connections; normally this
2372  * is only a second or so, but Cygwin is reportedly *much* slower, and
2373  * test builds using Valgrind or similar tools might be too. Hence,
2374  * allow the default timeout of 60 seconds to be overridden from the
2375  * PGCTLTIMEOUT environment variable.
2376  */
2377  env_wait = getenv("PGCTLTIMEOUT");
2378  if (env_wait != NULL)
2379  {
2380  wait_seconds = atoi(env_wait);
2381  if (wait_seconds <= 0)
2382  wait_seconds = 60;
2383  }
2384  else
2385  wait_seconds = 60;
2386 
2387  for (i = 0; i < wait_seconds; i++)
2388  {
2389  /* Done if psql succeeds */
2390  if (system(buf2) == 0)
2391  break;
2392 
2393  /*
2394  * Fail immediately if postmaster has exited
2395  */
2396 #ifndef WIN32
2397  if (kill(postmaster_pid, 0) != 0)
2398 #else
2399  if (WaitForSingleObject(postmaster_pid, 0) == WAIT_OBJECT_0)
2400 #endif
2401  {
2402  fprintf(stderr, _("\n%s: postmaster failed\nExamine %s/log/postmaster.log for the reason\n"), progname, outputdir);
2403  exit(2);
2404  }
2405 
2406  pg_usleep(1000000L);
2407  }
2408  if (i >= wait_seconds)
2409  {
2410  fprintf(stderr, _("\n%s: postmaster did not respond within %d seconds\nExamine %s/log/postmaster.log for the reason\n"),
2411  progname, wait_seconds, outputdir);
2412 
2413  /*
2414  * If we get here, the postmaster is probably wedged somewhere in
2415  * startup. Try to kill it ungracefully rather than leaving a
2416  * stuck postmaster that might interfere with subsequent test
2417  * attempts.
2418  */
2419 #ifndef WIN32
2420  if (kill(postmaster_pid, SIGKILL) != 0 &&
2421  errno != ESRCH)
2422  fprintf(stderr, _("\n%s: could not kill failed postmaster: %s\n"),
2423  progname, strerror(errno));
2424 #else
2425  if (TerminateProcess(postmaster_pid, 255) == 0)
2426  fprintf(stderr, _("\n%s: could not kill failed postmaster: error code %lu\n"),
2427  progname, GetLastError());
2428 #endif
2429 
2430  exit(2);
2431  }
2432 
2433  postmaster_running = true;
2434 
2435 #ifdef _WIN64
2436 /* need a series of two casts to convert HANDLE without compiler warning */
2437 #define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2438 #else
2439 #define ULONGPID(x) (unsigned long) (x)
2440 #endif
2441  printf(_("running on port %d with PID %lu\n"),
2443  }
2444  else
2445  {
2446  /*
2447  * Using an existing installation, so may need to get rid of
2448  * pre-existing database(s) and role(s)
2449  */
2450  if (!use_existing)
2451  {
2452  for (sl = dblist; sl; sl = sl->next)
2454  for (sl = extraroles; sl; sl = sl->next)
2455  drop_role_if_exists(sl->str);
2456  }
2457  }
2458 
2459  /*
2460  * Create the test database(s) and role(s)
2461  */
2462  if (!use_existing)
2463  {
2464  for (sl = dblist; sl; sl = sl->next)
2465  create_database(sl->str);
2466  for (sl = extraroles; sl; sl = sl->next)
2467  create_role(sl->str, dblist);
2468  }
2469 
2470  /*
2471  * Ready to run the tests
2472  */
2473  header(_("running regression test queries"));
2474 
2475  for (sl = schedulelist; sl != NULL; sl = sl->next)
2476  {
2477  run_schedule(sl->str, tfunc);
2478  }
2479 
2480  for (sl = extra_tests; sl != NULL; sl = sl->next)
2481  {
2482  run_single_test(sl->str, tfunc);
2483  }
2484 
2485  /*
2486  * Shut down temp installation's postmaster
2487  */
2488  if (temp_instance)
2489  {
2490  header(_("shutting down postmaster"));
2491  stop_postmaster();
2492  }
2493 
2494  /*
2495  * If there were no errors, remove the temp instance immediately to
2496  * conserve disk space. (If there were errors, we leave the instance in
2497  * place for possible manual investigation.)
2498  */
2499  if (temp_instance && fail_count == 0 && fail_ignore_count == 0)
2500  {
2501  header(_("removing temporary instance"));
2502  if (!rmtree(temp_instance, true))
2503  fprintf(stderr, _("\n%s: could not remove temp instance \"%s\"\n"),
2505  }
2506 
2507  fclose(logfile);
2508 
2509  /*
2510  * Emit nice-looking summary message
2511  */
2512  if (fail_count == 0 && fail_ignore_count == 0)
2513  snprintf(buf, sizeof(buf),
2514  _(" All %d tests passed. "),
2515  success_count);
2516  else if (fail_count == 0) /* fail_count=0, fail_ignore_count>0 */
2517  snprintf(buf, sizeof(buf),
2518  _(" %d of %d tests passed, %d failed test(s) ignored. "),
2519  success_count,
2522  else if (fail_ignore_count == 0) /* fail_count>0 && fail_ignore_count=0 */
2523  snprintf(buf, sizeof(buf),
2524  _(" %d of %d tests failed. "),
2525  fail_count,
2527  else
2528  /* fail_count>0 && fail_ignore_count>0 */
2529  snprintf(buf, sizeof(buf),
2530  _(" %d of %d tests failed, %d of these failures ignored. "),
2534 
2535  putchar('\n');
2536  for (i = strlen(buf); i > 0; i--)
2537  putchar('=');
2538  printf("\n%s\n", buf);
2539  for (i = strlen(buf); i > 0; i--)
2540  putchar('=');
2541  putchar('\n');
2542  putchar('\n');
2543 
2544  if (file_size(difffilename) > 0)
2545  {
2546  printf(_("The differences that caused some tests to fail can be viewed in the\n"
2547  "file \"%s\". A copy of the test summary that you see\n"
2548  "above is saved in the file \"%s\".\n\n"),
2550  }
2551  else
2552  {
2555  }
2556 
2557  if (fail_count != 0)
2558  exit(1);
2559 
2560  return 0;
2561 }
char * make_absolute_path(const char *path)
Definition: path.c:608
static bool directory_exists(const char *dir)
Definition: pg_regress.c:1241
static void drop_role_if_exists(const char *rolename)
Definition: pg_regress.c:1962
static void drop_database_if_exists(const char *dbname)
Definition: pg_regress.c:1909
static const char * sockdir
Definition: pg_regress.c:101
static int wait_seconds
Definition: pg_ctl.c:72
static _stringlist * extra_tests
Definition: pg_regress.c:83
static void help(void)
Definition: pg_regress.c:1981
char * str
Definition: pg_regress.h:24
static void initialize_environment(void)
Definition: pg_regress.c:724
static void run_single_test(const char *test, test_function tfunc)
Definition: pg_regress.c:1807
bool debug
Definition: pg_regress.c:73
const char * get_progname(const char *argv0)
Definition: path.c:453
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:154
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
static void run_schedule(const char *schedule, test_function tfunc)
Definition: pg_regress.c:1581
static char * encoding
Definition: pg_regress.c:81
static const char * progname
Definition: pg_regress.c:97
static void make_directory(const char *dir)
Definition: pg_regress.c:1254
static bool use_existing
Definition: pg_regress.c:87
static bool postmaster_running
Definition: pg_regress.c:111
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static FILE * logfile
Definition: pg_regress.c:99
static void stop_postmaster(void)
Definition: pg_regress.c:257
static char * temp_instance
Definition: pg_regress.c:84
char * launcher
Definition: pg_regress.c:77
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
Definition: pg_regress.c:190
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:175
static _stringlist * loadlanguage
Definition: pg_regress.c:78
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1126
static char * difffilename
Definition: pg_regress.c:100
void pg_usleep(long microsec)
Definition: signal.c:53
#define required_argument
Definition: getopt_long.h:25
int optind
Definition: getopt.c:51
static _stringlist * loadextension
Definition: pg_regress.c:79
#define MAXPGPATH
_stringlist * dblist
Definition: pg_regress.c:72
static _stringlist * extraroles
Definition: pg_regress.c:93
static _stringlist * temp_configs
Definition: pg_regress.c:85
char * c
const char * pretty_diff_opts
Definition: pg_regress.c:65
static char * buf
Definition: pg_test_fsync.c:66
#define INVALID_PID
Definition: pg_regress.h:15
static void create_role(const char *rolename, const _stringlist *granted_dbs)
Definition: pg_regress.c:1969
static char * dlpath
Definition: pg_regress.c:91
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int success_count
Definition: pg_regress.c:113
#define DEVNULL
Definition: port.h:116
int unlink(const char *filename)
static int max_connections
Definition: pg_regress.c:80
static int port
Definition: pg_regress.c:89
static PID_TYPE postmaster_pid
Definition: pg_regress.c:110
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:36
#define no_argument
Definition: getopt_long.h:24
static char * config_auth_datadir
Definition: pg_regress.c:94
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1012
static int fail_ignore_count
Definition: pg_regress.c:115
static int fail_count
Definition: pg_regress.c:114
char * outputdir
Definition: pg_regress.c:75
static char * logfilename
Definition: pg_regress.c:98
char * inputdir
Definition: pg_regress.c:74
static long file_size(const char *file)
Definition: pg_regress.c:1187
#define NULL
Definition: c.h:229
static bool port_specified_by_user
Definition: pg_regress.c:90
char * bindir
Definition: pg_regress.c:76
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
static void doputenv(const char *var, const char *val)
Definition: pg_regress.c:712
static char * user
Definition: pg_regress.c:92
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:550
char * optarg
Definition: getopt.c:53
static _stringlist * schedulelist
Definition: pg_regress.c:82
struct _stringlist * next
Definition: pg_regress.h:25
int i
const char * strerror(int errnum)
Definition: strerror.c:19
static bool nolocale
Definition: pg_regress.c:86
static void open_result_files(void)
Definition: pg_regress.c:1869
#define SIGKILL
Definition: win32.h:192
static char * hostname
Definition: pg_regress.c:88
#define _(x)
Definition: elog.c:84
#define ULONGPID(x)
static void create_database(const char *dbname)
Definition: pg_regress.c:1916
void replace_string ( char *  string,
char *  replace,
char *  replacement 
)

Definition at line 440 of file pg_regress.c.

References free, NULL, pg_strdup(), and strlcpy().

Referenced by convert_sourcefiles_in(), ecpg_filter(), and ecpg_start_test().

441 {
442  char *ptr;
443 
444  while ((ptr = strstr(string, replace)) != NULL)
445  {
446  char *dup = pg_strdup(string);
447 
448  strlcpy(string, dup, ptr - string + 1);
449  strcat(string, replacement);
450  strcat(string, dup + (ptr - string) + strlen(replace));
451  free(dup);
452  }
453 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:229
static bool results_differ ( const char *  testname,
const char *  resultsfile,
const char *  default_expectfile 
)
static

Definition at line 1335 of file pg_regress.c.

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

Referenced by run_schedule(), and run_single_test().

1336 {
1337  char expectfile[MAXPGPATH];
1338  char diff[MAXPGPATH];
1339  char cmd[MAXPGPATH * 3];
1340  char best_expect_file[MAXPGPATH];
1341  FILE *difffile;
1342  int best_line_count;
1343  int i;
1344  int l;
1345  const char *platform_expectfile;
1346 
1347  /*
1348  * We can pass either the resultsfile or the expectfile, they should have
1349  * the same type (filename.type) anyway.
1350  */
1351  platform_expectfile = get_expectfile(testname, resultsfile);
1352 
1353  strlcpy(expectfile, default_expectfile, sizeof(expectfile));
1354  if (platform_expectfile)
1355  {
1356  /*
1357  * Replace everything after the last slash in expectfile with what the
1358  * platform_expectfile contains.
1359  */
1360  char *p = strrchr(expectfile, '/');
1361 
1362  if (p)
1363  strcpy(++p, platform_expectfile);
1364  }
1365 
1366  /* Name to use for temporary diff file */
1367  snprintf(diff, sizeof(diff), "%s.diff", resultsfile);
1368 
1369  /* OK, run the diff */
1370  snprintf(cmd, sizeof(cmd),
1371  "diff %s \"%s\" \"%s\" > \"%s\"",
1372  basic_diff_opts, expectfile, resultsfile, diff);
1373 
1374  /* Is the diff file empty? */
1375  if (run_diff(cmd, diff) == 0)
1376  {
1377  unlink(diff);
1378  return false;
1379  }
1380 
1381  /* There may be secondary comparison files that match better */
1382  best_line_count = file_line_count(diff);
1383  strcpy(best_expect_file, expectfile);
1384 
1385  for (i = 0; i <= 9; i++)
1386  {
1387  char *alt_expectfile;
1388 
1389  alt_expectfile = get_alternative_expectfile(expectfile, i);
1390  if (!alt_expectfile)
1391  {
1392  fprintf(stderr, _("Unable to check secondary comparison files: %s\n"),
1393  strerror(errno));
1394  exit(2);
1395  }
1396 
1397  if (!file_exists(alt_expectfile))
1398  {
1399  free(alt_expectfile);
1400  continue;
1401  }
1402 
1403  snprintf(cmd, sizeof(cmd),
1404  "diff %s \"%s\" \"%s\" > \"%s\"",
1405  basic_diff_opts, alt_expectfile, resultsfile, diff);
1406 
1407  if (run_diff(cmd, diff) == 0)
1408  {
1409  unlink(diff);
1410  free(alt_expectfile);
1411  return false;
1412  }
1413 
1414  l = file_line_count(diff);
1415  if (l < best_line_count)
1416  {
1417  /* This diff was a better match than the last one */
1418  best_line_count = l;
1419  strlcpy(best_expect_file, alt_expectfile, sizeof(best_expect_file));
1420  }
1421  free(alt_expectfile);
1422  }
1423 
1424  /*
1425  * fall back on the canonical results file if we haven't tried it yet and
1426  * haven't found a complete match yet.
1427  */
1428 
1429  if (platform_expectfile)
1430  {
1431  snprintf(cmd, sizeof(cmd),
1432  "diff %s \"%s\" \"%s\" > \"%s\"",
1433  basic_diff_opts, default_expectfile, resultsfile, diff);
1434 
1435  if (run_diff(cmd, diff) == 0)
1436  {
1437  /* No diff = no changes = good */
1438  unlink(diff);
1439  return false;
1440  }
1441 
1442  l = file_line_count(diff);
1443  if (l < best_line_count)
1444  {
1445  /* This diff was a better match than the last one */
1446  best_line_count = l;
1447  strlcpy(best_expect_file, default_expectfile, sizeof(best_expect_file));
1448  }
1449  }
1450 
1451  /*
1452  * Use the best comparison file to generate the "pretty" diff, which we
1453  * append to the diffs summary file.
1454  */
1455  snprintf(cmd, sizeof(cmd),
1456  "diff %s \"%s\" \"%s\" >> \"%s\"",
1457  pretty_diff_opts, best_expect_file, resultsfile, difffilename);
1458  run_diff(cmd, difffilename);
1459 
1460  /* And append a separator */
1461  difffile = fopen(difffilename, "a");
1462  if (difffile)
1463  {
1464  fprintf(difffile,
1465  "\n======================================================================\n\n");
1466  fclose(difffile);
1467  }
1468 
1469  unlink(diff);
1470  return true;
1471 }
static char * get_alternative_expectfile(const char *expectfile, int i)
Definition: pg_regress.c:1268
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static char * difffilename
Definition: pg_regress.c:100
#define MAXPGPATH
const char * pretty_diff_opts
Definition: pg_regress.c:65
static int run_diff(const char *cmd, const char *filename)
Definition: pg_regress.c:1302
int unlink(const char *filename)
#define free(a)
Definition: header.h:65
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static const char * get_expectfile(const char *testname, const char *file)
Definition: pg_regress.c:683
static int file_line_count(const char *file)
Definition: pg_regress.c:1208
bool file_exists(const char *file)
Definition: pg_regress.c:1230
int i
const char * strerror(int errnum)
Definition: strerror.c:19
const char * basic_diff_opts
Definition: pg_regress.c:64
#define _(x)
Definition: elog.c:84
static int run_diff ( const char *  cmd,
const char *  filename 
)
static

Definition at line 1302 of file pg_regress.c.

References _, file_size(), WEXITSTATUS, and WIFEXITED.

Referenced by results_differ().

1303 {
1304  int r;
1305 
1306  r = system(cmd);
1307  if (!WIFEXITED(r) || WEXITSTATUS(r) > 1)
1308  {
1309  fprintf(stderr, _("diff command failed with status %d: %s\n"), r, cmd);
1310  exit(2);
1311  }
1312 #ifdef WIN32
1313 
1314  /*
1315  * On WIN32, if the 'diff' command cannot be found, system() returns 1,
1316  * but produces nothing to stdout, so we check for that here.
1317  */
1318  if (WEXITSTATUS(r) == 1 && file_size(filename) <= 0)
1319  {
1320  fprintf(stderr, _("diff command not found: %s\n"), cmd);
1321  exit(2);
1322  }
1323 #endif
1324 
1325  return WEXITSTATUS(r);
1326 }
#define WIFEXITED(w)
Definition: win32.h:172
static long file_size(const char *file)
Definition: pg_regress.c:1187
#define WEXITSTATUS(w)
Definition: win32.h:174
static char * filename
Definition: pg_dumpall.c:87
#define _(x)
Definition: elog.c:84
static void run_schedule ( const char *  schedule,
test_function  tfunc 
)
static

Definition at line 1581 of file pg_regress.c.

References _, add_stringlist_item(), fail_count, fail_ignore_count, free_stringlist(), i, log_child_failure(), max_connections, MAX_PARALLEL_TESTS, _stringlist::next, NULL, PID_TYPE, progname, results_differ(), status(), status_end(), _stringlist::str, strerror(), success_count, test(), and wait_for_tests().

Referenced by regression_main().

1582 {
1583 #define MAX_PARALLEL_TESTS 100
1584  char *tests[MAX_PARALLEL_TESTS];
1585  _stringlist *resultfiles[MAX_PARALLEL_TESTS];
1586  _stringlist *expectfiles[MAX_PARALLEL_TESTS];
1589  int statuses[MAX_PARALLEL_TESTS];
1590  _stringlist *ignorelist = NULL;
1591  char scbuf[1024];
1592  FILE *scf;
1593  int line_num = 0;
1594 
1595  memset(resultfiles, 0, sizeof(_stringlist *) * MAX_PARALLEL_TESTS);
1596  memset(expectfiles, 0, sizeof(_stringlist *) * MAX_PARALLEL_TESTS);
1597  memset(tags, 0, sizeof(_stringlist *) * MAX_PARALLEL_TESTS);
1598 
1599  scf = fopen(schedule, "r");
1600  if (!scf)
1601  {
1602  fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
1603  progname, schedule, strerror(errno));
1604  exit(2);
1605  }
1606 
1607  while (fgets(scbuf, sizeof(scbuf), scf))
1608  {
1609  char *test = NULL;
1610  char *c;
1611  int num_tests;
1612  bool inword;
1613  int i;
1614 
1615  line_num++;
1616 
1617  for (i = 0; i < MAX_PARALLEL_TESTS; i++)
1618  {
1619  if (resultfiles[i] == NULL)
1620  break;
1621  free_stringlist(&resultfiles[i]);
1622  free_stringlist(&expectfiles[i]);
1623  free_stringlist(&tags[i]);
1624  }
1625 
1626  /* strip trailing whitespace, especially the newline */
1627  i = strlen(scbuf);
1628  while (i > 0 && isspace((unsigned char) scbuf[i - 1]))
1629  scbuf[--i] = '\0';
1630 
1631  if (scbuf[0] == '\0' || scbuf[0] == '#')
1632  continue;
1633  if (strncmp(scbuf, "test: ", 6) == 0)
1634  test = scbuf + 6;
1635  else if (strncmp(scbuf, "ignore: ", 8) == 0)
1636  {
1637  c = scbuf + 8;
1638  while (*c && isspace((unsigned char) *c))
1639  c++;
1640  add_stringlist_item(&ignorelist, c);
1641 
1642  /*
1643  * Note: ignore: lines do not run the test, they just say that
1644  * failure of this test when run later on is to be ignored. A bit
1645  * odd but that's how the shell-script version did it.
1646  */
1647  continue;
1648  }
1649  else
1650  {
1651  fprintf(stderr, _("syntax error in schedule file \"%s\" line %d: %s\n"),
1652  schedule, line_num, scbuf);
1653  exit(2);
1654  }
1655 
1656  num_tests = 0;
1657  inword = false;
1658  for (c = test; *c; c++)
1659  {
1660  if (isspace((unsigned char) *c))
1661  {
1662  *c = '\0';
1663  inword = false;
1664  }
1665  else if (!inword)
1666  {
1667  if (num_tests >= MAX_PARALLEL_TESTS)
1668  {
1669  /* can't print scbuf here, it's already been trashed */
1670  fprintf(stderr, _("too many parallel tests in schedule file \"%s\", line %d\n"),
1671  schedule, line_num);
1672  exit(2);
1673  }
1674  tests[num_tests] = c;
1675  num_tests++;
1676  inword = true;
1677  }
1678  }
1679 
1680  if (num_tests == 0)
1681  {
1682  fprintf(stderr, _("syntax error in schedule file \"%s\" line %d: %s\n"),
1683  schedule, line_num, scbuf);
1684  exit(2);
1685  }
1686 
1687  if (num_tests == 1)
1688  {
1689  status(_("test %-24s ... "), tests[0]);
1690  pids[0] = (tfunc) (tests[0], &resultfiles[0], &expectfiles[0], &tags[0]);
1691  wait_for_tests(pids, statuses, NULL, 1);
1692  /* status line is finished below */
1693  }
1694  else if (max_connections > 0 && max_connections < num_tests)
1695  {
1696  int oldest = 0;
1697 
1698  status(_("parallel group (%d tests, in groups of %d): "),
1699  num_tests, max_connections);
1700  for (i = 0; i < num_tests; i++)
1701  {
1702  if (i - oldest >= max_connections)
1703  {
1704  wait_for_tests(pids + oldest, statuses + oldest,
1705  tests + oldest, i - oldest);
1706  oldest = i;
1707  }
1708  pids[i] = (tfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1709  }
1710  wait_for_tests(pids + oldest, statuses + oldest,
1711  tests + oldest, i - oldest);
1712  status_end();
1713  }
1714  else
1715  {
1716  status(_("parallel group (%d tests): "), num_tests);
1717  for (i = 0; i < num_tests; i++)
1718  {
1719  pids[i] = (tfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1720  }
1721  wait_for_tests(pids, statuses, tests, num_tests);
1722  status_end();
1723  }
1724 
1725  /* Check results for all tests */
1726  for (i = 0; i < num_tests; i++)
1727  {
1728  _stringlist *rl,
1729  *el,
1730  *tl;
1731  bool differ = false;
1732 
1733  if (num_tests > 1)
1734  status(_(" %-24s ... "), tests[i]);
1735 
1736  /*
1737  * Advance over all three lists simultaneously.
1738  *
1739  * Compare resultfiles[j] with expectfiles[j] always. Tags are
1740  * optional but if there are tags, the tag list has the same
1741  * length as the other two lists.
1742  */
1743  for (rl = resultfiles[i], el = expectfiles[i], tl = tags[i];
1744  rl != NULL; /* rl and el have the same length */
1745  rl = rl->next, el = el->next)
1746  {
1747  bool newdiff;
1748 
1749  if (tl)
1750  tl = tl->next; /* tl has the same length as rl and el
1751  * if it exists */
1752 
1753  newdiff = results_differ(tests[i], rl->str, el->str);
1754  if (newdiff && tl)
1755  {
1756  printf("%s ", tl->str);
1757  }
1758  differ |= newdiff;
1759  }
1760 
1761  if (differ)
1762  {
1763  bool ignore = false;
1764  _stringlist *sl;
1765 
1766  for (sl = ignorelist; sl != NULL; sl = sl->next)
1767  {
1768  if (strcmp(tests[i], sl->str) == 0)
1769  {
1770  ignore = true;
1771  break;
1772  }
1773  }
1774  if (ignore)
1775  {
1776  status(_("failed (ignored)"));
1778  }
1779  else
1780  {
1781  status(_("FAILED"));
1782  fail_count++;
1783  }
1784  }
1785  else
1786  {
1787  status(_("ok"));
1788  success_count++;
1789  }
1790 
1791  if (statuses[i] != 0)
1792  log_child_failure(statuses[i]);
1793 
1794  status_end();
1795  }
1796  }
1797 
1798  free_stringlist(&ignorelist);
1799 
1800  fclose(scf);
1801 }
static void test(void)
static void log_child_failure(int exitstatus)
Definition: pg_regress.c:1552
char * str
Definition: pg_regress.h:24
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:154
static const char * progname
Definition: pg_regress.c:97
static void status_end(void)
Definition: pg_regress.c:245
#define PID_TYPE
Definition: pg_regress.h:14
static bool results_differ(const char *testname, const char *resultsfile, const char *default_expectfile)
Definition: pg_regress.c:1335
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:175
char * c
#define MAX_PARALLEL_TESTS
static int success_count
Definition: pg_regress.c:113
static int max_connections
Definition: pg_regress.c:80
static int fail_ignore_count
Definition: pg_regress.c:115
static int fail_count
Definition: pg_regress.c:114
#define NULL
Definition: c.h:229
struct _stringlist * next
Definition: pg_regress.h:25
int i
const char * strerror(int errnum)
Definition: strerror.c:19
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
static void wait_for_tests(PID_TYPE *pids, int *statuses, char **names, int num_tests)
Definition: pg_regress.c:1482
#define _(x)
Definition: elog.c:84
static void run_single_test ( const char *  test,
test_function  tfunc 
)
static

Definition at line 1807 of file pg_regress.c.

References _, fail_count, log_child_failure(), _stringlist::next, NULL, PID_TYPE, results_differ(), status(), status_end(), _stringlist::str, success_count, and wait_for_tests().

Referenced by regression_main().

1808 {
1809  PID_TYPE pid;
1810  int exit_status;
1811  _stringlist *resultfiles = NULL;
1812  _stringlist *expectfiles = NULL;
1813  _stringlist *tags = NULL;
1814  _stringlist *rl,
1815  *el,
1816  *tl;
1817  bool differ = false;
1818 
1819  status(_("test %-24s ... "), test);
1820  pid = (tfunc) (test, &resultfiles, &expectfiles, &tags);
1821  wait_for_tests(&pid, &exit_status, NULL, 1);
1822 
1823  /*
1824  * Advance over all three lists simultaneously.
1825  *
1826  * Compare resultfiles[j] with expectfiles[j] always. Tags are optional
1827  * but if there are tags, the tag list has the same length as the other
1828  * two lists.
1829  */
1830  for (rl = resultfiles, el = expectfiles, tl = tags;
1831  rl != NULL; /* rl and el have the same length */
1832  rl = rl->next, el = el->next)
1833  {
1834  bool newdiff;
1835 
1836  if (tl)
1837  tl = tl->next; /* tl has the same length as rl and el if it
1838  * exists */
1839 
1840  newdiff = results_differ(test, rl->str, el->str);
1841  if (newdiff && tl)
1842  {
1843  printf("%s ", tl->str);
1844  }
1845  differ |= newdiff;
1846  }
1847 
1848  if (differ)
1849  {
1850  status(_("FAILED"));
1851  fail_count++;
1852  }
1853  else
1854  {
1855  status(_("ok"));
1856  success_count++;
1857  }
1858 
1859  if (exit_status != 0)
1860  log_child_failure(exit_status);
1861 
1862  status_end();
1863 }
static void test(void)
static void log_child_failure(int exitstatus)
Definition: pg_regress.c:1552
char * str
Definition: pg_regress.h:24
static void status_end(void)
Definition: pg_regress.c:245
#define PID_TYPE
Definition: pg_regress.h:14
static bool results_differ(const char *testname, const char *resultsfile, const char *default_expectfile)
Definition: pg_regress.c:1335
static int success_count
Definition: pg_regress.c:113
static int fail_count
Definition: pg_regress.c:114
#define NULL
Definition: c.h:229
struct _stringlist * next
Definition: pg_regress.h:25
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
static void wait_for_tests(PID_TYPE *pids, int *statuses, char **names, int num_tests)
Definition: pg_regress.c:1482
#define _(x)
Definition: elog.c:84
PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1126 of file pg_regress.c.

References _, logfile, NULL, progname, psprintf(), shellprog, and strerror().

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

1127 {
1128 #ifndef WIN32
1129  pid_t pid;
1130 
1131  /*
1132  * Must flush I/O buffers before fork. Ideally we'd use fflush(NULL) here
1133  * ... does anyone still care about systems where that doesn't work?
1134  */
1135  fflush(stdout);
1136  fflush(stderr);
1137  if (logfile)
1138  fflush(logfile);
1139 
1140  pid = fork();
1141  if (pid == -1)
1142  {
1143  fprintf(stderr, _("%s: could not fork: %s\n"),
1144  progname, strerror(errno));
1145  exit(2);
1146  }
1147  if (pid == 0)
1148  {
1149  /*
1150  * In child
1151  *
1152  * Instead of using system(), exec the shell directly, and tell it to
1153  * "exec" the command too. This saves two useless processes per
1154  * parallel test case.
1155  */
1156  char *cmdline2;
1157 
1158  cmdline2 = psprintf("exec %s", cmdline);
1159  execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1160  fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
1161  progname, shellprog, strerror(errno));
1162  _exit(1); /* not exit() here... */
1163  }
1164  /* in parent */
1165  return pid;
1166 #else
1167  PROCESS_INFORMATION pi;
1168  char *cmdline2;
1169  HANDLE restrictedToken;
1170 
1171  memset(&pi, 0, sizeof(pi));
1172  cmdline2 = psprintf("cmd /c \"%s\"", cmdline);
1173 
1174  if ((restrictedToken =
1175  CreateRestrictedProcess(cmdline2, &pi, progname)) == 0)
1176  exit(2);
1177 
1178  CloseHandle(pi.hThread);
1179  return pi.hProcess;
1180 #endif
1181 }
static char * shellprog
Definition: pg_regress.c:55
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static const char * progname
Definition: pg_regress.c:97
static FILE * logfile
Definition: pg_regress.c:99
#define NULL
Definition: c.h:229
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static void split_to_stringlist ( const char *  s,
const char *  delim,
_stringlist **  listhead 
)
static

Definition at line 190 of file pg_regress.c.

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

Referenced by regression_main().

191 {
192  char *sc = pg_strdup(s);
193  char *token = strtok(sc, delim);
194 
195  while (token)
196  {
197  add_stringlist_item(listhead, token);
198  token = strtok(NULL, delim);
199  }
200  free(sc);
201 }
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:154
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static void status ( const char *  fmt,
  ... 
)
static

Definition at line 224 of file pg_regress.c.

References logfile.

Referenced by _bt_first(), _bt_parallel_seize(), _bt_readnextpage(), _bt_steppage(), AtAbort_Portals(), AtCleanup_Portals(), AtEOSubXact_RelationCache(), AtEOXact_RelationCache(), AtPrepare_Locks(), AtSubAbort_Portals(), AtSubCleanup_Portals(), AtSubCommit_Portals(), BackendInitialize(), BaseBackup(), be_lo_lseek(), be_lo_lseek64(), bf_check_supported_key_len(), check_worker_status(), ClientAuthentication(), compute_new_xmax_infomask(), dblink_get_connections(), do_lo_export(), do_lo_unlink(), DoesMultiXactIdConflict(), ecpg_process_output(), ecpg_store_result(), exec_command(), exec_command_crosstabview(), exec_command_d(), exec_command_edit(), exec_command_ef(), exec_command_ev(), exec_command_g(), exec_command_gexec(), exec_command_gset(), exec_command_lo(), exec_command_quit(), exec_command_sf(), exec_command_sv(), exec_command_write(), executeQueryOrDie(), forget_invalid_pages(), forget_invalid_pages_db(), FreezeMultiXactId(), get_collation_actual_version(), GetMultiXactIdHintBits(), HandleSlashCmds(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), InvalidateAttoptCacheCallback(), InvalidateOprCacheCallBack(), InvalidateOprProofCacheCallBack(), InvalidateShippableCacheCallback(), InvalidateTableSpaceCacheCallback(), InvalidateTSCacheCallBack(), libpqrcv_connect(), ListenToWorkers(), lo_read(), lo_write(), LockAcquireExtended(), LockReassignCurrentOwner(), LockReleaseAll(), LockReleaseCurrentOwner(), LockReleaseSession(), log_child_failure(), logicalrep_relmap_invalidate_cb(), logicalrep_typmap_invalidate_cb(), MultiXactIdCreateFromMembers(), MultiXactIdExpand(), MultiXactIdGetUpdateXid(), mxid_to_string(), parallel_restore(), parseServiceInfo(), parseWorkerResponse(), pg_import_system_collations(), pg_newlocale_from_collation(), pg_prepared_xact(), pg_start_backup(), pg_stop_backup(), pg_stop_backup_v2(), pgrowlocks(), PortalHashTableDeleteAll(), PostmasterMain(), PostPrepare_Locks(), pqFunctionCall2(), pqFunctionCall3(), pqGetline3(), PQmakeEmptyPGresult(), PQresetPoll(), PQresStatus(), PQsetClientEncoding(), PreCommit_Portals(), RecordNewMultiXact(), rel_sync_cache_publication_cb(), RelationCacheInitializePhase3(), RelationCacheInvalidate(), RelfilenodeMapInvalidateCallback(), restore_toc_entry(), run_schedule(), run_single_test(), run_vacuum_command(), sepgsql_client_auth(), shm_mq_counterparty_gone(), shm_mq_wait_internal(), smgrcloseall(), test_config_settings(), test_postmaster_connection(), ThereAreNoReadyPortals(), tintervalrecv(), TransactionIdGetStatus(), txid_status(), TypeCacheOpcCallback(), TypeCacheRelCallback(), uuid_generate_internal(), varstr_abbrev_convert(), varstr_cmp(), varstrfastcmp_locale(), wait_for_tests(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForCommands(), WaitForParallelWorkersToExit(), WaitForReplicationWorkerAttach(), WaitForTerminatingWorkers(), worker_spi_launch(), write_relcache_init_file(), XLogCheckInvalidPages(), and yearistype().

225 {
226  va_list ap;
227 
228  va_start(ap, fmt);
229  vfprintf(stdout, fmt, ap);
230  fflush(stdout);
231  va_end(ap);
232 
233  if (logfile)
234  {
235  va_start(ap, fmt);
236  vfprintf(logfile, fmt, ap);
237  va_end(ap);
238  }
239 }
static FILE * logfile
Definition: pg_regress.c:99
static void status_end ( void  )
static

Definition at line 245 of file pg_regress.c.

References logfile.

Referenced by run_schedule(), and run_single_test().

246 {
247  fprintf(stdout, "\n");
248  fflush(stdout);
249  if (logfile)
250  fprintf(logfile, "\n");
251 }
static FILE * logfile
Definition: pg_regress.c:99
static void stop_postmaster ( void  )
static

Definition at line 257 of file pg_regress.c.

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

Referenced by regression_main().

258 {
259  if (postmaster_running)
260  {
261  /* We use pg_ctl to issue the kill and wait for stop */
262  char buf[MAXPGPATH * 2];
263  int r;
264 
265  /* On Windows, system() seems not to force fflush, so... */
266  fflush(stdout);
267  fflush(stderr);
268 
269  snprintf(buf, sizeof(buf),
270  "\"%s%spg_ctl\" stop -D \"%s/data\" -s",
271  bindir ? bindir : "",
272  bindir ? "/" : "",
273  temp_instance);
274  r = system(buf);
275  if (r != 0)
276  {
277  fprintf(stderr, _("\n%s: could not stop postmaster: exit code was %d\n"),
278  progname, r);
279  _exit(2); /* not exit(), that could be recursive */
280  }
281 
282  postmaster_running = false;
283  }
284 }
static const char * progname
Definition: pg_regress.c:97
static bool postmaster_running
Definition: pg_regress.c:111
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static char * temp_instance
Definition: pg_regress.c:84
#define MAXPGPATH
static char * buf
Definition: pg_test_fsync.c:66
char * bindir
Definition: pg_regress.c:76
#define _(x)
Definition: elog.c:84
static bool string_matches_pattern ( const char *  str,
const char *  pattern 
)
static

Definition at line 375 of file pg_regress.c.

Referenced by load_resultmap().

376 {
377  while (*str && *pattern)
378  {
379  if (*pattern == '.' && pattern[1] == '*')
380  {
381  pattern += 2;
382  /* Trailing .* matches everything. */
383  if (*pattern == '\0')
384  return true;
385 
386  /*
387  * Otherwise, scan for a text position at which we can match the
388  * rest of the pattern.
389  */
390  while (*str)
391  {
392  /*
393  * Optimization to prevent most recursion: don't recurse
394  * unless first pattern char might match this text char.
395  */
396  if (*str == *pattern || *pattern == '.')
397  {
398  if (string_matches_pattern(str, pattern))
399  return true;
400  }
401 
402  str++;
403  }
404 
405  /*
406  * End of text with no match.
407  */
408  return false;
409  }
410  else if (*pattern != '.' && *str != *pattern)
411  {
412  /*
413  * Not the single-character wildcard and no explicit match? Then
414  * time to quit...
415  */
416  return false;
417  }
418 
419  str++;
420  pattern++;
421  }
422 
423  if (*pattern == '\0')
424  return true; /* end of pattern, so declare match */
425 
426  /* End of input string. Do we have matching pattern remaining? */
427  while (*pattern == '.' && pattern[1] == '*')
428  pattern += 2;
429  if (*pattern == '\0')
430  return true; /* end of pattern, so declare match */
431 
432  return false;
433 }
static bool string_matches_pattern(const char *str, const char *pattern)
Definition: pg_regress.c:375
static void wait_for_tests ( PID_TYPE pids,
int *  statuses,
char **  names,
int  num_tests 
)
static

Definition at line 1482 of file pg_regress.c.

References _, FALSE, free, i, INVALID_PID, pg_malloc(), PID_TYPE, status(), and strerror().

Referenced by run_schedule(), and run_single_test().

1483 {
1484  int tests_left;
1485  int i;
1486 
1487 #ifdef WIN32
1488  PID_TYPE *active_pids = pg_malloc(num_tests * sizeof(PID_TYPE));
1489 
1490  memcpy(active_pids, pids, num_tests * sizeof(PID_TYPE));
1491 #endif
1492 
1493  tests_left = num_tests;
1494  while (tests_left > 0)
1495  {
1496  PID_TYPE p;
1497 
1498 #ifndef WIN32
1499  int exit_status;
1500 
1501  p = wait(&exit_status);
1502 
1503  if (p == INVALID_PID)
1504  {
1505  fprintf(stderr, _("failed to wait for subprocesses: %s\n"),
1506  strerror(errno));
1507  exit(2);
1508  }
1509 #else
1510  DWORD exit_status;
1511  int r;
1512 
1513  r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE);
1514  if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left)
1515  {
1516  fprintf(stderr, _("failed to wait for subprocesses: error code %lu\n"),
1517  GetLastError());
1518  exit(2);
1519  }
1520  p = active_pids[r - WAIT_OBJECT_0];
1521  /* compact the active_pids array */
1522  active_pids[r - WAIT_OBJECT_0] = active_pids[tests_left - 1];
1523 #endif /* WIN32 */
1524 
1525  for (i = 0; i < num_tests; i++)
1526  {
1527  if (p == pids[i])
1528  {
1529 #ifdef WIN32
1530  GetExitCodeProcess(pids[i], &exit_status);
1531  CloseHandle(pids[i]);
1532 #endif
1533  pids[i] = INVALID_PID;
1534  statuses[i] = (int) exit_status;
1535  if (names)
1536  status(" %s", names[i]);
1537  tests_left--;
1538  break;
1539  }
1540  }
1541  }
1542 
1543 #ifdef WIN32
1544  free(active_pids);
1545 #endif
1546 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define PID_TYPE
Definition: pg_regress.h:14
#define FALSE
Definition: c.h:221
#define INVALID_PID
Definition: pg_regress.h:15
#define free(a)
Definition: header.h:65
int i
const char * strerror(int errnum)
Definition: strerror.c:19
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
#define _(x)
Definition: elog.c:84

Variable Documentation

const char* basic_diff_opts = ""

Definition at line 64 of file pg_regress.c.

Referenced by results_differ().

char* bindir = PGBINDIR

Definition at line 76 of file pg_regress.c.

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

char* config_auth_datadir = NULL
static

Definition at line 94 of file pg_regress.c.

Referenced by regression_main().

bool debug = false

Definition at line 73 of file pg_regress.c.

Referenced by regression_main().

char* difffilename
static

Definition at line 100 of file pg_regress.c.

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

char* dlpath = PKGLIBDIR
static

Definition at line 91 of file pg_regress.c.

Referenced by convert_sourcefiles_in(), and regression_main().

char* encoding = NULL
static

Definition at line 81 of file pg_regress.c.

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

_stringlist* extra_tests = NULL
static

Definition at line 83 of file pg_regress.c.

_stringlist* extraroles = NULL
static

Definition at line 93 of file pg_regress.c.

int fail_count = 0
static

Definition at line 114 of file pg_regress.c.

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

int fail_ignore_count = 0
static

Definition at line 115 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

char* host_platform = HOST_TUPLE

Definition at line 52 of file pg_regress.c.

Referenced by load_resultmap().

char* hostname = NULL
static

Definition at line 88 of file pg_regress.c.

Referenced by initialize_environment(), and regression_main().

char* launcher = NULL

Definition at line 77 of file pg_regress.c.

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

_stringlist* loadextension = NULL
static

Definition at line 79 of file pg_regress.c.

_stringlist* loadlanguage = NULL
static

Definition at line 78 of file pg_regress.c.

FILE* logfile
static
char* logfilename
static

Definition at line 98 of file pg_regress.c.

Referenced by open_result_files(), and regression_main().

int max_connections = 0
static

Definition at line 80 of file pg_regress.c.

Referenced by regression_main(), and run_schedule().

bool nolocale = false
static

Definition at line 86 of file pg_regress.c.

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

bool port_specified_by_user = false
static

Definition at line 90 of file pg_regress.c.

Referenced by regression_main().

PID_TYPE postmaster_pid = INVALID_PID
static

Definition at line 110 of file pg_regress.c.

Referenced by regression_main().

bool postmaster_running = false
static

Definition at line 111 of file pg_regress.c.

Referenced by regression_main(), and stop_postmaster().

const char* pretty_diff_opts = "-C3"

Definition at line 65 of file pg_regress.c.

Referenced by regression_main(), and results_differ().

_resultmap* resultmap = NULL
static

Definition at line 108 of file pg_regress.c.

Referenced by load_resultmap().

_stringlist* schedulelist = NULL
static

Definition at line 82 of file pg_regress.c.

char* shellprog = SHELLPROG
static

Definition at line 55 of file pg_regress.c.

Referenced by spawn_process().

const char* sockdir
static
int success_count = 0
static

Definition at line 113 of file pg_regress.c.

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

_stringlist* temp_configs = NULL
static

Definition at line 85 of file pg_regress.c.

char* temp_instance = NULL
static

Definition at line 84 of file pg_regress.c.

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

bool use_existing = false
static

Definition at line 87 of file pg_regress.c.

Referenced by regression_main().