From fa0c1baaf89805182de56d6a2e8eed2265a94b40 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 24 Apr 2025 10:21:40 +0200 Subject: [PATCH 1/2] test: Add imports for util bpf_cflags This is required for the next commit. --- test/functional/interface_usdt_coinselection.py | 3 ++- test/functional/interface_usdt_mempool.py | 7 +++++-- test/functional/interface_usdt_net.py | 8 ++++++-- test/functional/interface_usdt_utxocache.py | 7 +++++-- test/functional/interface_usdt_validation.py | 8 +++++--- test/functional/test_framework/util.py | 7 +++++++ 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/test/functional/interface_usdt_coinselection.py b/test/functional/interface_usdt_coinselection.py index 1f4d6d6fbf1..52cee9372a9 100755 --- a/test/functional/interface_usdt_coinselection.py +++ b/test/functional/interface_usdt_coinselection.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2022 The Bitcoin Core developers +# Copyright (c) 2022-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -17,6 +17,7 @@ from test_framework.util import ( assert_equal, assert_greater_than, assert_raises_rpc_error, + bpf_cflags, ) coinselection_tracepoints_program = """ diff --git a/test/functional/interface_usdt_mempool.py b/test/functional/interface_usdt_mempool.py index 75359541722..a5a0ee448e9 100755 --- a/test/functional/interface_usdt_mempool.py +++ b/test/functional/interface_usdt_mempool.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2022 The Bitcoin Core developers +# Copyright (c) 2022-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -20,7 +20,10 @@ from test_framework.blocktools import COINBASE_MATURITY from test_framework.messages import COIN, DEFAULT_MEMPOOL_EXPIRY_HOURS from test_framework.p2p import P2PDataStore from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.util import ( + assert_equal, + bpf_cflags, +) from test_framework.wallet import MiniWallet MEMPOOL_TRACEPOINTS_PROGRAM = """ diff --git a/test/functional/interface_usdt_net.py b/test/functional/interface_usdt_net.py index 94baacf3dd9..b7b9d6bcfc5 100755 --- a/test/functional/interface_usdt_net.py +++ b/test/functional/interface_usdt_net.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2022 The Bitcoin Core developers +# Copyright (c) 2022-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -17,7 +17,11 @@ 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, assert_greater_than +from test_framework.util import ( + assert_equal, + assert_greater_than, + bpf_cflags, +) # Tor v3 addresses are 62 chars + 6 chars for the port (':12345'). MAX_PEER_ADDR_LENGTH = 68 diff --git a/test/functional/interface_usdt_utxocache.py b/test/functional/interface_usdt_utxocache.py index 9e0d2a6072b..b28db0e3f3d 100755 --- a/test/functional/interface_usdt_utxocache.py +++ b/test/functional/interface_usdt_utxocache.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2022 The Bitcoin Core developers +# Copyright (c) 2022-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -15,7 +15,10 @@ except ImportError: pass from test_framework.messages import COIN from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.util import ( + assert_equal, + bpf_cflags, +) from test_framework.wallet import MiniWallet utxocache_changes_program = """ diff --git a/test/functional/interface_usdt_validation.py b/test/functional/interface_usdt_validation.py index 9b2e708d955..0a27e5eaefb 100755 --- a/test/functional/interface_usdt_validation.py +++ b/test/functional/interface_usdt_validation.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2022 The Bitcoin Core developers +# Copyright (c) 2022-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -18,8 +18,10 @@ except ImportError: from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal - +from test_framework.util import ( + assert_equal, + bpf_cflags, +) validation_blockconnected_program = """ #include diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 903dd1b2b5b..f7acc290a5b 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -321,6 +321,13 @@ def wait_until_helper_internal(predicate, *, timeout=60, lock=None, timeout_fact raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout)) +def bpf_cflags(): + return [ + "-Wno-error=implicit-function-declaration", + "-Wno-duplicate-decl-specifier", # https://github.com/bitcoin/bitcoin/issues/32322 + ] + + def sha256sum_file(filename): h = hashlib.sha256() with open(filename, 'rb') as f: From facb9b327b9da39ce1e09ed56199be9efb19b5b8 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 24 Apr 2025 10:26:11 +0200 Subject: [PATCH 2/2] scripted-diff: Use bpf_cflags -BEGIN VERIFY SCRIPT- ren() { sed --regexp-extended -i "s/$1/$2/g" $( git grep --extended-regexp -l "$1" ) ; } ren 'cflags=\["-Wno-error=implicit-function-declaration"\]' 'cflags=bpf_cflags()' -END VERIFY SCRIPT- --- test/functional/interface_usdt_coinselection.py | 2 +- test/functional/interface_usdt_mempool.py | 8 ++++---- test/functional/interface_usdt_net.py | 12 ++++++------ test/functional/interface_usdt_utxocache.py | 8 ++++---- test/functional/interface_usdt_validation.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/functional/interface_usdt_coinselection.py b/test/functional/interface_usdt_coinselection.py index 52cee9372a9..93acffd8318 100755 --- a/test/functional/interface_usdt_coinselection.py +++ b/test/functional/interface_usdt_coinselection.py @@ -176,7 +176,7 @@ class CoinSelectionTracepointTest(BitcoinTestFramework): ctx.enable_probe(probe="coin_selection:normal_create_tx_internal", fn_name="trace_normal_create_tx") ctx.enable_probe(probe="coin_selection:attempting_aps_create_tx", fn_name="trace_attempt_aps") ctx.enable_probe(probe="coin_selection:aps_create_tx_internal", fn_name="trace_aps_create_tx") - self.bpf = BPF(text=coinselection_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + self.bpf = BPF(text=coinselection_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) self.log.info("Prepare wallets") self.generate(self.nodes[0], 101) diff --git a/test/functional/interface_usdt_mempool.py b/test/functional/interface_usdt_mempool.py index a5a0ee448e9..c356d0f010c 100755 --- a/test/functional/interface_usdt_mempool.py +++ b/test/functional/interface_usdt_mempool.py @@ -169,7 +169,7 @@ class MempoolTracepointTest(BitcoinTestFramework): node = self.nodes[0] ctx = USDT(pid=node.process.pid) ctx.enable_probe(probe="mempool:added", fn_name="trace_added") - bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) def handle_added_event(_, data, __): events.append(bpf["added_events"].event(data)) @@ -206,7 +206,7 @@ class MempoolTracepointTest(BitcoinTestFramework): node = self.nodes[0] ctx = USDT(pid=node.process.pid) ctx.enable_probe(probe="mempool:removed", fn_name="trace_removed") - bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) def handle_removed_event(_, data, __): events.append(bpf["removed_events"].event(data)) @@ -252,7 +252,7 @@ class MempoolTracepointTest(BitcoinTestFramework): node = self.nodes[0] ctx = USDT(pid=node.process.pid) ctx.enable_probe(probe="mempool:replaced", fn_name="trace_replaced") - bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) def handle_replaced_event(_, data, __): event = ctypes.cast(data, ctypes.POINTER(MempoolReplaced)).contents @@ -305,7 +305,7 @@ class MempoolTracepointTest(BitcoinTestFramework): self.log.info("Hooking into mempool:rejected tracepoint...") ctx = USDT(pid=node.process.pid) ctx.enable_probe(probe="mempool:rejected", fn_name="trace_rejected") - bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) def handle_rejected_event(_, data, __): events.append(bpf["rejected_events"].event(data)) diff --git a/test/functional/interface_usdt_net.py b/test/functional/interface_usdt_net.py index b7b9d6bcfc5..d9d7ee12e09 100755 --- a/test/functional/interface_usdt_net.py +++ b/test/functional/interface_usdt_net.py @@ -287,7 +287,7 @@ class NetTracepointTest(BitcoinTestFramework): fn_name="trace_inbound_message") ctx.enable_probe(probe="net:outbound_message", fn_name="trace_outbound_message") - bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) EXPECTED_INOUTBOUND_VERSION_MSG = 1 checked_inbound_version_msg = 0 @@ -345,7 +345,7 @@ class NetTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="net:inbound_connection", fn_name="trace_inbound_connection") - bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) inbound_connections = [] EXPECTED_INBOUND_CONNECTIONS = 2 @@ -382,7 +382,7 @@ class NetTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="net:outbound_connection", fn_name="trace_outbound_connection") - bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) # that the handle_* function succeeds. EXPECTED_OUTBOUND_CONNECTIONS = 2 @@ -423,7 +423,7 @@ class NetTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="net:evicted_inbound_connection", fn_name="trace_evicted_inbound_connection") - bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) EXPECTED_EVICTED_CONNECTIONS = 2 evicted_connections = [] @@ -460,7 +460,7 @@ class NetTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="net:misbehaving_connection", fn_name="trace_misbehaving_connection") - bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) EXPECTED_MISBEHAVING_CONNECTIONS = 2 misbehaving_connections = [] @@ -494,7 +494,7 @@ class NetTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="net:closed_connection", fn_name="trace_closed_connection") - bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=net_tracepoints_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) EXPECTED_CLOSED_CONNECTIONS = 2 closed_connections = [] diff --git a/test/functional/interface_usdt_utxocache.py b/test/functional/interface_usdt_utxocache.py index b28db0e3f3d..b30d0e88ac7 100755 --- a/test/functional/interface_usdt_utxocache.py +++ b/test/functional/interface_usdt_utxocache.py @@ -184,7 +184,7 @@ class UTXOCacheTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="utxocache:uncache", fn_name="trace_utxocache_uncache") - bpf = BPF(text=utxocache_changes_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=utxocache_changes_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) # The handle_* function is a ctypes callback function called from C. When # we assert in the handle_* function, the AssertError doesn't propagate @@ -253,7 +253,7 @@ class UTXOCacheTracepointTest(BitcoinTestFramework): ctx.enable_probe(probe="utxocache:add", fn_name="trace_utxocache_add") ctx.enable_probe(probe="utxocache:spent", fn_name="trace_utxocache_spent") - bpf = BPF(text=utxocache_changes_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=utxocache_changes_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) # The handle_* function is a ctypes callback function called from C. When # we assert in the handle_* function, the AssertError doesn't propagate @@ -353,7 +353,7 @@ class UTXOCacheTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="utxocache:flush", fn_name="trace_utxocache_flush") - bpf = BPF(text=utxocache_flushes_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=utxocache_flushes_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) # The handle_* function is a ctypes callback function called from C. When # we assert in the handle_* function, the AssertError doesn't propagate @@ -410,7 +410,7 @@ class UTXOCacheTracepointTest(BitcoinTestFramework): ctx = USDT(pid=self.nodes[0].process.pid) ctx.enable_probe(probe="utxocache:flush", fn_name="trace_utxocache_flush") - bpf = BPF(text=utxocache_flushes_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + bpf = BPF(text=utxocache_flushes_program, usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) bpf["utxocache_flush"].open_perf_buffer(handle_utxocache_flush) self.log.info("prune blockchain to trigger a flush for pruning") diff --git a/test/functional/interface_usdt_validation.py b/test/functional/interface_usdt_validation.py index 0a27e5eaefb..f7d518d8930 100755 --- a/test/functional/interface_usdt_validation.py +++ b/test/functional/interface_usdt_validation.py @@ -99,7 +99,7 @@ class ValidationTracepointTest(BitcoinTestFramework): ctx.enable_probe(probe="validation:block_connected", fn_name="trace_block_connected") bpf = BPF(text=validation_blockconnected_program, - usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"]) + usdt_contexts=[ctx], debug=0, cflags=bpf_cflags()) def handle_blockconnected(_, data, __): event = ctypes.cast(data, ctypes.POINTER(Block)).contents