-
Notifications
You must be signed in to change notification settings - Fork 597
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
PeekPokeAPI: include source location on failed expect() calls. #4144
PeekPokeAPI: include source location on failed expect() calls. #4144
Conversation
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.
This is a fantastic PR, thank you!
I have left a few minor/nitty comments, please address and I will merge!
I haven't tried stack trace collection. Other than simply not getting to it yet, I don't think I have a rigorous enough setup (or a large enough testcase, which I have a working build going for) to meaningfully assess the performance cost.
I don't see any reason to bother, this is great.
I try a very simple refactor of the source line collection in ErrorLog, and use it to embellish the exception. It's not very pretty — I just nyonk getErrorLineInFile over to ExceptionHelpers and mark it private[chisel3] so it doesn't become a new public API to maintain. We have to take sourceRoots as an argument.
I would have done the exact same thing so LGTM
I couldn't actually find a meaningful way to collect source roots at the point of calling expect() (no Builder context, etc., so I'm not sure how to get at the ChiselOptions for a given module, if it's even possible), so we just use none, which defaults to Seq(new File(".")). This works fine for Chisel's own test cases and mine in my testing, but maybe there's more complicated setups out there.
Yeah it would be nice if we could extract that information from the Builder context, but that requires a larger effort of propagating that info from Chisel elaboration to ChiselSim that's way beyond the scope of this PR. This particular issue probably also doesn't come up very often, and in those cases, they will still get the source locator even if they don't get the source line and carat.
Note this is failing formatting which you can run with |
1228ac3
to
bb50415
Compare
Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
bb50415
to
e0b4e5d
Compare
Thanks for pointing that out! I just got started with Scala a month ago or so and I've been very slowly exposing myself to the toolchain; Mill is one I've been deferring on (until now!). All cleaned up — I went and reformatted the individual patches rather than adding a 'reformat' commit at the end — and rebased on main. Thanks for your guidance on this, I really appreciate it! |
…raContext. Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
e0b4e5d
to
77ebff8
Compare
It doesn't help that we are in the process of slowly switching from SBT to mill so like 80% of things in this repo are still using SBT but a couple of things are using Mill 🙃 |
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.
Thank you!
* simulator: add SourceInfo to expect calls and report. * simulator: add test for failed expects. * simulator: attempt to extract source line. * simulator: make testableData.expect's sourceInfo parameter explicit. * simulator: add factory method for giving failed expect sourceInfo/extraContext. (cherry picked from commit 45dd82a) # Conflicts: # src/test/scala/chiselTests/simulator/SimulatorSpec.scala
…ort #4144) (#4149) * PeekPokeAPI: include source location on failed expect() calls. (#4144) * simulator: add SourceInfo to expect calls and report. * simulator: add test for failed expects. * simulator: attempt to extract source line. * simulator: make testableData.expect's sourceInfo parameter explicit. * simulator: add factory method for giving failed expect sourceInfo/extraContext. (cherry picked from commit 45dd82a) # Conflicts: # src/test/scala/chiselTests/simulator/SimulatorSpec.scala * Resolve backport conflicts and binary compatibility issues * Run scalafmt --------- Co-authored-by: Asherah Connor <ashe@kivikakk.ee> Co-authored-by: Jack Koenig <koenig@sifive.com>
Fixes #4128. (cc @jackkoenig)
Some notes:
SourceInfo
collection and reporting in the exception.testableData.expect
(withexpected
,encode
andbuildMessage
arguments) to be called by a test user directly? If not, I have a slight preference for making thesourceInfo
argument non-implicit there, and only having it implicit in the user-facing calls onSimulationData
.expect()
actually does anything. This isn't specific to this work.ErrorLog
, and use it to embellish the exception.getErrorLineInFile
over toExceptionHelpers
and mark itprivate[chisel3]
so it doesn't become a new public API to maintain. We have to takesourceRoots
as an argument.expect()
(noBuilder
context, etc., so I'm not sure how to get at theChiselOptions
for a given module, if it's even possible), so we just use none, which defaults toSeq(new File("."))
. This works fine for Chisel's own test cases and mine in my testing, but maybe there's more complicated setups out there.I'm not emotionally wed to any of this, so do feel free to suggest other ways for it to be done, or to rework it yourself if that's less overall work! (Particularly thinking of the refactor here, as it's not the cleanest.)
It does work nicely, though:
Contributor Checklist
docs/src
?Type of Improvement
Desired Merge Strategy
Release Notes
SimulationData.expect
calls now record source location and report it in theFailedExpectationException
on failure.Reviewer Checklist (only modified by reviewer)
3.6.x
,5.x
, or6.x
depending on impact, API modification or big change:7.0
)?Enable auto-merge (squash)
, clean up the commit message, and label withPlease Merge
.Create a merge commit
.