2073{
2074 static struct option long_options[] = {
2099 {NULL, 0, NULL, 0}
2100 };
2101
2102 bool use_unix_sockets;
2106 int option_index;
2108
2112
2114
2116
2117#if defined(WIN32)
2118
2119
2120
2121
2122
2123 use_unix_sockets = getenv(
"PG_TEST_USE_UNIX_SOCKETS") ?
true :
false;
2124#else
2125 use_unix_sockets = true;
2126#endif
2127
2128 if (!use_unix_sockets)
2130
2131
2132
2133
2134
2135 ifunc(argc, argv);
2136
2137 if (getenv("PG_REGRESS_DIFF_OPTS"))
2139
2140 while ((
c =
getopt_long(argc, argv,
"hV", long_options, &option_index)) != -1)
2141 {
2143 {
2144 case 'h':
2146 exit(0);
2147 case 'V':
2148 puts("pg_regress (PostgreSQL) " PG_VERSION);
2149 exit(0);
2150 case 1:
2151
2152
2153
2154
2155
2158 break;
2159 case 2:
2161 break;
2162 case 3:
2164 break;
2165 case 5:
2167 break;
2168 case 6:
2170 break;
2171 case 7:
2173 break;
2174 case 8:
2176 break;
2177 case 9:
2179 break;
2180 case 10:
2182 break;
2183 case 13:
2185 break;
2186 case 14:
2189 break;
2190 case 15:
2192 break;
2193 case 16:
2194
2197 else
2199 break;
2200 case 17:
2202 break;
2203 case 18:
2205 break;
2206 case 19:
2208 break;
2209 case 20:
2211 break;
2212 case 21:
2214 break;
2215 case 22:
2217 break;
2218 case 24:
2220 break;
2221 case 25:
2223 break;
2224 case 26:
2226 break;
2227 default:
2228
2231 exit(2);
2232 }
2233 }
2234
2235
2236
2237
2238 while (argc -
optind >= 1)
2239 {
2242 }
2243
2244
2245
2246
2247
2249 {
2250 bail(
"no database name was specified");
2251 }
2252
2254 {
2255#ifdef ENABLE_SSPI
2256 if (!use_unix_sockets)
2258#endif
2259 exit(0);
2260 }
2261
2263
2264
2265
2266
2267
2268
2269
2270
2271 port = 0xC000 | (PG_VERSION_NUM & 0x3FFF);
2272
2277
2278
2279
2280
2282
2284
2285#if defined(HAVE_GETRLIMIT)
2287#endif
2288
2290 {
2292 FILE *pg_conf;
2293 const char *env_wait;
2295 const char *initdb_template_dir;
2299 const char *initdb_extra_opts_env;
2300
2301
2302
2303
2304
2306 {
2308 {
2310 }
2311 }
2312
2313
2315
2316
2320
2321 initdb_extra_opts_env = getenv("PG_TEST_INITDB_EXTRA_OPTS");
2322
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334 initdb_template_dir = getenv("INITDB_TEMPLATE");
2335 if (initdb_template_dir == NULL ||
nolocale ||
debug || initdb_extra_opts_env)
2336 {
2337 note(
"initializing database system by running initdb");
2338
2340 "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync",
2348 if (initdb_extra_opts_env)
2351 fflush(NULL);
2352 if (system(cmd.
data))
2353 {
2354 bail(
"initdb failed\n"
2355 "# Examine \"%s/log/initdb.log\" for the reason.\n"
2356 "# Command was: %s",
2358 }
2359 }
2360 else
2361 {
2362#ifndef WIN32
2363 const char *copycmd = "cp -RPp \"%s\" \"%s/data\"";
2364 int expected_exitcode = 0;
2365#else
2366 const char *copycmd = "robocopy /E /NJS /NJH /NFL /NDL /NP \"%s\" \"%s/data\"";
2367 int expected_exitcode = 1;
2368#endif
2369
2370 note(
"initializing database system by copying initdb template");
2371
2373 copycmd,
2374 initdb_template_dir,
2377 fflush(NULL);
2378 if (system(cmd.
data) != expected_exitcode)
2379 {
2380 bail(
"copying of initdb template failed\n"
2381 "# Examine \"%s/log/initdb.log\" for the reason.\n"
2382 "# Command was: %s",
2384 }
2385 }
2386
2388
2389
2390
2391
2392
2393
2394
2395
2396
2398 pg_conf = fopen(
buf,
"a");
2399 if (pg_conf == NULL)
2400 bail(
"could not open \"%s\" for adding extra config: %m",
buf);
2401
2402 fputs("\n# Configuration added by pg_regress\n\n", pg_conf);
2403 fputs("log_autovacuum_min_duration = 0\n", pg_conf);
2404 fputs("log_autoanalyze_min_duration = 0\n", pg_conf);
2405 fputs("log_checkpoints = on\n", pg_conf);
2406 fputs("log_line_prefix = '%m %b[%p] %q%a '\n", pg_conf);
2407 fputs("log_lock_waits = on\n", pg_conf);
2408 fputs("log_temp_files = 128kB\n", pg_conf);
2409 fputs("max_prepared_transactions = 2\n", pg_conf);
2410
2412 {
2413 char *temp_config = sl->
str;
2414 FILE *extra_conf;
2415 char line_buf[1024];
2416
2417 extra_conf = fopen(temp_config, "r");
2418 if (extra_conf == NULL)
2419 {
2420 bail(
"could not open \"%s\" to read extra config: %m",
2421 temp_config);
2422 }
2423 while (fgets(line_buf, sizeof(line_buf), extra_conf) != NULL)
2424 fputs(line_buf, pg_conf);
2425 fclose(extra_conf);
2426 }
2427
2428 fclose(pg_conf);
2429
2430#ifdef ENABLE_SSPI
2431 if (!use_unix_sockets)
2432 {
2433
2434
2435
2436
2438 config_sspi_auth(
buf, NULL);
2439 }
2440#endif
2441
2442
2443
2444
2445
2455
2456
2457
2458
2459 for (
i = 0;
i < 16;
i++)
2460 {
2462
2464 {
2466 {
2467 note(
"port %d apparently in use",
port);
2469 note(
"could not determine an available port");
2470 bail(
"Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.");
2471 }
2472
2473 note(
"port %d apparently in use, trying %d",
port,
port + 1);
2477 }
2478 else
2479 break;
2480 }
2481
2482
2483
2484
2486 "\"%s%spostgres\" -D \"%s/data\" -F%s "
2487 "-c \"listen_addresses=%s\" -k \"%s\" "
2488 "> \"%s/log/postmaster.log\" 2>&1",
2496 bail(
"could not spawn postmaster: %m");
2497
2498
2499
2500
2501
2502
2503
2504
2505 env_wait = getenv("PGCTLTIMEOUT");
2506 if (env_wait != NULL)
2507 {
2511 }
2512 else
2514
2516 {
2517
2518
2519
2520
2521
2523
2525
2526
2528 break;
2529
2531 bail(
"attempting to connect to postmaster failed");
2532
2533
2534
2535
2536#ifndef WIN32
2538#else
2540#endif
2541 {
2542 bail(
"postmaster failed, examine \"%s/log/postmaster.log\" for the reason",
2544 }
2545 }
2547 {
2548 diag(
"postmaster did not respond within %d seconds, examine \"%s/log/postmaster.log\" for the reason",
2550
2551
2552
2553
2554
2555
2556
2557#ifndef WIN32
2559 bail(
"could not kill failed postmaster: %m");
2560#else
2562 bail(
"could not kill failed postmaster: error code %lu",
2563 GetLastError());
2564#endif
2565 bail(
"postmaster failed");
2566 }
2567
2569
2570#ifdef _WIN64
2571
2572#define ULONGPID(x) (unsigned long) (unsigned long long) (x)
2573#else
2574#define ULONGPID(x) (unsigned long) (x)
2575#endif
2576 note(
"using temp instance on port %d with PID %lu",
2578 }
2579 else
2580 {
2581
2582
2583
2584
2586 {
2591 }
2592 }
2593
2594
2595
2596
2598 {
2603 }
2604
2605
2606
2607
2609 {
2611 }
2612
2614 {
2616 }
2617
2618
2619
2620
2622 {
2624 }
2625
2626
2627
2628
2629
2630
2632 {
2634 diag(
"could not remove temp instance \"%s\"",
2636 }
2637
2638
2639
2640
2642
2643
2644
2645
2648 else
2650
2652 {
2653 diag(
"The differences that caused some tests to fail can be viewed in the file \"%s\".",
2655 diag(
"A copy of the test summary that you see above is saved in the file \"%s\".",
2657 }
2658 else
2659 {
2662 }
2663
2666
2668 exit(1);
2669
2670 return 0;
2671}
static Datum values[MAXATTR]
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
PGPing PQpingParams(const char *const *keywords, const char *const *values, int expand_dbname)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
static const JsonPathKeyword keywords[]
void pg_logging_init(const char *argv0)
#define pg_log_error_hint(...)
void pfree(void *pointer)
PGDLLIMPORT char * optarg
static void open_result_files(void)
static int max_connections
static bool port_specified_by_user
static void stop_postmaster(void)
static int max_concurrent_tests
static void create_database(const char *dbname)
static void free_stringlist(_stringlist **listhead)
static void drop_role_if_exists(const char *rolename)
static void unlimit_core_size(void)
static bool directory_exists(const char *dir)
static _stringlist * schedulelist
#define WAIT_TICKS_PER_SECOND
static _stringlist * loadextension
static char * logfilename
static _stringlist * temp_configs
static _stringlist * extra_tests
static void make_directory(const char *dir)
static void split_to_stringlist(const char *s, const char *delim, _stringlist **listhead)
static void run_single_test(const char *test, test_start_function startfunc, postprocess_result_function postfunc)
const char * pretty_diff_opts
static char * difffilename
static char * config_auth_datadir
static void drop_database_if_exists(const char *dbname)
static void initialize_environment(void)
static char * temp_instance
static const char * sockdir
static long file_size(const char *file)
static bool postmaster_running
static const char * progname
static _stringlist * extraroles
PID_TYPE spawn_process(const char *cmdline)
static void create_role(const char *rolename, const _stringlist *granted_dbs)
static void run_schedule(const char *schedule, test_start_function startfunc, postprocess_result_function postfunc)
void add_stringlist_item(_stringlist **listhead, const char *str)
static PID_TYPE postmaster_pid
char * make_absolute_path(const char *path)
const char * get_progname(const char *argv0)
void get_restricted_token(void)
bool rmtree(const char *path, bool rmtopdir)
void pg_usleep(long microsec)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)