PostgreSQL Source Code  git master
pg_regress.h File Reference
#include <unistd.h>
Include dependency graph for pg_regress.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _stringlist
 

Macros

#define PID_TYPE   pid_t
 
#define INVALID_PID   (-1)
 

Typedefs

typedef struct _stringlist _stringlist
 
typedef void(* init_function) (int argc, char **argv)
 
typedef PID_TYPE(* test_start_function) (const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
 
typedef void(* postprocess_result_function) (const char *filename)
 

Functions

int regression_main (int argc, char *argv[], init_function ifunc, test_start_function startfunc, postprocess_result_function postfunc)
 
void add_stringlist_item (_stringlist **listhead, const char *str)
 
PID_TYPE spawn_process (const char *cmdline)
 
bool file_exists (const char *file)
 

Variables

char * bindir
 
char * libdir
 
char * datadir
 
char * host_platform
 
_stringlistdblist
 
bool debug
 
char * inputdir
 
char * outputdir
 
char * expecteddir
 
char * launcher
 
const char * basic_diff_opts
 
const char * pretty_diff_opts
 

Macro Definition Documentation

◆ INVALID_PID

#define INVALID_PID   (-1)

Definition at line 15 of file pg_regress.h.

◆ PID_TYPE

#define PID_TYPE   pid_t

Definition at line 14 of file pg_regress.h.

Typedef Documentation

◆ _stringlist

typedef struct _stringlist _stringlist

◆ init_function

typedef void(* init_function) (int argc, char **argv)

Definition at line 35 of file pg_regress.h.

◆ postprocess_result_function

typedef void(* postprocess_result_function) (const char *filename)

Definition at line 44 of file pg_regress.h.

◆ test_start_function

typedef PID_TYPE(* test_start_function) (const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)

Definition at line 38 of file pg_regress.h.

Function Documentation

◆ add_stringlist_item()

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

Definition at line 154 of file pg_regress.c.

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 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * str
Definition: initdb.c:91
struct _stringlist * next
Definition: initdb.c:92

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

Referenced by regression_main(), and split_to_stringlist().

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1167 of file pg_regress.c.

1168 {
1169  FILE *f = fopen(file, "r");
1170 
1171  if (!f)
1172  return false;
1173  fclose(f);
1174  return true;
1175 }

Referenced by results_differ().

◆ regression_main()

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

Definition at line 1985 of file pg_regress.c.

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

References _, add_stringlist_item(), bindir, buf, config_auth_datadir, create_database(), create_role(), dblist, debug, DEVNULL, difffilename, directory_exists(), dlpath, drop_database_if_exists(), drop_role_if_exists(), encoding, exit(), expecteddir, extra_tests, extraroles, fail_count, fflush(), file_size(), fprintf, free_stringlist(), get_progname(), get_restricted_token(), getopt_long(), header(), help(), hostname, i, initialize_environment(), inputdir, INVALID_PID, kill, launcher, loadextension, logfile, logfilename, make_absolute_path(), make_directory(), max_concurrent_tests, max_connections, MAXPGPATH, _stringlist::next, no_argument, nolocale, open_result_files(), optarg, optind, outputdir, pg_logging_init(), pg_strdup(), PG_TEXTDOMAIN, pg_usleep(), port, port_specified_by_user, postmaster_pid, postmaster_running, pretty_diff_opts, printf, progname, required_argument, rmtree(), run_schedule(), run_single_test(), schedulelist, set_pglocale_pgservice(), setenv, SIGKILL, snprintf, sockdir, spawn_process(), split_to_stringlist(), sprintf, stop_postmaster(), _stringlist::str, strerror, success_count, temp_configs, temp_instance, true, ULONGPID, unlimit_core_size(), use_existing, user, and wait_seconds.

Referenced by main().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1057 of file pg_regress.c.

1058 {
1059 #ifndef WIN32
1060  pid_t pid;
1061 
1062  /*
1063  * Must flush I/O buffers before fork.
1064  */
1065  fflush(NULL);
1066 
1067 #ifdef EXEC_BACKEND
1068  pg_disable_aslr();
1069 #endif
1070 
1071  pid = fork();
1072  if (pid == -1)
1073  {
1074  fprintf(stderr, _("%s: could not fork: %s\n"),
1075  progname, strerror(errno));
1076  exit(2);
1077  }
1078  if (pid == 0)
1079  {
1080  /*
1081  * In child
1082  *
1083  * Instead of using system(), exec the shell directly, and tell it to
1084  * "exec" the command too. This saves two useless processes per
1085  * parallel test case.
1086  */
1087  char *cmdline2;
1088 
1089  cmdline2 = psprintf("exec %s", cmdline);
1090  execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1091  fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
1092  progname, shellprog, strerror(errno));
1093  _exit(1); /* not exit() here... */
1094  }
1095  /* in parent */
1096  return pid;
1097 #else
1098  PROCESS_INFORMATION pi;
1099  char *cmdline2;
1100  HANDLE restrictedToken;
1101  const char *comspec;
1102 
1103  /* Find CMD.EXE location using COMSPEC, if it's set */
1104  comspec = getenv("COMSPEC");
1105  if (comspec == NULL)
1106  comspec = "CMD";
1107 
1108  memset(&pi, 0, sizeof(pi));
1109  cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
1110 
1111  if ((restrictedToken =
1112  CreateRestrictedProcess(cmdline2, &pi)) == 0)
1113  exit(2);
1114 
1115  CloseHandle(pi.hThread);
1116  return pi.hProcess;
1117 #endif
1118 }
static char * shellprog
Definition: pg_regress.c:55
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46

References _, exit(), fflush(), fprintf, progname, psprintf(), shellprog, and strerror.

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

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts
extern

Definition at line 64 of file pg_regress.c.

Referenced by results_differ().

◆ bindir

char* bindir
extern

Definition at line 77 of file pg_regress.c.

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

◆ datadir

◆ dblist

◆ debug

bool debug
extern

Definition at line 73 of file pg_regress.c.

Referenced by regression_main().

◆ expecteddir

char* expecteddir
extern

Definition at line 76 of file pg_regress.c.

Referenced by ecpg_start_test(), and regression_main().

◆ host_platform

char* host_platform
extern

Definition at line 52 of file pg_regress.c.

Referenced by load_resultmap().

◆ inputdir

◆ launcher

char* launcher
extern

Definition at line 78 of file pg_regress.c.

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

◆ libdir

char* libdir
extern

◆ outputdir

◆ pretty_diff_opts

const char* pretty_diff_opts
extern

Definition at line 65 of file pg_regress.c.

Referenced by regression_main(), and results_differ().