PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
isolation_main.c File Reference
#include "postgres_fe.h"
#include "pg_regress.h"
Include dependency graph for isolation_main.c:

Go to the source code of this file.

Macros

#define PG_ISOLATION_VERSIONSTR   "isolationtester (PostgreSQL) " PG_VERSION "\n"
 

Functions

static PID_TYPE isolation_start_test (const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
 
static void isolation_init (int argc, char **argv)
 
int main (int argc, char *argv[])
 

Variables

char saved_argv0 [MAXPGPATH]
 
char isolation_exec [MAXPGPATH]
 
bool looked_up_isolation_exec = false
 

Macro Definition Documentation

#define PG_ISOLATION_VERSIONSTR   "isolationtester (PostgreSQL) " PG_VERSION "\n"

Definition at line 21 of file isolation_main.c.

Referenced by isolation_start_test().

Function Documentation

static void isolation_init ( int  argc,
char **  argv 
)
static

Definition at line 101 of file isolation_main.c.

References _, add_stringlist_item(), dblist, MAXPGPATH, saved_argv0, and strlcpy().

Referenced by main().

102 {
103  size_t argv0_len;
104 
105  /*
106  * We unfortunately cannot do the find_other_exec() lookup to find the
107  * "isolationtester" binary here. regression_main() calls the
108  * initialization functions before parsing the commandline arguments and
109  * thus hasn't changed the library search path at this point which in turn
110  * can cause the "isolationtester -V" invocation that find_other_exec()
111  * does to fail since it's linked to libpq. So we instead copy argv[0]
112  * and do the lookup the first time through isolation_start_test().
113  */
114  argv0_len = strlcpy(saved_argv0, argv[0], MAXPGPATH);
115  if (argv0_len >= MAXPGPATH)
116  {
117  fprintf(stderr, _("path for isolationtester executable is longer than %d bytes\n"),
118  (int) (MAXPGPATH - 1));
119  exit(2);
120  }
121 
122  /* set default regression database name */
123  add_stringlist_item(&dblist, "isolation_regression");
124 }
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:154
#define MAXPGPATH
_stringlist * dblist
Definition: pg_regress.c:72
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
char saved_argv0[MAXPGPATH]
#define _(x)
Definition: elog.c:84
static PID_TYPE isolation_start_test ( const char *  testname,
_stringlist **  resultfiles,
_stringlist **  expectfiles,
_stringlist **  tags 
)
static

Definition at line 28 of file isolation_main.c.

References _, add_stringlist_item(), dblist, file_exists(), find_other_exec(), infile(), inputdir, INVALID_PID, isolation_exec, launcher, looked_up_isolation_exec, MAXPGPATH, outfile, outputdir, PG_ISOLATION_VERSIONSTR, PID_TYPE, saved_argv0, snprintf(), spawn_process(), and _stringlist::str.

Referenced by main().

32 {
33  PID_TYPE pid;
34  char infile[MAXPGPATH];
35  char outfile[MAXPGPATH];
36  char expectfile[MAXPGPATH];
37  char psql_cmd[MAXPGPATH * 3];
38  size_t offset = 0;
39 
40  /* need to do the path lookup here, check isolation_init() for details */
42  {
43  /* look for isolationtester binary */
44  if (find_other_exec(saved_argv0, "isolationtester",
46  {
47  fprintf(stderr, _("could not find proper isolationtester binary\n"));
48  exit(2);
49  }
51  }
52 
53  /*
54  * Look for files in the output dir first, consistent with a vpath search.
55  * This is mainly to create more reasonable error messages if the file is
56  * not found. It also allows local test overrides when running pg_regress
57  * outside of the source tree.
58  */
59  snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
60  outputdir, testname);
61  if (!file_exists(infile))
62  snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
63  inputdir, testname);
64 
65  snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
66  outputdir, testname);
67 
68  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
69  outputdir, testname);
70  if (!file_exists(expectfile))
71  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
72  inputdir, testname);
73 
74  add_stringlist_item(resultfiles, outfile);
75  add_stringlist_item(expectfiles, expectfile);
76 
77  if (launcher)
78  offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
79  "%s ", launcher);
80 
81  snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
82  "\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1",
84  dblist->str,
85  infile,
86  outfile);
87 
88  pid = spawn_process(psql_cmd);
89 
90  if (pid == INVALID_PID)
91  {
92  fprintf(stderr, _("could not start process for test %s\n"),
93  testname);
94  exit(2);
95  }
96 
97  return pid;
98 }
char isolation_exec[MAXPGPATH]
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:307
char * str
Definition: pg_regress.h:24
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:154
#define PID_TYPE
Definition: pg_regress.h:14
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * launcher
Definition: pg_regress.c:77
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1126
static bool file_exists(const char *name)
Definition: dfmgr.c:455
#define MAXPGPATH
_stringlist * dblist
Definition: pg_regress.c:72
#define INVALID_PID
Definition: pg_regress.h:15
bool looked_up_isolation_exec
char * outputdir
Definition: pg_regress.c:75
char * inputdir
Definition: pg_regress.c:74
static void infile(const char *filename)
Definition: zic.c:1150
char saved_argv0[MAXPGPATH]
#define PG_ISOLATION_VERSIONSTR
static char * outfile
#define _(x)
Definition: elog.c:84
int main ( int  argc,
char *  argv[] 
)

Definition at line 127 of file isolation_main.c.

References isolation_init(), isolation_start_test(), and regression_main().

128 {
130 }
static void isolation_init(int argc, char **argv)
static PID_TYPE isolation_start_test(const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
int regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc)
Definition: pg_regress.c:2025

Variable Documentation

char isolation_exec[MAXPGPATH]

Definition at line 18 of file isolation_main.c.

Referenced by isolation_start_test().

bool looked_up_isolation_exec = false

Definition at line 19 of file isolation_main.c.

Referenced by isolation_start_test().

char saved_argv0[MAXPGPATH]

Definition at line 17 of file isolation_main.c.

Referenced by isolation_init(), and isolation_start_test().