LCOV - code coverage report
Current view: top level - src/dblib/unittests - proc_limit.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 28 32 87.5 %
Date: 2025-01-18 11:50:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Purpose: Test reaching processes limit trigger a specific error
       3             :  * Functions: dbopen dbsetmaxprocs
       4             :  */
       5             : 
       6             : #include "common.h"
       7             : #include <freetds/bool.h>
       8             : 
       9             : static bool proc_limit_hit = false;
      10             : 
      11             : static int
      12           8 : err_handler(DBPROCESS * dbproc TDS_UNUSED, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
      13             : {
      14           8 :         if (dberr == 20011) {
      15           8 :                 proc_limit_hit = true;
      16           8 :                 fprintf(stderr, "OK: anticipated error %d (%s) arrived\n", dberr, dberrstr);
      17           8 :                 return INT_CANCEL;
      18             :         }
      19             : 
      20           0 :         fprintf(stderr,
      21             :                 "DB-LIBRARY error (severity %d, dberr %d, oserr %d, dberrstr %s, oserrstr %s):\n",
      22             :                 severity, dberr, oserr, dberrstr ? dberrstr : "(null)", oserrstr ? oserrstr : "(null)");
      23           0 :         fflush(stderr);
      24             : 
      25           0 :         return INT_CANCEL;
      26             : }
      27             : 
      28             : int
      29           8 : main(int argc, char *argv[])
      30             : {
      31             :         LOGINREC *login;
      32             :         DBPROCESS *dbproc, *dbproc2;
      33           8 :         bool failed = false;
      34             : 
      35           8 :         set_malloc_options();
      36             : 
      37           8 :         read_login_info(argc, argv);
      38           8 :         printf("Starting %s\n", argv[0]);
      39           8 :         dbinit();
      40             : 
      41             :         /* limit number of processes to get error */
      42           8 :         dbsetmaxprocs(1);
      43             : 
      44           8 :         dberrhandle(syb_err_handler);
      45           8 :         dbmsghandle(syb_msg_handler);
      46             : 
      47           8 :         printf("About to logon\n");
      48             : 
      49           8 :         login = dblogin();
      50           8 :         DBSETLPWD(login, PASSWORD);
      51           8 :         DBSETLUSER(login, USER);
      52           8 :         DBSETLAPP(login, "proc_limit");
      53             : 
      54           8 :         dbproc = dbopen(login, SERVER);
      55             : 
      56             :         /* another process should fail as limit reached */
      57           8 :         dberrhandle(err_handler);
      58           8 :         dbproc2 = dbopen(login, SERVER);
      59           8 :         dbloginfree(login);
      60             : 
      61           8 :         if (dbproc == NULL || dbproc2 != NULL || !proc_limit_hit)
      62           0 :                 failed = true;
      63             : 
      64           8 :         dbclose(dbproc);
      65           8 :         dbexit();
      66             : 
      67           8 :         printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
      68           8 :         return failed ? 1 : 0;
      69             : }

Generated by: LCOV version 1.13