qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Gustavo Romero <gustavo.romero@linaro.org>,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	alex.bennee@linaro.org, thuth@redhat.com, armbru@redhat.com,
	Fabiano Rosas <farosas@suse.de>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH v3 6/7] tests/qtest: Add API functions to capture IRQ toggling
Date: Tue, 7 Jan 2025 19:35:05 +0100	[thread overview]
Message-ID: <77ee967d-00e6-45fa-a8b1-42192e61b553@linaro.org> (raw)
In-Reply-To: <20241216141818.111255-7-gustavo.romero@linaro.org>

Cc'ing maintainers:

$ ./scripts/get_maintainer.pl -f tests/qtest/libqtest.c
Fabiano Rosas <farosas@suse.de> (maintainer:qtest)
Laurent Vivier <lvivier@redhat.com> (maintainer:qtest)
Paolo Bonzini <pbonzini@redhat.com> (reviewer:qtest)

On 16/12/24 15:18, Gustavo Romero wrote:
> Currently, the QTest API does not provide a function to capture when an
> IRQ line is raised or lowered, although the QTest Protocol already
> reports such IRQ transitions. As a consequence, it is also not possible
> to capture when an IRQ line is toggled. Functions like qtest_get_irq()
> only read the current state of the intercepted IRQ lines, which is
> already high (or low) when the function is called if the IRQ line is
> toggled. Therefore, these functions miss the IRQ line state transitions.
> 
> This commit introduces two new API functions:
> qtest_get_irq_raised_counter() and qtest_get_irq_lowered_counter().
> These functions allow capturing the number of times an observed IRQ line
> transitioned from low to high state or from high to low state,
> respectively.
> 
> When used together, these new API functions then allow checking if one
> or more pulses were generated (indicating if the IRQ line was toggled).
> 
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Acked-by: Thomas Huth <thuth@redhat.com>
> ---
>   tests/qtest/libqtest.c | 24 ++++++++++++++++++++++++
>   tests/qtest/libqtest.h | 28 ++++++++++++++++++++++++++++
>   2 files changed, 52 insertions(+)
> 
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 8de5f1fde3..dfe3139a88 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -83,6 +83,8 @@ struct QTestState
>       int expected_status;
>       bool big_endian;
>       bool irq_level[MAX_IRQ];
> +    uint64_t irq_raised_counter[MAX_IRQ];
> +    uint64_t irq_lowered_counter[MAX_IRQ];
>       GString *rx;
>       QTestTransportOps ops;
>       GList *pending_events;
> @@ -515,6 +517,8 @@ static QTestState *qtest_init_internal(const char *qemu_bin,
>       s->rx = g_string_new("");
>       for (i = 0; i < MAX_IRQ; i++) {
>           s->irq_level[i] = false;
> +        s->irq_raised_counter[i] = 0;
> +        s->irq_lowered_counter[i] = 0;
>       }
>   
>       /*
> @@ -706,8 +710,10 @@ redo:
>           g_assert_cmpint(irq, <, MAX_IRQ);
>   
>           if (strcmp(words[1], "raise") == 0) {
> +            s->irq_raised_counter[irq]++;
>               s->irq_level[irq] = true;
>           } else {
> +            s->irq_lowered_counter[irq]++;
>               s->irq_level[irq] = false;
>           }
>   
> @@ -999,6 +1005,22 @@ bool qtest_get_irq(QTestState *s, int num)
>       return s->irq_level[num];
>   }
>   
> +uint64_t qtest_get_irq_raised_counter(QTestState *s, int num)
> +{
> +    /* dummy operation in order to make sure irq is up to date */
> +    qtest_inb(s, 0);

Isn't it better to simply call:

        qtest_rsp(s);

?

> +
> +    return s->irq_raised_counter[num];
> +}
> +
> +uint64_t qtest_get_irq_lowered_counter(QTestState *s, int num)
> +{
> +    /* dummy operation in order to make sure irq is up to date */
> +    qtest_inb(s, 0);

Ditto.

> +
> +    return s->irq_lowered_counter[num];
> +}
> +
>   void qtest_module_load(QTestState *s, const char *prefix, const char *libname)
>   {
>       qtest_sendf(s, "module_load %s %s\n", prefix, libname);
> @@ -1902,6 +1924,8 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
>       qts->wstatus = 0;
>       for (int i = 0; i < MAX_IRQ; i++) {
>           qts->irq_level[i] = false;
> +        qts->irq_raised_counter[i] = 0;
> +        qts->irq_lowered_counter[i] = 0;
>       }
>   
>       qtest_client_set_rx_handler(qts, qtest_client_inproc_recv_line);
> diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
> index f23d80e9e5..b73c04139e 100644
> --- a/tests/qtest/libqtest.h
> +++ b/tests/qtest/libqtest.h
> @@ -389,6 +389,34 @@ void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
>    */
>   bool qtest_get_irq(QTestState *s, int num);
>   
> +/**
> + * qtest_get_irq_raised_counter:
> + * @s: #QTestState instance to operate on.
> + * @num: Interrupt to observe.
> + *
> + * This function can be used in conjunction with the
> + * qtest_get_irq_lowered_counter() to check if one or more pulses where
> + * generated on the observed interrupt.

Missing to mention a device must be previously intercepted with
qtest_irq_intercept_*().

> + *
> + * Returns: The number of times IRQ @num was raised, i.e., transitioned from
> + * a low state (false) to a high state (true).
> + */
> +uint64_t qtest_get_irq_raised_counter(QTestState *s, int num);
> +
> +/**
> + * qtest_get_irq_lowered_counter:
> + * @s: #QTestState instance to operate on.
> + * @num: Interrupt to observe.
> + *
> + * This function can be used in conjunction with the
> + * qtest_get_irq_raised_counter() to check if one or more pulses where
> + * generated on the observed interrupt.

Ditto.

> + *
> + * Returns: The number of times IRQ @num was lowered, i.e., transitioned from
> + * a high state (true) to a low state (false).
> + */
> +uint64_t qtest_get_irq_lowered_counter(QTestState *s, int num);
> +
>   /**
>    * qtest_irq_intercept_in:
>    * @s: #QTestState instance to operate on.



  reply	other threads:[~2025-01-07 18:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16 14:18 [RESEND][PATCH v3 0/7] Add ivshmem-flat device Gustavo Romero
2024-12-16 14:18 ` [PATCH v3 1/7] hw/misc/ivshmem-flat: " Gustavo Romero
2024-12-31 18:01   ` Philippe Mathieu-Daudé
2024-12-31 19:10   ` Philippe Mathieu-Daudé
2024-12-16 14:18 ` [PATCH v3 2/7] hw/misc/ivshmem-flat: Allow device to wire itself on sysbus Gustavo Romero
2024-12-16 14:18 ` [PATCH v3 3/7] hw/arm: Allow some machines to use the ivshmem-flat device Gustavo Romero
2024-12-16 14:18 ` [PATCH v3 4/7] hw/misc/ivshmem: Rename ivshmem to ivshmem-pci Gustavo Romero
2024-12-16 14:18 ` [PATCH v3 5/7] tests/qtest: Reorganize common code in ivshmem-test Gustavo Romero
2024-12-16 14:18 ` [PATCH v3 6/7] tests/qtest: Add API functions to capture IRQ toggling Gustavo Romero
2025-01-07 18:35   ` Philippe Mathieu-Daudé [this message]
2025-01-07 18:57     ` Philippe Mathieu-Daudé
2024-12-16 14:18 ` [PATCH v3 7/7] tests/qtest: Add ivshmem-flat test Gustavo Romero
2025-01-07 14:25 ` [RESEND][PATCH v3 0/7] Add ivshmem-flat device Markus Armbruster
2025-01-07 17:02   ` Alex Bennée

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=77ee967d-00e6-45fa-a8b1-42192e61b553@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=farosas@suse.de \
    --cc=gustavo.romero@linaro.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).