diff options
author | Thomas Huth | 2020-09-30 13:13:52 +0200 |
---|---|---|
committer | Thomas Huth | 2020-10-24 07:23:19 +0200 |
commit | b7f47e82e2d8ccf368d70fc4fd1467db55a74a32 (patch) | |
tree | 8e77b86bcce0487c787381884533c158fd91cffa | |
parent | tests/migration: fix memleak in wait_command/wait_command_fd (diff) | |
download | qemu-b7f47e82e2d8ccf368d70fc4fd1467db55a74a32.tar.gz qemu-b7f47e82e2d8ccf368d70fc4fd1467db55a74a32.tar.xz qemu-b7f47e82e2d8ccf368d70fc4fd1467db55a74a32.zip |
tests/qtest/libqtest: Fix detection of architecture for binaries without path
The qtests can be run directly by specifying the QEMU binary with the
QTEST_QEMU_BINARY environment variable, for example:
$ QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 tests/qtest/test-hmp
However, if you specify a binary without a path, for example with
QTEST_QEMU_BINARY=qemu-system-x86_64 if the QEMU binary is in your
$PATH, then the test currently simply crashes.
Let's try a little bit smarter here by looking for the final '-'
instead of the slash.
Message-Id: <20201012114816.43546-1-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
-rw-r--r-- | tests/qtest/libqtest.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 08929f5ff6..b9ff29055b 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -870,9 +870,14 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) const char *qtest_get_arch(void) { const char *qemu = qtest_qemu_binary(); - const char *end = strrchr(qemu, '/'); + const char *end = strrchr(qemu, '-'); - return end + strlen("/qemu-system-"); + if (!end) { + fprintf(stderr, "Can't determine architecture from binary name.\n"); + abort(); + } + + return end + 1; } bool qtest_get_irq(QTestState *s, int num) |