2007-06-12 13:07:34 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2018-01-03 05:30:12 +01:00
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
2007-06-12 13:07:34 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/test/regress/pg_regress_main.c
|
2007-06-12 13:07:34 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2017-03-09 02:41:06 +01:00
|
|
|
#include "postgres_fe.h"
|
|
|
|
|
2007-06-12 13:07:34 +02:00
|
|
|
#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,
|
2014-05-06 18:12:18 +02:00
|
|
|
_stringlist **resultfiles,
|
|
|
|
_stringlist **expectfiles,
|
|
|
|
_stringlist **tags)
|
2007-06-12 13:07:34 +02:00
|
|
|
{
|
|
|
|
PID_TYPE pid;
|
|
|
|
char infile[MAXPGPATH];
|
|
|
|
char outfile[MAXPGPATH];
|
|
|
|
char expectfile[MAXPGPATH];
|
|
|
|
char psql_cmd[MAXPGPATH * 3];
|
2011-01-24 02:44:48 +01:00
|
|
|
size_t offset = 0;
|
2016-09-30 18:00:00 +02:00
|
|
|
char *appnameenv;
|
2007-06-12 13:07:34 +02:00
|
|
|
|
2008-10-02 00:38:57 +02:00
|
|
|
/*
|
2009-06-11 16:49:15 +02:00
|
|
|
* 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.
|
2008-10-02 00:38:57 +02:00
|
|
|
*/
|
2007-06-12 13:07:34 +02:00
|
|
|
snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
|
2008-10-02 00:38:57 +02:00
|
|
|
outputdir, testname);
|
|
|
|
if (!file_exists(infile))
|
|
|
|
snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
|
|
|
|
inputdir, testname);
|
|
|
|
|
2007-06-12 13:07:34 +02:00
|
|
|
snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
|
|
|
|
outputdir, testname);
|
2008-10-02 00:38:57 +02:00
|
|
|
|
2007-06-12 13:07:34 +02:00
|
|
|
snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
|
2008-10-02 00:38:57 +02:00
|
|
|
outputdir, testname);
|
|
|
|
if (!file_exists(expectfile))
|
|
|
|
snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
|
|
|
|
inputdir, testname);
|
2007-06-12 13:07:34 +02:00
|
|
|
|
|
|
|
add_stringlist_item(resultfiles, outfile);
|
|
|
|
add_stringlist_item(expectfiles, expectfile);
|
|
|
|
|
2011-01-24 02:44:48 +01:00
|
|
|
if (launcher)
|
|
|
|
offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
|
|
|
|
"%s ", launcher);
|
|
|
|
|
2016-09-30 18:00:00 +02:00
|
|
|
appnameenv = psprintf("PGAPPNAME=pg_regress/%s", testname);
|
|
|
|
putenv(appnameenv);
|
|
|
|
|
2011-01-24 02:44:48 +01:00
|
|
|
snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
|
Replace SYSTEMQUOTEs with Windows-specific wrapper functions.
It's easy to forget using SYSTEMQUOTEs when constructing command strings
for system() or popen(). Even if we fix all the places missing it now, it is
bound to be forgotten again in the future. Introduce wrapper functions that
do the the extra quoting for you, and get rid of SYSTEMQUOTEs in all the
callers.
We previosly used SYSTEMQUOTEs in all the hard-coded command strings, and
this doesn't change the behavior of those. But user-supplied commands, like
archive_command, restore_command, COPY TO/FROM PROGRAM calls, as well as
pgbench's \shell, will now gain an extra pair of quotes. That is desirable,
but if you have existing scripts or config files that include an extra
pair of quotes, those might need to be adjusted.
Reviewed by Amit Kapila and Tom Lane
2014-05-05 15:07:40 +02:00
|
|
|
"\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1",
|
2015-04-23 14:59:52 +02:00
|
|
|
bindir ? bindir : "",
|
|
|
|
bindir ? "/" : "",
|
2007-06-12 13:07:34 +02:00
|
|
|
dblist->str,
|
|
|
|
infile,
|
|
|
|
outfile);
|
|
|
|
|
|
|
|
pid = spawn_process(psql_cmd);
|
|
|
|
|
|
|
|
if (pid == INVALID_PID)
|
|
|
|
{
|
|
|
|
fprintf(stderr, _("could not start process for test %s\n"),
|
|
|
|
testname);
|
2012-01-02 21:08:04 +01:00
|
|
|
exit(2);
|
2007-06-12 13:07:34 +02:00
|
|
|
}
|
|
|
|
|
2016-09-30 18:00:00 +02:00
|
|
|
unsetenv("PGAPPNAME");
|
|
|
|
free(appnameenv);
|
|
|
|
|
2007-06-12 13:07:34 +02:00
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-08 20:40:41 +01:00
|
|
|
psql_init(int argc, char **argv)
|
2007-06-12 13:07:34 +02:00
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
}
|