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 PID_TYPE(* test_function) (const char *, _stringlist **, _stringlist **, _stringlist **)
 
typedef void(* init_function) (int argc, char **argv)
 

Functions

int regression_main (int argc, char *argv[], init_function ifunc, test_function tfunc)
 
void add_stringlist_item (_stringlist **listhead, const char *str)
 
PID_TYPE spawn_process (const char *cmdline)
 
void replace_string (char *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 32 of file pg_regress.h.

◆ test_function

typedef PID_TYPE(* test_function) (const char *, _stringlist **, _stringlist **, _stringlist **)

Definition at line 28 of file pg_regress.h.

Function Documentation

◆ add_stringlist_item()

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

Definition at line 155 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().

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

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1262 of file pg_regress.c.

Referenced by results_differ().

1263 {
1264  FILE *f = fopen(file, "r");
1265 
1266  if (!f)
1267  return false;
1268  fclose(f);
1269  return true;
1270 }

◆ regression_main()

int regression_main ( int  argc,
char *  argv[],
init_function  ifunc,
test_function  tfunc 
)

Definition at line 2080 of file pg_regress.c.

References _, add_stringlist_item(), bindir, buf, config_auth_datadir, create_database(), create_role(), debug, DEVNULL, difffilename, directory_exists(), dlpath, doputenv(), 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(), 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().

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

◆ replace_string()

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

Definition at line 442 of file pg_regress.c.

References free, pg_strdup(), and strlcpy().

Referenced by convert_sourcefiles_in(), ecpg_filter(), and ecpg_start_test().

443 {
444  char *ptr;
445 
446  while ((ptr = strstr(string, replace)) != NULL)
447  {
448  char *dup = pg_strdup(string);
449 
450  strlcpy(string, dup, ptr - string + 1);
451  strcat(string, replacement);
452  strcat(string, dup + (ptr - string) + strlen(replace));
453  free(dup);
454  }
455 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1152 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().

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

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts

Definition at line 65 of file pg_regress.c.

Referenced by results_differ().

◆ bindir

char* bindir

Definition at line 77 of file pg_regress.c.

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

◆ datadir

char* datadir

◆ dblist

◆ debug

◆ host_platform

char* host_platform

Definition at line 53 of file pg_regress.c.

Referenced by load_resultmap().

◆ inputdir

◆ launcher

char* launcher

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

Referenced by regression_main(), and results_differ().