PostgreSQL Source Code  git master
pg_regress_ecpg.c File Reference
#include "postgres_fe.h"
#include "pg_regress.h"
#include "common/string.h"
#include "lib/stringinfo.h"
Include dependency graph for pg_regress_ecpg.c:

Go to the source code of this file.

Functions

static void ecpg_filter (const char *sourcefile, const char *outfile)
 
static PID_TYPE ecpg_start_test (const char *testname, _stringlist **resultfiles, _stringlist **expectfiles, _stringlist **tags)
 
static void ecpg_init (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Function Documentation

◆ ecpg_filter()

static void ecpg_filter ( const char *  sourcefile,
const char *  outfile 
)
static

Definition at line 27 of file pg_regress_ecpg.c.

References StringInfoData::data, fprintf, initStringInfo(), pfree(), pg_get_line_append(), PID_TYPE, and resetStringInfo().

Referenced by ecpg_start_test().

28 {
29  /*
30  * Create a filtered copy of sourcefile, replacing #line x
31  * "./../bla/foo.h" with #line x "foo.h"
32  */
33  FILE *s,
34  *t;
35  StringInfoData linebuf;
36 
37  s = fopen(sourcefile, "r");
38  if (!s)
39  {
40  fprintf(stderr, "Could not open file %s for reading\n", sourcefile);
41  exit(2);
42  }
43  t = fopen(outfile, "w");
44  if (!t)
45  {
46  fprintf(stderr, "Could not open file %s for writing\n", outfile);
47  exit(2);
48  }
49 
50  initStringInfo(&linebuf);
51 
52  while (pg_get_line_append(s, &linebuf))
53  {
54  /* check for "#line " in the beginning */
55  if (strstr(linebuf.data, "#line ") == linebuf.data)
56  {
57  char *p = strchr(linebuf.data, '"');
58  int plen = 1;
59 
60  while (*p && (*(p + plen) == '.' || strchr(p + plen, '/') != NULL))
61  {
62  plen++;
63  }
64  /* plen is one more than the number of . and / characters */
65  if (plen > 1)
66  {
67  memmove(p + 1, p + plen, strlen(p + plen) + 1);
68  /* we don't bother to fix up linebuf.len */
69  }
70  }
71  fputs(linebuf.data, t);
72  resetStringInfo(&linebuf);
73  }
74 
75  pfree(linebuf.data);
76  fclose(s);
77  fclose(t);
78 }
#define fprintf
Definition: port.h:197
void pfree(void *pointer)
Definition: mcxt.c:1057
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:75
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
bool pg_get_line_append(FILE *stream, StringInfo buf)
Definition: pg_get_line.c:85
static char * outfile

◆ ecpg_init()

static void ecpg_init ( int  argc,
char *  argv[] 
)
static

Definition at line 172 of file pg_regress_ecpg.c.

Referenced by main().

173 {
174  /* nothing to do here at the moment */
175 }

◆ ecpg_start_test()

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

Definition at line 86 of file pg_regress_ecpg.c.

References _, add_stringlist_item(), appendStringInfoString(), StringInfoData::data, ecpg_filter(), fprintf, free, initStringInfo(), inputdir, INVALID_PID, MAXPGPATH, outputdir, PID_TYPE, psprintf(), putenv, replace_string(), snprintf, spawn_process(), and unsetenv.

Referenced by main().

90 {
91  PID_TYPE pid;
92  char inprg[MAXPGPATH];
93  char insource[MAXPGPATH];
94  StringInfoData testname_dash;
95  char outfile_stdout[MAXPGPATH],
96  expectfile_stdout[MAXPGPATH];
97  char outfile_stderr[MAXPGPATH],
98  expectfile_stderr[MAXPGPATH];
99  char outfile_source[MAXPGPATH],
100  expectfile_source[MAXPGPATH];
101  char cmd[MAXPGPATH * 3];
102  char *appnameenv;
103 
104  snprintf(inprg, sizeof(inprg), "%s/%s", inputdir, testname);
105  snprintf(insource, sizeof(insource), "%s.c", testname);
106 
107  initStringInfo(&testname_dash);
108  appendStringInfoString(&testname_dash, testname);
109  replace_string(&testname_dash, "/", "-");
110 
111  snprintf(expectfile_stdout, sizeof(expectfile_stdout),
112  "%s/expected/%s.stdout",
113  outputdir, testname_dash.data);
114  snprintf(expectfile_stderr, sizeof(expectfile_stderr),
115  "%s/expected/%s.stderr",
116  outputdir, testname_dash.data);
117  snprintf(expectfile_source, sizeof(expectfile_source),
118  "%s/expected/%s.c",
119  outputdir, testname_dash.data);
120 
121  snprintf(outfile_stdout, sizeof(outfile_stdout),
122  "%s/results/%s.stdout",
123  outputdir, testname_dash.data);
124  snprintf(outfile_stderr, sizeof(outfile_stderr),
125  "%s/results/%s.stderr",
126  outputdir, testname_dash.data);
127  snprintf(outfile_source, sizeof(outfile_source),
128  "%s/results/%s.c",
129  outputdir, testname_dash.data);
130 
131  add_stringlist_item(resultfiles, outfile_stdout);
132  add_stringlist_item(expectfiles, expectfile_stdout);
133  add_stringlist_item(tags, "stdout");
134 
135  add_stringlist_item(resultfiles, outfile_stderr);
136  add_stringlist_item(expectfiles, expectfile_stderr);
137  add_stringlist_item(tags, "stderr");
138 
139  add_stringlist_item(resultfiles, outfile_source);
140  add_stringlist_item(expectfiles, expectfile_source);
141  add_stringlist_item(tags, "source");
142 
143  ecpg_filter(insource, outfile_source);
144 
145  snprintf(cmd, sizeof(cmd),
146  "\"%s\" >\"%s\" 2>\"%s\"",
147  inprg,
148  outfile_stdout,
149  outfile_stderr);
150 
151  appnameenv = psprintf("PGAPPNAME=ecpg/%s", testname_dash.data);
152  putenv(appnameenv);
153 
154  pid = spawn_process(cmd);
155 
156  if (pid == INVALID_PID)
157  {
158  fprintf(stderr, _("could not start process for test %s\n"),
159  testname);
160  exit(2);
161  }
162 
163  unsetenv("PGAPPNAME");
164  free(appnameenv);
165 
166  free(testname_dash.data);
167 
168  return pid;
169 }
static void static void static void void add_stringlist_item(_stringlist **listhead, const char *str)
Definition: pg_regress.c:157
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define PID_TYPE
Definition: pg_regress.h:14
#define fprintf
Definition: port.h:197
PID_TYPE spawn_process(const char *cmdline)
Definition: pg_regress.c:1170
#define MAXPGPATH
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
#define INVALID_PID
Definition: pg_regress.h:15
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * outputdir
Definition: pg_regress.c:78
char * inputdir
Definition: pg_regress.c:77
#define free(a)
Definition: header.h:65
#define putenv(x)
Definition: win32_port.h:474
void replace_string(StringInfo string, const char *replace, const char *replacement)
Definition: pg_regress.c:447
static void ecpg_filter(const char *sourcefile, const char *outfile)
#define snprintf
Definition: port.h:193
#define _(x)
Definition: elog.c:88
#define unsetenv(x)
Definition: win32_port.h:475

◆ main()

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

Definition at line 178 of file pg_regress_ecpg.c.

References ecpg_init(), ecpg_start_test(), and regression_main().

179 {
180  return regression_main(argc, argv, ecpg_init, ecpg_start_test);
181 }
static void ecpg_init(int argc, char *argv[])
static PID_TYPE ecpg_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:2098