LCOV - code coverage report
Current view: top level - src/test/regress - pg_regress_main.c (source / functions) Hit Total Coverage
Test: PostgreSQL Lines: 26 31 83.9 %
Date: 2017-09-29 15:12:54 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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-2017, 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 "postgres_fe.h"
      20             : 
      21             : #include "pg_regress.h"
      22             : 
      23             : /*
      24             :  * start a psql test process for specified file (including redirection),
      25             :  * and return process ID
      26             :  */
      27             : static PID_TYPE
      28         180 : psql_start_test(const char *testname,
      29             :                 _stringlist **resultfiles,
      30             :                 _stringlist **expectfiles,
      31             :                 _stringlist **tags)
      32             : {
      33             :     PID_TYPE    pid;
      34             :     char        infile[MAXPGPATH];
      35             :     char        outfile[MAXPGPATH];
      36             :     char        expectfile[MAXPGPATH];
      37             :     char        psql_cmd[MAXPGPATH * 3];
      38         180 :     size_t      offset = 0;
      39             :     char       *appnameenv;
      40             : 
      41             :     /*
      42             :      * Look for files in the output dir first, consistent with a vpath search.
      43             :      * This is mainly to create more reasonable error messages if the file is
      44             :      * not found.  It also allows local test overrides when running pg_regress
      45             :      * outside of the source tree.
      46             :      */
      47         180 :     snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
      48             :              outputdir, testname);
      49         180 :     if (!file_exists(infile))
      50           0 :         snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
      51             :                  inputdir, testname);
      52             : 
      53         180 :     snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
      54             :              outputdir, testname);
      55             : 
      56         180 :     snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
      57             :              outputdir, testname);
      58         180 :     if (!file_exists(expectfile))
      59           0 :         snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
      60             :                  inputdir, testname);
      61             : 
      62         180 :     add_stringlist_item(resultfiles, outfile);
      63         180 :     add_stringlist_item(expectfiles, expectfile);
      64             : 
      65         180 :     if (launcher)
      66           0 :         offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
      67             :                            "%s ", launcher);
      68             : 
      69         180 :     appnameenv = psprintf("PGAPPNAME=pg_regress/%s", testname);
      70         180 :     putenv(appnameenv);
      71             : 
      72         540 :     snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
      73             :              "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1",
      74         180 :              bindir ? bindir : "",
      75         180 :              bindir ? "/" : "",
      76         180 :              dblist->str,
      77             :              infile,
      78             :              outfile);
      79             : 
      80         180 :     pid = spawn_process(psql_cmd);
      81             : 
      82         180 :     if (pid == INVALID_PID)
      83             :     {
      84           0 :         fprintf(stderr, _("could not start process for test %s\n"),
      85             :                 testname);
      86           0 :         exit(2);
      87             :     }
      88             : 
      89         180 :     unsetenv("PGAPPNAME");
      90         180 :     free(appnameenv);
      91             : 
      92         180 :     return pid;
      93             : }
      94             : 
      95             : static void
      96           1 : psql_init(int argc, char **argv)
      97             : {
      98             :     /* set default regression database name */
      99           1 :     add_stringlist_item(&dblist, "regression");
     100           1 : }
     101             : 
     102             : int
     103           1 : main(int argc, char *argv[])
     104             : {
     105           1 :     return regression_main(argc, argv, psql_init, psql_start_test);
     106             : }

Generated by: LCOV version 1.11