From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: "Ani Sinha" <anisinha@redhat.com>,
"Reviewed-by : Daniel P . Berrangé" <berrange@redhat.com>
Subject: [PULL 03/15] tests/qtest/libqtest: add qtest_has_cpu_model() api
Date: Wed, 12 Jun 2024 15:20:43 +0200 [thread overview]
Message-ID: <20240612132055.326889-4-thuth@redhat.com> (raw)
In-Reply-To: <20240612132055.326889-1-thuth@redhat.com>
From: Ani Sinha <anisinha@redhat.com>
Added a new test api qtest_has_cpu_model() 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.
Signed-off-by: Ani Sinha <anisinha@redhat.com>
Reviewed-by: Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20240610155303.7933-3-anisinha@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/libqtest.h | 8 ++++
tests/qtest/libqtest.c | 83 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+)
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 6e3d3525bf..beb96b18eb 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -949,6 +949,14 @@ bool qtest_has_machine(const char *machine);
*/
bool qtest_has_machine_with_env(const char *var, const char *machine);
+/**
+ * qtest_has_cpu_model:
+ * @cpu: The cpu to look for
+ *
+ * Returns: true if the cpu is available in the target binary.
+ */
+bool qtest_has_cpu_model(const char *cpu);
+
/**
* qtest_has_device:
* @device: The device to look for
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index d8f80d335e..18e2f7f282 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 CpuModel {
+ char *name;
+ char *alias_of;
+ bool deprecated;
+};
+
static void qtest_free_machine_list(struct MachInfo *machines)
{
if (machines) {
@@ -1550,6 +1557,82 @@ static struct MachInfo *qtest_get_machines(const char *var)
return machines;
}
+static struct CpuModel *qtest_get_cpu_models(void)
+{
+ static struct CpuModel *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_new0(struct CpuModel, qlist_size(list) + 1);
+
+ 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;
+
+ return cpus;
+}
+
+bool qtest_has_cpu_model(const char *cpu)
+{
+ struct CpuModel *cpus;
+ int i;
+
+ cpus = qtest_get_cpu_models();
+
+ for (i = 0; cpus[i].name != NULL; i++) {
+ if (g_str_equal(cpu, cpus[i].name) ||
+ (cpus[i].alias_of && g_str_equal(cpu, cpus[i].alias_of))) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void qtest_cb_for_every_machine(void (*cb)(const char *machine),
bool skip_old_versioned)
{
--
2.45.2
next prev parent reply other threads:[~2024-06-12 13:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 13:20 [PULL 00/15] CPU-related test updates Thomas Huth
2024-06-12 13:20 ` [PULL 01/15] tests/avocado: Update LoongArch bios file Thomas Huth
2024-06-12 13:20 ` [PULL 02/15] qtest/x86/numa-test: do not use the obsolete 'pentium' cpu Thomas Huth
2024-06-12 13:20 ` Thomas Huth [this message]
2024-06-12 13:20 ` [PULL 04/15] tests/qtest/x86: check for availability of older cpu models before running tests Thomas Huth
2024-06-12 13:20 ` [PULL 05/15] meson: Remove libibumad dependence Thomas Huth
2024-06-12 13:20 ` [PULL 06/15] test: " Thomas Huth
2024-06-12 13:20 ` [PULL 07/15] tests/unit/test-smp-parse: Fix comments of drawers and books case Thomas Huth
2024-06-12 13:20 ` [PULL 08/15] tests/unit/test-smp-parse: Fix comment of parameters=1 case Thomas Huth
2024-06-12 13:20 ` [PULL 09/15] tests/unit/test-smp-parse: Fix an invalid topology case Thomas Huth
2024-06-12 13:20 ` [PULL 10/15] tests/unit/test-smp-parse: Use default parameters=0 when not set in -smp Thomas Huth
2024-06-12 13:20 ` [PULL 11/15] tests/unit/test-smp-parse: Make test cases aware of module level Thomas Huth
2024-06-12 13:20 ` [PULL 12/15] tests/unit/test-smp-parse: Test "modules" parameter in -smp Thomas Huth
2024-06-12 13:20 ` [PULL 13/15] tests/unit/test-smp-parse: Test "modules" and "dies" combination case Thomas Huth
2024-06-12 13:20 ` [PULL 14/15] tests/unit/test-smp-parse: Test the full 8-levels topology hierarchy Thomas Huth
2024-06-12 13:20 ` [PULL 15/15] tests/tcg/s390x: Allow specifying extra QEMU options on the command line Thomas Huth
2024-06-14 3:59 ` [PULL 00/15] CPU-related test updates Richard Henderson
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=20240612132055.326889-4-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=anisinha@redhat.com \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).