All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH 1/1] tests/qtest: add scenario for -readconfig handling
Date: Mon, 8 Aug 2022 18:03:56 +0100	[thread overview]
Message-ID: <YvFB/DZ+lYRHbd+U@redhat.com> (raw)
In-Reply-To: <0d00fbb9-3b47-6041-4afa-63bb618689f0@redhat.com>

On Mon, Aug 08, 2022 at 07:55:50AM +0200, Thomas Huth wrote:
> On 05/08/2022 13.55, Daniel P. Berrangé wrote:
> > This test of -readconfig validates the last three regressions we
> > have fixed with -readconfig:
> > 
> >   * Interpretation of memory size units as MiB not bytes
> >   * Allow use of [spice]
> >   * Allow use of [object]
> 
> Good idea!
> 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >   tests/qtest/meson.build       |   1 +
> >   tests/qtest/readconfig-test.c | 195 ++++++++++++++++++++++++++++++++++
> >   2 files changed, 196 insertions(+)
> >   create mode 100644 tests/qtest/readconfig-test.c
> > 
> > diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> > index 3a474010e4..be4b30dea2 100644
> > --- a/tests/qtest/meson.build
> > +++ b/tests/qtest/meson.build
> > @@ -26,6 +26,7 @@ qtests_generic = [
> >     'qom-test',
> >     'test-hmp',
> >     'qos-test',
> > +  'readconfig-test',
> >   ]
> >   if config_host.has_key('CONFIG_MODULES')
> >     qtests_generic += [ 'modules-test' ]
> > diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c
> > new file mode 100644
> > index 0000000000..2e604d7c2d
> > --- /dev/null
> > +++ b/tests/qtest/readconfig-test.c
> > @@ -0,0 +1,195 @@
> > +/*
> > + * Validate -readconfig
> > + *
> > + * Copyright (c) 2022 Red Hat, Inc.
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> > + * See the COPYING file in the top-level directory.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "libqtest.h"
> > +#include "qapi/error.h"
> > +#include "qapi/qapi-visit-machine.h"
> > +#include "qapi/qapi-visit-qom.h"
> > +#include "qapi/qapi-visit-ui.h"
> > +#include "qapi/qmp/qdict.h"
> > +#include "qapi/qmp/qlist.h"
> > +#include "qapi/qobject-input-visitor.h"
> > +#include "qapi/qmp/qstring.h"
> > +#include "qemu/units.h"
> > +
> > +static QTestState *qtest_init_with_config(const char *cfgdata)
> > +{
> > +    GError *error = NULL;
> > +    g_autofree char *args = NULL;
> > +    int cfgfd = -1;
> > +    g_autofree char *cfgpath = NULL;
> > +    QTestState *qts;
> > +    ssize_t ret;
> > +
> > +    cfgfd = g_file_open_tmp("readconfig-test-XXXXXX", &cfgpath, &error);
> > +    g_assert_no_error(error);
> > +    g_assert_cmpint(cfgfd, >=, 0);
> > +
> > +    ret = qemu_write_full(cfgfd, cfgdata, strlen(cfgdata));
> > +    if (ret < 0) {
> > +        unlink(cfgpath);
> > +    }
> > +    g_assert_cmpint(ret, ==, strlen(cfgdata));
> > +
> > +    close(cfgfd);
> 
> Maybe move the close() before the "if (ret < 0)"
> 
> > +    args = g_strdup_printf("-nodefaults -machine none -readconfig %s", cfgpath);
> > +
> > +    qts = qtest_init(args);
> > +
> > +    unlink(cfgpath);
> > +
> > +    return qts;
> > +}
> > +
> > +static void test_x86_memdev_resp(QObject *res)
> > +{
> > +    Visitor *v;
> > +    g_autoptr(MemdevList) memdevs = NULL;
> > +    Memdev *memdev;
> > +
> > +    g_assert(res);
> > +    v = qobject_input_visitor_new(res);
> > +    visit_type_MemdevList(v, NULL, &memdevs, &error_abort);
> > +
> > +    g_assert(memdevs);
> > +    g_assert(memdevs->value);
> > +    g_assert(!memdevs->next);
> > +
> > +    memdev = memdevs->value;
> > +    g_assert_cmpstr(memdev->id, ==, "ram");
> > +    g_assert_cmpint(memdev->size, ==, 200 * MiB);
> > +
> > +    visit_free(v);
> > +}
> > +
> > +static void test_x86_memdev(void)
> > +{
> > +    QDict *resp;
> > +    QTestState *qts;
> > +    const char *cfgdata =
> > +        "[memory]\n"
> > +        "size = \"200\"";
> > +
> > +    qts = qtest_init_with_config(cfgdata);
> > +   /* Test valid command */
> 
> Comment has bad indentation.
> 
> > +    resp = qtest_qmp(qts, "{ 'execute': 'query-memdev' }");
> > +    test_x86_memdev_resp(qdict_get(resp, "return"));
> > +    qobject_unref(resp);
> > +
> > +    qtest_quit(qts);
> > +}
> > +
> > +
> > +#ifdef CONFIG_SPICE
> > +static void test_spice_resp(QObject *res)
> > +{
> > +    Visitor *v;
> > +    g_autoptr(SpiceInfo) spice = NULL;
> > +
> > +    g_assert(res);
> > +    v = qobject_input_visitor_new(res);
> > +    visit_type_SpiceInfo(v, "spcie", &spice, &error_abort);
> 
> That "spcie" looks like a typo?

Yes, but I believe this argument is ignored by the visitor in this
scenario - it didn't fail for me at least.

Regardless, sHould be fixed of course


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2022-08-08 17:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 11:55 [PATCH 0/1] tests/qtest: add testing coverage of -readconfig Daniel P. Berrangé
2022-08-05 11:55 ` [PATCH 1/1] tests/qtest: add scenario for -readconfig handling Daniel P. Berrangé
2022-08-08  5:55   ` Thomas Huth
2022-08-08 17:03     ` Daniel P. Berrangé [this message]
2022-08-09  6:18       ` Markus Armbruster

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=YvFB/DZ+lYRHbd+U@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --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 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.