LCOV - code coverage report
Current view: top level - src/test - util_trace_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 83.3 % 18 15
Test Date: 2025-01-19 05:08:01 Functions: 85.7 % 7 6
Branches: 49.5 % 188 93

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2023 The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <test/util/setup_common.h>
       6                 :             : 
       7                 :             : #include <boost/test/unit_test.hpp>
       8                 :             : 
       9                 :             : #include <util/trace.h>
      10                 :             : 
      11                 :             : TRACEPOINT_SEMAPHORE(test, zero_args);
      12                 :             : TRACEPOINT_SEMAPHORE(test, one_arg);
      13                 :             : TRACEPOINT_SEMAPHORE(test, six_args);
      14                 :             : TRACEPOINT_SEMAPHORE(test, twelve_args);
      15                 :             : TRACEPOINT_SEMAPHORE(test, check_if_attached);
      16                 :             : TRACEPOINT_SEMAPHORE(test, expensive_section);
      17                 :             : 
      18                 :             : BOOST_FIXTURE_TEST_SUITE(util_trace_tests, BasicTestingSetup)
      19                 :             : 
      20                 :             : // Tests the TRACEPOINT macro and that we can compile tracepoints with 0 to 12 args.
      21   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_tracepoints)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      22                 :             : {
      23                 :           1 :     TRACEPOINT(test, zero_args);
      24                 :           1 :     TRACEPOINT(test, one_arg, 1);
      25                 :           1 :     TRACEPOINT(test, six_args, 1, 2, 3, 4, 5, 6);
      26                 :           1 :     TRACEPOINT(test, twelve_args, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
      27         [ +  - ]:           2 :     BOOST_CHECK(true);
      28                 :           1 : }
      29                 :             : 
      30                 :           0 : int fail_test_if_executed()
      31                 :             : {
      32         [ #  # ]:           0 :     BOOST_CHECK(false);
      33                 :           0 :     return 0;
      34                 :             : }
      35                 :             : 
      36   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_tracepoint_check_if_attached)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      37                 :             : {
      38                 :             :     // TRACEPOINT should check if we are attaching to the tracepoint and only then
      39                 :             :     // process arguments. This means, only if we are attached to the
      40                 :             :     // `test:check_if_attached` tracepoint, fail_test_if_executed() is executed.
      41                 :             :     // Since we don't attach to the tracepoint when running the test, it succeeds.
      42                 :           1 :     TRACEPOINT(test, check_if_attached, fail_test_if_executed());
      43         [ +  - ]:           2 :     BOOST_CHECK(true);
      44                 :           1 : }
      45                 :             : 
      46   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(test_tracepoint_manual_tracepoint_active_check)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      47                 :             : {
      48                 :             :     // We should be able to use the TRACEPOINT_ACTIVE() macro to only
      49                 :             :     // execute an 'expensive' code section if we are attached to the
      50                 :             :     // tracepoint.
      51                 :           1 :     if (TRACEPOINT_ACTIVE(test, expensive_section)) {
      52                 :             :         BOOST_CHECK(false); // expensive_function()
      53                 :             :         TRACEPOINT(test, expensive_section);
      54                 :             :     }
      55         [ +  - ]:           2 :     BOOST_CHECK(true);
      56                 :           1 : }
      57                 :             : 
      58                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1