aboutsummaryrefslogtreecommitdiff
path: root/test/functional/interface_usdt_utxocache.py
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-09-10 14:06:17 +0100
committerfanquake <fanquake@gmail.com>2023-09-10 14:10:16 +0100
commitc5a63ea56f8347139bd84e1669b378ecfb234c3c (patch)
treebcff7efe1e14c318f23b7575ce150c538ed012e9 /test/functional/interface_usdt_utxocache.py
parente25af11225d9d94ecf7068bf7a9a359268786fbe (diff)
parent9f55773a370a0d039e727445ccee6b84e05f562a (diff)
Merge bitcoin/bitcoin#27944: test: various USDT functional test cleanups (27831 follow-ups)
9f55773a370a0d039e727445ccee6b84e05f562a test: refactor: usdt_mempool: store all events (stickies-v) bc432704505eb165dd86de39ea3434c6fb7a2514 test: refactor: remove unnecessary nonlocal (stickies-v) 326db63a6819813db55ba0d01ab4fe80f7a0d818 test: log sanity check assertion failures (stickies-v) f5525ad6808df6afc38e5c6e4767ab577e30629c test: store utxocache events (stickies-v) f1b99ac94fb77340c4d3a5b4bbc3df28009bc773 test: refactor: deduplicate handle_utxocache_* logic (stickies-v) ad90ba36bd930f00753643cd1fe0af72d1c828c2 test: refactor: rename inbound to is_inbound (stickies-v) afc0224cdbe73e326addf5fb98a3e95d941f2104 test: refactor: remove unnecessary blocks_checked counter (stickies-v) Pull request description: Various cleanups to the USDT functional tests, largely (but not exclusively) follow-ups to https://github.com/bitcoin/bitcoin/pull/27831#pullrequestreview-1491438045. Except for slightly different logging behaviour in "test: store utxocache events" and "test: log sanity check assertion failures", this is a refactor PR, removing unnecessary code and (imo) making it more readable and maintainable. The rationale for each change is in the corresponding commit message. Note: except for "test: store utxocache events" (which relies on its parent, and I separated into two commits because we may want the parent but not the child), all commits are stand-alone and I'm okay with dropping one/multiple commits if they turn out to be controversial or undesired. ACKs for top commit: 0xB10C: ACK 9f55773a370a0d039e727445ccee6b84e05f562a. Reviewed the code and ran the USDT interface tests. I stepped through the commits and think all changes are reasonable. Tree-SHA512: 6c37a0265b6c26d4f9552a056a690b8f86f7304bd33b4419febd8b17369cf6af799cb87c16df35d0c2a1b839ad31de24661d4384eafa88816c2051c522fd3bf5
Diffstat (limited to 'test/functional/interface_usdt_utxocache.py')
-rwxr-xr-xtest/functional/interface_usdt_utxocache.py68
1 files changed, 29 insertions, 39 deletions
diff --git a/test/functional/interface_usdt_utxocache.py b/test/functional/interface_usdt_utxocache.py
index 5f2ba49026..2fc5981451 100755
--- a/test/functional/interface_usdt_utxocache.py
+++ b/test/functional/interface_usdt_utxocache.py
@@ -252,43 +252,30 @@ class UTXOCacheTracepointTest(BitcoinTestFramework):
# that the handle_* functions succeeded.
EXPECTED_HANDLE_ADD_SUCCESS = 2
EXPECTED_HANDLE_SPENT_SUCCESS = 1
- handle_add_succeeds = 0
- handle_spent_succeeds = 0
- expected_utxocache_spents = []
expected_utxocache_adds = []
+ expected_utxocache_spents = []
+
+ actual_utxocache_adds = []
+ actual_utxocache_spents = []
+
+ def compare_utxo_with_event(utxo, event):
+ """Compare a utxo dict to the event produced by BPF"""
+ assert_equal(utxo["txid"], bytes(event.txid[::-1]).hex())
+ assert_equal(utxo["index"], event.index)
+ assert_equal(utxo["height"], event.height)
+ assert_equal(utxo["value"], event.value)
+ assert_equal(utxo["is_coinbase"], event.is_coinbase)
def handle_utxocache_add(_, data, __):
- nonlocal handle_add_succeeds
event = ctypes.cast(data, ctypes.POINTER(UTXOCacheChange)).contents
self.log.info(f"handle_utxocache_add(): {event}")
- add = expected_utxocache_adds.pop(0)
- try:
- assert_equal(add["txid"], bytes(event.txid[::-1]).hex())
- assert_equal(add["index"], event.index)
- assert_equal(add["height"], event.height)
- assert_equal(add["value"], event.value)
- assert_equal(add["is_coinbase"], event.is_coinbase)
- except AssertionError:
- self.log.exception("Assertion failed")
- else:
- handle_add_succeeds += 1
+ actual_utxocache_adds.append(event)
def handle_utxocache_spent(_, data, __):
- nonlocal handle_spent_succeeds
event = ctypes.cast(data, ctypes.POINTER(UTXOCacheChange)).contents
self.log.info(f"handle_utxocache_spent(): {event}")
- spent = expected_utxocache_spents.pop(0)
- try:
- assert_equal(spent["txid"], bytes(event.txid[::-1]).hex())
- assert_equal(spent["index"], event.index)
- assert_equal(spent["height"], event.height)
- assert_equal(spent["value"], event.value)
- assert_equal(spent["is_coinbase"], event.is_coinbase)
- except AssertionError:
- self.log.exception("Assertion failed")
- else:
- handle_spent_succeeds += 1
+ actual_utxocache_spents.append(event)
bpf["utxocache_add"].open_perf_buffer(handle_utxocache_add)
bpf["utxocache_spent"].open_perf_buffer(handle_utxocache_spent)
@@ -324,19 +311,18 @@ class UTXOCacheTracepointTest(BitcoinTestFramework):
"is_coinbase": block_index == 0,
})
- assert_equal(EXPECTED_HANDLE_ADD_SUCCESS, len(expected_utxocache_adds))
- assert_equal(EXPECTED_HANDLE_SPENT_SUCCESS,
- len(expected_utxocache_spents))
-
bpf.perf_buffer_poll(timeout=200)
- bpf.cleanup()
+
+ assert_equal(EXPECTED_HANDLE_ADD_SUCCESS, len(expected_utxocache_adds), len(actual_utxocache_adds))
+ assert_equal(EXPECTED_HANDLE_SPENT_SUCCESS, len(expected_utxocache_spents), len(actual_utxocache_spents))
self.log.info(
f"check that we successfully traced {EXPECTED_HANDLE_ADD_SUCCESS} adds and {EXPECTED_HANDLE_SPENT_SUCCESS} spent")
- assert_equal(0, len(expected_utxocache_adds))
- assert_equal(0, len(expected_utxocache_spents))
- assert_equal(EXPECTED_HANDLE_ADD_SUCCESS, handle_add_succeeds)
- assert_equal(EXPECTED_HANDLE_SPENT_SUCCESS, handle_spent_succeeds)
+ for expected_utxo, actual_event in zip(expected_utxocache_adds + expected_utxocache_spents,
+ actual_utxocache_adds + actual_utxocache_spents):
+ compare_utxo_with_event(expected_utxo, actual_event)
+
+ bpf.cleanup()
def test_flush(self):
""" Tests the utxocache:flush tracepoint API.
@@ -367,9 +353,13 @@ class UTXOCacheTracepointTest(BitcoinTestFramework):
"size": event.size
})
# sanity checks only
- assert event.memory > 0
- assert event.duration > 0
- handle_flush_succeeds += 1
+ try:
+ assert event.memory > 0
+ assert event.duration > 0
+ except AssertionError:
+ self.log.exception("Assertion error")
+ else:
+ handle_flush_succeeds += 1
bpf["utxocache_flush"].open_perf_buffer(handle_utxocache_flush)