On 3/4/26 7:35 AM, Florian Hofhammer wrote:
On 03/03/2026 20:46, Pierrick Bouvier wrote:
On 3/3/26 5:07 AM, Florian Hofhammer wrote:
The test plugin intercepts execution in different contexts. Without the
plugin, any of the implemented test functions would trigger an assert
and fail. With the plugin, control flow is redirected to skip the assert
and return cleanly via the qemu_plugin_set_pc() API.

Signed-off-by: Florian Hofhammer <[email protected]>
---
   MAINTAINERS                                        |   1 +
   tests/tcg/arm/Makefile.target                      |   6 +
   tests/tcg/multiarch/Makefile.target                |  17 ++-
   .../multiarch/{ => plugin}/check-plugin-output.sh  |   0
   .../{ => plugin}/test-plugin-mem-access.c          |   0
   tests/tcg/multiarch/plugin/test-plugin-set-pc.c    | 140 
+++++++++++++++++++++
   tests/tcg/plugins/meson.build                      |   1 +
   tests/tcg/plugins/setpc.c                          | 120 ++++++++++++++++++
   8 files changed, 282 insertions(+), 3 deletions(-)


...


As mentioned on v4, you can simply use an external function for failing the 
test, which won't be tainted with noreturn attribute.
This way, you don't need any guard at all or assert(0), and resulting code is 
linear and easier to read.
It test completes, it all worked. If it crashes, something was wrong.

void panic(void)
{
      g_assert_not_reached();
}

void test_...() {
...
on_panic:
      panic();
after_panic:
      printf("Hello World\n");
}

I've reworked it to look similar to this (without g_assert_not_reached()
though, because glib is not available in the test itself). Still
required some shuffling of stuff to make sure the compiler doesn't
optimize things away then :) Especially on hexagon, which is the only
target (by default) built with clang instead of gcc. Clang/LLVM seems to
be way more aggressive even at -O0 to do deadcode elimination and
inlining, so I had to add extra CFLAGS for the hexagon target.

You're right, I forgot glib is not available there.
assert(0), exit for abort works instead of g_assert_not_reached().

Sounds good for hexagon target.
We can always update the test later if needed, and at least it stays simple. Thanks for doing this extra step.

Regards,
Pierrick

Reply via email to