diff options
Diffstat (limited to 'test/functional/interface_usdt_net.py')
-rwxr-xr-x | test/functional/interface_usdt_net.py | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/test/functional/interface_usdt_net.py b/test/functional/interface_usdt_net.py index beb2546153..94baacf3dd 100755 --- a/test/functional/interface_usdt_net.py +++ b/test/functional/interface_usdt_net.py @@ -17,7 +17,7 @@ except ImportError: from test_framework.messages import CBlockHeader, MAX_HEADERS_RESULTS, msg_headers, msg_version from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.util import assert_equal, assert_greater_than # Tor v3 addresses are 62 chars + 6 chars for the port (':12345'). MAX_PEER_ADDR_LENGTH = 68 @@ -91,12 +91,17 @@ struct MisbehavingConnection BPF_PERF_OUTPUT(inbound_messages); int trace_inbound_message(struct pt_regs *ctx) { struct p2p_message msg = {}; + void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL; bpf_usdt_readarg(1, ctx, &msg.peer_id); - bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH); - bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH); - bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH); + bpf_usdt_readarg(2, ctx, &paddr); + bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr); + bpf_usdt_readarg(3, ctx, &pconn_type); + bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type); + bpf_usdt_readarg(4, ctx, &pmsg_type); + bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type); bpf_usdt_readarg(5, ctx, &msg.msg_size); - bpf_usdt_readarg_p(6, ctx, &msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH)); + bpf_usdt_readarg(6, ctx, &pmsg); + bpf_probe_read_user(&msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH), pmsg); inbound_messages.perf_submit(ctx, &msg, sizeof(msg)); return 0; } @@ -104,12 +109,18 @@ int trace_inbound_message(struct pt_regs *ctx) { BPF_PERF_OUTPUT(outbound_messages); int trace_outbound_message(struct pt_regs *ctx) { struct p2p_message msg = {}; + void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL; bpf_usdt_readarg(1, ctx, &msg.peer_id); - bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH); - bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH); - bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH); + bpf_usdt_readarg(1, ctx, &msg.peer_id); + bpf_usdt_readarg(2, ctx, &paddr); + bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr); + bpf_usdt_readarg(3, ctx, &pconn_type); + bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type); + bpf_usdt_readarg(4, ctx, &pmsg_type); + bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type); bpf_usdt_readarg(5, ctx, &msg.msg_size); - bpf_usdt_readarg_p(6, ctx, &msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH)); + bpf_usdt_readarg(6, ctx, &pmsg); + bpf_probe_read_user(&msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH), pmsg); outbound_messages.perf_submit(ctx, &msg, sizeof(msg)); return 0; }; @@ -353,8 +364,8 @@ class NetTracepointTest(BitcoinTestFramework): assert_equal(EXPECTED_INBOUND_CONNECTIONS, len(inbound_connections)) for inbound_connection in inbound_connections: - assert inbound_connection.conn.id > 0 - assert inbound_connection.existing > 0 + assert_greater_than(inbound_connection.conn.id, 0) + assert_greater_than(inbound_connection.existing, 0) assert_equal(b'inbound', inbound_connection.conn.conn_type) assert_equal(NETWORK_TYPE_UNROUTABLE, inbound_connection.conn.network) @@ -394,8 +405,8 @@ class NetTracepointTest(BitcoinTestFramework): assert_equal(EXPECTED_OUTBOUND_CONNECTIONS, len(outbound_connections)) for outbound_connection in outbound_connections: - assert outbound_connection.conn.id > 0 - assert outbound_connection.existing > 0 + assert_greater_than(outbound_connection.conn.id, 0) + assert_greater_than(outbound_connection.existing, 0) assert_equal(EXPECTED_CONNECTION_TYPE, outbound_connection.conn.conn_type.decode('utf-8')) assert_equal(NETWORK_TYPE_UNROUTABLE, outbound_connection.conn.network) @@ -431,8 +442,8 @@ class NetTracepointTest(BitcoinTestFramework): assert_equal(EXPECTED_EVICTED_CONNECTIONS, len(evicted_connections)) for evicted_connection in evicted_connections: - assert evicted_connection.conn.id > 0 - assert evicted_connection.time_established > 0 + assert_greater_than(evicted_connection.conn.id, 0) + assert_greater_than(evicted_connection.time_established, 0) assert_equal("inbound", evicted_connection.conn.conn_type.decode('utf-8')) assert_equal(NETWORK_TYPE_UNROUTABLE, evicted_connection.conn.network) @@ -462,15 +473,15 @@ class NetTracepointTest(BitcoinTestFramework): for _ in range(EXPECTED_MISBEHAVING_CONNECTIONS): testnode = P2PInterface() self.nodes[0].add_p2p_connection(testnode) - testnode.send_message(msg) + testnode.send_without_ping(msg) bpf.perf_buffer_poll(timeout=500) testnode.peer_disconnect() assert_equal(EXPECTED_MISBEHAVING_CONNECTIONS, len(misbehaving_connections)) for misbehaving_connection in misbehaving_connections: - assert misbehaving_connection.id > 0 - assert len(misbehaving_connection.message) > 0 - assert misbehaving_connection.message == b"headers message size = 2001" + assert_greater_than(misbehaving_connection.id, 0) + assert_greater_than(len(misbehaving_connection.message), 0) + assert_equal(misbehaving_connection.message, b"headers message size = 2001") bpf.cleanup() @@ -505,10 +516,10 @@ class NetTracepointTest(BitcoinTestFramework): assert_equal(EXPECTED_CLOSED_CONNECTIONS, len(closed_connections)) for closed_connection in closed_connections: - assert closed_connection.conn.id > 0 + assert_greater_than(closed_connection.conn.id, 0) assert_equal("inbound", closed_connection.conn.conn_type.decode('utf-8')) assert_equal(0, closed_connection.conn.network) - assert closed_connection.time_established > 0 + assert_greater_than(closed_connection.time_established, 0) bpf.cleanup() |