-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
forc test single-step until jump point instead of patching binary #6731
Conversation
58decfa
to
4f8169e
Compare
Nice, thanks for doing this! |
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.
Everything looks pretty reasonable here to me. Will defer to @kayagokalp for a review though
Hey there, thanks a lot for the PR! I'll be checking it next thing in the morning 🙌 |
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.
Looks good to me! Thanks again.
Just for me to understand the choices behind the implementation better I have a question. With recent changes being done in the emitted metadata for @sdankel's work (to remove configurable for ABI uploads), I believe we have the information where the configurable section ends(?) So instead of single stepping in the vm could we use that information and add the jump instruction after that offset? (This is not to argue that is a better choice but for me to understand what exactly was the problem)
As far as I can see the problem was: we had the jmp instruction patched to the beginning of the bytecode, before configurable initialization, which was causing configurables not being available to tests.
Or am I interpreting the reason of single stepping wrong?
Yes. Correct.
At the beginning of the binary we have where the "encoded values" of the configurables are, but we do not have where the initialization of configurables starts and ends. And there is not guarantee that there is "space" between the configurable end and the rest of the binary to overwrite with the necessary jump. For scrips/contracts and predicates using encoding v1, the first function is the "__entry" function, and we can overwrite is prologue, as it is not going to be called. But for libraries, there is no configurable initialization, but there is also no "spare" instruction to use. As after the initialization, the first instruction is the first function prologue, and we cannot overwrite it, as it can be called. For example: library;
fn f() {
}
#[test]
fn ff() {
f();
} Generates:
There is no "spare" instruction between 0x00000014 and 0x00000018 that we can replace. That is why I think single-stepping (or a breakpoint) are better solutions for the moment. |
Oh I see, that is nice. Thanks for the great explanation |
Description
Fixes #6720.
Since configurables started to use encoding v1, it is not possible to use configurables inside tests, because
forc test
patches the binary forcing a jump into the test function before configurables are initialized.This PR fixes this changing the approach from patching the binary, to single-stepping the initialization and them manually changing the
PC
register to the first instruction of the test.Performance is acceptable, a test with a lot of configurables takes
572.382µs
.Checklist
Breaking*
orNew Feature
labels where relevant.