Skip to content

Conversation

@AlexJones0
Copy link
Contributor

@AlexJones0 AlexJones0 commented Dec 2, 2025

This PR refactors the logic for constructing the list of arguments that must be passed to QEMU to run an OT Earlgrey 1.0.0 machine into a separate qemu.sh utility script that can be used to spawn a standalone instance of QEMU, without needing to go through an opentitan_test. This allows for more widespread use of QEMU outside of the current standard test environment, which it was previously constrained to.

There are a couple of key differences from the existing flow that are worth noting:

  • More arguments are now parameterized by the qemu.sh start script and can be changed as part of this standalone flow (e.g. the monitor/socket paths). These are also used to be able to clean up leftover CharDev interfaces on exit so that a bazel run should be idempotent and not complain about existing PTYs.
  • The cleanup trap handler logic in qemu_test.sh has been fixed so that it now takes the process ID of the daemonized process that is returned by QEMU, rather than trying to kill the original QEMU process (which should instead exit directly after daemonization). The kill output is also silenced and conditional to help clean up some noise.

Aside: I've kept this as a bash script for now since I think it's just around simple enough that it would be more work to maintain an equivalent Python script, but it might be nice to convert these scripts to Python if they are likely to grow much larger.

Also, an open question: is there a nicer way to set environment variables to pass into qemu_test.sh instead of using templating? I can't figure out all the moving parts to do that but I'm not a huge fan of the existing templating approach, albeit I know we use it in a few shell scripts with Bazel.

@AlexJones0 AlexJones0 requested a review from cfrantz as a code owner December 2, 2025 18:08
@AlexJones0 AlexJones0 requested review from jwnrt, pamaury and ziuziakowska and removed request for cfrantz December 2, 2025 18:08
@AlexJones0 AlexJones0 force-pushed the qemu_standalone branch 2 times, most recently from 87a9b4a to 6d3f04c Compare December 2, 2025 21:20
@AlexJones0
Copy link
Contributor Author

For reference I also ran a full QEMU regression with no visible changes from the current results (the spi_device_tpm_tx_rx_test is known to be flaky currently when run in parallel on GH runners, likely due to tight timing).

Copy link
Contributor

@ziuziakowska ziuziakowska left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@pamaury pamaury left a comment

Choose a reason for hiding this comment

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

Thanks Alex, this changes look good. Regarding the templating, I have a suggestion, I will write a comment on the PR.

@pamaury
Copy link
Contributor

pamaury commented Dec 3, 2025

I haven't actually tested it but in theory, an executable or test rule can return, in addition to the usual DefaultInfo and other providers, a RunEnvironmentInfo provider. Unfortunately there isn't any documentation available that could find, only the source code. It seems that you need to create it as follows:

env = RunEnvironmentInfo({"VAR1": "value 1", "VAR2": "value2"}, [])

Unfortunately, the way the exec_env are setup makes it a bit tricky because the dispatch function returns a tuple script, data_files instead of providers. Maybe you could change the code to support test dispatch function which return an optional third member in the tuple with additional providers.

EDIT: here is an example in rules_go which could help

@AlexJones0
Copy link
Contributor Author

Thanks @pamaury, that's very useful info and makes sense. In the interest of time I think I'll leave this PR as is, but it would be nice to change in the future as I think the process you have described sounds nicer. What we currently have is fine, it just stops us from easily reusing the qemu_test.sh script outside of the Bazel qemu test_dispatch rule.

Refactor all of the logic for constructing the arguments that must be
passed to QEMU to run an OT Earlgrey 1.0.0 machine into a separate
`qemu.sh` utility script that can be used to spawn a standalone instance
of QEMU, without going through Bazel. This allows for more widespread
use of QEMU outside of the current `opentitan_test` environment, which it
was previously constrained to.

This commit also makes a couple of modifications to the existing flow:
 - More arguments are now parameterized and can be changed as part of
   this standalone flow (e.g. the monitor/socket paths).
 - The cleanup trap handler logic in `qemu_test.sh` is fixed to take the
   daemonized process ID returned by QEMU, rather than trying to kill
   the original QEMU process (which should exit after daemonization,
   hence it was not doing anything and processes could persist through a
   `bazel run`). The kill output is silenced to clean up some noise.

Signed-off-by: Alex Jones <[email protected]>
Co-authored-by: James Wainwright <[email protected]>
@AlexJones0
Copy link
Contributor Author

Last couple of force pushes just move the qemu.sh script from hw/top_earlgrey/util to hw/top_earlgrey/sw/util because it seems like the FuseSoc bitstream build is messed up if there is a BUILD file located there, as it can no longer find the Vivado hooks.

@AlexJones0
Copy link
Contributor Author

Failing CI FPGA test //sw/device/tests:usbdev_deep_disconnect_test_fpga_cw310_sival_rom_ext is known flaky/failing on earlgrey_1.0.0, so I'm merging this PR regardless.

@AlexJones0 AlexJones0 merged commit b08aa0b into lowRISC:earlgrey_1.0.0 Dec 4, 2025
63 of 66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants