Skip to content

Commit 0f77fa5

Browse files
committed
update tracing scripts to use correct probe names as in c++ code
1 parent ef79d87 commit 0f77fa5

9 files changed

Lines changed: 206 additions & 111 deletions

cmake/module/FindUSDT.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ if(USDT_FOUND AND NOT TARGET USDT::headers)
7474
set_target_properties(USDT::headers PROPERTIES
7575
INTERFACE_INCLUDE_DIRECTORIES "${USDT_INCLUDE_DIR}"
7676
)
77-
set(ENABLE_TRACING TRUE)
77+
set(ENABLE_TRACING ON)
7878
endif()

src/test/checkqueue_tests.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <vector>
1717
#include <mutex>
1818
#include <condition_variable>
19+
#include <chrono>
1920

2021
#include <unordered_set>
2122
#include <memory>
@@ -221,18 +222,39 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
221222
auto fail_queue = new Failing_Queue{QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS};
222223

223224
for (size_t i = 0; i < 1001; ++i) {
224-
CCheckQueueControl<FailingCheck> control(fail_queue);
225-
size_t remaining = i;
226-
while (remaining) {
227-
size_t r = InsecureRandRange(10);
225+
std::atomic<bool> test_completed{false};
226+
std::atomic<bool> test_success{false};
228227

229-
std::vector<FailingCheck> vChecks;
230-
vChecks.reserve(r);
231-
for (size_t k = 0; k < r && remaining; k++, remaining--)
232-
vChecks.emplace_back(remaining == 1);
233-
control.Add(std::move(vChecks));
228+
std::thread test_thread([&]() {
229+
CCheckQueueControl<FailingCheck> control(fail_queue);
230+
size_t remaining = i;
231+
while (remaining) {
232+
size_t r = InsecureRandRange(10);
233+
std::vector<FailingCheck> vChecks;
234+
vChecks.reserve(r);
235+
for (size_t k = 0; k < r && remaining; k++, remaining--)
236+
vChecks.emplace_back(remaining == 1);
237+
control.Add(std::move(vChecks));
238+
}
239+
bool success = control.Wait();
240+
test_success.store(success);
241+
test_completed.store(true);
242+
});
243+
244+
// Wait for test completion with timeout
245+
auto start_time = std::chrono::steady_clock::now();
246+
while (!test_completed.load() &&
247+
std::chrono::steady_clock::now() - start_time < std::chrono::seconds(10)) {
248+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
249+
}
250+
251+
if (test_thread.joinable()) {
252+
test_thread.join();
234253
}
235-
bool success = control.Wait();
254+
255+
BOOST_REQUIRE(test_completed.load());
256+
257+
bool success = test_success.load();
236258
if (i > 0) {
237259
BOOST_REQUIRE(!success);
238260
} else if (i == 0) {

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ if(NOT ENABLE_ZMQ)
1919
set(ENABLE_ZMQ_TRUE "#")
2020
endif()
2121

22+
if(NOT ENABLE_TRACING)
23+
set(ENABLE_TRACING_TRUE "#")
24+
endif()
25+
2226
# Create build ini file in build and source dir
2327
configure_file(config.ini.in config.ini USE_SOURCE_PERMISSIONS @ONLY)
2428
configure_file(config.ini.in ${abs_top_srcdir}/test/config.ini USE_SOURCE_PERMISSIONS @ONLY)

test/config.ini.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
2020
@BUILD_GENESIS_TRUE@BUILD_GENESIS=true
2121
@ENABLE_WALLET_TRUE@ENABLE_WALLET=true
2222
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true
23-
@ENABLE_USDT_TRACEPOINTS_TRUE@ENABLE_USDT_TRACEPOINTS=true
23+
@ENABLE_TRACING_TRUE@ENABLE_TRACING=true

test/functional/interface_usdt_coinselection.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,29 @@
2323
coinselection_tracepoints_program = """
2424
#include <uapi/linux/ptrace.h>
2525
26-
#define WALLET_NAME_LENGTH 16
26+
#define COLOR_ID_LENGTH 64
2727
#define ALGO_NAME_LENGTH 16
2828
2929
struct event_data
3030
{
3131
u8 type;
32-
char wallet_name[WALLET_NAME_LENGTH];
32+
char color_id[COLOR_ID_LENGTH];
3333
34-
// selected coins event
35-
char algo[ALGO_NAME_LENGTH];
36-
s64 target;
37-
s64 waste;
34+
// selected coins event (type 1)
35+
s64 target_value;
3836
s64 selected_value;
37+
s64 num_coins;
38+
char algo[ALGO_NAME_LENGTH];
39+
40+
// coins requested event (type 2)
41+
s64 amount;
3942
40-
// create tx event
41-
bool success;
42-
s64 fee;
43-
s32 change_pos;
43+
// change info event (type 3)
44+
s64 change_amount;
4445
45-
// aps create tx event
46-
bool use_aps;
46+
// fee info event (type 4)
47+
s64 fee_ret;
48+
s64 fee_needed;
4749
};
4850
4951
BPF_QUEUE(coin_selection_events, struct event_data, 1024);
@@ -52,45 +54,41 @@
5254
struct event_data data;
5355
__builtin_memset(&data, 0, sizeof(data));
5456
data.type = 1;
55-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
56-
bpf_usdt_readarg_p(2, ctx, &data.algo, ALGO_NAME_LENGTH);
57-
bpf_usdt_readarg(3, ctx, &data.target);
58-
bpf_usdt_readarg(4, ctx, &data.waste);
59-
bpf_usdt_readarg(5, ctx, &data.selected_value);
57+
bpf_usdt_readarg_p(1, ctx, &data.color_id, COLOR_ID_LENGTH);
58+
bpf_usdt_readarg(2, ctx, &data.target_value);
59+
bpf_usdt_readarg(3, ctx, &data.selected_value);
60+
bpf_usdt_readarg(4, ctx, &data.num_coins);
61+
bpf_usdt_readarg_p(5, ctx, &data.algo, ALGO_NAME_LENGTH);
6062
coin_selection_events.push(&data, 0);
6163
return 0;
6264
}
6365
64-
int trace_normal_create_tx(struct pt_regs *ctx) {
66+
int trace_coins_requested(struct pt_regs *ctx) {
6567
struct event_data data;
6668
__builtin_memset(&data, 0, sizeof(data));
6769
data.type = 2;
68-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
69-
bpf_usdt_readarg(2, ctx, &data.success);
70-
bpf_usdt_readarg(3, ctx, &data.fee);
71-
bpf_usdt_readarg(4, ctx, &data.change_pos);
70+
bpf_usdt_readarg(1, ctx, &data.amount);
71+
bpf_usdt_readarg_p(2, ctx, &data.color_id, COLOR_ID_LENGTH);
7272
coin_selection_events.push(&data, 0);
7373
return 0;
7474
}
7575
76-
int trace_attempt_aps(struct pt_regs *ctx) {
76+
int trace_change_info(struct pt_regs *ctx) {
7777
struct event_data data;
7878
__builtin_memset(&data, 0, sizeof(data));
7979
data.type = 3;
80-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
80+
bpf_usdt_readarg(1, ctx, &data.change_amount);
81+
bpf_usdt_readarg_p(2, ctx, &data.color_id, COLOR_ID_LENGTH);
8182
coin_selection_events.push(&data, 0);
8283
return 0;
8384
}
8485
85-
int trace_aps_create_tx(struct pt_regs *ctx) {
86+
int trace_fee_info(struct pt_regs *ctx) {
8687
struct event_data data;
8788
__builtin_memset(&data, 0, sizeof(data));
8889
data.type = 4;
89-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
90-
bpf_usdt_readarg(2, ctx, &data.use_aps);
91-
bpf_usdt_readarg(3, ctx, &data.success);
92-
bpf_usdt_readarg(4, ctx, &data.fee);
93-
bpf_usdt_readarg(5, ctx, &data.change_pos);
90+
bpf_usdt_readarg(1, ctx, &data.fee_ret);
91+
bpf_usdt_readarg(2, ctx, &data.fee_needed);
9492
coin_selection_events.push(&data, 0);
9593
return 0;
9694
}
@@ -99,7 +97,7 @@
9997

10098
class CoinSelectionTracepointTest(BitcoinTestFramework):
10199
def add_options(self, parser):
102-
self.add_wallet_options(parser)
100+
pass
103101

104102
def set_test_params(self):
105103
self.num_nodes = 1
@@ -165,9 +163,9 @@ def run_test(self):
165163
self.log.info("hook into the coin_selection tracepoints")
166164
ctx = USDT(pid=self.nodes[0].process.pid)
167165
ctx.enable_probe(probe="coin_selection:selected_coins", fn_name="trace_selected_coins")
168-
ctx.enable_probe(probe="coin_selection:normal_create_tx_internal", fn_name="trace_normal_create_tx")
169-
ctx.enable_probe(probe="coin_selection:attempting_aps_create_tx", fn_name="trace_attempt_aps")
170-
ctx.enable_probe(probe="coin_selection:aps_create_tx_internal", fn_name="trace_aps_create_tx")
166+
ctx.enable_probe(probe="coin_selection:coins_requested", fn_name="trace_coins_requested")
167+
ctx.enable_probe(probe="coin_selection:change_info", fn_name="trace_change_info")
168+
ctx.enable_probe(probe="coin_selection:fee_info", fn_name="trace_fee_info")
171169
self.bpf = BPF(text=coinselection_tracepoints_program, usdt_contexts=[ctx], debug=0)
172170

173171
self.log.info("Prepare wallets")

test/functional/interface_usdt_mempool.py

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616
from test_framework.util import assert_equal, TAPYRUS_MODES
1717
from test_framework.timeout_config import TAPYRUSD_SYNC_TIMEOUT
1818

19-
MEMPOOL_TRACEPOINTS_PROGRAM = """
19+
MEMPOOL_ADDED_PROGRAM = """
2020
# include <uapi/linux/ptrace.h>
2121
22-
// The longest rejection reason is 118 chars and is generated in case of SCRIPT_ERR_EVAL_FALSE by
23-
// strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(check.GetScriptError()))
24-
#define MAX_REJECT_REASON_LENGTH 118
25-
// The longest string returned by RemovalReasonToString() is 'sizelimit'
26-
#define MAX_REMOVAL_REASON_LENGTH 9
27-
#define HASH_LENGTH 32
22+
#define HASH_LENGTH 32
2823
2924
struct added_event
3025
{
@@ -33,37 +28,7 @@
3328
s64 fee;
3429
};
3530
36-
struct removed_event
37-
{
38-
u8 hash[HASH_LENGTH];
39-
char reason[MAX_REMOVAL_REASON_LENGTH];
40-
s32 vsize;
41-
s64 fee;
42-
u64 entry_time;
43-
};
44-
45-
struct rejected_event
46-
{
47-
u8 hash[HASH_LENGTH];
48-
char reason[MAX_REJECT_REASON_LENGTH];
49-
};
50-
51-
struct replaced_event
52-
{
53-
u8 replaced_hash[HASH_LENGTH];
54-
s32 replaced_vsize;
55-
s64 replaced_fee;
56-
u64 replaced_entry_time;
57-
u8 replacement_hash[HASH_LENGTH];
58-
s32 replacement_vsize;
59-
s64 replacement_fee;
60-
};
61-
62-
// BPF perf buffer to push the data to user space.
6331
BPF_PERF_OUTPUT(added_events);
64-
BPF_PERF_OUTPUT(removed_events);
65-
BPF_PERF_OUTPUT(rejected_events);
66-
BPF_PERF_OUTPUT(replaced_events);
6732
6833
int trace_added(struct pt_regs *ctx) {
6934
struct added_event added = {};
@@ -75,6 +40,24 @@
7540
added_events.perf_submit(ctx, &added, sizeof(added));
7641
return 0;
7742
}
43+
"""
44+
45+
MEMPOOL_REMOVED_PROGRAM = """
46+
# include <uapi/linux/ptrace.h>
47+
48+
#define MAX_REMOVAL_REASON_LENGTH 9
49+
#define HASH_LENGTH 32
50+
51+
struct removed_event
52+
{
53+
u8 hash[HASH_LENGTH];
54+
char reason[MAX_REMOVAL_REASON_LENGTH];
55+
s32 vsize;
56+
s64 fee;
57+
u64 entry_time;
58+
};
59+
60+
BPF_PERF_OUTPUT(removed_events);
7861
7962
int trace_removed(struct pt_regs *ctx) {
8063
struct removed_event removed = {};
@@ -88,6 +71,21 @@
8871
removed_events.perf_submit(ctx, &removed, sizeof(removed));
8972
return 0;
9073
}
74+
"""
75+
76+
MEMPOOL_REJECTED_PROGRAM = """
77+
# include <uapi/linux/ptrace.h>
78+
79+
#define MAX_REJECT_REASON_LENGTH 118
80+
#define HASH_LENGTH 32
81+
82+
struct rejected_event
83+
{
84+
u8 hash[HASH_LENGTH];
85+
char reason[MAX_REJECT_REASON_LENGTH];
86+
};
87+
88+
BPF_PERF_OUTPUT(rejected_events);
9189
9290
int trace_rejected(struct pt_regs *ctx) {
9391
struct rejected_event rejected = {};
@@ -98,6 +96,25 @@
9896
rejected_events.perf_submit(ctx, &rejected, sizeof(rejected));
9997
return 0;
10098
}
99+
"""
100+
101+
MEMPOOL_REPLACED_PROGRAM = """
102+
# include <uapi/linux/ptrace.h>
103+
104+
#define HASH_LENGTH 32
105+
106+
struct replaced_event
107+
{
108+
u8 replaced_hash[HASH_LENGTH];
109+
s32 replaced_vsize;
110+
s64 replaced_fee;
111+
u64 replaced_entry_time;
112+
u8 replacement_hash[HASH_LENGTH];
113+
s32 replacement_vsize;
114+
s64 replacement_fee;
115+
};
116+
117+
BPF_PERF_OUTPUT(replaced_events);
101118
102119
int trace_replaced(struct pt_regs *ctx) {
103120
struct replaced_event replaced = {};
@@ -138,8 +155,8 @@ def added_test(self):
138155
self.log.info("Hooking into mempool:added tracepoint...")
139156
node = self.nodes[0]
140157
ctx = USDT(pid=node.process.pid)
141-
ctx.enable_probe(probe="added", fn_name="trace_added")
142-
bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0)
158+
ctx.enable_probe(probe="mempool:added", fn_name="trace_added")
159+
bpf = BPF(text=MEMPOOL_ADDED_PROGRAM, usdt_contexts=[ctx], debug=0)
143160

144161
def handle_added_event(_, data, __):
145162
nonlocal handled_added_events
@@ -179,8 +196,8 @@ def removed_test(self):
179196
self.log.info("Hooking into mempool:removed tracepoint...")
180197
node = self.nodes[0]
181198
ctx = USDT(pid=node.process.pid)
182-
ctx.enable_probe(probe="removed", fn_name="trace_removed")
183-
bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0)
199+
ctx.enable_probe(probe="mempool:removed", fn_name="trace_removed")
200+
bpf = BPF(text=MEMPOOL_REMOVED_PROGRAM, usdt_contexts=[ctx], debug=0)
184201

185202
def handle_removed_event(_, data, __):
186203
nonlocal handled_removed_events
@@ -229,8 +246,8 @@ def replaced_test(self):
229246
self.log.info("Hooking into mempool:replaced tracepoint...")
230247
node = self.nodes[0]
231248
ctx = USDT(pid=node.process.pid)
232-
ctx.enable_probe(probe="replaced", fn_name="trace_replaced")
233-
bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0)
249+
ctx.enable_probe(probe="mempool:replaced", fn_name="trace_replaced")
250+
bpf = BPF(text=MEMPOOL_REPLACED_PROGRAM, usdt_contexts=[ctx], debug=0)
234251

235252
def handle_replaced_event(_, data, __):
236253
nonlocal handled_replaced_events
@@ -285,8 +302,8 @@ def rejected_test(self):
285302

286303
self.log.info("Hooking into mempool:rejected tracepoint...")
287304
ctx = USDT(pid=node.process.pid)
288-
ctx.enable_probe(probe="rejected", fn_name="trace_rejected")
289-
bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0)
305+
ctx.enable_probe(probe="mempool:rejected", fn_name="trace_rejected")
306+
bpf = BPF(text=MEMPOOL_REJECTED_PROGRAM, usdt_contexts=[ctx], debug=0)
290307

291308
def handle_rejected_event(_, data, __):
292309
nonlocal handled_rejected_events

test/functional/interface_usdt_net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def __repr__(self):
103103
self.log.info(
104104
"hook into the net:inbound_message and net:outbound_message tracepoints")
105105
ctx = USDT(pid=self.nodes[0].process.pid)
106-
ctx.enable_probe(probe="inbound_message",
106+
ctx.enable_probe(probe="net:inbound_message",
107107
fn_name="trace_inbound_message")
108-
ctx.enable_probe(probe="outbound_message",
108+
ctx.enable_probe(probe="net:outbound_message",
109109
fn_name="trace_outbound_message")
110110
bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=1)
111111

0 commit comments

Comments
 (0)