Skip to content
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

[svsim] Handle Chisel assertions more elegantly #4386

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jackkoenig
Copy link
Contributor

This is a bugfix but I'm not sure if it should be backported [yet] because adding new arguments, even with default arguments, to public methods breaks binary compatibility. I don't feel like dealing with that at the moment. If we need to backport it later, we can. We could backport just the bugfix part of it I guess.

The returned exception is now a lot more elegant than svsim.Simulation.UnexpectedEndOfMessages. This also fixes an issue where the Verilator crashes could create core dumps depending on the user's ulimit settings.

I have not yet tested this with VCS, so there may be follow up work (possibly in a follow up PR).

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Bugfix

Desired Merge Strategy

  • Squash

Release Notes

  • svsim now overrides Verilators $fatal handling to more elegantly report the error.
  • svsim can now accept a java.io.OutputStream to consume the stderr from the simulation process. This is especially useful for testing.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash), clean up the commit message, and label with Please Merge.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@jackkoenig jackkoenig added the Bugfix Fixes a bug, will be included in release notes label Sep 6, 2024
* svsim now overrides Verilators $fatal handling to more elegantly
  report the error.
* svsim can now accept a java.io.OutputStream to consume the stderr from
  the simulation process. This is especially useful for testing.
* svsim will throw Simulation.Message.Error on assertion failures rather
  than Simulation.UnexpectedEndOfMessages.
@jackkoenig
Copy link
Contributor Author

What's weird is that these failing tests are currently printing failures and maybe even crashing on main, but for some reason SVSim returns success. I think my changes are just exposing some other underlying issue. I had been planning to revisit how we deal with $stop in a follow on PR, but it might just have to be done in this PR as well.

Comment on lines +45 to +60
// Fire and forget a thread that forwards the process's stderr.
// This thread will block on the processes error stream until it is closed, then the thread will complete.
implicit val e: ExecutionContext = ExecutionContext.global
Future {
// TODO use transferTo once we require Java 9 or newer.
val BufSize = 8192 // Taken from java.io.InputStream.DEFAULT_BUFFER_SIZE.
val err = process.getErrorStream()
val buffer = new Array[Byte](BufSize)
var read = 0
while ({
read = err.read(buffer, 0, BufSize)
read >= 0
}) {
stderrStream.write(buffer, 0, read)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of a drive-by comment, but is there a particular reason why you're handling this as a Java Stream rather than using Scala's nice streaming data-types and stream programming constructs? Is there non Scala equivalent to Console.err that you can use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Scala's streaming constructs are generally for streaming data, whereas for process-level I/O streams I think it's still pretty typical to just use java.io streams (as evidenced by the fact that scala.Console.err is a java.io.OutputStream). I guess I'm not aware of any advantage to wrapping this in a Scala type but if anyone has a suggestion I'm all ears 🙂.

I could use System.err, I'm not really sure when one should use Java's System vs. Scala's Console for these sorts of things, but we often use things like Console.withOut to capture stdout, so I figured I'd go with the Scala API.

Copy link
Member

@dobios dobios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, this looks good to me given that I couldn't find a better way to handle those streams either. Not sure why CI is broken tho

@jackkoenig
Copy link
Contributor Author

Thanks for the review @dobios! I think I sadly have to bite the bullet and also implement $stop for this to pass CI... will revisit eventually 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Fixes a bug, will be included in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants