1 /*-------------------------------------------------------------------------
3 * pg_regress_main --- regression test for the main backend
5 * This is a C implementation of the previous shell script for running
6 * the regression tests, and should be mostly compatible with it.
7 * Initial author of C translation: Magnus Hagander
9 * This code is released under the terms of the PostgreSQL License.
11 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/test/regress/pg_regress_main.c
16 *-------------------------------------------------------------------------
19 #include "postgres_fe.h"
21 #include "lib/stringinfo.h"
22 #include "pg_regress.h"
25 * start a psql test process for specified file (including redirection),
26 * and return process ID
29 psql_start_test(const char *testname
,
30 _stringlist
**resultfiles
,
31 _stringlist
**expectfiles
,
35 char infile
[MAXPGPATH
];
36 char outfile
[MAXPGPATH
];
37 char expectfile
[MAXPGPATH
];
38 StringInfoData psql_cmd
;
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.
47 snprintf(infile
, sizeof(infile
), "%s/sql/%s.sql",
49 if (!file_exists(infile
))
50 snprintf(infile
, sizeof(infile
), "%s/sql/%s.sql",
53 snprintf(outfile
, sizeof(outfile
), "%s/results/%s.out",
56 snprintf(expectfile
, sizeof(expectfile
), "%s/expected/%s.out",
57 expecteddir
, testname
);
58 if (!file_exists(expectfile
))
59 snprintf(expectfile
, sizeof(expectfile
), "%s/expected/%s.out",
62 add_stringlist_item(resultfiles
, outfile
);
63 add_stringlist_item(expectfiles
, expectfile
);
65 initStringInfo(&psql_cmd
);
68 appendStringInfo(&psql_cmd
, "%s ", launcher
);
71 * Use HIDE_TABLEAM to hide different AMs to allow to use regression tests
72 * against different AMs without unnecessary differences.
74 appendStringInfo(&psql_cmd
,
75 "\"%s%spsql\" -X -a -q -d \"%s\" %s < \"%s\" > \"%s\" 2>&1",
79 "-v HIDE_TABLEAM=on -v HIDE_TOAST_COMPRESSION=on",
83 appnameenv
= psprintf("pg_regress/%s", testname
);
84 setenv("PGAPPNAME", appnameenv
, 1);
87 pid
= spawn_process(psql_cmd
.data
);
89 if (pid
== INVALID_PID
)
91 fprintf(stderr
, _("could not start process for test %s\n"),
96 unsetenv("PGAPPNAME");
104 psql_init(int argc
, char **argv
)
106 /* set default regression database name */
107 add_stringlist_item(&dblist
, "regression");
111 main(int argc
, char *argv
[])
113 return regression_main(argc
, argv
,
116 NULL
/* no postfunc needed */ );