Changeset View
Changeset View
Standalone View
Standalone View
test/functional/interface_usdt_validation.py
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# back to Python. The exception is ignored. We manually count and assert | # back to Python. The exception is ignored. We manually count and assert | ||||
# that the handle_* functions succeeded. | # that the handle_* functions succeeded. | ||||
BLOCKS_EXPECTED = 2 | BLOCKS_EXPECTED = 2 | ||||
blocks_checked = 0 | blocks_checked = 0 | ||||
expected_blocks = [] | expected_blocks = [] | ||||
self.log.info("hook into the validation:block_connected tracepoint") | self.log.info("hook into the validation:block_connected tracepoint") | ||||
ctx = USDT(pid=self.nodes[0].process.pid) | ctx = USDT(pid=self.nodes[0].process.pid) | ||||
ctx.enable_probe(probe="validation:block_connected", | ctx.enable_probe( | ||||
fn_name="trace_block_connected") | probe="validation:block_connected", fn_name="trace_block_connected" | ||||
bpf = BPF(text=validation_blockconnected_program, | ) | ||||
usdt_contexts=[ctx], debug=0) | bpf = BPF(text=validation_blockconnected_program, usdt_contexts=[ctx], debug=0) | ||||
def handle_blockconnected(_, data, __): | def handle_blockconnected(_, data, __): | ||||
nonlocal expected_blocks, blocks_checked | nonlocal expected_blocks, blocks_checked | ||||
event = ctypes.cast(data, ctypes.POINTER(Block)).contents | event = ctypes.cast(data, ctypes.POINTER(Block)).contents | ||||
self.log.info(f"handle_blockconnected(): {event}") | self.log.info(f"handle_blockconnected(): {event}") | ||||
block = expected_blocks.pop(0) | block = expected_blocks.pop(0) | ||||
assert_equal(block["hash"], bytes(event.hash[::-1]).hex()) | assert_equal(block["hash"], bytes(event.hash[::-1]).hex()) | ||||
assert_equal(block["height"], event.height) | assert_equal(block["height"], event.height) | ||||
assert_equal(len(block["tx"]), event.transactions) | assert_equal(len(block["tx"]), event.transactions) | ||||
assert_equal(len([tx["vin"] for tx in block["tx"]]), event.inputs) | assert_equal(len([tx["vin"] for tx in block["tx"]]), event.inputs) | ||||
# no sigchk in coinbase tx | # no sigchk in coinbase tx | ||||
assert_equal(0, event.sigchk) | assert_equal(0, event.sigchk) | ||||
# only plausibility checks | # only plausibility checks | ||||
assert event.duration > 0 | assert event.duration > 0 | ||||
blocks_checked += 1 | blocks_checked += 1 | ||||
bpf["block_connected"].open_perf_buffer( | bpf["block_connected"].open_perf_buffer(handle_blockconnected) | ||||
handle_blockconnected) | |||||
self.log.info(f"mine {BLOCKS_EXPECTED} blocks") | self.log.info(f"mine {BLOCKS_EXPECTED} blocks") | ||||
block_hashes = self.generatetoaddress( | block_hashes = self.generatetoaddress( | ||||
self.nodes[0], BLOCKS_EXPECTED, ADDRESS_ECREG_UNSPENDABLE) | self.nodes[0], BLOCKS_EXPECTED, ADDRESS_ECREG_UNSPENDABLE | ||||
) | |||||
for block_hash in block_hashes: | for block_hash in block_hashes: | ||||
expected_blocks.append(self.nodes[0].getblock(block_hash, 2)) | expected_blocks.append(self.nodes[0].getblock(block_hash, 2)) | ||||
bpf.perf_buffer_poll(timeout=200) | bpf.perf_buffer_poll(timeout=200) | ||||
bpf.cleanup() | bpf.cleanup() | ||||
self.log.info(f"check that we traced {BLOCKS_EXPECTED} blocks") | self.log.info(f"check that we traced {BLOCKS_EXPECTED} blocks") | ||||
assert_equal(BLOCKS_EXPECTED, blocks_checked) | assert_equal(BLOCKS_EXPECTED, blocks_checked) | ||||
assert_equal(0, len(expected_blocks)) | assert_equal(0, len(expected_blocks)) | ||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
ValidationTracepointTest().main() | ValidationTracepointTest().main() |