blob: b72c37e10cf561004f6088461d7037c619af90bc [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*-------------------------------------------------------------------------
*
* 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-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/test/regress/pg_regress_main.c,v 1.9 2010/01/02 16:58:16 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#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];
char use_utility_mode = 0;
/* generalise later */
if (strcmp(testname, "upg2") == 0)
use_utility_mode = 1;
/*
* 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);
if (optimizer_enabled)
{
snprintf(expectfile, sizeof(expectfile), "%s/expected/%s_optimizer.out",
outputdir, testname);
if (!file_exists(expectfile))
{
snprintf(expectfile, sizeof(expectfile), "%s/expected/%s_optimizer.out",
inputdir, testname);
}
}
// if optimizer is off or there is no orca-specific answer file, then
// use the default answer file
if (!file_exists(expectfile))
{
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);
snprintf(psql_cmd, sizeof(psql_cmd),
"%s " SYSTEMQUOTE "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
use_utility_mode ? "env PGOPTIONS='-c gp_session_role=utility'" : "",
psqldir ? psqldir : "",
psqldir ? "/" : "",
dblist->str,
infile,
outfile);
pid = spawn_process(psql_cmd);
if (pid == INVALID_PID)
{
fprintf(stderr, _("could not start process for test %s\n"),
testname);
exit_nicely(2);
}
return pid;
}
static void
psql_init(void)
{
/* 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);
}