qemu-arm.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: "Alastair D'Silva" <alastair@au1.ibm.com>
Cc: "Andrew Jeffery" <andrew@aj.id.au>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	qemu-arm <qemu-arm@nongnu.org>, "Joel Stanley" <joel@jms.id.au>,
	"Alastair D'Silva" <alastair@d-silva.org>,
	"Cédric Le Goater" <clg@kaod.org>
Subject: Re: [Qemu-arm] [PATCH v3 4/7] qtest: Support named interrupts
Date: Wed, 14 Dec 2016 18:29:11 +0000	[thread overview]
Message-ID: <CAFEAcA8__YWN9f2=GDeX5ddFnV_WWknpdrUeVud9-YLu9cE0Pw@mail.gmail.com> (raw)
In-Reply-To: <20161202054617.6749-5-alastair@au1.ibm.com>

On 2 December 2016 at 05:46, Alastair D'Silva <alastair@au1.ibm.com> wrote:
> From: Alastair D'Silva <alastair@d-silva.org>
>
> The QTest framework cannot work with named interrupts. This patch
> adds support for them, as well as the ability to manipulate them
> from within a test.
>
> Read actions are via callbacks, which allows for pulsed interrupts
> to be read (the polled method used for the unnamed interrupts
> cannot read pulsed interrupts as the value is reverted before the
> test sees the changes).
>
> Signed-off-by: Alastair D'Silva <alastair@d-silva.org>

> --- a/qtest.c
> +++ b/qtest.c
> @@ -40,7 +40,6 @@ static DeviceState *irq_intercept_dev;
>  static FILE *qtest_log_fp;
>  static CharBackend qtest_chr;
>  static GString *inbuf;
> -static int irq_levels[MAX_IRQ];
>  static qemu_timeval start_time;
>  static bool qtest_opened;
>
> @@ -160,10 +159,16 @@ static bool qtest_opened;
>   *
>   *  IRQ raise NUM
>   *  IRQ lower NUM
> + *  IRQ_NAMED NAME NUM LEVEL

I think we should be consistent about the protocol here:
unnamed IRQs get 'raise' and 'lower' messages, so we should
do the same for named IRQs.

>   *
>   * where NUM is an IRQ number.  For the PC, interrupts can be intercepted
>   * simply with "irq_intercept_in ioapic" (note that IRQ0 comes out with
>   * NUM=0 even though it is remapped to GSI 2).
> + *
> + *  > irq_set NAME NUM LEVEL
> + *  < OK
> + *
> + *  Set the named input IRQ to the level (0/1)

I think adding support for raising and lowering device IRQs
should be a separate patch, as it's a different feature.
(I'm also not sure we should need it -- devices will be
wired into the system, and qtest is testing the whole
system from the point of view of the CPU. The CPU can't
arbitrarily reach in and assert a device's outgoing
interrupt line, so I'm not sure the tests should be able
to do it either.)

(Everything else below here is trivial fixes.)

>   */
>
>  static int hex2nib(char ch)
> @@ -243,17 +248,31 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(CharBackend *chr,
>      va_end(ap);
>  }
>
> +typedef struct qtest_irq {
> +    qemu_irq old_irq;
> +    char *name;
> +    bool last_level;
> +} qtest_irq;
> +
>  static void qtest_irq_handler(void *opaque, int n, int level)
>  {
> -    qemu_irq old_irq = *(qemu_irq *)opaque;
> -    qemu_set_irq(old_irq, level);
> +    qtest_irq *data = (qtest_irq *)opaque;
> +    level = !!level;
> +
> +    qemu_set_irq(data->old_irq, level);
>
> -    if (irq_levels[n] != level) {
> +    if (level != data->last_level) {
>          CharBackend *chr = &qtest_chr;
> -        irq_levels[n] = level;
>          qtest_send_prefix(chr);
> -        qtest_sendf(chr, "IRQ %s %d\n",
> -                    level ? "raise" : "lower", n);
> +
> +        if (data->name) {
> +            qtest_sendf(chr, "IRQ_NAMED %s %d %d\n",
> +                    data->name, n, level);
> +        } else {
> +            qtest_sendf(chr, "IRQ %s %d\n", level ? "raise" : "lower", n);
> +        }
> +
> +        data->last_level = level;
>      }
>  }
>
> @@ -289,7 +308,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
>          if (!dev) {
>              qtest_send_prefix(chr);
>              qtest_send(chr, "FAIL Unknown device\n");
> -           return;
> +            return;
>          }
>
>          if (irq_intercept_dev) {
> @@ -299,33 +318,73 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
>              } else {
>                  qtest_send(chr, "OK\n");
>              }
> -           return;
> +            return;
>          }

