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)
 
void replace_string (struct StringInfoData *string, const char *replace, const char *replacement)
 
bool file_exists (const char *file)
 

Variables

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

Macro Definition Documentation

◆ INVALID_PID

#define INVALID_PID   (-1)

◆ PID_TYPE

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

References _stringlist::next, 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().

160 {
161  _stringlist *newentry = pg_malloc(sizeof(_stringlist));
162  _stringlist *oldentry;
163 
164  newentry->str = pg_strdup(str);
165  newentry->next = NULL;
166  if (*listhead == NULL)
167  *listhead = newentry;
168  else
169  {
170  for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
171  /* skip */ ;
172  oldentry->next = newentry;
173  }
174 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * str
Definition: pg_regress.h:26
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
struct _stringlist * next
Definition: pg_regress.h:27

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1345 of file pg_regress.c.

Referenced by results_differ().

1346 {
1347  FILE *f = fopen(file, "r");
1348 
1349  if (!f)
1350  return false;
1351  fclose(f);
1352  return true;
1353 }

◆ regression_main()

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

Definition at line 2185 of file pg_regress.c.

References _, add_stringlist_item(), bindir, config_auth_datadir, create_database(), create_role(), debug, DEVNULL, difffilename, directory_exists(), dlpath, drop_database_if_exists(), drop_role_if_exists(), encoding, fail_count, fail_ignore_count, file_size(), fprintf, free_stringlist(), get_progname(), get_restricted_token(), getopt_long(), header(), help(), hostname, i, initialize_environment(), inputdir, INVALID_PID, kill, launcher, 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, prepare_testtablespace_dir(), pretty_diff_opts, printf, progname, required_argument, rmtree(), run_schedule(), run_single_test(), set_pglocale_pgservice(), setenv, SIGKILL, snprintf, sockdir, spawn_process(), split_to_stringlist(), sprintf, stop_postmaster(), _stringlist::str, strerror, success_count, temp_instance, true, ULONGPID, use_existing, user, and wait_seconds.

Referenced by main().

2189 {
2190  static struct option long_options[] = {
2191  {"help", no_argument, NULL, 'h'},
2192  {"version", no_argument, NULL, 'V'},
2193  {"dbname", required_argument, NULL, 1},
2194  {"debug", no_argument, NULL, 2},
2195  {"inputdir", required_argument, NULL, 3},
2196  {"max-connections", required_argument, NULL, 5},
2197  {"encoding", required_argument, NULL, 6},
2198  {"outputdir", required_argument, NULL, 7},
2199  {"schedule", required_argument, NULL, 8},
2200  {"temp-instance", required_argument, NULL, 9},
2201  {"no-locale", no_argument, NULL, 10},
2202  {"host", required_argument, NULL, 13},
2203  {"port", required_argument, NULL, 14},
2204  {"user", required_argument, NULL, 15},
2205  {"bindir", required_argument, NULL, 16},
2206  {"dlpath", required_argument, NULL, 17},
2207  {"create-role", required_argument, NULL, 18},
2208  {"temp-config", required_argument, NULL, 19},
2209  {"use-existing", no_argument, NULL, 20},
2210  {"launcher", required_argument, NULL, 21},
2211  {"load-extension", required_argument, NULL, 22},
2212  {"config-auth", required_argument, NULL, 24},
2213  {"max-concurrent-tests", required_argument, NULL, 25},
2214  {"make-testtablespace-dir", no_argument, NULL, 26},
2215  {NULL, 0, NULL, 0}
2216  };
2217 
2218  bool use_unix_sockets;
2219  bool make_testtablespace_dir = false;
2220  _stringlist *sl;
2221  int c;
2222  int i;
2223  int option_index;
2224  char buf[MAXPGPATH * 4];
2225  char buf2[MAXPGPATH * 4];
2226 
2227  pg_logging_init(argv[0]);
2228  progname = get_progname(argv[0]);
2229  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_regress"));
2230 
2232 
2233  atexit(stop_postmaster);
2234 
2235 #if !defined(HAVE_UNIX_SOCKETS)
2236  use_unix_sockets = false;
2237 #elif defined(WIN32)
2238 
2239  /*
2240  * We don't use Unix-domain sockets on Windows by default, even if the
2241  * build supports them. (See comment at remove_temp() for a reason.)
2242  * Override at your own risk.
2243  */
2244  use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false;
2245 #else
2246  use_unix_sockets = true;
2247 #endif
2248 
2249  if (!use_unix_sockets)
2250  hostname = "localhost";
2251 
2252  /*
2253  * We call the initialization function here because that way we can set
2254  * default parameters and let them be overwritten by the commandline.
2255  */
2256  ifunc(argc, argv);
2257 
2258  if (getenv("PG_REGRESS_DIFF_OPTS"))
2259  pretty_diff_opts = getenv("PG_REGRESS_DIFF_OPTS");
2260 
2261  while ((c = getopt_long(argc, argv, "hV", long_options, &option_index)) != -1)
2262  {
2263  switch (c)
2264  {
2265  case 'h':
2266  help();
2267  exit(0);
2268  case 'V':
2269  puts("pg_regress (PostgreSQL) " PG_VERSION);
2270  exit(0);
2271  case 1:
2272 
2273  /*
2274  * If a default database was specified, we need to remove it
2275  * before we add the specified one.
2276  */
2279  break;
2280  case 2:
2281  debug = true;
2282  break;
2283  case 3:
2285  break;
2286  case 5:
2287  max_connections = atoi(optarg);
2288  break;
2289  case 6:
2291  break;
2292  case 7:
2294  break;
2295  case 8:
2297  break;
2298  case 9:
2300  break;
2301  case 10:
2302  nolocale = true;
2303  break;
2304  case 13:
2306  break;
2307  case 14:
2308  port = atoi(optarg);
2309  port_specified_by_user = true;
2310  break;
2311  case 15:
2312  user = pg_strdup(optarg);
2313  break;
2314  case 16:
2315  /* "--bindir=" means to use PATH */
2316  if (strlen(optarg))
2317  bindir = pg_strdup(optarg);
2318  else
2319  bindir = NULL;
2320  break;
2321  case 17:
2322  dlpath = pg_strdup(optarg);
2323  break;
2324  case 18:
2326  break;
2327  case 19:
2329  break;
2330  case 20:
2331  use_existing = true;
2332  break;
2333  case 21:
2335  break;
2336  case 22:
2338  break;
2339  case 24:
2341  break;
2342  case 25:
2343  max_concurrent_tests = atoi(optarg);
2344  break;
2345  case 26:
2346  make_testtablespace_dir = true;
2347  break;
2348  default:
2349  /* getopt_long already emitted a complaint */
2350  fprintf(stderr, _("\nTry \"%s -h\" for more information.\n"),
2351  progname);
2352  exit(2);
2353  }
2354  }
2355 
2356  /*
2357  * if we still have arguments, they are extra tests to run
2358  */
2359  while (argc - optind >= 1)
2360  {
2362  optind++;
2363  }
2364 
2365  if (config_auth_datadir)
2366  {
2367 #ifdef ENABLE_SSPI
2368  if (!use_unix_sockets)
2369  config_sspi_auth(config_auth_datadir, user);
2370 #endif
2371  exit(0);
2372  }
2373 
2375 
2376  /*
2377  * To reduce chances of interference with parallel installations, use
2378  * a port number starting in the private range (49152-65535)
2379  * calculated from the version number. This aids !HAVE_UNIX_SOCKETS
2380  * systems; elsewhere, the use of a private socket directory already
2381  * prevents interference.
2382  */
2383  port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2384 
2388 
2389  /*
2390  * Initialization
2391  */
2393 
2395 
2396 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE)
2397  unlimit_core_size();
2398 #endif
2399 
2400  if (make_testtablespace_dir)
2402 
2403  if (temp_instance)
2404  {
2405  FILE *pg_conf;
2406  const char *env_wait;
2407  int wait_seconds;
2408 
2409  /*
2410  * Prepare the temp instance
2411  */
2412 
2414  {
2415  header(_("removing existing temp instance"));
2416  if (!rmtree(temp_instance, true))
2417  {
2418  fprintf(stderr, _("\n%s: could not remove temp instance \"%s\"\n"),
2420  exit(2);
2421  }
2422  }
2423 
2424  header(_("creating temporary instance"));
2425 
2426  /* make the temp instance top directory */
2428 
2429  /* and a directory for log files */
2430  snprintf(buf, sizeof(buf), "%s/log", outputdir);
2431  if (!directory_exists(buf))
2432  make_directory(buf);
2433 
2434  /* initdb */
2435  header(_("initializing database system"));
2436  snprintf(buf, sizeof(buf),
2437  "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync%s%s > \"%s/log/initdb.log\" 2>&1",
2438  bindir ? bindir : "",
2439  bindir ? "/" : "",
2440  temp_instance,
2441  debug ? " --debug" : "",
2442  nolocale ? " --no-locale" : "",
2443  outputdir);
2444  if (system(buf))
2445  {
2446  fprintf(stderr, _("\n%s: initdb failed\nExamine %s/log/initdb.log for the reason.\nCommand was: %s\n"), progname, outputdir, buf);
2447  exit(2);
2448  }
2449 
2450  /*
2451  * Adjust the default postgresql.conf for regression testing. The user
2452  * can specify a file to be appended; in any case we expand logging
2453  * and set max_prepared_transactions to enable testing of prepared
2454  * xacts. (Note: to reduce the probability of unexpected shmmax
2455  * failures, don't set max_prepared_transactions any higher than
2456  * actually needed by the prepared_xacts regression test.)
2457  */
2458  snprintf(buf, sizeof(buf), "%s/data/postgresql.conf", temp_instance);
2459  pg_conf = fopen(buf, "a");
2460  if (pg_conf == NULL)
2461  {
2462  fprintf(stderr, _("\n%s: could not open \"%s\" for adding extra config: %s\n"), progname, buf, strerror(errno));
2463  exit(2);
2464  }
2465  fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
2466  fputs("log_autovacuum_min_duration = 0\n", pg_conf);
2467  fputs("log_checkpoints = on\n", pg_conf);
2468  fputs("log_line_prefix = '%m %b[%p] %q%a '\n", pg_conf);
2469  fputs("log_lock_waits = on\n", pg_conf);
2470  fputs("log_temp_files = 128kB\n", pg_conf);
2471  fputs("max_prepared_transactions = 2\n", pg_conf);
2472 
2473  for (sl = temp_configs; sl != NULL; sl = sl->next)
2474  {
2475  char *temp_config = sl->str;
2476  FILE *extra_conf;
2477  char line_buf[1024];
2478 
2479  extra_conf = fopen(temp_config, "r");
2480  if (extra_conf == NULL)
2481  {
2482  fprintf(stderr, _("\n%s: could not open \"%s\" to read extra config: %s\n"), progname, temp_config, strerror(errno));
2483  exit(2);
2484  }
2485  while (fgets(line_buf, sizeof(line_buf), extra_conf) != NULL)
2486  fputs(line_buf, pg_conf);
2487  fclose(extra_conf);
2488  }
2489 
2490  fclose(pg_conf);
2491 
2492 #ifdef ENABLE_SSPI
2493  if (!use_unix_sockets)
2494  {
2495  /*
2496  * Since we successfully used the same buffer for the much-longer
2497  * "initdb" command, this can't truncate.
2498  */
2499  snprintf(buf, sizeof(buf), "%s/data", temp_instance);
2500  config_sspi_auth(buf, NULL);
2501  }
2502 #elif !defined(HAVE_UNIX_SOCKETS)
2503 #error Platform has no means to secure the test installation.
2504 #endif
2505 
2506  /*
2507  * Check if there is a postmaster running already.
2508  */
2509  snprintf(buf2, sizeof(buf2),
2510  "\"%s%spsql\" -X postgres <%s 2>%s",
2511  bindir ? bindir : "",
2512  bindir ? "/" : "",
2513  DEVNULL, DEVNULL);
2514 
2515  for (i = 0; i < 16; i++)
2516  {
2517  if (system(buf2) == 0)
2518  {
2519  char s[16];
2520 
2521  if (port_specified_by_user || i == 15)
2522  {
2523  fprintf(stderr, _("port %d apparently in use\n"), port);
2525  fprintf(stderr, _("%s: could not determine an available port\n"), progname);
2526  fprintf(stderr, _("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.\n"));
2527  exit(2);
2528  }
2529 
2530  fprintf(stderr, _("port %d apparently in use, trying %d\n"), port, port + 1);
2531  port++;
2532  sprintf(s, "%d", port);
2533  setenv("PGPORT", s, 1);
2534  }
2535  else
2536  break;
2537  }
2538 
2539  /*
2540  * Start the temp postmaster
2541  */
2542  header(_("starting postmaster"));
2543  snprintf(buf, sizeof(buf),
2544  "\"%s%spostgres\" -D \"%s/data\" -F%s "
2545  "-c \"listen_addresses=%s\" -k \"%s\" "
2546  "> \"%s/log/postmaster.log\" 2>&1",
2547  bindir ? bindir : "",
2548  bindir ? "/" : "",
2549  temp_instance, debug ? " -d 5" : "",
2550  hostname ? hostname : "", sockdir ? sockdir : "",
2551  outputdir);
2553  if (postmaster_pid == INVALID_PID)
2554  {
2555  fprintf(stderr, _("\n%s: could not spawn postmaster: %s\n"),
2556  progname, strerror(errno));
2557  exit(2);
2558  }
2559 
2560  /*
2561  * Wait till postmaster is able to accept connections; normally this
2562  * is only a second or so, but Cygwin is reportedly *much* slower, and
2563  * test builds using Valgrind or similar tools might be too. Hence,
2564  * allow the default timeout of 60 seconds to be overridden from the
2565  * PGCTLTIMEOUT environment variable.
2566  */
2567  env_wait = getenv("PGCTLTIMEOUT");
2568  if (env_wait != NULL)
2569  {
2570  wait_seconds = atoi(env_wait);
2571  if (wait_seconds <= 0)
2572  wait_seconds = 60;
2573  }
2574  else
2575  wait_seconds = 60;
2576 
2577  for (i = 0; i < wait_seconds; i++)
2578  {
2579  /* Done if psql succeeds */
2580  if (system(buf2) == 0)
2581  break;
2582 
2583  /*
2584  * Fail immediately if postmaster has exited
2585  */
2586 #ifndef WIN32
2587  if (waitpid(postmaster_pid, NULL, WNOHANG) == postmaster_pid)
2588 #else
2589  if (WaitForSingleObject(postmaster_pid, 0) == WAIT_OBJECT_0)
2590 #endif
2591  {
2592  fprintf(stderr, _("\n%s: postmaster failed\nExamine %s/log/postmaster.log for the reason\n"), progname, outputdir);
2593  exit(2);
2594  }
2595 
2596  pg_usleep(1000000L);
2597  }
2598  if (i >= wait_seconds)
2599  {
2600  fprintf(stderr, _("\n%s: postmaster did not respond within %d seconds\nExamine %s/log/postmaster.log for the reason\n"),
2601  progname, wait_seconds, outputdir);
2602 
2603  /*
2604  * If we get here, the postmaster is probably wedged somewhere in
2605  * startup. Try to kill it ungracefully rather than leaving a
2606  * stuck postmaster that might interfere with subsequent test
2607  * attempts.
2608  */
2609 #ifndef WIN32
2610  if (kill(postmaster_pid, SIGKILL) != 0 &&
2611  errno != ESRCH)
2612  fprintf(stderr, _("\n%s: could not kill failed postmaster: %s\n"),
2613  progname, strerror(errno));
2614 #else
2615  if (TerminateProcess(postmaster_pid, 255) == 0)
2616  fprintf(stderr, _("\n%s: could not kill failed postmaster: error code %lu\n"),
2617  progname, GetLastError());
2618 #endif
2619 
2620  exit(2);
2621  }
2622 
2623  postmaster_running = true;
2624 
2625 #ifdef _WIN64
2626 /* need a series of two casts to convert HANDLE without compiler warning */
2627 #define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2628 #else
2629 #define ULONGPID(x) (unsigned long) (x)
2630 #endif
2631  printf(_("running on port %d with PID %lu\n"),
2633  }
2634  else
2635  {
2636  /*
2637  * Using an existing installation, so may need to get rid of
2638  * pre-existing database(s) and role(s)
2639  */
2640  if (!use_existing)
2641  {
2642  for (sl = dblist; sl; sl = sl->next)
2644  for (sl = extraroles; sl; sl = sl->next)
2645  drop_role_if_exists(sl->str);
2646  }
2647  }
2648 
2649  /*
2650  * Create the test database(s) and role(s)
2651  */
2652  if (!use_existing)
2653  {
2654  for (sl = dblist; sl; sl = sl->next)
2655  create_database(sl->str);
2656  for (sl = extraroles; sl; sl = sl->next)
2657  create_role(sl->str, dblist);
2658  }
2659 
2660  /*
2661  * Ready to run the tests
2662  */
2663  header(_("running regression test queries"));
2664 
2665  for (sl = schedulelist; sl != NULL; sl = sl->next)
2666  {
2667  run_schedule(sl->str, startfunc, postfunc);
2668  }
2669 
2670  for (sl = extra_tests; sl != NULL; sl = sl->next)
2671  {
2672  run_single_test(sl->str, startfunc, postfunc);
2673  }
2674 
2675  /*
2676  * Shut down temp installation's postmaster
2677  */
2678  if (temp_instance)
2679  {
2680  header(_("shutting down postmaster"));
2681  stop_postmaster();
2682  }
2683 
2684  /*
2685  * If there were no errors, remove the temp instance immediately to
2686  * conserve disk space. (If there were errors, we leave the instance in
2687  * place for possible manual investigation.)
2688  */
2689  if (temp_instance && fail_count == 0 && fail_ignore_count == 0)
2690  {
2691  header(_("removing temporary instance"));
2692  if (!rmtree(temp_instance, true))
2693  fprintf(stderr, _("\n%s: could not remove temp instance \"%s\"\n"),
2695  }
2696 
2697  fclose(logfile);
2698 
2699  /*
2700  * Emit nice-looking summary message
2701  */
2702  if (fail_count == 0 && fail_ignore_count == 0)
2703  snprintf(buf, sizeof(buf),
2704  _(" All %d tests passed. "),
2705  success_count);
2706  else if (fail_count == 0) /* fail_count=0, fail_ignore_count>0 */
2707  snprintf(buf, sizeof(buf),
2708  _(" %d of %d tests passed, %d failed test(s) ignored. "),
2709  success_count,
2712  else if (fail_ignore_count == 0) /* fail_count>0 && fail_ignore_count=0 */
2713  snprintf(buf, sizeof(buf),
2714  _(" %d of %d tests failed. "),
2715  fail_count,
2717  else
2718  /* fail_count>0 && fail_ignore_count>0 */
2719  snprintf(buf, sizeof(buf),
2720  _(" %d of %d tests failed, %d of these failures ignored. "),
2724 
2725  putchar('\n');
2726  for (i = strlen(buf); i > 0; i--)
2727  putchar('=');
2728  printf("\n%s\n", buf);
2729  for (i = strlen(buf); i > 0; i--)
2730  putchar('=');
2731  putchar('\n');
2732  putchar('\n');
2733 
2734  if (file_size(difffilename) > 0)
2735  {
2736  printf(_("The differences that caused some tests to fail can be viewed in the\n"
2737  "file \"%s\". A copy of the test summary that you see\n"
2738  "above is saved in the file \"%s\".\n\n"),
2740  }
2741  else
2742  {
2743  unlink(difffilename);
2744  unlink(logfilename);
2745  }
2746 
2747  if (fail_count != 0)
2748  exit(1);
2749 
2750  return 0;
2751 }
char * make_absolute_path(const char *path)
Definition: path.c:608
static bool directory_exists(const char *dir)
Definition: pg_regress.c:1356
static void drop_role_if_exists(const char *rolename)
Definition: pg_regress.c:2108
static void drop_database_if_exists(const char *dbname)
Definition: pg_regress.c:2058
static int max_concurrent_tests
Definition: pg_regress.c:83
static const char * sockdir
Definition: pg_regress.c:104
static int wait_seconds
Definition: pg_ctl.c:80
static _stringlist * extra_tests
Definition: pg_regress.c:86
static void help(void)
Definition: pg_regress.c:2135
char * str
Definition: pg_regress.h:26
static void initialize_environment(void)
Definition: pg_regress.c:741
bool debug
Definition: pg_regress.c:76
const char * get_progname(const char *argv0)
Definition: path.c:453
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
void get_restricted_token(void)
void pg_logging_init(const char *argv0)
Definition: logging.c:81
static char * encoding
Definition: pg_regress.c:84
static const char * progname
Definition: pg_regress.c:100
static void make_directory(const char *dir)
Definition: pg_regress.c:1369
static bool use_existing
Definition: pg_regress.c:90
static bool postmaster_running
Definition: pg_regress.c:114
#define kill(pid, sig)
Definition: win32_port.h:464
#define printf(...)
Definition: port.h:223
static FILE * logfile
Definition: pg_regress.c:102
static void stop_postmaster(void)
Definition: pg_regress.c:262
#define fprintf
Definition: port.h:221
static char * temp_instance
Definition: pg_regress.c:87
char * launcher
Definition: pg_regress.c:80
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
Definition: pg_regress.c:195
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:180
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1235
#define SIGKILL
Definition: win32_port.h:171
#define sprintf
Definition: port.h:219
#define setenv(x, y, z)
Definition: win32_port.h:507
#define true
Definition: c.h:395
static char * difffilename
Definition: pg_regress.c:103
void pg_usleep(long microsec)
Definition: signal.c:53
#define required_argument
Definition: getopt_long.h:25
int optind
Definition: getopt.c:50
static _stringlist * loadextension
Definition: pg_regress.c:81
static void run_schedule(const char *schedule, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:1696
#define MAXPGPATH
_stringlist * dblist
Definition: pg_regress.c:75
static _stringlist * extraroles
Definition: pg_regress.c:96
static _stringlist * temp_configs
Definition: pg_regress.c:88
char * c
const char * pretty_diff_opts
Definition: pg_regress.c:68
static char * buf
Definition: pg_test_fsync.c:68
#define INVALID_PID
Definition: pg_regress.h:15
static void create_role(const char *rolename, const _stringlist *granted_dbs)
Definition: pg_regress.c:2120
static char * dlpath
Definition: pg_regress.c:94
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static int success_count
Definition: pg_regress.c:116
#define DEVNULL
Definition: port.h:148
static int max_connections
Definition: pg_regress.c:82
static int port
Definition: pg_regress.c:92
static PID_TYPE postmaster_pid
Definition: pg_regress.c:113
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:42
#define no_argument
Definition: getopt_long.h:24
static char * config_auth_datadir
Definition: pg_regress.c:97
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1215
static int fail_ignore_count
Definition: pg_regress.c:118
static int fail_count
Definition: pg_regress.c:117
char * outputdir
Definition: pg_regress.c:78
static void prepare_testtablespace_dir(void)
Definition: pg_regress.c:598
static char * logfilename
Definition: pg_regress.c:101
char * inputdir
Definition: pg_regress.c:77
static long file_size(const char *file)
Definition: pg_regress.c:1302
static bool port_specified_by_user
Definition: pg_regress.c:93
char * bindir
Definition: pg_regress.c:79
#define strerror
Definition: port.h:230
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:212
static char * user
Definition: pg_regress.c:95
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:433
char * optarg
Definition: getopt.c:52
static _stringlist * schedulelist
Definition: pg_regress.c:85
struct _stringlist * next
Definition: pg_regress.h:27
int i
static bool nolocale
Definition: pg_regress.c:89
static void open_result_files(void)
Definition: pg_regress.c:2018
static char * hostname
Definition: pg_regress.c:91
#define snprintf
Definition: port.h:217
#define _(x)
Definition: elog.c:89
static void run_single_test(const char *test, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:1950
void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:159
#define ULONGPID(x)
static void create_database(const char *dbname)
Definition: pg_regress.c:2070

◆ replace_string()

void replace_string ( struct StringInfoData string,
const char *  replace,
const char *  replacement 
)

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1235 of file pg_regress.c.

References _, fprintf, logfile, progname, psprintf(), shellprog, generate_unaccent_rules::stdout, and strerror.

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

1236 {
1237 #ifndef WIN32
1238  pid_t pid;
1239 
1240  /*
1241  * Must flush I/O buffers before fork. Ideally we'd use fflush(NULL) here
1242  * ... does anyone still care about systems where that doesn't work?
1243  */
1244  fflush(stdout);
1245  fflush(stderr);
1246  if (logfile)
1247  fflush(logfile);
1248 
1249  pid = fork();
1250  if (pid == -1)
1251  {
1252  fprintf(stderr, _("%s: could not fork: %s\n"),
1253  progname, strerror(errno));
1254  exit(2);
1255  }
1256  if (pid == 0)
1257  {
1258  /*
1259  * In child
1260  *
1261  * Instead of using system(), exec the shell directly, and tell it to
1262  * "exec" the command too. This saves two useless processes per
1263  * parallel test case.
1264  */
1265  char *cmdline2;
1266 
1267  cmdline2 = psprintf("exec %s", cmdline);
1268  execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1269  fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
1270  progname, shellprog, strerror(errno));
1271  _exit(1); /* not exit() here... */
1272  }
1273  /* in parent */
1274  return pid;
1275 #else
1276  PROCESS_INFORMATION pi;
1277  char *cmdline2;
1278  HANDLE restrictedToken;
1279  const char *comspec;
1280 
1281  /* Find CMD.EXE location using COMSPEC, if it's set */
1282  comspec = getenv("COMSPEC");
1283  if (comspec == NULL)
1284  comspec = "CMD";
1285 
1286  memset(&pi, 0, sizeof(pi));
1287  cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
1288 
1289  if ((restrictedToken =
1290  CreateRestrictedProcess(cmdline2, &pi)) == 0)
1291  exit(2);
1292 
1293  CloseHandle(pi.hThread);
1294  return pi.hProcess;
1295 #endif
1296 }
static char * shellprog
Definition: pg_regress.c:58
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static const char * progname
Definition: pg_regress.c:100
static FILE * logfile
Definition: pg_regress.c:102
#define fprintf
Definition: port.h:221
#define strerror
Definition: port.h:230
#define _(x)
Definition: elog.c:89

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts

Definition at line 67 of file pg_regress.c.

Referenced by results_differ().

◆ bindir

char* bindir

Definition at line 79 of file pg_regress.c.

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

◆ datadir

◆ dblist

◆ debug

bool debug

Definition at line 76 of file pg_regress.c.

Referenced by regression_main().

◆ host_platform

char* host_platform

Definition at line 55 of file pg_regress.c.

Referenced by load_resultmap().

◆ inputdir

◆ launcher

char* launcher

Definition at line 80 of file pg_regress.c.

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

◆ libdir

char* libdir

◆ outputdir

◆ pretty_diff_opts

const char* pretty_diff_opts

Definition at line 68 of file pg_regress.c.

Referenced by regression_main(), and results_differ().