PostgreSQL Source Code  git master
pg_regress_main.c File Reference
#include "postgres_fe.h"
#include "lib/stringinfo.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

◆ main()

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

Definition at line 111 of file pg_regress_main.c.

112 {
113  return regression_main(argc, argv,
114  psql_init,
116  NULL /* no postfunc needed */ );
117 }
int regression_main(int argc, char *argv[], init_function ifunc, test_start_function startfunc, postprocess_result_function postfunc)
Definition: pg_regress.c:2079
static void psql_init(int argc, char **argv)
static PID_TYPE psql_start_test(const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)

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

◆ psql_init()

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

Definition at line 104 of file pg_regress_main.c.

105 {
106  /* set default regression database name */
107  add_stringlist_item(&dblist, "regression");
108 }
static void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: initdb.c:385
_stringlist * dblist
Definition: pg_regress.c:98

References add_stringlist_item(), and dblist.

Referenced by main().

◆ psql_start_test()

static PID_TYPE psql_start_test ( const char *  testname,
_stringlist **  resultfiles,
_stringlist **  expectfiles,
_stringlist **  tags 
)
static

Definition at line 29 of file pg_regress_main.c.

33 {
34  PID_TYPE pid;
35  char infile[MAXPGPATH];
36  char outfile[MAXPGPATH];
37  char expectfile[MAXPGPATH];
38  StringInfoData psql_cmd;
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  initStringInfo(&psql_cmd);
66 
67  if (launcher)
68  appendStringInfo(&psql_cmd, "%s ", launcher);
69 
70  /*
71  * Use HIDE_TABLEAM to hide different AMs to allow to use regression tests
72  * against different AMs without unnecessary differences.
73  */
74  appendStringInfo(&psql_cmd,
75  "\"%s%spsql\" -X -a -q -d \"%s\" %s < \"%s\" > \"%s\" 2>&1",
76  bindir ? bindir : "",
77  bindir ? "/" : "",
78  dblist->str,
79  "-v HIDE_TABLEAM=on -v HIDE_TOAST_COMPRESSION=on",
80  infile,
81  outfile);
82 
83  appnameenv = psprintf("pg_regress/%s", testname);
84  setenv("PGAPPNAME", appnameenv, 1);
85  free(appnameenv);
86 
87  pid = spawn_process(psql_cmd.data);
88 
89  if (pid == INVALID_PID)
90  {
91  fprintf(stderr, _("could not start process for test %s\n"),
92  testname);
93  exit(2);
94  }
95 
96  unsetenv("PGAPPNAME");
97 
98  pfree(psql_cmd.data);
99 
100  return pid;
101 }
#define _(x)
Definition: elog.c:91
#define free(a)
Definition: header.h:65
exit(1)
void pfree(void *pointer)
Definition: mcxt.c:1431
#define MAXPGPATH
static char * outfile
bool file_exists(const char *file)
Definition: pg_regress.c:1302
char * outputdir
Definition: pg_regress.c:101
char * launcher
Definition: pg_regress.c:104
char * inputdir
Definition: pg_regress.c:100
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1197
char * bindir
Definition: pg_regress.c:103
#define PID_TYPE
Definition: pg_regress.h:14
#define INVALID_PID
Definition: pg_regress.h:15
#define snprintf
Definition: port.h:238
#define fprintf
Definition: port.h:242
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * str
Definition: initdb.c:92
#define unsetenv(x)
Definition: win32_port.h:538
#define setenv(x, y, z)
Definition: win32_port.h:537
static void infile(const char *name)
Definition: zic.c:1243

References _, add_stringlist_item(), appendStringInfo(), bindir, StringInfoData::data, dblist, exit(), file_exists(), fprintf, free, infile(), initStringInfo(), inputdir, INVALID_PID, launcher, MAXPGPATH, outfile, outputdir, pfree(), PID_TYPE, psprintf(), setenv, snprintf, spawn_process(), _stringlist::str, and unsetenv.

Referenced by main().