LCOV - code coverage report
Current view: top level - src/test/regress - pg_regress_main.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 29 37 78.4 %
Date: 2023-12-11 15:11:28 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-2023, 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        1854 : 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        1854 :     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        1854 :     snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
      48             :              outputdir, testname);
      49        1854 :     if (!file_exists(infile))
      50         864 :         snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
      51             :                  inputdir, testname);
      52             : 
      53        1854 :     snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
      54             :              outputdir, testname);
      55             : 
      56        1854 :     snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
      57             :              outputdir, testname);
      58        1854 :     if (!file_exists(expectfile))
      59         864 :         snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
      60             :                  inputdir, testname);
      61             : 
      62        1854 :     add_stringlist_item(resultfiles, outfile);
      63        1854 :     add_stringlist_item(expectfiles, expectfile);
      64             : 
      65        1854 :     if (launcher)
      66             :     {
      67           0 :         offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
      68             :                            "%s ", launcher);
      69           0 :         if (offset >= sizeof(psql_cmd))
      70             :         {
      71           0 :             fprintf(stderr, _("command too long\n"));
      72           0 :             exit(2);
      73             :         }
      74             :     }
      75             : 
      76             :     /*
      77             :      * Use HIDE_TABLEAM to hide different AMs to allow to use regression tests
      78             :      * against different AMs without unnecessary differences.
      79             :      */
      80        3708 :     offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
      81             :                        "\"%s%spsql\" -X -a -q -d \"%s\" %s < \"%s\" > \"%s\" 2>&1",
      82        1854 :                        bindir ? bindir : "",
      83        1854 :                        bindir ? "/" : "",
      84        1854 :                        dblist->str,
      85             :                        "-v HIDE_TABLEAM=on -v HIDE_TOAST_COMPRESSION=on",
      86             :                        infile,
      87             :                        outfile);
      88        1854 :     if (offset >= sizeof(psql_cmd))
      89             :     {
      90           0 :         fprintf(stderr, _("command too long\n"));
      91           0 :         exit(2);
      92             :     }
      93             : 
      94        1854 :     appnameenv = psprintf("pg_regress/%s", testname);
      95        1854 :     setenv("PGAPPNAME", appnameenv, 1);
      96        1854 :     free(appnameenv);
      97             : 
      98        1854 :     pid = spawn_process(psql_cmd);
      99             : 
     100        1854 :     if (pid == INVALID_PID)
     101             :     {
     102           0 :         fprintf(stderr, _("could not start process for test %s\n"),
     103             :                 testname);
     104           0 :         exit(2);
     105             :     }
     106             : 
     107        1854 :     unsetenv("PGAPPNAME");
     108             : 
     109        1854 :     return pid;
     110             : }
     111             : 
     112             : static void
     113         612 : psql_init(int argc, char **argv)
     114             : {
     115             :     /* set default regression database name */
     116         612 :     add_stringlist_item(&dblist, "regression");
     117         612 : }
     118             : 
     119             : int
     120         612 : main(int argc, char *argv[])
     121             : {
     122         612 :     return regression_main(argc, argv,
     123             :                            psql_init,
     124             :                            psql_start_test,
     125             :                            NULL /* no postfunc needed */ );
     126             : }

Generated by: LCOV version 1.14