qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: lvivier@redhat.com, thuth@redhat.com, f4bug@amsat.org, mst@redhat.com
Subject: [PATCH v2 02/15] tests: qtest: add qtest_has_accel() to check if tested binary supports accelerator
Date: Thu,  2 Sep 2021 07:35:38 -0400	[thread overview]
Message-ID: <20210902113551.461632-3-imammedo@redhat.com> (raw)
In-Reply-To: <20210902113551.461632-1-imammedo@redhat.com>

Currently it is not possible to create tests that have KVM as a hard
requirement on a host that doesn't support KVM for tested target
binary (modulo going through the trouble of compiling out
the offending test case).

Following scenario makes test fail when it's run on non x86 host:
  qemu-system-x86_64 -enable-kvm -M q35,kernel-irqchip=on -smp 1,maxcpus=288

This patch introduces qtest_has_accel() to let users check if accel is
available in advance and avoid executing non run-able test-cases.

It implements detection of TCG and KVM only, the rest could be
added later on, when we actually start testing them in qtest.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
PS:
There is an alternative 'runtime' approach on list:
'query-accels' series.
https://patchwork.kernel.org/project/qemu-devel/patch/20210503211020.894589-4-philmd@redhat.com/

on upside this impl. much cheaper to execute than the 'query-accels'
as it doesn't need to run QEMU for probing.

v4:
  - s/qtest_has_kvm/qtest_has_accel/
  - add TCG detection (based on --disable-tcg)
v3:
  - make it work with --disable-kvm
       (Claudio Fontana <cfontana@suse.de>)
v2:
  - fix access() check.
     s/access()/!access()/
  - format C array items at meson.build time

CC: thuth@redhat.com
CC: lvivier@redhat.com
CC: f4bug@amsat.org
---
 tests/qtest/libqos/libqtest.h |  8 ++++++++
 meson.build                   |  6 ++++++
 tests/qtest/libqtest.c        | 27 +++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
index a68dcd79d4..59e9271195 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -588,6 +588,14 @@ bool qtest_big_endian(QTestState *s);
  */
 const char *qtest_get_arch(void);
 
+/**
+ * qtest_has_accel:
+ * @accel_name: Accelerator name to check for.
+ *
+ * Returns: true if the accelerator is built in.
+ */
+bool qtest_has_accel(const char *accel_name);
+
 /**
  * qtest_add_func:
  * @str: Test case path.
diff --git a/meson.build b/meson.build
index bf63784812..42c99b1ebd 100644
--- a/meson.build
+++ b/meson.build
@@ -76,6 +76,12 @@ else
   kvm_targets = []
 endif
 
+kvm_targets_c = ''
+if not get_option('kvm').disabled() and targetos == 'linux'
+  kvm_targets_c = '"' + '" ,"'.join(kvm_targets) + '"'
+endif
+config_host_data.set('CONFIG_KVM_TARGETS', kvm_targets_c)
+
 accelerator_targets = { 'CONFIG_KVM': kvm_targets }
 if cpu in ['x86', 'x86_64', 'arm', 'aarch64']
   # i368 emulator provides xenpv machine type for multiple architectures
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 825b13a44c..643769e416 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -920,6 +920,33 @@ const char *qtest_get_arch(void)
     return end + 1;
 }
 
+bool qtest_has_accel(const char *accel_name)
+{
+    if (g_str_equal(accel_name, "tcg")) {
+#if defined(CONFIG_TCG)
+        return true;
+#else
+        return false;
+#endif
+    } else if (g_str_equal(accel_name, "kvm")) {
+        int i;
+        const char *arch = qtest_get_arch();
+        const char *targets[] = { CONFIG_KVM_TARGETS };
+
+        for (i = 0; i < ARRAY_SIZE(targets); i++) {
+            if (!strncmp(targets[i], arch, strlen(arch))) {
+                if (!access("/dev/kvm", R_OK | W_OK)) {
+                    return true;
+                }
+            }
+        }
+    } else {
+        /* not implemented */
+        g_assert_not_reached();
+    }
+    return false;
+}
+
 bool qtest_get_irq(QTestState *s, int num)
 {
     /* dummy operation in order to make sure irq is up to date */
-- 
2.27.0



  parent reply	other threads:[~2021-09-02 11:55 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 11:35 [PATCH v2 00/15] tests: acpi: add x2apic and various iommu tests Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 01/15] tests: acpi: dump table with failed checksum Igor Mammedov
2021-09-02 11:35 ` Igor Mammedov [this message]
2021-09-02 11:35 ` [PATCH v2 03/15] tests: acpi: whitelist expected tables for acpi/q35/xapic testcase Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 04/15] tests: acpi: q35: test for x2APIC entries in SRAT Igor Mammedov
2021-10-18 21:31   ` Michael S. Tsirkin
2021-10-19  9:48     ` Igor Mammedov
2021-10-19 10:23       ` Michael S. Tsirkin
2021-10-19 11:36         ` Igor Mammedov
2021-10-19 11:44           ` Michael S. Tsirkin
2021-10-20  8:16             ` Igor Mammedov
2021-10-20  8:18               ` Michael S. Tsirkin
2021-10-20  8:53                 ` Igor Mammedov
2021-10-20  8:58                   ` Thomas Huth
2021-10-20  9:43                     ` Igor Mammedov
2021-10-20  9:46                   ` Michael S. Tsirkin
2021-10-20 10:01                     ` Igor Mammedov
2021-10-20 10:03                       ` Michael S. Tsirkin
2021-09-02 11:35 ` [PATCH v2 05/15] tests: acpi: update expected tables blobs Igor Mammedov
2021-10-18 20:37   ` Michael S. Tsirkin
2021-10-19  9:56     ` Igor Mammedov
2021-10-19 10:27       ` Michael S. Tsirkin
2021-10-20  9:05         ` Igor Mammedov
2021-10-20  9:45           ` Michael S. Tsirkin
2021-10-20  9:57             ` Igor Mammedov
2021-10-20 10:02               ` Michael S. Tsirkin
2021-09-02 11:35 ` [PATCH v2 06/15] tests: acpi: whitelist new expected table tests/data/acpi/q35/DMAR.dmar Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 07/15] tests: acpi: add testcase for intel_iommu (DMAR table) Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 08/15] tests: acpi: add expected blob for DMAR table Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 09/15] tests: acpi: whitelist expected blobs for new acpi/q35/ivrs testcase Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 10/15] tests: acpi: add testcase for amd-iommu (IVRS table) Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 11/15] tests: acpi: update expected blobs Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 12/15] tests: acpi: arm/virt: drop redundant test_acpi_one() in test_acpi_virt_tcg() Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 13/15] tests: arm-cpu-features: use qtest_has_kvm() API Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 14/15] tests: migration-test: use qtest_has_accel() API Igor Mammedov
2021-09-02 11:35 ` [PATCH v2 15/15] tests: bios-tables-test: use qtest_has_accel() API to register TCG only tests Igor Mammedov
2021-10-06 14:05 ` [PATCH v2 00/15] tests: acpi: add x2apic and various iommu tests Igor Mammedov

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=20210902113551.461632-3-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=lvivier@redhat.com \
    --cc=mst@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 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).