PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
isolation_main.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * isolation_main --- pg_regress test launcher for isolation tests
4  *
5  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
6  * Portions Copyright (c) 1994, Regents of the University of California
7  *
8  * src/test/isolation/isolation_main.c
9  *
10  *-------------------------------------------------------------------------
11  */
12 
13 #include "pg_regress.h"
14 
18 
19 #define PG_ISOLATION_VERSIONSTR "isolationtester (PostgreSQL) " PG_VERSION "\n"
20 
21 /*
22  * start an isolation tester process for specified file (including
23  * redirection), and return process ID
24  */
25 static PID_TYPE
26 isolation_start_test(const char *testname,
27  _stringlist **resultfiles,
28  _stringlist **expectfiles,
29  _stringlist **tags)
30 {
31  PID_TYPE pid;
32  char infile[MAXPGPATH];
33  char outfile[MAXPGPATH];
34  char expectfile[MAXPGPATH];
35  char psql_cmd[MAXPGPATH * 3];
36  size_t offset = 0;
37 
38  /* need to do the path lookup here, check isolation_init() for details */
40  {
41  /* look for isolationtester binary */
42  if (find_other_exec(saved_argv0, "isolationtester",
44  {
45  fprintf(stderr, _("could not find proper isolationtester binary\n"));
46  exit(2);
47  }
49  }
50 
51  /*
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.
56  */
57  snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
58  outputdir, testname);
59  if (!file_exists(infile))
60  snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
61  inputdir, testname);
62 
63  snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
64  outputdir, testname);
65 
66  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
67  outputdir, testname);
68  if (!file_exists(expectfile))
69  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
70  inputdir, testname);
71 
72  add_stringlist_item(resultfiles, outfile);
73  add_stringlist_item(expectfiles, expectfile);
74 
75  if (launcher)
76  offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
77  "%s ", launcher);
78 
79  snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
80  "\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1",
82  dblist->str,
83  infile,
84  outfile);
85 
86  pid = spawn_process(psql_cmd);
87 
88  if (pid == INVALID_PID)
89  {
90  fprintf(stderr, _("could not start process for test %s\n"),
91  testname);
92  exit(2);
93  }
94 
95  return pid;
96 }
97 
98 static void
99 isolation_init(int argc, char **argv)
100 {
101  size_t argv0_len;
102 
103  /*
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().
111  */
112  argv0_len = strlcpy(saved_argv0, argv[0], MAXPGPATH);
113  if (argv0_len >= MAXPGPATH)
114  {
115  fprintf(stderr, _("path for isolationtester executable is longer than %d bytes\n"),
116  (int) (MAXPGPATH - 1));
117  exit(2);
118  }
119 
120  /* set default regression database name */
121  add_stringlist_item(&dblist, "isolation_regression");
122 }
123 
124 int
125 main(int argc, char *argv[])
126 {
128 }
char isolation_exec[MAXPGPATH]
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:307
static void isolation_init(int argc, char **argv)
char * str
Definition: pg_regress.h:25
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:152
#define PID_TYPE
Definition: pg_regress.h:15
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * launcher
Definition: pg_regress.c:75
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1124
static bool file_exists(const char *name)
Definition: dfmgr.c:450
#define MAXPGPATH
_stringlist * dblist
Definition: pg_regress.c:70
#define INVALID_PID
Definition: pg_regress.h:16
static PID_TYPE isolation_start_test(const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
int main(int argc, char *argv[])
bool looked_up_isolation_exec
char * outputdir
Definition: pg_regress.c:73
char * inputdir
Definition: pg_regress.c:72
static void infile(const char *filename)
Definition: zic.c:1151
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
char saved_argv0[MAXPGPATH]
#define PG_ISOLATION_VERSIONSTR
static char * outfile
#define _(x)
Definition: elog.c:84
int regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc)
Definition: pg_regress.c:2018