LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - prep.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 26 26
Test Date: 2026-07-03 19:57:34 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 60.0 % 30 18

             Branch data     Line data    Source code
       1                 :             : #include <stdint.h>
       2                 :             : #include <stdlib.h>
       3                 :             : #include "ecpg_config.h"
       4                 :             : 
       5                 :             : #ifdef WIN32
       6                 :             : #define WIN32_LEAN_AND_MEAN
       7                 :             : #include <windows.h>
       8                 :             : #include <process.h>
       9                 :             : #include <locale.h>
      10                 :             : #else
      11                 :             : #include <pthread.h>
      12                 :             : #endif
      13                 :             : #include <stdio.h>
      14                 :             : 
      15                 :             : #define THREADS     16
      16                 :             : #define REPEATS     50
      17                 :             : 
      18                 :             : exec sql include sqlca;
      19                 :             : exec sql include ../regression;
      20                 :             : 
      21                 :             : exec sql whenever sqlerror sqlprint;
      22                 :             : exec sql whenever not found sqlprint;
      23                 :             : 
      24                 :             : #ifdef WIN32
      25                 :             : static unsigned __stdcall fn(void* arg)
      26                 :             : #else
      27                 :          32 : static void* fn(void* arg)
      28                 :             : #endif
      29                 :             : {
      30                 :             :     int i;
      31                 :             : 
      32                 :             :     EXEC SQL BEGIN DECLARE SECTION;
      33                 :             :     int  value;
      34                 :             :     char name[100];
      35                 :          32 :     char query[256] = "INSERT INTO T VALUES ( ? )";
      36                 :             :     EXEC SQL END DECLARE SECTION;
      37                 :             : 
      38                 :          32 :     value = (intptr_t) arg;
      39                 :          32 :     sprintf(name, "Connection: %d", value);
      40                 :             : 
      41                 :          32 :     EXEC SQL CONNECT TO REGRESSDB1 AS :name;
      42         [ -  + ]:          32 :     EXEC SQL SET AUTOCOMMIT TO ON;
      43   [ -  +  +  + ]:        1632 :     for (i = 1; i <= REPEATS; ++i)
      44                 :             :     {
      45                 :        1600 :         EXEC SQL PREPARE I FROM :query;
      46         [ -  + ]:        1600 :         EXEC SQL EXECUTE I USING :value;
      47   [ -  +  -  + ]:        1600 :     }
      48                 :          32 :     EXEC SQL DEALLOCATE I;
      49         [ -  + ]:          32 :     EXEC SQL DISCONNECT :name;
      50         [ -  + ]:          32 : 
      51                 :          32 :     return 0;
      52                 :             : }
      53                 :             : 
      54                 :           2 : int main(void)
      55                 :             : {
      56                 :             :     intptr_t i;
      57                 :             : #ifdef WIN32
      58                 :             :     HANDLE threads[THREADS];
      59                 :             : #else
      60                 :             :     pthread_t threads[THREADS];
      61                 :             : #endif
      62                 :             : 
      63                 :           2 :     EXEC SQL CONNECT TO REGRESSDB1;
      64         [ -  + ]:           2 :     EXEC SQL SET AUTOCOMMIT TO ON;
      65         [ -  + ]:           2 :     EXEC SQL DROP TABLE IF EXISTS T;
      66         [ -  + ]:           2 :     EXEC SQL CREATE TABLE T ( i int );
      67         [ -  + ]:           2 :     EXEC SQL DISCONNECT;
      68         [ -  + ]:           2 : 
      69                 :             : #ifdef WIN32
      70                 :             :     for (i = 0; i < THREADS; ++i)
      71                 :             :     {
      72                 :             :         unsigned id;
      73                 :             :         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
      74                 :             :     }
      75                 :             : 
      76                 :             :     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
      77                 :             :     for (i = 0; i < THREADS; ++i)
      78                 :             :         CloseHandle(threads[i]);
      79                 :             : #else
      80         [ +  + ]:          34 :     for (i = 0; i < THREADS; ++i)
      81                 :          32 :         pthread_create(&threads[i], NULL, fn, (void *) i);
      82         [ +  + ]:          34 :     for (i = 0; i < THREADS; ++i)
      83                 :          32 :         pthread_join(threads[i], NULL);
      84                 :             : #endif
      85                 :             : 
      86                 :           2 :     return 0;
      87                 :             : }
        

Generated by: LCOV version 2.0-1