Header And Logo

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

isolation_main.c

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