Bitcoin Core 28.99.0
P2P Digital Currency
util_trace_tests.cpp
Go to the documentation of this file.
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
6
7#include <boost/test/unit_test.hpp>
8
9#include <util/trace.h>
10
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);
17
19
20// Tests the TRACEPOINT macro and that we can compile tracepoints with 0 to 12 args.
21BOOST_AUTO_TEST_CASE(test_tracepoints)
22{
23 TRACEPOINT(test, zero_args);
24 TRACEPOINT(test, one_arg, 1);
25 TRACEPOINT(test, six_args, 1, 2, 3, 4, 5, 6);
26 TRACEPOINT(test, twelve_args, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
27 BOOST_CHECK(true);
28}
29
31{
32 BOOST_CHECK(false);
33 return 0;
34}
35
36BOOST_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 TRACEPOINT(test, check_if_attached, fail_test_if_executed());
43 BOOST_CHECK(true);
44}
45
46BOOST_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 if (TRACEPOINT_ACTIVE(test, expensive_section)) {
52 BOOST_CHECK(false); // expensive_function()
53 TRACEPOINT(test, expensive_section);
54 }
55 BOOST_CHECK(true);
56}
57
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK(expr)
Definition: object.cpp:17
Basic testing setup.
Definition: setup_common.h:63
#define TRACEPOINT_ACTIVE(context, event)
Definition: trace.h:48
#define TRACEPOINT(context,...)
Definition: trace.h:49
int fail_test_if_executed()
TRACEPOINT_SEMAPHORE(test, zero_args)
BOOST_AUTO_TEST_CASE(test_tracepoints)