]> granicus.if.org Git - postgresql/blob - src/test/regress/pg_regress_main.c
Update copyright for 2016
[postgresql] / src / test / regress / pg_regress_main.c
1 /*-------------------------------------------------------------------------
2  *
3  * pg_regress_main --- regression test for the main backend
4  *
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
8  *
9  * This code is released under the terms of the PostgreSQL License.
10  *
11  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
12  * Portions Copyright (c) 1994, Regents of the University of California
13  *
14  * src/test/regress/pg_regress_main.c
15  *
16  *-------------------------------------------------------------------------
17  */
18
19 #include "pg_regress.h"
20
21 /*
22  * start a psql test process for specified file (including redirection),
23  * and return process ID
24  */
25 static PID_TYPE
26 psql_start_test(const char *testname,
27                                 _stringlist **resultfiles,
28                                 _stringlist **expectfiles,
29                                 _stringlist **tags)
30 {
31         PID_TYPE        pid;
32         char            infile[MAXPGPATH];
33         char            outfile[MAXPGPATH];
34         char            expectfile[MAXPGPATH];
35         char            psql_cmd[MAXPGPATH * 3];
36         size_t          offset = 0;
37
38         /*
39          * Look for files in the output dir first, consistent with a vpath search.
40          * This is mainly to create more reasonable error messages if the file is
41          * not found.  It also allows local test overrides when running pg_regress
42          * outside of the source tree.
43          */
44         snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
45                          outputdir, testname);
46         if (!file_exists(infile))
47                 snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
48                                  inputdir, testname);
49
50         snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
51                          outputdir, testname);
52
53         snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
54                          outputdir, testname);
55         if (!file_exists(expectfile))
56                 snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
57                                  inputdir, testname);
58
59         add_stringlist_item(resultfiles, outfile);
60         add_stringlist_item(expectfiles, expectfile);
61
62         if (launcher)
63                 offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
64                                                    "%s ", launcher);
65
66         snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
67                          "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1",
68                          bindir ? bindir : "",
69                          bindir ? "/" : "",
70                          dblist->str,
71                          infile,
72                          outfile);
73
74         pid = spawn_process(psql_cmd);
75
76         if (pid == INVALID_PID)
77         {
78                 fprintf(stderr, _("could not start process for test %s\n"),
79                                 testname);
80                 exit(2);
81         }
82
83         return pid;
84 }
85
86 static void
87 psql_init(int argc, char **argv)
88 {
89         /* set default regression database name */
90         add_stringlist_item(&dblist, "regression");
91 }
92
93 int
94 main(int argc, char *argv[])
95 {
96         return regression_main(argc, argv, psql_init, psql_start_test);
97 }