qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/6] tests/qtest: Add qtest_probe_accel() method


From: Thomas Huth
Subject: Re: [PATCH 2/6] tests/qtest: Add qtest_probe_accel() method
Date: Fri, 12 Mar 2021 09:16:01 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0

On 12/03/2021 00.11, Philippe Mathieu-Daudé wrote:
Introduce the qtest_probe_accel() method which allows
to query at runtime if a QEMU instance has an accelerator
built-in.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
  tests/qtest/libqos/libqtest.h |  9 +++++++++
  tests/qtest/libqtest.c        | 24 ++++++++++++++++++++++++
  2 files changed, 33 insertions(+)

diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
index a68dcd79d44..ebedb82ec98 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -763,6 +763,15 @@ void qmp_expect_error_and_unref(QDict *rsp, const char 
*class);
   */
  bool qtest_probe_child(QTestState *s);
+/**
+ * qtest_probe_accel:
+ * @s: QTestState instance to operate on.
+ * @name: Accelerator name to check for.
+ *
+ * Returns: true if the accelerator is built in.
+ */
+bool qtest_probe_accel(QTestState *s, const char *name);

Maybe better qtest_has_accel() ? ... that makes it clear right from the start what the return type is about.

  /**
   * qtest_set_expected_status:
   * @s: QTestState instance to operate on.
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 71e359efcd3..57e7e55b9cc 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -872,6 +872,30 @@ void qtest_qmp_eventwait(QTestState *s, const char *event)
      qobject_unref(response);
  }
+bool qtest_probe_accel(QTestState *s, const char *name)
+{
+    bool has_accel = false;
+    QDict *response;
+    QList *accels;
+    QListEntry *accel;
+
+    response = qtest_qmp(s, "{'execute': 'query-accels'}");
+    accels = qdict_get_qlist(response, "return");
+
+    QLIST_FOREACH_ENTRY(accels, accel) {
+        QDict *accel_dict = qobject_to(QDict, qlist_entry_obj(accel));
+        const char *accel_name = qdict_get_str(accel_dict, "name");
+
+        if (!strcmp(name, accel_name)) {

I'd prefer g_str_equal() ... that's easier to read.

+            has_accel = true;
+            break;
+        }
+    }
+    qobject_unref(response);
+
+    return has_accel;
+}
+
  char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
  {
      char *cmd;


 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]