LCOV - code coverage report
Current view: top level - gcc - selftest-logical-location.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 84.6 % 39 33
Test Date: 2025-06-21 16:26:05 Functions: 70.0 % 10 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Concrete subclass of logical_location for use in selftests.
       2                 :             :    Copyright (C) 2024-2025 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                 :             : #include "config.h"
      22                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "selftest.h"
      25                 :             : #include "selftest-logical-location.h"
      26                 :             : 
      27                 :             : #if CHECKING_P
      28                 :             : 
      29                 :             : namespace selftest {
      30                 :             : 
      31                 :             : /* class test_logical_location_manager : public logical_location_manager.  */
      32                 :             : 
      33                 :        1656 : test_logical_location_manager::~test_logical_location_manager ()
      34                 :             : {
      35                 :        1752 :   for (auto iter : m_name_to_item_map)
      36                 :          48 :     delete iter.second;
      37                 :        1656 : }
      38                 :             : 
      39                 :             : const char *
      40                 :           8 : test_logical_location_manager::get_short_name (key k) const
      41                 :             : {
      42                 :           8 :   auto item = item_from_key (k);
      43                 :           8 :   if (!item)
      44                 :             :     return nullptr;
      45                 :           8 :   return item->m_name;
      46                 :             : }
      47                 :             : 
      48                 :             : const char *
      49                 :           0 : test_logical_location_manager::get_name_with_scope (key k) const
      50                 :             : {
      51                 :           0 :   auto item = item_from_key (k);
      52                 :           0 :   return item->m_name;
      53                 :             : }
      54                 :             : 
      55                 :             : const char *
      56                 :           0 : test_logical_location_manager::get_internal_name (key k) const
      57                 :             : {
      58                 :           0 :   auto item = item_from_key (k);
      59                 :           0 :   return item->m_name;
      60                 :             : }
      61                 :             : 
      62                 :             : enum logical_location_kind
      63                 :          16 : test_logical_location_manager::get_kind (key k) const
      64                 :             : {
      65                 :          16 :   auto item = item_from_key (k);
      66                 :          16 :   return item->m_kind;
      67                 :             : }
      68                 :             : 
      69                 :             : label_text
      70                 :         148 : test_logical_location_manager::get_name_for_path_output (key k) const
      71                 :             : {
      72                 :         148 :   auto item = item_from_key (k);
      73                 :         148 :   return label_text::borrow (item->m_name);
      74                 :             : }
      75                 :             : 
      76                 :             : logical_location
      77                 :        4664 : test_logical_location_manager::
      78                 :             : logical_location_from_funcname (const char *funcname)
      79                 :             : {
      80                 :        4664 :   const item *i = item_from_funcname (funcname);
      81                 :        4664 :   return key::from_ptr (i);
      82                 :             : }
      83                 :             : 
      84                 :             : const test_logical_location_manager::item *
      85                 :        4664 : test_logical_location_manager::item_from_funcname (const char *funcname)
      86                 :             : {
      87                 :        4664 :   if (!funcname)
      88                 :             :     return nullptr;
      89                 :             : 
      90                 :         148 :   if (item **slot = m_name_to_item_map.get (funcname))
      91                 :         100 :     return *slot;
      92                 :             : 
      93                 :          48 :   item *i = new item (logical_location_kind::function, funcname);
      94                 :          48 :   m_name_to_item_map.put (funcname, i);
      95                 :          48 :   return i;
      96                 :             : }
      97                 :             : 
      98                 :             : /* Run all of the selftests within this file.  */
      99                 :             : 
     100                 :             : void
     101                 :           4 : selftest_logical_location_cc_tests ()
     102                 :             : {
     103                 :           4 :   test_logical_location_manager mgr;
     104                 :             : 
     105                 :           4 :   ASSERT_FALSE (mgr.logical_location_from_funcname (nullptr));
     106                 :             : 
     107                 :           4 :   logical_location loc_foo = mgr.logical_location_from_funcname ("foo");
     108                 :           4 :   logical_location loc_bar = mgr.logical_location_from_funcname ("bar");
     109                 :             : 
     110                 :           4 :   ASSERT_NE (loc_foo, loc_bar);
     111                 :             : 
     112                 :           4 :   ASSERT_STREQ (mgr.get_short_name (loc_foo), "foo");
     113                 :           4 :   ASSERT_STREQ (mgr.get_short_name (loc_bar), "bar");
     114                 :           4 : }
     115                 :             : 
     116                 :             : } // namespace selftest
     117                 :             : 
     118                 :             : #endif /* #if CHECKING_P */
        

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.