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 157 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().

158 {
159  _stringlist *newentry = pg_malloc(sizeof(_stringlist));
160  _stringlist *oldentry;
161 
162  newentry->str = pg_strdup(str);
163  newentry->next = NULL;
164  if (*listhead == NULL)
165  *listhead = newentry;
166  else
167  {
168  for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
169  /* skip */ ;
170  oldentry->next = newentry;
171  }
172 }
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 1266 of file pg_regress.c.

Referenced by results_differ().

1267 {
1268  FILE *f = fopen(file, "r");
1269 
1270  if (!f)
1271  return false;
1272  fclose(f);
1273  return true;
1274 }

◆ regression_main()

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

Definition at line 2090 of file pg_regress.c.

References _, add_stringlist_item(), bindir, buf, 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, 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().

2094 {
2095  static struct option long_options[] = {
2096  {"help", no_argument, NULL, 'h'},
2097  {"version", no_argument, NULL, 'V'},
2098  {"dbname", required_argument, NULL, 1},
2099  {"debug", no_argument, NULL, 2},
2100  {"inputdir", required_argument, NULL, 3},
2101  {"max-connections", required_argument, NULL, 5},
2102  {"encoding", required_argument, NULL, 6},
2103  {"outputdir", required_argument, NULL, 7},
2104  {"schedule", required_argument, NULL, 8},
2105  {"temp-instance", required_argument, NULL, 9},
2106  {"no-locale", no_argument, NULL, 10},
2107  {"host", required_argument, NULL, 13},
2108  {"port", required_argument, NULL, 14},
2109  {"user", required_argument, NULL, 15},
2110  {"bindir", required_argument, NULL, 16},
2111  {"dlpath", required_argument, NULL, 17},
2112  {"create-role", required_argument, NULL, 18},
2113  {"temp-config", required_argument, NULL, 19},
2114  {"use-existing", no_argument, NULL, 20},
2115  {"launcher", required_argument, NULL, 21},
2116  {"load-extension", required_argument, NULL, 22},
2117  {"config-auth", required_argument, NULL, 24},
2118  {"max-concurrent-tests", required_argument, NULL, 25},
2119  {NULL, 0, NULL, 0}
2120  };
2121 
2122  bool use_unix_sockets;
2123  _stringlist *sl;
2124  int c;
2125  int i;
2126  int option_index;
2127  char buf[MAXPGPATH * 4];
2128  char buf2[MAXPGPATH * 4];
2129 
2130  pg_logging_init(argv[0]);
2131  progname = get_progname(argv[0]);
2132  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_regress"));
2133 
2135 
2136  atexit(stop_postmaster);
2137 
2138 #if !defined(HAVE_UNIX_SOCKETS)
2139  use_unix_sockets = false;
2140 #elif defined(WIN32)
2141 
2142  /*
2143  * We don't use Unix-domain sockets on Windows by default, even if the
2144  * build supports them. (See comment at remove_temp() for a reason.)
2145  * Override at your own risk.
2146  */
2147  use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false;
2148 #else
2149  use_unix_sockets = true;
2150 #endif
2151 
2152  if (!use_unix_sockets)
2153  hostname = "localhost";
2154 
2155  /*
2156  * We call the initialization function here because that way we can set
2157  * default parameters and let them be overwritten by the commandline.
2158  */
2159  ifunc(argc, argv);
2160 
2161  if (getenv("PG_REGRESS_DIFF_OPTS"))
2162  pretty_diff_opts = getenv("PG_REGRESS_DIFF_OPTS");
2163 
2164  while ((c = getopt_long(argc, argv, "hV", long_options, &option_index)) != -1)
2165  {
2166  switch (c)
2167  {
2168  case 'h':
2169  help();
2170  exit(0);
2171  case 'V':
2172  puts("pg_regress (PostgreSQL) " PG_VERSION);
2173  exit(0);
2174  case 1:
2175 
2176  /*
2177  * If a default database was specified, we need to remove it
2178  * before we add the specified one.
2179  */
2182  break;
2183  case 2:
2184  debug = true;
2185  break;
2186  case 3:
2188  break;
2189  case 5:
2190  max_connections = atoi(optarg);
2191  break;
2192  case 6:
2194  break;
2195  case 7:
2197  break;
2198  case 8:
2200  break;
2201  case 9:
2203  break;
2204  case 10:
2205  nolocale = true;
2206  break;
2207  case 13:
2209  break;
2210  case 14:
2211  port = atoi(optarg);
2212  port_specified_by_user = true;
2213  break;
2214  case 15:
2215  user = pg_strdup(optarg);
2216  break;
2217  case 16:
2218  /* "--bindir=" means to use PATH */
2219  if (strlen(optarg))
2220  bindir = pg_strdup(optarg);
2221  else
2222  bindir = NULL;
2223  break;
2224  case 17:
2225  dlpath = pg_strdup(optarg);
2226  break;
2227  case 18:
2229  break;
2230  case 19:
2232  break;
2233  case 20:
2234  use_existing = true;
2235  break;
2236  case 21:
2238  break;
2239  case 22:
2241  break;
2242  case 24:
2244  break;
2245  case 25:
2246  max_concurrent_tests = atoi(optarg);
2247  break;
2248  default:
2249  /* getopt_long already emitted a complaint */
2250  fprintf(stderr, _("\nTry \"%s -h\" for more information.\n"),
2251  progname);
2252  exit(2);
2253  }
2254  }
2255 
2256  /*
2257  * if we still have arguments, they are extra tests to run
2258  */
2259  while (argc - optind >= 1)
2260  {
2262  optind++;
2263  }
2264 
2265  if (config_auth_datadir)
2266  {
2267 #ifdef ENABLE_SSPI
2268  if (!use_unix_sockets)
2269  config_sspi_auth(config_auth_datadir, user);
2270 #endif
2271  exit(0);
2272  }
2273 
2275 
2276  /*
2277  * To reduce chances of interference with parallel installations, use
2278  * a port number starting in the private range (49152-65535)
2279  * calculated from the version number. This aids !HAVE_UNIX_SOCKETS
2280  * systems; elsewhere, the use of a private socket directory already
2281  * prevents interference.
2282  */
2283  port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2284 
2288 
2289  /*
2290  * Initialization
2291  */
2293 
2295 
2296 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE)
2297  unlimit_core_size();
2298 #endif
2299 
2300  if (temp_instance)
2301  {
2302  FILE *pg_conf;
2303  const char *env_wait;
2304  int wait_seconds;
2305 
2306  /*
2307  * Prepare the temp instance
2308  */
2309 
2311  {
2312  header(_("removing existing temp instance"));
2313  if (!rmtree(temp_instance, true))
2314  {
2315  fprintf(stderr, _("\n%s: could not remove temp instance \"%s\"\n"),
2317  exit(2);
2318  }
2319  }
2320 
2321  header(_("creating temporary instance"));
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))
2329  make_directory(buf);
2330 
2331  /* initdb */
2332  header(_("initializing database system"));
2333  snprintf(buf, sizeof(buf),
2334  "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync%s%s > \"%s/log/initdb.log\" 2>&1",
2335  bindir ? bindir : "",
2336  bindir ? "/" : "",
2337  temp_instance,
2338  debug ? " --debug" : "",
2339  nolocale ? " --no-locale" : "",
2340  outputdir);
2341  if (system(buf))
2342  {
2343  fprintf(stderr, _("\n%s: initdb failed\nExamine %s/log/initdb.log for the reason.\nCommand was: %s\n"), progname, outputdir, buf);
2344  exit(2);
2345  }
2346 
2347  /*
2348  * Adjust the default postgresql.conf for regression testing. The user
2349  * can specify a file to be appended; in any case we expand logging
2350  * and set max_prepared_transactions to enable testing of prepared
2351  * xacts. (Note: to reduce the probability of unexpected shmmax
2352  * failures, don't set max_prepared_transactions any higher than
2353  * actually needed by the prepared_xacts regression test.)
2354  */
2355  snprintf(buf, sizeof(buf), "%s/data/postgresql.conf", temp_instance);
2356  pg_conf = fopen(buf, "a");
2357  if (pg_conf == NULL)
2358  {
2359  fprintf(stderr, _("\n%s: could not open \"%s\" for adding extra config: %s\n"), progname, buf, strerror(errno));
2360  exit(2);
2361  }
2362  fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
2363  fputs("log_autovacuum_min_duration = 0\n", pg_conf);
2364  fputs("log_checkpoints = on\n", pg_conf);
2365  fputs("log_line_prefix = '%m %b[%p] %q%a '\n", pg_conf);
2366  fputs("log_lock_waits = on\n", pg_conf);
2367  fputs("log_temp_files = 128kB\n", pg_conf);
2368  fputs("max_prepared_transactions = 2\n", pg_conf);
2369 
2370  for (sl = temp_configs; sl != NULL; sl = sl->next)
2371  {
2372  char *temp_config = sl->str;
2373  FILE *extra_conf;
2374  char line_buf[1024];
2375 
2376  extra_conf = fopen(temp_config, "r");
2377  if (extra_conf == NULL)
2378  {
2379  fprintf(stderr, _("\n%s: could not open \"%s\" to read extra config: %s\n"), progname, temp_config, strerror(errno));
2380  exit(2);
2381  }
2382  while (fgets(line_buf, sizeof(line_buf), extra_conf) != NULL)
2383  fputs(line_buf, pg_conf);
2384  fclose(extra_conf);
2385  }
2386 
2387  fclose(pg_conf);
2388 
2389 #ifdef ENABLE_SSPI
2390  if (!use_unix_sockets)
2391  {
2392  /*
2393  * Since we successfully used the same buffer for the much-longer
2394  * "initdb" command, this can't truncate.
2395  */
2396  snprintf(buf, sizeof(buf), "%s/data", temp_instance);
2397  config_sspi_auth(buf, NULL);
2398  }
2399 #elif !defined(HAVE_UNIX_SOCKETS)
2400 #error Platform has no means to secure the test installation.
2401 #endif
2402 
2403  /*
2404  * Check if there is a postmaster running already.
2405  */
2406  snprintf(buf2, sizeof(buf2),
2407  "\"%s%spsql\" -X postgres <%s 2>%s",
2408  bindir ? bindir : "",
2409  bindir ? "/" : "",
2410  DEVNULL, DEVNULL);
2411 
2412  for (i = 0; i < 16; i++)
2413  {
2414  if (system(buf2) == 0)
2415  {
2416  char s[16];
2417 
2418  if (port_specified_by_user || i == 15)
2419  {
2420  fprintf(stderr, _("port %d apparently in use\n"), port);
2422  fprintf(stderr, _("%s: could not determine an available port\n"), progname);
2423  fprintf(stderr, _("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.\n"));
2424  exit(2);
2425  }
2426 
2427  fprintf(stderr, _("port %d apparently in use, trying %d\n"), port, port + 1);
2428  port++;
2429  sprintf(s, "%d", port);
2430  setenv("PGPORT", s, 1);
2431  }
2432  else
2433  break;
2434  }
2435 
2436  /*
2437  * Start the temp postmaster
2438  */
2439  header(_("starting postmaster"));
2440  snprintf(buf, sizeof(buf),
2441  "\"%s%spostgres\" -D \"%s/data\" -F%s "
2442  "-c \"listen_addresses=%s\" -k \"%s\" "
2443  "> \"%s/log/postmaster.log\" 2>&1",
2444  bindir ? bindir : "",
2445  bindir ? "/" : "",
2446  temp_instance, debug ? " -d 5" : "",
2447  hostname ? hostname : "", sockdir ? sockdir : "",
2448  outputdir);
2450  if (postmaster_pid == INVALID_PID)
2451  {
2452  fprintf(stderr, _("\n%s: could not spawn postmaster: %s\n"),
2453  progname, strerror(errno));
2454  exit(2);
2455  }
2456 
2457  /*
2458  * Wait till postmaster is able to accept connections; normally this
2459  * is only a second or so, but Cygwin is reportedly *much* slower, and
2460  * test builds using Valgrind or similar tools might be too. Hence,
2461  * allow the default timeout of 60 seconds to be overridden from the
2462  * PGCTLTIMEOUT environment variable.
2463  */
2464  env_wait = getenv("PGCTLTIMEOUT");
2465  if (env_wait != NULL)
2466  {
2467  wait_seconds = atoi(env_wait);
2468  if (wait_seconds <= 0)
2469  wait_seconds = 60;
2470  }
2471  else
2472  wait_seconds = 60;
2473 
2474  for (i = 0; i < wait_seconds; i++)
2475  {
2476  /* Done if psql succeeds */
2477  if (system(buf2) == 0)
2478  break;
2479 
2480  /*
2481  * Fail immediately if postmaster has exited
2482  */
2483 #ifndef WIN32
2484  if (waitpid(postmaster_pid, NULL, WNOHANG) == postmaster_pid)
2485 #else
2486  if (WaitForSingleObject(postmaster_pid, 0) == WAIT_OBJECT_0)
2487 #endif
2488  {
2489  fprintf(stderr, _("\n%s: postmaster failed\nExamine %s/log/postmaster.log for the reason\n"), progname, outputdir);
2490  exit(2);
2491  }
2492 
2493  pg_usleep(1000000L);
2494  }
2495  if (i >= wait_seconds)
2496  {
2497  fprintf(stderr, _("\n%s: postmaster did not respond within %d seconds\nExamine %s/log/postmaster.log for the reason\n"),
2498  progname, wait_seconds, outputdir);
2499 
2500  /*
2501  * If we get here, the postmaster is probably wedged somewhere in
2502  * startup. Try to kill it ungracefully rather than leaving a
2503  * stuck postmaster that might interfere with subsequent test
2504  * attempts.
2505  */
2506 #ifndef WIN32
2507  if (kill(postmaster_pid, SIGKILL) != 0 &&
2508  errno != ESRCH)
2509  fprintf(stderr, _("\n%s: could not kill failed postmaster: %s\n"),
2510  progname, strerror(errno));
2511 #else
2512  if (TerminateProcess(postmaster_pid, 255) == 0)
2513  fprintf(stderr, _("\n%s: could not kill failed postmaster: error code %lu\n"),
2514  progname, GetLastError());
2515 #endif
2516 
2517  exit(2);
2518  }
2519 
2520  postmaster_running = true;
2521 
2522 #ifdef _WIN64
2523 /* need a series of two casts to convert HANDLE without compiler warning */
2524 #define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2525 #else
2526 #define ULONGPID(x) (unsigned long) (x)
2527 #endif
2528  printf(_("running on port %d with PID %lu\n"),
2530  }
2531  else
2532  {
2533  /*
2534  * Using an existing installation, so may need to get rid of
2535  * pre-existing database(s) and role(s)
2536  */
2537  if (!use_existing)
2538  {
2539  for (sl = dblist; sl; sl = sl->next)
2541  for (sl = extraroles; sl; sl = sl->next)
2542  drop_role_if_exists(sl->str);
2543  }
2544  }
2545 
2546  /*
2547  * Create the test database(s) and role(s)
2548  */
2549  if (!use_existing)
2550  {
2551  for (sl = dblist; sl; sl = sl->next)
2552  create_database(sl->str);
2553  for (sl = extraroles; sl; sl = sl->next)
2554  create_role(sl->str, dblist);
2555  }
2556 
2557  /*
2558  * Ready to run the tests
2559  */
2560  header(_("running regression test queries"));
2561 
2562  for (sl = schedulelist; sl != NULL; sl = sl->next)
2563  {
2564  run_schedule(sl->str, startfunc, postfunc);
2565  }
2566 
2567  for (sl = extra_tests; sl != NULL; sl = sl->next)
2568  {
2569  run_single_test(sl->str, startfunc, postfunc);
2570  }
2571 
2572  /*
2573  * Shut down temp installation's postmaster
2574  */
2575  if (temp_instance)
2576  {
2577  header(_("shutting down postmaster"));
2578  stop_postmaster();
2579  }
2580 
2581  /*
2582  * If there were no errors, remove the temp instance immediately to
2583  * conserve disk space. (If there were errors, we leave the instance in
2584  * place for possible manual investigation.)
2585  */
2586  if (temp_instance && fail_count == 0 && fail_ignore_count == 0)
2587  {
2588  header(_("removing temporary instance"));
2589  if (!rmtree(temp_instance, true))
2590  fprintf(stderr, _("\n%s: could not remove temp instance \"%s\"\n"),
2592  }
2593 
2594  fclose(logfile);
2595 
2596  /*
2597  * Emit nice-looking summary message
2598  */
2599  if (fail_count == 0 && fail_ignore_count == 0)
2600  snprintf(buf, sizeof(buf),
2601  _(" All %d tests passed. "),
2602  success_count);
2603  else if (fail_count == 0) /* fail_count=0, fail_ignore_count>0 */
2604  snprintf(buf, sizeof(buf),
2605  _(" %d of %d tests passed, %d failed test(s) ignored. "),
2606  success_count,
2609  else if (fail_ignore_count == 0) /* fail_count>0 && fail_ignore_count=0 */
2610  snprintf(buf, sizeof(buf),
2611  _(" %d of %d tests failed. "),
2612  fail_count,
2614  else
2615  /* fail_count>0 && fail_ignore_count>0 */
2616  snprintf(buf, sizeof(buf),
2617  _(" %d of %d tests failed, %d of these failures ignored. "),
2621 
2622  putchar('\n');
2623  for (i = strlen(buf); i > 0; i--)
2624  putchar('=');
2625  printf("\n%s\n", buf);
2626  for (i = strlen(buf); i > 0; i--)
2627  putchar('=');
2628  putchar('\n');
2629  putchar('\n');
2630 
2631  if (file_size(difffilename) > 0)
2632  {
2633  printf(_("The differences that caused some tests to fail can be viewed in the\n"
2634  "file \"%s\". A copy of the test summary that you see\n"
2635  "above is saved in the file \"%s\".\n\n"),
2637  }
2638  else
2639  {
2640  unlink(difffilename);
2641  unlink(logfilename);
2642  }
2643 
2644  if (fail_count != 0)
2645  exit(1);
2646 
2647  return 0;
2648 }
char * make_absolute_path(const char *path)
Definition: path.c:608
static bool directory_exists(const char *dir)
Definition: pg_regress.c:1277
static void drop_role_if_exists(const char *rolename)
Definition: pg_regress.c:2022
static void drop_database_if_exists(const char *dbname)
Definition: pg_regress.c:1979
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:2041
char * str
Definition: pg_regress.h:26
static void initialize_environment(void)
Definition: pg_regress.c:729
bool debug
Definition: pg_regress.c:76
const char * get_progname(const char *argv0)
Definition: path.c:453
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:157
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:1290
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:454
#define printf(...)
Definition: port.h:222
static FILE * logfile
Definition: pg_regress.c:102
static void stop_postmaster(void)
Definition: pg_regress.c:260
#define fprintf
Definition: port.h:220
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:193
static void free_stringlist(_stringlist **listhead)
Definition: pg_regress.c:178
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1156
#define SIGKILL
Definition: win32_port.h:163
#define sprintf
Definition: port.h:218
#define setenv(x, y, z)
Definition: win32_port.h:497
#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:1617
#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:2029
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:147
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 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:1223
static bool port_specified_by_user
Definition: pg_regress.c:93
char * bindir
Definition: pg_regress.c:79
#define strerror
Definition: port.h:229
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:210
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:1939
static char * hostname
Definition: pg_regress.c:91
#define snprintf
Definition: port.h:216
#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:1871
#define ULONGPID(x)
static void create_database(const char *dbname)
Definition: pg_regress.c:1986

◆ 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 1156 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().

1157 {
1158 #ifndef WIN32
1159  pid_t pid;
1160 
1161  /*
1162  * Must flush I/O buffers before fork. Ideally we'd use fflush(NULL) here
1163  * ... does anyone still care about systems where that doesn't work?
1164  */
1165  fflush(stdout);
1166  fflush(stderr);
1167  if (logfile)
1168  fflush(logfile);
1169 
1170  pid = fork();
1171  if (pid == -1)
1172  {
1173  fprintf(stderr, _("%s: could not fork: %s\n"),
1174  progname, strerror(errno));
1175  exit(2);
1176  }
1177  if (pid == 0)
1178  {
1179  /*
1180  * In child
1181  *
1182  * Instead of using system(), exec the shell directly, and tell it to
1183  * "exec" the command too. This saves two useless processes per
1184  * parallel test case.
1185  */
1186  char *cmdline2;
1187 
1188  cmdline2 = psprintf("exec %s", cmdline);
1189  execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1190  fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
1191  progname, shellprog, strerror(errno));
1192  _exit(1); /* not exit() here... */
1193  }
1194  /* in parent */
1195  return pid;
1196 #else
1197  PROCESS_INFORMATION pi;
1198  char *cmdline2;
1199  HANDLE restrictedToken;
1200  const char *comspec;
1201 
1202  /* Find CMD.EXE location using COMSPEC, if it's set */
1203  comspec = getenv("COMSPEC");
1204  if (comspec == NULL)
1205  comspec = "CMD";
1206 
1207  memset(&pi, 0, sizeof(pi));
1208  cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
1209 
1210  if ((restrictedToken =
1211  CreateRestrictedProcess(cmdline2, &pi)) == 0)
1212  exit(2);
1213 
1214  CloseHandle(pi.hThread);
1215  return pi.hProcess;
1216 #endif
1217 }
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:220
#define strerror
Definition: port.h:229
#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_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().