tests/qtest: Make qtest_get_arch() cleverer
The qtest_get_arch() function tries to determine the architecture under test by extracting it from the binary name as provided in QTEST_QEMU_BINARY. The current logic finds the last '-' in the string and assumes everything beyond it is the architecture name. Although we also look for the substring "-system-", the only effect this check has is that we will exit with an error if it is not present. Because the logic at the moment is very simplistic, although it is possible to provide more complex commands than a bare QEMU binary path, such as: QTEST_QEMU_BINARY='rr record ./qemu-system-x86_64' it is not possible to provide extra arguments to QEMU, such as: QTEST_QEMU_BINARY='./qemu-system-x86_64 -d trace:foo' Because the "-system-" check and the "find the architecture" check are not the same, the latter example will pass the "we found -system-" check and not notice that the "architecture name" it has found starts further on in the string; so rather than printing an error it will return "d trace:foo" to the test. Improve the "find the architecture name" logic to look for the rightmost occurrence of the substring "-system-" in QTEST_QEMU_BINARY, and take the architecture name as starting there and continuing until the first whitespace character or the end of the string. Because we now need to potentially modify the environment variable string to terminate the architecture name if it is not the last part of the string, we make a copy of it which we cache in a static variable. This lets us avoid having to modify all the callers to get them to take ownership of the returned string. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260427150007.1185559-1-peter.maydell@linaro.org Signed-off-by: Fabiano Rosas <farosas@suse.de>