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

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 101 of file pg_regress_main.c.

References psql_init(), psql_start_test(), and regression_main().

102 {
103  return regression_main(argc, argv, psql_init, psql_start_test);
104 }
static PID_TYPE psql_start_test(const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
static void psql_init(int argc, char **argv)
int regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc)
Definition: pg_regress.c:2018
static void psql_init ( int  argc,
char **  argv 
)
static

Definition at line 94 of file pg_regress_main.c.

References add_stringlist_item(), and dblist.

Referenced by main().

95 {
96  /* set default regression database name */
97  add_stringlist_item(&dblist, "regression");
98 }
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:152
_stringlist * dblist
Definition: pg_regress.c:70
static PID_TYPE psql_start_test ( const char *  testname,
_stringlist **  resultfiles,
_stringlist **  expectfiles,
_stringlist **  tags 
)
static

Definition at line 26 of file pg_regress_main.c.

References _, add_stringlist_item(), bindir, dblist, file_exists(), free, infile(), inputdir, INVALID_PID, launcher, MAXPGPATH, outfile, outputdir, PID_TYPE, psprintf(), putenv, snprintf(), spawn_process(), _stringlist::str, and unsetenv.

Referenced by main().

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  char *appnameenv;
38 
39  /*
40  * Look for files in the output dir first, consistent with a vpath search.
41  * This is mainly to create more reasonable error messages if the file is
42  * not found. It also allows local test overrides when running pg_regress
43  * outside of the source tree.
44  */
45  snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
46  outputdir, testname);
47  if (!file_exists(infile))
48  snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
49  inputdir, testname);
50 
51  snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
52  outputdir, testname);
53 
54  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
55  outputdir, testname);
56  if (!file_exists(expectfile))
57  snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
58  inputdir, testname);
59 
60  add_stringlist_item(resultfiles, outfile);
61  add_stringlist_item(expectfiles, expectfile);
62 
63  if (launcher)
64  offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
65  "%s ", launcher);
66 
67  appnameenv = psprintf("PGAPPNAME=pg_regress/%s", testname);
68  putenv(appnameenv);
69 
70  snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
71  "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1",
72  bindir ? bindir : "",
73  bindir ? "/" : "",
74  dblist->str,
75  infile,
76  outfile);
77 
78  pid = spawn_process(psql_cmd);
79 
80  if (pid == INVALID_PID)
81  {
82  fprintf(stderr, _("could not start process for test %s\n"),
83  testname);
84  exit(2);
85  }
86 
87  unsetenv("PGAPPNAME");
88  free(appnameenv);
89 
90  return pid;
91 }
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
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define PID_TYPE
Definition: pg_regress.h:15
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define putenv(x)
Definition: win32.h:421
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
char * outputdir
Definition: pg_regress.c:73
char * inputdir
Definition: pg_regress.c:72
static void infile(const char *filename)
Definition: zic.c:1150
#define free(a)
Definition: header.h:60
char * bindir
Definition: pg_regress.c:74
#define unsetenv(x)
Definition: win32.h:422
static char * outfile
#define _(x)
Definition: elog.c:84