From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Ani Sinha <anisinha@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>,
Laurent Vivier <lvivier@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [PATCH 2/3] tests/qtest/libqtest: add qtest_has_cpu() api
Date: Mon, 10 Jun 2024 10:02:10 +0100 [thread overview]
Message-ID: <ZmbBElz4clEuZ1zp@redhat.com> (raw)
In-Reply-To: <20240606044419.8806-3-anisinha@redhat.com>
On Thu, Jun 06, 2024 at 10:14:18AM +0530, Ani Sinha wrote:
> Added a new test api qtest_has_cpu() in order to check availability of some
> cpu models in the current QEMU binary. The specific architecture of the QEMU
> binary is selected using the QTEST_QEMU_BINARY environment variable. This api
> would be useful to run tests against some older cpu models after checking if
> QEMU actually supported these models.
>
> CC: thuth@redhat.com
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> ---
> tests/qtest/libqtest.c | 84 ++++++++++++++++++++++++++++++++++++++++++
> tests/qtest/libqtest.h | 8 ++++
> 2 files changed, 92 insertions(+)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index d8f80d335e..135a607728 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -37,6 +37,7 @@
> #include "qapi/qmp/qjson.h"
> #include "qapi/qmp/qlist.h"
> #include "qapi/qmp/qstring.h"
> +#include "qapi/qmp/qbool.h"
>
> #define MAX_IRQ 256
>
> @@ -1471,6 +1472,12 @@ struct MachInfo {
> char *alias;
> };
>
> +struct CpuInfo {
> + char *name;
> + char *alias_of;
> + bool deprecated;
> +};
> +
> static void qtest_free_machine_list(struct MachInfo *machines)
> {
> if (machines) {
> @@ -1550,6 +1557,83 @@ static struct MachInfo *qtest_get_machines(const char *var)
> return machines;
> }
>
> +static struct CpuInfo *qtest_get_cpus(void)
> +{
> + static struct CpuInfo *cpus;
> + QDict *response, *minfo;
> + QList *list;
> + const QListEntry *p;
> + QObject *qobj;
> + QString *qstr;
> + QBool *qbool;
> + QTestState *qts;
> + int idx;
> +
> + if (cpus) {
> + return cpus;
> + }
> +
> + silence_spawn_log = !g_test_verbose();
> +
> + qts = qtest_init_with_env(NULL, "-machine none");
> + response = qtest_qmp(qts, "{ 'execute': 'query-cpu-definitions' }");
> + g_assert(response);
> + list = qdict_get_qlist(response, "return");
> + g_assert(list);
> +
> + cpus = g_new(struct CpuInfo, qlist_size(list) + 1);
Just use g_new0 here.
> +
> + for (p = qlist_first(list), idx = 0; p; p = qlist_next(p), idx++) {
> + minfo = qobject_to(QDict, qlist_entry_obj(p));
> + g_assert(minfo);
> +
> + qobj = qdict_get(minfo, "name");
> + g_assert(qobj);
> + qstr = qobject_to(QString, qobj);
> + g_assert(qstr);
> + cpus[idx].name = g_strdup(qstring_get_str(qstr));
> +
> + qobj = qdict_get(minfo, "alias_of");
> + if (qobj) { /* old machines do not report aliases */
> + qstr = qobject_to(QString, qobj);
> + g_assert(qstr);
> + cpus[idx].alias_of = g_strdup(qstring_get_str(qstr));
> + } else {
> + cpus[idx].alias_of = NULL;
> + }
> +
> + qobj = qdict_get(minfo, "deprecated");
> + qbool = qobject_to(QBool, qobj);
> + g_assert(qbool);
> + cpus[idx].deprecated = qbool_get_bool(qbool);
> + }
> +
> + qtest_quit(qts);
> + qobject_unref(response);
> +
> + silence_spawn_log = false;
> +
> + memset(&cpus[idx], 0, sizeof(struct CpuInfo)); /* Terminating entry */
Not required with g_new0 usage.
> + return cpus;
> +}
With the minor change
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
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 :|
next prev parent reply other threads:[~2024-06-10 9:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 4:44 [PATCH v3 0/3] x86 cpu test refactoring Ani Sinha
2024-06-06 4:44 ` [PATCH v3 1/3] qtest/x86/numa-test: do not use the obsolete 'pentium' cpu Ani Sinha
2024-06-06 4:44 ` [PATCH 2/3] tests/qtest/libqtest: add qtest_has_cpu() api Ani Sinha
2024-06-10 9:02 ` Daniel P. Berrangé [this message]
2024-06-06 4:44 ` [PATCH v3 3/3] tests/qtest/x86: check for availability of older cpu models before running tests Ani Sinha
2024-06-10 9:04 ` Daniel P. Berrangé
-- strict thread matches above, loose matches on Subject: below --
2024-06-05 14:13 [PATCH v2 0/3] x86 cpu test refactoring Ani Sinha
2024-06-05 14:13 ` [PATCH 2/3] tests/qtest/libqtest: add qtest_has_cpu() api Ani Sinha
2024-06-05 7:25 [PATCH 0/3] x86 cpu test refactoring Ani Sinha
2024-06-05 7:25 ` [PATCH 2/3] tests/qtest/libqtest: add qtest_has_cpu() api Ani Sinha
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=ZmbBElz4clEuZ1zp@redhat.com \
--to=berrange@redhat.com \
--cc=anisinha@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.