PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_regress_main.c File Reference
#include "postgres_fe.h"
#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 103 of file pg_regress_main.c.

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

104 {
105  return regression_main(argc, argv, psql_init, psql_start_test);
106 }
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:2025
static void psql_init ( int  argc,
char **  argv 
)
static

Definition at line 96 of file pg_regress_main.c.

References add_stringlist_item(), and dblist.

Referenced by main().

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

Definition at line 28 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().

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