From: Fabiano Rosas <farosas@suse.de>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 3/3] tests/qtest/libqtest: Use a GArray for QTestState::irq_level[]
Date: Tue, 27 Oct 2026 09:30:22 -0300 [thread overview]
Message-ID: <87o6cfjpgh.fsf@suse.de> (raw)
In-Reply-To: <20261026125655.2668658-4-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> Currently we use a fixed irq_level[] array of 256 elements in
> QTestState to implement capturing the IRQ level reported by the QEMU
> under test so we can return it in qtest_get_irq(). This is smaller
> than is actually used by some devices, and if a test tries to
> intercept more IRQs than this and one is reported to libqtest then
> we'll fail an assertion in qtest_rsp_args().
>
> Switch to a GArray, which automatically resizes as required.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> tests/qtest/libqtest.c | 28 ++++++++++++++--------------
> 1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 9e7a2d43a18..22b0dc193c9 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -42,8 +42,6 @@
> #include "qobject/qstring.h"
> #include "qobject/qbool.h"
>
> -#define MAX_IRQ 256
> -
> #define ACCEPT_TIMEOUT_MS 250
> #define ACCEPT_RETRIES (4 * 50)
>
> @@ -88,7 +86,7 @@ struct QTestState
> #endif
> int expected_status;
> bool big_endian;
> - bool irq_level[MAX_IRQ];
> + GArray *irq_level;
> GString *rx;
> QTestTransportOps ops;
> GList *pending_events;
> @@ -501,7 +499,7 @@ static QTestState *qtest_init_internal(const char *qemu_bin,
> void *opaque)
> {
> QTestState *s;
> - int sock, qmpsock, i;
> + int sock, qmpsock;
> g_autofree gchar *socket_path = qtest_socket_path("sock");
> g_autofree gchar *qmp_socket_path = qtest_socket_path("qmp");
> g_autofree gchar *args = qtest_qemu_args(extra_args);
> @@ -525,9 +523,7 @@ static QTestState *qtest_init_internal(const char *qemu_bin,
> qtest_client_set_tx_handler(s, qtest_client_socket_send);
>
> s->rx = g_string_new("");
> - for (i = 0; i < MAX_IRQ; i++) {
> - s->irq_level[i] = false;
> - }
> + s->irq_level = g_array_new(false, true, sizeof(bool));
>
> s->fd = -1;
> s->qmp_fd = -1;
> @@ -693,6 +689,7 @@ void qtest_quit(QTestState *s)
> close(s->fd);
> close(s->qmp_fd);
> g_string_free(s->rx, true);
> + g_array_unref(s->irq_level);
>
> for (GList *it = s->pending_events; it != NULL; it = it->next) {
> qobject_unref((QDict *)it->data);
> @@ -778,12 +775,14 @@ redo:
> ret = qemu_strtol(words[2], NULL, 0, &irq);
> g_assert(!ret);
> g_assert_cmpint(irq, >=, 0);
> - g_assert_cmpint(irq, <, MAX_IRQ);
>
> + if (s->irq_level->len <= irq) {
> + g_array_set_size(s->irq_level, irq + 1);
> + }
> if (strcmp(words[1], "raise") == 0) {
> - s->irq_level[irq] = true;
> + g_array_index(s->irq_level, bool, irq) = true;
> } else {
> - s->irq_level[irq] = false;
> + g_array_index(s->irq_level, bool, irq) = false;
> }
>
> g_strfreev(words);
> @@ -1192,7 +1191,10 @@ bool qtest_get_irq(QTestState *s, int num)
> /* dummy operation in order to make sure irq is up to date */
> qtest_inb(s, 0);
>
> - return s->irq_level[num];
> + if (s->irq_level->len <= num) {
> + return false;
> + }
> + return g_array_index(s->irq_level, bool, num);
> }
>
> void qtest_module_load(QTestState *s, const char *prefix, const char *libname)
> @@ -2100,9 +2102,7 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
> qts->pending_events = NULL;
> *s = qts; /* Expose qts early on, since the query endianness relies on it */
> qts->wstatus = 0;
> - for (int i = 0; i < MAX_IRQ; i++) {
> - qts->irq_level[i] = false;
> - }
> + qts->irq_level = g_array_new(false, true, sizeof(bool));
>
> qtest_client_set_rx_handler(qts, qtest_client_inproc_recv_line);
Reviewed-by: Fabiano Rosas <farosas@suse.de>
next prev parent reply other threads:[~2026-10-27 12:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:56 [PATCH 0/3] qtest: Remove 256 IRQ limit on irq intercepts Peter Maydell
2026-10-26 12:56 ` [PATCH 1/3] system/qtest: Avoid fixed-size irq_levels array for IRQ intercept Peter Maydell
2026-10-27 12:21 ` Fabiano Rosas
2026-10-26 12:56 ` [PATCH 2/3] system/qtest: Check ngl->name for irq_intercept_in Peter Maydell
2026-10-27 12:24 ` Fabiano Rosas
2026-10-26 12:56 ` [PATCH 3/3] tests/qtest/libqtest: Use a GArray for QTestState::irq_level[] Peter Maydell
2026-10-27 12:30 ` Fabiano Rosas [this message]
2026-10-27 12:30 ` [PATCH 0/3] qtest: Remove 256 IRQ limit on irq intercepts Fabiano Rosas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o6cfjpgh.fsf@suse.de \
--to=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.