-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: USDT tracepoint interface tests #24358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Nice! Concept ACK. |
I tested it on my machine:
Tested with bpftrace
|
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
This adds tests for the net:inbound_message and net:outbound_message tracepoint interface.
This adds tests for the - utxocache:flush - utxocache:uncache - utxocache:add - utxocache:spent tracepoint interfaces.
This adds a test for the validation:block_connected tracepoint.
db3a05f
to
76c60d7
Compare
#23907 is merged. Rebased and ready for review. |
Concept ACK |
Tests pass on my end, but oddly enough when I run
|
@jb55 which version of This is kinda off topic here, but there have been quite a few problems with |
tACK 76c60d7 |
I managed to get the required privileges as a user, and get the tests to run (don't forget to patch
It's apparently also possible to assign fixed capabilities to users through BTW:
|
Tested ACK 76c60d7 Will open a PR to fix the RPC assertion in |
When `getrawtransaction` is successfully used on a coinbase transaction, there is an assertion error. This is very unlikely but happens in the test in bitcoin#24358. This does the following: - Add missing "coinbase" documentation. - Synchronize documentation between `getrawtransaction` and `decoderawtransaction`, the two users of `TxToUniv` that have detailed documentation. `decodepsbt` also uses it but fortunately elides this block. - Change "vout[].amount" to `STR_AMOUNT` for consistency. - Add maintainer comment to keep the two places synchronized. It might be possible to get smarter with deduplication, but there are some extra fields that prevent the obvious way.
"""Skip the running test if we don't have permissions to do BPF syscalls and load BPF maps.""" | ||
# check for 'root' permissions | ||
if os.geteuid() != 0: | ||
raise SkipTest("no permissions to use BPF (please review the tests carefully before running them with higher privileges)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As alternative to / in addition to os.geteuid() != 0
for non-root use we'll probably want to check CapEff
in /proc/<pid>/status
for (1 << CAP_PERFMON) | (1 << CAP_BPF)
.
CAP_PERFMON = 38
CAP_BPF = 39
Not necessarily in this PR though. I think it's fine to merge as-is and do that later.
Concept ACK. Nice functional demonstration of USDT usage, too. I'll test this soon. |
…saction` 71038a1 rpc: Fix documentation assertion for `getrawtransaction` (laanwj) Pull request description: When `getrawtransaction` is successfully used on a coinbase transaction, there is an assertion error. This is very unlikely but happens in the `interface_usdt_utxocache.py` test in bitcoin#24358. This does the following: - Add missing "coinbase" documentation. - Synchronize documentation between `getrawtransaction` and `decoderawtransaction`, the two users of `TxToUniv` that have detailed documentation. `decodepsbt` and `getblock` also uses it but fortunately elides this block. - Change "vout[].amount" to `STR_AMOUNT` for consistency. - Add maintainer comment to keep the two places synchronized. It might be possible to get smarter with deduplication, but there are some extra fields that prevent the obvious way. ACKs for top commit: jonatack: ACK 71038a1 Tree-SHA512: 962236130455d805190ff9a5c971e4e25c17db35614a90ce340264ec953b0ad7fb814eb33ae430b5073955a8a350f72bdd67ba93e35f9c70e5175b836a767a35
@jamesob I'm going ahead and merge this as I think it's ready. I hope you'll still get around to testing it though. |
When `getrawtransaction` is successfully used on a coinbase transaction, there is an assertion error. This is very unlikely but happens in the test in bitcoin#24358. This does the following: - Add missing "coinbase" documentation. - Synchronize documentation between `getrawtransaction` and `decoderawtransaction`, the two users of `TxToUniv` that have detailed documentation. `decodepsbt` also uses it but fortunately elides this block. - Change "vout[].amount" to `STR_AMOUNT` for consistency. - Add maintainer comment to keep the two places synchronized. It might be possible to get smarter with deduplication, but there are some extra fields that prevent the obvious way. Github-Pull: bitcoin#24716 Rebased-From: 71038a1
cc7335e ci: run USDT interface test in a VM (0xb10c) dba6f82 test: adopt USDT utxocache interface tests (0xb10c) 220a5a2 test: hook into PID in tracing tests (0xb10c) Pull request description: Changes a CI task that runs test the previously not run `test/functional/interface_usdt_*.py` functional tests (added in bitcoin/bitcoin#24358). This task is run as CirussCI `compute_engine_instance` VM as hooking into the tracepoints is not possible in CirrusCI docker containers (bitcoin/bitcoin#23296 (comment)). We use an unoffical PPA and untrusted `bpfcc-tools` package in the CI as the Ubuntu jammy and Debian bullseye packages are outdated. We hope use an official package when new Ubuntu/Debian releases are available for the use with Google Compute Engine. We make sure to hook into `bitcoind` binaries in USDT interface tests via their PID, instead of their path. This makes sure multiple functional tests running in parallel don't interfere with each other. The utxocache USDT interface tests is adopted to a change of the functional test framework that wasn't detected as the tests weren't run in the CI. As the tracepoints expose internals, it can happen that we need to adopt the interface test when internals change. This is a bit awkward, and if it happens to frequently, we should consider generalizing the tests a bit more. For now it's fine, I think. See the individual commit messages for more details on the changes. Fixes bitcoin/bitcoin#24782 Fixes bitcoin/bitcoin#23296 I'd like to hear from reviewers: - Are we OK with using the [`hadret/bpfcc`](https://launchpad.net/~hadret/+archive/ubuntu/bpfcc) PPA for now? There is a clear plan when to drop it and as is currently, it could only impact the newly added VM task. - ~~Adding a new task increases CI runtime and costs. Should an existing `container` CI task be ported to a VM and reused instead?~~ Yes, see bitcoin/bitcoin#25528 (comment) ACKs for top commit: MarcoFalke: cr ACK cc7335e Tree-SHA512: b7fddccc0a77d82371229d048abe0bf2c4ccaa45906497ef3040cf99e7f05561890aef4c253c40e4afc96bb838c9787fae81c8454c6fd9db583276e005a4ccb3
Summary: ``` This adds functional tests for the USDT tracepoints added in #22006 and #22902. This partially fixes #23296. The tests are probably skipped on most systems as these tests require: a Linux system with a kernel that supports BPF (and available kernel headers) that Bitcoin Core is compiled with tracepoints for USDT support (default when compiled with depends) bcc installed the tests are run with a privileged user that is able to e.g. do BPF syscalls and load BPF maps ``` Backport of [[bitcoin/bitcoin#24358 | core#24358]] and [[bitcoin/bitcoin#25528 | core#25528]] for the test fixes. Depends on D12737. Note that: - We don't run it on CI (yet) - We need to prune more blocks to trigger the expected flush event as our block files are smaller - The 3 tests succeed on my machine, but the runner returns an error because I got compilation warnings that print to stderr Test Plan: With tracing enabled: sudo ./test/functional/test_runner.py interface_usdt_net sudo ./test/functional/test_runner.py interface_usdt_utxocache sudo ./test/functional/test_runner.py interface_usdt_validation ninja check-functional Check the tests are skipped as expected when not run as root. Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Subscribers: PiRK Differential Revision: https://reviews.bitcoinabc.org/D12739
This adds functional tests for the USDT tracepoints added in #22006 and #22902. This partially fixes #23296. The tests are probably skipped on most systems as these tests require:
The tests are not yet run in our CI as the CirrusCI containers lack the required permissions (see #23296 (comment)). Running the tests in a VM in the CI could work, but I haven't experimented with this yet. The priority was to get the actual tests done first to ensure the tracepoints work as intended for the v23.0 release. Running the tracepoint tests in the CI is planned as the next step to finish #23296.
The tests can, however, be run against e.g. release candidates by hand. Additionally, they provide a starting point for tests for future tracepoints. PRs adding new tracepoint should include tests. This makes reviewing these PRs easier.
The tests require privileges to execute BPF sycalls (
CAP_SYS_ADMIN
before Linux kernel 5.8 andCAP_BPF
andCAP_PERFMON
on 5.8+) and permissions to/sys/kernel/debug/tracing/
. It's currently recommended to run the tests in a virtual machine (or on a VPS) where it's sensible to use theroot
user to gain these privileges. Never run python scripts you haven't carefully reviewed withroot
permissions! It's unclear if a non-root user can even gain the required privileges. This needs more experimenting.The goal here is to test the tracepoint interface to make sure the documented interface does not break by accident. The tracepoints expose implementation details. This means we also need to rely on implementation details of Bitcoin Core in these functional tests to trigger the tracepoints. An example is the test of the
utxocache:flush
tracepoint: On Bitcoin Core shutdown, the UTXO cache is flushed twice. The corresponding tracepoint test expects two flushes, too - if not, the test fails. Changing implementation details could cause these tests to fail and the tracepoint API to break. However, we purposefully treat the tracepoints only as semi-stable. The tracepoints should not block refactors or changes to other internals.