Fixing whitespace issues is generally best done in a separate patch.


> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 6f69752..36b3960 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -21,12 +21,16 @@
>  #include <sys/wait.h>
>  #include <sys/un.h>
>
> +#include <glib.h>
> +

osdep.h pulls in glib for you.

>  #include "qapi/qmp/json-parser.h"
>  #include "qapi/qmp/json-streamer.h"
>  #include "qapi/qmp/qjson.h"
>
> +

Stray whitespace change.

>  #define MAX_IRQ 256
>  #define SOCKET_TIMEOUT 50
> +#define IRQ_KEY_LENGTH 64
>
>  QTestState *global_qtest;


> @@ -346,6 +408,17 @@ redo:
>          g_strfreev(words);
>      }
>
> +/* Defer processing of IRQ actions until all communications have been handled,
> + * otherwise, interrupt handler that cause further communication can disrupt
> + * the communication stream
> + */

Bad indent on this comment.

> +    for (action_index = 0; action_index < action_count; action_index++) {
> +        irq_action *action = actions[action_index];
> +        action->cb(action->opaque, action->name, action->n,
> +                action_raise[action_index]);
> +        action->level = action_raise[action_index];
> +    }
> +
>      return words;
>  }
>

>  /**
> + * irq_attach:
> + * @name: the name of the gpio list containing the IRQ
> + * @irq: The IRQ to attach to
> + * @irq_cb: The callback to execute when the interrupt changes
> + * @opaque: opaque info to pass to the callback
> + *
> + * Attach a callback to an intecepted interrupt
> + */
> +static inline void irq_attach(const char *name, int irq,
> +        void (*irq_cb)(void *opaque, const char *name, int irq, bool level),
> +        void *opaque)
> +{
> +    qtest_irq_attach(global_qtest, name, irq, irq_cb, opaque);
> +}
> +
> +/**
> + * qtest_irq_set

Comment doesn't match function name (and missing ':').

> + * Set an interrupt level
> + * @id: the device to inject interrupts for
> + * @gpiolist: the GPIO list containing the line to seh
> + * @n: the line to set within the list
> + * @level: the IRQ level
> + */
> +static inline void irq_set(const char *id, const char *gpiolist, int n,
> +        bool level)
> +{
> +    qtest_irq_set(global_qtest, id, gpiolist, n, level);
> +}
> +
> +
> +/**
>   * outb:
>   * @addr: I/O port to write to.
>   * @value: Value being written.
> --
> 2.9.3

thanks
-- PMM

  reply	other threads:[~2016-12-14 18:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02  5:46 [Qemu-arm] [PATCH v3 0/7] Add support for the Epson RX8900 RTC to the aspeed board Alastair D'Silva
2016-12-02  5:46 ` [Qemu-arm] [PATCH v3 1/7] arm: Uniquely name imx25 I2C buses Alastair D'Silva
2016-12-14 17:41   ` Peter Maydell
2016-12-14 17:54     ` Cédric Le Goater
2016-12-02  5:46 ` [Qemu-devel] [PATCH v3 2/7] hw/arm: remove trailing whitespace Alastair D'Silva
2016-12-14 18:05   ` Peter Maydell
2016-12-02  5:46 ` [Qemu-devel] [PATCH v3 3/7] hw/i2c: Add a NULL check for i2c slave init callbacks Alastair D'Silva
2016-12-14 18:05   ` [Qemu-arm] " Peter Maydell
2016-12-02  5:46 ` [Qemu-devel] [PATCH v3 4/7] qtest: Support named interrupts Alastair D'Silva
2016-12-14 18:29   ` Peter Maydell [this message]
2016-12-14 23:19     ` [Qemu-arm] " Alastair D'Silva
2016-12-02  5:46 ` [Qemu-arm] [PATCH v3 5/7] hw/timer: Add Epson RX8900 RTC support Alastair D'Silva
2016-12-14 18:02   ` Peter Maydell
2016-12-15  0:48     ` Alastair D'Silva
2016-12-02  5:46 ` [Qemu-arm] [PATCH v3 6/7] tests: Test all implemented RX8900 functionality Alastair D'Silva
2016-12-02  5:46 ` [Qemu-arm] [PATCH v3 7/7] arm: Add an RX8900 RTC to the ASpeed board Alastair D'Silva

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='CAFEAcA8__YWN9f2=GDeX5ddFnV_WWknpdrUeVud9-YLu9cE0Pw@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=alastair@au1.ibm.com \
    --cc=alastair@d-silva.org \
    --cc=andrew@aj.id.au \
    --cc=clg@kaod.org \
    --cc=joel@jms.id.au \
    --cc=qemu-arm@nongnu.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 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).