mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:35:38 +00:00
test: Add debug output to common tested types #36091
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36091
Loading…
Reference in a new issue
No description provided.
Delete branch "26-8-25-display"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
If the
<<operator exists, boost can use this as a debug output when a check fails (besidesBOOST_CHECK). This adds<<for types commonly used across the unit tests that do not yet have a display output. Each callsite that uses these types are then updated to use macros that will print the debug output on failure. All of these display strings would be used as part of #35713, but we can also use them with boost today.What this PR does:
BOOST_CHECKcalls. This covers the majority of custom types that did not yet have a debug string.What this PR does not do:
BOOST_CHECKcallsites for types that already do have a debug output (all primitive type comparisons,CFeeRate, etc). This would be a much larger refactor and could perhaps be done after.std::vector<T>whereTis streamable. These can be migrated toBOOST_CHECK_EQUAL_COLLECTIONS, but is a similar refactor to the one above.std::vector<unsigned char>and related. Also a large refactor, and could use discussion.friendmethod in the source code (ByRatio)The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept ACK
Concept ACK
🚧 At least one of the CI tasks failed.
Task
Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32965723886/job/98167644980LLM reason (✨ experimental): CI failed because the fuzz test target
rpccrashed (exit code3221225477, Windows access violation).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Concept ACK
Left three comments.
feefrac_testsandtxgraph_testsonly need theFeeFracprinters, but this block drags addrman, key_io and protocol in with it. Touching addrman now rebuilds both, and it's about 12k extra preprocessed lines in the first one. Would it be worth splitting this by area?This one leaves out
nTimeandnServices, whichoperator==does compare, so in the two addrv1/addrv2 unserialize checks a regression in time or in flags comes out as[::1]:0 != [::1]:0. TheCTxDestinationone printsCTxDestination()forCNoDestinationandPubKeyDestination. Worth checking each printer against the type'soperator==?Encode()asserts on an empty key, which is whatDecodeExtKeyleaves you with when it fails, and that's the valuebip32_testscompares. I broke the decode to see. The case dies on SIGABRT and takes the following ones with it. On master the same break just prints 17 failures and the suite finishes. Worth a guard here and in theCExtPubKeyone?If I understood this correctly I added a length guard for each of these. Lmk if that was what you were suggesting.
Added additional info for
CAddressand took a glance through the rest of the==, I think all fields should be covered. As far asCTxDestination, I added specific displays for each variant and theCTxDestinationprinter now just passes through to those.In the current state of #35713 I have it like this; however, I'm a little hesitant to make this change because having each test translation unit define the
<<would bloat the tests with additional code that doesn't pertain to the logic of the test. With everything defined in a single file, developers know where to make changes to the debug string, but otherwise it is out of the way. I can adjust if other reviewers agree with this suggestion.While checking the changes I noticed a small nit.
CService's==comparesm_net, which the printer doesn't show, so IPv6 and CJDNS with the same bytes come out identical.MaybeFlipIPv6toCJDNSinadvertise_local_addressbuilds the pair. No check reaches that today.Yes, that's what I meant. I broke the decode again and now it prints
CExtKey(<invalid>)and the suite finishes, no SIGABRT. Small thing, theCExtPubKeyinvalid branch saysCPubExtKey.Fixed thanks
Added a
netfield toCServiceMost of the functions can be just the signature and a fwd decl for the type, and the actual stringify can move to a cpp file?
This saves re-compilation at least in the other cases (
AddressPosition, etc)Also, if this is the new display module, the other stuff should move here from
./src/test/util/common.hlater?This could just as well go into
common, I was just trying to avoid bloat in that file bc I wasn't sure if debug outputs are "common", but I suppose they are.Sure, we can go this route. I don't have a strong preference.
Moved the definitions to
display.cpp. Can figure out thecommon.hsituation later IMO.No need for separate template instantiations for each derived type:
And then you can also move the implementation to the source file forward declare
FeeFracin the header.I de-templated
ByRatioNegSizeas well because the only intended and current use case is withFeeFrac. Updated in latest push.Why is this pair thing needed? Seems to be a single test-only thing? So either this should be moved to that test, or maybe pair should be handled generally, like the existing optional:
Either would allow dropping the includes for this.
There is a callsite that uses both
BOOST_CHECKandstd::pairon types that do not implement<<. #35713 works around this because both types make sense as hex representations, but I couldn't compile after rebasing on this branch becauseoperator<<resolved first. I added arequires requires(std::ostream& os, const T& t, const U& u) { os << t; os << u; }, which I think it correct. Otherwise yeah this should be general, updated in latest push.Ah interesting. I wonder if the hex fallback should be added here (even if unused). The benefit would be that the stringify logic and fallback logic would only need to be reviewed once.
It probably makes sense for
HasReasonto sit in the same header/module? If all display stuff is grouped with one include, it would seem odd to require another include forHasReason. But no strong opinion. Also, not sure how if this will change with https://github.com/bitcoin/bitcoin/pull/35713 and the display+HasReasonstuff is provided by the framework include?I am currently using
typeidas additional information in that debug output, but that doesn't seem great since it'll be a mangled type name. Another option is to just addHexType(0x00..00). Either way, seems like that can occur in a different pull since this one is to improve specific callsites?I intend to invert where the display comes from so
frameworkimportscommon. Sincecommonand the header here are serving the same purpose, I think I will add these forward decl tocommon.hand make acommon.cpphere.approach lgtm.
Haven't looked closely, but all of this seems fine.
Added
common.cppwith the implementations and all forward delc tocommon.hin latest pushCode review ACK 056bd2582bc96f1fc2b47933badcd4fe85832c3c
Left a few comments. I checked the new test modification and did not see any change in the test invariants.
In "test: Convert
BOOST_CHECKmacros with known debug string" 056bd2582bc96f1fc2b47933badcd4fe85832c3cnit: It will be nice if callers don't have to include this in order to use the displayable macros. Reviewers now have to point to pr authors so they can use it instead of boost check. Because when u use boost check equal without the include, it won't compile.
Should we make common.h self-advertising so authors discover it without a reviewer? A short header comment listing the types it makes BOOST_CHECK_*-printable, e.g.:
In "test: Convert
BOOST_CHECKmacros with known debug string" 056bd2582bc96f1fc2b47933badcd4fe85832c3cIt seems you missed some.
diff
In "test: Add display
operator<<overloads tocommon.{h,cpp}" 05bd1513be2d9aaeb0a94671024f585f0d3cca15nit: add context to what we are displaying here and other places.
diff
In "test: Add display
operator<<overloads tocommon.{h,cpp}" 05bd1513be2d9aaeb0a94671024f585f0d3cca15Should we add for script too?
Makes sense. Applied those changes as well as adding a
addrfield toCServiceandCAddress.Applied those changes, thanks
Yeah, definitely, I added a debug output and modified
psbt_testsandscript_teststo include it.Added a comment to
common.hdescribing the purpose of the file. I think it would be a bit cumbersome to update the list on each addition to this file, and the developer would already be either in the file or one click away, so I noted that debug-available types are listed in the header.tACK 0560c013476708771cf9141fda54410cbee07645
Rebuilt and ran the unit tests on this head. Left one non-blocking nit.
nit:
ScriptToAsmStrdecodes any push of up to four bytes as a number, so scripts that differ in bytes can come out as the same string.A P2WPKH scriptPubKey and the same script with
OP_0replaced by a one-byte zero push, which is no longer a witness program, both print the same, andpsbt_testscompares exactlyGetScriptForDestination(WitnessV0KeyHash{...}). Would it be worth addinghex=%salongside?Nice find. Somewhat unfortunate to make the debug output longer here, but given the ASM will be the most useful a majority of the time, with the possibility of needing to use hex, I added the hex string alongside the ASM in the latest push.
reACK
387e443275, all my suggestions were addressed.re-ACK
387e443275How exhaustive is the conversion supposed to be? In this file alone there seem to be more cases where we compare scriptsigs.
It is intended to be completely exhaustive for the types with << added here. I ran the following:
rg -nP '\bBOOST_CHECK(?!_)\s*\(\s*(?=[^()\n]*(?:==|!=|<=|>=|<|>))[^()\n]*\)'which showed quite a few additional sites I missed that have been updated now (descriptor_tests,key_tests,script_standard_tests,script_tests). Should be cleaned up now, updated in latest push.That grep also showed a number of sites that could be converted from
BOOST_CHECKtoBOOST_CHECK_*bc the types haveoperator<<, but those could be done as follow up or deferred.reACK
fc42f878cbThe recent push converted a few call sites that were supposed to be converted from bare boost check but are left out.
I also used the same
rg -nP '\bBOOST_CHECK(?!_)\s*\(\s*(?=[^()\n]*(?:==|!=|<=|>=|<|>))[^()\n]*\)'command and inspected the remaining ones; there are some that can also have a display string likeTxGraph::Ref. Intentional I guess?Integer comparisons are left untouched as well. Also intentional?
The PR description should be more explicit about this and the rationale.
This is a nice cleanup consequence of the main goal, which is replacing the framework, and I support it, but AFAICT only the first commit is needed
ed9dd30570for the main PR https://github.com/bitcoin/bitcoin/pull/35713,Thanks, I updated the description to be more thorough as far as what this seeks to accomplish.
Yes, added to description
What is being compared in those tests is
std::vector<std::vector<TxGraph::Ref*>>, which is more nuanced. Also updated the description.reACK
e239d936cfIn
b6ec94b700"test: Add displayoperator<<overloads tocommon.{h,cpp}"minor grammar nit:
Fixed a silent build error where
Encodewas removed and added another callsite migration of anXOnlyPubkey1f6262c559reACK
1f6262c559Base:
f655a8df755330911c6c109c8b1d04ef5dd4ea09Head:
722d08e03980c359bae4e3b65551d6b8ba615a7aNo verified findings are available from this review.
Review coverage was incomplete.
Review limitations
Full review report
I haven't reviewed that the printing of fields is exhaustive, nor that the replacement is exhaustive, but this is just adding more test debug logs, which seems harmless. lgtm.
happy to re-ack for the nits, but up to you.
review ACK
cf4412a592🌧Show signature
Signature:
nit: I find
SpanWriter{code} << k;more readable.nit in
05053fc29c: Could forward to op<<(const Cscript&) ?same: fwd?
nit: should this say
std::pair(_, _)?Addressed review
aa94fda3adreview ACK
aa94fda3ad🗝Show signature
Signature:
Looks like a few more arrived in the meantime:
Can you add these? The PR seems good to go otherwise.
review ACK
722d08e039🍟Show signature
Signature:
reACK
722d08e039Some nits were addressed, and more conversions of boost check to boost check equal.
rfm? This is in a rebase,re-ack,nit loop for several months now?