LCOV - code coverage report
Current view: top level - gcc - selftest-diagnostic-path.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 21 21
Test Date: 2024-12-21 13:15:12 Functions: 100.0 % 8 8
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Concrete classes for selftests involving diagnostic paths.
       2                 :             :    Copyright (C) 2019-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by David Malcolm <dmalcolm@redhat.com>
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #ifndef GCC_SELFTEST_DIAGNOSTIC_PATH_H
      22                 :             : #define GCC_SELFTEST_DIAGNOSTIC_PATH_H
      23                 :             : 
      24                 :             : #include "diagnostic-path.h"
      25                 :             : #include "selftest-logical-location.h"
      26                 :             : 
      27                 :             : /* The selftest code should entirely disappear in a production
      28                 :             :    configuration, hence we guard all of it with #if CHECKING_P.  */
      29                 :             : 
      30                 :             : #if CHECKING_P
      31                 :             : 
      32                 :             : namespace selftest {
      33                 :             : 
      34                 :             : /* Concrete subclasses of the abstract base classes
      35                 :             :    declared in diagnostic-path.h for use in selftests.
      36                 :             : 
      37                 :             :    This code should have no dependency on "tree".  */
      38                 :             : 
      39                 :             : /* An implementation of diagnostic_event.  */
      40                 :             : 
      41                 :             : class test_diagnostic_event : public diagnostic_event
      42                 :             : {
      43                 :             :  public:
      44                 :             :   test_diagnostic_event (location_t loc, const char *funcname, int depth,
      45                 :             :                          const char *desc,
      46                 :             :                          diagnostic_thread_id_t thread_id = 0);
      47                 :             :   ~test_diagnostic_event ();
      48                 :             : 
      49                 :       19164 :   location_t get_location () const final override { return m_loc; }
      50                 :       10712 :   int get_stack_depth () const final override { return m_depth; }
      51                 :        3796 :   void print_desc (pretty_printer &pp) const final override
      52                 :             :   {
      53                 :        3796 :     pp_string (&pp, m_desc);
      54                 :        3796 :   }
      55                 :        2056 :   const logical_location *get_logical_location () const final override
      56                 :             :   {
      57                 :        2056 :     if (m_logical_loc.get_name ())
      58                 :         164 :       return &m_logical_loc;
      59                 :             :     else
      60                 :             :       return nullptr;
      61                 :             :   }
      62                 :        3404 :   meaning get_meaning () const final override
      63                 :             :   {
      64                 :        3404 :     return meaning ();
      65                 :             :   }
      66                 :       12964 :   bool connect_to_next_event_p () const final override
      67                 :             :   {
      68                 :       12964 :     return m_connected_to_next_event;
      69                 :             :   }
      70                 :       10868 :   diagnostic_thread_id_t get_thread_id () const final override
      71                 :             :   {
      72                 :       10868 :     return m_thread_id;
      73                 :             :   }
      74                 :             : 
      75                 :        2016 :   void connect_to_next_event ()
      76                 :             :   {
      77                 :        2016 :     m_connected_to_next_event = true;
      78                 :             :   }
      79                 :             : 
      80                 :       12480 :   const char *get_function_name () const
      81                 :             :   {
      82                 :        6240 :     return m_logical_loc.get_name ();
      83                 :             :   }
      84                 :             : 
      85                 :             :  private:
      86                 :             :   location_t m_loc;
      87                 :             :   test_logical_location m_logical_loc;
      88                 :             :   int m_depth;
      89                 :             :   char *m_desc; // has been formatted; doesn't get i18n-ed
      90                 :             :   bool m_connected_to_next_event;
      91                 :             :   diagnostic_thread_id_t m_thread_id;
      92                 :             : };
      93                 :             : 
      94                 :             : /* A simple implementation of diagnostic_thread.  */
      95                 :             : 
      96                 :             : class test_diagnostic_thread : public diagnostic_thread
      97                 :             : {
      98                 :             : public:
      99                 :        1652 :   test_diagnostic_thread (const char *name) : m_name (name) {}
     100                 :        1280 :   label_text get_name (bool) const final override
     101                 :             :   {
     102                 :        1280 :     return label_text::borrow (m_name);
     103                 :             :   }
     104                 :             : 
     105                 :             : private:
     106                 :             :   const char *m_name; // has been i18n-ed and formatted
     107                 :             : };
     108                 :             : 
     109                 :             : /* A concrete subclass of diagnostic_path for implementing selftests
     110                 :             :    - a vector of test_diagnostic_event instances
     111                 :             :    - adds member functions for adding test event
     112                 :             :    - does no translation of its events
     113                 :             :    - has no dependency on "tree".  */
     114                 :             : 
     115                 :             : class test_diagnostic_path : public diagnostic_path
     116                 :             : {
     117                 :             :  public:
     118                 :             :   test_diagnostic_path (pretty_printer *event_pp);
     119                 :             : 
     120                 :             :   unsigned num_events () const final override;
     121                 :             :   const diagnostic_event & get_event (int idx) const final override;
     122                 :             :   unsigned num_threads () const final override;
     123                 :             :   const diagnostic_thread &
     124                 :             :   get_thread (diagnostic_thread_id_t) const final override;
     125                 :             :   bool
     126                 :             :   same_function_p (int event_idx_a,
     127                 :             :                    int event_idx_b) const final override;
     128                 :             : 
     129                 :             :   diagnostic_thread_id_t add_thread (const char *name);
     130                 :             : 
     131                 :             :   diagnostic_event_id_t add_event (location_t loc, const char *funcname, int depth,
     132                 :             :                                    const char *fmt, ...)
     133                 :             :     ATTRIBUTE_GCC_DIAG(5,6);
     134                 :             :   diagnostic_event_id_t
     135                 :             :   add_thread_event (diagnostic_thread_id_t thread_id,
     136                 :             :                     location_t loc, const char *funcname, int depth,
     137                 :             :                     const char *fmt, ...)
     138                 :             :     ATTRIBUTE_GCC_DIAG(6,7);
     139                 :             : 
     140                 :             :   void connect_to_next_event ();
     141                 :             : 
     142                 :             :   void add_entry (const char *callee_name, int stack_depth,
     143                 :             :                   diagnostic_thread_id_t thread_id = 0);
     144                 :             :   void add_return (const char *caller_name, int stack_depth,
     145                 :             :                    diagnostic_thread_id_t thread_id = 0);
     146                 :             :   void add_call (const char *caller_name,
     147                 :             :                  int caller_stack_depth,
     148                 :             :                  const char *callee_name,
     149                 :             :                  diagnostic_thread_id_t thread_id = 0);
     150                 :             : 
     151                 :             :  private:
     152                 :             :   auto_delete_vec<test_diagnostic_thread> m_threads;
     153                 :             :   auto_delete_vec<test_diagnostic_event> m_events;
     154                 :             : 
     155                 :             :   /* (for use by add_event).  */
     156                 :             :   pretty_printer *m_event_pp;
     157                 :             : };
     158                 :             : 
     159                 :             : } // namespace selftest
     160                 :             : 
     161                 :             : #endif /* #if CHECKING_P */
     162                 :             : 
     163                 :             : #endif /* ! GCC_SELFTEST_DIAGNOSTIC_PATH_H */
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.