PostgreSQL Source Code  git master
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

◆ PG_ISOLATION_VERSIONSTR

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

Definition at line 21 of file isolation_main.c.

Function Documentation

◆ isolation_init()

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

Definition at line 120 of file isolation_main.c.

121 {
122  size_t argv0_len;
123 
124  /*
125  * We unfortunately cannot do the find_other_exec() lookup to find the
126  * "isolationtester" binary here. regression_main() calls the
127  * initialization functions before parsing the commandline arguments and
128  * thus hasn't changed the library search path at this point which in turn
129  * can cause the "isolationtester -V" invocation that find_other_exec()
130  * does to fail since it's linked to libpq. So we instead copy argv[0]
131  * and do the lookup the first time through isolation_start_test().
132  */
133  argv0_len = strlcpy(saved_argv0, argv[0], MAXPGPATH);
134  if (argv0_len >= MAXPGPATH)
135  {
136  fprintf(stderr, _("path for isolationtester executable is longer than %d bytes\n"),
137  (int) (MAXPGPATH - 1));
138  exit(2);
139  }
140 
141  /* set default regression database name */
142  add_stringlist_item(&dblist, "isolation_regression");
143 }
#define _(x)
Definition: elog.c:91
static void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: initdb.c:387
char saved_argv0[MAXPGPATH]
exit(1)
#define MAXPGPATH
_stringlist * dblist
Definition: pg_regress.c:91
#define fprintf
Definition: port.h:242
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

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

Referenced by main().

◆ isolation_start_test()

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.

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  char *appnameenv;
40 
41  /* need to do the path lookup here, check isolation_init() for details */
43  {
44  /* look for isolationtester binary */
45  if (find_other_exec(saved_argv0, "isolationtester",
47  {
48  fprintf(stderr, _("could not find proper isolationtester binary\n"));
49  exit(2);
50  }
52  }
53 
54  /*
55  * Look for files in the output dir first, consistent with a vpath search.
56  * This is mainly to create more reasonable error messages if the file is
57  * not found. It also allows local test overrides when running pg_regress
58  * outside of the source tree.
59  */
60  snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
61  outputdir, testname);
62  if (!file_exists(infile))
63  snprintf(infile, sizeof(infile), "%s/specs/%s.spec",
64  inputdir, testname);
65 
66  snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
67  outputdir, testname);
68 
69  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
70  outputdir, testname);
71  if (!file_exists(expectfile))
72  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
73  inputdir, testname);
74 
75  add_stringlist_item(resultfiles, outfile);
76  add_stringlist_item(expectfiles, expectfile);
77 
78  if (launcher)
79  {
80  offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
81  "%s ", launcher);
82  if (offset >= sizeof(psql_cmd))
83  {
84  fprintf(stderr, _("command too long\n"));
85  exit(2);
86  }
87  }
88 
89  offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
90  "\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1",
92  dblist->str,
93  infile,
94  outfile);
95  if (offset >= sizeof(psql_cmd))
96  {
97  fprintf(stderr, _("command too long\n"));
98  exit(2);
99  }
100 
101  appnameenv = psprintf("isolation/%s", testname);
102  setenv("PGAPPNAME", appnameenv, 1);
103  free(appnameenv);
104 
105  pid = spawn_process(psql_cmd);
106 
107  if (pid == INVALID_PID)
108  {
109  fprintf(stderr, _("could not start process for test %s\n"),
110  testname);
111  exit(2);
112  }
113 
114  unsetenv("PGAPPNAME");
115 
116  return pid;
117 }
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:327
#define free(a)
Definition: header.h:65
#define PG_ISOLATION_VERSIONSTR
bool looked_up_isolation_exec
char isolation_exec[MAXPGPATH]
static bool file_exists(const char *name)
Definition: jit.c:194
static char * outfile
char * outputdir
Definition: pg_regress.c:94
char * launcher
Definition: pg_regress.c:97
char * inputdir
Definition: pg_regress.c:93
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1189
#define PID_TYPE
Definition: pg_regress.h:14
#define INVALID_PID
Definition: pg_regress.h:15
#define snprintf
Definition: port.h:238
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * str
Definition: initdb.c:91
#define unsetenv(x)
Definition: win32_port.h:548
#define setenv(x, y, z)
Definition: win32_port.h:547
static void infile(const char *name)
Definition: zic.c:1243

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

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 146 of file isolation_main.c.

147 {
148  return regression_main(argc, argv,
151  NULL /* no postfunc needed */ );
152 }
static PID_TYPE isolation_start_test(const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
static void isolation_init(int argc, char **argv)
int regression_main(int argc, char *argv[], init_function ifunc, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:2073

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

Variable Documentation

◆ isolation_exec

char isolation_exec[MAXPGPATH]

Definition at line 18 of file isolation_main.c.

Referenced by isolation_start_test().

◆ looked_up_isolation_exec

bool looked_up_isolation_exec = false

Definition at line 19 of file isolation_main.c.

Referenced by isolation_start_test().

◆ saved_argv0

char saved_argv0[MAXPGPATH]

Definition at line 17 of file isolation_main.c.

Referenced by isolation_init(), and isolation_start_test().