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

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 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
struct _stringlist * next
Definition: pg_regress.h:27
char * str
Definition: pg_regress.h:26

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

◆ file_exists()

bool file_exists ( const char *  file)

Definition at line 1187 of file pg_regress.c.

1188 {
1189  FILE *f = fopen(file, "r");
1190 
1191  if (!f)
1192  return false;
1193  fclose(f);
1194  return true;
1195 }

Referenced by 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 2026 of file pg_regress.c.

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

References _, add_stringlist_item(), bindir, buf, config_auth_datadir, create_database(), create_role(), dblist, debug, DEVNULL, difffilename, directory_exists(), dlpath, drop_database_if_exists(), drop_role_if_exists(), encoding, exit(), extra_tests, extraroles, 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, loadextension, 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(), 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, use_existing, user, and wait_seconds.

Referenced by main().

◆ spawn_process()

PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1073 of file pg_regress.c.

1074 {
1075 #ifndef WIN32
1076  pid_t pid;
1077 
1078  /*
1079  * Must flush I/O buffers before fork. Ideally we'd use fflush(NULL) here
1080  * ... does anyone still care about systems where that doesn't work?
1081  */
1082  fflush(stdout);
1083  fflush(stderr);
1084  if (logfile)
1085  fflush(logfile);
1086 
1087 #ifdef EXEC_BACKEND
1088  pg_disable_aslr();
1089 #endif
1090 
1091  pid = fork();
1092  if (pid == -1)
1093  {
1094  fprintf(stderr, _("%s: could not fork: %s\n"),
1095  progname, strerror(errno));
1096  exit(2);
1097  }
1098  if (pid == 0)
1099  {
1100  /*
1101  * In child
1102  *
1103  * Instead of using system(), exec the shell directly, and tell it to
1104  * "exec" the command too. This saves two useless processes per
1105  * parallel test case.
1106  */
1107  char *cmdline2;
1108 
1109  cmdline2 = psprintf("exec %s", cmdline);
1110  execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1111  fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
1112  progname, shellprog, strerror(errno));
1113  _exit(1); /* not exit() here... */
1114  }
1115  /* in parent */
1116  return pid;
1117 #else
1118  PROCESS_INFORMATION pi;
1119  char *cmdline2;
1120  HANDLE restrictedToken;
1121  const char *comspec;
1122 
1123  /* Find CMD.EXE location using COMSPEC, if it's set */
1124  comspec = getenv("COMSPEC");
1125  if (comspec == NULL)
1126  comspec = "CMD";
1127 
1128  memset(&pi, 0, sizeof(pi));
1129  cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
1130 
1131  if ((restrictedToken =
1132  CreateRestrictedProcess(cmdline2, &pi)) == 0)
1133  exit(2);
1134 
1135  CloseHandle(pi.hThread);
1136  return pi.hProcess;
1137 #endif
1138 }
static void const char fflush(stdout)
static char * shellprog
Definition: pg_regress.c:58
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46

References _, exit(), fflush(), 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().

Variable Documentation

◆ basic_diff_opts

const char* basic_diff_opts
extern

Definition at line 67 of file pg_regress.c.

Referenced by results_differ().

◆ bindir

char* bindir
extern

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
extern

Definition at line 76 of file pg_regress.c.

Referenced by regression_main().

◆ host_platform

char* host_platform
extern

Definition at line 55 of file pg_regress.c.

Referenced by load_resultmap().

◆ inputdir

◆ launcher

char* launcher
extern

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

Referenced by regression_main(), and results_differ().