Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2023-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <test/util/setup_common.h>7#include <boost/test/unit_test.hpp>9#include <util/trace.h>11TRACEPOINT_SEMAPHORE(test, zero_args);12TRACEPOINT_SEMAPHORE(test, one_arg);13TRACEPOINT_SEMAPHORE(test, six_args);14TRACEPOINT_SEMAPHORE(test, twelve_args);15TRACEPOINT_SEMAPHORE(test, check_if_attached);16TRACEPOINT_SEMAPHORE(test, expensive_section);18BOOST_FIXTURE_TEST_SUITE(util_trace_tests, BasicTestingSetup)20// Tests the TRACEPOINT macro and that we can compile tracepoints with 0 to 12 args.21BOOST_AUTO_TEST_CASE(test_tracepoints)22{23TRACEPOINT(test, zero_args);24TRACEPOINT(test, one_arg, 1);25TRACEPOINT(test, six_args, 1, 2, 3, 4, 5, 6);26TRACEPOINT(test, twelve_args, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);27BOOST_CHECK(true);28}30int fail_test_if_executed()31{32BOOST_CHECK(false);33return 0;34}36BOOST_AUTO_TEST_CASE(test_tracepoint_check_if_attached)37{38// TRACEPOINT should check if we are attaching to the tracepoint and only then39// process arguments. This means, only if we are attached to the40// `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.42TRACEPOINT(test, check_if_attached, fail_test_if_executed());43BOOST_CHECK(true);44}46BOOST_AUTO_TEST_CASE(test_tracepoint_manual_tracepoint_active_check)47{48// We should be able to use the TRACEPOINT_ACTIVE() macro to only49// execute an 'expensive' code section if we are attached to the50// tracepoint.51if (TRACEPOINT_ACTIVE(test, expensive_section)) {52BOOST_CHECK(false); // expensive_function()53TRACEPOINT(test, expensive_section);54}55BOOST_CHECK(true);56}58BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.