1 /*-------------------------------------------------------------------------
3 * isolation_main --- pg_regress test launcher for isolation tests
5 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
8 * src/test/isolation/isolation_main.c
10 *-------------------------------------------------------------------------
13 #include "pg_regress.h"
15 char saved_argv0[MAXPGPATH];
16 char isolation_exec[MAXPGPATH];
17 bool looked_up_isolation_exec = false;
19 #define PG_ISOLATION_VERSIONSTR "isolationtester (PostgreSQL) " PG_VERSION "\n"
22 * start an isolation tester process for specified file (including
23 * redirection), and return process ID
26 isolation_start_test(const char *testname,
27 _stringlist **resultfiles,
28 _stringlist **expectfiles,
32 char infile[MAXPGPATH];
33 char outfile[MAXPGPATH];
34 char expectfile[MAXPGPATH];
35 char psql_cmd[MAXPGPATH * 3];
38 /* need to do the path lookup here, check isolation_init() for details */
39 if (!looked_up_isolation_exec)
41 /* look for isolationtester binary */
42 if (find_other_exec(saved_argv0, "isolationtester",
43 PG_ISOLATION_VERSIONSTR, isolation_exec) != 0)
45 fprintf(stderr, _("could not find proper isolationtester binary\n"));
48 looked_up_isolation_exec = true;
52 * Look for files in the output dir first, consistent with a vpath search.
53 * This is mainly to create more reasonable error messages if the file is
54 * not found. It also allows local test overrides when running pg_regress
55 * outside of the source tree.
57 snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
59 if (!file_exists(infile))
60 snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
63 snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
66 snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
68 if (!file_exists(expectfile))
69 snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
72 add_stringlist_item(resultfiles, outfile);
73 add_stringlist_item(expectfiles, expectfile);
76 offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
79 snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
80 "\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1",
86 pid = spawn_process(psql_cmd);
88 if (pid == INVALID_PID)
90 fprintf(stderr, _("could not start process for test %s\n"),
99 isolation_init(int argc, char **argv)
104 * We unfortunately cannot do the find_other_exec() lookup to find the
105 * "isolationtester" binary here. regression_main() calls the
106 * initialization functions before parsing the commandline arguments and
107 * thus hasn't changed the library search path at this point which in turn
108 * can cause the "isolationtester -V" invocation that find_other_exec()
109 * does to fail since it's linked to libpq. So we instead copy argv[0]
110 * and do the lookup the first time through isolation_start_test().
112 argv0_len = strlcpy(saved_argv0, argv[0], MAXPGPATH);
113 if (argv0_len >= MAXPGPATH)
115 fprintf(stderr, _("path for isolationtester executable is longer than %d bytes\n"),
116 (int) (MAXPGPATH - 1));
120 /* set default regression database name */
121 add_stringlist_item(&dblist, "isolation_regression");
125 main(int argc, char *argv[])
127 return regression_main(argc, argv, isolation_init, isolation_start_test);