Skip to content

Conversation

@pamaury
Copy link
Contributor

@pamaury pamaury commented Oct 22, 2025

Even though opentitanlib supports asking QEMU to shutdown, it is (1) optional, (2) relies on the test harness stopping cleanly. One may argue that it is not really the responsability of the test harness to shutdown QEMU anyway since it is not spawn by the harness but rather by the qemu_test.sh script.

This commit makes the qemu_test.sh script always shutdown QEMU on exit. It first sends a SIGINT and after one second a SIGKILL.

Even though opentitanlib supports asking QEMU to shutdown, it is
(1) optional, (2) relies on the test harness stopping cleanly.
One may argue that it is not really the responsability of the test
harness to shutdown QEMU anyway since it is not spawn by the harness
but rather by the qemu_test.sh script.

This commit makes the qemu_test.sh script always shutdown QEMU on
exit. It first sends a SIGINT and after one second a SIGKILL.

Signed-off-by: Amaury Pouly <[email protected]>
@rivos-eblot
Copy link
Contributor

rivos-eblot commented Oct 22, 2025

I'm not using Bazel so I can't really provide any useful feedback.
As a sidenote, couldn't you use the timeout command that manages the termination sequence (ask for termination, then kill after a secondary timeout)?

Copy link
Contributor

@AlexJones0 AlexJones0 left a comment

Choose a reason for hiding this comment

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

LGTM, but yes I think it might be possible to use timeout?

@pamaury
Copy link
Contributor Author

pamaury commented Oct 22, 2025

I'm not using Bazel so I can't really provide any useful feedback. As a sidenote, couldn't you use the timeout command that manages the termination sequence (ask for termination, then kill after a secondary timeout)?

I don't think timeout applies here: it would require to run qemu itself using timeout, e.g. timeout qemu ..., but that is not what is happening here: qemu is already running and on cleanup but just want to stop it. My code does exactly what you describe: it sends a SIGTERM then wait. In the background, another process waits 1s and sends a SIGKILL. So if QEMU still hasn't stopped after one second, it will get killed. Possibly the inelegant part is that the subprocess might end up sending a KILL to a non-existent process potentially, but I don't see how timeout would help me solve this.

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.

3 participants