summaryrefslogtreecommitdiffstats
path: root/src/test/regress/pg_regress_main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/test/regress/pg_regress_main.c
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/regress/pg_regress_main.c')
-rw-r--r--src/test/regress/pg_regress_main.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/test/regress/pg_regress_main.c b/src/test/regress/pg_regress_main.c
new file mode 100644
index 0000000..a4b354c
--- /dev/null
+++ b/src/test/regress/pg_regress_main.c
@@ -0,0 +1,126 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_regress_main --- regression test for the main backend
+ *
+ * This is a C implementation of the previous shell script for running
+ * the regression tests, and should be mostly compatible with it.
+ * Initial author of C translation: Magnus Hagander
+ *
+ * This code is released under the terms of the PostgreSQL License.
+ *
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/test/regress/pg_regress_main.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "postgres_fe.h"
+
+#include "pg_regress.h"
+
+/*
+ * start a psql test process for specified file (including redirection),
+ * and return process ID
+ */
+static PID_TYPE
+psql_start_test(const char *testname,
+ _stringlist **resultfiles,
+ _stringlist **expectfiles,
+ _stringlist **tags)
+{
+ PID_TYPE pid;
+ char infile[MAXPGPATH];
+ char outfile[MAXPGPATH];
+ char expectfile[MAXPGPATH];
+ char psql_cmd[MAXPGPATH * 3];
+ size_t offset = 0;
+ char *appnameenv;
+
+ /*
+ * Look for files in the output dir first, consistent with a vpath search.
+ * This is mainly to create more reasonable error messages if the file is
+ * not found. It also allows local test overrides when running pg_regress
+ * outside of the source tree.
+ */
+ snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
+ outputdir, testname);
+ if (!file_exists(infile))
+ snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
+ inputdir, testname);
+
+ snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
+ outputdir, testname);
+
+ snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
+ outputdir, testname);
+ if (!file_exists(expectfile))
+ snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
+ inputdir, testname);
+
+ add_stringlist_item(resultfiles, outfile);
+ add_stringlist_item(expectfiles, expectfile);
+
+ if (launcher)
+ {
+ offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
+ "%s ", launcher);
+ if (offset >= sizeof(psql_cmd))
+ {
+ fprintf(stderr, _("command too long\n"));
+ exit(2);
+ }
+ }
+
+ /*
+ * Use HIDE_TABLEAM to hide different AMs to allow to use regression tests
+ * against different AMs without unnecessary differences.
+ */
+ offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
+ "\"%s%spsql\" -X -a -q -d \"%s\" %s < \"%s\" > \"%s\" 2>&1",
+ bindir ? bindir : "",
+ bindir ? "/" : "",
+ dblist->str,
+ "-v HIDE_TABLEAM=on -v HIDE_TOAST_COMPRESSION=on",
+ infile,
+ outfile);
+ if (offset >= sizeof(psql_cmd))
+ {
+ fprintf(stderr, _("command too long\n"));
+ exit(2);
+ }
+
+ appnameenv = psprintf("pg_regress/%s", testname);
+ setenv("PGAPPNAME", appnameenv, 1);
+ free(appnameenv);
+
+ pid = spawn_process(psql_cmd);
+
+ if (pid == INVALID_PID)
+ {
+ fprintf(stderr, _("could not start process for test %s\n"),
+ testname);
+ exit(2);
+ }
+
+ unsetenv("PGAPPNAME");
+
+ return pid;
+}
+
+static void
+psql_init(int argc, char **argv)
+{
+ /* set default regression database name */
+ add_stringlist_item(&dblist, "regression");
+}
+
+int
+main(int argc, char *argv[])
+{
+ return regression_main(argc, argv,
+ psql_init,
+ psql_start_test,
+ NULL /* no postfunc needed */ );
+}