LCOV - code coverage report
Current view: top level - tests/harness - fdtracker.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 1 2 50.0 %
Date: 2019-06-30 05:20:33 Functions: 1 2 50.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file fdtracker.h
       2                 :            :  * @brief Track leaked file descriptors.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2010,2018 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_FDTRACKER_H
      22                 :            : #define XAPIAN_INCLUDED_FDTRACKER_H
      23                 :            : 
      24                 :            : #include <string>
      25                 :            : #include <vector>
      26                 :            : 
      27                 :            : // Disable fd tracking where it can't possibly work.
      28                 :            : #ifndef __WIN32__
      29                 :            : # define XAPIAN_TESTSUITE_TRACK_FDS
      30                 :            : #endif
      31                 :            : 
      32                 :            : class FDTracker {
      33                 :            : #ifdef XAPIAN_TESTSUITE_TRACK_FDS
      34                 :            :     /** Which fds are open.
      35                 :            :      *
      36                 :            :      *  The lowest unused fd is used whenever a new fd is needed so we
      37                 :            :      *  can expect them to form a dense set and vector<bool> should be an
      38                 :            :      *  efficient representation both in space and time.
      39                 :            :      */
      40                 :            :     std::vector<bool> fds;
      41                 :            : 
      42                 :            :     /** The DIR* from opendir("/proc/self/fd") (or equivalent) cast to void*.
      43                 :            :      *
      44                 :            :      *  We store this cast to void* here to minimise the header we have to
      45                 :            :      *  include here.
      46                 :            :      */
      47                 :            :     void * dir_void;
      48                 :            : 
      49                 :            :     std::string message;
      50                 :            : 
      51                 :            :     void mark_fd(int fd);
      52                 :            : 
      53                 :            :     bool check_fd(int fd) const;
      54                 :            : 
      55                 :            :   public:
      56         [ +  - ]:       2607 :     FDTracker() : dir_void(NULL) { }
      57                 :            : 
      58                 :            :     ~FDTracker();
      59                 :            : 
      60                 :            :     void init();
      61                 :            : 
      62                 :            :     bool check();
      63                 :            : 
      64                 :          0 :     const std::string & get_message() const { return message; }
      65                 :            : #else
      66                 :            :   public:
      67                 :            :     FDTracker() { }
      68                 :            : 
      69                 :            :     void init() { }
      70                 :            : 
      71                 :            :     bool check() { return true; }
      72                 :            : 
      73                 :            :     std::string get_message() const { return std::string(); }
      74                 :            : #endif
      75                 :            : 
      76                 :            :     FDTracker(const FDTracker&) = delete;
      77                 :            : 
      78                 :            :     FDTracker& operator=(const FDTracker&) = delete;
      79                 :            : };
      80                 :            : 
      81                 :            : #endif // XAPIAN_INCLUDED_FDTRACKER_H

Generated by: LCOV version 1.11