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

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

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

Referenced by regression_main(), and split_to_stringlist().

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1301 of file pg_regress.c.

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

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

◆ regression_main()

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

Definition at line 2063 of file pg_regress.c.

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

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

Referenced by main().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1198 of file pg_regress.c.

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

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

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

Referenced by results_differ().

◆ bindir

char* bindir
extern

◆ datadir

◆ dblist

◆ debug

bool debug
extern

Definition at line 99 of file pg_regress.c.

Referenced by regression_main().

◆ expecteddir

char* expecteddir
extern

Definition at line 102 of file pg_regress.c.

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

◆ host_platform

char* host_platform
extern

Definition at line 53 of file pg_regress.c.

Referenced by load_resultmap().

◆ inputdir

◆ launcher

char* launcher
extern

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

Referenced by regression_main(), and results_differ().