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

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

Referenced by regression_main(), and split_to_stringlist().

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1302 of file pg_regress.c.

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

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

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

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

Referenced by main().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1197 of file pg_regress.c.

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