PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_regress.h File Reference
#include "postgres_fe.h"
#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, char *replace, 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

#define INVALID_PID   (-1)
#define PID_TYPE   pid_t

Typedef Documentation

typedef void(* init_function)(int argc, char **argv)

Definition at line 33 of file pg_regress.h.

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

Definition at line 29 of file pg_regress.h.

Function Documentation

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

Definition at line 152 of file pg_regress.c.

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

153 {
154  _stringlist *newentry = pg_malloc(sizeof(_stringlist));
155  _stringlist *oldentry;
156 
157  newentry->str = pg_strdup(str);
158  newentry->next = NULL;
159  if (*listhead == NULL)
160  *listhead = newentry;
161  else
162  {
163  for (oldentry = *listhead; oldentry->next; oldentry = oldentry->next)
164  /* skip */ ;
165  oldentry->next = newentry;
166  }
167 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * str
Definition: pg_regress.h:25
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define NULL
Definition: c.h:226
struct _stringlist * next
Definition: pg_regress.h:26
bool file_exists ( const char *  file)

Definition at line 1228 of file pg_regress.c.

Referenced by results_differ().

1229 {
1230  FILE *f = fopen(file, "r");
1231 
1232  if (!f)
1233  return false;
1234  fclose(f);
1235  return true;
1236 }
int regression_main ( int  argc,
char *  argv[],
init_function  ifunc,
test_function  tfunc 
)

Definition at line 2018 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(), free_stringlist(), get_progname(), getopt_long(), header(), help(), hostname, i, initialize_environment(), inputdir, INVALID_PID, launcher, logfile, logfilename, make_absolute_path(), make_directory(), max_connections, MAXPGPATH, _stringlist::next, no_argument, nolocale, NULL, open_result_files(), optarg, optind, outputdir, pg_strdup(), PG_TEXTDOMAIN, pg_usleep(), port, port_specified_by_user, postmaster_pid, postmaster_running, pretty_diff_opts, progname, required_argument, rmtree(), run_schedule(), run_single_test(), set_pglocale_pgservice(), SIGKILL, snprintf(), sockdir, spawn_process(), split_to_stringlist(), stop_postmaster(), _stringlist::str, strerror(), success_count, temp_instance, ULONGPID, unlink(), use_existing, user, and wait_seconds.

Referenced by main().

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

Definition at line 438 of file pg_regress.c.

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

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

439 {
440  char *ptr;
441 
442  while ((ptr = strstr(string, replace)) != NULL)
443  {
444  char *dup = pg_strdup(string);
445 
446  strlcpy(string, dup, ptr - string + 1);
447  strcat(string, replacement);
448  strcat(string, dup + (ptr - string) + strlen(replace));
449  free(dup);
450  }
451 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:60
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:226
PID_TYPE spawn_process ( const char *  cmdline)

Definition at line 1124 of file pg_regress.c.

References _, logfile, NULL, progname, psprintf(), shellprog, and strerror().

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

1125 {
1126 #ifndef WIN32
1127  pid_t pid;
1128 
1129  /*
1130  * Must flush I/O buffers before fork. Ideally we'd use fflush(NULL) here
1131  * ... does anyone still care about systems where that doesn't work?
1132  */
1133  fflush(stdout);
1134  fflush(stderr);
1135  if (logfile)
1136  fflush(logfile);
1137 
1138  pid = fork();
1139  if (pid == -1)
1140  {
1141  fprintf(stderr, _("%s: could not fork: %s\n"),
1142  progname, strerror(errno));
1143  exit(2);
1144  }
1145  if (pid == 0)
1146  {
1147  /*
1148  * In child
1149  *
1150  * Instead of using system(), exec the shell directly, and tell it to
1151  * "exec" the command too. This saves two useless processes per
1152  * parallel test case.
1153  */
1154  char *cmdline2;
1155 
1156  cmdline2 = psprintf("exec %s", cmdline);
1157  execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
1158  fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
1159  progname, shellprog, strerror(errno));
1160  _exit(1); /* not exit() here... */
1161  }
1162  /* in parent */
1163  return pid;
1164 #else
1165  PROCESS_INFORMATION pi;
1166  char *cmdline2;
1167  HANDLE restrictedToken;
1168 
1169  memset(&pi, 0, sizeof(pi));
1170  cmdline2 = psprintf("cmd /c \"%s\"", cmdline);
1171 
1172  if ((restrictedToken =
1173  CreateRestrictedProcess(cmdline2, &pi, progname)) == 0)
1174  exit(2);
1175 
1176  CloseHandle(pi.hThread);
1177  return pi.hProcess;
1178 #endif
1179 }
static char * shellprog
Definition: pg_regress.c:53
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static const char * progname
Definition: pg_regress.c:95
static FILE * logfile
Definition: pg_regress.c:97
#define NULL
Definition: c.h:226
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84

Variable Documentation

const char* basic_diff_opts

Definition at line 62 of file pg_regress.c.

Referenced by results_differ().

char* bindir

Definition at line 74 of file pg_regress.c.

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

char* host_platform

Definition at line 50 of file pg_regress.c.

Referenced by load_resultmap().

char* launcher

Definition at line 75 of file pg_regress.c.

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

char* libdir
const char* pretty_diff_opts

Definition at line 63 of file pg_regress.c.

Referenced by regression_main(), and results_differ().