Skip to content

Commit c934087

Browse files
committed
test: checks for tracepoint tests
For testing the USDT tracepoint API in the functional tests we require: - that we are on a Linux system* - that Bitcoin Core is compiled with tracepoints - that bcc and the the Python bcc module [0] is installed - that we run the tests with the required permissions** otherwise we skip the tests. *: We currently only support tracepoints on Linux. Tracepoints are not compiled on other platforms. **: Currently, we check for root permissions via getuid == 0. It's unclear if it's even possible to run the tests a non-root user with e.g. CAP_BPF, CAP_PERFMON, and access to /sys/kernel/debug/ tracing/. Anyone running these tests as root should carefully review them first and then run them in a disposable VM. [0]: https://github.com/iovisor/bcc/blob/master/INSTALL.md
1 parent 5f44c5c commit c934087

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ if test "$use_usdt" != "no"; then
13631363
[AC_MSG_RESULT([no]); use_usdt=no;]
13641364
)
13651365
fi
1366+
AM_CONDITIONAL([ENABLE_USDT_TRACEPOINTS], [test "$use_usdt" = "yes"])
13661367

13671368
if test "$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_util$build_bitcoind$bitcoin_enable_qt$use_bench$use_tests" = "nonononononono"; then
13681369
use_upnp=no

test/config.ini.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
2525
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true
2626
@ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true
2727
@ENABLE_SYSCALL_SANDBOX_TRUE@ENABLE_SYSCALL_SANDBOX=true
28+
@ENABLE_USDT_TRACEPOINTS_TRUE@ENABLE_USDT_TRACEPOINTS=true

test/functional/test_framework/test_framework.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import logging
1111
import os
12+
import platform
1213
import pdb
1314
import random
1415
import re
@@ -821,6 +822,29 @@ def skip_if_no_py3_zmq(self):
821822
except ImportError:
822823
raise SkipTest("python3-zmq module not available.")
823824

825+
def skip_if_no_python_bcc(self):
826+
"""Attempt to import the bcc package and skip the tests if the import fails."""
827+
try:
828+
import bcc # type: ignore[import] # noqa: F401
829+
except ImportError:
830+
raise SkipTest("bcc python module not available")
831+
832+
def skip_if_no_bitcoind_tracepoints(self):
833+
"""Skip the running test if bitcoind has not been compiled with USDT tracepoint support."""
834+
if not self.is_usdt_compiled():
835+
raise SkipTest("bitcoind has not been built with USDT tracepoints enabled.")
836+
837+
def skip_if_no_bpf_permissions(self):
838+
"""Skip the running test if we don't have permissions to do BPF syscalls and load BPF maps."""
839+
# check for 'root' permissions
840+
if os.geteuid() != 0:
841+
raise SkipTest("no permissions to use BPF (please review the tests carefully before running them with higher privileges)")
842+
843+
def skip_if_platform_not_linux(self):
844+
"""Skip the running test if we are not on a Linux platform"""
845+
if platform.system() != "Linux":
846+
raise SkipTest("not on a Linux system")
847+
824848
def skip_if_no_bitcoind_zmq(self):
825849
"""Skip the running test if bitcoind has not been compiled with zmq support."""
826850
if not self.is_zmq_compiled():
@@ -902,6 +926,10 @@ def is_zmq_compiled(self):
902926
"""Checks whether the zmq module was compiled."""
903927
return self.config["components"].getboolean("ENABLE_ZMQ")
904928

929+
def is_usdt_compiled(self):
930+
"""Checks whether the USDT tracepoints were compiled."""
931+
return self.config["components"].getboolean("ENABLE_USDT_TRACEPOINTS")
932+
905933
def is_sqlite_compiled(self):
906934
"""Checks whether the wallet module was compiled with Sqlite support."""
907935
return self.config["components"].getboolean("USE_SQLITE")

0 commit comments

Comments
 (0)