> On 27 Jul 2025, at 19:35, Antonio Borneo <borneo.anto...@gmail.com> wrote:
>
> If I understand correctly, Liviu uses this exit code in some test that
> runs OpenOCD, let OpenOCD start a FW on target, get the exit status of
> the FW and quit OpenOCD with that exit status. The test gets the exit
> status from OpenOCD.
Yes, this is the intended use case for Arm semihosting when running unit tests.
Of the many semihosting calls, only a few are expected to be used with a
debugger like GDB connected (WRITEC, WRITE0 to implement a trace output
stream). The majority are intended to provide a minimalistic file I/O
interface, allowing the running test to read/write files on the host, obtain
command-line argv, and return an exit code.
Therefore, for this use case, do not expect OpenOCD to run under the command of
a debugger, nor expect that after the semihosting EXIT operation is called, the
target must do anything other than halt.
Unit tests running via semihosting on a target are standalone applications. You
should understand them exactly as native `main(argc, argv) { ... exit(code) }`
applications, which no longer exist after exit.
Consequently, if you want to perform any cleanup actions in OpenOCD after the
semihosting EXIT is called, you certainly can do so. However, if there is no
debugger connected, there is no 'resume' because the unit test can do nothing
else after terminating. All you can do is halt the target and leave it in a
state that will allow a subsequent OpenOCD invocation to run another unit test
on it, then finally exit OpenOCD.
You should also not require custom scripts to achieve the above default
behaviour.
On the other hand, if semihosting is used with a debugger connected (for
example, to run a debug session on a unit test), you can envisage all sorts of
debugging scenarios, but this is a different matter entirely.
Liviu