Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_regress_main.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pg_regress_main --- regression test for the main backend
00004  *
00005  * This is a C implementation of the previous shell script for running
00006  * the regression tests, and should be mostly compatible with it.
00007  * Initial author of C translation: Magnus Hagander
00008  *
00009  * This code is released under the terms of the PostgreSQL License.
00010  *
00011  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00012  * Portions Copyright (c) 1994, Regents of the University of California
00013  *
00014  * src/test/regress/pg_regress_main.c
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 
00019 #include "pg_regress.h"
00020 
00021 /*
00022  * start a psql test process for specified file (including redirection),
00023  * and return process ID
00024  */
00025 static PID_TYPE
00026 psql_start_test(const char *testname,
00027                 _stringlist ** resultfiles,
00028                 _stringlist ** expectfiles,
00029                 _stringlist ** tags)
00030 {
00031     PID_TYPE    pid;
00032     char        infile[MAXPGPATH];
00033     char        outfile[MAXPGPATH];
00034     char        expectfile[MAXPGPATH];
00035     char        psql_cmd[MAXPGPATH * 3];
00036     size_t      offset = 0;
00037 
00038     /*
00039      * Look for files in the output dir first, consistent with a vpath search.
00040      * This is mainly to create more reasonable error messages if the file is
00041      * not found.  It also allows local test overrides when running pg_regress
00042      * outside of the source tree.
00043      */
00044     snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
00045              outputdir, testname);
00046     if (!file_exists(infile))
00047         snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
00048                  inputdir, testname);
00049 
00050     snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
00051              outputdir, testname);
00052 
00053     snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
00054              outputdir, testname);
00055     if (!file_exists(expectfile))
00056         snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
00057                  inputdir, testname);
00058 
00059     add_stringlist_item(resultfiles, outfile);
00060     add_stringlist_item(expectfiles, expectfile);
00061 
00062     if (launcher)
00063         offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
00064                            "%s ", launcher);
00065 
00066     snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
00067              SYSTEMQUOTE "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
00068              psqldir ? psqldir : "",
00069              psqldir ? "/" : "",
00070              dblist->str,
00071              infile,
00072              outfile);
00073 
00074     pid = spawn_process(psql_cmd);
00075 
00076     if (pid == INVALID_PID)
00077     {
00078         fprintf(stderr, _("could not start process for test %s\n"),
00079                 testname);
00080         exit(2);
00081     }
00082 
00083     return pid;
00084 }
00085 
00086 static void
00087 psql_init(void)
00088 {
00089     /* set default regression database name */
00090     add_stringlist_item(&dblist, "regression");
00091 }
00092 
00093 int
00094 main(int argc, char *argv[])
00095 {
00096     return regression_main(argc, argv, psql_init, psql_start_test);
00097 }